Optimize damage region tracking under Android

* java/org/gnu/emacs/EmacsDrawLine.java (perform):

* java/org/gnu/emacs/EmacsDrawRectangle.java (perform): Call
damageRect with integer coordinates in lieu of consing a new
Rect.

* java/org/gnu/emacs/EmacsDrawable.java (damageRect) <IIII>:
Declare a new variant of damageRect, accepting four integers
designating the extents of the damage rectangle.

* java/org/gnu/emacs/EmacsPixmap.java (damageRect) <IIII>: New
stub.

* java/org/gnu/emacs/EmacsView.java (damageRect) <IIII>:
Implement this overloaded variant of damageRect.

* java/org/gnu/emacs/EmacsWindow.java (damageRect): Ditto.

* src/android.c (android_init_emacs_drawable)
(android_init_emacs_window): Move search for `damageRect' to
android_init_emacs_window.
(android_damage_window): Call IIII variant of `damageRect' to
avoid consing a new rectangle.  Ameliorate dynamic method
dispatch overhead.
This commit is contained in:
Po Lu
2023-09-18 10:59:55 +08:00
parent 514b70d5a0
commit 4e46df9651
7 changed files with 49 additions and 26 deletions

View File

@@ -29,7 +29,6 @@ public final class EmacsDrawLine
perform (EmacsDrawable drawable, EmacsGC gc,
int x, int y, int x2, int y2)
{
Rect rect;
Canvas canvas;
Paint paint;
int x0, x1, y0, y1;
@@ -48,7 +47,6 @@ public final class EmacsDrawLine
/* And the clip rectangle. */
paint = gc.gcPaint;
rect = new Rect (x0, y0, x1, y1);
canvas = drawable.lockCanvas (gc);
if (canvas == null)
@@ -74,6 +72,6 @@ public final class EmacsDrawLine
/* DrawLine with clip mask not implemented; it is not used by
Emacs. */
drawable.damageRect (rect);
drawable.damageRect (x0, y0, x1, y1);
}
}

View File

@@ -114,7 +114,6 @@ public final class EmacsDrawRectangle
maskBitmap.recycle ();
}
drawable.damageRect (new Rect (x, y, x + width + 1,
y + height + 1));
drawable.damageRect (x, y, x + width + 1, y + height + 1);
}
}

View File

@@ -27,6 +27,7 @@ public interface EmacsDrawable
{
public Canvas lockCanvas (EmacsGC gc);
public void damageRect (Rect damageRect);
public void damageRect (int left, int top, int right, int bottom);
public Bitmap getBitmap ();
public boolean isDestroyed ();
};

View File

@@ -175,6 +175,13 @@ public final class EmacsPixmap extends EmacsHandleObject
}
@Override
public void
damageRect (int left, int top, int right, int bottom)
{
}
@Override
public Bitmap
getBitmap ()

View File

@@ -437,6 +437,16 @@ public final class EmacsView extends ViewGroup
damageRegion.union (damageRect);
}
/* This function enables damage to be recorded without consing a new
Rect object. */
public void
damageRect (int left, int top, int right, int bottom)
{
EmacsService.checkEmacsThread ();
damageRegion.op (left, top, right, bottom, Region.Op.UNION);
}
/* This method is called from both the UI thread and the Emacs
thread. */

View File

@@ -514,7 +514,17 @@ public final class EmacsWindow extends EmacsHandleObject
public void
damageRect (Rect damageRect)
{
view.damageRect (damageRect);
view.damageRect (damageRect.left,
damageRect.top,
damageRect.right,
damageRect.bottom);
}
@Override
public void
damageRect (int left, int top, int right, int bottom)
{
view.damageRect (left, top, right, bottom);
}
public void