]> git.eshelyaron.com Git - emacs.git/commitdiff
Optimize stipples on Android
authorPo Lu <luangruo@yahoo.com>
Mon, 6 May 2024 04:09:21 +0000 (12:09 +0800)
committerEshel Yaron <me@eshelyaron.com>
Mon, 6 May 2024 16:56:38 +0000 (18:56 +0200)
* java/org/gnu/emacs/EmacsGC.java (EmacsGC) <tileObject>:
Change type to EmacsTileObject.
(markDirty): Create an EmacsTileObject rather than a
BitmapDrawable.

* java/org/gnu/emacs/EmacsTileObject.java: New file,
significantly leaner than BitmapDrawable.

(cherry picked from commit 2f36fc1b4f78aa27f4f484fbd09fcabacee36504)

java/org/gnu/emacs/EmacsGC.java
java/org/gnu/emacs/EmacsTileObject.java [new file with mode: 0644]

index f956b230f8c984dc5dbe8eb330611708cf748ee3..d400c23e067df04b159d474ab77f43d5626f4d7b 100644 (file)
@@ -29,8 +29,6 @@ import android.graphics.PorterDuff.Mode;
 import android.graphics.PorterDuffColorFilter;
 import android.graphics.Shader.TileMode;
 
-import android.graphics.drawable.BitmapDrawable;
-
 import android.os.Build;
 
 /* X like graphics context structures.  Keep the enums in synch with
@@ -58,7 +56,7 @@ public final class EmacsGC extends EmacsHandleObject
   public Paint gcPaint;
 
   /* Drawable object for rendering the stiple bitmap.  */
-  public BitmapDrawable tileObject;
+  public EmacsTileObject tileObject;
 
   /* ID incremented every time the clipping rectangles of any GC
      changes.  */
@@ -132,11 +130,9 @@ public final class EmacsGC extends EmacsHandleObject
 
        /* Allocate a new tile object if none is already present or it
           cannot be reconfigured.  */
-       if ((tileObject == null)
-           || (Build.VERSION.SDK_INT < Build.VERSION_CODES.S))
+       if (tileObject == null)
          {
-           tileObject = new BitmapDrawable (EmacsService.resources,
-                                            stippleBitmap);
+           tileObject = new EmacsTileObject (stippleBitmap);
            tileObject.setTileModeXY (TileMode.REPEAT, TileMode.REPEAT);
          }
        else
@@ -144,11 +140,8 @@ public final class EmacsGC extends EmacsHandleObject
             bitmap.  */
          tileObject.setBitmap (stippleBitmap);
       }
-    else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S
-            && tileObject != null)
-      tileObject.setBitmap (null);
     else if (tileObject != null)
-      tileObject = null;
+      tileObject.setBitmap (null);
   }
 
   /* Prepare the tile object to draw a stippled image onto a section of
diff --git a/java/org/gnu/emacs/EmacsTileObject.java b/java/org/gnu/emacs/EmacsTileObject.java
new file mode 100644 (file)
index 0000000..34a35e8
--- /dev/null
@@ -0,0 +1,101 @@
+/* Communication module for Android terminals.  -*- c-file-style: "GNU" -*-
+
+Copyright (C) 2023-2024 Free Software Foundation, Inc.
+
+This file is part of GNU Emacs.
+
+GNU Emacs is free software: you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation, either version 3 of the License, or (at
+your option) any later version.
+
+GNU Emacs is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Emacs.  If not, see <https://www.gnu.org/licenses/>.  */
+
+package org.gnu.emacs;
+
+import android.graphics.Bitmap;
+import android.graphics.BitmapShader;
+import android.graphics.Canvas;
+import android.graphics.ColorFilter;
+import android.graphics.Paint;
+import android.graphics.Rect;
+import android.graphics.Shader.TileMode;
+
+/* This is a crude facsimilie of the BitmapDrawable class implementing
+   just enough of its functionality to support displaying stipples in
+   EmacsGC.  */
+
+public final class EmacsTileObject
+{
+  /* Color filter object set by EmacsGC.  */
+  private ColorFilter colorFilter;
+
+  /* Bitmap object set by EmacsGC.  */
+  private Bitmap bitmap;
+
+  /* Tiling modes on either axis.  */
+  private TileMode xTile, yTile;
+
+  /* Destination rectangle.  */
+  private Rect boundsRect;
+
+  /* Paint providing graphics properties for drawBitmap.  */
+  private Paint paint;
+
+\f
+
+  public
+  EmacsTileObject (Bitmap stippleBitmap)
+  {
+    bitmap = stippleBitmap;
+    paint  = new Paint ();
+  }
+
+  public void
+  setBitmap (Bitmap newBitmap)
+  {
+    bitmap = newBitmap;
+  }
+
+  public void
+  setBounds (Rect bounds)
+  {
+    boundsRect = bounds;
+  }
+
+  public void
+  setTileModeXY (TileMode newXTile, TileMode newYTile)
+  {
+    xTile = newXTile;
+    yTile = newYTile;
+  }
+
+  public void
+  setColorFilter (ColorFilter filterObject)
+  {
+    paint.setColorFilter (filterObject);
+  }
+
+  public Bitmap
+  getBitmap ()
+  {
+    return bitmap;
+  }
+
+  /* Replicate `bitmap' over CANVAS so that boundsRect is covered with
+     copies thereof on the X axis, if xTile is REPEAT, and also on the Y
+     axis, if yTile is a like value.  */
+
+  public void
+  draw (Canvas canvas)
+  {
+    paint.setShader (new BitmapShader (bitmap, xTile, yTile));
+    canvas.drawRect (boundsRect, paint);
+  }
+};