Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 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 | |
| 17 | package android.view; |
| 18 | |
| 19 | import android.graphics.Bitmap; |
| 20 | import android.graphics.Canvas; |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 21 | import android.graphics.Paint; |
Romain Guy | 7d7b549 | 2011-01-24 16:33:45 -0800 | [diff] [blame] | 22 | import android.graphics.Rect; |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 23 | |
| 24 | /** |
Chet Haase | daf98e9 | 2011-01-10 14:10:36 -0800 | [diff] [blame] | 25 | * Hardware accelerated canvas. |
Romain Guy | 52036b1 | 2013-02-14 18:03:37 -0800 | [diff] [blame] | 26 | * |
| 27 | * @hide |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 28 | */ |
Chet Haase | daf98e9 | 2011-01-10 14:10:36 -0800 | [diff] [blame] | 29 | public abstract class HardwareCanvas extends Canvas { |
Romain Guy | ef35927 | 2013-01-31 19:07:29 -0800 | [diff] [blame] | 30 | private String mName; |
| 31 | |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 32 | @Override |
| 33 | public boolean isHardwareAccelerated() { |
| 34 | return true; |
| 35 | } |
| 36 | |
| 37 | @Override |
| 38 | public void setBitmap(Bitmap bitmap) { |
| 39 | throw new UnsupportedOperationException(); |
| 40 | } |
Romain Guy | ef35927 | 2013-01-31 19:07:29 -0800 | [diff] [blame] | 41 | |
| 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 Guy | 52036b1 | 2013-02-14 18:03:37 -0800 | [diff] [blame] | 49 | * |
| 50 | * @hide |
Romain Guy | ef35927 | 2013-01-31 19:07:29 -0800 | [diff] [blame] | 51 | */ |
| 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 Guy | 52036b1 | 2013-02-14 18:03:37 -0800 | [diff] [blame] | 62 | * |
| 63 | * @hide |
Romain Guy | ef35927 | 2013-01-31 19:07:29 -0800 | [diff] [blame] | 64 | */ |
| 65 | public String getName() { |
| 66 | return mName; |
| 67 | } |
| 68 | |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 69 | /** |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 70 | * Invoked before any drawing operation is performed in this canvas. |
Romain Guy | 7d7b549 | 2011-01-24 16:33:45 -0800 | [diff] [blame] | 71 | * |
| 72 | * @param dirty The dirty rectangle to update, can be null. |
Chet Haase | 44b2fe3 | 2012-06-06 19:03:58 -0700 | [diff] [blame] | 73 | * @return {@link DisplayList#STATUS_DREW} if anything was drawn (such as a call to clear |
Romain Guy | 52036b1 | 2013-02-14 18:03:37 -0800 | [diff] [blame] | 74 | * the canvas). |
| 75 | * |
| 76 | * @hide |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 77 | */ |
Chet Haase | 44b2fe3 | 2012-06-06 19:03:58 -0700 | [diff] [blame] | 78 | public abstract int onPreDraw(Rect dirty); |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 79 | |
| 80 | /** |
| 81 | * Invoked after all drawing operation have been performed. |
Romain Guy | 52036b1 | 2013-02-14 18:03:37 -0800 | [diff] [blame] | 82 | * |
| 83 | * @hide |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 84 | */ |
Gilles Debunne | b35ab7b | 2011-12-05 15:54:00 -0800 | [diff] [blame] | 85 | public abstract void onPostDraw(); |
Chet Haase | 1271e2c | 2012-04-20 09:54:27 -0700 | [diff] [blame] | 86 | |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 87 | /** |
Romain Guy | 52036b1 | 2013-02-14 18:03:37 -0800 | [diff] [blame] | 88 | * 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 Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 98 | * Draws the specified display list onto this canvas. |
Chet Haase | 1271e2c | 2012-04-20 09:54:27 -0700 | [diff] [blame] | 99 | * |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 100 | * @param displayList The display list to replay. |
Romain Guy | cabfcc1 | 2011-03-07 18:06:46 -0800 | [diff] [blame] | 101 | * @param dirty The dirty region to redraw in the next pass, matters only |
Romain Guy | 52036b1 | 2013-02-14 18:03:37 -0800 | [diff] [blame] | 102 | * if this method returns {@link DisplayList#STATUS_DRAW}, can be null. |
Romain Guy | 33f6beb | 2012-02-16 19:24:51 -0800 | [diff] [blame] | 103 | * @param flags Optional flags about drawing, see {@link DisplayList} for |
| 104 | * the possible flags. |
Romain Guy | 6554943 | 2012-03-26 16:45:05 -0700 | [diff] [blame] | 105 | * |
Chet Haase | 44b2fe3 | 2012-06-06 19:03:58 -0700 | [diff] [blame] | 106 | * @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 Guy | 52036b1 | 2013-02-14 18:03:37 -0800 | [diff] [blame] | 109 | * |
| 110 | * @hide |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 111 | */ |
Chet Haase | 1271e2c | 2012-04-20 09:54:27 -0700 | [diff] [blame] | 112 | public abstract int drawDisplayList(DisplayList displayList, Rect dirty, int flags); |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 113 | |
| 114 | /** |
Chet Haase | ed30fd8 | 2011-04-22 16:18:45 -0700 | [diff] [blame] | 115 | * 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 Guy | 52036b1 | 2013-02-14 18:03:37 -0800 | [diff] [blame] | 119 | * |
| 120 | * @hide |
Chet Haase | ed30fd8 | 2011-04-22 16:18:45 -0700 | [diff] [blame] | 121 | */ |
| 122 | abstract void outputDisplayList(DisplayList displayList); |
| 123 | |
| 124 | /** |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 125 | * Draws the specified layer onto this canvas. |
| 126 | * |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 127 | * @param layer The layer to composite on this canvas |
Romain Guy | ada830f | 2011-01-13 12:13:20 -0800 | [diff] [blame] | 128 | * @param x The left coordinate of the layer |
| 129 | * @param y The top coordinate of the layer |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 130 | * @param paint The paint used to draw the layer |
Romain Guy | 52036b1 | 2013-02-14 18:03:37 -0800 | [diff] [blame] | 131 | * |
| 132 | * @hide |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 133 | */ |
Chet Haase | daf98e9 | 2011-01-10 14:10:36 -0800 | [diff] [blame] | 134 | 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 Guy | 6554943 | 2012-03-26 16:45:05 -0700 | [diff] [blame] | 142 | * |
| 143 | * @return One of {@link DisplayList#STATUS_DONE}, {@link DisplayList#STATUS_DRAW} or |
| 144 | * {@link DisplayList#STATUS_INVOKE} |
Romain Guy | 52036b1 | 2013-02-14 18:03:37 -0800 | [diff] [blame] | 145 | * |
| 146 | * @hide |
Chet Haase | daf98e9 | 2011-01-10 14:10:36 -0800 | [diff] [blame] | 147 | */ |
Ashok Bhat | a039843 | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 148 | public int callDrawGLFunction(long drawGLFunction) { |
Chet Haase | daf98e9 | 2011-01-10 14:10:36 -0800 | [diff] [blame] | 149 | // Noop - this is done in the display list recorder subclass |
Romain Guy | 6554943 | 2012-03-26 16:45:05 -0700 | [diff] [blame] | 150 | return DisplayList.STATUS_DONE; |
Chet Haase | daf98e9 | 2011-01-10 14:10:36 -0800 | [diff] [blame] | 151 | } |
Romain Guy | 8f3b8e3 | 2012-03-27 16:33:45 -0700 | [diff] [blame] | 152 | |
| 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 Guy | 52036b1 | 2013-02-14 18:03:37 -0800 | [diff] [blame] | 160 | * |
| 161 | * @hide |
Romain Guy | 8f3b8e3 | 2012-03-27 16:33:45 -0700 | [diff] [blame] | 162 | */ |
| 163 | public int invokeFunctors(Rect dirty) { |
| 164 | return DisplayList.STATUS_DONE; |
| 165 | } |
Romain Guy | ba6be8a | 2012-04-23 18:22:09 -0700 | [diff] [blame] | 166 | |
| 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) |
Ashok Bhat | a039843 | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 173 | * @see #callDrawGLFunction(long) |
| 174 | * @see #detachFunctor(long) |
Romain Guy | 52036b1 | 2013-02-14 18:03:37 -0800 | [diff] [blame] | 175 | * |
| 176 | * @hide |
Romain Guy | ba6be8a | 2012-04-23 18:22:09 -0700 | [diff] [blame] | 177 | */ |
Ashok Bhat | a039843 | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 178 | abstract void detachFunctor(long functor); |
Romain Guy | ba6be8a | 2012-04-23 18:22:09 -0700 | [diff] [blame] | 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) |
Ashok Bhat | a039843 | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 186 | * @see #callDrawGLFunction(long) |
| 187 | * @see #detachFunctor(long) |
Romain Guy | 52036b1 | 2013-02-14 18:03:37 -0800 | [diff] [blame] | 188 | * |
| 189 | * @hide |
Romain Guy | ba6be8a | 2012-04-23 18:22:09 -0700 | [diff] [blame] | 190 | */ |
Ashok Bhat | a039843 | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 191 | abstract void attachFunctor(long functor); |
Romain Guy | 11cb642 | 2012-09-21 00:39:43 -0700 | [diff] [blame] | 192 | |
| 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 Guy | 52036b1 | 2013-02-14 18:03:37 -0800 | [diff] [blame] | 199 | * |
| 200 | * @hide |
Romain Guy | 11cb642 | 2012-09-21 00:39:43 -0700 | [diff] [blame] | 201 | */ |
| 202 | abstract void pushLayerUpdate(HardwareLayer layer); |
| 203 | |
| 204 | /** |
Romain Guy | e93482f | 2013-06-17 13:14:51 -0700 | [diff] [blame] | 205 | * Cancels a queued layer update. If the specified layer was not |
| 206 | * queued for update, this method has no effect. |
| 207 | * |
| 208 | * @param layer The layer whose update to cancel |
| 209 | * |
| 210 | * @see #pushLayerUpdate(HardwareLayer) |
| 211 | * @see #clearLayerUpdates() |
| 212 | * |
| 213 | * @hide |
| 214 | */ |
| 215 | abstract void cancelLayerUpdate(HardwareLayer layer); |
| 216 | |
| 217 | /** |
Romain Guy | 4054360 | 2013-06-12 15:31:28 -0700 | [diff] [blame] | 218 | * Immediately executes all enqueued layer updates. |
| 219 | * |
| 220 | * @see #pushLayerUpdate(HardwareLayer) |
| 221 | * |
| 222 | * @hide |
| 223 | */ |
| 224 | abstract void flushLayerUpdates(); |
| 225 | |
| 226 | /** |
Romain Guy | 11cb642 | 2012-09-21 00:39:43 -0700 | [diff] [blame] | 227 | * Removes all enqueued layer updates. |
| 228 | * |
Romain Guy | 52036b1 | 2013-02-14 18:03:37 -0800 | [diff] [blame] | 229 | * @see #pushLayerUpdate(HardwareLayer) |
| 230 | * |
| 231 | * @hide |
Romain Guy | 11cb642 | 2012-09-21 00:39:43 -0700 | [diff] [blame] | 232 | */ |
| 233 | abstract void clearLayerUpdates(); |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 234 | } |