diff options
| author | Po Lu | 2024-05-06 12:09:21 +0800 |
|---|---|---|
| committer | Po Lu | 2024-05-06 12:09:21 +0800 |
| commit | 2f36fc1b4f78aa27f4f484fbd09fcabacee36504 (patch) | |
| tree | 2a7eae93d0ff48352def6b30ef6d37b0c363676f /java | |
| parent | f920959ac98afa8f8eb142abe94bec276fa7a2b7 (diff) | |
| download | emacs-2f36fc1b4f78aa27f4f484fbd09fcabacee36504.tar.gz emacs-2f36fc1b4f78aa27f4f484fbd09fcabacee36504.zip | |
Optimize stipples on Android
* 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.
Diffstat (limited to 'java')
| -rw-r--r-- | java/org/gnu/emacs/EmacsGC.java | 15 | ||||
| -rw-r--r-- | java/org/gnu/emacs/EmacsTileObject.java | 101 |
2 files changed, 105 insertions, 11 deletions
diff --git a/java/org/gnu/emacs/EmacsGC.java b/java/org/gnu/emacs/EmacsGC.java index f956b230f8c..d400c23e067 100644 --- a/java/org/gnu/emacs/EmacsGC.java +++ b/java/org/gnu/emacs/EmacsGC.java | |||
| @@ -29,8 +29,6 @@ import android.graphics.PorterDuff.Mode; | |||
| 29 | import android.graphics.PorterDuffColorFilter; | 29 | import android.graphics.PorterDuffColorFilter; |
| 30 | import android.graphics.Shader.TileMode; | 30 | import android.graphics.Shader.TileMode; |
| 31 | 31 | ||
| 32 | import android.graphics.drawable.BitmapDrawable; | ||
| 33 | |||
| 34 | import android.os.Build; | 32 | import android.os.Build; |
| 35 | 33 | ||
| 36 | /* X like graphics context structures. Keep the enums in synch with | 34 | /* X like graphics context structures. Keep the enums in synch with |
| @@ -58,7 +56,7 @@ public final class EmacsGC extends EmacsHandleObject | |||
| 58 | public Paint gcPaint; | 56 | public Paint gcPaint; |
| 59 | 57 | ||
| 60 | /* Drawable object for rendering the stiple bitmap. */ | 58 | /* Drawable object for rendering the stiple bitmap. */ |
| 61 | public BitmapDrawable tileObject; | 59 | public EmacsTileObject tileObject; |
| 62 | 60 | ||
| 63 | /* ID incremented every time the clipping rectangles of any GC | 61 | /* ID incremented every time the clipping rectangles of any GC |
| 64 | changes. */ | 62 | changes. */ |
| @@ -132,11 +130,9 @@ public final class EmacsGC extends EmacsHandleObject | |||
| 132 | 130 | ||
| 133 | /* Allocate a new tile object if none is already present or it | 131 | /* Allocate a new tile object if none is already present or it |
| 134 | cannot be reconfigured. */ | 132 | cannot be reconfigured. */ |
| 135 | if ((tileObject == null) | 133 | if (tileObject == null) |
| 136 | || (Build.VERSION.SDK_INT < Build.VERSION_CODES.S)) | ||
| 137 | { | 134 | { |
| 138 | tileObject = new BitmapDrawable (EmacsService.resources, | 135 | tileObject = new EmacsTileObject (stippleBitmap); |
| 139 | stippleBitmap); | ||
| 140 | tileObject.setTileModeXY (TileMode.REPEAT, TileMode.REPEAT); | 136 | tileObject.setTileModeXY (TileMode.REPEAT, TileMode.REPEAT); |
| 141 | } | 137 | } |
| 142 | else | 138 | else |
| @@ -144,11 +140,8 @@ public final class EmacsGC extends EmacsHandleObject | |||
| 144 | bitmap. */ | 140 | bitmap. */ |
| 145 | tileObject.setBitmap (stippleBitmap); | 141 | tileObject.setBitmap (stippleBitmap); |
| 146 | } | 142 | } |
| 147 | else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S | ||
| 148 | && tileObject != null) | ||
| 149 | tileObject.setBitmap (null); | ||
| 150 | else if (tileObject != null) | 143 | else if (tileObject != null) |
| 151 | tileObject = null; | 144 | tileObject.setBitmap (null); |
| 152 | } | 145 | } |
| 153 | 146 | ||
| 154 | /* Prepare the tile object to draw a stippled image onto a section of | 147 | /* 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 index 00000000000..34a35e83bfb --- /dev/null +++ b/java/org/gnu/emacs/EmacsTileObject.java | |||
| @@ -0,0 +1,101 @@ | |||
| 1 | /* Communication module for Android terminals. -*- c-file-style: "GNU" -*- | ||
| 2 | |||
| 3 | Copyright (C) 2023-2024 Free Software Foundation, Inc. | ||
| 4 | |||
| 5 | This file is part of GNU Emacs. | ||
| 6 | |||
| 7 | GNU Emacs is free software: you can redistribute it and/or modify | ||
| 8 | it under the terms of the GNU General Public License as published by | ||
| 9 | the Free Software Foundation, either version 3 of the License, or (at | ||
| 10 | your option) any later version. | ||
| 11 | |||
| 12 | GNU Emacs is distributed in the hope that it will be useful, | ||
| 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 15 | GNU General Public License for more details. | ||
| 16 | |||
| 17 | You should have received a copy of the GNU General Public License | ||
| 18 | along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>. */ | ||
| 19 | |||
| 20 | package org.gnu.emacs; | ||
| 21 | |||
| 22 | import android.graphics.Bitmap; | ||
| 23 | import android.graphics.BitmapShader; | ||
| 24 | import android.graphics.Canvas; | ||
| 25 | import android.graphics.ColorFilter; | ||
| 26 | import android.graphics.Paint; | ||
| 27 | import android.graphics.Rect; | ||
| 28 | import android.graphics.Shader.TileMode; | ||
| 29 | |||
| 30 | /* This is a crude facsimilie of the BitmapDrawable class implementing | ||
| 31 | just enough of its functionality to support displaying stipples in | ||
| 32 | EmacsGC. */ | ||
| 33 | |||
| 34 | public final class EmacsTileObject | ||
| 35 | { | ||
| 36 | /* Color filter object set by EmacsGC. */ | ||
| 37 | private ColorFilter colorFilter; | ||
| 38 | |||
| 39 | /* Bitmap object set by EmacsGC. */ | ||
| 40 | private Bitmap bitmap; | ||
| 41 | |||
| 42 | /* Tiling modes on either axis. */ | ||
| 43 | private TileMode xTile, yTile; | ||
| 44 | |||
| 45 | /* Destination rectangle. */ | ||
| 46 | private Rect boundsRect; | ||
| 47 | |||
| 48 | /* Paint providing graphics properties for drawBitmap. */ | ||
| 49 | private Paint paint; | ||
| 50 | |||
| 51 | |||
| 52 | |||
| 53 | public | ||
| 54 | EmacsTileObject (Bitmap stippleBitmap) | ||
| 55 | { | ||
| 56 | bitmap = stippleBitmap; | ||
| 57 | paint = new Paint (); | ||
| 58 | } | ||
| 59 | |||
| 60 | public void | ||
| 61 | setBitmap (Bitmap newBitmap) | ||
| 62 | { | ||
| 63 | bitmap = newBitmap; | ||
| 64 | } | ||
| 65 | |||
| 66 | public void | ||
| 67 | setBounds (Rect bounds) | ||
| 68 | { | ||
| 69 | boundsRect = bounds; | ||
| 70 | } | ||
| 71 | |||
| 72 | public void | ||
| 73 | setTileModeXY (TileMode newXTile, TileMode newYTile) | ||
| 74 | { | ||
| 75 | xTile = newXTile; | ||
| 76 | yTile = newYTile; | ||
| 77 | } | ||
| 78 | |||
| 79 | public void | ||
| 80 | setColorFilter (ColorFilter filterObject) | ||
| 81 | { | ||
| 82 | paint.setColorFilter (filterObject); | ||
| 83 | } | ||
| 84 | |||
| 85 | public Bitmap | ||
| 86 | getBitmap () | ||
| 87 | { | ||
| 88 | return bitmap; | ||
| 89 | } | ||
| 90 | |||
| 91 | /* Replicate `bitmap' over CANVAS so that boundsRect is covered with | ||
| 92 | copies thereof on the X axis, if xTile is REPEAT, and also on the Y | ||
| 93 | axis, if yTile is a like value. */ | ||
| 94 | |||
| 95 | public void | ||
| 96 | draw (Canvas canvas) | ||
| 97 | { | ||
| 98 | paint.setShader (new BitmapShader (bitmap, xTile, yTile)); | ||
| 99 | canvas.drawRect (boundsRect, paint); | ||
| 100 | } | ||
| 101 | }; | ||