blob: 23383d9c0473651d6ac6283308c3096c154a0477 [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
17package android.view;
18
Romain Guy02ccac62011-06-24 13:20:23 -070019import android.graphics.Bitmap;
Romain Guyc89b14b2012-08-08 14:53:48 -070020import android.graphics.Canvas;
Romain Guy302a9df2011-08-16 13:55:02 -070021import android.graphics.Matrix;
Chet Haased15ebf22012-09-05 11:40:29 -070022import android.graphics.Paint;
Romain Guy2bf68f02012-03-02 13:37:47 -080023import android.graphics.Rect;
Romain Guy6c319ca2011-01-11 14:29:25 -080024
25/**
26 * A hardware layer can be used to render graphics operations into a hardware
Romain Guy52036b12013-02-14 18:03:37 -080027 * friendly buffer. For instance, with an OpenGL backend a hardware layer
Romain Guy6c319ca2011-01-11 14:29:25 -080028 * would use a Frame Buffer Object (FBO.) The hardware layer can be used as
29 * a drawing cache when a complex set of graphics operations needs to be
30 * drawn several times.
31 */
32abstract class HardwareLayer {
Romain Guyaa6c24c2011-04-28 18:40:04 -070033 /**
34 * Indicates an unknown dimension (width or height.)
35 */
36 static final int DIMENSION_UNDEFINED = -1;
37
Romain Guy6c319ca2011-01-11 14:29:25 -080038 int mWidth;
39 int mHeight;
Chet Haasea1cff502012-02-21 13:43:44 -080040 DisplayList mDisplayList;
Romain Guy6c319ca2011-01-11 14:29:25 -080041
Romain Guy02ccac62011-06-24 13:20:23 -070042 boolean mOpaque;
Romain Guy6c319ca2011-01-11 14:29:25 -080043
44 /**
Romain Guyaa6c24c2011-04-28 18:40:04 -070045 * Creates a new hardware layer with undefined dimensions.
46 */
47 HardwareLayer() {
48 this(DIMENSION_UNDEFINED, DIMENSION_UNDEFINED, false);
49 }
50
51 /**
Romain Guy6c319ca2011-01-11 14:29:25 -080052 * Creates a new hardware layer at least as large as the supplied
53 * dimensions.
54 *
55 * @param width The minimum width of the layer
56 * @param height The minimum height of the layer
57 * @param isOpaque Whether the layer should be opaque or not
58 */
59 HardwareLayer(int width, int height, boolean isOpaque) {
60 mWidth = width;
61 mHeight = height;
62 mOpaque = isOpaque;
63 }
64
65 /**
Chet Haased15ebf22012-09-05 11:40:29 -070066 * Update the paint used when drawing this layer.
67 *
68 * @param paint The paint used when the layer is drawn into the destination canvas.
69 * @see View#setLayerPaint(android.graphics.Paint)
70 */
Romain Guy52036b12013-02-14 18:03:37 -080071 void setLayerPaint(Paint paint) { }
Chet Haased15ebf22012-09-05 11:40:29 -070072
73 /**
Romain Guy6c319ca2011-01-11 14:29:25 -080074 * Returns the minimum width of the layer.
75 *
76 * @return The minimum desired width of the hardware layer
77 */
78 int getWidth() {
79 return mWidth;
80 }
81
82 /**
83 * Returns the minimum height of the layer.
84 *
85 * @return The minimum desired height of the hardware layer
86 */
87 int getHeight() {
88 return mHeight;
89 }
90
91 /**
Chet Haasea1cff502012-02-21 13:43:44 -080092 * Returns the DisplayList for the layer.
93 *
94 * @return The DisplayList of the hardware layer
95 */
96 DisplayList getDisplayList() {
97 return mDisplayList;
98 }
99
100 /**
101 * Sets the DisplayList for the layer.
102 *
103 * @param displayList The new DisplayList for this layer
104 */
105 void setDisplayList(DisplayList displayList) {
106 mDisplayList = displayList;
107 }
108
109 /**
Romain Guy6c319ca2011-01-11 14:29:25 -0800110 * Returns whether or not this layer is opaque.
111 *
112 * @return True if the layer is opaque, false otherwise
113 */
114 boolean isOpaque() {
115 return mOpaque;
116 }
117
118 /**
Romain Guy846a5332012-07-11 17:44:57 -0700119 * Sets whether or not this layer should be considered opaque.
120 *
121 * @param isOpaque True if the layer is opaque, false otherwise
122 */
123 abstract void setOpaque(boolean isOpaque);
124
125 /**
Romain Guy6c319ca2011-01-11 14:29:25 -0800126 * Indicates whether this layer can be rendered.
127 *
128 * @return True if the layer can be rendered into, false otherwise
129 */
130 abstract boolean isValid();
131
132 /**
Romain Guy02ccac62011-06-24 13:20:23 -0700133 * Resize the layer, if necessary, to be at least as large
Romain Guy6c319ca2011-01-11 14:29:25 -0800134 * as the supplied dimensions.
135 *
136 * @param width The new desired minimum width for this layer
137 * @param height The new desired minimum height for this layer
Chet Haase603f6de2012-09-14 15:31:25 -0700138 * @return True if the resulting layer is valid, false otherwise
Romain Guy6c319ca2011-01-11 14:29:25 -0800139 */
Chet Haase603f6de2012-09-14 15:31:25 -0700140 abstract boolean resize(int width, int height);
Romain Guy6c319ca2011-01-11 14:29:25 -0800141
142 /**
143 * Returns a hardware canvas that can be used to render onto
144 * this layer.
145 *
146 * @return A hardware canvas, or null if a canvas cannot be created
Romain Guy52036b12013-02-14 18:03:37 -0800147 *
148 * @see #start(android.graphics.Canvas)
149 * @see #end(android.graphics.Canvas)
Romain Guy6c319ca2011-01-11 14:29:25 -0800150 */
151 abstract HardwareCanvas getCanvas();
152
153 /**
154 * Destroys resources without waiting for a GC.
155 */
156 abstract void destroy();
157
158 /**
159 * This must be invoked before drawing onto this layer.
Romain Guy52036b12013-02-14 18:03:37 -0800160 *
Romain Guy78dd96d2013-05-03 14:24:16 -0700161 * @param currentCanvas The canvas whose rendering needs to be interrupted
Romain Guy6c319ca2011-01-11 14:29:25 -0800162 */
Romain Guyc89b14b2012-08-08 14:53:48 -0700163 abstract HardwareCanvas start(Canvas currentCanvas);
Romain Guy52036b12013-02-14 18:03:37 -0800164
Romain Guy6c319ca2011-01-11 14:29:25 -0800165 /**
Romain Guy78dd96d2013-05-03 14:24:16 -0700166 * This must be invoked before drawing onto this layer.
167 *
168 * @param dirty The dirty area to repaint
169 * @param currentCanvas The canvas whose rendering needs to be interrupted
170 */
171 abstract HardwareCanvas start(Canvas currentCanvas, Rect dirty);
172
173 /**
Romain Guy6c319ca2011-01-11 14:29:25 -0800174 * This must be invoked after drawing onto this layer.
Romain Guy52036b12013-02-14 18:03:37 -0800175 *
Romain Guy78dd96d2013-05-03 14:24:16 -0700176 * @param currentCanvas The canvas whose rendering needs to be resumed
Romain Guy6c319ca2011-01-11 14:29:25 -0800177 */
Romain Guyc89b14b2012-08-08 14:53:48 -0700178 abstract void end(Canvas currentCanvas);
Romain Guy02ccac62011-06-24 13:20:23 -0700179
180 /**
181 * Copies this layer into the specified bitmap.
182 *
183 * @param bitmap The bitmap to copy they layer into
184 *
185 * @return True if the copy was successful, false otherwise
186 */
187 abstract boolean copyInto(Bitmap bitmap);
188
189 /**
190 * Update the layer's properties. This method should be used
191 * when the underlying storage is modified by an external entity.
192 * To change the underlying storage, use the {@link #resize(int, int)}
193 * method instead.
194 *
195 * @param width The new width of this layer
196 * @param height The new height of this layer
197 * @param isOpaque Whether this layer is opaque
198 */
199 void update(int width, int height, boolean isOpaque) {
200 mWidth = width;
201 mHeight = height;
202 mOpaque = isOpaque;
203 }
Romain Guy302a9df2011-08-16 13:55:02 -0700204
205 /**
206 * Sets an optional transform on this layer.
207 *
208 * @param matrix The transform to apply to the layer.
209 */
210 abstract void setTransform(Matrix matrix);
Romain Guy2bf68f02012-03-02 13:37:47 -0800211
212 /**
213 * Specifies the display list to use to refresh the layer.
Michael Jurka7e52caf2012-03-06 15:57:06 -0800214 *
Romain Guy2bf68f02012-03-02 13:37:47 -0800215 * @param displayList The display list containing the drawing commands to
216 * execute in this layer
217 * @param dirtyRect The dirty region of the layer that needs to be redrawn
218 */
Romain Guy11cb6422012-09-21 00:39:43 -0700219 abstract void redrawLater(DisplayList displayList, Rect dirtyRect);
Romain Guyef09a212012-09-25 12:17:14 -0700220
221 /**
222 * Indicates that this layer has lost its underlying storage.
223 */
224 abstract void clearStorage();
Romain Guy6c319ca2011-01-11 14:29:25 -0800225}