GLES20Layer.java revision aa6c24c21c727a196451332448d4e3b11a80be69
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 18package android.view; 19 20/** 21 * An OpenGL ES 2.0 implementation of {@link HardwareLayer}. 22 */ 23abstract class GLES20Layer extends HardwareLayer { 24 int mLayer; 25 Finalizer mFinalizer; 26 27 GLES20Layer() { 28 } 29 30 GLES20Layer(int width, int height, boolean opaque) { 31 super(width, height, opaque); 32 } 33 34 /** 35 * Returns the native layer object used to render this layer. 36 * 37 * @return A pointer to the native layer object, or 0 if the object is NULL 38 */ 39 public int getLayer() { 40 return mLayer; 41 } 42 43 44 @Override 45 void destroy() { 46 if (mFinalizer != null) mFinalizer.destroy(); 47 mLayer = 0; 48 } 49 50 static class Finalizer { 51 private int mLayerId; 52 53 public Finalizer(int layerId) { 54 mLayerId = layerId; 55 } 56 57 @Override 58 protected void finalize() throws Throwable { 59 try { 60 if (mLayerId != 0) { 61 GLES20Canvas.nDestroyLayerDeferred(mLayerId); 62 } 63 } finally { 64 super.finalize(); 65 } 66 } 67 68 void destroy() { 69 GLES20Canvas.nDestroyLayer(mLayerId); 70 mLayerId = 0; 71 } 72 } 73} 74