This source file includes following definitions.
- lockCanvas
- damageRect
- getBitmap
- destroyHandle
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.gnu.emacs;
21
22 import java.lang.IllegalArgumentException;
23
24 import android.graphics.Bitmap;
25 import android.graphics.Canvas;
26 import android.graphics.Rect;
27
28 import android.os.Build;
29
30
31
32 public final class EmacsPixmap extends EmacsHandleObject
33 implements EmacsDrawable
34 {
35
36
37 public int depth, width, height;
38
39
40 public Bitmap bitmap;
41
42
43 public Canvas canvas;
44
45
46
47 private boolean needCollect;
48
49
50
51 private long gcClipRectID;
52
53 public
54 EmacsPixmap (short handle, int colors[], int width,
55 int height, int depth)
56 {
57 super (handle);
58
59 if (depth != 1 && depth != 24)
60 throw new IllegalArgumentException ("Invalid depth specified"
61 + " for pixmap: " + depth);
62
63 switch (depth)
64 {
65 case 1:
66 bitmap = Bitmap.createBitmap (colors, width, height,
67 Bitmap.Config.ALPHA_8);
68 break;
69
70 case 24:
71 bitmap = Bitmap.createBitmap (colors, width, height,
72 Bitmap.Config.ARGB_8888);
73 bitmap.setHasAlpha (false);
74 break;
75 }
76
77 this.width = width;
78 this.height = height;
79 this.depth = depth;
80 }
81
82 public
83 EmacsPixmap (short handle, int width, int height, int depth)
84 {
85 super (handle);
86
87 if (depth != 1 && depth != 24)
88 throw new IllegalArgumentException ("Invalid depth specified"
89 + " for pixmap: " + depth);
90
91 switch (depth)
92 {
93 case 1:
94 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O)
95 bitmap = Bitmap.createBitmap (width, height,
96 Bitmap.Config.ALPHA_8,
97 false);
98 else
99 bitmap = Bitmap.createBitmap (width, height,
100 Bitmap.Config.ALPHA_8);
101 break;
102
103 case 24:
104
105
106
107
108 if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O)
109 bitmap = Bitmap.createBitmap (width, height,
110 Bitmap.Config.ARGB_8888);
111 else
112 bitmap = Bitmap.createBitmap (width, height,
113 Bitmap.Config.ARGB_8888,
114 false);
115 break;
116 }
117
118 if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB_MR1)
119
120
121 needCollect = false;
122 else if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT)
123 needCollect = (bitmap.getByteCount ()
124 >= 1024 * 512);
125 else
126 needCollect = (bitmap.getAllocationByteCount ()
127 >= 1024 * 512);
128
129 bitmap.eraseColor (0xff000000);
130
131 this.width = width;
132 this.height = height;
133 this.depth = depth;
134 }
135
136 @Override
137 public Canvas
138 lockCanvas (EmacsGC gc)
139 {
140 int i;
141
142 if (canvas == null)
143 {
144 canvas = new Canvas (bitmap);
145 canvas.save ();
146 }
147
148
149 if (gc.clipRectID == gcClipRectID)
150 return canvas;
151
152
153 canvas.restore ();
154 canvas.save ();
155
156 if (gc.real_clip_rects != null)
157 {
158 for (i = 0; i < gc.real_clip_rects.length; ++i)
159 canvas.clipRect (gc.real_clip_rects[i]);
160 }
161
162
163 gcClipRectID = gc.clipRectID;
164 return canvas;
165 }
166
167 @Override
168 public void
169 damageRect (Rect damageRect)
170 {
171
172 }
173
174 @Override
175 public Bitmap
176 getBitmap ()
177 {
178 return bitmap;
179 }
180
181 @Override
182 public void
183 destroyHandle ()
184 {
185 bitmap.recycle ();
186 bitmap = null;
187
188
189 if (needCollect)
190 Runtime.getRuntime ().gc ();
191 }
192 };