Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [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 | |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 17 | |
Romain Guy | aa6c24c | 2011-04-28 18:40:04 -0700 | [diff] [blame] | 18 | package android.view; |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 19 | |
Romain Guy | 77a8116 | 2011-06-14 16:45:55 -0700 | [diff] [blame] | 20 | import android.graphics.Bitmap; |
| 21 | |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 22 | /** |
| 23 | * An OpenGL ES 2.0 implementation of {@link HardwareLayer}. |
| 24 | */ |
Romain Guy | aa6c24c | 2011-04-28 18:40:04 -0700 | [diff] [blame] | 25 | abstract class GLES20Layer extends HardwareLayer { |
| 26 | int mLayer; |
| 27 | Finalizer mFinalizer; |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 28 | |
Romain Guy | aa6c24c | 2011-04-28 18:40:04 -0700 | [diff] [blame] | 29 | GLES20Layer() { |
| 30 | } |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 31 | |
Romain Guy | aa6c24c | 2011-04-28 18:40:04 -0700 | [diff] [blame] | 32 | GLES20Layer(int width, int height, boolean opaque) { |
| 33 | super(width, height, opaque); |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 34 | } |
| 35 | |
Romain Guy | ada830f | 2011-01-13 12:13:20 -0800 | [diff] [blame] | 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 | */ |
| 41 | public int getLayer() { |
| 42 | return mLayer; |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 43 | } |
| 44 | |
Romain Guy | 02ccac6 | 2011-06-24 13:20:23 -0700 | [diff] [blame] | 45 | @Override |
Romain Guy | 77a8116 | 2011-06-14 16:45:55 -0700 | [diff] [blame] | 46 | boolean copyInto(Bitmap bitmap) { |
| 47 | return GLES20Canvas.nCopyLayer(mLayer, bitmap.mNativeBitmap); |
Romain Guy | 02ccac6 | 2011-06-24 13:20:23 -0700 | [diff] [blame] | 48 | } |
Romain Guy | 77a8116 | 2011-06-14 16:45:55 -0700 | [diff] [blame] | 49 | |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 50 | @Override |
| 51 | void destroy() { |
Romain Guy | ea83503 | 2011-07-28 19:24:37 -0700 | [diff] [blame] | 52 | if (mFinalizer != null) { |
| 53 | mFinalizer.destroy(); |
| 54 | mFinalizer = null; |
| 55 | } |
Romain Guy | ada830f | 2011-01-13 12:13:20 -0800 | [diff] [blame] | 56 | mLayer = 0; |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 57 | } |
| 58 | |
Romain Guy | aa6c24c | 2011-04-28 18:40:04 -0700 | [diff] [blame] | 59 | static class Finalizer { |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 60 | private int mLayerId; |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 61 | |
Romain Guy | ada830f | 2011-01-13 12:13:20 -0800 | [diff] [blame] | 62 | public Finalizer(int layerId) { |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 63 | mLayerId = layerId; |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 64 | } |
| 65 | |
| 66 | @Override |
| 67 | protected void finalize() throws Throwable { |
| 68 | try { |
Romain Guy | ada830f | 2011-01-13 12:13:20 -0800 | [diff] [blame] | 69 | if (mLayerId != 0) { |
| 70 | GLES20Canvas.nDestroyLayerDeferred(mLayerId); |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 71 | } |
| 72 | } finally { |
| 73 | super.finalize(); |
| 74 | } |
| 75 | } |
| 76 | |
| 77 | void destroy() { |
Romain Guy | ada830f | 2011-01-13 12:13:20 -0800 | [diff] [blame] | 78 | GLES20Canvas.nDestroyLayer(mLayerId); |
| 79 | mLayerId = 0; |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 80 | } |
| 81 | } |
| 82 | } |