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 18 package android.view; 19 20 import android.graphics.Bitmap; 21 22 /** 23 * An OpenGL ES 2.0 implementation of {@link HardwareLayer}. 24 */ 25 abstract class GLES20Layer extends HardwareLayer { 26 int mLayer; 27 Finalizer mFinalizer; 28 GLES20Layer()29 GLES20Layer() { 30 } 31 GLES20Layer(int width, int height, boolean opaque)32 GLES20Layer(int width, int height, boolean opaque) { 33 super(width, height, opaque); 34 } 35 36 /** 37 * Returns the native layer object used to render this layer. 38 * 39 * @return A pointer to the native layer object, or 0 if the object is NULL 40 */ getLayer()41 public int getLayer() { 42 return mLayer; 43 } 44 45 @Override copyInto(Bitmap bitmap)46 boolean copyInto(Bitmap bitmap) { 47 return GLES20Canvas.nCopyLayer(mLayer, bitmap.mNativeBitmap); 48 } 49 50 @Override update(int width, int height, boolean isOpaque)51 void update(int width, int height, boolean isOpaque) { 52 super.update(width, height, isOpaque); 53 } 54 55 @Override destroy()56 void destroy() { 57 if (mFinalizer != null) { 58 mFinalizer.destroy(); 59 mFinalizer = null; 60 } 61 mLayer = 0; 62 } 63 64 @Override flush()65 void flush() { 66 if (mLayer != 0) { 67 GLES20Canvas.nFlushLayer(mLayer); 68 } 69 } 70 71 static class Finalizer { 72 private int mLayerId; 73 Finalizer(int layerId)74 public Finalizer(int layerId) { 75 mLayerId = layerId; 76 } 77 78 @Override finalize()79 protected void finalize() throws Throwable { 80 try { 81 if (mLayerId != 0) { 82 GLES20Canvas.nDestroyLayerDeferred(mLayerId); 83 } 84 } finally { 85 super.finalize(); 86 } 87 } 88 destroy()89 void destroy() { 90 GLES20Canvas.nDestroyLayer(mLayerId); 91 mLayerId = 0; 92 } 93 } 94 } 95