blob: 0dfed69934a457e2325b63d6ade3ee5d26f4adf8 [file] [log] [blame]
Romain Guyb051e892010-09-28 19:09:36 -07001/*
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.graphics.Bitmap;
20import android.graphics.Canvas;
Romain Guy6c319ca2011-01-11 14:29:25 -080021import android.graphics.Paint;
Romain Guy7d7b5492011-01-24 16:33:45 -080022import android.graphics.Rect;
Romain Guyb051e892010-09-28 19:09:36 -070023
24/**
Chet Haasedaf98e92011-01-10 14:10:36 -080025 * Hardware accelerated canvas.
Romain Guy52036b12013-02-14 18:03:37 -080026 *
27 * @hide
Romain Guyb051e892010-09-28 19:09:36 -070028 */
Chet Haasedaf98e92011-01-10 14:10:36 -080029public abstract class HardwareCanvas extends Canvas {
Romain Guyef359272013-01-31 19:07:29 -080030 private String mName;
31
Romain Guyb051e892010-09-28 19:09:36 -070032 @Override
33 public boolean isHardwareAccelerated() {
34 return true;
35 }
36
37 @Override
38 public void setBitmap(Bitmap bitmap) {
39 throw new UnsupportedOperationException();
40 }
Romain Guyef359272013-01-31 19:07:29 -080041
42 /**
43 * Specifies the name of this canvas. Naming the canvas is entirely
44 * optional but can be useful for debugging purposes.
45 *
46 * @param name The name of the canvas, can be null
47 *
48 * @see #getName()
Romain Guy52036b12013-02-14 18:03:37 -080049 *
50 * @hide
Romain Guyef359272013-01-31 19:07:29 -080051 */
52 public void setName(String name) {
53 mName = name;
54 }
55
56 /**
57 * Returns the name of this canvas.
58 *
59 * @return The name of the canvas or null
60 *
61 * @see #setName(String)
Romain Guy52036b12013-02-14 18:03:37 -080062 *
63 * @hide
Romain Guyef359272013-01-31 19:07:29 -080064 */
65 public String getName() {
66 return mName;
67 }
68
Romain Guyb051e892010-09-28 19:09:36 -070069 /**
Romain Guyb051e892010-09-28 19:09:36 -070070 * Invoked before any drawing operation is performed in this canvas.
Romain Guy7d7b5492011-01-24 16:33:45 -080071 *
72 * @param dirty The dirty rectangle to update, can be null.
Chet Haase44b2fe32012-06-06 19:03:58 -070073 * @return {@link DisplayList#STATUS_DREW} if anything was drawn (such as a call to clear
Romain Guy52036b12013-02-14 18:03:37 -080074 * the canvas).
75 *
76 * @hide
Romain Guyb051e892010-09-28 19:09:36 -070077 */
Chet Haase44b2fe32012-06-06 19:03:58 -070078 public abstract int onPreDraw(Rect dirty);
Romain Guyb051e892010-09-28 19:09:36 -070079
80 /**
81 * Invoked after all drawing operation have been performed.
Romain Guy52036b12013-02-14 18:03:37 -080082 *
83 * @hide
Romain Guyb051e892010-09-28 19:09:36 -070084 */
Gilles Debunneb35ab7b2011-12-05 15:54:00 -080085 public abstract void onPostDraw();
Chet Haase1271e2c2012-04-20 09:54:27 -070086
Romain Guyb051e892010-09-28 19:09:36 -070087 /**
Romain Guy52036b12013-02-14 18:03:37 -080088 * Draws the specified display list onto this canvas. The display list can only
89 * be drawn if {@link android.view.DisplayList#isValid()} returns true.
90 *
91 * @param displayList The display list to replay.
92 */
93 public void drawDisplayList(DisplayList displayList) {
94 drawDisplayList(displayList, null, DisplayList.FLAG_CLIP_CHILDREN);
95 }
96
97 /**
Romain Guyb051e892010-09-28 19:09:36 -070098 * Draws the specified display list onto this canvas.
Chet Haase1271e2c2012-04-20 09:54:27 -070099 *
Romain Guyb051e892010-09-28 19:09:36 -0700100 * @param displayList The display list to replay.
Romain Guycabfcc12011-03-07 18:06:46 -0800101 * @param dirty The dirty region to redraw in the next pass, matters only
Romain Guy52036b12013-02-14 18:03:37 -0800102 * if this method returns {@link DisplayList#STATUS_DRAW}, can be null.
Romain Guy33f6beb2012-02-16 19:24:51 -0800103 * @param flags Optional flags about drawing, see {@link DisplayList} for
104 * the possible flags.
Romain Guy65549432012-03-26 16:45:05 -0700105 *
Chet Haase44b2fe32012-06-06 19:03:58 -0700106 * @return One of {@link DisplayList#STATUS_DONE}, {@link DisplayList#STATUS_DRAW}, or
107 * {@link DisplayList#STATUS_INVOKE}, or'd with {@link DisplayList#STATUS_DREW}
108 * if anything was drawn.
Romain Guy52036b12013-02-14 18:03:37 -0800109 *
110 * @hide
Romain Guyb051e892010-09-28 19:09:36 -0700111 */
Chet Haase1271e2c2012-04-20 09:54:27 -0700112 public abstract int drawDisplayList(DisplayList displayList, Rect dirty, int flags);
Romain Guy6c319ca2011-01-11 14:29:25 -0800113
114 /**
Chet Haaseed30fd82011-04-22 16:18:45 -0700115 * Outputs the specified display list to the log. This method exists for use by
116 * tools to output display lists for selected nodes to the log.
117 *
118 * @param displayList The display list to be logged.
Romain Guy52036b12013-02-14 18:03:37 -0800119 *
120 * @hide
Chet Haaseed30fd82011-04-22 16:18:45 -0700121 */
122 abstract void outputDisplayList(DisplayList displayList);
123
124 /**
Romain Guy6c319ca2011-01-11 14:29:25 -0800125 * Draws the specified layer onto this canvas.
126 *
Romain Guy6c319ca2011-01-11 14:29:25 -0800127 * @param layer The layer to composite on this canvas
Romain Guyada830f2011-01-13 12:13:20 -0800128 * @param x The left coordinate of the layer
129 * @param y The top coordinate of the layer
Romain Guy6c319ca2011-01-11 14:29:25 -0800130 * @param paint The paint used to draw the layer
Romain Guy52036b12013-02-14 18:03:37 -0800131 *
132 * @hide
Romain Guy6c319ca2011-01-11 14:29:25 -0800133 */
Chet Haasedaf98e92011-01-10 14:10:36 -0800134 abstract void drawHardwareLayer(HardwareLayer layer, float x, float y, Paint paint);
135
136 /**
137 * Calls the function specified with the drawGLFunction function pointer. This is
138 * functionality used by webkit for calling into their renderer from our display lists.
139 * This function may return true if an invalidation is needed after the call.
140 *
141 * @param drawGLFunction A native function pointer
Romain Guy65549432012-03-26 16:45:05 -0700142 *
143 * @return One of {@link DisplayList#STATUS_DONE}, {@link DisplayList#STATUS_DRAW} or
144 * {@link DisplayList#STATUS_INVOKE}
Romain Guy52036b12013-02-14 18:03:37 -0800145 *
146 * @hide
Chet Haasedaf98e92011-01-10 14:10:36 -0800147 */
Romain Guy65549432012-03-26 16:45:05 -0700148 public int callDrawGLFunction(int drawGLFunction) {
Chet Haasedaf98e92011-01-10 14:10:36 -0800149 // Noop - this is done in the display list recorder subclass
Romain Guy65549432012-03-26 16:45:05 -0700150 return DisplayList.STATUS_DONE;
Chet Haasedaf98e92011-01-10 14:10:36 -0800151 }
Romain Guy8f3b8e32012-03-27 16:33:45 -0700152
153 /**
154 * Invoke all the functors who requested to be invoked during the previous frame.
155 *
156 * @param dirty The region to redraw when the functors return {@link DisplayList#STATUS_DRAW}
157 *
158 * @return One of {@link DisplayList#STATUS_DONE}, {@link DisplayList#STATUS_DRAW} or
159 * {@link DisplayList#STATUS_INVOKE}
Romain Guy52036b12013-02-14 18:03:37 -0800160 *
161 * @hide
Romain Guy8f3b8e32012-03-27 16:33:45 -0700162 */
163 public int invokeFunctors(Rect dirty) {
164 return DisplayList.STATUS_DONE;
165 }
Romain Guyba6be8a2012-04-23 18:22:09 -0700166
167 /**
168 * Detaches the specified functor from the current functor execution queue.
169 *
170 * @param functor The native functor to remove from the execution queue.
171 *
172 * @see #invokeFunctors(android.graphics.Rect)
173 * @see #callDrawGLFunction(int)
Romain Guy52036b12013-02-14 18:03:37 -0800174 * @see #detachFunctor(int)
175 *
176 * @hide
Romain Guyba6be8a2012-04-23 18:22:09 -0700177 */
178 abstract void detachFunctor(int functor);
179
180 /**
181 * Attaches the specified functor to the current functor execution queue.
182 *
183 * @param functor The native functor to add to the execution queue.
184 *
185 * @see #invokeFunctors(android.graphics.Rect)
186 * @see #callDrawGLFunction(int)
Romain Guy52036b12013-02-14 18:03:37 -0800187 * @see #detachFunctor(int)
188 *
189 * @hide
Romain Guyba6be8a2012-04-23 18:22:09 -0700190 */
191 abstract void attachFunctor(int functor);
Romain Guy11cb6422012-09-21 00:39:43 -0700192
193 /**
194 * Indicates that the specified layer must be updated as soon as possible.
195 *
196 * @param layer The layer to update
197 *
198 * @see #clearLayerUpdates()
Romain Guy52036b12013-02-14 18:03:37 -0800199 *
200 * @hide
Romain Guy11cb6422012-09-21 00:39:43 -0700201 */
202 abstract void pushLayerUpdate(HardwareLayer layer);
203
204 /**
205 * Removes all enqueued layer updates.
206 *
Romain Guy52036b12013-02-14 18:03:37 -0800207 * @see #pushLayerUpdate(HardwareLayer)
208 *
209 * @hide
Romain Guy11cb6422012-09-21 00:39:43 -0700210 */
211 abstract void clearLayerUpdates();
Romain Guyb051e892010-09-28 19:09:36 -0700212}