This source file includes following definitions.
- copyToFrontBuffer
- reconfigureFrontBuffer
- setBitmap
- onDraw
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 android.view.View;
23
24 import android.os.Build;
25
26 import android.graphics.Bitmap;
27 import android.graphics.Canvas;
28 import android.graphics.Rect;
29 import android.graphics.Paint;
30
31 import java.lang.ref.WeakReference;
32
33
34
35
36
37
38 public final class EmacsSurfaceView extends View
39 {
40 private static final String TAG = "EmacsSurfaceView";
41
42
43 private Bitmap frontBuffer;
44
45
46
47 private boolean bitmapChanged;
48
49
50 private Canvas bitmapCanvas;
51
52
53 private WeakReference<Bitmap> bitmap;
54
55
56 private static final Paint bitmapPaint, uiThreadPaint;
57
58 static
59 {
60
61
62
63
64
65 bitmapPaint = new Paint ();
66 uiThreadPaint = new Paint ();
67 };
68
69 public
70 EmacsSurfaceView (EmacsView view)
71 {
72 super (view.getContext ());
73
74 this.bitmap = new WeakReference<Bitmap> (null);
75 }
76
77 private void
78 copyToFrontBuffer (Bitmap bitmap, Rect damageRect)
79 {
80 EmacsService.checkEmacsThread ();
81
82 if (Build.VERSION.SDK_INT != Build.VERSION_CODES.O
83 && Build.VERSION.SDK_INT != Build.VERSION_CODES.O_MR1
84 && Build.VERSION.SDK_INT != Build.VERSION_CODES.N_MR1
85 && Build.VERSION.SDK_INT != Build.VERSION_CODES.N)
86 {
87
88
89
90 if (damageRect != null)
91 bitmapCanvas.drawBitmap (bitmap, damageRect, damageRect,
92 bitmapPaint);
93 else
94 bitmapCanvas.drawBitmap (bitmap, 0f, 0f, bitmapPaint);
95 }
96 else
97 {
98
99
100
101 if (damageRect != null)
102 EmacsNative.blitRect (bitmap, frontBuffer,
103 damageRect.left,
104 damageRect.top,
105 damageRect.right,
106 damageRect.bottom);
107 else
108 EmacsNative.blitRect (bitmap, frontBuffer, 0, 0,
109 bitmap.getWidth (),
110 bitmap.getHeight ());
111 }
112
113
114 bitmapChanged = true;
115 }
116
117 private void
118 reconfigureFrontBuffer (Bitmap bitmap)
119 {
120
121
122 if (frontBuffer != null)
123 {
124 frontBuffer.recycle ();
125 frontBuffer = null;
126 bitmapCanvas = null;
127 }
128
129 this.bitmap = new WeakReference<Bitmap> (bitmap);
130
131
132
133 if (bitmap != null && frontBuffer == null)
134 {
135 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O)
136 frontBuffer = Bitmap.createBitmap (bitmap.getWidth (),
137 bitmap.getHeight (),
138 Bitmap.Config.ARGB_8888,
139 false);
140 else
141 frontBuffer = Bitmap.createBitmap (bitmap.getWidth (),
142 bitmap.getHeight (),
143 Bitmap.Config.ARGB_8888);
144
145 bitmapCanvas = new Canvas (frontBuffer);
146
147
148 copyToFrontBuffer (bitmap, null);
149 }
150 else if (bitmap != null)
151
152 copyToFrontBuffer (bitmap, null);
153 }
154
155 public synchronized void
156 setBitmap (Bitmap bitmap, Rect damageRect)
157 {
158 if (bitmap != this.bitmap.get ())
159 reconfigureFrontBuffer (bitmap);
160 else if (bitmap != null)
161 copyToFrontBuffer (bitmap, damageRect);
162
163 if (bitmap != null)
164 {
165
166
167
168
169
170
171
172
173 if (damageRect != null)
174 postInvalidate (damageRect.left, damageRect.top,
175 damageRect.right, damageRect.bottom);
176 else
177 postInvalidate ();
178 }
179 }
180
181 @Override
182 public synchronized void
183 onDraw (Canvas canvas)
184 {
185
186
187
188 if (frontBuffer != null)
189 {
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214 if (bitmapChanged)
215 {
216 EmacsNative.notifyPixelsChanged (frontBuffer);
217 bitmapChanged = false;
218 }
219
220 canvas.drawBitmap (frontBuffer, 0f, 0f, uiThreadPaint);
221 }
222 }
223 };