blob: a3c7b638c196842fb421cb8eadf876e64e0ea141 [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
Romain Guyb051e892010-09-28 19:09:36 -070031 @Override
32 public boolean isHardwareAccelerated() {
33 return true;
34 }
35
36 @Override
37 public void setBitmap(Bitmap bitmap) {
38 throw new UnsupportedOperationException();
39 }
Romain Guyef359272013-01-31 19:07:29 -080040
41 /**
Romain Guyb051e892010-09-28 19:09:36 -070042 * Invoked before any drawing operation is performed in this canvas.
Romain Guy7d7b5492011-01-24 16:33:45 -080043 *
44 * @param dirty The dirty rectangle to update, can be null.
Chet Haase44b2fe32012-06-06 19:03:58 -070045 * @return {@link DisplayList#STATUS_DREW} if anything was drawn (such as a call to clear
Romain Guy52036b12013-02-14 18:03:37 -080046 * the canvas).
47 *
48 * @hide
Romain Guyb051e892010-09-28 19:09:36 -070049 */
Chet Haase44b2fe32012-06-06 19:03:58 -070050 public abstract int onPreDraw(Rect dirty);
Romain Guyb051e892010-09-28 19:09:36 -070051
52 /**
53 * Invoked after all drawing operation have been performed.
Romain Guy52036b12013-02-14 18:03:37 -080054 *
55 * @hide
Romain Guyb051e892010-09-28 19:09:36 -070056 */
Gilles Debunneb35ab7b2011-12-05 15:54:00 -080057 public abstract void onPostDraw();
Chet Haase1271e2c2012-04-20 09:54:27 -070058
Romain Guyb051e892010-09-28 19:09:36 -070059 /**
Romain Guy52036b12013-02-14 18:03:37 -080060 * Draws the specified display list onto this canvas. The display list can only
61 * be drawn if {@link android.view.DisplayList#isValid()} returns true.
62 *
63 * @param displayList The display list to replay.
64 */
65 public void drawDisplayList(DisplayList displayList) {
66 drawDisplayList(displayList, null, DisplayList.FLAG_CLIP_CHILDREN);
67 }
68
69 /**
Romain Guyb051e892010-09-28 19:09:36 -070070 * Draws the specified display list onto this canvas.
Chet Haase1271e2c2012-04-20 09:54:27 -070071 *
Romain Guyb051e892010-09-28 19:09:36 -070072 * @param displayList The display list to replay.
Romain Guycabfcc12011-03-07 18:06:46 -080073 * @param dirty The dirty region to redraw in the next pass, matters only
Romain Guy52036b12013-02-14 18:03:37 -080074 * if this method returns {@link DisplayList#STATUS_DRAW}, can be null.
Romain Guy33f6beb2012-02-16 19:24:51 -080075 * @param flags Optional flags about drawing, see {@link DisplayList} for
76 * the possible flags.
Romain Guy65549432012-03-26 16:45:05 -070077 *
Chet Haase44b2fe32012-06-06 19:03:58 -070078 * @return One of {@link DisplayList#STATUS_DONE}, {@link DisplayList#STATUS_DRAW}, or
79 * {@link DisplayList#STATUS_INVOKE}, or'd with {@link DisplayList#STATUS_DREW}
80 * if anything was drawn.
Romain Guy52036b12013-02-14 18:03:37 -080081 *
82 * @hide
Romain Guyb051e892010-09-28 19:09:36 -070083 */
Chet Haase1271e2c2012-04-20 09:54:27 -070084 public abstract int drawDisplayList(DisplayList displayList, Rect dirty, int flags);
Romain Guy6c319ca2011-01-11 14:29:25 -080085
86 /**
87 * Draws the specified layer onto this canvas.
88 *
Romain Guy6c319ca2011-01-11 14:29:25 -080089 * @param layer The layer to composite on this canvas
Romain Guyada830f2011-01-13 12:13:20 -080090 * @param x The left coordinate of the layer
91 * @param y The top coordinate of the layer
Romain Guy6c319ca2011-01-11 14:29:25 -080092 * @param paint The paint used to draw the layer
Romain Guy52036b12013-02-14 18:03:37 -080093 *
94 * @hide
Romain Guy6c319ca2011-01-11 14:29:25 -080095 */
Chet Haasedaf98e92011-01-10 14:10:36 -080096 abstract void drawHardwareLayer(HardwareLayer layer, float x, float y, Paint paint);
97
98 /**
99 * Calls the function specified with the drawGLFunction function pointer. This is
100 * functionality used by webkit for calling into their renderer from our display lists.
101 * This function may return true if an invalidation is needed after the call.
102 *
103 * @param drawGLFunction A native function pointer
Romain Guy65549432012-03-26 16:45:05 -0700104 *
105 * @return One of {@link DisplayList#STATUS_DONE}, {@link DisplayList#STATUS_DRAW} or
106 * {@link DisplayList#STATUS_INVOKE}
Romain Guy52036b12013-02-14 18:03:37 -0800107 *
108 * @hide
Chet Haasedaf98e92011-01-10 14:10:36 -0800109 */
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000110 public int callDrawGLFunction(long drawGLFunction) {
Chet Haasedaf98e92011-01-10 14:10:36 -0800111 // Noop - this is done in the display list recorder subclass
Romain Guy65549432012-03-26 16:45:05 -0700112 return DisplayList.STATUS_DONE;
Chet Haasedaf98e92011-01-10 14:10:36 -0800113 }
Romain Guy8f3b8e32012-03-27 16:33:45 -0700114
115 /**
116 * Invoke all the functors who requested to be invoked during the previous frame.
117 *
118 * @param dirty The region to redraw when the functors return {@link DisplayList#STATUS_DRAW}
119 *
120 * @return One of {@link DisplayList#STATUS_DONE}, {@link DisplayList#STATUS_DRAW} or
121 * {@link DisplayList#STATUS_INVOKE}
Romain Guy52036b12013-02-14 18:03:37 -0800122 *
123 * @hide
Romain Guy8f3b8e32012-03-27 16:33:45 -0700124 */
125 public int invokeFunctors(Rect dirty) {
126 return DisplayList.STATUS_DONE;
127 }
Romain Guyba6be8a2012-04-23 18:22:09 -0700128
129 /**
130 * Detaches the specified functor from the current functor execution queue.
131 *
132 * @param functor The native functor to remove from the execution queue.
133 *
134 * @see #invokeFunctors(android.graphics.Rect)
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000135 * @see #callDrawGLFunction(long)
136 * @see #detachFunctor(long)
Romain Guy52036b12013-02-14 18:03:37 -0800137 *
138 * @hide
Romain Guyba6be8a2012-04-23 18:22:09 -0700139 */
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000140 abstract void detachFunctor(long functor);
Romain Guyba6be8a2012-04-23 18:22:09 -0700141
142 /**
143 * Attaches the specified functor to the current functor execution queue.
144 *
145 * @param functor The native functor to add to the execution queue.
146 *
147 * @see #invokeFunctors(android.graphics.Rect)
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000148 * @see #callDrawGLFunction(long)
149 * @see #detachFunctor(long)
Romain Guy52036b12013-02-14 18:03:37 -0800150 *
151 * @hide
Romain Guyba6be8a2012-04-23 18:22:09 -0700152 */
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000153 abstract void attachFunctor(long functor);
Romain Guy11cb6422012-09-21 00:39:43 -0700154
155 /**
156 * Indicates that the specified layer must be updated as soon as possible.
157 *
158 * @param layer The layer to update
159 *
160 * @see #clearLayerUpdates()
Romain Guy52036b12013-02-14 18:03:37 -0800161 *
162 * @hide
Romain Guy11cb6422012-09-21 00:39:43 -0700163 */
164 abstract void pushLayerUpdate(HardwareLayer layer);
165
166 /**
Romain Guye93482f2013-06-17 13:14:51 -0700167 * Cancels a queued layer update. If the specified layer was not
168 * queued for update, this method has no effect.
169 *
170 * @param layer The layer whose update to cancel
171 *
172 * @see #pushLayerUpdate(HardwareLayer)
173 * @see #clearLayerUpdates()
174 *
175 * @hide
176 */
177 abstract void cancelLayerUpdate(HardwareLayer layer);
178
179 /**
Romain Guy40543602013-06-12 15:31:28 -0700180 * Immediately executes all enqueued layer updates.
181 *
182 * @see #pushLayerUpdate(HardwareLayer)
183 *
184 * @hide
185 */
186 abstract void flushLayerUpdates();
187
188 /**
Romain Guy11cb6422012-09-21 00:39:43 -0700189 * Removes all enqueued layer updates.
190 *
Romain Guy52036b12013-02-14 18:03:37 -0800191 * @see #pushLayerUpdate(HardwareLayer)
192 *
193 * @hide
Romain Guy11cb6422012-09-21 00:39:43 -0700194 */
195 abstract void clearLayerUpdates();
Romain Guyb051e892010-09-28 19:09:36 -0700196}