GLES20Canvas.java revision bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4
1/*
2 * Copyright (C) 2010 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package android.view;
18
19import android.graphics.Bitmap;
20import android.graphics.Canvas;
21import android.graphics.DrawFilter;
22import android.graphics.Matrix;
23import android.graphics.Paint;
24import android.graphics.Path;
25import android.graphics.Picture;
26import android.graphics.PorterDuff;
27import android.graphics.Rect;
28import android.graphics.RectF;
29import android.graphics.Region;
30
31import javax.microedition.khronos.opengles.GL;
32
33/**
34 * An implementation of Canvas on top of OpenGL ES 2.0.
35 */
36@SuppressWarnings({"deprecation"})
37class GLES20Canvas extends Canvas {
38    @SuppressWarnings({"FieldCanBeLocal", "UnusedDeclaration"})
39    private final GL mGl;
40    private final boolean mOpaque;
41    private final int mRenderer;
42
43    private int mWidth;
44    private int mHeight;
45
46    ///////////////////////////////////////////////////////////////////////////
47    // Constructors
48    ///////////////////////////////////////////////////////////////////////////
49
50    GLES20Canvas(GL gl, boolean translucent) {
51        mGl = gl;
52        mOpaque = !translucent;
53
54        mRenderer = nCreateRenderer();
55    }
56
57    private native int nCreateRenderer();
58
59    @Override
60    protected void finalize() throws Throwable {
61        try {
62            super.finalize();
63        } finally {
64            nDestroyRenderer(mRenderer);
65        }
66    }
67
68    private native void nDestroyRenderer(int renderer);
69
70    ///////////////////////////////////////////////////////////////////////////
71    // Canvas management
72    ///////////////////////////////////////////////////////////////////////////
73
74    @Override
75    public boolean isHardwareAccelerated() {
76        return true;
77    }
78
79    @Override
80    public GL getGL() {
81        throw new UnsupportedOperationException();
82    }
83
84    @Override
85    public void setBitmap(Bitmap bitmap) {
86        throw new UnsupportedOperationException();
87    }
88
89    @Override
90    public boolean isOpaque() {
91        return mOpaque;
92    }
93
94    @Override
95    public int getWidth() {
96        return mWidth;
97    }
98
99    @Override
100    public int getHeight() {
101        return mHeight;
102    }
103
104    ///////////////////////////////////////////////////////////////////////////
105    // Setup
106    ///////////////////////////////////////////////////////////////////////////
107
108    @Override
109    public void setViewport(int width, int height) {
110        mWidth = width;
111        mHeight = height;
112
113        nSetViewport(mRenderer, width, height);
114    }
115
116    private native void nSetViewport(int renderer, int width, int height);
117
118    void onPreDraw() {
119        nPrepare(mRenderer);
120    }
121
122    private native void nPrepare(int renderer);
123
124    ///////////////////////////////////////////////////////////////////////////
125    // Clipping
126    ///////////////////////////////////////////////////////////////////////////
127
128    @Override
129    public boolean clipPath(Path path) {
130        throw new UnsupportedOperationException();
131    }
132
133    @Override
134    public boolean clipPath(Path path, Region.Op op) {
135        throw new UnsupportedOperationException();
136    }
137
138    @Override
139    public boolean clipRect(float left, float top, float right, float bottom) {
140        return nClipRect(mRenderer, left, top, right, bottom);
141    }
142
143    private native boolean nClipRect(int renderer, float left, float top, float right, float bottom);
144
145    @Override
146    public boolean clipRect(float left, float top, float right, float bottom, Region.Op op) {
147        throw new UnsupportedOperationException();
148    }
149
150    @Override
151    public boolean clipRect(int left, int top, int right, int bottom) {
152        return nClipRect(mRenderer, left, top, right, bottom);
153    }
154
155    private native boolean nClipRect(int renderer, int left, int top, int right, int bottom);
156
157    @Override
158    public boolean clipRect(Rect rect) {
159        return clipRect(rect.left, rect.top, rect.right, rect.bottom);
160    }
161
162    @Override
163    public boolean clipRect(Rect rect, Region.Op op) {
164        throw new UnsupportedOperationException();
165    }
166
167    @Override
168    public boolean clipRect(RectF rect) {
169        return clipRect(rect.left, rect.top, rect.right, rect.bottom);
170    }
171
172    @Override
173    public boolean clipRect(RectF rect, Region.Op op) {
174        throw new UnsupportedOperationException();
175    }
176
177    @Override
178    public boolean clipRegion(Region region) {
179        throw new UnsupportedOperationException();
180    }
181
182    @Override
183    public boolean clipRegion(Region region, Region.Op op) {
184        throw new UnsupportedOperationException();
185    }
186
187    @Override
188    public boolean getClipBounds(Rect bounds) {
189        // TODO: Implement
190        return false;
191    }
192
193    @Override
194    public boolean quickReject(float left, float top, float right, float bottom, EdgeType type) {
195        // TODO: Implement
196        return false;
197    }
198
199    @Override
200    public boolean quickReject(Path path, EdgeType type) {
201        throw new UnsupportedOperationException();
202    }
203
204    @Override
205    public boolean quickReject(RectF rect, EdgeType type) {
206        return quickReject(rect.left, rect.top, rect.right, rect.bottom, type);
207    }
208
209    ///////////////////////////////////////////////////////////////////////////
210    // Transformations
211    ///////////////////////////////////////////////////////////////////////////
212
213    @Override
214    public void translate(float dx, float dy) {
215        // TODO: Implement
216    }
217
218    @Override
219    public void skew(float sx, float sy) {
220        throw new UnsupportedOperationException();
221    }
222
223    @Override
224    public void rotate(float degrees) {
225        // TODO: Implement
226    }
227
228    @Override
229    public void scale(float sx, float sy) {
230        // TODO: Implement
231    }
232
233
234    @Override
235    public void setMatrix(Matrix matrix) {
236        // TODO: Implement
237    }
238
239    @Override
240    public void getMatrix(Matrix ctm) {
241        // TODO: Implement
242    }
243
244    @Override
245    public void concat(Matrix matrix) {
246        // TODO: Implement
247    }
248
249    ///////////////////////////////////////////////////////////////////////////
250    // State management
251    ///////////////////////////////////////////////////////////////////////////
252
253    @Override
254    public int save() {
255        return nSave(mRenderer, 0);
256    }
257
258    @Override
259    public int save(int saveFlags) {
260        return nSave(mRenderer, saveFlags);
261    }
262
263    private native int nSave(int renderer, int flags);
264
265    @Override
266    public int saveLayer(RectF bounds, Paint paint, int saveFlags) {
267        // TODO: Implement
268        return 0;
269    }
270
271    @Override
272    public int saveLayer(float left, float top, float right, float bottom, Paint paint,
273            int saveFlags) {
274        // TODO: Implement
275        return 0;
276    }
277
278    @Override
279    public int saveLayerAlpha(RectF bounds, int alpha, int saveFlags) {
280        // TODO: Implement
281        return 0;
282    }
283
284    @Override
285    public int saveLayerAlpha(float left, float top, float right, float bottom, int alpha,
286            int saveFlags) {
287        // TODO: Implement
288        return 0;
289    }
290
291    @Override
292    public void restore() {
293        nRestore(mRenderer);
294    }
295
296    private native void nRestore(int renderer);
297
298    @Override
299    public void restoreToCount(int saveCount) {
300        nRestoreToCount(mRenderer, saveCount);
301    }
302
303    private native void nRestoreToCount(int renderer, int saveCount);
304
305    @Override
306    public int getSaveCount() {
307        return nGetSaveCount(mRenderer);
308    }
309
310    private native int nGetSaveCount(int renderer);
311
312    ///////////////////////////////////////////////////////////////////////////
313    // Filtering
314    ///////////////////////////////////////////////////////////////////////////
315
316    @Override
317    public void setDrawFilter(DrawFilter filter) {
318        throw new UnsupportedOperationException();
319    }
320
321    @Override
322    public DrawFilter getDrawFilter() {
323        throw new UnsupportedOperationException();
324    }
325
326    ///////////////////////////////////////////////////////////////////////////
327    // Drawing
328    ///////////////////////////////////////////////////////////////////////////
329
330    @Override
331    public void drawArc(RectF oval, float startAngle, float sweepAngle, boolean useCenter,
332            Paint paint) {
333        throw new UnsupportedOperationException();
334    }
335
336    @Override
337    public void drawARGB(int a, int r, int g, int b) {
338        drawColor((a & 0xFF) << 24 | (r & 0xFF) << 16 | (g & 0xFF) << 8 | (b & 0xFF));
339    }
340
341    @Override
342    public void drawBitmap(Bitmap bitmap, float left, float top, Paint paint) {
343        // TODO: Implement
344    }
345
346    @Override
347    public void drawBitmap(Bitmap bitmap, Matrix matrix, Paint paint) {
348        // TODO: Implement
349    }
350
351    @Override
352    public void drawBitmap(Bitmap bitmap, Rect src, Rect dst, Paint paint) {
353        // TODO: Implement
354    }
355
356    @Override
357    public void drawBitmap(Bitmap bitmap, Rect src, RectF dst, Paint paint) {
358        // TODO: Implement
359    }
360
361    @Override
362    public void drawBitmap(int[] colors, int offset, int stride, float x, float y,
363            int width, int height, boolean hasAlpha, Paint paint) {
364
365        // TODO: Implement
366    }
367
368    @Override
369    public void drawBitmap(int[] colors, int offset, int stride, int x, int y,
370            int width, int height, boolean hasAlpha, Paint paint) {
371
372        // TODO: Implement
373    }
374
375    @Override
376    public void drawBitmapMesh(Bitmap bitmap, int meshWidth, int meshHeight, float[] verts,
377            int vertOffset, int[] colors, int colorOffset, Paint paint) {
378
379        throw new UnsupportedOperationException();
380    }
381
382    @Override
383    public void drawCircle(float cx, float cy, float radius, Paint paint) {
384        throw new UnsupportedOperationException();
385    }
386
387    @Override
388    public void drawColor(int color) {
389        drawColor(color, PorterDuff.Mode.SRC_OVER);
390    }
391
392    @Override
393    public void drawColor(int color, PorterDuff.Mode mode) {
394        nDrawColor(mRenderer, color, mode.nativeInt);
395    }
396
397    private native void nDrawColor(int renderer, int color, int mode);
398
399    @Override
400    public void drawLine(float startX, float startY, float stopX, float stopY, Paint paint) {
401        // TODO: Implement
402    }
403
404    @Override
405    public void drawLines(float[] pts, int offset, int count, Paint paint) {
406        // TODO: Implement
407    }
408
409    @Override
410    public void drawLines(float[] pts, Paint paint) {
411        // TODO: Implement
412    }
413
414    @Override
415    public void drawOval(RectF oval, Paint paint) {
416        throw new UnsupportedOperationException();
417    }
418
419    @Override
420    public void drawPaint(Paint paint) {
421        // TODO: Implement
422    }
423
424    @Override
425    public void drawPath(Path path, Paint paint) {
426        throw new UnsupportedOperationException();
427    }
428
429    @Override
430    public void drawPicture(Picture picture) {
431        throw new UnsupportedOperationException();
432    }
433
434    @Override
435    public void drawPicture(Picture picture, Rect dst) {
436        throw new UnsupportedOperationException();
437    }
438
439    @Override
440    public void drawPicture(Picture picture, RectF dst) {
441        throw new UnsupportedOperationException();
442    }
443
444    @Override
445    public void drawPoint(float x, float y, Paint paint) {
446        // TODO: Implement
447    }
448
449    @Override
450    public void drawPoints(float[] pts, int offset, int count, Paint paint) {
451        // TODO: Implement
452    }
453
454    @Override
455    public void drawPoints(float[] pts, Paint paint) {
456        // TODO: Implement
457    }
458
459    @Override
460    public void drawPosText(char[] text, int index, int count, float[] pos, Paint paint) {
461        throw new UnsupportedOperationException();
462    }
463
464    @Override
465    public void drawPosText(String text, float[] pos, Paint paint) {
466        throw new UnsupportedOperationException();
467    }
468
469    @Override
470    public void drawRect(float left, float top, float right, float bottom, Paint paint) {
471        // TODO: Implement
472    }
473
474    @Override
475    public void drawRect(Rect r, Paint paint) {
476        // TODO: Implement
477    }
478
479    @Override
480    public void drawRect(RectF rect, Paint paint) {
481        // TODO: Implement
482    }
483
484    @Override
485    public void drawRGB(int r, int g, int b) {
486        drawColor(0xFF000000 | (r & 0xFF) << 16 | (g & 0xFF) << 8 | (b & 0xFF));
487    }
488
489    @Override
490    public void drawRoundRect(RectF rect, float rx, float ry, Paint paint) {
491        throw new UnsupportedOperationException();
492    }
493
494    @Override
495    public void drawText(char[] text, int index, int count, float x, float y, Paint paint) {
496        // TODO: Implement
497    }
498
499    @Override
500    public void drawText(CharSequence text, int start, int end, float x, float y, Paint paint) {
501        // TODO: Implement
502    }
503
504    @Override
505    public void drawText(String text, int start, int end, float x, float y, Paint paint) {
506        // TODO: Implement
507    }
508
509    @Override
510    public void drawText(String text, float x, float y, Paint paint) {
511        // TODO: Implement
512    }
513
514    @Override
515    public void drawTextOnPath(char[] text, int index, int count, Path path, float hOffset,
516            float vOffset, Paint paint) {
517
518        throw new UnsupportedOperationException();
519    }
520
521    @Override
522    public void drawTextOnPath(String text, Path path, float hOffset, float vOffset, Paint paint) {
523        throw new UnsupportedOperationException();
524    }
525
526    @Override
527    public void drawTextRun(char[] text, int index, int count, int contextIndex, int contextCount,
528            float x, float y, int dir, Paint paint) {
529
530        throw new UnsupportedOperationException();
531    }
532
533    @Override
534    public void drawTextRun(CharSequence text, int start, int end, int contextStart, int contextEnd,
535            float x, float y, int dir, Paint paint) {
536
537        throw new UnsupportedOperationException();
538    }
539
540    @Override
541    public void drawVertices(VertexMode mode, int vertexCount, float[] verts, int vertOffset,
542            float[] texs, int texOffset, int[] colors, int colorOffset, short[] indices,
543            int indexOffset, int indexCount, Paint paint) {
544
545        throw new UnsupportedOperationException();
546    }
547}
548