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 | |
| 19 | import android.graphics.Bitmap; |
| 20 | import android.graphics.Canvas; |
Romain Guy | db1938e | 2010-08-02 18:50:22 -0700 | [diff] [blame] | 21 | import android.graphics.ColorFilter; |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 22 | import android.graphics.DrawFilter; |
| 23 | import android.graphics.Matrix; |
Romain Guy | 3b748a4 | 2013-04-17 18:54:38 -0700 | [diff] [blame] | 24 | import android.graphics.NinePatch; |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 25 | import android.graphics.Paint; |
Romain Guy | 5ff9df6 | 2012-01-23 17:09:05 -0800 | [diff] [blame] | 26 | import android.graphics.PaintFlagsDrawFilter; |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 27 | import android.graphics.Path; |
| 28 | import android.graphics.Picture; |
| 29 | import android.graphics.PorterDuff; |
| 30 | import android.graphics.Rect; |
| 31 | import android.graphics.RectF; |
| 32 | import android.graphics.Region; |
Romain Guy | d27977d | 2010-07-14 19:18:51 -0700 | [diff] [blame] | 33 | import android.graphics.Shader; |
Romain Guy | e5e0c50 | 2011-06-15 15:18:31 -0700 | [diff] [blame] | 34 | import android.graphics.SurfaceTexture; |
Romain Guy | a1db574 | 2010-07-20 13:09:13 -0700 | [diff] [blame] | 35 | import android.graphics.TemporaryBuffer; |
| 36 | import android.text.GraphicsOperations; |
| 37 | import android.text.SpannableString; |
| 38 | import android.text.SpannedString; |
| 39 | import android.text.TextUtils; |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 40 | |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 41 | /** |
| 42 | * An implementation of Canvas on top of OpenGL ES 2.0. |
| 43 | */ |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 44 | class GLES20Canvas extends HardwareCanvas { |
Romain Guy | a168d73 | 2011-03-18 16:50:13 -0700 | [diff] [blame] | 45 | // Must match modifiers used in the JNI layer |
| 46 | private static final int MODIFIER_NONE = 0; |
| 47 | private static final int MODIFIER_SHADOW = 1; |
| 48 | private static final int MODIFIER_SHADER = 2; |
| 49 | private static final int MODIFIER_COLOR_FILTER = 4; |
| 50 | |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 51 | private final boolean mOpaque; |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 52 | private long mRenderer; |
Patrick Dubroy | f890fab | 2010-12-19 16:47:17 -0800 | [diff] [blame] | 53 | |
| 54 | // The native renderer will be destroyed when this object dies. |
| 55 | // DO NOT overwrite this reference once it is set. |
Romain Guy | eea6069 | 2011-07-26 20:35:55 -0700 | [diff] [blame] | 56 | @SuppressWarnings({"unused", "FieldCanBeLocal"}) |
Patrick Dubroy | f890fab | 2010-12-19 16:47:17 -0800 | [diff] [blame] | 57 | private CanvasFinalizer mFinalizer; |
| 58 | |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 59 | private int mWidth; |
| 60 | private int mHeight; |
Romain Guy | ce0537b | 2010-06-29 21:05:21 -0700 | [diff] [blame] | 61 | |
Romain Guy | 6410c0a | 2013-06-17 11:21:58 -0700 | [diff] [blame] | 62 | private float[] mPoint; |
| 63 | private float[] mLine; |
Romain Guy | 6926c72 | 2010-07-12 20:20:03 -0700 | [diff] [blame] | 64 | |
Romain Guy | 6410c0a | 2013-06-17 11:21:58 -0700 | [diff] [blame] | 65 | private Rect mClipBounds; |
| 66 | private RectF mPathBounds; |
Romain Guy | 6926c72 | 2010-07-12 20:20:03 -0700 | [diff] [blame] | 67 | |
| 68 | private DrawFilter mFilter; |
Romain Guy | da8532c | 2010-08-31 11:50:35 -0700 | [diff] [blame] | 69 | |
Romain Guy | 1639351 | 2010-08-08 00:14:31 -0700 | [diff] [blame] | 70 | /////////////////////////////////////////////////////////////////////////// |
| 71 | // JNI |
| 72 | /////////////////////////////////////////////////////////////////////////// |
| 73 | |
| 74 | private static native boolean nIsAvailable(); |
| 75 | private static boolean sIsAvailable = nIsAvailable(); |
| 76 | |
| 77 | static boolean isAvailable() { |
| 78 | return sIsAvailable; |
| 79 | } |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 80 | |
| 81 | /////////////////////////////////////////////////////////////////////////// |
| 82 | // Constructors |
| 83 | /////////////////////////////////////////////////////////////////////////// |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 84 | |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 85 | /** |
| 86 | * Creates a canvas to render directly on screen. |
| 87 | */ |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 88 | GLES20Canvas(boolean translucent) { |
| 89 | this(false, translucent); |
| 90 | } |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 91 | |
| 92 | /** |
| 93 | * Creates a canvas to render into an FBO. |
| 94 | */ |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 95 | GLES20Canvas(long layer, boolean translucent) { |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 96 | mOpaque = !translucent; |
Romain Guy | ada830f | 2011-01-13 12:13:20 -0800 | [diff] [blame] | 97 | mRenderer = nCreateLayerRenderer(layer); |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 98 | setupFinalizer(); |
| 99 | } |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 100 | |
Patrick Dubroy | f890fab | 2010-12-19 16:47:17 -0800 | [diff] [blame] | 101 | protected GLES20Canvas(boolean record, boolean translucent) { |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 102 | mOpaque = !translucent; |
| 103 | |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 104 | if (record) { |
Jeff Brown | 162a021 | 2011-07-21 17:02:54 -0700 | [diff] [blame] | 105 | mRenderer = nCreateDisplayListRenderer(); |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 106 | } else { |
| 107 | mRenderer = nCreateRenderer(); |
| 108 | } |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 109 | |
| 110 | setupFinalizer(); |
| 111 | } |
| 112 | |
| 113 | private void setupFinalizer() { |
Romain Guy | fb8b763 | 2010-08-23 21:05:08 -0700 | [diff] [blame] | 114 | if (mRenderer == 0) { |
| 115 | throw new IllegalStateException("Could not create GLES20Canvas renderer"); |
Chet Haase | 5c13d89 | 2010-10-08 08:37:55 -0700 | [diff] [blame] | 116 | } else { |
Jeff Brown | 162a021 | 2011-07-21 17:02:54 -0700 | [diff] [blame] | 117 | mFinalizer = new CanvasFinalizer(mRenderer); |
Romain Guy | fb8b763 | 2010-08-23 21:05:08 -0700 | [diff] [blame] | 118 | } |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 119 | } |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 120 | |
Jeff Brown | 162a021 | 2011-07-21 17:02:54 -0700 | [diff] [blame] | 121 | protected void resetDisplayListRenderer() { |
| 122 | nResetDisplayListRenderer(mRenderer); |
| 123 | } |
| 124 | |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 125 | private static native long nCreateRenderer(); |
| 126 | private static native long nCreateLayerRenderer(long layer); |
| 127 | private static native long nCreateDisplayListRenderer(); |
| 128 | private static native void nResetDisplayListRenderer(long renderer); |
| 129 | private static native void nDestroyRenderer(long renderer); |
Chet Haase | 5c13d89 | 2010-10-08 08:37:55 -0700 | [diff] [blame] | 130 | |
Jeff Brown | 162a021 | 2011-07-21 17:02:54 -0700 | [diff] [blame] | 131 | private static final class CanvasFinalizer { |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 132 | private final long mRenderer; |
Chet Haase | 5c13d89 | 2010-10-08 08:37:55 -0700 | [diff] [blame] | 133 | |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 134 | public CanvasFinalizer(long renderer) { |
Patrick Dubroy | f890fab | 2010-12-19 16:47:17 -0800 | [diff] [blame] | 135 | mRenderer = renderer; |
Chet Haase | 5c13d89 | 2010-10-08 08:37:55 -0700 | [diff] [blame] | 136 | } |
| 137 | |
| 138 | @Override |
Patrick Dubroy | f890fab | 2010-12-19 16:47:17 -0800 | [diff] [blame] | 139 | protected void finalize() throws Throwable { |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 140 | try { |
Jeff Brown | 162a021 | 2011-07-21 17:02:54 -0700 | [diff] [blame] | 141 | nDestroyRenderer(mRenderer); |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 142 | } finally { |
| 143 | super.finalize(); |
| 144 | } |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 145 | } |
| 146 | } |
Romain Guy | ce0537b | 2010-06-29 21:05:21 -0700 | [diff] [blame] | 147 | |
Chris Craik | ba9b613 | 2013-12-15 17:10:19 -0800 | [diff] [blame] | 148 | public static void setProperty(String name, String value) { |
| 149 | nSetProperty(name, value); |
| 150 | } |
| 151 | |
| 152 | private static native void nSetProperty(String name, String value); |
| 153 | |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 154 | /////////////////////////////////////////////////////////////////////////// |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 155 | // Hardware layers |
| 156 | /////////////////////////////////////////////////////////////////////////// |
Romain Guy | 11cb642 | 2012-09-21 00:39:43 -0700 | [diff] [blame] | 157 | |
| 158 | @Override |
| 159 | void pushLayerUpdate(HardwareLayer layer) { |
| 160 | nPushLayerUpdate(mRenderer, ((GLES20RenderLayer) layer).mLayer); |
| 161 | } |
| 162 | |
| 163 | @Override |
Romain Guy | e93482f | 2013-06-17 13:14:51 -0700 | [diff] [blame] | 164 | void cancelLayerUpdate(HardwareLayer layer) { |
| 165 | nCancelLayerUpdate(mRenderer, ((GLES20RenderLayer) layer).mLayer); |
| 166 | } |
| 167 | |
| 168 | @Override |
Romain Guy | 4054360 | 2013-06-12 15:31:28 -0700 | [diff] [blame] | 169 | void flushLayerUpdates() { |
| 170 | nFlushLayerUpdates(mRenderer); |
| 171 | } |
| 172 | |
| 173 | @Override |
Romain Guy | 11cb642 | 2012-09-21 00:39:43 -0700 | [diff] [blame] | 174 | void clearLayerUpdates() { |
| 175 | nClearLayerUpdates(mRenderer); |
| 176 | } |
| 177 | |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 178 | static native long nCreateTextureLayer(boolean opaque, int[] layerInfo); |
| 179 | static native long nCreateLayer(int width, int height, boolean isOpaque, int[] layerInfo); |
| 180 | static native boolean nResizeLayer(long layerId, int width, int height, int[] layerInfo); |
| 181 | static native void nSetOpaqueLayer(long layerId, boolean isOpaque); |
| 182 | static native void nSetLayerPaint(long layerId, long nativePaint); |
| 183 | static native void nSetLayerColorFilter(long layerId, long nativeColorFilter); |
| 184 | static native void nUpdateTextureLayer(long layerId, int width, int height, boolean opaque, |
Romain Guy | a948927 | 2011-06-22 20:58:11 -0700 | [diff] [blame] | 185 | SurfaceTexture surface); |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 186 | static native void nClearLayerTexture(long layerId); |
| 187 | static native void nSetTextureLayerTransform(long layerId, long matrix); |
| 188 | static native void nDestroyLayer(long layerId); |
| 189 | static native void nDestroyLayerDeferred(long layerId); |
| 190 | static native void nUpdateRenderLayer(long layerId, long renderer, long displayList, |
Romain Guy | 2bf68f0 | 2012-03-02 13:37:47 -0800 | [diff] [blame] | 191 | int left, int top, int right, int bottom); |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 192 | static native boolean nCopyLayer(long layerId, long bitmap); |
Romain Guy | 57066eb | 2011-01-12 12:53:32 -0800 | [diff] [blame] | 193 | |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 194 | private static native void nClearLayerUpdates(long renderer); |
| 195 | private static native void nFlushLayerUpdates(long renderer); |
| 196 | private static native void nPushLayerUpdate(long renderer, long layer); |
| 197 | private static native void nCancelLayerUpdate(long renderer, long layer); |
Romain Guy | 11cb642 | 2012-09-21 00:39:43 -0700 | [diff] [blame] | 198 | |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 199 | /////////////////////////////////////////////////////////////////////////// |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 200 | // Canvas management |
| 201 | /////////////////////////////////////////////////////////////////////////// |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 202 | |
| 203 | @Override |
| 204 | public boolean isOpaque() { |
| 205 | return mOpaque; |
| 206 | } |
| 207 | |
| 208 | @Override |
| 209 | public int getWidth() { |
| 210 | return mWidth; |
| 211 | } |
| 212 | |
| 213 | @Override |
| 214 | public int getHeight() { |
| 215 | return mHeight; |
| 216 | } |
| 217 | |
Romain Guy | f61970fc | 2011-07-07 14:10:06 -0700 | [diff] [blame] | 218 | @Override |
| 219 | public int getMaximumBitmapWidth() { |
| 220 | return nGetMaximumTextureWidth(); |
| 221 | } |
| 222 | |
| 223 | @Override |
| 224 | public int getMaximumBitmapHeight() { |
| 225 | return nGetMaximumTextureHeight(); |
| 226 | } |
| 227 | |
| 228 | private static native int nGetMaximumTextureWidth(); |
Romain Guy | 530041d | 2012-01-25 18:56:29 -0800 | [diff] [blame] | 229 | private static native int nGetMaximumTextureHeight(); |
Romain Guy | f61970fc | 2011-07-07 14:10:06 -0700 | [diff] [blame] | 230 | |
Romain Guy | 2bf68f0 | 2012-03-02 13:37:47 -0800 | [diff] [blame] | 231 | /** |
| 232 | * Returns the native OpenGLRenderer object. |
| 233 | */ |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 234 | long getRenderer() { |
Romain Guy | 2bf68f0 | 2012-03-02 13:37:47 -0800 | [diff] [blame] | 235 | return mRenderer; |
| 236 | } |
| 237 | |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 238 | /////////////////////////////////////////////////////////////////////////// |
| 239 | // Setup |
| 240 | /////////////////////////////////////////////////////////////////////////// |
| 241 | |
| 242 | @Override |
| 243 | public void setViewport(int width, int height) { |
| 244 | mWidth = width; |
| 245 | mHeight = height; |
| 246 | |
| 247 | nSetViewport(mRenderer, width, height); |
| 248 | } |
| 249 | |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 250 | private static native void nSetViewport(long renderer, int width, int height); |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 251 | |
Romain Guy | 7d7b549 | 2011-01-24 16:33:45 -0800 | [diff] [blame] | 252 | @Override |
Chet Haase | 44b2fe3 | 2012-06-06 19:03:58 -0700 | [diff] [blame] | 253 | public int onPreDraw(Rect dirty) { |
Romain Guy | 7d7b549 | 2011-01-24 16:33:45 -0800 | [diff] [blame] | 254 | if (dirty != null) { |
Chet Haase | 44b2fe3 | 2012-06-06 19:03:58 -0700 | [diff] [blame] | 255 | return nPrepareDirty(mRenderer, dirty.left, dirty.top, dirty.right, dirty.bottom, |
| 256 | mOpaque); |
Romain Guy | 7d7b549 | 2011-01-24 16:33:45 -0800 | [diff] [blame] | 257 | } else { |
Chet Haase | 44b2fe3 | 2012-06-06 19:03:58 -0700 | [diff] [blame] | 258 | return nPrepare(mRenderer, mOpaque); |
Romain Guy | 7d7b549 | 2011-01-24 16:33:45 -0800 | [diff] [blame] | 259 | } |
| 260 | } |
| 261 | |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 262 | private static native int nPrepare(long renderer, boolean opaque); |
| 263 | private static native int nPrepareDirty(long renderer, int left, int top, int right, int bottom, |
Romain Guy | 7d7b549 | 2011-01-24 16:33:45 -0800 | [diff] [blame] | 264 | boolean opaque); |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 265 | |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 266 | @Override |
Gilles Debunne | b35ab7b | 2011-12-05 15:54:00 -0800 | [diff] [blame] | 267 | public void onPostDraw() { |
Romain Guy | b025b9c | 2010-09-16 14:16:48 -0700 | [diff] [blame] | 268 | nFinish(mRenderer); |
| 269 | } |
Romain Guy | 9ace8f5 | 2011-07-07 20:50:11 -0700 | [diff] [blame] | 270 | |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 271 | private static native void nFinish(long renderer); |
Romain Guy | b025b9c | 2010-09-16 14:16:48 -0700 | [diff] [blame] | 272 | |
Romain Guy | 530041d | 2012-01-25 18:56:29 -0800 | [diff] [blame] | 273 | /** |
| 274 | * Returns the size of the stencil buffer required by the underlying |
| 275 | * implementation. |
| 276 | * |
| 277 | * @return The minimum number of bits the stencil buffer must. Always >= 0. |
| 278 | * |
| 279 | * @hide |
| 280 | */ |
| 281 | public static int getStencilSize() { |
| 282 | return nGetStencilSize(); |
| 283 | } |
| 284 | |
| 285 | private static native int nGetStencilSize(); |
| 286 | |
| 287 | /////////////////////////////////////////////////////////////////////////// |
| 288 | // Functor |
| 289 | /////////////////////////////////////////////////////////////////////////// |
| 290 | |
Romain Guy | da8532c | 2010-08-31 11:50:35 -0700 | [diff] [blame] | 291 | @Override |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 292 | public int callDrawGLFunction(long drawGLFunction) { |
Chet Haase | daf98e9 | 2011-01-10 14:10:36 -0800 | [diff] [blame] | 293 | return nCallDrawGLFunction(mRenderer, drawGLFunction); |
| 294 | } |
| 295 | |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 296 | private static native int nCallDrawGLFunction(long renderer, long drawGLFunction); |
Chet Haase | daf98e9 | 2011-01-10 14:10:36 -0800 | [diff] [blame] | 297 | |
Romain Guy | 8f3b8e3 | 2012-03-27 16:33:45 -0700 | [diff] [blame] | 298 | @Override |
| 299 | public int invokeFunctors(Rect dirty) { |
| 300 | return nInvokeFunctors(mRenderer, dirty); |
| 301 | } |
| 302 | |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 303 | private static native int nInvokeFunctors(long renderer, Rect dirty); |
Romain Guy | 8f3b8e3 | 2012-03-27 16:33:45 -0700 | [diff] [blame] | 304 | |
Romain Guy | ba6be8a | 2012-04-23 18:22:09 -0700 | [diff] [blame] | 305 | @Override |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 306 | public void detachFunctor(long functor) { |
Romain Guy | ba6be8a | 2012-04-23 18:22:09 -0700 | [diff] [blame] | 307 | nDetachFunctor(mRenderer, functor); |
| 308 | } |
| 309 | |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 310 | private static native void nDetachFunctor(long renderer, long functor); |
Romain Guy | ba6be8a | 2012-04-23 18:22:09 -0700 | [diff] [blame] | 311 | |
| 312 | @Override |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 313 | public void attachFunctor(long functor) { |
Romain Guy | ba6be8a | 2012-04-23 18:22:09 -0700 | [diff] [blame] | 314 | nAttachFunctor(mRenderer, functor); |
| 315 | } |
| 316 | |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 317 | private static native void nAttachFunctor(long renderer, long functor); |
Romain Guy | ba6be8a | 2012-04-23 18:22:09 -0700 | [diff] [blame] | 318 | |
Romain Guy | bdf7609 | 2011-07-18 15:00:43 -0700 | [diff] [blame] | 319 | /////////////////////////////////////////////////////////////////////////// |
| 320 | // Memory |
| 321 | /////////////////////////////////////////////////////////////////////////// |
| 322 | |
| 323 | /** |
Romain Guy | 6d7475d | 2011-07-27 16:28:21 -0700 | [diff] [blame] | 324 | * Must match Caches::FlushMode values |
| 325 | * |
Romain Guy | bdf7609 | 2011-07-18 15:00:43 -0700 | [diff] [blame] | 326 | * @see #flushCaches(int) |
| 327 | */ |
Romain Guy | 3b748a4 | 2013-04-17 18:54:38 -0700 | [diff] [blame] | 328 | static final int FLUSH_CACHES_LAYERS = 0; |
Romain Guy | 6d7475d | 2011-07-27 16:28:21 -0700 | [diff] [blame] | 329 | |
| 330 | /** |
| 331 | * Must match Caches::FlushMode values |
| 332 | * |
| 333 | * @see #flushCaches(int) |
| 334 | */ |
Romain Guy | 3b748a4 | 2013-04-17 18:54:38 -0700 | [diff] [blame] | 335 | static final int FLUSH_CACHES_MODERATE = 1; |
Romain Guy | bdf7609 | 2011-07-18 15:00:43 -0700 | [diff] [blame] | 336 | |
| 337 | /** |
Romain Guy | 6d7475d | 2011-07-27 16:28:21 -0700 | [diff] [blame] | 338 | * Must match Caches::FlushMode values |
| 339 | * |
Romain Guy | bdf7609 | 2011-07-18 15:00:43 -0700 | [diff] [blame] | 340 | * @see #flushCaches(int) |
| 341 | */ |
Romain Guy | 3b748a4 | 2013-04-17 18:54:38 -0700 | [diff] [blame] | 342 | static final int FLUSH_CACHES_FULL = 2; |
Romain Guy | bdf7609 | 2011-07-18 15:00:43 -0700 | [diff] [blame] | 343 | |
| 344 | /** |
| 345 | * Flush caches to reclaim as much memory as possible. The amount of memory |
| 346 | * to reclaim is indicate by the level parameter. |
| 347 | * |
| 348 | * The level can be one of {@link #FLUSH_CACHES_MODERATE} or |
| 349 | * {@link #FLUSH_CACHES_FULL}. |
| 350 | * |
| 351 | * @param level Hint about the amount of memory to reclaim |
Romain Guy | bdf7609 | 2011-07-18 15:00:43 -0700 | [diff] [blame] | 352 | */ |
Romain Guy | 3b748a4 | 2013-04-17 18:54:38 -0700 | [diff] [blame] | 353 | static void flushCaches(int level) { |
Romain Guy | bdf7609 | 2011-07-18 15:00:43 -0700 | [diff] [blame] | 354 | nFlushCaches(level); |
| 355 | } |
| 356 | |
| 357 | private static native void nFlushCaches(int level); |
| 358 | |
Romain Guy | 8ff6b9e | 2011-11-09 20:10:18 -0800 | [diff] [blame] | 359 | /** |
| 360 | * Release all resources associated with the underlying caches. This should |
| 361 | * only be called after a full flushCaches(). |
| 362 | * |
| 363 | * @hide |
| 364 | */ |
Romain Guy | 3b748a4 | 2013-04-17 18:54:38 -0700 | [diff] [blame] | 365 | static void terminateCaches() { |
Romain Guy | 8ff6b9e | 2011-11-09 20:10:18 -0800 | [diff] [blame] | 366 | nTerminateCaches(); |
| 367 | } |
| 368 | |
| 369 | private static native void nTerminateCaches(); |
| 370 | |
Romain Guy | 3b748a4 | 2013-04-17 18:54:38 -0700 | [diff] [blame] | 371 | static boolean initCaches() { |
| 372 | return nInitCaches(); |
Romain Guy | 8ff6b9e | 2011-11-09 20:10:18 -0800 | [diff] [blame] | 373 | } |
| 374 | |
Romain Guy | 3b748a4 | 2013-04-17 18:54:38 -0700 | [diff] [blame] | 375 | private static native boolean nInitCaches(); |
| 376 | |
| 377 | /////////////////////////////////////////////////////////////////////////// |
| 378 | // Atlas |
| 379 | /////////////////////////////////////////////////////////////////////////// |
| 380 | |
| 381 | static void initAtlas(GraphicBuffer buffer, int[] map) { |
| 382 | nInitAtlas(buffer, map, map.length); |
| 383 | } |
| 384 | |
| 385 | private static native void nInitAtlas(GraphicBuffer buffer, int[] map, int count); |
| 386 | |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 387 | /////////////////////////////////////////////////////////////////////////// |
| 388 | // Display list |
| 389 | /////////////////////////////////////////////////////////////////////////// |
| 390 | |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 391 | long getDisplayList(long displayList) { |
Jeff Brown | 162a021 | 2011-07-21 17:02:54 -0700 | [diff] [blame] | 392 | return nGetDisplayList(mRenderer, displayList); |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 393 | } |
| 394 | |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 395 | private static native long nGetDisplayList(long renderer, long displayList); |
Romain Guy | 52036b1 | 2013-02-14 18:03:37 -0800 | [diff] [blame] | 396 | |
| 397 | @Override |
Chet Haase | 1271e2c | 2012-04-20 09:54:27 -0700 | [diff] [blame] | 398 | public int drawDisplayList(DisplayList displayList, Rect dirty, int flags) { |
Chris Craik | 5438979 | 2013-12-20 13:28:11 -0800 | [diff] [blame] | 399 | return nDrawDisplayList(mRenderer, displayList.getNativeDisplayList(), |
Chet Haase | 1271e2c | 2012-04-20 09:54:27 -0700 | [diff] [blame] | 400 | dirty, flags); |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 401 | } |
| 402 | |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 403 | private static native int nDrawDisplayList(long renderer, long displayList, |
Chet Haase | 1271e2c | 2012-04-20 09:54:27 -0700 | [diff] [blame] | 404 | Rect dirty, int flags); |
Romain Guy | da8532c | 2010-08-31 11:50:35 -0700 | [diff] [blame] | 405 | |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 406 | /////////////////////////////////////////////////////////////////////////// |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 407 | // Hardware layer |
| 408 | /////////////////////////////////////////////////////////////////////////// |
| 409 | |
Romain Guy | ada830f | 2011-01-13 12:13:20 -0800 | [diff] [blame] | 410 | void drawHardwareLayer(HardwareLayer layer, float x, float y, Paint paint) { |
Chris Craik | a4e16c5 | 2013-03-22 10:00:48 -0700 | [diff] [blame] | 411 | layer.setLayerPaint(paint); |
| 412 | |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 413 | final GLES20Layer glLayer = (GLES20Layer) layer; |
Chris Craik | a4e16c5 | 2013-03-22 10:00:48 -0700 | [diff] [blame] | 414 | nDrawLayer(mRenderer, glLayer.getLayer(), x, y); |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 415 | } |
| 416 | |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 417 | 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] | 418 | |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 419 | void interrupt() { |
| 420 | nInterrupt(mRenderer); |
| 421 | } |
| 422 | |
| 423 | void resume() { |
| 424 | nResume(mRenderer); |
| 425 | } |
| 426 | |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 427 | private static native void nInterrupt(long renderer); |
| 428 | private static native void nResume(long renderer); |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 429 | |
| 430 | /////////////////////////////////////////////////////////////////////////// |
Romain Guy | 6410c0a | 2013-06-17 11:21:58 -0700 | [diff] [blame] | 431 | // Support |
| 432 | /////////////////////////////////////////////////////////////////////////// |
| 433 | |
| 434 | private Rect getInternalClipBounds() { |
| 435 | if (mClipBounds == null) mClipBounds = new Rect(); |
| 436 | return mClipBounds; |
| 437 | } |
| 438 | |
| 439 | |
| 440 | private RectF getPathBounds() { |
| 441 | if (mPathBounds == null) mPathBounds = new RectF(); |
| 442 | return mPathBounds; |
| 443 | } |
| 444 | |
| 445 | private float[] getPointStorage() { |
| 446 | if (mPoint == null) mPoint = new float[2]; |
| 447 | return mPoint; |
| 448 | } |
| 449 | |
| 450 | private float[] getLineStorage() { |
| 451 | if (mLine == null) mLine = new float[4]; |
| 452 | return mLine; |
| 453 | } |
| 454 | |
| 455 | /////////////////////////////////////////////////////////////////////////// |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 456 | // Clipping |
| 457 | /////////////////////////////////////////////////////////////////////////// |
| 458 | |
| 459 | @Override |
| 460 | public boolean clipPath(Path path) { |
Romain Guy | 735738c | 2012-12-03 12:34:51 -0800 | [diff] [blame] | 461 | return nClipPath(mRenderer, path.mNativePath, Region.Op.INTERSECT.nativeInt); |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 462 | } |
| 463 | |
| 464 | @Override |
| 465 | public boolean clipPath(Path path, Region.Op op) { |
Romain Guy | 735738c | 2012-12-03 12:34:51 -0800 | [diff] [blame] | 466 | return nClipPath(mRenderer, path.mNativePath, op.nativeInt); |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 467 | } |
| 468 | |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 469 | private static native boolean nClipPath(long renderer, long path, int op); |
Romain Guy | 735738c | 2012-12-03 12:34:51 -0800 | [diff] [blame] | 470 | |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 471 | @Override |
| 472 | public boolean clipRect(float left, float top, float right, float bottom) { |
Romain Guy | 079ba2c | 2010-07-16 14:12:24 -0700 | [diff] [blame] | 473 | return nClipRect(mRenderer, left, top, right, bottom, Region.Op.INTERSECT.nativeInt); |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 474 | } |
Romain Guy | bb9524b | 2010-06-22 18:56:38 -0700 | [diff] [blame] | 475 | |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 476 | private static native boolean nClipRect(long renderer, float left, float top, |
Romain Guy | 079ba2c | 2010-07-16 14:12:24 -0700 | [diff] [blame] | 477 | float right, float bottom, int op); |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 478 | |
| 479 | @Override |
| 480 | public boolean clipRect(float left, float top, float right, float bottom, Region.Op op) { |
Romain Guy | 079ba2c | 2010-07-16 14:12:24 -0700 | [diff] [blame] | 481 | return nClipRect(mRenderer, left, top, right, bottom, op.nativeInt); |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 482 | } |
| 483 | |
| 484 | @Override |
| 485 | public boolean clipRect(int left, int top, int right, int bottom) { |
Chet Haase | daf98e9 | 2011-01-10 14:10:36 -0800 | [diff] [blame] | 486 | return nClipRect(mRenderer, left, top, right, bottom, Region.Op.INTERSECT.nativeInt); |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 487 | } |
Romain Guy | bb9524b | 2010-06-22 18:56:38 -0700 | [diff] [blame] | 488 | |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 489 | private static native boolean nClipRect(long renderer, int left, int top, |
Romain Guy | 735738c | 2012-12-03 12:34:51 -0800 | [diff] [blame] | 490 | int right, int bottom, int op); |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 491 | |
| 492 | @Override |
| 493 | public boolean clipRect(Rect rect) { |
Romain Guy | 079ba2c | 2010-07-16 14:12:24 -0700 | [diff] [blame] | 494 | return nClipRect(mRenderer, rect.left, rect.top, rect.right, rect.bottom, |
| 495 | Region.Op.INTERSECT.nativeInt); |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 496 | } |
| 497 | |
| 498 | @Override |
| 499 | public boolean clipRect(Rect rect, Region.Op op) { |
Romain Guy | 079ba2c | 2010-07-16 14:12:24 -0700 | [diff] [blame] | 500 | return nClipRect(mRenderer, rect.left, rect.top, rect.right, rect.bottom, op.nativeInt); |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 501 | } |
| 502 | |
| 503 | @Override |
| 504 | public boolean clipRect(RectF rect) { |
Romain Guy | 079ba2c | 2010-07-16 14:12:24 -0700 | [diff] [blame] | 505 | return nClipRect(mRenderer, rect.left, rect.top, rect.right, rect.bottom, |
| 506 | Region.Op.INTERSECT.nativeInt); |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 507 | } |
| 508 | |
| 509 | @Override |
| 510 | public boolean clipRect(RectF rect, Region.Op op) { |
Romain Guy | 079ba2c | 2010-07-16 14:12:24 -0700 | [diff] [blame] | 511 | return nClipRect(mRenderer, rect.left, rect.top, rect.right, rect.bottom, op.nativeInt); |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 512 | } |
| 513 | |
| 514 | @Override |
| 515 | public boolean clipRegion(Region region) { |
Romain Guy | 735738c | 2012-12-03 12:34:51 -0800 | [diff] [blame] | 516 | return nClipRegion(mRenderer, region.mNativeRegion, Region.Op.INTERSECT.nativeInt); |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 517 | } |
| 518 | |
| 519 | @Override |
| 520 | public boolean clipRegion(Region region, Region.Op op) { |
Romain Guy | 735738c | 2012-12-03 12:34:51 -0800 | [diff] [blame] | 521 | return nClipRegion(mRenderer, region.mNativeRegion, op.nativeInt); |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 522 | } |
| 523 | |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 524 | private static native boolean nClipRegion(long renderer, long region, int op); |
Romain Guy | 735738c | 2012-12-03 12:34:51 -0800 | [diff] [blame] | 525 | |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 526 | @Override |
| 527 | public boolean getClipBounds(Rect bounds) { |
Romain Guy | 9d5316e | 2010-06-24 19:30:36 -0700 | [diff] [blame] | 528 | return nGetClipBounds(mRenderer, bounds); |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 529 | } |
| 530 | |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 531 | private static native boolean nGetClipBounds(long renderer, Rect bounds); |
Romain Guy | 9d5316e | 2010-06-24 19:30:36 -0700 | [diff] [blame] | 532 | |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 533 | @Override |
| 534 | public boolean quickReject(float left, float top, float right, float bottom, EdgeType type) { |
Derek Sollenberger | ca79cf6 | 2012-08-14 16:44:52 -0400 | [diff] [blame] | 535 | return nQuickReject(mRenderer, left, top, right, bottom); |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 536 | } |
Romain Guy | c7d5349 | 2010-06-25 13:41:57 -0700 | [diff] [blame] | 537 | |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 538 | private static native boolean nQuickReject(long renderer, float left, float top, |
Derek Sollenberger | ca79cf6 | 2012-08-14 16:44:52 -0400 | [diff] [blame] | 539 | float right, float bottom); |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 540 | |
| 541 | @Override |
| 542 | public boolean quickReject(Path path, EdgeType type) { |
Romain Guy | 6410c0a | 2013-06-17 11:21:58 -0700 | [diff] [blame] | 543 | RectF pathBounds = getPathBounds(); |
| 544 | path.computeBounds(pathBounds, true); |
| 545 | return nQuickReject(mRenderer, pathBounds.left, pathBounds.top, |
| 546 | pathBounds.right, pathBounds.bottom); |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 547 | } |
| 548 | |
| 549 | @Override |
| 550 | public boolean quickReject(RectF rect, EdgeType type) { |
Derek Sollenberger | ca79cf6 | 2012-08-14 16:44:52 -0400 | [diff] [blame] | 551 | return nQuickReject(mRenderer, rect.left, rect.top, rect.right, rect.bottom); |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 552 | } |
| 553 | |
| 554 | /////////////////////////////////////////////////////////////////////////// |
| 555 | // Transformations |
| 556 | /////////////////////////////////////////////////////////////////////////// |
| 557 | |
| 558 | @Override |
| 559 | public void translate(float dx, float dy) { |
Romain Guy | 807daf7 | 2011-01-18 11:19:19 -0800 | [diff] [blame] | 560 | if (dx != 0.0f || dy != 0.0f) nTranslate(mRenderer, dx, dy); |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 561 | } |
Romain Guy | f6a11b8 | 2010-06-23 17:47:49 -0700 | [diff] [blame] | 562 | |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 563 | private static native void nTranslate(long renderer, float dx, float dy); |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 564 | |
| 565 | @Override |
| 566 | public void skew(float sx, float sy) { |
Romain Guy | 807daf7 | 2011-01-18 11:19:19 -0800 | [diff] [blame] | 567 | nSkew(mRenderer, sx, sy); |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 568 | } |
| 569 | |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 570 | private static native void nSkew(long renderer, float sx, float sy); |
Romain Guy | 807daf7 | 2011-01-18 11:19:19 -0800 | [diff] [blame] | 571 | |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 572 | @Override |
| 573 | public void rotate(float degrees) { |
Romain Guy | f6a11b8 | 2010-06-23 17:47:49 -0700 | [diff] [blame] | 574 | nRotate(mRenderer, degrees); |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 575 | } |
Romain Guy | f6a11b8 | 2010-06-23 17:47:49 -0700 | [diff] [blame] | 576 | |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 577 | private static native void nRotate(long renderer, float degrees); |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 578 | |
| 579 | @Override |
| 580 | public void scale(float sx, float sy) { |
Romain Guy | f6a11b8 | 2010-06-23 17:47:49 -0700 | [diff] [blame] | 581 | nScale(mRenderer, sx, sy); |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 582 | } |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 583 | |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 584 | private static native void nScale(long renderer, float sx, float sy); |
Romain Guy | f6a11b8 | 2010-06-23 17:47:49 -0700 | [diff] [blame] | 585 | |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 586 | @Override |
| 587 | public void setMatrix(Matrix matrix) { |
Romain Guy | e707859 | 2011-10-28 14:32:20 -0700 | [diff] [blame] | 588 | nSetMatrix(mRenderer, matrix == null ? 0 : matrix.native_instance); |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 589 | } |
Romain Guy | f6a11b8 | 2010-06-23 17:47:49 -0700 | [diff] [blame] | 590 | |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 591 | private static native void nSetMatrix(long renderer, long matrix); |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 592 | |
Romain Guy | 5ff9df6 | 2012-01-23 17:09:05 -0800 | [diff] [blame] | 593 | @SuppressWarnings("deprecation") |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 594 | @Override |
Romain Guy | f6a11b8 | 2010-06-23 17:47:49 -0700 | [diff] [blame] | 595 | public void getMatrix(Matrix matrix) { |
| 596 | nGetMatrix(mRenderer, matrix.native_instance); |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 597 | } |
Romain Guy | f6a11b8 | 2010-06-23 17:47:49 -0700 | [diff] [blame] | 598 | |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 599 | private static native void nGetMatrix(long renderer, long matrix); |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 600 | |
| 601 | @Override |
| 602 | public void concat(Matrix matrix) { |
Romain Guy | 4e7b772 | 2013-07-16 13:47:01 -0700 | [diff] [blame] | 603 | if (matrix != null) nConcatMatrix(mRenderer, matrix.native_instance); |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 604 | } |
| 605 | |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 606 | private static native void nConcatMatrix(long renderer, long matrix); |
Romain Guy | f6a11b8 | 2010-06-23 17:47:49 -0700 | [diff] [blame] | 607 | |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 608 | /////////////////////////////////////////////////////////////////////////// |
| 609 | // State management |
| 610 | /////////////////////////////////////////////////////////////////////////// |
| 611 | |
| 612 | @Override |
| 613 | public int save() { |
Romain Guy | 8aef54f | 2010-09-01 15:13:49 -0700 | [diff] [blame] | 614 | return nSave(mRenderer, Canvas.CLIP_SAVE_FLAG | Canvas.MATRIX_SAVE_FLAG); |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 615 | } |
Romain Guy | bb9524b | 2010-06-22 18:56:38 -0700 | [diff] [blame] | 616 | |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 617 | @Override |
| 618 | public int save(int saveFlags) { |
Romain Guy | bb9524b | 2010-06-22 18:56:38 -0700 | [diff] [blame] | 619 | return nSave(mRenderer, saveFlags); |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 620 | } |
| 621 | |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 622 | private static native int nSave(long renderer, int flags); |
Romain Guy | bb9524b | 2010-06-22 18:56:38 -0700 | [diff] [blame] | 623 | |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 624 | @Override |
| 625 | public int saveLayer(RectF bounds, Paint paint, int saveFlags) { |
Romain Guy | 189887e | 2011-08-25 11:45:13 -0700 | [diff] [blame] | 626 | if (bounds != null) { |
| 627 | return saveLayer(bounds.left, bounds.top, bounds.right, bounds.bottom, paint, saveFlags); |
| 628 | } |
| 629 | |
Romain Guy | 445c83c | 2012-02-16 16:43:07 -0800 | [diff] [blame] | 630 | int count; |
Romain Guy | 189887e | 2011-08-25 11:45:13 -0700 | [diff] [blame] | 631 | int modifier = paint != null ? setupColorFilter(paint) : MODIFIER_NONE; |
Romain Guy | 445c83c | 2012-02-16 16:43:07 -0800 | [diff] [blame] | 632 | try { |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 633 | final long nativePaint = paint == null ? 0 : paint.mNativePaint; |
Romain Guy | 445c83c | 2012-02-16 16:43:07 -0800 | [diff] [blame] | 634 | count = nSaveLayer(mRenderer, nativePaint, saveFlags); |
| 635 | } finally { |
| 636 | if (modifier != MODIFIER_NONE) nResetModifiers(mRenderer, modifier); |
| 637 | } |
Romain Guy | 189887e | 2011-08-25 11:45:13 -0700 | [diff] [blame] | 638 | return count; |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 639 | } |
| 640 | |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 641 | private static native int nSaveLayer(long renderer, long paint, int saveFlags); |
Romain Guy | 189887e | 2011-08-25 11:45:13 -0700 | [diff] [blame] | 642 | |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 643 | @Override |
| 644 | public int saveLayer(float left, float top, float right, float bottom, Paint paint, |
| 645 | int saveFlags) { |
Romain Guy | 01d58e4 | 2011-01-19 21:54:02 -0800 | [diff] [blame] | 646 | if (left < right && top < bottom) { |
Romain Guy | 445c83c | 2012-02-16 16:43:07 -0800 | [diff] [blame] | 647 | int count; |
Romain Guy | a168d73 | 2011-03-18 16:50:13 -0700 | [diff] [blame] | 648 | int modifier = paint != null ? setupColorFilter(paint) : MODIFIER_NONE; |
Romain Guy | 445c83c | 2012-02-16 16:43:07 -0800 | [diff] [blame] | 649 | try { |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 650 | final long nativePaint = paint == null ? 0 : paint.mNativePaint; |
Romain Guy | 445c83c | 2012-02-16 16:43:07 -0800 | [diff] [blame] | 651 | count = nSaveLayer(mRenderer, left, top, right, bottom, nativePaint, saveFlags); |
| 652 | } finally { |
| 653 | if (modifier != MODIFIER_NONE) nResetModifiers(mRenderer, modifier); |
| 654 | } |
Romain Guy | 01d58e4 | 2011-01-19 21:54:02 -0800 | [diff] [blame] | 655 | return count; |
| 656 | } |
| 657 | return save(saveFlags); |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 658 | } |
| 659 | |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 660 | private static native int nSaveLayer(long renderer, float left, float top, |
| 661 | float right, float bottom, long paint, int saveFlags); |
Romain Guy | bd6b79b | 2010-06-26 00:13:53 -0700 | [diff] [blame] | 662 | |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 663 | @Override |
| 664 | public int saveLayerAlpha(RectF bounds, int alpha, int saveFlags) { |
Romain Guy | 189887e | 2011-08-25 11:45:13 -0700 | [diff] [blame] | 665 | if (bounds != null) { |
| 666 | return saveLayerAlpha(bounds.left, bounds.top, bounds.right, bounds.bottom, |
| 667 | alpha, saveFlags); |
| 668 | } |
| 669 | return nSaveLayerAlpha(mRenderer, alpha, saveFlags); |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 670 | } |
| 671 | |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 672 | private static native int nSaveLayerAlpha(long renderer, int alpha, int saveFlags); |
Romain Guy | 189887e | 2011-08-25 11:45:13 -0700 | [diff] [blame] | 673 | |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 674 | @Override |
| 675 | public int saveLayerAlpha(float left, float top, float right, float bottom, int alpha, |
| 676 | int saveFlags) { |
Romain Guy | 01d58e4 | 2011-01-19 21:54:02 -0800 | [diff] [blame] | 677 | if (left < right && top < bottom) { |
| 678 | return nSaveLayerAlpha(mRenderer, left, top, right, bottom, alpha, saveFlags); |
| 679 | } |
| 680 | return save(saveFlags); |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 681 | } |
| 682 | |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 683 | private static native int nSaveLayerAlpha(long renderer, float left, float top, float right, |
Romain Guy | bd6b79b | 2010-06-26 00:13:53 -0700 | [diff] [blame] | 684 | float bottom, int alpha, int saveFlags); |
| 685 | |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 686 | @Override |
| 687 | public void restore() { |
Romain Guy | bb9524b | 2010-06-22 18:56:38 -0700 | [diff] [blame] | 688 | nRestore(mRenderer); |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 689 | } |
Romain Guy | bb9524b | 2010-06-22 18:56:38 -0700 | [diff] [blame] | 690 | |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 691 | private static native void nRestore(long renderer); |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 692 | |
| 693 | @Override |
| 694 | public void restoreToCount(int saveCount) { |
Romain Guy | bb9524b | 2010-06-22 18:56:38 -0700 | [diff] [blame] | 695 | nRestoreToCount(mRenderer, saveCount); |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 696 | } |
| 697 | |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 698 | private static native void nRestoreToCount(long renderer, int saveCount); |
Romain Guy | bb9524b | 2010-06-22 18:56:38 -0700 | [diff] [blame] | 699 | |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 700 | @Override |
| 701 | public int getSaveCount() { |
Romain Guy | bb9524b | 2010-06-22 18:56:38 -0700 | [diff] [blame] | 702 | return nGetSaveCount(mRenderer); |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 703 | } |
Romain Guy | bb9524b | 2010-06-22 18:56:38 -0700 | [diff] [blame] | 704 | |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 705 | private static native int nGetSaveCount(long renderer); |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 706 | |
| 707 | /////////////////////////////////////////////////////////////////////////// |
| 708 | // Filtering |
| 709 | /////////////////////////////////////////////////////////////////////////// |
| 710 | |
| 711 | @Override |
| 712 | public void setDrawFilter(DrawFilter filter) { |
Romain Guy | 6926c72 | 2010-07-12 20:20:03 -0700 | [diff] [blame] | 713 | mFilter = filter; |
Romain Guy | 5ff9df6 | 2012-01-23 17:09:05 -0800 | [diff] [blame] | 714 | if (filter == null) { |
| 715 | nResetPaintFilter(mRenderer); |
| 716 | } else if (filter instanceof PaintFlagsDrawFilter) { |
| 717 | PaintFlagsDrawFilter flagsFilter = (PaintFlagsDrawFilter) filter; |
| 718 | nSetupPaintFilter(mRenderer, flagsFilter.clearBits, flagsFilter.setBits); |
| 719 | } |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 720 | } |
| 721 | |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 722 | private static native void nResetPaintFilter(long renderer); |
| 723 | private static native void nSetupPaintFilter(long renderer, int clearBits, int setBits); |
Romain Guy | 5ff9df6 | 2012-01-23 17:09:05 -0800 | [diff] [blame] | 724 | |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 725 | @Override |
| 726 | public DrawFilter getDrawFilter() { |
Romain Guy | 6926c72 | 2010-07-12 20:20:03 -0700 | [diff] [blame] | 727 | return mFilter; |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 728 | } |
| 729 | |
| 730 | /////////////////////////////////////////////////////////////////////////// |
| 731 | // Drawing |
| 732 | /////////////////////////////////////////////////////////////////////////// |
| 733 | |
| 734 | @Override |
| 735 | public void drawArc(RectF oval, float startAngle, float sweepAngle, boolean useCenter, |
| 736 | Paint paint) { |
Romain Guy | 765dcf3 | 2012-02-27 13:28:22 -0800 | [diff] [blame] | 737 | int modifiers = setupModifiers(paint, MODIFIER_COLOR_FILTER | MODIFIER_SHADER); |
Romain Guy | 445c83c | 2012-02-16 16:43:07 -0800 | [diff] [blame] | 738 | try { |
| 739 | nDrawArc(mRenderer, oval.left, oval.top, oval.right, oval.bottom, |
| 740 | startAngle, sweepAngle, useCenter, paint.mNativePaint); |
| 741 | } finally { |
| 742 | if (modifiers != MODIFIER_NONE) nResetModifiers(mRenderer, modifiers); |
| 743 | } |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 744 | } |
| 745 | |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 746 | private static native void nDrawArc(long renderer, float left, float top, |
Romain Guy | 7d7b549 | 2011-01-24 16:33:45 -0800 | [diff] [blame] | 747 | float right, float bottom, float startAngle, float sweepAngle, |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 748 | boolean useCenter, long paint); |
Romain Guy | 8b2f526 | 2011-01-23 16:15:02 -0800 | [diff] [blame] | 749 | |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 750 | @Override |
| 751 | public void drawARGB(int a, int r, int g, int b) { |
Romain Guy | 85bf02f | 2010-06-22 13:11:24 -0700 | [diff] [blame] | 752 | drawColor((a & 0xFF) << 24 | (r & 0xFF) << 16 | (g & 0xFF) << 8 | (b & 0xFF)); |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 753 | } |
| 754 | |
| 755 | @Override |
Romain Guy | f3187b7 | 2013-06-07 12:17:11 -0700 | [diff] [blame] | 756 | public void drawPatch(NinePatch patch, Rect dst, Paint paint) { |
| 757 | Bitmap bitmap = patch.getBitmap(); |
Chris Craik | 1abf5d6 | 2013-08-16 12:47:03 -0700 | [diff] [blame] | 758 | throwIfCannotDraw(bitmap); |
Romain Guy | f3187b7 | 2013-06-07 12:17:11 -0700 | [diff] [blame] | 759 | // Shaders are ignored when drawing patches |
| 760 | int modifier = paint != null ? setupColorFilter(paint) : MODIFIER_NONE; |
| 761 | try { |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 762 | final long nativePaint = paint == null ? 0 : paint.mNativePaint; |
Chris Craik | 0c20c38 | 2013-07-02 10:48:54 -0700 | [diff] [blame] | 763 | nDrawPatch(mRenderer, bitmap.mNativeBitmap, bitmap.mBuffer, patch.mNativeChunk, |
Romain Guy | f3187b7 | 2013-06-07 12:17:11 -0700 | [diff] [blame] | 764 | dst.left, dst.top, dst.right, dst.bottom, nativePaint); |
| 765 | } finally { |
| 766 | if (modifier != MODIFIER_NONE) nResetModifiers(mRenderer, modifier); |
| 767 | } |
| 768 | } |
| 769 | |
| 770 | @Override |
Romain Guy | 3b748a4 | 2013-04-17 18:54:38 -0700 | [diff] [blame] | 771 | public void drawPatch(NinePatch patch, RectF dst, Paint paint) { |
| 772 | Bitmap bitmap = patch.getBitmap(); |
Chris Craik | 1abf5d6 | 2013-08-16 12:47:03 -0700 | [diff] [blame] | 773 | throwIfCannotDraw(bitmap); |
Romain Guy | d27977d | 2010-07-14 19:18:51 -0700 | [diff] [blame] | 774 | // Shaders are ignored when drawing patches |
Romain Guy | a168d73 | 2011-03-18 16:50:13 -0700 | [diff] [blame] | 775 | int modifier = paint != null ? setupColorFilter(paint) : MODIFIER_NONE; |
Romain Guy | 445c83c | 2012-02-16 16:43:07 -0800 | [diff] [blame] | 776 | try { |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 777 | final long nativePaint = paint == null ? 0 : paint.mNativePaint; |
Chris Craik | 0c20c38 | 2013-07-02 10:48:54 -0700 | [diff] [blame] | 778 | nDrawPatch(mRenderer, bitmap.mNativeBitmap, bitmap.mBuffer, patch.mNativeChunk, |
Romain Guy | 445c83c | 2012-02-16 16:43:07 -0800 | [diff] [blame] | 779 | dst.left, dst.top, dst.right, dst.bottom, nativePaint); |
| 780 | } finally { |
| 781 | if (modifier != MODIFIER_NONE) nResetModifiers(mRenderer, modifier); |
| 782 | } |
Romain Guy | deba785 | 2010-07-07 17:54:48 -0700 | [diff] [blame] | 783 | } |
| 784 | |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 785 | private static native void nDrawPatch(long renderer, long bitmap, byte[] buffer, long chunk, |
| 786 | float left, float top, float right, float bottom, long paint); |
Romain Guy | deba785 | 2010-07-07 17:54:48 -0700 | [diff] [blame] | 787 | |
| 788 | @Override |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 789 | public void drawBitmap(Bitmap bitmap, float left, float top, Paint paint) { |
Chris Craik | 1abf5d6 | 2013-08-16 12:47:03 -0700 | [diff] [blame] | 790 | throwIfCannotDraw(bitmap); |
Romain Guy | d27977d | 2010-07-14 19:18:51 -0700 | [diff] [blame] | 791 | // Shaders are ignored when drawing bitmaps |
Romain Guy | a168d73 | 2011-03-18 16:50:13 -0700 | [diff] [blame] | 792 | int modifiers = paint != null ? setupModifiers(bitmap, paint) : MODIFIER_NONE; |
Romain Guy | 445c83c | 2012-02-16 16:43:07 -0800 | [diff] [blame] | 793 | try { |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 794 | final long nativePaint = paint == null ? 0 : paint.mNativePaint; |
Chris Craik | 0c20c38 | 2013-07-02 10:48:54 -0700 | [diff] [blame] | 795 | nDrawBitmap(mRenderer, bitmap.mNativeBitmap, bitmap.mBuffer, left, top, nativePaint); |
Romain Guy | 445c83c | 2012-02-16 16:43:07 -0800 | [diff] [blame] | 796 | } finally { |
| 797 | if (modifiers != MODIFIER_NONE) nResetModifiers(mRenderer, modifiers); |
| 798 | } |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 799 | } |
| 800 | |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 801 | private static native void nDrawBitmap(long renderer, long bitmap, byte[] buffer, |
| 802 | float left, float top, long paint); |
Romain Guy | dbd77cd | 2010-07-09 10:36:05 -0700 | [diff] [blame] | 803 | |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 804 | @Override |
| 805 | public void drawBitmap(Bitmap bitmap, Matrix matrix, Paint paint) { |
Chris Craik | 1abf5d6 | 2013-08-16 12:47:03 -0700 | [diff] [blame] | 806 | throwIfCannotDraw(bitmap); |
Romain Guy | d27977d | 2010-07-14 19:18:51 -0700 | [diff] [blame] | 807 | // Shaders are ignored when drawing bitmaps |
Romain Guy | a168d73 | 2011-03-18 16:50:13 -0700 | [diff] [blame] | 808 | int modifiers = paint != null ? setupModifiers(bitmap, paint) : MODIFIER_NONE; |
Romain Guy | 445c83c | 2012-02-16 16:43:07 -0800 | [diff] [blame] | 809 | try { |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 810 | final long nativePaint = paint == null ? 0 : paint.mNativePaint; |
Chris Craik | 0c20c38 | 2013-07-02 10:48:54 -0700 | [diff] [blame] | 811 | nDrawBitmap(mRenderer, bitmap.mNativeBitmap, bitmap.mBuffer, |
| 812 | matrix.native_instance, nativePaint); |
Romain Guy | 445c83c | 2012-02-16 16:43:07 -0800 | [diff] [blame] | 813 | } finally { |
| 814 | if (modifiers != MODIFIER_NONE) nResetModifiers(mRenderer, modifiers); |
| 815 | } |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 816 | } |
| 817 | |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 818 | private static native void nDrawBitmap(long renderer, long bitmap, byte[] buffer, |
| 819 | long matrix, long paint); |
Romain Guy | f86ef57 | 2010-07-01 11:05:42 -0700 | [diff] [blame] | 820 | |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 821 | @Override |
| 822 | public void drawBitmap(Bitmap bitmap, Rect src, Rect dst, Paint paint) { |
Chris Craik | 1abf5d6 | 2013-08-16 12:47:03 -0700 | [diff] [blame] | 823 | throwIfCannotDraw(bitmap); |
Romain Guy | d27977d | 2010-07-14 19:18:51 -0700 | [diff] [blame] | 824 | // Shaders are ignored when drawing bitmaps |
Romain Guy | a168d73 | 2011-03-18 16:50:13 -0700 | [diff] [blame] | 825 | int modifiers = paint != null ? setupModifiers(bitmap, paint) : MODIFIER_NONE; |
Romain Guy | 445c83c | 2012-02-16 16:43:07 -0800 | [diff] [blame] | 826 | try { |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 827 | final long nativePaint = paint == null ? 0 : paint.mNativePaint; |
Romain Guy | 694b519 | 2010-07-21 21:33:20 -0700 | [diff] [blame] | 828 | |
Romain Guy | 445c83c | 2012-02-16 16:43:07 -0800 | [diff] [blame] | 829 | int left, top, right, bottom; |
| 830 | if (src == null) { |
| 831 | left = top = 0; |
| 832 | right = bitmap.getWidth(); |
| 833 | bottom = bitmap.getHeight(); |
| 834 | } else { |
| 835 | left = src.left; |
| 836 | right = src.right; |
| 837 | top = src.top; |
| 838 | bottom = src.bottom; |
| 839 | } |
| 840 | |
Chris Craik | 0c20c38 | 2013-07-02 10:48:54 -0700 | [diff] [blame] | 841 | nDrawBitmap(mRenderer, bitmap.mNativeBitmap, bitmap.mBuffer, left, top, right, bottom, |
Romain Guy | 445c83c | 2012-02-16 16:43:07 -0800 | [diff] [blame] | 842 | dst.left, dst.top, dst.right, dst.bottom, nativePaint); |
| 843 | } finally { |
| 844 | if (modifiers != MODIFIER_NONE) nResetModifiers(mRenderer, modifiers); |
Romain Guy | 694b519 | 2010-07-21 21:33:20 -0700 | [diff] [blame] | 845 | } |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 846 | } |
| 847 | |
| 848 | @Override |
| 849 | public void drawBitmap(Bitmap bitmap, Rect src, RectF dst, Paint paint) { |
Chris Craik | 1abf5d6 | 2013-08-16 12:47:03 -0700 | [diff] [blame] | 850 | throwIfCannotDraw(bitmap); |
Romain Guy | d27977d | 2010-07-14 19:18:51 -0700 | [diff] [blame] | 851 | // Shaders are ignored when drawing bitmaps |
Romain Guy | a168d73 | 2011-03-18 16:50:13 -0700 | [diff] [blame] | 852 | int modifiers = paint != null ? setupModifiers(bitmap, paint) : MODIFIER_NONE; |
Romain Guy | 445c83c | 2012-02-16 16:43:07 -0800 | [diff] [blame] | 853 | try { |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 854 | final long nativePaint = paint == null ? 0 : paint.mNativePaint; |
Romain Guy | 445c83c | 2012-02-16 16:43:07 -0800 | [diff] [blame] | 855 | |
| 856 | float left, top, right, bottom; |
| 857 | if (src == null) { |
| 858 | left = top = 0; |
| 859 | right = bitmap.getWidth(); |
| 860 | bottom = bitmap.getHeight(); |
| 861 | } else { |
| 862 | left = src.left; |
| 863 | right = src.right; |
| 864 | top = src.top; |
| 865 | bottom = src.bottom; |
| 866 | } |
| 867 | |
Chris Craik | 0c20c38 | 2013-07-02 10:48:54 -0700 | [diff] [blame] | 868 | nDrawBitmap(mRenderer, bitmap.mNativeBitmap, bitmap.mBuffer, left, top, right, bottom, |
Romain Guy | 445c83c | 2012-02-16 16:43:07 -0800 | [diff] [blame] | 869 | dst.left, dst.top, dst.right, dst.bottom, nativePaint); |
| 870 | } finally { |
| 871 | if (modifiers != MODIFIER_NONE) nResetModifiers(mRenderer, modifiers); |
Romain Guy | ff98fa5 | 2011-11-28 09:35:09 -0800 | [diff] [blame] | 872 | } |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 873 | } |
| 874 | |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 875 | private static native void nDrawBitmap(long renderer, long bitmap, byte[] buffer, |
Romain Guy | ce0537b | 2010-06-29 21:05:21 -0700 | [diff] [blame] | 876 | float srcLeft, float srcTop, float srcRight, float srcBottom, |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 877 | float left, float top, float right, float bottom, long paint); |
Romain Guy | ce0537b | 2010-06-29 21:05:21 -0700 | [diff] [blame] | 878 | |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 879 | @Override |
| 880 | public void drawBitmap(int[] colors, int offset, int stride, float x, float y, |
| 881 | int width, int height, boolean hasAlpha, Paint paint) { |
Romain Guy | e651cc6 | 2012-05-14 19:44:40 -0700 | [diff] [blame] | 882 | if (width < 0) { |
| 883 | throw new IllegalArgumentException("width must be >= 0"); |
| 884 | } |
| 885 | |
| 886 | if (height < 0) { |
| 887 | throw new IllegalArgumentException("height must be >= 0"); |
| 888 | } |
| 889 | |
| 890 | if (Math.abs(stride) < width) { |
| 891 | throw new IllegalArgumentException("abs(stride) must be >= width"); |
| 892 | } |
| 893 | |
| 894 | int lastScanline = offset + (height - 1) * stride; |
| 895 | int length = colors.length; |
| 896 | |
| 897 | if (offset < 0 || (offset + width > length) || lastScanline < 0 || |
| 898 | (lastScanline + width > length)) { |
| 899 | throw new ArrayIndexOutOfBoundsException(); |
| 900 | } |
| 901 | |
Romain Guy | d27977d | 2010-07-14 19:18:51 -0700 | [diff] [blame] | 902 | // Shaders are ignored when drawing bitmaps |
Romain Guy | a168d73 | 2011-03-18 16:50:13 -0700 | [diff] [blame] | 903 | int modifier = paint != null ? setupColorFilter(paint) : MODIFIER_NONE; |
Romain Guy | 445c83c | 2012-02-16 16:43:07 -0800 | [diff] [blame] | 904 | try { |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 905 | final long nativePaint = paint == null ? 0 : paint.mNativePaint; |
Romain Guy | e651cc6 | 2012-05-14 19:44:40 -0700 | [diff] [blame] | 906 | nDrawBitmap(mRenderer, colors, offset, stride, x, y, |
| 907 | width, height, hasAlpha, nativePaint); |
Romain Guy | 445c83c | 2012-02-16 16:43:07 -0800 | [diff] [blame] | 908 | } finally { |
| 909 | if (modifier != MODIFIER_NONE) nResetModifiers(mRenderer, modifier); |
| 910 | } |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 911 | } |
| 912 | |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 913 | private static native void nDrawBitmap(long renderer, int[] colors, int offset, int stride, |
| 914 | float x, float y, int width, int height, boolean hasAlpha, long nativePaint); |
Romain Guy | e651cc6 | 2012-05-14 19:44:40 -0700 | [diff] [blame] | 915 | |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 916 | @Override |
| 917 | public void drawBitmap(int[] colors, int offset, int stride, int x, int y, |
| 918 | int width, int height, boolean hasAlpha, Paint paint) { |
Romain Guy | d27977d | 2010-07-14 19:18:51 -0700 | [diff] [blame] | 919 | // Shaders are ignored when drawing bitmaps |
Romain Guy | ce0537b | 2010-06-29 21:05:21 -0700 | [diff] [blame] | 920 | drawBitmap(colors, offset, stride, (float) x, (float) y, width, height, hasAlpha, paint); |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 921 | } |
| 922 | |
| 923 | @Override |
| 924 | public void drawBitmapMesh(Bitmap bitmap, int meshWidth, int meshHeight, float[] verts, |
| 925 | int vertOffset, int[] colors, int colorOffset, Paint paint) { |
Chris Craik | 1abf5d6 | 2013-08-16 12:47:03 -0700 | [diff] [blame] | 926 | throwIfCannotDraw(bitmap); |
Romain Guy | 5a7b466 | 2011-01-20 19:09:30 -0800 | [diff] [blame] | 927 | if (meshWidth < 0 || meshHeight < 0 || vertOffset < 0 || colorOffset < 0) { |
| 928 | throw new ArrayIndexOutOfBoundsException(); |
| 929 | } |
| 930 | |
| 931 | if (meshWidth == 0 || meshHeight == 0) { |
| 932 | return; |
| 933 | } |
| 934 | |
| 935 | final int count = (meshWidth + 1) * (meshHeight + 1); |
| 936 | checkRange(verts.length, vertOffset, count * 2); |
| 937 | |
Romain Guy | ff316ec | 2013-02-13 18:39:43 -0800 | [diff] [blame] | 938 | if (colors != null) { |
| 939 | checkRange(colors.length, colorOffset, count); |
| 940 | } |
Romain Guy | 5a7b466 | 2011-01-20 19:09:30 -0800 | [diff] [blame] | 941 | |
Romain Guy | a168d73 | 2011-03-18 16:50:13 -0700 | [diff] [blame] | 942 | int modifiers = paint != null ? setupModifiers(bitmap, paint) : MODIFIER_NONE; |
Romain Guy | 445c83c | 2012-02-16 16:43:07 -0800 | [diff] [blame] | 943 | try { |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 944 | final long nativePaint = paint == null ? 0 : paint.mNativePaint; |
Chris Craik | 0c20c38 | 2013-07-02 10:48:54 -0700 | [diff] [blame] | 945 | nDrawBitmapMesh(mRenderer, bitmap.mNativeBitmap, bitmap.mBuffer, meshWidth, meshHeight, |
Romain Guy | 445c83c | 2012-02-16 16:43:07 -0800 | [diff] [blame] | 946 | verts, vertOffset, colors, colorOffset, nativePaint); |
| 947 | } finally { |
| 948 | if (modifiers != MODIFIER_NONE) nResetModifiers(mRenderer, modifiers); |
| 949 | } |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 950 | } |
| 951 | |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 952 | private static native void nDrawBitmapMesh(long renderer, long bitmap, byte[] buffer, |
Romain Guy | 5a7b466 | 2011-01-20 19:09:30 -0800 | [diff] [blame] | 953 | int meshWidth, int meshHeight, float[] verts, int vertOffset, |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 954 | int[] colors, int colorOffset, long paint); |
Romain Guy | 5a7b466 | 2011-01-20 19:09:30 -0800 | [diff] [blame] | 955 | |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 956 | @Override |
| 957 | public void drawCircle(float cx, float cy, float radius, Paint paint) { |
Romain Guy | 765dcf3 | 2012-02-27 13:28:22 -0800 | [diff] [blame] | 958 | int modifiers = setupModifiers(paint, MODIFIER_COLOR_FILTER | MODIFIER_SHADER); |
Romain Guy | 445c83c | 2012-02-16 16:43:07 -0800 | [diff] [blame] | 959 | try { |
| 960 | nDrawCircle(mRenderer, cx, cy, radius, paint.mNativePaint); |
| 961 | } finally { |
| 962 | if (modifiers != MODIFIER_NONE) nResetModifiers(mRenderer, modifiers); |
| 963 | } |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 964 | } |
| 965 | |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 966 | private static native void nDrawCircle(long renderer, float cx, float cy, |
| 967 | float radius, long paint); |
Romain Guy | 01d58e4 | 2011-01-19 21:54:02 -0800 | [diff] [blame] | 968 | |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 969 | @Override |
| 970 | public void drawColor(int color) { |
Romain Guy | 85bf02f | 2010-06-22 13:11:24 -0700 | [diff] [blame] | 971 | drawColor(color, PorterDuff.Mode.SRC_OVER); |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 972 | } |
| 973 | |
| 974 | @Override |
| 975 | public void drawColor(int color, PorterDuff.Mode mode) { |
Romain Guy | 85bf02f | 2010-06-22 13:11:24 -0700 | [diff] [blame] | 976 | nDrawColor(mRenderer, color, mode.nativeInt); |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 977 | } |
Romain Guy | 85bf02f | 2010-06-22 13:11:24 -0700 | [diff] [blame] | 978 | |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 979 | private static native void nDrawColor(long renderer, int color, int mode); |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 980 | |
| 981 | @Override |
| 982 | public void drawLine(float startX, float startY, float stopX, float stopY, Paint paint) { |
Romain Guy | 6410c0a | 2013-06-17 11:21:58 -0700 | [diff] [blame] | 983 | float[] line = getLineStorage(); |
| 984 | line[0] = startX; |
| 985 | line[1] = startY; |
| 986 | line[2] = stopX; |
| 987 | line[3] = stopY; |
| 988 | drawLines(line, 0, 4, paint); |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 989 | } |
| 990 | |
| 991 | @Override |
| 992 | public void drawLines(float[] pts, int offset, int count, Paint paint) { |
Chris Craik | 5d11676 | 2013-02-19 17:49:31 -0800 | [diff] [blame] | 993 | if (count < 4) return; |
| 994 | |
Romain Guy | 759ea80 | 2010-09-16 20:49:46 -0700 | [diff] [blame] | 995 | if ((offset | count) < 0 || offset + count > pts.length) { |
| 996 | throw new IllegalArgumentException("The lines array must contain 4 elements per line."); |
| 997 | } |
Romain Guy | 765dcf3 | 2012-02-27 13:28:22 -0800 | [diff] [blame] | 998 | int modifiers = setupModifiers(paint, MODIFIER_COLOR_FILTER | MODIFIER_SHADER); |
Romain Guy | 445c83c | 2012-02-16 16:43:07 -0800 | [diff] [blame] | 999 | try { |
| 1000 | nDrawLines(mRenderer, pts, offset, count, paint.mNativePaint); |
| 1001 | } finally { |
| 1002 | if (modifiers != MODIFIER_NONE) nResetModifiers(mRenderer, modifiers); |
| 1003 | } |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 1004 | } |
| 1005 | |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 1006 | private static native void nDrawLines(long renderer, float[] points, |
| 1007 | int offset, int count, long paint); |
Romain Guy | 759ea80 | 2010-09-16 20:49:46 -0700 | [diff] [blame] | 1008 | |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 1009 | @Override |
| 1010 | public void drawLines(float[] pts, Paint paint) { |
Romain Guy | 759ea80 | 2010-09-16 20:49:46 -0700 | [diff] [blame] | 1011 | drawLines(pts, 0, pts.length, paint); |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 1012 | } |
| 1013 | |
| 1014 | @Override |
| 1015 | public void drawOval(RectF oval, Paint paint) { |
Romain Guy | 765dcf3 | 2012-02-27 13:28:22 -0800 | [diff] [blame] | 1016 | int modifiers = setupModifiers(paint, MODIFIER_COLOR_FILTER | MODIFIER_SHADER); |
Romain Guy | 445c83c | 2012-02-16 16:43:07 -0800 | [diff] [blame] | 1017 | try { |
| 1018 | nDrawOval(mRenderer, oval.left, oval.top, oval.right, oval.bottom, paint.mNativePaint); |
| 1019 | } finally { |
| 1020 | if (modifiers != MODIFIER_NONE) nResetModifiers(mRenderer, modifiers); |
| 1021 | } |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 1022 | } |
| 1023 | |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 1024 | private static native void nDrawOval(long renderer, float left, float top, |
| 1025 | float right, float bottom, long paint); |
Romain Guy | c1cd9ba3 | 2011-01-23 14:18:41 -0800 | [diff] [blame] | 1026 | |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 1027 | @Override |
| 1028 | public void drawPaint(Paint paint) { |
Romain Guy | 6410c0a | 2013-06-17 11:21:58 -0700 | [diff] [blame] | 1029 | final Rect r = getInternalClipBounds(); |
Romain Guy | 6926c72 | 2010-07-12 20:20:03 -0700 | [diff] [blame] | 1030 | nGetClipBounds(mRenderer, r); |
| 1031 | drawRect(r.left, r.top, r.right, r.bottom, paint); |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 1032 | } |
| 1033 | |
| 1034 | @Override |
| 1035 | public void drawPath(Path path, Paint paint) { |
Romain Guy | 765dcf3 | 2012-02-27 13:28:22 -0800 | [diff] [blame] | 1036 | int modifiers = setupModifiers(paint, MODIFIER_COLOR_FILTER | MODIFIER_SHADER); |
Romain Guy | 445c83c | 2012-02-16 16:43:07 -0800 | [diff] [blame] | 1037 | try { |
| 1038 | if (path.isSimplePath) { |
| 1039 | if (path.rects != null) { |
| 1040 | nDrawRects(mRenderer, path.rects.mNativeRegion, paint.mNativePaint); |
| 1041 | } |
| 1042 | } else { |
| 1043 | nDrawPath(mRenderer, path.mNativePath, paint.mNativePaint); |
Romain Guy | a48a1a8 | 2010-08-10 14:59:15 -0700 | [diff] [blame] | 1044 | } |
Romain Guy | 445c83c | 2012-02-16 16:43:07 -0800 | [diff] [blame] | 1045 | } finally { |
| 1046 | if (modifiers != MODIFIER_NONE) nResetModifiers(mRenderer, modifiers); |
Romain Guy | a48a1a8 | 2010-08-10 14:59:15 -0700 | [diff] [blame] | 1047 | } |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 1048 | } |
| 1049 | |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 1050 | private static native void nDrawPath(long renderer, long path, long paint); |
| 1051 | private static native void nDrawRects(long renderer, long region, long paint); |
Romain Guy | 7fbcc04 | 2010-08-04 15:40:07 -0700 | [diff] [blame] | 1052 | |
Romain Guy | 672433d | 2013-01-04 19:05:13 -0800 | [diff] [blame] | 1053 | void drawRects(float[] rects, int count, Paint paint) { |
| 1054 | int modifiers = setupModifiers(paint, MODIFIER_COLOR_FILTER | MODIFIER_SHADER); |
| 1055 | try { |
| 1056 | nDrawRects(mRenderer, rects, count, paint.mNativePaint); |
| 1057 | } finally { |
| 1058 | if (modifiers != MODIFIER_NONE) nResetModifiers(mRenderer, modifiers); |
| 1059 | } |
| 1060 | } |
| 1061 | |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 1062 | private static native void nDrawRects(long renderer, float[] rects, int count, long paint); |
Romain Guy | 672433d | 2013-01-04 19:05:13 -0800 | [diff] [blame] | 1063 | |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 1064 | @Override |
| 1065 | public void drawPicture(Picture picture) { |
Romain Guy | f9d9c06 | 2012-01-19 16:53:41 -0800 | [diff] [blame] | 1066 | if (picture.createdFromStream) { |
| 1067 | return; |
| 1068 | } |
| 1069 | |
Romain Guy | 75582e8 | 2012-01-18 18:13:35 -0800 | [diff] [blame] | 1070 | picture.endRecording(); |
| 1071 | // TODO: Implement rendering |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 1072 | } |
| 1073 | |
| 1074 | @Override |
| 1075 | public void drawPicture(Picture picture, Rect dst) { |
Romain Guy | f9d9c06 | 2012-01-19 16:53:41 -0800 | [diff] [blame] | 1076 | if (picture.createdFromStream) { |
| 1077 | return; |
| 1078 | } |
| 1079 | |
Romain Guy | 75582e8 | 2012-01-18 18:13:35 -0800 | [diff] [blame] | 1080 | save(); |
| 1081 | translate(dst.left, dst.top); |
| 1082 | if (picture.getWidth() > 0 && picture.getHeight() > 0) { |
| 1083 | scale(dst.width() / picture.getWidth(), dst.height() / picture.getHeight()); |
| 1084 | } |
| 1085 | drawPicture(picture); |
| 1086 | restore(); |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 1087 | } |
| 1088 | |
| 1089 | @Override |
| 1090 | public void drawPicture(Picture picture, RectF dst) { |
Romain Guy | f9d9c06 | 2012-01-19 16:53:41 -0800 | [diff] [blame] | 1091 | if (picture.createdFromStream) { |
| 1092 | return; |
| 1093 | } |
| 1094 | |
Romain Guy | 75582e8 | 2012-01-18 18:13:35 -0800 | [diff] [blame] | 1095 | save(); |
| 1096 | translate(dst.left, dst.top); |
| 1097 | if (picture.getWidth() > 0 && picture.getHeight() > 0) { |
| 1098 | scale(dst.width() / picture.getWidth(), dst.height() / picture.getHeight()); |
| 1099 | } |
| 1100 | drawPicture(picture); |
| 1101 | restore(); |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 1102 | } |
| 1103 | |
| 1104 | @Override |
| 1105 | public void drawPoint(float x, float y, Paint paint) { |
Romain Guy | 6410c0a | 2013-06-17 11:21:58 -0700 | [diff] [blame] | 1106 | float[] point = getPointStorage(); |
| 1107 | point[0] = x; |
| 1108 | point[1] = y; |
| 1109 | drawPoints(point, 0, 2, paint); |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 1110 | } |
| 1111 | |
| 1112 | @Override |
| 1113 | public void drawPoints(float[] pts, Paint paint) { |
Romain Guy | ed6fcb0 | 2011-03-21 13:11:28 -0700 | [diff] [blame] | 1114 | drawPoints(pts, 0, pts.length, paint); |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 1115 | } |
| 1116 | |
| 1117 | @Override |
Romain Guy | ed6fcb0 | 2011-03-21 13:11:28 -0700 | [diff] [blame] | 1118 | public void drawPoints(float[] pts, int offset, int count, Paint paint) { |
Chris Craik | 5d11676 | 2013-02-19 17:49:31 -0800 | [diff] [blame] | 1119 | if (count < 2) return; |
| 1120 | |
Romain Guy | 765dcf3 | 2012-02-27 13:28:22 -0800 | [diff] [blame] | 1121 | int modifiers = setupModifiers(paint, MODIFIER_COLOR_FILTER | MODIFIER_SHADER); |
Romain Guy | 445c83c | 2012-02-16 16:43:07 -0800 | [diff] [blame] | 1122 | try { |
| 1123 | nDrawPoints(mRenderer, pts, offset, count, paint.mNativePaint); |
| 1124 | } finally { |
| 1125 | if (modifiers != MODIFIER_NONE) nResetModifiers(mRenderer, modifiers); |
| 1126 | } |
Romain Guy | ed6fcb0 | 2011-03-21 13:11:28 -0700 | [diff] [blame] | 1127 | } |
| 1128 | |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 1129 | private static native void nDrawPoints(long renderer, float[] points, |
| 1130 | int offset, int count, long paint); |
Romain Guy | ed6fcb0 | 2011-03-21 13:11:28 -0700 | [diff] [blame] | 1131 | |
Romain Guy | 5ff9df6 | 2012-01-23 17:09:05 -0800 | [diff] [blame] | 1132 | @SuppressWarnings("deprecation") |
Romain Guy | ed6fcb0 | 2011-03-21 13:11:28 -0700 | [diff] [blame] | 1133 | @Override |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 1134 | public void drawPosText(char[] text, int index, int count, float[] pos, Paint paint) { |
Romain Guy | eb9a536 | 2012-01-17 17:39:26 -0800 | [diff] [blame] | 1135 | if (index < 0 || index + count > text.length || count * 2 > pos.length) { |
| 1136 | throw new IndexOutOfBoundsException(); |
| 1137 | } |
| 1138 | |
| 1139 | int modifiers = setupModifiers(paint); |
| 1140 | try { |
| 1141 | nDrawPosText(mRenderer, text, index, count, pos, paint.mNativePaint); |
| 1142 | } finally { |
| 1143 | if (modifiers != MODIFIER_NONE) nResetModifiers(mRenderer, modifiers); |
| 1144 | } |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 1145 | } |
| 1146 | |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 1147 | private static native void nDrawPosText(long renderer, char[] text, int index, int count, |
| 1148 | float[] pos, long paint); |
Romain Guy | eb9a536 | 2012-01-17 17:39:26 -0800 | [diff] [blame] | 1149 | |
Romain Guy | 5ff9df6 | 2012-01-23 17:09:05 -0800 | [diff] [blame] | 1150 | @SuppressWarnings("deprecation") |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 1151 | @Override |
| 1152 | public void drawPosText(String text, float[] pos, Paint paint) { |
Romain Guy | eb9a536 | 2012-01-17 17:39:26 -0800 | [diff] [blame] | 1153 | if (text.length() * 2 > pos.length) { |
| 1154 | throw new ArrayIndexOutOfBoundsException(); |
| 1155 | } |
| 1156 | |
| 1157 | int modifiers = setupModifiers(paint); |
| 1158 | try { |
| 1159 | nDrawPosText(mRenderer, text, 0, text.length(), pos, paint.mNativePaint); |
| 1160 | } finally { |
| 1161 | if (modifiers != MODIFIER_NONE) nResetModifiers(mRenderer, modifiers); |
| 1162 | } |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 1163 | } |
| 1164 | |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 1165 | private static native void nDrawPosText(long renderer, String text, int start, int end, |
| 1166 | float[] pos, long paint); |
Romain Guy | eb9a536 | 2012-01-17 17:39:26 -0800 | [diff] [blame] | 1167 | |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 1168 | @Override |
| 1169 | public void drawRect(float left, float top, float right, float bottom, Paint paint) { |
Romain Guy | 765dcf3 | 2012-02-27 13:28:22 -0800 | [diff] [blame] | 1170 | if (left == right || top == bottom) return; |
| 1171 | int modifiers = setupModifiers(paint, MODIFIER_COLOR_FILTER | MODIFIER_SHADER); |
Romain Guy | 445c83c | 2012-02-16 16:43:07 -0800 | [diff] [blame] | 1172 | try { |
| 1173 | nDrawRect(mRenderer, left, top, right, bottom, paint.mNativePaint); |
| 1174 | } finally { |
| 1175 | if (modifiers != MODIFIER_NONE) nResetModifiers(mRenderer, modifiers); |
| 1176 | } |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 1177 | } |
| 1178 | |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 1179 | private static native void nDrawRect(long renderer, float left, float top, |
| 1180 | float right, float bottom, long paint); |
Romain Guy | c7d5349 | 2010-06-25 13:41:57 -0700 | [diff] [blame] | 1181 | |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 1182 | @Override |
| 1183 | public void drawRect(Rect r, Paint paint) { |
Romain Guy | c7d5349 | 2010-06-25 13:41:57 -0700 | [diff] [blame] | 1184 | drawRect(r.left, r.top, r.right, r.bottom, paint); |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 1185 | } |
| 1186 | |
| 1187 | @Override |
Romain Guy | c7d5349 | 2010-06-25 13:41:57 -0700 | [diff] [blame] | 1188 | public void drawRect(RectF r, Paint paint) { |
| 1189 | drawRect(r.left, r.top, r.right, r.bottom, paint); |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 1190 | } |
| 1191 | |
| 1192 | @Override |
| 1193 | public void drawRGB(int r, int g, int b) { |
Romain Guy | 85bf02f | 2010-06-22 13:11:24 -0700 | [diff] [blame] | 1194 | drawColor(0xFF000000 | (r & 0xFF) << 16 | (g & 0xFF) << 8 | (b & 0xFF)); |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 1195 | } |
| 1196 | |
| 1197 | @Override |
| 1198 | public void drawRoundRect(RectF rect, float rx, float ry, Paint paint) { |
Romain Guy | 765dcf3 | 2012-02-27 13:28:22 -0800 | [diff] [blame] | 1199 | int modifiers = setupModifiers(paint, MODIFIER_COLOR_FILTER | MODIFIER_SHADER); |
Romain Guy | 445c83c | 2012-02-16 16:43:07 -0800 | [diff] [blame] | 1200 | try { |
| 1201 | nDrawRoundRect(mRenderer, rect.left, rect.top, rect.right, rect.bottom, |
| 1202 | rx, ry, paint.mNativePaint); |
| 1203 | } finally { |
| 1204 | if (modifiers != MODIFIER_NONE) nResetModifiers(mRenderer, modifiers); |
| 1205 | } |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 1206 | } |
| 1207 | |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 1208 | private static native void nDrawRoundRect(long renderer, float left, float top, |
| 1209 | float right, float bottom, float rx, float y, long paint); |
Romain Guy | 01d58e4 | 2011-01-19 21:54:02 -0800 | [diff] [blame] | 1210 | |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 1211 | @Override |
| 1212 | public void drawText(char[] text, int index, int count, float x, float y, Paint paint) { |
Romain Guy | a1db574 | 2010-07-20 13:09:13 -0700 | [diff] [blame] | 1213 | if ((index | count | (index + count) | (text.length - index - count)) < 0) { |
| 1214 | throw new IndexOutOfBoundsException(); |
| 1215 | } |
Romain Guy | 61c8c9c | 2010-08-09 20:48:09 -0700 | [diff] [blame] | 1216 | |
Romain Guy | a168d73 | 2011-03-18 16:50:13 -0700 | [diff] [blame] | 1217 | int modifiers = setupModifiers(paint); |
Romain Guy | 61c8c9c | 2010-08-09 20:48:09 -0700 | [diff] [blame] | 1218 | try { |
Fabrice Di Meglio | da12f38 | 2013-03-15 11:26:56 -0700 | [diff] [blame] | 1219 | nDrawText(mRenderer, text, index, count, x, y, paint.mBidiFlags, paint.mNativePaint); |
Romain Guy | 61c8c9c | 2010-08-09 20:48:09 -0700 | [diff] [blame] | 1220 | } finally { |
Romain Guy | a168d73 | 2011-03-18 16:50:13 -0700 | [diff] [blame] | 1221 | if (modifiers != MODIFIER_NONE) nResetModifiers(mRenderer, modifiers); |
Romain Guy | 61c8c9c | 2010-08-09 20:48:09 -0700 | [diff] [blame] | 1222 | } |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 1223 | } |
Romain Guy | a1db574 | 2010-07-20 13:09:13 -0700 | [diff] [blame] | 1224 | |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 1225 | private static native void nDrawText(long renderer, char[] text, int index, int count, |
| 1226 | float x, float y, int bidiFlags, long paint); |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 1227 | |
| 1228 | @Override |
| 1229 | public void drawText(CharSequence text, int start, int end, float x, float y, Paint paint) { |
Romain Guy | a168d73 | 2011-03-18 16:50:13 -0700 | [diff] [blame] | 1230 | int modifiers = setupModifiers(paint); |
Romain Guy | 61c8c9c | 2010-08-09 20:48:09 -0700 | [diff] [blame] | 1231 | try { |
| 1232 | if (text instanceof String || text instanceof SpannedString || |
| 1233 | text instanceof SpannableString) { |
Fabrice Di Meglio | da12f38 | 2013-03-15 11:26:56 -0700 | [diff] [blame] | 1234 | nDrawText(mRenderer, text.toString(), start, end, x, y, paint.mBidiFlags, |
| 1235 | paint.mNativePaint); |
Romain Guy | 61c8c9c | 2010-08-09 20:48:09 -0700 | [diff] [blame] | 1236 | } else if (text instanceof GraphicsOperations) { |
| 1237 | ((GraphicsOperations) text).drawText(this, start, end, x, y, |
| 1238 | paint); |
| 1239 | } else { |
| 1240 | char[] buf = TemporaryBuffer.obtain(end - start); |
| 1241 | TextUtils.getChars(text, start, end, buf, 0); |
Fabrice Di Meglio | da12f38 | 2013-03-15 11:26:56 -0700 | [diff] [blame] | 1242 | nDrawText(mRenderer, buf, 0, end - start, x, y, |
| 1243 | paint.mBidiFlags, paint.mNativePaint); |
Romain Guy | 61c8c9c | 2010-08-09 20:48:09 -0700 | [diff] [blame] | 1244 | TemporaryBuffer.recycle(buf); |
| 1245 | } |
| 1246 | } finally { |
Romain Guy | a168d73 | 2011-03-18 16:50:13 -0700 | [diff] [blame] | 1247 | if (modifiers != MODIFIER_NONE) nResetModifiers(mRenderer, modifiers); |
Romain Guy | a1db574 | 2010-07-20 13:09:13 -0700 | [diff] [blame] | 1248 | } |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 1249 | } |
| 1250 | |
| 1251 | @Override |
| 1252 | public void drawText(String text, int start, int end, float x, float y, Paint paint) { |
Romain Guy | a1db574 | 2010-07-20 13:09:13 -0700 | [diff] [blame] | 1253 | if ((start | end | (end - start) | (text.length() - end)) < 0) { |
| 1254 | throw new IndexOutOfBoundsException(); |
| 1255 | } |
Romain Guy | 61c8c9c | 2010-08-09 20:48:09 -0700 | [diff] [blame] | 1256 | |
Romain Guy | a168d73 | 2011-03-18 16:50:13 -0700 | [diff] [blame] | 1257 | int modifiers = setupModifiers(paint); |
Romain Guy | 61c8c9c | 2010-08-09 20:48:09 -0700 | [diff] [blame] | 1258 | try { |
Fabrice Di Meglio | da12f38 | 2013-03-15 11:26:56 -0700 | [diff] [blame] | 1259 | nDrawText(mRenderer, text, start, end, x, y, paint.mBidiFlags, paint.mNativePaint); |
Romain Guy | 61c8c9c | 2010-08-09 20:48:09 -0700 | [diff] [blame] | 1260 | } finally { |
Romain Guy | a168d73 | 2011-03-18 16:50:13 -0700 | [diff] [blame] | 1261 | if (modifiers != MODIFIER_NONE) nResetModifiers(mRenderer, modifiers); |
Romain Guy | 61c8c9c | 2010-08-09 20:48:09 -0700 | [diff] [blame] | 1262 | } |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 1263 | } |
| 1264 | |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 1265 | private static native void nDrawText(long renderer, String text, int start, int end, |
| 1266 | float x, float y, int bidiFlags, long paint); |
Romain Guy | a1db574 | 2010-07-20 13:09:13 -0700 | [diff] [blame] | 1267 | |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 1268 | @Override |
| 1269 | public void drawText(String text, float x, float y, Paint paint) { |
Romain Guy | a168d73 | 2011-03-18 16:50:13 -0700 | [diff] [blame] | 1270 | int modifiers = setupModifiers(paint); |
Romain Guy | 61c8c9c | 2010-08-09 20:48:09 -0700 | [diff] [blame] | 1271 | try { |
Fabrice Di Meglio | da12f38 | 2013-03-15 11:26:56 -0700 | [diff] [blame] | 1272 | nDrawText(mRenderer, text, 0, text.length(), x, y, paint.mBidiFlags, |
| 1273 | paint.mNativePaint); |
Romain Guy | 61c8c9c | 2010-08-09 20:48:09 -0700 | [diff] [blame] | 1274 | } finally { |
Romain Guy | a168d73 | 2011-03-18 16:50:13 -0700 | [diff] [blame] | 1275 | if (modifiers != MODIFIER_NONE) nResetModifiers(mRenderer, modifiers); |
Romain Guy | 61c8c9c | 2010-08-09 20:48:09 -0700 | [diff] [blame] | 1276 | } |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 1277 | } |
| 1278 | |
| 1279 | @Override |
| 1280 | public void drawTextOnPath(char[] text, int index, int count, Path path, float hOffset, |
| 1281 | float vOffset, Paint paint) { |
Romain Guy | 325740f | 2012-02-24 16:48:34 -0800 | [diff] [blame] | 1282 | if (index < 0 || index + count > text.length) { |
| 1283 | throw new ArrayIndexOutOfBoundsException(); |
| 1284 | } |
| 1285 | |
| 1286 | int modifiers = setupModifiers(paint); |
| 1287 | try { |
| 1288 | nDrawTextOnPath(mRenderer, text, index, count, path.mNativePath, hOffset, vOffset, |
Fabrice Di Meglio | da12f38 | 2013-03-15 11:26:56 -0700 | [diff] [blame] | 1289 | paint.mBidiFlags, paint.mNativePaint); |
Romain Guy | 325740f | 2012-02-24 16:48:34 -0800 | [diff] [blame] | 1290 | } finally { |
| 1291 | if (modifiers != MODIFIER_NONE) nResetModifiers(mRenderer, modifiers); |
| 1292 | } |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 1293 | } |
| 1294 | |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 1295 | private static native void nDrawTextOnPath(long renderer, char[] text, int index, int count, |
| 1296 | long path, float hOffset, float vOffset, int bidiFlags, long nativePaint); |
Romain Guy | 325740f | 2012-02-24 16:48:34 -0800 | [diff] [blame] | 1297 | |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 1298 | @Override |
| 1299 | public void drawTextOnPath(String text, Path path, float hOffset, float vOffset, Paint paint) { |
Romain Guy | 325740f | 2012-02-24 16:48:34 -0800 | [diff] [blame] | 1300 | if (text.length() == 0) return; |
| 1301 | |
| 1302 | int modifiers = setupModifiers(paint); |
| 1303 | try { |
| 1304 | nDrawTextOnPath(mRenderer, text, 0, text.length(), path.mNativePath, hOffset, vOffset, |
Fabrice Di Meglio | da12f38 | 2013-03-15 11:26:56 -0700 | [diff] [blame] | 1305 | paint.mBidiFlags, paint.mNativePaint); |
Romain Guy | 325740f | 2012-02-24 16:48:34 -0800 | [diff] [blame] | 1306 | } finally { |
| 1307 | if (modifiers != MODIFIER_NONE) nResetModifiers(mRenderer, modifiers); |
| 1308 | } |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 1309 | } |
| 1310 | |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 1311 | private static native void nDrawTextOnPath(long renderer, String text, int start, int end, |
| 1312 | long path, float hOffset, float vOffset, int bidiFlags, long nativePaint); |
Romain Guy | 325740f | 2012-02-24 16:48:34 -0800 | [diff] [blame] | 1313 | |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 1314 | @Override |
| 1315 | public void drawTextRun(char[] text, int index, int count, int contextIndex, int contextCount, |
Fabrice Di Meglio | da12f38 | 2013-03-15 11:26:56 -0700 | [diff] [blame] | 1316 | float x, float y, int dir, Paint paint) { |
Romain Guy | 61c8c9c | 2010-08-09 20:48:09 -0700 | [diff] [blame] | 1317 | if ((index | count | text.length - index - count) < 0) { |
| 1318 | throw new IndexOutOfBoundsException(); |
| 1319 | } |
Fabrice Di Meglio | da12f38 | 2013-03-15 11:26:56 -0700 | [diff] [blame] | 1320 | if (dir != DIRECTION_LTR && dir != DIRECTION_RTL) { |
| 1321 | throw new IllegalArgumentException("Unknown direction: " + dir); |
| 1322 | } |
Romain Guy | 61c8c9c | 2010-08-09 20:48:09 -0700 | [diff] [blame] | 1323 | |
Romain Guy | a168d73 | 2011-03-18 16:50:13 -0700 | [diff] [blame] | 1324 | int modifiers = setupModifiers(paint); |
Romain Guy | 61c8c9c | 2010-08-09 20:48:09 -0700 | [diff] [blame] | 1325 | try { |
Fabrice Di Meglio | da12f38 | 2013-03-15 11:26:56 -0700 | [diff] [blame] | 1326 | nDrawTextRun(mRenderer, text, index, count, contextIndex, contextCount, x, y, dir, |
Romain Guy | 61c8c9c | 2010-08-09 20:48:09 -0700 | [diff] [blame] | 1327 | paint.mNativePaint); |
| 1328 | } finally { |
Romain Guy | a168d73 | 2011-03-18 16:50:13 -0700 | [diff] [blame] | 1329 | if (modifiers != MODIFIER_NONE) nResetModifiers(mRenderer, modifiers); |
Romain Guy | 61c8c9c | 2010-08-09 20:48:09 -0700 | [diff] [blame] | 1330 | } |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 1331 | } |
| 1332 | |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 1333 | private static native void nDrawTextRun(long renderer, char[] text, int index, int count, |
| 1334 | int contextIndex, int contextCount, float x, float y, int dir, long nativePaint); |
Romain Guy | 61c8c9c | 2010-08-09 20:48:09 -0700 | [diff] [blame] | 1335 | |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 1336 | @Override |
| 1337 | public void drawTextRun(CharSequence text, int start, int end, int contextStart, int contextEnd, |
Fabrice Di Meglio | da12f38 | 2013-03-15 11:26:56 -0700 | [diff] [blame] | 1338 | float x, float y, int dir, Paint paint) { |
Romain Guy | 61c8c9c | 2010-08-09 20:48:09 -0700 | [diff] [blame] | 1339 | if ((start | end | end - start | text.length() - end) < 0) { |
| 1340 | throw new IndexOutOfBoundsException(); |
| 1341 | } |
| 1342 | |
Romain Guy | a168d73 | 2011-03-18 16:50:13 -0700 | [diff] [blame] | 1343 | int modifiers = setupModifiers(paint); |
Romain Guy | 61c8c9c | 2010-08-09 20:48:09 -0700 | [diff] [blame] | 1344 | try { |
Fabrice Di Meglio | da12f38 | 2013-03-15 11:26:56 -0700 | [diff] [blame] | 1345 | int flags = dir == 0 ? 0 : 1; |
Romain Guy | 61c8c9c | 2010-08-09 20:48:09 -0700 | [diff] [blame] | 1346 | if (text instanceof String || text instanceof SpannedString || |
| 1347 | text instanceof SpannableString) { |
| 1348 | nDrawTextRun(mRenderer, text.toString(), start, end, contextStart, |
Fabrice Di Meglio | da12f38 | 2013-03-15 11:26:56 -0700 | [diff] [blame] | 1349 | contextEnd, x, y, flags, paint.mNativePaint); |
Romain Guy | 61c8c9c | 2010-08-09 20:48:09 -0700 | [diff] [blame] | 1350 | } else if (text instanceof GraphicsOperations) { |
| 1351 | ((GraphicsOperations) text).drawTextRun(this, start, end, |
Fabrice Di Meglio | da12f38 | 2013-03-15 11:26:56 -0700 | [diff] [blame] | 1352 | contextStart, contextEnd, x, y, flags, paint); |
Romain Guy | 61c8c9c | 2010-08-09 20:48:09 -0700 | [diff] [blame] | 1353 | } else { |
| 1354 | int contextLen = contextEnd - contextStart; |
| 1355 | int len = end - start; |
| 1356 | char[] buf = TemporaryBuffer.obtain(contextLen); |
| 1357 | TextUtils.getChars(text, contextStart, contextEnd, buf, 0); |
| 1358 | nDrawTextRun(mRenderer, buf, start - contextStart, len, 0, contextLen, |
Fabrice Di Meglio | da12f38 | 2013-03-15 11:26:56 -0700 | [diff] [blame] | 1359 | x, y, flags, paint.mNativePaint); |
Romain Guy | 61c8c9c | 2010-08-09 20:48:09 -0700 | [diff] [blame] | 1360 | TemporaryBuffer.recycle(buf); |
| 1361 | } |
| 1362 | } finally { |
Romain Guy | a168d73 | 2011-03-18 16:50:13 -0700 | [diff] [blame] | 1363 | if (modifiers != MODIFIER_NONE) nResetModifiers(mRenderer, modifiers); |
Romain Guy | 61c8c9c | 2010-08-09 20:48:09 -0700 | [diff] [blame] | 1364 | } |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 1365 | } |
| 1366 | |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 1367 | private static native void nDrawTextRun(long renderer, String text, int start, int end, |
| 1368 | int contextStart, int contextEnd, float x, float y, int flags, long nativePaint); |
Romain Guy | 61c8c9c | 2010-08-09 20:48:09 -0700 | [diff] [blame] | 1369 | |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 1370 | @Override |
| 1371 | public void drawVertices(VertexMode mode, int vertexCount, float[] verts, int vertOffset, |
| 1372 | float[] texs, int texOffset, int[] colors, int colorOffset, short[] indices, |
| 1373 | int indexOffset, int indexCount, Paint paint) { |
Romain Guy | 6926c72 | 2010-07-12 20:20:03 -0700 | [diff] [blame] | 1374 | // TODO: Implement |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 1375 | } |
Romain Guy | d27977d | 2010-07-14 19:18:51 -0700 | [diff] [blame] | 1376 | |
Romain Guy | a168d73 | 2011-03-18 16:50:13 -0700 | [diff] [blame] | 1377 | private int setupModifiers(Bitmap b, Paint paint) { |
Romain Guy | 445c83c | 2012-02-16 16:43:07 -0800 | [diff] [blame] | 1378 | if (b.getConfig() != Bitmap.Config.ALPHA_8) { |
| 1379 | final ColorFilter filter = paint.getColorFilter(); |
| 1380 | if (filter != null) { |
| 1381 | nSetupColorFilter(mRenderer, filter.nativeColorFilter); |
| 1382 | return MODIFIER_COLOR_FILTER; |
| 1383 | } |
| 1384 | |
| 1385 | return MODIFIER_NONE; |
| 1386 | } else { |
Romain Guy | a168d73 | 2011-03-18 16:50:13 -0700 | [diff] [blame] | 1387 | return setupModifiers(paint); |
| 1388 | } |
Romain Guy | a168d73 | 2011-03-18 16:50:13 -0700 | [diff] [blame] | 1389 | } |
| 1390 | |
| 1391 | private int setupModifiers(Paint paint) { |
| 1392 | int modifiers = MODIFIER_NONE; |
Romain Guy | db1938e | 2010-08-02 18:50:22 -0700 | [diff] [blame] | 1393 | |
Romain Guy | 1e45aae | 2010-08-13 19:39:53 -0700 | [diff] [blame] | 1394 | if (paint.hasShadow) { |
| 1395 | nSetupShadow(mRenderer, paint.shadowRadius, paint.shadowDx, paint.shadowDy, |
| 1396 | paint.shadowColor); |
Romain Guy | a168d73 | 2011-03-18 16:50:13 -0700 | [diff] [blame] | 1397 | modifiers |= MODIFIER_SHADOW; |
Romain Guy | 1e45aae | 2010-08-13 19:39:53 -0700 | [diff] [blame] | 1398 | } |
| 1399 | |
Romain Guy | d27977d | 2010-07-14 19:18:51 -0700 | [diff] [blame] | 1400 | final Shader shader = paint.getShader(); |
| 1401 | if (shader != null) { |
Romain Guy | 06f96e2 | 2010-07-30 19:18:16 -0700 | [diff] [blame] | 1402 | nSetupShader(mRenderer, shader.native_shader); |
Romain Guy | a168d73 | 2011-03-18 16:50:13 -0700 | [diff] [blame] | 1403 | modifiers |= MODIFIER_SHADER; |
Romain Guy | db1938e | 2010-08-02 18:50:22 -0700 | [diff] [blame] | 1404 | } |
| 1405 | |
| 1406 | final ColorFilter filter = paint.getColorFilter(); |
| 1407 | if (filter != null) { |
| 1408 | nSetupColorFilter(mRenderer, filter.nativeColorFilter); |
Romain Guy | a168d73 | 2011-03-18 16:50:13 -0700 | [diff] [blame] | 1409 | modifiers |= MODIFIER_COLOR_FILTER; |
Romain Guy | db1938e | 2010-08-02 18:50:22 -0700 | [diff] [blame] | 1410 | } |
| 1411 | |
Romain Guy | a168d73 | 2011-03-18 16:50:13 -0700 | [diff] [blame] | 1412 | return modifiers; |
Romain Guy | db1938e | 2010-08-02 18:50:22 -0700 | [diff] [blame] | 1413 | } |
Romain Guy | 1e45aae | 2010-08-13 19:39:53 -0700 | [diff] [blame] | 1414 | |
Romain Guy | 765dcf3 | 2012-02-27 13:28:22 -0800 | [diff] [blame] | 1415 | private int setupModifiers(Paint paint, int flags) { |
| 1416 | int modifiers = MODIFIER_NONE; |
| 1417 | |
| 1418 | if (paint.hasShadow && (flags & MODIFIER_SHADOW) != 0) { |
| 1419 | nSetupShadow(mRenderer, paint.shadowRadius, paint.shadowDx, paint.shadowDy, |
| 1420 | paint.shadowColor); |
| 1421 | modifiers |= MODIFIER_SHADOW; |
| 1422 | } |
| 1423 | |
| 1424 | final Shader shader = paint.getShader(); |
| 1425 | if (shader != null && (flags & MODIFIER_SHADER) != 0) { |
| 1426 | nSetupShader(mRenderer, shader.native_shader); |
| 1427 | modifiers |= MODIFIER_SHADER; |
| 1428 | } |
| 1429 | |
| 1430 | final ColorFilter filter = paint.getColorFilter(); |
| 1431 | if (filter != null && (flags & MODIFIER_COLOR_FILTER) != 0) { |
| 1432 | nSetupColorFilter(mRenderer, filter.nativeColorFilter); |
| 1433 | modifiers |= MODIFIER_COLOR_FILTER; |
| 1434 | } |
| 1435 | |
| 1436 | return modifiers; |
| 1437 | } |
| 1438 | |
Romain Guy | a168d73 | 2011-03-18 16:50:13 -0700 | [diff] [blame] | 1439 | private int setupColorFilter(Paint paint) { |
Romain Guy | db1938e | 2010-08-02 18:50:22 -0700 | [diff] [blame] | 1440 | final ColorFilter filter = paint.getColorFilter(); |
| 1441 | if (filter != null) { |
| 1442 | nSetupColorFilter(mRenderer, filter.nativeColorFilter); |
Romain Guy | a168d73 | 2011-03-18 16:50:13 -0700 | [diff] [blame] | 1443 | return MODIFIER_COLOR_FILTER; |
Romain Guy | d27977d | 2010-07-14 19:18:51 -0700 | [diff] [blame] | 1444 | } |
Romain Guy | 5621527 | 2011-03-23 16:55:38 -0700 | [diff] [blame] | 1445 | return MODIFIER_NONE; |
Romain Guy | d27977d | 2010-07-14 19:18:51 -0700 | [diff] [blame] | 1446 | } |
Romain Guy | a168d73 | 2011-03-18 16:50:13 -0700 | [diff] [blame] | 1447 | |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 1448 | private static native void nSetupShader(long renderer, long shader); |
| 1449 | private static native void nSetupColorFilter(long renderer, long colorFilter); |
| 1450 | private static native void nSetupShadow(long renderer, float radius, |
Romain Guy | 7d7b549 | 2011-01-24 16:33:45 -0800 | [diff] [blame] | 1451 | float dx, float dy, int color); |
Romain Guy | 1e45aae | 2010-08-13 19:39:53 -0700 | [diff] [blame] | 1452 | |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 1453 | private static native void nResetModifiers(long renderer, int modifiers); |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 1454 | } |