diff options
| author | Po Lu | 2024-06-16 11:35:44 +0800 |
|---|---|---|
| committer | Po Lu | 2024-06-16 11:35:44 +0800 |
| commit | 8d60b6bab8b95e4f3b350a8b093e8f60e3f83f69 (patch) | |
| tree | f6bbcad99cc2bcbd8805fbdbd51ff484075043ec /java | |
| parent | 3241d6cfbfeca48fbd5dc12dbf56c21688e9dce4 (diff) | |
| download | emacs-8d60b6bab8b95e4f3b350a8b093e8f60e3f83f69.tar.gz emacs-8d60b6bab8b95e4f3b350a8b093e8f60e3f83f69.zip | |
Simplify bitmap reallocation on Android
* java/org/gnu/emacs/EmacsView.java: Update outdated commentary.
(handleDirtyBitmap): Don't copy contents of the previous bitmap
to the new.
(onLayout): Unconditionally expose upon layout changes.
Diffstat (limited to 'java')
| -rw-r--r-- | java/org/gnu/emacs/EmacsView.java | 35 |
1 files changed, 17 insertions, 18 deletions
diff --git a/java/org/gnu/emacs/EmacsView.java b/java/org/gnu/emacs/EmacsView.java index 4a505b3c0dc..78d1ef785da 100644 --- a/java/org/gnu/emacs/EmacsView.java +++ b/java/org/gnu/emacs/EmacsView.java | |||
| @@ -49,11 +49,13 @@ import java.util.Arrays; | |||
| 49 | 49 | ||
| 50 | /* This is an Android view which has a back and front buffer. When | 50 | /* This is an Android view which has a back and front buffer. When |
| 51 | swapBuffers is called, the back buffer is swapped to the front | 51 | swapBuffers is called, the back buffer is swapped to the front |
| 52 | buffer, and any damage is invalidated. frontBitmap and backBitmap | 52 | buffer, and any damage is invalidated. A front buffer bitmap defined |
| 53 | are modified and used both from the UI and the Emacs thread. As a | 53 | in EmacsSurfaceView, and the write buffer in this file, are modified |
| 54 | result, there is a lock held during all drawing operations. | 54 | and used both from the UI and the Emacs thread. As a result, there |
| 55 | is a lock held during all drawing operations. | ||
| 55 | 56 | ||
| 56 | It is also a ViewGroup, as it also lays out children. */ | 57 | It is also a ViewGroup, so that it may also manage the layout of its |
| 58 | children. */ | ||
| 57 | 59 | ||
| 58 | public final class EmacsView extends ViewGroup | 60 | public final class EmacsView extends ViewGroup |
| 59 | implements ViewTreeObserver.OnGlobalLayoutListener | 61 | implements ViewTreeObserver.OnGlobalLayoutListener |
| @@ -204,19 +206,19 @@ public final class EmacsView extends ViewGroup | |||
| 204 | rectangle ID. */ | 206 | rectangle ID. */ |
| 205 | lastClipSerial = 0; | 207 | lastClipSerial = 0; |
| 206 | 208 | ||
| 207 | /* Copy over the contents of the old bitmap. */ | 209 | /* Clear the bitmap reallocation flag. */ |
| 208 | if (oldBitmap != null) | ||
| 209 | canvas.drawBitmap (oldBitmap, 0f, 0f, new Paint ()); | ||
| 210 | |||
| 211 | bitmapDirty = false; | 210 | bitmapDirty = false; |
| 212 | 211 | ||
| 213 | /* Explicitly free the old bitmap's memory. */ | 212 | /* Explicitly free the old bitmap's memory. The bitmap might |
| 214 | 213 | continue to be referenced by canvas or JNI objects returned by | |
| 214 | getBitmap or getCanvas, but the underlying storage will not be | ||
| 215 | released until such references disappear. See | ||
| 216 | BitmapWrapper::freePixels in hwui/jni/Bitmap.cpp. */ | ||
| 215 | if (oldBitmap != null) | 217 | if (oldBitmap != null) |
| 216 | oldBitmap.recycle (); | 218 | oldBitmap.recycle (); |
| 217 | 219 | ||
| 218 | /* Some Android versions still don't free the bitmap until the | 220 | /* Some Android versions still refuse to release the bitmap until |
| 219 | next GC. */ | 221 | the next GC. */ |
| 220 | Runtime.getRuntime ().gc (); | 222 | Runtime.getRuntime ().gc (); |
| 221 | } | 223 | } |
| 222 | 224 | ||
| @@ -367,13 +369,10 @@ public final class EmacsView extends ViewGroup | |||
| 367 | 369 | ||
| 368 | if (changed) | 370 | if (changed) |
| 369 | { | 371 | { |
| 372 | /* Expose the window upon a change in the view's size that | ||
| 373 | prompts the creation of a new bitmap. */ | ||
| 370 | explicitlyDirtyBitmap (); | 374 | explicitlyDirtyBitmap (); |
| 371 | 375 | needExpose = true; | |
| 372 | /* Expose the window upon a change in the view's size. */ | ||
| 373 | |||
| 374 | if (right - left > oldMeasuredWidth | ||
| 375 | || bottom - top > oldMeasuredHeight) | ||
| 376 | needExpose = true; | ||
| 377 | 376 | ||
| 378 | /* This might return NULL if this view is not attached. */ | 377 | /* This might return NULL if this view is not attached. */ |
| 379 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) | 378 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) |