From: Po Lu Date: Mon, 19 Jun 2023 07:26:07 +0000 (+0800) Subject: Update Android port X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=405d14402f21df3404ce9c5aa3c7f942e6deb3e3;p=emacs.git Update Android port * java/org/gnu/emacs/EmacsView.java (EmacsView, dimensionsLock): New field. (): Create new lock object. (handleDirtyBitmap, onLayout, onAttachedToWindow): Make sure measuredWidth and measuredHeight are extracted and set atomically. Send Expose upon layout changes if the view has grown. --- diff --git a/java/org/gnu/emacs/EmacsView.java b/java/org/gnu/emacs/EmacsView.java index 0cabefdf385..bb4dace655a 100644 --- a/java/org/gnu/emacs/EmacsView.java +++ b/java/org/gnu/emacs/EmacsView.java @@ -88,6 +88,9 @@ public final class EmacsView extends ViewGroup /* The last measured width and height. */ private int measuredWidth, measuredHeight; + /* Object acting as a lock for those values. */ + private Object dimensionsLock; + /* The serial of the last clip rectangle change. */ private long lastClipSerial; @@ -144,12 +147,23 @@ public final class EmacsView extends ViewGroup /* Add this view as its own global layout listener. */ getViewTreeObserver ().addOnGlobalLayoutListener (this); + + /* Create an object used as a lock. */ + this.dimensionsLock = new Object (); } private void handleDirtyBitmap () { Bitmap oldBitmap; + int measuredWidth, measuredHeight; + + synchronized (dimensionsLock) + { + /* Load measuredWidth and measuredHeight. */ + measuredWidth = this.measuredWidth; + measuredHeight = this.measuredHeight; + } if (measuredWidth == 0 || measuredHeight == 0) return; @@ -171,7 +185,7 @@ public final class EmacsView extends ViewGroup /* Save the old bitmap. */ oldBitmap = bitmap; - /* Recreate the front and back buffer bitmaps. */ + /* Recreate the back buffer bitmap. */ bitmap = Bitmap.createBitmap (measuredWidth, measuredHeight, @@ -249,8 +263,11 @@ public final class EmacsView extends ViewGroup public void prepareForLayout (int wantedWidth, int wantedHeight) { - measuredWidth = wantedWidth; - measuredHeight = wantedWidth; + synchronized (dimensionsLock) + { + measuredWidth = wantedWidth; + measuredHeight = wantedWidth; + } } @Override @@ -294,19 +311,39 @@ public final class EmacsView extends ViewGroup onLayout (boolean changed, int left, int top, int right, int bottom) { - int count, i; + int count, i, oldMeasuredWidth, oldMeasuredHeight; View child; Rect windowRect; + boolean needExpose; count = getChildCount (); + needExpose = false; - measuredWidth = right - left; - measuredHeight = bottom - top; + synchronized (dimensionsLock) + { + /* Load measuredWidth and measuredHeight. */ + oldMeasuredWidth = measuredWidth; + oldMeasuredHeight = measuredHeight; - /* Dirty the back buffer. */ + /* Set measuredWidth and measuredHeight. */ + measuredWidth = right - left; + measuredHeight = bottom - top; + } - if (changed) - explicitlyDirtyBitmap (); + /* Dirty the back buffer if the layout change resulted in the view + being resized. */ + + if (changed && (right - left != oldMeasuredWidth + || bottom - top != oldMeasuredHeight)) + { + explicitlyDirtyBitmap (); + + /* Expose the window upon a change in the view's size. */ + + if (right - left > oldMeasuredWidth + || bottom - top > oldMeasuredHeight) + needExpose = true; + } for (i = 0; i < count; ++i) { @@ -336,6 +373,10 @@ public final class EmacsView extends ViewGroup mustReportLayout = false; window.viewLayout (left, top, right, bottom); } + + if (needExpose) + EmacsNative.sendExpose (this.window.handle, 0, 0, + right - left, bottom - top); } public void @@ -579,9 +620,12 @@ public final class EmacsView extends ViewGroup was called. */ bitmapDirty = true; - /* Now expose the view contents again. */ - EmacsNative.sendExpose (this.window.handle, 0, 0, - measuredWidth, measuredHeight); + synchronized (dimensionsLock) + { + /* Now expose the view contents again. */ + EmacsNative.sendExpose (this.window.handle, 0, 0, + measuredWidth, measuredHeight); + } super.onAttachedToWindow (); }