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 | |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 31 | @Override |
| 32 | public boolean isHardwareAccelerated() { |
| 33 | return true; |
| 34 | } |
| 35 | |
| 36 | @Override |
| 37 | public void setBitmap(Bitmap bitmap) { |
| 38 | throw new UnsupportedOperationException(); |
| 39 | } |
Romain Guy | ef35927 | 2013-01-31 19:07:29 -0800 | [diff] [blame] | 40 | |
| 41 | /** |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 42 | * Invoked before any drawing operation is performed in this canvas. |
Romain Guy | 7d7b549 | 2011-01-24 16:33:45 -0800 | [diff] [blame] | 43 | * |
| 44 | * @param dirty The dirty rectangle to update, can be null. |
John Reck | f666ad7 | 2014-03-14 16:24:57 -0700 | [diff] [blame] | 45 | * @return {@link RenderNode#STATUS_DREW} if anything was drawn (such as a call to clear |
Romain Guy | 52036b1 | 2013-02-14 18:03:37 -0800 | [diff] [blame] | 46 | * the canvas). |
| 47 | * |
| 48 | * @hide |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 49 | */ |
Chet Haase | 44b2fe3 | 2012-06-06 19:03:58 -0700 | [diff] [blame] | 50 | public abstract int onPreDraw(Rect dirty); |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 51 | |
| 52 | /** |
| 53 | * Invoked after all drawing operation have been performed. |
Romain Guy | 52036b1 | 2013-02-14 18:03:37 -0800 | [diff] [blame] | 54 | * |
| 55 | * @hide |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 56 | */ |
Gilles Debunne | b35ab7b | 2011-12-05 15:54:00 -0800 | [diff] [blame] | 57 | public abstract void onPostDraw(); |
Chet Haase | 1271e2c | 2012-04-20 09:54:27 -0700 | [diff] [blame] | 58 | |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 59 | /** |
Romain Guy | 52036b1 | 2013-02-14 18:03:37 -0800 | [diff] [blame] | 60 | * Draws the specified display list onto this canvas. The display list can only |
John Reck | f666ad7 | 2014-03-14 16:24:57 -0700 | [diff] [blame] | 61 | * be drawn if {@link android.view.RenderNode#isValid()} returns true. |
Romain Guy | 52036b1 | 2013-02-14 18:03:37 -0800 | [diff] [blame] | 62 | * |
| 63 | * @param displayList The display list to replay. |
| 64 | */ |
John Reck | f666ad7 | 2014-03-14 16:24:57 -0700 | [diff] [blame] | 65 | public void drawDisplayList(RenderNode displayList) { |
| 66 | drawDisplayList(displayList, null, RenderNode.FLAG_CLIP_CHILDREN); |
Romain Guy | 52036b1 | 2013-02-14 18:03:37 -0800 | [diff] [blame] | 67 | } |
| 68 | |
| 69 | /** |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 70 | * Draws the specified display list onto this canvas. |
Chet Haase | 1271e2c | 2012-04-20 09:54:27 -0700 | [diff] [blame] | 71 | * |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 72 | * @param displayList The display list to replay. |
Romain Guy | cabfcc1 | 2011-03-07 18:06:46 -0800 | [diff] [blame] | 73 | * @param dirty The dirty region to redraw in the next pass, matters only |
John Reck | f666ad7 | 2014-03-14 16:24:57 -0700 | [diff] [blame] | 74 | * if this method returns {@link RenderNode#STATUS_DRAW}, can be null. |
| 75 | * @param flags Optional flags about drawing, see {@link RenderNode} for |
Romain Guy | 33f6beb | 2012-02-16 19:24:51 -0800 | [diff] [blame] | 76 | * the possible flags. |
Romain Guy | 6554943 | 2012-03-26 16:45:05 -0700 | [diff] [blame] | 77 | * |
John Reck | f666ad7 | 2014-03-14 16:24:57 -0700 | [diff] [blame] | 78 | * @return One of {@link RenderNode#STATUS_DONE}, {@link RenderNode#STATUS_DRAW}, or |
| 79 | * {@link RenderNode#STATUS_INVOKE}, or'd with {@link RenderNode#STATUS_DREW} |
Chet Haase | 44b2fe3 | 2012-06-06 19:03:58 -0700 | [diff] [blame] | 80 | * if anything was drawn. |
Romain Guy | 52036b1 | 2013-02-14 18:03:37 -0800 | [diff] [blame] | 81 | * |
| 82 | * @hide |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 83 | */ |
John Reck | f666ad7 | 2014-03-14 16:24:57 -0700 | [diff] [blame] | 84 | public abstract int drawDisplayList(RenderNode displayList, Rect dirty, int flags); |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 85 | |
| 86 | /** |
| 87 | * Draws the specified layer onto this canvas. |
| 88 | * |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 89 | * @param layer The layer to composite on this canvas |
Romain Guy | ada830f | 2011-01-13 12:13:20 -0800 | [diff] [blame] | 90 | * @param x The left coordinate of the layer |
| 91 | * @param y The top coordinate of the layer |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 92 | * @param paint The paint used to draw the layer |
Romain Guy | 52036b1 | 2013-02-14 18:03:37 -0800 | [diff] [blame] | 93 | * |
| 94 | * @hide |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 95 | */ |
Chet Haase | daf98e9 | 2011-01-10 14:10:36 -0800 | [diff] [blame] | 96 | 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 Guy | 6554943 | 2012-03-26 16:45:05 -0700 | [diff] [blame] | 104 | * |
John Reck | f666ad7 | 2014-03-14 16:24:57 -0700 | [diff] [blame] | 105 | * @return One of {@link RenderNode#STATUS_DONE}, {@link RenderNode#STATUS_DRAW} or |
| 106 | * {@link RenderNode#STATUS_INVOKE} |
Romain Guy | 52036b1 | 2013-02-14 18:03:37 -0800 | [diff] [blame] | 107 | * |
| 108 | * @hide |
Chet Haase | daf98e9 | 2011-01-10 14:10:36 -0800 | [diff] [blame] | 109 | */ |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 110 | public int callDrawGLFunction(long drawGLFunction) { |
Chet Haase | daf98e9 | 2011-01-10 14:10:36 -0800 | [diff] [blame] | 111 | // Noop - this is done in the display list recorder subclass |
John Reck | f666ad7 | 2014-03-14 16:24:57 -0700 | [diff] [blame] | 112 | return RenderNode.STATUS_DONE; |
Chet Haase | daf98e9 | 2011-01-10 14:10:36 -0800 | [diff] [blame] | 113 | } |
Romain Guy | 8f3b8e3 | 2012-03-27 16:33:45 -0700 | [diff] [blame] | 114 | |
| 115 | /** |
| 116 | * Invoke all the functors who requested to be invoked during the previous frame. |
| 117 | * |
John Reck | f666ad7 | 2014-03-14 16:24:57 -0700 | [diff] [blame] | 118 | * @param dirty The region to redraw when the functors return {@link RenderNode#STATUS_DRAW} |
Romain Guy | 8f3b8e3 | 2012-03-27 16:33:45 -0700 | [diff] [blame] | 119 | * |
John Reck | f666ad7 | 2014-03-14 16:24:57 -0700 | [diff] [blame] | 120 | * @return One of {@link RenderNode#STATUS_DONE}, {@link RenderNode#STATUS_DRAW} or |
| 121 | * {@link RenderNode#STATUS_INVOKE} |
Romain Guy | 52036b1 | 2013-02-14 18:03:37 -0800 | [diff] [blame] | 122 | * |
| 123 | * @hide |
Romain Guy | 8f3b8e3 | 2012-03-27 16:33:45 -0700 | [diff] [blame] | 124 | */ |
| 125 | public int invokeFunctors(Rect dirty) { |
John Reck | f666ad7 | 2014-03-14 16:24:57 -0700 | [diff] [blame] | 126 | return RenderNode.STATUS_DONE; |
Romain Guy | 8f3b8e3 | 2012-03-27 16:33:45 -0700 | [diff] [blame] | 127 | } |
Romain Guy | ba6be8a | 2012-04-23 18:22:09 -0700 | [diff] [blame] | 128 | |
| 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 Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 135 | * @see #callDrawGLFunction(long) |
| 136 | * @see #detachFunctor(long) |
Romain Guy | 52036b1 | 2013-02-14 18:03:37 -0800 | [diff] [blame] | 137 | * |
| 138 | * @hide |
Romain Guy | ba6be8a | 2012-04-23 18:22:09 -0700 | [diff] [blame] | 139 | */ |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 140 | abstract void detachFunctor(long functor); |
Romain Guy | ba6be8a | 2012-04-23 18:22:09 -0700 | [diff] [blame] | 141 | |
| 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 Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 148 | * @see #callDrawGLFunction(long) |
| 149 | * @see #detachFunctor(long) |
Romain Guy | 52036b1 | 2013-02-14 18:03:37 -0800 | [diff] [blame] | 150 | * |
| 151 | * @hide |
Romain Guy | ba6be8a | 2012-04-23 18:22:09 -0700 | [diff] [blame] | 152 | */ |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 153 | abstract void attachFunctor(long functor); |
Romain Guy | 11cb642 | 2012-09-21 00:39:43 -0700 | [diff] [blame] | 154 | |
| 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 Guy | 52036b1 | 2013-02-14 18:03:37 -0800 | [diff] [blame] | 161 | * |
| 162 | * @hide |
Romain Guy | 11cb642 | 2012-09-21 00:39:43 -0700 | [diff] [blame] | 163 | */ |
| 164 | abstract void pushLayerUpdate(HardwareLayer layer); |
| 165 | |
| 166 | /** |
Romain Guy | e93482f | 2013-06-17 13:14:51 -0700 | [diff] [blame] | 167 | * 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 Guy | 4054360 | 2013-06-12 15:31:28 -0700 | [diff] [blame] | 180 | * Immediately executes all enqueued layer updates. |
| 181 | * |
| 182 | * @see #pushLayerUpdate(HardwareLayer) |
| 183 | * |
| 184 | * @hide |
| 185 | */ |
| 186 | abstract void flushLayerUpdates(); |
| 187 | |
| 188 | /** |
Romain Guy | 11cb642 | 2012-09-21 00:39:43 -0700 | [diff] [blame] | 189 | * Removes all enqueued layer updates. |
| 190 | * |
Romain Guy | 52036b1 | 2013-02-14 18:03:37 -0800 | [diff] [blame] | 191 | * @see #pushLayerUpdate(HardwareLayer) |
| 192 | * |
| 193 | * @hide |
Romain Guy | 11cb642 | 2012-09-21 00:39:43 -0700 | [diff] [blame] | 194 | */ |
| 195 | abstract void clearLayerUpdates(); |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 196 | } |