blob: 06c6e7ce77e880596f852f4819dbd6490daaf906 [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 Guy6c319ca2011-01-11 14:29:25 -080020import android.graphics.Canvas;
Romain Guy302a9df2011-08-16 13:55:02 -070021import android.graphics.Matrix;
Romain Guy2bf68f02012-03-02 13:37:47 -080022import android.graphics.Rect;
Romain Guy6c319ca2011-01-11 14:29:25 -080023
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 */
31abstract class HardwareLayer {
Romain Guyaa6c24c2011-04-28 18:40:04 -070032 /**
33 * Indicates an unknown dimension (width or height.)
34 */
35 static final int DIMENSION_UNDEFINED = -1;
36
Romain Guy6c319ca2011-01-11 14:29:25 -080037 int mWidth;
38 int mHeight;
Chet Haasea1cff502012-02-21 13:43:44 -080039 DisplayList mDisplayList;
Romain Guy6c319ca2011-01-11 14:29:25 -080040
Romain Guy02ccac62011-06-24 13:20:23 -070041 boolean mOpaque;
Romain Guy6c319ca2011-01-11 14:29:25 -080042
43 /**
Romain Guyaa6c24c2011-04-28 18:40:04 -070044 * Creates a new hardware layer with undefined dimensions.
45 */
46 HardwareLayer() {
47 this(DIMENSION_UNDEFINED, DIMENSION_UNDEFINED, false);
48 }
49
50 /**
Romain Guy6c319ca2011-01-11 14:29:25 -080051 * 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 Haasea1cff502012-02-21 13:43:44 -080083 * 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 Guy6c319ca2011-01-11 14:29:25 -0800101 * 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 Guy846a5332012-07-11 17:44:57 -0700110 * 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 Guy6c319ca2011-01-11 14:29:25 -0800117 * 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 Guy02ccac62011-06-24 13:20:23 -0700124 * Resize the layer, if necessary, to be at least as large
Romain Guy6c319ca2011-01-11 14:29:25 -0800125 * 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 Guy02ccac62011-06-24 13:20:23 -0700156
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 Guy302a9df2011-08-16 13:55:02 -0700181
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 Guy2bf68f02012-03-02 13:37:47 -0800188
189 /**
190 * Specifies the display list to use to refresh the layer.
Michael Jurka7e52caf2012-03-06 15:57:06 -0800191 *
Romain Guy2bf68f02012-03-02 13:37:47 -0800192 * @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 Guy6c319ca2011-01-11 14:29:25 -0800197}