diff options
| author | Po Lu | 2023-06-19 15:26:07 +0800 |
|---|---|---|
| committer | Po Lu | 2023-06-19 15:26:07 +0800 |
| commit | 405d14402f21df3404ce9c5aa3c7f942e6deb3e3 (patch) | |
| tree | 074dda76c8e586fceea7eeb63a5daac141772498 /java | |
| parent | 0bdeb217fce90f17f6b67cf581f2f5f0ebf7e168 (diff) | |
| download | emacs-405d14402f21df3404ce9c5aa3c7f942e6deb3e3.tar.gz emacs-405d14402f21df3404ce9c5aa3c7f942e6deb3e3.zip | |
Update Android port
* java/org/gnu/emacs/EmacsView.java (EmacsView, dimensionsLock):
New field.
(<init>): 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.
Diffstat (limited to 'java')
| -rw-r--r-- | java/org/gnu/emacs/EmacsView.java | 68 |
1 files changed, 56 insertions, 12 deletions
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 | |||
| 88 | /* The last measured width and height. */ | 88 | /* The last measured width and height. */ |
| 89 | private int measuredWidth, measuredHeight; | 89 | private int measuredWidth, measuredHeight; |
| 90 | 90 | ||
| 91 | /* Object acting as a lock for those values. */ | ||
| 92 | private Object dimensionsLock; | ||
| 93 | |||
| 91 | /* The serial of the last clip rectangle change. */ | 94 | /* The serial of the last clip rectangle change. */ |
| 92 | private long lastClipSerial; | 95 | private long lastClipSerial; |
| 93 | 96 | ||
| @@ -144,12 +147,23 @@ public final class EmacsView extends ViewGroup | |||
| 144 | 147 | ||
| 145 | /* Add this view as its own global layout listener. */ | 148 | /* Add this view as its own global layout listener. */ |
| 146 | getViewTreeObserver ().addOnGlobalLayoutListener (this); | 149 | getViewTreeObserver ().addOnGlobalLayoutListener (this); |
| 150 | |||
| 151 | /* Create an object used as a lock. */ | ||
| 152 | this.dimensionsLock = new Object (); | ||
| 147 | } | 153 | } |
| 148 | 154 | ||
| 149 | private void | 155 | private void |
| 150 | handleDirtyBitmap () | 156 | handleDirtyBitmap () |
| 151 | { | 157 | { |
| 152 | Bitmap oldBitmap; | 158 | Bitmap oldBitmap; |
| 159 | int measuredWidth, measuredHeight; | ||
| 160 | |||
| 161 | synchronized (dimensionsLock) | ||
| 162 | { | ||
| 163 | /* Load measuredWidth and measuredHeight. */ | ||
| 164 | measuredWidth = this.measuredWidth; | ||
| 165 | measuredHeight = this.measuredHeight; | ||
| 166 | } | ||
| 153 | 167 | ||
| 154 | if (measuredWidth == 0 || measuredHeight == 0) | 168 | if (measuredWidth == 0 || measuredHeight == 0) |
| 155 | return; | 169 | return; |
| @@ -171,7 +185,7 @@ public final class EmacsView extends ViewGroup | |||
| 171 | /* Save the old bitmap. */ | 185 | /* Save the old bitmap. */ |
| 172 | oldBitmap = bitmap; | 186 | oldBitmap = bitmap; |
| 173 | 187 | ||
| 174 | /* Recreate the front and back buffer bitmaps. */ | 188 | /* Recreate the back buffer bitmap. */ |
| 175 | bitmap | 189 | bitmap |
| 176 | = Bitmap.createBitmap (measuredWidth, | 190 | = Bitmap.createBitmap (measuredWidth, |
| 177 | measuredHeight, | 191 | measuredHeight, |
| @@ -249,8 +263,11 @@ public final class EmacsView extends ViewGroup | |||
| 249 | public void | 263 | public void |
| 250 | prepareForLayout (int wantedWidth, int wantedHeight) | 264 | prepareForLayout (int wantedWidth, int wantedHeight) |
| 251 | { | 265 | { |
| 252 | measuredWidth = wantedWidth; | 266 | synchronized (dimensionsLock) |
| 253 | measuredHeight = wantedWidth; | 267 | { |
| 268 | measuredWidth = wantedWidth; | ||
| 269 | measuredHeight = wantedWidth; | ||
| 270 | } | ||
| 254 | } | 271 | } |
| 255 | 272 | ||
| 256 | @Override | 273 | @Override |
| @@ -294,19 +311,39 @@ public final class EmacsView extends ViewGroup | |||
| 294 | onLayout (boolean changed, int left, int top, int right, | 311 | onLayout (boolean changed, int left, int top, int right, |
| 295 | int bottom) | 312 | int bottom) |
| 296 | { | 313 | { |
| 297 | int count, i; | 314 | int count, i, oldMeasuredWidth, oldMeasuredHeight; |
| 298 | View child; | 315 | View child; |
| 299 | Rect windowRect; | 316 | Rect windowRect; |
| 317 | boolean needExpose; | ||
| 300 | 318 | ||
| 301 | count = getChildCount (); | 319 | count = getChildCount (); |
| 320 | needExpose = false; | ||
| 302 | 321 | ||
| 303 | measuredWidth = right - left; | 322 | synchronized (dimensionsLock) |
| 304 | measuredHeight = bottom - top; | 323 | { |
| 324 | /* Load measuredWidth and measuredHeight. */ | ||
| 325 | oldMeasuredWidth = measuredWidth; | ||
| 326 | oldMeasuredHeight = measuredHeight; | ||
| 305 | 327 | ||
| 306 | /* Dirty the back buffer. */ | 328 | /* Set measuredWidth and measuredHeight. */ |
| 329 | measuredWidth = right - left; | ||
| 330 | measuredHeight = bottom - top; | ||
| 331 | } | ||
| 307 | 332 | ||
| 308 | if (changed) | 333 | /* Dirty the back buffer if the layout change resulted in the view |
| 309 | explicitlyDirtyBitmap (); | 334 | being resized. */ |
| 335 | |||
| 336 | if (changed && (right - left != oldMeasuredWidth | ||
| 337 | || bottom - top != oldMeasuredHeight)) | ||
| 338 | { | ||
| 339 | explicitlyDirtyBitmap (); | ||
| 340 | |||
| 341 | /* Expose the window upon a change in the view's size. */ | ||
| 342 | |||
| 343 | if (right - left > oldMeasuredWidth | ||
| 344 | || bottom - top > oldMeasuredHeight) | ||
| 345 | needExpose = true; | ||
| 346 | } | ||
| 310 | 347 | ||
| 311 | for (i = 0; i < count; ++i) | 348 | for (i = 0; i < count; ++i) |
| 312 | { | 349 | { |
| @@ -336,6 +373,10 @@ public final class EmacsView extends ViewGroup | |||
| 336 | mustReportLayout = false; | 373 | mustReportLayout = false; |
| 337 | window.viewLayout (left, top, right, bottom); | 374 | window.viewLayout (left, top, right, bottom); |
| 338 | } | 375 | } |
| 376 | |||
| 377 | if (needExpose) | ||
| 378 | EmacsNative.sendExpose (this.window.handle, 0, 0, | ||
| 379 | right - left, bottom - top); | ||
| 339 | } | 380 | } |
| 340 | 381 | ||
| 341 | public void | 382 | public void |
| @@ -579,9 +620,12 @@ public final class EmacsView extends ViewGroup | |||
| 579 | was called. */ | 620 | was called. */ |
| 580 | bitmapDirty = true; | 621 | bitmapDirty = true; |
| 581 | 622 | ||
| 582 | /* Now expose the view contents again. */ | 623 | synchronized (dimensionsLock) |
| 583 | EmacsNative.sendExpose (this.window.handle, 0, 0, | 624 | { |
| 584 | measuredWidth, measuredHeight); | 625 | /* Now expose the view contents again. */ |
| 626 | EmacsNative.sendExpose (this.window.handle, 0, 0, | ||
| 627 | measuredWidth, measuredHeight); | ||
| 628 | } | ||
| 585 | 629 | ||
| 586 | super.onAttachedToWindow (); | 630 | super.onAttachedToWindow (); |
| 587 | } | 631 | } |