Romain Guy | e4d0112 | 2010-06-16 18:44:05 -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 | |
Chris Craik | c9070eb | 2015-03-09 18:50:14 -0700 | [diff] [blame] | 19 | import android.annotation.NonNull; |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 20 | import android.graphics.Bitmap; |
Chris Craik | f6829a0 | 2015-03-10 10:28:59 -0700 | [diff] [blame] | 21 | import android.graphics.Canvas; |
John Reck | 52244ff | 2014-05-01 21:27:37 -0700 | [diff] [blame] | 22 | import android.graphics.CanvasProperty; |
Romain Guy | 3b748a4 | 2013-04-17 18:54:38 -0700 | [diff] [blame] | 23 | import android.graphics.NinePatch; |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 24 | import android.graphics.Paint; |
| 25 | import android.graphics.Path; |
| 26 | import android.graphics.Picture; |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 27 | import android.graphics.Rect; |
| 28 | import android.graphics.RectF; |
Chris Craik | c9070eb | 2015-03-09 18:50:14 -0700 | [diff] [blame] | 29 | import android.util.Pools.SynchronizedPool; |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 30 | |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 31 | /** |
Chris Craik | c9070eb | 2015-03-09 18:50:14 -0700 | [diff] [blame] | 32 | * An implementation of a GL canvas that records drawing operations. |
| 33 | * This is intended for use with a DisplayList. This class keeps a list of all the Paint and |
| 34 | * Bitmap objects that it draws, preventing the backing memory of Bitmaps from being freed while |
| 35 | * the DisplayList is still holding a native reference to the memory. |
Chris Craik | f6829a0 | 2015-03-10 10:28:59 -0700 | [diff] [blame] | 36 | * |
| 37 | * @hide |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 38 | */ |
Chris Craik | f6829a0 | 2015-03-10 10:28:59 -0700 | [diff] [blame] | 39 | public class DisplayListCanvas extends Canvas { |
Chris Craik | c9070eb | 2015-03-09 18:50:14 -0700 | [diff] [blame] | 40 | // The recording canvas pool should be large enough to handle a deeply nested |
| 41 | // view hierarchy because display lists are generated recursively. |
| 42 | private static final int POOL_LIMIT = 25; |
| 43 | |
| 44 | private static final SynchronizedPool<DisplayListCanvas> sPool = |
| 45 | new SynchronizedPool<DisplayListCanvas>(POOL_LIMIT); |
| 46 | |
| 47 | RenderNode mNode; |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 48 | private int mWidth; |
| 49 | private int mHeight; |
Raph Levien | 051910b | 2014-06-15 18:25:29 -0700 | [diff] [blame] | 50 | |
Chris Craik | c9070eb | 2015-03-09 18:50:14 -0700 | [diff] [blame] | 51 | static DisplayListCanvas obtain(@NonNull RenderNode node) { |
| 52 | if (node == null) throw new IllegalArgumentException("node cannot be null"); |
| 53 | DisplayListCanvas canvas = sPool.acquire(); |
| 54 | if (canvas == null) { |
| 55 | canvas = new DisplayListCanvas(); |
| 56 | } |
| 57 | canvas.mNode = node; |
| 58 | return canvas; |
| 59 | } |
| 60 | |
| 61 | void recycle() { |
| 62 | mNode = null; |
| 63 | sPool.release(this); |
| 64 | } |
| 65 | |
| 66 | long finishRecording() { |
| 67 | return nFinishRecording(mNativeCanvasWrapper); |
| 68 | } |
| 69 | |
| 70 | @Override |
| 71 | public boolean isRecordingFor(Object o) { |
| 72 | return o == mNode; |
| 73 | } |
Romain Guy | 6926c72 | 2010-07-12 20:20:03 -0700 | [diff] [blame] | 74 | |
Romain Guy | 1639351 | 2010-08-08 00:14:31 -0700 | [diff] [blame] | 75 | /////////////////////////////////////////////////////////////////////////// |
| 76 | // JNI |
| 77 | /////////////////////////////////////////////////////////////////////////// |
| 78 | |
| 79 | private static native boolean nIsAvailable(); |
| 80 | private static boolean sIsAvailable = nIsAvailable(); |
| 81 | |
| 82 | static boolean isAvailable() { |
| 83 | return sIsAvailable; |
| 84 | } |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 85 | |
| 86 | /////////////////////////////////////////////////////////////////////////// |
| 87 | // Constructors |
| 88 | /////////////////////////////////////////////////////////////////////////// |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 89 | |
Chris Craik | c9070eb | 2015-03-09 18:50:14 -0700 | [diff] [blame] | 90 | private DisplayListCanvas() { |
Chris Craik | db663fe | 2015-04-20 13:34:45 -0700 | [diff] [blame] | 91 | super(nCreateDisplayListCanvas()); |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 92 | } |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 93 | |
Chris Craik | db663fe | 2015-04-20 13:34:45 -0700 | [diff] [blame] | 94 | private static native long nCreateDisplayListCanvas(); |
Romain Guy | ce0537b | 2010-06-29 21:05:21 -0700 | [diff] [blame] | 95 | |
Chris Craik | ba9b613 | 2013-12-15 17:10:19 -0800 | [diff] [blame] | 96 | public static void setProperty(String name, String value) { |
| 97 | nSetProperty(name, value); |
| 98 | } |
| 99 | |
| 100 | private static native void nSetProperty(String name, String value); |
| 101 | |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 102 | /////////////////////////////////////////////////////////////////////////// |
| 103 | // Canvas management |
| 104 | /////////////////////////////////////////////////////////////////////////// |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 105 | |
| 106 | @Override |
Chris Craik | f6829a0 | 2015-03-10 10:28:59 -0700 | [diff] [blame] | 107 | public boolean isHardwareAccelerated() { |
| 108 | return true; |
| 109 | } |
| 110 | |
| 111 | @Override |
| 112 | public void setBitmap(Bitmap bitmap) { |
| 113 | throw new UnsupportedOperationException(); |
| 114 | } |
| 115 | |
| 116 | @Override |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 117 | public boolean isOpaque() { |
Tom Hudson | 8dfaa49 | 2014-12-09 15:03:44 -0500 | [diff] [blame] | 118 | return false; |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 119 | } |
| 120 | |
| 121 | @Override |
| 122 | public int getWidth() { |
| 123 | return mWidth; |
| 124 | } |
| 125 | |
| 126 | @Override |
| 127 | public int getHeight() { |
| 128 | return mHeight; |
| 129 | } |
| 130 | |
Romain Guy | f61970fc | 2011-07-07 14:10:06 -0700 | [diff] [blame] | 131 | @Override |
| 132 | public int getMaximumBitmapWidth() { |
| 133 | return nGetMaximumTextureWidth(); |
| 134 | } |
| 135 | |
| 136 | @Override |
| 137 | public int getMaximumBitmapHeight() { |
| 138 | return nGetMaximumTextureHeight(); |
| 139 | } |
| 140 | |
| 141 | private static native int nGetMaximumTextureWidth(); |
Romain Guy | 530041d | 2012-01-25 18:56:29 -0800 | [diff] [blame] | 142 | private static native int nGetMaximumTextureHeight(); |
Romain Guy | f61970fc | 2011-07-07 14:10:06 -0700 | [diff] [blame] | 143 | |
Romain Guy | 2bf68f0 | 2012-03-02 13:37:47 -0800 | [diff] [blame] | 144 | /** |
| 145 | * Returns the native OpenGLRenderer object. |
| 146 | */ |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 147 | long getRenderer() { |
Tom Hudson | 8dfaa49 | 2014-12-09 15:03:44 -0500 | [diff] [blame] | 148 | return mNativeCanvasWrapper; |
Romain Guy | 2bf68f0 | 2012-03-02 13:37:47 -0800 | [diff] [blame] | 149 | } |
| 150 | |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 151 | /////////////////////////////////////////////////////////////////////////// |
| 152 | // Setup |
| 153 | /////////////////////////////////////////////////////////////////////////// |
| 154 | |
| 155 | @Override |
| 156 | public void setViewport(int width, int height) { |
| 157 | mWidth = width; |
| 158 | mHeight = height; |
| 159 | |
Tom Hudson | 8dfaa49 | 2014-12-09 15:03:44 -0500 | [diff] [blame] | 160 | nSetViewport(mNativeCanvasWrapper, width, height); |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 161 | } |
Raph Levien | 051910b | 2014-06-15 18:25:29 -0700 | [diff] [blame] | 162 | |
Chris Craik | cce47eb | 2014-07-16 15:12:15 -0700 | [diff] [blame] | 163 | private static native void nSetViewport(long renderer, |
| 164 | int width, int height); |
| 165 | |
| 166 | @Override |
| 167 | public void setHighContrastText(boolean highContrastText) { |
Tom Hudson | 8dfaa49 | 2014-12-09 15:03:44 -0500 | [diff] [blame] | 168 | nSetHighContrastText(mNativeCanvasWrapper, highContrastText); |
Chris Craik | cce47eb | 2014-07-16 15:12:15 -0700 | [diff] [blame] | 169 | } |
| 170 | |
| 171 | private static native void nSetHighContrastText(long renderer, boolean highContrastText); |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 172 | |
Romain Guy | 7d7b549 | 2011-01-24 16:33:45 -0800 | [diff] [blame] | 173 | @Override |
Chris Craik | 8afd0f2 | 2014-08-21 17:41:57 -0700 | [diff] [blame] | 174 | public void insertReorderBarrier() { |
Tom Hudson | 8dfaa49 | 2014-12-09 15:03:44 -0500 | [diff] [blame] | 175 | nInsertReorderBarrier(mNativeCanvasWrapper, true); |
Chris Craik | 8afd0f2 | 2014-08-21 17:41:57 -0700 | [diff] [blame] | 176 | } |
| 177 | |
| 178 | @Override |
| 179 | public void insertInorderBarrier() { |
Tom Hudson | 8dfaa49 | 2014-12-09 15:03:44 -0500 | [diff] [blame] | 180 | nInsertReorderBarrier(mNativeCanvasWrapper, false); |
Chris Craik | 8afd0f2 | 2014-08-21 17:41:57 -0700 | [diff] [blame] | 181 | } |
| 182 | |
| 183 | private static native void nInsertReorderBarrier(long renderer, boolean enableReorder); |
| 184 | |
Chris Craik | f6829a0 | 2015-03-10 10:28:59 -0700 | [diff] [blame] | 185 | /** |
| 186 | * Invoked before any drawing operation is performed in this canvas. |
| 187 | * |
| 188 | * @param dirty The dirty rectangle to update, can be null. |
| 189 | */ |
Tom Hudson | 107843d | 2014-09-08 11:26:26 -0400 | [diff] [blame] | 190 | public void onPreDraw(Rect dirty) { |
Romain Guy | 7d7b549 | 2011-01-24 16:33:45 -0800 | [diff] [blame] | 191 | if (dirty != null) { |
Tom Hudson | 8dfaa49 | 2014-12-09 15:03:44 -0500 | [diff] [blame] | 192 | nPrepareDirty(mNativeCanvasWrapper, dirty.left, dirty.top, dirty.right, dirty.bottom); |
Romain Guy | 7d7b549 | 2011-01-24 16:33:45 -0800 | [diff] [blame] | 193 | } else { |
Tom Hudson | 8dfaa49 | 2014-12-09 15:03:44 -0500 | [diff] [blame] | 194 | nPrepare(mNativeCanvasWrapper); |
Romain Guy | 7d7b549 | 2011-01-24 16:33:45 -0800 | [diff] [blame] | 195 | } |
| 196 | } |
| 197 | |
Tom Hudson | 8dfaa49 | 2014-12-09 15:03:44 -0500 | [diff] [blame] | 198 | private static native void nPrepare(long renderer); |
| 199 | private static native void nPrepareDirty(long renderer, int left, int top, int right, int bottom); |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 200 | |
Chris Craik | f6829a0 | 2015-03-10 10:28:59 -0700 | [diff] [blame] | 201 | /** |
| 202 | * Invoked after all drawing operation have been performed. |
| 203 | */ |
Gilles Debunne | b35ab7b | 2011-12-05 15:54:00 -0800 | [diff] [blame] | 204 | public void onPostDraw() { |
Tom Hudson | 8dfaa49 | 2014-12-09 15:03:44 -0500 | [diff] [blame] | 205 | nFinish(mNativeCanvasWrapper); |
Romain Guy | b025b9c | 2010-09-16 14:16:48 -0700 | [diff] [blame] | 206 | } |
Romain Guy | 9ace8f5 | 2011-07-07 20:50:11 -0700 | [diff] [blame] | 207 | |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 208 | private static native void nFinish(long renderer); |
Romain Guy | b025b9c | 2010-09-16 14:16:48 -0700 | [diff] [blame] | 209 | |
Romain Guy | 530041d | 2012-01-25 18:56:29 -0800 | [diff] [blame] | 210 | /////////////////////////////////////////////////////////////////////////// |
| 211 | // Functor |
| 212 | /////////////////////////////////////////////////////////////////////////// |
| 213 | |
Chris Craik | f6829a0 | 2015-03-10 10:28:59 -0700 | [diff] [blame] | 214 | /** |
| 215 | * Calls the function specified with the drawGLFunction function pointer. This is |
| 216 | * functionality used by webkit for calling into their renderer from our display lists. |
| 217 | * This function may return true if an invalidation is needed after the call. |
| 218 | * |
| 219 | * @param drawGLFunction A native function pointer |
| 220 | */ |
Narayan Kamath | 57616d3e | 2014-11-21 11:57:07 +0000 | [diff] [blame] | 221 | public void callDrawGLFunction2(long drawGLFunction) { |
Tom Hudson | 8dfaa49 | 2014-12-09 15:03:44 -0500 | [diff] [blame] | 222 | nCallDrawGLFunction(mNativeCanvasWrapper, drawGLFunction); |
Chet Haase | daf98e9 | 2011-01-10 14:10:36 -0800 | [diff] [blame] | 223 | } |
| 224 | |
Tom Hudson | 107843d | 2014-09-08 11:26:26 -0400 | [diff] [blame] | 225 | private static native void nCallDrawGLFunction(long renderer, long drawGLFunction); |
Chet Haase | daf98e9 | 2011-01-10 14:10:36 -0800 | [diff] [blame] | 226 | |
Romain Guy | bdf7609 | 2011-07-18 15:00:43 -0700 | [diff] [blame] | 227 | /////////////////////////////////////////////////////////////////////////// |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 228 | // Display list |
| 229 | /////////////////////////////////////////////////////////////////////////// |
| 230 | |
John Reck | 44fd8d2 | 2014-02-26 11:00:11 -0800 | [diff] [blame] | 231 | protected static native long nFinishRecording(long renderer); |
Romain Guy | 52036b1 | 2013-02-14 18:03:37 -0800 | [diff] [blame] | 232 | |
Chris Craik | f6829a0 | 2015-03-10 10:28:59 -0700 | [diff] [blame] | 233 | /** |
| 234 | * Draws the specified display list onto this canvas. The display list can only |
| 235 | * be drawn if {@link android.view.RenderNode#isValid()} returns true. |
| 236 | * |
| 237 | * @param renderNode The RenderNode to replay. |
| 238 | */ |
| 239 | public void drawRenderNode(RenderNode renderNode) { |
| 240 | drawRenderNode(renderNode, RenderNode.FLAG_CLIP_CHILDREN); |
| 241 | } |
| 242 | |
| 243 | /** |
| 244 | * Draws the specified display list onto this canvas. |
| 245 | * |
| 246 | * @param renderNode The RenderNode to replay. |
| 247 | * @param flags Optional flags about drawing, see {@link RenderNode} for |
| 248 | * the possible flags. |
| 249 | */ |
Tom Hudson | 107843d | 2014-09-08 11:26:26 -0400 | [diff] [blame] | 250 | public void drawRenderNode(RenderNode renderNode, int flags) { |
Tom Hudson | 8dfaa49 | 2014-12-09 15:03:44 -0500 | [diff] [blame] | 251 | nDrawRenderNode(mNativeCanvasWrapper, renderNode.getNativeDisplayList(), flags); |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 252 | } |
| 253 | |
Tom Hudson | 107843d | 2014-09-08 11:26:26 -0400 | [diff] [blame] | 254 | private static native void nDrawRenderNode(long renderer, long renderNode, |
| 255 | int flags); |
Romain Guy | da8532c | 2010-08-31 11:50:35 -0700 | [diff] [blame] | 256 | |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 257 | /////////////////////////////////////////////////////////////////////////// |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 258 | // Hardware layer |
| 259 | /////////////////////////////////////////////////////////////////////////// |
Raph Levien | 051910b | 2014-06-15 18:25:29 -0700 | [diff] [blame] | 260 | |
Chris Craik | f6829a0 | 2015-03-10 10:28:59 -0700 | [diff] [blame] | 261 | /** |
| 262 | * Draws the specified layer onto this canvas. |
| 263 | * |
| 264 | * @param layer The layer to composite on this canvas |
| 265 | * @param x The left coordinate of the layer |
| 266 | * @param y The top coordinate of the layer |
| 267 | * @param paint The paint used to draw the layer |
| 268 | */ |
Romain Guy | ada830f | 2011-01-13 12:13:20 -0800 | [diff] [blame] | 269 | void drawHardwareLayer(HardwareLayer layer, float x, float y, Paint paint) { |
Chris Craik | a4e16c5 | 2013-03-22 10:00:48 -0700 | [diff] [blame] | 270 | layer.setLayerPaint(paint); |
Tom Hudson | 8dfaa49 | 2014-12-09 15:03:44 -0500 | [diff] [blame] | 271 | nDrawLayer(mNativeCanvasWrapper, layer.getLayerHandle(), x, y); |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 272 | } |
| 273 | |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 274 | private static native void nDrawLayer(long renderer, long layer, float x, float y); |
Romain Guy | aa6c24c | 2011-04-28 18:40:04 -0700 | [diff] [blame] | 275 | |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 276 | /////////////////////////////////////////////////////////////////////////// |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 277 | // Drawing |
| 278 | /////////////////////////////////////////////////////////////////////////// |
| 279 | |
Tom Hudson | 8dfaa49 | 2014-12-09 15:03:44 -0500 | [diff] [blame] | 280 | // TODO: move to Canvas.java |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 281 | @Override |
Romain Guy | f3187b7 | 2013-06-07 12:17:11 -0700 | [diff] [blame] | 282 | public void drawPatch(NinePatch patch, Rect dst, Paint paint) { |
| 283 | Bitmap bitmap = patch.getBitmap(); |
Chris Craik | 1abf5d6 | 2013-08-16 12:47:03 -0700 | [diff] [blame] | 284 | throwIfCannotDraw(bitmap); |
Derek Sollenberger | dfba4d3 | 2014-09-02 15:42:54 -0400 | [diff] [blame] | 285 | final long nativePaint = paint == null ? 0 : paint.getNativeInstance(); |
John Reck | 1ff961d | 2015-04-17 20:45:15 +0000 | [diff] [blame] | 286 | nDrawPatch(mNativeCanvasWrapper, bitmap.getSkBitmap(), patch.mNativeChunk, |
Derek Sollenberger | 76d3a1b | 2013-12-10 12:28:58 -0500 | [diff] [blame] | 287 | dst.left, dst.top, dst.right, dst.bottom, nativePaint); |
Romain Guy | f3187b7 | 2013-06-07 12:17:11 -0700 | [diff] [blame] | 288 | } |
| 289 | |
Tom Hudson | 8dfaa49 | 2014-12-09 15:03:44 -0500 | [diff] [blame] | 290 | // TODO: move to Canvas.java |
Romain Guy | f3187b7 | 2013-06-07 12:17:11 -0700 | [diff] [blame] | 291 | @Override |
Romain Guy | 3b748a4 | 2013-04-17 18:54:38 -0700 | [diff] [blame] | 292 | public void drawPatch(NinePatch patch, RectF dst, Paint paint) { |
| 293 | Bitmap bitmap = patch.getBitmap(); |
Chris Craik | 1abf5d6 | 2013-08-16 12:47:03 -0700 | [diff] [blame] | 294 | throwIfCannotDraw(bitmap); |
Derek Sollenberger | dfba4d3 | 2014-09-02 15:42:54 -0400 | [diff] [blame] | 295 | final long nativePaint = paint == null ? 0 : paint.getNativeInstance(); |
John Reck | 1ff961d | 2015-04-17 20:45:15 +0000 | [diff] [blame] | 296 | nDrawPatch(mNativeCanvasWrapper, bitmap.getSkBitmap(), patch.mNativeChunk, |
Derek Sollenberger | 76d3a1b | 2013-12-10 12:28:58 -0500 | [diff] [blame] | 297 | dst.left, dst.top, dst.right, dst.bottom, nativePaint); |
Romain Guy | deba785 | 2010-07-07 17:54:48 -0700 | [diff] [blame] | 298 | } |
| 299 | |
John Reck | 1ff961d | 2015-04-17 20:45:15 +0000 | [diff] [blame] | 300 | private static native void nDrawPatch(long renderer, long bitmap, long chunk, |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 301 | float left, float top, float right, float bottom, long paint); |
Romain Guy | deba785 | 2010-07-07 17:54:48 -0700 | [diff] [blame] | 302 | |
John Reck | 52244ff | 2014-05-01 21:27:37 -0700 | [diff] [blame] | 303 | public void drawCircle(CanvasProperty<Float> cx, CanvasProperty<Float> cy, |
| 304 | CanvasProperty<Float> radius, CanvasProperty<Paint> paint) { |
Tom Hudson | 8dfaa49 | 2014-12-09 15:03:44 -0500 | [diff] [blame] | 305 | nDrawCircle(mNativeCanvasWrapper, cx.getNativeContainer(), cy.getNativeContainer(), |
John Reck | 52244ff | 2014-05-01 21:27:37 -0700 | [diff] [blame] | 306 | radius.getNativeContainer(), paint.getNativeContainer()); |
| 307 | } |
| 308 | |
| 309 | private static native void nDrawCircle(long renderer, long propCx, |
| 310 | long propCy, long propRadius, long propPaint); |
| 311 | |
Jorim Jaggi | 072707d | 2014-09-15 17:20:08 +0200 | [diff] [blame] | 312 | public void drawRoundRect(CanvasProperty<Float> left, CanvasProperty<Float> top, |
| 313 | CanvasProperty<Float> right, CanvasProperty<Float> bottom, CanvasProperty<Float> rx, |
| 314 | CanvasProperty<Float> ry, CanvasProperty<Paint> paint) { |
Tom Hudson | 8dfaa49 | 2014-12-09 15:03:44 -0500 | [diff] [blame] | 315 | nDrawRoundRect(mNativeCanvasWrapper, left.getNativeContainer(), top.getNativeContainer(), |
Jorim Jaggi | 072707d | 2014-09-15 17:20:08 +0200 | [diff] [blame] | 316 | right.getNativeContainer(), bottom.getNativeContainer(), |
| 317 | rx.getNativeContainer(), ry.getNativeContainer(), |
| 318 | paint.getNativeContainer()); |
| 319 | } |
| 320 | |
| 321 | private static native void nDrawRoundRect(long renderer, long propLeft, long propTop, |
| 322 | long propRight, long propBottom, long propRx, long propRy, long propPaint); |
| 323 | |
Tom Hudson | 8dfaa49 | 2014-12-09 15:03:44 -0500 | [diff] [blame] | 324 | // TODO: move this optimization to Canvas.java |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 325 | @Override |
| 326 | public void drawPath(Path path, Paint paint) { |
Leon Scroggins III | d1ad5e6 | 2014-05-05 12:50:38 -0400 | [diff] [blame] | 327 | if (path.isSimplePath) { |
| 328 | if (path.rects != null) { |
Tom Hudson | 8dfaa49 | 2014-12-09 15:03:44 -0500 | [diff] [blame] | 329 | nDrawRects(mNativeCanvasWrapper, path.rects.mNativeRegion, paint.getNativeInstance()); |
Romain Guy | a48a1a8 | 2010-08-10 14:59:15 -0700 | [diff] [blame] | 330 | } |
Leon Scroggins III | d1ad5e6 | 2014-05-05 12:50:38 -0400 | [diff] [blame] | 331 | } else { |
Tom Hudson | 8dfaa49 | 2014-12-09 15:03:44 -0500 | [diff] [blame] | 332 | super.drawPath(path, paint); |
Romain Guy | a48a1a8 | 2010-08-10 14:59:15 -0700 | [diff] [blame] | 333 | } |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 334 | } |
| 335 | |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 336 | private static native void nDrawRects(long renderer, long region, long paint); |
Romain Guy | 7fbcc04 | 2010-08-04 15:40:07 -0700 | [diff] [blame] | 337 | |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 338 | @Override |
| 339 | public void drawPicture(Picture picture) { |
Romain Guy | 75582e8 | 2012-01-18 18:13:35 -0800 | [diff] [blame] | 340 | picture.endRecording(); |
| 341 | // TODO: Implement rendering |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 342 | } |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 343 | } |