From 140755f2cfe6a39f643ab0a9ca2d81b0ed470ae7 Mon Sep 17 00:00:00 2001
From: Po Lu
Date: Thu, 13 Jul 2023 12:05:50 +0800
Subject: Disable hardware acceleration on Android
It serves no purpose and causes tearing. Uploading the bitmap
to the GPU takes about as long as it does to incrementally
update the surface in software.
* java/AndroidManifest.xml.in: Disable hardware acceleration.
* java/org/gnu/emacs/EmacsActivity.java (EmacsActivity): Make
lastClosedMenu static.
* java/org/gnu/emacs/EmacsDialog.java (toAlertDialog): Enable
hardware acceleration within alert dialogs.
* java/org/gnu/emacs/EmacsSurfaceView.java (onDraw): Describe
why hardware acceleration is disabled.
* java/org/gnu/emacs/EmacsWindow.java (run): Remove redundant
call.
---
java/AndroidManifest.xml.in | 5 +++++
java/org/gnu/emacs/EmacsActivity.java | 2 +-
java/org/gnu/emacs/EmacsDialog.java | 14 +++++++++++++-
java/org/gnu/emacs/EmacsSurfaceView.java | 20 +++++++++++++++++++-
java/org/gnu/emacs/EmacsWindow.java | 2 +-
5 files changed, 39 insertions(+), 4 deletions(-)
(limited to 'java')
diff --git a/java/AndroidManifest.xml.in b/java/AndroidManifest.xml.in
index e79fb4e46e7..f2aede7369c 100644
--- a/java/AndroidManifest.xml.in
+++ b/java/AndroidManifest.xml.in
@@ -77,10 +77,14 @@ along with GNU Emacs. If not, see . -->
@ANDROID_SHARED_USER_ID@
android:extractNativeLibs="true">
+
+
@@ -173,6 +177,7 @@ along with GNU Emacs. If not, see . -->
= Build.VERSION_CODES.HONEYCOMB)
+ {
+ flag = WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED;
+ window = dialog.getWindow ();
+ window.addFlags (flag);
+ }
+
return dialog;
}
diff --git a/java/org/gnu/emacs/EmacsSurfaceView.java b/java/org/gnu/emacs/EmacsSurfaceView.java
index 3f62af4ab99..54fe70e1634 100644
--- a/java/org/gnu/emacs/EmacsSurfaceView.java
+++ b/java/org/gnu/emacs/EmacsSurfaceView.java
@@ -176,7 +176,25 @@ public final class EmacsSurfaceView extends View
onDraw (Canvas canvas)
{
/* Paint the view's bitmap; the bitmap might be recycled right
- now. */
+ now.
+
+ Hardware acceleration is disabled in AndroidManifest.xml to
+ prevent Android from uploading the front buffer to the GPU from
+ a separate thread. This is important for two reasons: first,
+ the GPU command queue uses a massive amount of memory (dozens
+ of MiB) to upload bitmaps to the GPU, regardless of how much of
+ the bitmap has actually changed.
+
+ Secondly, asynchronous texturization leads to race conditions
+ when a buffer swap occurs before the front buffer is fully
+ uploaded to the GPU. Normally, only slight and tolerable
+ tearing should result from this behavior, but Android does not
+ properly interlock the ``generation ID'' used to avoid
+ texturizing unchanged bitmaps with the bitmap contents,
+ consequentially leading to textures in an incomplete state
+ remaining in use to the GPU if a buffer swap happens between
+ the image data being uploaded and the ``generation ID'' being
+ read. */
if (frontBuffer != null)
canvas.drawBitmap (frontBuffer, 0f, 0f, uiThreadPaint);
diff --git a/java/org/gnu/emacs/EmacsWindow.java b/java/org/gnu/emacs/EmacsWindow.java
index 5e45275631b..0e96a8382d0 100644
--- a/java/org/gnu/emacs/EmacsWindow.java
+++ b/java/org/gnu/emacs/EmacsWindow.java
@@ -1377,7 +1377,7 @@ public final class EmacsWindow extends EmacsHandleObject
if (tem != null)
{
- activity = (EmacsActivity) getAttachedConsumer ();
+ activity = (EmacsActivity) tem;
activity.syncFullscreenWith (EmacsWindow.this);
}
}
--
cgit v1.2.1