GLES20TextureLayer.java revision 846a533945576e5cb1a66529ca3a52d71749f04f
1/* 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; 20import android.graphics.Matrix; 21import android.graphics.Rect; 22import 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 33 GLES20TextureLayer(boolean isOpaque) { 34 int[] layerInfo = new int[2]; 35 mLayer = GLES20Canvas.nCreateTextureLayer(isOpaque, layerInfo); 36 37 if (mLayer != 0) { 38 mTexture = layerInfo[0]; 39 mFinalizer = new Finalizer(mLayer); 40 } else { 41 mFinalizer = null; 42 } 43 } 44 45 @Override 46 boolean isValid() { 47 return mLayer != 0 && mTexture != 0; 48 } 49 50 @Override 51 void resize(int width, int height) { 52 } 53 54 @Override 55 HardwareCanvas getCanvas() { 56 return null; 57 } 58 59 @Override 60 HardwareCanvas start(Canvas currentCanvas) { 61 return null; 62 } 63 64 @Override 65 void end(Canvas currentCanvas) { 66 } 67 68 SurfaceTexture getSurfaceTexture() { 69 if (mSurface == null) { 70 mSurface = new SurfaceTexture(mTexture, false); 71 } 72 return mSurface; 73 } 74 75 void setSurfaceTexture(SurfaceTexture surfaceTexture) { 76 if (mSurface != null) { 77 mSurface.release(); 78 } 79 mSurface = surfaceTexture; 80 mSurface.attachToGLContext(mTexture); 81 } 82 83 @Override 84 void update(int width, int height, boolean isOpaque) { 85 super.update(width, height, isOpaque); 86 GLES20Canvas.nUpdateTextureLayer(mLayer, width, height, isOpaque, mSurface); 87 } 88 89 @Override 90 void setOpaque(boolean isOpaque) { 91 throw new UnsupportedOperationException("Use update(int, int, boolean) instead"); 92 } 93 94 @Override 95 void setTransform(Matrix matrix) { 96 GLES20Canvas.nSetTextureLayerTransform(mLayer, matrix.native_instance); 97 } 98 99 @Override 100 void redraw(DisplayList displayList, Rect dirtyRect) { 101 } 102} 103