aboutsummaryrefslogtreecommitdiffstats
path: root/java
diff options
context:
space:
mode:
Diffstat (limited to 'java')
-rw-r--r--java/org/gnu/emacs/EmacsDrawRectangle.java18
-rw-r--r--java/org/gnu/emacs/EmacsFillRectangle.java96
-rw-r--r--java/org/gnu/emacs/EmacsGC.java16
-rw-r--r--java/org/gnu/emacs/EmacsSafThread.java8
4 files changed, 56 insertions, 82 deletions
diff --git a/java/org/gnu/emacs/EmacsDrawRectangle.java b/java/org/gnu/emacs/EmacsDrawRectangle.java
index e40a7c16068..ea0f1c28106 100644
--- a/java/org/gnu/emacs/EmacsDrawRectangle.java
+++ b/java/org/gnu/emacs/EmacsDrawRectangle.java
@@ -22,13 +22,23 @@ package org.gnu.emacs;
22import android.graphics.Bitmap; 22import android.graphics.Bitmap;
23import android.graphics.Canvas; 23import android.graphics.Canvas;
24import android.graphics.Paint; 24import android.graphics.Paint;
25import android.graphics.PorterDuff.Mode;
26import android.graphics.PorterDuffXfermode;
25import android.graphics.Rect; 27import android.graphics.Rect;
26import android.graphics.RectF; 28import android.graphics.RectF;
29import android.graphics.Xfermode;
27 30
28import android.util.Log; 31import android.util.Log;
29 32
30public final class EmacsDrawRectangle 33public final class EmacsDrawRectangle
31{ 34{
35 private static final Xfermode srcInAlu;
36
37 static
38 {
39 srcInAlu = new PorterDuffXfermode (Mode.SRC_IN);
40 };
41
32 public static void 42 public static void
33 perform (EmacsDrawable drawable, EmacsGC gc, 43 perform (EmacsDrawable drawable, EmacsGC gc,
34 int x, int y, int width, int height) 44 int x, int y, int width, int height)
@@ -40,8 +50,10 @@ public final class EmacsDrawRectangle
40 Canvas canvas; 50 Canvas canvas;
41 Bitmap clipBitmap; 51 Bitmap clipBitmap;
42 52
43 /* TODO implement stippling. */ 53 /* TODO implement stippling for this request. */
44 if (gc.fill_style == EmacsGC.GC_FILL_OPAQUE_STIPPLED) 54 if (gc.fill_style == EmacsGC.GC_FILL_OPAQUE_STIPPLED
55 /* And GC_INVERT also. */
56 || gc.fill_style == EmacsGC.GC_INVERT)
45 return; 57 return;
46 58
47 canvas = drawable.lockCanvas (gc); 59 canvas = drawable.lockCanvas (gc);
@@ -103,7 +115,7 @@ public final class EmacsDrawRectangle
103 /* Set the transfer mode to SRC_IN to preserve only the parts 115 /* Set the transfer mode to SRC_IN to preserve only the parts
104 of the source that overlap with the mask. */ 116 of the source that overlap with the mask. */
105 maskPaint = new Paint (); 117 maskPaint = new Paint ();
106 maskPaint.setXfermode (EmacsGC.srcInAlu); 118 maskPaint.setXfermode (srcInAlu);
107 maskPaint.setStyle (Paint.Style.STROKE); 119 maskPaint.setStyle (Paint.Style.STROKE);
108 120
109 /* Draw the source. */ 121 /* Draw the source. */
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;
21 21
22import android.graphics.Bitmap; 22import android.graphics.Bitmap;
23import android.graphics.Canvas; 23import android.graphics.Canvas;
24import android.graphics.ColorFilter;
25import android.graphics.ColorMatrixColorFilter;
24import android.graphics.Paint; 26import android.graphics.Paint;
25import android.graphics.Rect; 27import android.graphics.Rect;
26 28
@@ -28,30 +30,42 @@ import android.util.Log;
28 30
29public final class EmacsFillRectangle 31public final class EmacsFillRectangle
30{ 32{
33 /* Color filter that inverts colors from the source. */
34 private static final ColorFilter invertFilter;
35
36 static
37 {
38 invertFilter = new ColorMatrixColorFilter (new float[] {
39 -1f, 0f, 0f, 0f, 255f,
40 0f, -1f, 0f, 0f, 255f,
41 0f, 0f, -1f, 0f, 255f,
42 0f, 0f, 0f, 1f, 0f,
43 });
44 };
45
31 public static void 46 public static void
32 perform (EmacsDrawable drawable, EmacsGC gc, 47 perform (EmacsDrawable drawable, EmacsGC gc,
33 int x, int y, int width, int height) 48 int x, int y, int width, int height)
34 { 49 {
35 Paint maskPaint, paint; 50 Paint paint;
36 Canvas maskCanvas;
37 Bitmap maskBitmap;
38 Rect rect; 51 Rect rect;
39 Rect maskRect, dstRect;
40 Canvas canvas; 52 Canvas canvas;
41 Bitmap clipBitmap; 53 Bitmap invertBitmap;
42 54
43 canvas = drawable.lockCanvas (gc); 55 canvas = drawable.lockCanvas (gc);
44 56
45 if (canvas == null) 57 /* Clip masks are not respected or implemented when specified with
58 this request. */
59 if (canvas == null || gc.clip_mask != null)
46 return; 60 return;
47 61
48 rect = new Rect (x, y, x + width, y + height); 62 rect = new Rect (x, y, x + width, y + height);
49 63
50 paint = gc.gcPaint; 64 if (gc.function != EmacsGC.GC_INVERT)
51 paint.setStyle (Paint.Style.FILL);
52
53 if (gc.clip_mask == null)
54 { 65 {
66 paint = gc.gcPaint;
67 paint.setStyle (Paint.Style.FILL);
68
55 if (gc.fill_style != EmacsGC.GC_FILL_OPAQUE_STIPPLED) 69 if (gc.fill_style != EmacsGC.GC_FILL_OPAQUE_STIPPLED)
56 canvas.drawRect (rect, paint); 70 canvas.drawRect (rect, paint);
57 else 71 else
@@ -59,57 +73,17 @@ public final class EmacsFillRectangle
59 } 73 }
60 else 74 else
61 { 75 {
62 /* Drawing with a clip mask involves calculating the 76 paint = new Paint ();
63 intersection of the clip mask with the dst rect, and 77
64 extrapolating the corresponding part of the src rect. */ 78 /* Simply invert the destination, which is only implemented for
65 79 this request. As Android doesn't permit copying a bitmap to
66 clipBitmap = gc.clip_mask.bitmap; 80 itself, a copy of the source must be procured beforehand. */
67 dstRect = new Rect (x, y, x + width, y + height); 81 invertBitmap = Bitmap.createBitmap (drawable.getBitmap (),
68 maskRect = new Rect (gc.clip_x_origin, 82 x, y, width, height);
69 gc.clip_y_origin, 83 paint.setColorFilter (invertFilter);
70 (gc.clip_x_origin 84 canvas.drawBitmap (invertBitmap, null, rect, paint);
71 + clipBitmap.getWidth ()), 85 paint.setColorFilter (null);
72 (gc.clip_y_origin 86 invertBitmap.recycle ();
73 + clipBitmap.getHeight ()));
74
75 if (!maskRect.setIntersect (dstRect, maskRect))
76 /* There is no intersection between the clip mask and the
77 dest rect. */
78 return;
79
80 /* Finally, create a temporary bitmap that is the size of
81 maskRect. */
82
83 maskBitmap
84 = Bitmap.createBitmap (maskRect.width (), maskRect.height (),
85 Bitmap.Config.ARGB_8888);
86
87 /* Draw the mask onto the maskBitmap. */
88 maskCanvas = new Canvas (maskBitmap);
89 maskRect.offset (-gc.clip_x_origin,
90 -gc.clip_y_origin);
91 maskCanvas.drawBitmap (gc.clip_mask.bitmap,
92 maskRect, new Rect (0, 0,
93 maskRect.width (),
94 maskRect.height ()),
95 paint);
96 maskRect.offset (gc.clip_x_origin,
97 gc.clip_y_origin);
98
99 /* Set the transfer mode to SRC_IN to preserve only the parts
100 of the source that overlap with the mask. */
101 maskPaint = new Paint ();
102 maskPaint.setXfermode (EmacsGC.srcInAlu);
103
104 /* Draw the source. */
105 maskCanvas.drawRect (maskRect, maskPaint);
106
107 /* Finally, draw the mask bitmap to the destination. */
108 paint.setXfermode (null);
109 canvas.drawBitmap (maskBitmap, null, maskRect, paint);
110
111 /* Recycle this unused bitmap. */
112 maskBitmap.recycle ();
113 } 87 }
114 88
115 drawable.damageRect (rect); 89 drawable.damageRect (rect);
diff --git a/java/org/gnu/emacs/EmacsGC.java b/java/org/gnu/emacs/EmacsGC.java
index ec2b9c9e475..bb11f76c800 100644
--- a/java/org/gnu/emacs/EmacsGC.java
+++ b/java/org/gnu/emacs/EmacsGC.java
@@ -27,9 +27,7 @@ import android.graphics.Canvas;
27import android.graphics.ColorFilter; 27import android.graphics.ColorFilter;
28import android.graphics.PorterDuff.Mode; 28import android.graphics.PorterDuff.Mode;
29import android.graphics.PorterDuffColorFilter; 29import android.graphics.PorterDuffColorFilter;
30import android.graphics.PorterDuffXfermode;
31import android.graphics.Shader.TileMode; 30import android.graphics.Shader.TileMode;
32import android.graphics.Xfermode;
33 31
34import android.graphics.drawable.BitmapDrawable; 32import android.graphics.drawable.BitmapDrawable;
35 33
@@ -40,8 +38,8 @@ import android.os.Build;
40 38
41public final class EmacsGC extends EmacsHandleObject 39public final class EmacsGC extends EmacsHandleObject
42{ 40{
43 public static final int GC_COPY = 0; 41 public static final int GC_COPY = 0;
44 public static final int GC_XOR = 1; 42 public static final int GC_INVERT = 1;
45 43
46 public static final int GC_FILL_SOLID = 0; 44 public static final int GC_FILL_SOLID = 0;
47 public static final int GC_FILL_OPAQUE_STIPPLED = 1; 45 public static final int GC_FILL_OPAQUE_STIPPLED = 1;
@@ -49,8 +47,6 @@ public final class EmacsGC extends EmacsHandleObject
49 public static final int GC_LINE_SOLID = 0; 47 public static final int GC_LINE_SOLID = 0;
50 public static final int GC_LINE_ON_OFF_DASH = 1; 48 public static final int GC_LINE_ON_OFF_DASH = 1;
51 49
52 public static final Xfermode xorAlu, srcInAlu;
53
54 public int function, fill_style; 50 public int function, fill_style;
55 public int foreground, background; 51 public int foreground, background;
56 public int clip_x_origin, clip_y_origin; 52 public int clip_x_origin, clip_y_origin;
@@ -72,12 +68,6 @@ public final class EmacsGC extends EmacsHandleObject
72 rectangles changed. 0 if there are no clip rectangles. */ 68 rectangles changed. 0 if there are no clip rectangles. */
73 public long clipRectID; 69 public long clipRectID;
74 70
75 static
76 {
77 xorAlu = new PorterDuffXfermode (Mode.XOR);
78 srcInAlu = new PorterDuffXfermode (Mode.SRC_IN);
79 }
80
81 /* The following fields are only set on immutable GCs. */ 71 /* The following fields are only set on immutable GCs. */
82 72
83 public 73 public
@@ -131,8 +121,6 @@ public final class EmacsGC extends EmacsHandleObject
131 /* A line_width of 0 is equivalent to that of 1. */ 121 /* A line_width of 0 is equivalent to that of 1. */
132 gcPaint.setStrokeWidth (line_width < 1 ? 1 : line_width); 122 gcPaint.setStrokeWidth (line_width < 1 ? 1 : line_width);
133 gcPaint.setColor (foreground | 0xff000000); 123 gcPaint.setColor (foreground | 0xff000000);
134 gcPaint.setXfermode (function == GC_XOR
135 ? xorAlu : srcInAlu);
136 124
137 /* Update the stipple object with the new stipple bitmap, or delete 125 /* Update the stipple object with the new stipple bitmap, or delete
138 it if the stipple has been cleared on systems too old to support 126 it if the stipple has been cleared on systems too old to support
diff --git a/java/org/gnu/emacs/EmacsSafThread.java b/java/org/gnu/emacs/EmacsSafThread.java
index 14c3f222833..ee8c2e7e0c3 100644
--- a/java/org/gnu/emacs/EmacsSafThread.java
+++ b/java/org/gnu/emacs/EmacsSafThread.java
@@ -1623,10 +1623,10 @@ public final class EmacsSafThread extends HandlerThread
1623 mode is merely w. 1623 mode is merely w.
1624 1624
1625 This may be ascribed to a mix-up in Android's documentation 1625 This may be ascribed to a mix-up in Android's documentation
1626 regardin DocumentsProvider: the `openDocument' function is only 1626 regarding DocumentsProvider: the `openDocument' function is only
1627 documented to accept r or rw, whereas the default 1627 documented to accept r or rw, whereas the default implementation
1628 implementation of the `openFile' function (which documents rwt) 1628 of the `openFile' function (which documents rwt) delegates to
1629 delegates to `openDocument'. */ 1629 `openDocument'. */
1630 1630
1631 if (read && write && truncate && fileDescriptor != null 1631 if (read && write && truncate && fileDescriptor != null
1632 && !EmacsNative.ftruncate (fileDescriptor.getFd ())) 1632 && !EmacsNative.ftruncate (fileDescriptor.getFd ()))