summaryrefslogtreecommitdiff
path: root/java/org/gnu/emacs/EmacsFillRectangle.java
diff options
context:
space:
mode:
authorPo Lu <luangruo@yahoo.com>2024-05-02 11:31:37 +0800
committerPo Lu <luangruo@yahoo.com>2024-05-02 11:31:37 +0800
commitb84fa71f8985284560bacda7d407e3559583844f (patch)
treed7ed4518760fe51795dce384bc9dfa0b4ed32faf /java/org/gnu/emacs/EmacsFillRectangle.java
parentd3e95fcae9078a0ea8fcb15a4aee417e6e546ee5 (diff)
Port visible bell to Android
* java/org/gnu/emacs/EmacsDrawRectangle.java (perform): Ignore GC_INVERT. * java/org/gnu/emacs/EmacsFillRectangle.java (EmacsFillRectangle) <invertFilter>: New variable. (perform): If the transfer mode is invert, copy the source to itself with invertFilter as the color filter. * java/org/gnu/emacs/EmacsGC.java (EmacsGC) <xorAlu, srcInAlu>: Delete now-redundant ALUs. (markDirty): Cease updating the paint's transfermode. * java/org/gnu/emacs/EmacsSafThread.java (openDocument1): Fix typo in documentation. * src/android.c (android_blit_xor): Delete unused function. (android_copy_area): Remove calls to unused blit functions. * src/androidgui.h (enum android_gc_function): Rename XOR to INVERT. * src/androidterm.c (android_flash): Replace with GXinvert.
Diffstat (limited to 'java/org/gnu/emacs/EmacsFillRectangle.java')
-rw-r--r--java/org/gnu/emacs/EmacsFillRectangle.java94
1 files changed, 34 insertions, 60 deletions
diff --git a/java/org/gnu/emacs/EmacsFillRectangle.java b/java/org/gnu/emacs/EmacsFillRectangle.java
index f338a54f97b..7642deed7c3 100644
--- a/java/org/gnu/emacs/EmacsFillRectangle.java
+++ b/java/org/gnu/emacs/EmacsFillRectangle.java
@@ -21,6 +21,8 @@ package org.gnu.emacs;
import android.graphics.Bitmap;
import android.graphics.Canvas;
+import android.graphics.ColorFilter;
+import android.graphics.ColorMatrixColorFilter;
import android.graphics.Paint;
import android.graphics.Rect;
@@ -28,30 +30,42 @@ import android.util.Log;
public final class EmacsFillRectangle
{
+ /* Color filter that inverts colors from the source. */
+ private static final ColorFilter invertFilter;
+
+ static
+ {
+ invertFilter = new ColorMatrixColorFilter (new float[] {
+ -1f, 0f, 0f, 0f, 255f,
+ 0f, -1f, 0f, 0f, 255f,
+ 0f, 0f, -1f, 0f, 255f,
+ 0f, 0f, 0f, 1f, 0f,
+ });
+ };
+
public static void
perform (EmacsDrawable drawable, EmacsGC gc,
int x, int y, int width, int height)
{
- Paint maskPaint, paint;
- Canvas maskCanvas;
- Bitmap maskBitmap;
+ Paint paint;
Rect rect;
- Rect maskRect, dstRect;
Canvas canvas;
- Bitmap clipBitmap;
+ Bitmap invertBitmap;
canvas = drawable.lockCanvas (gc);
- if (canvas == null)
+ /* Clip masks are not respected or implemented when specified with
+ this request. */
+ if (canvas == null || gc.clip_mask != null)
return;
rect = new Rect (x, y, x + width, y + height);
- paint = gc.gcPaint;
- paint.setStyle (Paint.Style.FILL);
-
- if (gc.clip_mask == null)
+ if (gc.function != EmacsGC.GC_INVERT)
{
+ paint = gc.gcPaint;
+ paint.setStyle (Paint.Style.FILL);
+
if (gc.fill_style != EmacsGC.GC_FILL_OPAQUE_STIPPLED)
canvas.drawRect (rect, paint);
else
@@ -59,57 +73,17 @@ public final class EmacsFillRectangle
}
else
{
- /* Drawing with a clip mask involves calculating the
- intersection of the clip mask with the dst rect, and
- extrapolating the corresponding part of the src rect. */
-
- clipBitmap = gc.clip_mask.bitmap;
- dstRect = new Rect (x, y, x + width, y + height);
- maskRect = new Rect (gc.clip_x_origin,
- gc.clip_y_origin,
- (gc.clip_x_origin
- + clipBitmap.getWidth ()),
- (gc.clip_y_origin
- + clipBitmap.getHeight ()));
-
- if (!maskRect.setIntersect (dstRect, maskRect))
- /* There is no intersection between the clip mask and the
- dest rect. */
- return;
-
- /* Finally, create a temporary bitmap that is the size of
- maskRect. */
-
- maskBitmap
- = Bitmap.createBitmap (maskRect.width (), maskRect.height (),
- Bitmap.Config.ARGB_8888);
-
- /* Draw the mask onto the maskBitmap. */
- maskCanvas = new Canvas (maskBitmap);
- maskRect.offset (-gc.clip_x_origin,
- -gc.clip_y_origin);
- maskCanvas.drawBitmap (gc.clip_mask.bitmap,
- maskRect, new Rect (0, 0,
- maskRect.width (),
- maskRect.height ()),
- paint);
- maskRect.offset (gc.clip_x_origin,
- gc.clip_y_origin);
-
- /* Set the transfer mode to SRC_IN to preserve only the parts
- of the source that overlap with the mask. */
- maskPaint = new Paint ();
- maskPaint.setXfermode (EmacsGC.srcInAlu);
-
- /* Draw the source. */
- maskCanvas.drawRect (maskRect, maskPaint);
-
- /* Finally, draw the mask bitmap to the destination. */
- paint.setXfermode (null);
- canvas.drawBitmap (maskBitmap, null, maskRect, paint);
+ paint = new Paint ();
- /* Recycle this unused bitmap. */
- maskBitmap.recycle ();
+ /* Simply invert the destination, which is only implemented for
+ this request. As Android doesn't permit copying a bitmap to
+ itself, a copy of the source must be procured beforehand. */
+ invertBitmap = Bitmap.createBitmap (drawable.getBitmap (),
+ x, y, width, height);
+ paint.setColorFilter (invertFilter);
+ canvas.drawBitmap (invertBitmap, null, rect, paint);
+ paint.setColorFilter (null);
+ invertBitmap.recycle ();
}
drawable.damageRect (rect);