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 | |
| 17 | package android.view; |
| 18 | |
Romain Guy | 02ccac6 | 2011-06-24 13:20:23 -0700 | [diff] [blame] | 19 | import android.graphics.Bitmap; |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 20 | import android.graphics.Canvas; |
Romain Guy | 302a9df | 2011-08-16 13:55:02 -0700 | [diff] [blame] | 21 | import android.graphics.Matrix; |
Romain Guy | 2bf68f0 | 2012-03-02 13:37:47 -0800 | [diff] [blame] | 22 | import android.graphics.Rect; |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 23 | |
| 24 | /** |
| 25 | * A hardware layer can be used to render graphics operations into a hardware |
| 26 | * friendly buffer. For instance, with an OpenGL backend, a hardware layer |
| 27 | * would use a Frame Buffer Object (FBO.) The hardware layer can be used as |
| 28 | * a drawing cache when a complex set of graphics operations needs to be |
| 29 | * drawn several times. |
| 30 | */ |
| 31 | abstract class HardwareLayer { |
Romain Guy | aa6c24c | 2011-04-28 18:40:04 -0700 | [diff] [blame] | 32 | /** |
| 33 | * Indicates an unknown dimension (width or height.) |
| 34 | */ |
| 35 | static final int DIMENSION_UNDEFINED = -1; |
| 36 | |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 37 | int mWidth; |
| 38 | int mHeight; |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 39 | DisplayList mDisplayList; |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 40 | |
Romain Guy | 02ccac6 | 2011-06-24 13:20:23 -0700 | [diff] [blame] | 41 | boolean mOpaque; |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 42 | |
| 43 | /** |
Romain Guy | aa6c24c | 2011-04-28 18:40:04 -0700 | [diff] [blame] | 44 | * Creates a new hardware layer with undefined dimensions. |
| 45 | */ |
| 46 | HardwareLayer() { |
| 47 | this(DIMENSION_UNDEFINED, DIMENSION_UNDEFINED, false); |
| 48 | } |
| 49 | |
| 50 | /** |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 51 | * Creates a new hardware layer at least as large as the supplied |
| 52 | * dimensions. |
| 53 | * |
| 54 | * @param width The minimum width of the layer |
| 55 | * @param height The minimum height of the layer |
| 56 | * @param isOpaque Whether the layer should be opaque or not |
| 57 | */ |
| 58 | HardwareLayer(int width, int height, boolean isOpaque) { |
| 59 | mWidth = width; |
| 60 | mHeight = height; |
| 61 | mOpaque = isOpaque; |
| 62 | } |
| 63 | |
| 64 | /** |
| 65 | * Returns the minimum width of the layer. |
| 66 | * |
| 67 | * @return The minimum desired width of the hardware layer |
| 68 | */ |
| 69 | int getWidth() { |
| 70 | return mWidth; |
| 71 | } |
| 72 | |
| 73 | /** |
| 74 | * Returns the minimum height of the layer. |
| 75 | * |
| 76 | * @return The minimum desired height of the hardware layer |
| 77 | */ |
| 78 | int getHeight() { |
| 79 | return mHeight; |
| 80 | } |
| 81 | |
| 82 | /** |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 83 | * Returns the DisplayList for the layer. |
| 84 | * |
| 85 | * @return The DisplayList of the hardware layer |
| 86 | */ |
| 87 | DisplayList getDisplayList() { |
| 88 | return mDisplayList; |
| 89 | } |
| 90 | |
| 91 | /** |
| 92 | * Sets the DisplayList for the layer. |
| 93 | * |
| 94 | * @param displayList The new DisplayList for this layer |
| 95 | */ |
| 96 | void setDisplayList(DisplayList displayList) { |
| 97 | mDisplayList = displayList; |
| 98 | } |
| 99 | |
| 100 | /** |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 101 | * Returns whether or not this layer is opaque. |
| 102 | * |
| 103 | * @return True if the layer is opaque, false otherwise |
| 104 | */ |
| 105 | boolean isOpaque() { |
| 106 | return mOpaque; |
| 107 | } |
| 108 | |
| 109 | /** |
Romain Guy | 846a533 | 2012-07-11 17:44:57 -0700 | [diff] [blame] | 110 | * Sets whether or not this layer should be considered opaque. |
| 111 | * |
| 112 | * @param isOpaque True if the layer is opaque, false otherwise |
| 113 | */ |
| 114 | abstract void setOpaque(boolean isOpaque); |
| 115 | |
| 116 | /** |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 117 | * Indicates whether this layer can be rendered. |
| 118 | * |
| 119 | * @return True if the layer can be rendered into, false otherwise |
| 120 | */ |
| 121 | abstract boolean isValid(); |
| 122 | |
| 123 | /** |
Romain Guy | 02ccac6 | 2011-06-24 13:20:23 -0700 | [diff] [blame] | 124 | * Resize the layer, if necessary, to be at least as large |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 125 | * as the supplied dimensions. |
| 126 | * |
| 127 | * @param width The new desired minimum width for this layer |
| 128 | * @param height The new desired minimum height for this layer |
| 129 | */ |
| 130 | abstract void resize(int width, int height); |
| 131 | |
| 132 | /** |
| 133 | * Returns a hardware canvas that can be used to render onto |
| 134 | * this layer. |
| 135 | * |
| 136 | * @return A hardware canvas, or null if a canvas cannot be created |
| 137 | */ |
| 138 | abstract HardwareCanvas getCanvas(); |
| 139 | |
| 140 | /** |
| 141 | * Destroys resources without waiting for a GC. |
| 142 | */ |
| 143 | abstract void destroy(); |
| 144 | |
| 145 | /** |
| 146 | * This must be invoked before drawing onto this layer. |
| 147 | * @param currentCanvas |
| 148 | */ |
| 149 | abstract HardwareCanvas start(Canvas currentCanvas); |
| 150 | |
| 151 | /** |
| 152 | * This must be invoked after drawing onto this layer. |
| 153 | * @param currentCanvas |
| 154 | */ |
| 155 | abstract void end(Canvas currentCanvas); |
Romain Guy | 02ccac6 | 2011-06-24 13:20:23 -0700 | [diff] [blame] | 156 | |
| 157 | /** |
| 158 | * Copies this layer into the specified bitmap. |
| 159 | * |
| 160 | * @param bitmap The bitmap to copy they layer into |
| 161 | * |
| 162 | * @return True if the copy was successful, false otherwise |
| 163 | */ |
| 164 | abstract boolean copyInto(Bitmap bitmap); |
| 165 | |
| 166 | /** |
| 167 | * Update the layer's properties. This method should be used |
| 168 | * when the underlying storage is modified by an external entity. |
| 169 | * To change the underlying storage, use the {@link #resize(int, int)} |
| 170 | * method instead. |
| 171 | * |
| 172 | * @param width The new width of this layer |
| 173 | * @param height The new height of this layer |
| 174 | * @param isOpaque Whether this layer is opaque |
| 175 | */ |
| 176 | void update(int width, int height, boolean isOpaque) { |
| 177 | mWidth = width; |
| 178 | mHeight = height; |
| 179 | mOpaque = isOpaque; |
| 180 | } |
Romain Guy | 302a9df | 2011-08-16 13:55:02 -0700 | [diff] [blame] | 181 | |
| 182 | /** |
| 183 | * Sets an optional transform on this layer. |
| 184 | * |
| 185 | * @param matrix The transform to apply to the layer. |
| 186 | */ |
| 187 | abstract void setTransform(Matrix matrix); |
Romain Guy | 2bf68f0 | 2012-03-02 13:37:47 -0800 | [diff] [blame] | 188 | |
| 189 | /** |
| 190 | * Specifies the display list to use to refresh the layer. |
Michael Jurka | 7e52caf | 2012-03-06 15:57:06 -0800 | [diff] [blame] | 191 | * |
Romain Guy | 2bf68f0 | 2012-03-02 13:37:47 -0800 | [diff] [blame] | 192 | * @param displayList The display list containing the drawing commands to |
| 193 | * execute in this layer |
| 194 | * @param dirtyRect The dirty region of the layer that needs to be redrawn |
| 195 | */ |
| 196 | abstract void redraw(DisplayList displayList, Rect dirtyRect); |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 197 | } |