blob: a0ae3791577ff01c04977df8d7b69fb901289f48 [file] [log] [blame]
Romain Guy6c319ca2011-01-11 14:29:25 -08001/*
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
Romain Guy6c319ca2011-01-11 14:29:25 -080017
Romain Guyaa6c24c2011-04-28 18:40:04 -070018package android.view;
Romain Guy6c319ca2011-01-11 14:29:25 -080019
Romain Guy77a81162011-06-14 16:45:55 -070020import android.graphics.Bitmap;
21
Romain Guy6c319ca2011-01-11 14:29:25 -080022/**
23 * An OpenGL ES 2.0 implementation of {@link HardwareLayer}.
24 */
Romain Guyaa6c24c2011-04-28 18:40:04 -070025abstract class GLES20Layer extends HardwareLayer {
26 int mLayer;
27 Finalizer mFinalizer;
Romain Guy6c319ca2011-01-11 14:29:25 -080028
Romain Guyaa6c24c2011-04-28 18:40:04 -070029 GLES20Layer() {
30 }
Romain Guy6c319ca2011-01-11 14:29:25 -080031
Romain Guyaa6c24c2011-04-28 18:40:04 -070032 GLES20Layer(int width, int height, boolean opaque) {
33 super(width, height, opaque);
Romain Guy6c319ca2011-01-11 14:29:25 -080034 }
35
Romain Guyada830f2011-01-13 12:13:20 -080036 /**
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 */
41 public int getLayer() {
42 return mLayer;
Romain Guy6c319ca2011-01-11 14:29:25 -080043 }
44
Romain Guy02ccac62011-06-24 13:20:23 -070045 @Override
Romain Guy77a81162011-06-14 16:45:55 -070046 boolean copyInto(Bitmap bitmap) {
47 return GLES20Canvas.nCopyLayer(mLayer, bitmap.mNativeBitmap);
Romain Guy02ccac62011-06-24 13:20:23 -070048 }
Romain Guy77a81162011-06-14 16:45:55 -070049
Romain Guy6c319ca2011-01-11 14:29:25 -080050 @Override
51 void destroy() {
Romain Guyea835032011-07-28 19:24:37 -070052 if (mFinalizer != null) {
53 mFinalizer.destroy();
54 mFinalizer = null;
55 }
Romain Guyada830f2011-01-13 12:13:20 -080056 mLayer = 0;
Romain Guy6c319ca2011-01-11 14:29:25 -080057 }
58
Romain Guyaa6c24c2011-04-28 18:40:04 -070059 static class Finalizer {
Romain Guy6c319ca2011-01-11 14:29:25 -080060 private int mLayerId;
Romain Guy6c319ca2011-01-11 14:29:25 -080061
Romain Guyada830f2011-01-13 12:13:20 -080062 public Finalizer(int layerId) {
Romain Guy6c319ca2011-01-11 14:29:25 -080063 mLayerId = layerId;
Romain Guy6c319ca2011-01-11 14:29:25 -080064 }
65
66 @Override
67 protected void finalize() throws Throwable {
68 try {
Romain Guyada830f2011-01-13 12:13:20 -080069 if (mLayerId != 0) {
70 GLES20Canvas.nDestroyLayerDeferred(mLayerId);
Romain Guy6c319ca2011-01-11 14:29:25 -080071 }
72 } finally {
73 super.finalize();
74 }
75 }
76
77 void destroy() {
Romain Guyada830f2011-01-13 12:13:20 -080078 GLES20Canvas.nDestroyLayer(mLayerId);
79 mLayerId = 0;
Romain Guy6c319ca2011-01-11 14:29:25 -080080 }
81 }
82}