DisplayList.java revision bc7616eae90002879f1d82d5e99dea7d1152b742
1/*
2 * Copyright (C) 2010 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
19import android.os.Handler;
20
21/**
22 * A display lists records a series of graphics related operation and can replay
23 * them later. Display lists are usually built by recording operations on a
24 * {@link android.graphics.Canvas}. Replaying the operations from a display list
25 * avoids executing views drawing code on every frame, and is thus much more
26 * efficient.
27 *
28 * @hide
29 */
30public abstract class DisplayList {
31    private final Runnable mInvalidate = new Runnable() {
32        @Override
33        public void run() {
34            invalidate();
35        }
36    };
37
38    /**
39     * Flag used when calling
40     * {@link HardwareCanvas#drawDisplayList(DisplayList, int, int, android.graphics.Rect, int)}.
41     * When this flag is set, draw operations lying outside of the bounds of the
42     * display list will be culled early. It is recommeneded to always set this
43     * flag.
44     */
45    public static final int FLAG_CLIP_CHILDREN = 0x1;
46
47    /**
48     * Starts recording the display list. All operations performed on the
49     * returned canvas are recorded and stored in this display list.
50     *
51     * @return A canvas to record drawing operations.
52     */
53    public abstract HardwareCanvas start();
54
55    /**
56     * Ends the recording for this display list. A display list cannot be
57     * replayed if recording is not finished.
58     */
59    public abstract void end();
60
61    /**
62     * Invalidates the display list, indicating that it should be repopulated
63     * with new drawing commands prior to being used again. Calling this method
64     * causes calls to {@link #isValid()} to return <code>false</code>.
65     */
66    public abstract void invalidate();
67
68    /**
69     * Posts a call to {@link #invalidate()} in the specified handler.
70     */
71    final void postInvalidate(Handler handler) {
72        handler.post(mInvalidate);
73    }
74
75    /**
76     * Returns whether the display list is currently usable. If this returns false,
77     * the display list should be re-recorded prior to replaying it.
78     *
79     * @return boolean true if the display list is able to be replayed, false otherwise.
80     */
81    public abstract boolean isValid();
82
83    /**
84     * Return the amount of memory used by this display list.
85     *
86     * @return The size of this display list in bytes
87     */
88    public abstract int getSize();
89
90    ///////////////////////////////////////////////////////////////////////////
91    // DisplayList Property Setters
92    ///////////////////////////////////////////////////////////////////////////
93
94    /**
95     * Set the caching property on the DisplayList, which indicates whether the DisplayList
96     * holds a layer. Layer DisplayLists should avoid creating an alpha layer, since alpha is
97     * handled in the drawLayer operation directly (and more efficiently).
98     *
99     * @param caching true if the DisplayList represents a hardware layer, false otherwise.
100     */
101    public abstract void setCaching(boolean caching);
102
103    /**
104     * Set whether the DisplayList should clip itself to its bounds. This property is controlled by
105     * the view's parent.
106     *
107     * @param clipChildren true if the DisplayList should clip to its bounds
108     */
109    public abstract void setClipChildren(boolean clipChildren);
110
111    /**
112     * Set the application scale on the DisplayList. This scale is incurred by applications that
113     * are auto-scaled for compatibility reasons. By default, the value is 1 (unscaled).
114     *
115     * @param scale The scaling factor
116     */
117    public abstract void setApplicationScale(float scale);
118
119    /**
120     * Sets the alpha value for the DisplayList
121     *
122     * @param alpha The translucency of the DisplayList
123     * @see View#setAlpha(float)
124     */
125    public abstract void setAlpha(float alpha);
126
127    /**
128     * Sets the translationX value for the DisplayList
129     *
130     * @param translationX The translationX value of the DisplayList
131     * @see View#setTranslationX(float)
132     */
133    public abstract void setTranslationX(float translationX);
134
135    /**
136     * Sets the translationY value for the DisplayList
137     *
138     * @param translationY The translationY value of the DisplayList
139     * @see View#setTranslationY(float)
140     */
141    public abstract void setTranslationY(float translationY);
142
143    /**
144     * Sets the rotation value for the DisplayList
145     *
146     * @param rotation The rotation value of the DisplayList
147     * @see View#setRotation(float)
148     */
149    public abstract void setRotation(float rotation);
150
151    /**
152     * Sets the rotationX value for the DisplayList
153     *
154     * @param rotationX The rotationX value of the DisplayList
155     * @see View#setRotationX(float)
156     */
157    public abstract void setRotationX(float rotationX);
158
159    /**
160     * Sets the rotationY value for the DisplayList
161     *
162     * @param rotationY The rotationY value of the DisplayList
163     * @see View#setRotationY(float)
164     */
165    public abstract void setRotationY(float rotationY);
166
167    /**
168     * Sets the scaleX value for the DisplayList
169     *
170     * @param scaleX The scaleX value of the DisplayList
171     * @see View#setScaleX(float)
172     */
173    public abstract void setScaleX(float scaleX);
174
175    /**
176     * Sets the scaleY value for the DisplayList
177     *
178     * @param scaleY The scaleY value of the DisplayList
179     * @see View#setScaleY(float)
180     */
181    public abstract void setScaleY(float scaleY);
182
183    /**
184     * Sets all of the transform-related values of the View onto the DisplayList
185     *
186     * @param alpha The alpha value of the DisplayList
187     * @param translationX The translationX value of the DisplayList
188     * @param translationY The translationY value of the DisplayList
189     * @param rotation The rotation value of the DisplayList
190     * @param rotationX The rotationX value of the DisplayList
191     * @param rotationY The rotationY value of the DisplayList
192     * @param scaleX The scaleX value of the DisplayList
193     * @param scaleY The scaleY value of the DisplayList
194     */
195    public abstract void setTransformationInfo(float alpha, float translationX, float translationY,
196            float rotation, float rotationX, float rotationY, float scaleX, float scaleY);
197
198    /**
199     * Sets the pivotX value for the DisplayList
200     *
201     * @param pivotX The pivotX value of the DisplayList
202     * @see View#setPivotX(float)
203     */
204    public abstract void setPivotX(float pivotX);
205
206    /**
207     * Sets the pivotY value for the DisplayList
208     *
209     * @param pivotY The pivotY value of the DisplayList
210     * @see View#setPivotY(float)
211     */
212    public abstract void setPivotY(float pivotY);
213
214    /**
215     * Sets the camera distance for the DisplayList
216     *
217     * @param distance The distance in z of the camera of the DisplayList
218     * @see View#setCameraDistance(float)
219     */
220    public abstract void setCameraDistance(float distance);
221
222    /**
223     * Sets the left value for the DisplayList
224     *
225     * @param left The left value of the DisplayList
226     * @see View#setLeft(int)
227     */
228    public abstract void setLeft(int left);
229
230    /**
231     * Sets the top value for the DisplayList
232     *
233     * @param top The top value of the DisplayList
234     * @see View#setTop(int)
235     */
236    public abstract void setTop(int top);
237
238    /**
239     * Sets the right value for the DisplayList
240     *
241     * @param right The right value of the DisplayList
242     * @see View#setRight(int)
243     */
244    public abstract void setRight(int right);
245
246    /**
247     * Sets the bottom value for the DisplayList
248     *
249     * @param bottom The bottom value of the DisplayList
250     * @see View#setBottom(int)
251     */
252    public abstract void setBottom(int bottom);
253
254    /**
255     * Sets the left and top values for the DisplayList
256     *
257     * @param left The left value of the DisplayList
258     * @param top The top value of the DisplayList
259     * @see View#setLeft(int)
260     * @see View#setTop(int)
261     */
262    public abstract void setLeftTop(int left, int top);
263
264    /**
265     * Sets the left and top values for the DisplayList
266     *
267     * @param left The left value of the DisplayList
268     * @param top The top value of the DisplayList
269     * @see View#setLeft(int)
270     * @see View#setTop(int)
271     */
272    public abstract void setLeftTopRightBottom(int left, int top, int right, int bottom);
273
274    /**
275     * Offsets the left and right values for the DisplayList
276     *
277     * @param offset The amount that the left and right values of the DisplayList are offset
278     * @see View#offsetLeftAndRight(int)
279     */
280    public abstract void offsetLeftRight(int offset);
281
282    /**
283     * Offsets the top and bottom values for the DisplayList
284     *
285     * @param offset The amount that the top and bottom values of the DisplayList are offset
286     * @see View#offsetTopAndBottom(int)
287     */
288    public abstract void offsetTopBottom(int offset);
289}
290