blob: 7adac1ce3e3fe19c08214f4525116bf267cf4480 [file] [log] [blame]
Romain Guyaa6c24c2011-04-28 18:40:04 -07001/*
2 * Copyright (C) 2011 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.Canvas;
20
21/**
22 * An OpenGL ES 2.0 implementation of {@link HardwareLayer}. This
23 * implementation can be used a rendering target. It generates a
24 * {@link Canvas} that can be used to render into an FBO using OpenGL.
25 */
26class GLES20RenderLayer extends GLES20Layer {
27
28 private int mLayerWidth;
29 private int mLayerHeight;
30
31 private final GLES20Canvas mCanvas;
32
33 GLES20RenderLayer(int width, int height, boolean isOpaque) {
34 super(width, height, isOpaque);
35
36 int[] layerInfo = new int[2];
37 mLayer = GLES20Canvas.nCreateLayer(width, height, isOpaque, layerInfo);
38 if (mLayer != 0) {
39 mLayerWidth = layerInfo[0];
40 mLayerHeight = layerInfo[1];
41
42 mCanvas = new GLES20Canvas(mLayer, !isOpaque);
43 mFinalizer = new Finalizer(mLayer);
44 } else {
45 mCanvas = null;
46 mFinalizer = null;
47 }
48 }
49
50 @Override
51 boolean isValid() {
52 return mLayer != 0 && mLayerWidth > 0 && mLayerHeight > 0;
53 }
54
55 @Override
56 void resize(int width, int height) {
57 if (!isValid() || width <= 0 || height <= 0) return;
58
59 mWidth = width;
60 mHeight = height;
61
62 if (width != mLayerWidth || height != mLayerHeight) {
63 int[] layerInfo = new int[2];
64
65 GLES20Canvas.nResizeLayer(mLayer, width, height, layerInfo);
66
67 mLayerWidth = layerInfo[0];
68 mLayerHeight = layerInfo[1];
69 }
70 }
71
72 @Override
73 HardwareCanvas getCanvas() {
74 return mCanvas;
75 }
76
77 @Override
78 void end(Canvas currentCanvas) {
79 if (currentCanvas instanceof GLES20Canvas) {
80 ((GLES20Canvas) currentCanvas).resume();
81 }
82 }
83
84 @Override
85 HardwareCanvas start(Canvas currentCanvas) {
86 if (currentCanvas instanceof GLES20Canvas) {
87 ((GLES20Canvas) currentCanvas).interrupt();
88 }
89 return getCanvas();
90 }
91}