Romain Guy | aa6c24c | 2011-04-28 18:40:04 -0700 | [diff] [blame] | 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 | |
| 17 | package android.view; |
| 18 | |
Romain Guy | c89b14b | 2012-08-08 14:53:48 -0700 | [diff] [blame] | 19 | import android.graphics.Canvas; |
Romain Guy | 302a9df | 2011-08-16 13:55:02 -0700 | [diff] [blame] | 20 | import android.graphics.Matrix; |
Romain Guy | 2bf68f0 | 2012-03-02 13:37:47 -0800 | [diff] [blame] | 21 | import android.graphics.Rect; |
Romain Guy | aa6c24c | 2011-04-28 18:40:04 -0700 | [diff] [blame] | 22 | import 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 | */ |
| 29 | class GLES20TextureLayer extends GLES20Layer { |
| 30 | private int mTexture; |
| 31 | private SurfaceTexture mSurface; |
| 32 | |
Romain Guy | a948927 | 2011-06-22 20:58:11 -0700 | [diff] [blame] | 33 | GLES20TextureLayer(boolean isOpaque) { |
Romain Guy | aa6c24c | 2011-04-28 18:40:04 -0700 | [diff] [blame] | 34 | int[] layerInfo = new int[2]; |
Romain Guy | a948927 | 2011-06-22 20:58:11 -0700 | [diff] [blame] | 35 | mLayer = GLES20Canvas.nCreateTextureLayer(isOpaque, layerInfo); |
Romain Guy | aa6c24c | 2011-04-28 18:40:04 -0700 | [diff] [blame] | 36 | |
| 37 | if (mLayer != 0) { |
| 38 | mTexture = layerInfo[0]; |
| 39 | mFinalizer = new Finalizer(mLayer); |
| 40 | } else { |
| 41 | mFinalizer = null; |
Romain Guy | ef09a21 | 2012-09-25 12:17:14 -0700 | [diff] [blame] | 42 | } |
Romain Guy | aa6c24c | 2011-04-28 18:40:04 -0700 | [diff] [blame] | 43 | } |
| 44 | |
| 45 | @Override |
| 46 | boolean isValid() { |
| 47 | return mLayer != 0 && mTexture != 0; |
| 48 | } |
| 49 | |
| 50 | @Override |
Chet Haase | 603f6de | 2012-09-14 15:31:25 -0700 | [diff] [blame] | 51 | boolean resize(int width, int height) { |
| 52 | return isValid(); |
Romain Guy | aa6c24c | 2011-04-28 18:40:04 -0700 | [diff] [blame] | 53 | } |
| 54 | |
| 55 | @Override |
| 56 | HardwareCanvas getCanvas() { |
| 57 | return null; |
| 58 | } |
| 59 | |
| 60 | @Override |
Romain Guy | c89b14b | 2012-08-08 14:53:48 -0700 | [diff] [blame] | 61 | HardwareCanvas start(Canvas currentCanvas) { |
Romain Guy | aa6c24c | 2011-04-28 18:40:04 -0700 | [diff] [blame] | 62 | return null; |
| 63 | } |
| 64 | |
| 65 | @Override |
Romain Guy | 78dd96d | 2013-05-03 14:24:16 -0700 | [diff] [blame] | 66 | HardwareCanvas start(Canvas currentCanvas, Rect dirty) { |
| 67 | return null; |
| 68 | } |
| 69 | |
| 70 | @Override |
Romain Guy | c89b14b | 2012-08-08 14:53:48 -0700 | [diff] [blame] | 71 | void end(Canvas currentCanvas) { |
Romain Guy | aa6c24c | 2011-04-28 18:40:04 -0700 | [diff] [blame] | 72 | } |
| 73 | |
| 74 | SurfaceTexture getSurfaceTexture() { |
| 75 | if (mSurface == null) { |
Grace Kloba | 5c5050d | 2011-06-23 22:32:04 -0700 | [diff] [blame] | 76 | mSurface = new SurfaceTexture(mTexture, false); |
Romain Guy | aa6c24c | 2011-04-28 18:40:04 -0700 | [diff] [blame] | 77 | } |
| 78 | return mSurface; |
| 79 | } |
| 80 | |
Jamie Gennis | 2af3524 | 2012-04-05 11:44:30 -0700 | [diff] [blame] | 81 | void setSurfaceTexture(SurfaceTexture surfaceTexture) { |
| 82 | if (mSurface != null) { |
| 83 | mSurface.release(); |
| 84 | } |
| 85 | mSurface = surfaceTexture; |
| 86 | mSurface.attachToGLContext(mTexture); |
| 87 | } |
| 88 | |
Romain Guy | 02ccac6 | 2011-06-24 13:20:23 -0700 | [diff] [blame] | 89 | @Override |
Romain Guy | a948927 | 2011-06-22 20:58:11 -0700 | [diff] [blame] | 90 | void update(int width, int height, boolean isOpaque) { |
Romain Guy | 02ccac6 | 2011-06-24 13:20:23 -0700 | [diff] [blame] | 91 | super.update(width, height, isOpaque); |
Romain Guy | a948927 | 2011-06-22 20:58:11 -0700 | [diff] [blame] | 92 | GLES20Canvas.nUpdateTextureLayer(mLayer, width, height, isOpaque, mSurface); |
Romain Guy | aa6c24c | 2011-04-28 18:40:04 -0700 | [diff] [blame] | 93 | } |
Romain Guy | 302a9df | 2011-08-16 13:55:02 -0700 | [diff] [blame] | 94 | |
| 95 | @Override |
Romain Guy | 846a533 | 2012-07-11 17:44:57 -0700 | [diff] [blame] | 96 | void setOpaque(boolean isOpaque) { |
| 97 | throw new UnsupportedOperationException("Use update(int, int, boolean) instead"); |
| 98 | } |
| 99 | |
| 100 | @Override |
Romain Guy | 302a9df | 2011-08-16 13:55:02 -0700 | [diff] [blame] | 101 | void setTransform(Matrix matrix) { |
| 102 | GLES20Canvas.nSetTextureLayerTransform(mLayer, matrix.native_instance); |
| 103 | } |
Romain Guy | 2bf68f0 | 2012-03-02 13:37:47 -0800 | [diff] [blame] | 104 | |
| 105 | @Override |
Romain Guy | 11cb642 | 2012-09-21 00:39:43 -0700 | [diff] [blame] | 106 | void redrawLater(DisplayList displayList, Rect dirtyRect) { |
Romain Guy | 2bf68f0 | 2012-03-02 13:37:47 -0800 | [diff] [blame] | 107 | } |
Romain Guy | aa6c24c | 2011-04-28 18:40:04 -0700 | [diff] [blame] | 108 | } |