blob: 16a13cfa2f7a108c14d8bdc6adf23ae0797ab344 [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;
Romain Guy302a9df2011-08-16 13:55:02 -070020import android.graphics.Matrix;
Romain Guy2bf68f02012-03-02 13:37:47 -080021import android.graphics.Rect;
Romain Guyaa6c24c2011-04-28 18:40:04 -070022import android.graphics.SurfaceTexture;
23
24/**
25 * An OpenGL ES 2.0 implementation of {@link HardwareLayer}. This
26 * implementation can be used as a texture. Rendering into this
27 * layer is not controlled by a {@link HardwareCanvas}.
28 */
29class GLES20TextureLayer extends GLES20Layer {
30 private int mTexture;
31 private SurfaceTexture mSurface;
32
Romain Guya9489272011-06-22 20:58:11 -070033 GLES20TextureLayer(boolean isOpaque) {
Romain Guyaa6c24c2011-04-28 18:40:04 -070034 int[] layerInfo = new int[2];
Romain Guya9489272011-06-22 20:58:11 -070035 mLayer = GLES20Canvas.nCreateTextureLayer(isOpaque, layerInfo);
Romain Guyaa6c24c2011-04-28 18:40:04 -070036
37 if (mLayer != 0) {
38 mTexture = layerInfo[0];
39 mFinalizer = new Finalizer(mLayer);
40 } else {
41 mFinalizer = null;
42 }
43 }
44
Jamie Gennis2af35242012-04-05 11:44:30 -070045 GLES20TextureLayer(SurfaceTexture surface, boolean isOpaque) {
46 this(isOpaque);
47 mSurface = surface;
48 mSurface.attachToGLContext(mTexture);
49 }
50
Romain Guyaa6c24c2011-04-28 18:40:04 -070051 @Override
52 boolean isValid() {
53 return mLayer != 0 && mTexture != 0;
54 }
55
56 @Override
57 void resize(int width, int height) {
58 }
59
60 @Override
61 HardwareCanvas getCanvas() {
62 return null;
63 }
64
65 @Override
66 HardwareCanvas start(Canvas currentCanvas) {
67 return null;
68 }
69
70 @Override
71 void end(Canvas currentCanvas) {
72 }
73
74 SurfaceTexture getSurfaceTexture() {
75 if (mSurface == null) {
Grace Kloba5c5050d2011-06-23 22:32:04 -070076 mSurface = new SurfaceTexture(mTexture, false);
Romain Guyaa6c24c2011-04-28 18:40:04 -070077 }
78 return mSurface;
79 }
80
Jamie Gennis2af35242012-04-05 11:44:30 -070081 void setSurfaceTexture(SurfaceTexture surfaceTexture) {
82 if (mSurface != null) {
83 mSurface.release();
84 }
85 mSurface = surfaceTexture;
86 mSurface.attachToGLContext(mTexture);
87 }
88
Romain Guy02ccac62011-06-24 13:20:23 -070089 @Override
Romain Guya9489272011-06-22 20:58:11 -070090 void update(int width, int height, boolean isOpaque) {
Romain Guy02ccac62011-06-24 13:20:23 -070091 super.update(width, height, isOpaque);
Romain Guya9489272011-06-22 20:58:11 -070092 GLES20Canvas.nUpdateTextureLayer(mLayer, width, height, isOpaque, mSurface);
Romain Guyaa6c24c2011-04-28 18:40:04 -070093 }
Romain Guy302a9df2011-08-16 13:55:02 -070094
95 @Override
96 void setTransform(Matrix matrix) {
97 GLES20Canvas.nSetTextureLayerTransform(mLayer, matrix.native_instance);
98 }
Romain Guy2bf68f02012-03-02 13:37:47 -080099
100 @Override
101 void redraw(DisplayList displayList, Rect dirtyRect) {
102 }
Romain Guyaa6c24c2011-04-28 18:40:04 -0700103}