Derek Sollenberger | 8872b38 | 2014-06-23 14:13:53 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2014 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 | #include "jni.h" |
| 18 | #include "GraphicsJNI.h" |
Andreas Gampe | ed6b9df | 2014-11-20 22:02:20 -0800 | [diff] [blame] | 19 | #include "core_jni_helpers.h" |
Derek Sollenberger | 8872b38 | 2014-06-23 14:13:53 -0400 | [diff] [blame] | 20 | |
Mike Reed | 322bc57 | 2018-03-20 13:37:04 -0400 | [diff] [blame] | 21 | #include <android/api-level.h> |
Derek Sollenberger | 4c5efe9 | 2015-07-10 13:56:39 -0400 | [diff] [blame] | 22 | #include <androidfw/ResourceTypes.h> |
sergeyv | dccca44 | 2016-03-21 15:38:21 -0700 | [diff] [blame] | 23 | #include <hwui/Canvas.h> |
| 24 | #include <hwui/Paint.h> |
Ben Wagner | 0ed10be | 2018-06-28 17:08:16 -0400 | [diff] [blame] | 25 | #include <hwui/PaintFilter.h> |
sergeyv | bad9918 | 2016-03-17 11:24:22 -0700 | [diff] [blame] | 26 | #include <hwui/Typeface.h> |
sergeyv | dccca44 | 2016-03-21 15:38:21 -0700 | [diff] [blame] | 27 | #include <minikin/Layout.h> |
Seigo Nonaka | 3a4217f | 2018-05-02 12:56:16 -0700 | [diff] [blame] | 28 | #include <nativehelper/ScopedPrimitiveArray.h> |
| 29 | #include <nativehelper/ScopedStringChars.h> |
Derek Sollenberger | 4c5efe9 | 2015-07-10 13:56:39 -0400 | [diff] [blame] | 30 | |
| 31 | #include "Bitmap.h" |
Derek Sollenberger | 8872b38 | 2014-06-23 14:13:53 -0400 | [diff] [blame] | 32 | #include "SkGraphics.h" |
Mike Reed | 3318f8b | 2017-02-13 16:14:10 -0500 | [diff] [blame] | 33 | #include "SkRegion.h" |
Mike Reed | 826deef | 2017-04-04 15:32:04 -0400 | [diff] [blame] | 34 | #include "SkVertices.h" |
Derek Sollenberger | 8872b38 | 2014-06-23 14:13:53 -0400 | [diff] [blame] | 35 | |
Seigo Nonaka | 783f961 | 2018-01-20 12:11:13 -0800 | [diff] [blame] | 36 | namespace minikin { |
| 37 | class MeasuredText; |
| 38 | } // namespace minikin |
| 39 | |
Derek Sollenberger | 8872b38 | 2014-06-23 14:13:53 -0400 | [diff] [blame] | 40 | namespace android { |
| 41 | |
| 42 | namespace CanvasJNI { |
| 43 | |
| 44 | static Canvas* get_canvas(jlong canvasHandle) { |
| 45 | return reinterpret_cast<Canvas*>(canvasHandle); |
| 46 | } |
| 47 | |
Richard Uhler | 775873a | 2015-12-29 12:37:39 -0800 | [diff] [blame] | 48 | static void delete_canvas(Canvas* canvas) { |
| 49 | delete canvas; |
| 50 | } |
| 51 | |
| 52 | static jlong getNativeFinalizer(JNIEnv* env, jobject clazz) { |
| 53 | return static_cast<jlong>(reinterpret_cast<uintptr_t>(&delete_canvas)); |
Derek Sollenberger | 8872b38 | 2014-06-23 14:13:53 -0400 | [diff] [blame] | 54 | } |
| 55 | |
| 56 | // Native wrapper constructor used by Canvas(Bitmap) |
Leon Scroggins III | 71fae62 | 2019-03-26 16:28:41 -0400 | [diff] [blame] | 57 | static jlong initRaster(JNIEnv* env, jobject, jlong bitmapHandle) { |
John Reck | 3731dc2 | 2015-04-13 15:20:29 -0700 | [diff] [blame] | 58 | SkBitmap bitmap; |
Leon Scroggins III | 71fae62 | 2019-03-26 16:28:41 -0400 | [diff] [blame] | 59 | if (bitmapHandle != 0) { |
| 60 | bitmap::toBitmap(bitmapHandle).getSkBitmap(&bitmap); |
John Reck | c1b33d6 | 2015-04-22 09:04:45 -0700 | [diff] [blame] | 61 | } |
John Reck | 3731dc2 | 2015-04-13 15:20:29 -0700 | [diff] [blame] | 62 | return reinterpret_cast<jlong>(Canvas::create_canvas(bitmap)); |
Derek Sollenberger | 8872b38 | 2014-06-23 14:13:53 -0400 | [diff] [blame] | 63 | } |
| 64 | |
| 65 | // Set the given bitmap as the new draw target (wrapped in a new SkCanvas), |
| 66 | // optionally copying canvas matrix & clip state. |
Leon Scroggins III | 71fae62 | 2019-03-26 16:28:41 -0400 | [diff] [blame] | 67 | static void setBitmap(JNIEnv* env, jobject, jlong canvasHandle, jlong bitmapHandle) { |
John Reck | 3731dc2 | 2015-04-13 15:20:29 -0700 | [diff] [blame] | 68 | SkBitmap bitmap; |
Leon Scroggins III | 71fae62 | 2019-03-26 16:28:41 -0400 | [diff] [blame] | 69 | if (bitmapHandle != 0) { |
| 70 | bitmap::toBitmap(bitmapHandle).getSkBitmap(&bitmap); |
John Reck | c1b33d6 | 2015-04-22 09:04:45 -0700 | [diff] [blame] | 71 | } |
John Reck | 3731dc2 | 2015-04-13 15:20:29 -0700 | [diff] [blame] | 72 | get_canvas(canvasHandle)->setBitmap(bitmap); |
Derek Sollenberger | 8872b38 | 2014-06-23 14:13:53 -0400 | [diff] [blame] | 73 | } |
| 74 | |
Chris Craik | bfa0b29 | 2017-01-19 19:12:36 -0800 | [diff] [blame] | 75 | static jboolean isOpaque(jlong canvasHandle) { |
Derek Sollenberger | 8872b38 | 2014-06-23 14:13:53 -0400 | [diff] [blame] | 76 | return get_canvas(canvasHandle)->isOpaque() ? JNI_TRUE : JNI_FALSE; |
| 77 | } |
| 78 | |
Chris Craik | bfa0b29 | 2017-01-19 19:12:36 -0800 | [diff] [blame] | 79 | static jint getWidth(jlong canvasHandle) { |
Derek Sollenberger | 8872b38 | 2014-06-23 14:13:53 -0400 | [diff] [blame] | 80 | return static_cast<jint>(get_canvas(canvasHandle)->width()); |
| 81 | } |
| 82 | |
Chris Craik | bfa0b29 | 2017-01-19 19:12:36 -0800 | [diff] [blame] | 83 | static jint getHeight(jlong canvasHandle) { |
Derek Sollenberger | 8872b38 | 2014-06-23 14:13:53 -0400 | [diff] [blame] | 84 | return static_cast<jint>(get_canvas(canvasHandle)->height()); |
| 85 | } |
| 86 | |
Chris Craik | bfa0b29 | 2017-01-19 19:12:36 -0800 | [diff] [blame] | 87 | static jint save(jlong canvasHandle, jint flagsHandle) { |
Florin Malita | eecff56 | 2015-12-21 10:43:01 -0500 | [diff] [blame] | 88 | SaveFlags::Flags flags = static_cast<SaveFlags::Flags>(flagsHandle); |
Derek Sollenberger | 8872b38 | 2014-06-23 14:13:53 -0400 | [diff] [blame] | 89 | return static_cast<jint>(get_canvas(canvasHandle)->save(flags)); |
| 90 | } |
| 91 | |
Chris Craik | bfa0b29 | 2017-01-19 19:12:36 -0800 | [diff] [blame] | 92 | static jint saveLayer(jlong canvasHandle, jfloat l, jfloat t, |
Derek Sollenberger | 8872b38 | 2014-06-23 14:13:53 -0400 | [diff] [blame] | 93 | jfloat r, jfloat b, jlong paintHandle, jint flagsHandle) { |
Behdad Esfahbod | 6ba30b8 | 2014-07-15 16:22:32 -0400 | [diff] [blame] | 94 | Paint* paint = reinterpret_cast<Paint*>(paintHandle); |
Florin Malita | eecff56 | 2015-12-21 10:43:01 -0500 | [diff] [blame] | 95 | SaveFlags::Flags flags = static_cast<SaveFlags::Flags>(flagsHandle); |
Derek Sollenberger | 8872b38 | 2014-06-23 14:13:53 -0400 | [diff] [blame] | 96 | return static_cast<jint>(get_canvas(canvasHandle)->saveLayer(l, t, r, b, paint, flags)); |
| 97 | } |
| 98 | |
Chris Craik | bfa0b29 | 2017-01-19 19:12:36 -0800 | [diff] [blame] | 99 | static jint saveLayerAlpha(jlong canvasHandle, jfloat l, jfloat t, |
Derek Sollenberger | 8872b38 | 2014-06-23 14:13:53 -0400 | [diff] [blame] | 100 | jfloat r, jfloat b, jint alpha, jint flagsHandle) { |
Florin Malita | eecff56 | 2015-12-21 10:43:01 -0500 | [diff] [blame] | 101 | SaveFlags::Flags flags = static_cast<SaveFlags::Flags>(flagsHandle); |
Derek Sollenberger | 8872b38 | 2014-06-23 14:13:53 -0400 | [diff] [blame] | 102 | return static_cast<jint>(get_canvas(canvasHandle)->saveLayerAlpha(l, t, r, b, alpha, flags)); |
| 103 | } |
| 104 | |
Derek Sollenberger | 24fc901 | 2018-12-07 14:12:12 -0500 | [diff] [blame] | 105 | static jint saveUnclippedLayer(jlong canvasHandle, jint l, jint t, jint r, jint b) { |
| 106 | return reinterpret_cast<jint>(get_canvas(canvasHandle)->saveUnclippedLayer(l, t, r, b)); |
| 107 | } |
| 108 | |
Chris Craik | bfa0b29 | 2017-01-19 19:12:36 -0800 | [diff] [blame] | 109 | static bool restore(jlong canvasHandle) { |
Derek Sollenberger | 8872b38 | 2014-06-23 14:13:53 -0400 | [diff] [blame] | 110 | Canvas* canvas = get_canvas(canvasHandle); |
Chris Craik | bfa0b29 | 2017-01-19 19:12:36 -0800 | [diff] [blame] | 111 | if (canvas->getSaveCount() <= 1) { |
| 112 | return false; // cannot restore anymore |
Derek Sollenberger | 8872b38 | 2014-06-23 14:13:53 -0400 | [diff] [blame] | 113 | } |
| 114 | canvas->restore(); |
Chris Craik | bfa0b29 | 2017-01-19 19:12:36 -0800 | [diff] [blame] | 115 | return true; // success |
Derek Sollenberger | 8872b38 | 2014-06-23 14:13:53 -0400 | [diff] [blame] | 116 | } |
| 117 | |
Chris Craik | bfa0b29 | 2017-01-19 19:12:36 -0800 | [diff] [blame] | 118 | static void restoreToCount(jlong canvasHandle, jint saveCount) { |
Derek Sollenberger | 8872b38 | 2014-06-23 14:13:53 -0400 | [diff] [blame] | 119 | Canvas* canvas = get_canvas(canvasHandle); |
Chris Craik | bfa0b29 | 2017-01-19 19:12:36 -0800 | [diff] [blame] | 120 | canvas->restoreToCount(saveCount); |
Derek Sollenberger | 8872b38 | 2014-06-23 14:13:53 -0400 | [diff] [blame] | 121 | } |
| 122 | |
Chris Craik | bfa0b29 | 2017-01-19 19:12:36 -0800 | [diff] [blame] | 123 | static jint getSaveCount(jlong canvasHandle) { |
| 124 | return static_cast<jint>(get_canvas(canvasHandle)->getSaveCount()); |
| 125 | } |
| 126 | |
| 127 | static void getMatrix(jlong canvasHandle, jlong matrixHandle) { |
Derek Sollenberger | 8872b38 | 2014-06-23 14:13:53 -0400 | [diff] [blame] | 128 | SkMatrix* matrix = reinterpret_cast<SkMatrix*>(matrixHandle); |
| 129 | get_canvas(canvasHandle)->getMatrix(matrix); |
| 130 | } |
| 131 | |
Chris Craik | bfa0b29 | 2017-01-19 19:12:36 -0800 | [diff] [blame] | 132 | static void setMatrix(jlong canvasHandle, jlong matrixHandle) { |
Derek Sollenberger | 8872b38 | 2014-06-23 14:13:53 -0400 | [diff] [blame] | 133 | const SkMatrix* matrix = reinterpret_cast<SkMatrix*>(matrixHandle); |
| 134 | get_canvas(canvasHandle)->setMatrix(matrix ? *matrix : SkMatrix::I()); |
| 135 | } |
| 136 | |
Chris Craik | bfa0b29 | 2017-01-19 19:12:36 -0800 | [diff] [blame] | 137 | static void concat(jlong canvasHandle, jlong matrixHandle) { |
Derek Sollenberger | 8872b38 | 2014-06-23 14:13:53 -0400 | [diff] [blame] | 138 | const SkMatrix* matrix = reinterpret_cast<SkMatrix*>(matrixHandle); |
| 139 | get_canvas(canvasHandle)->concat(*matrix); |
| 140 | } |
| 141 | |
Chris Craik | bfa0b29 | 2017-01-19 19:12:36 -0800 | [diff] [blame] | 142 | static void rotate(jlong canvasHandle, jfloat degrees) { |
Derek Sollenberger | 8872b38 | 2014-06-23 14:13:53 -0400 | [diff] [blame] | 143 | get_canvas(canvasHandle)->rotate(degrees); |
| 144 | } |
| 145 | |
Chris Craik | bfa0b29 | 2017-01-19 19:12:36 -0800 | [diff] [blame] | 146 | static void scale(jlong canvasHandle, jfloat sx, jfloat sy) { |
Derek Sollenberger | 8872b38 | 2014-06-23 14:13:53 -0400 | [diff] [blame] | 147 | get_canvas(canvasHandle)->scale(sx, sy); |
| 148 | } |
| 149 | |
Chris Craik | bfa0b29 | 2017-01-19 19:12:36 -0800 | [diff] [blame] | 150 | static void skew(jlong canvasHandle, jfloat sx, jfloat sy) { |
Derek Sollenberger | 8872b38 | 2014-06-23 14:13:53 -0400 | [diff] [blame] | 151 | get_canvas(canvasHandle)->skew(sx, sy); |
| 152 | } |
| 153 | |
Chris Craik | bfa0b29 | 2017-01-19 19:12:36 -0800 | [diff] [blame] | 154 | static void translate(jlong canvasHandle, jfloat dx, jfloat dy) { |
Derek Sollenberger | 8872b38 | 2014-06-23 14:13:53 -0400 | [diff] [blame] | 155 | get_canvas(canvasHandle)->translate(dx, dy); |
| 156 | } |
| 157 | |
| 158 | static jboolean getClipBounds(JNIEnv* env, jobject, jlong canvasHandle, jobject bounds) { |
| 159 | SkRect r; |
| 160 | SkIRect ir; |
| 161 | bool result = get_canvas(canvasHandle)->getClipBounds(&r); |
| 162 | |
| 163 | if (!result) { |
| 164 | r.setEmpty(); |
| 165 | } |
| 166 | r.round(&ir); |
| 167 | |
| 168 | (void)GraphicsJNI::irect_to_jrect(ir, env, bounds); |
| 169 | return result ? JNI_TRUE : JNI_FALSE; |
| 170 | } |
| 171 | |
Chris Craik | bfa0b29 | 2017-01-19 19:12:36 -0800 | [diff] [blame] | 172 | static jboolean quickRejectRect(jlong canvasHandle, |
Derek Sollenberger | 8872b38 | 2014-06-23 14:13:53 -0400 | [diff] [blame] | 173 | jfloat left, jfloat top, jfloat right, jfloat bottom) { |
| 174 | bool result = get_canvas(canvasHandle)->quickRejectRect(left, top, right, bottom); |
| 175 | return result ? JNI_TRUE : JNI_FALSE; |
| 176 | } |
| 177 | |
Chris Craik | bfa0b29 | 2017-01-19 19:12:36 -0800 | [diff] [blame] | 178 | static jboolean quickRejectPath(jlong canvasHandle, jlong pathHandle) { |
Derek Sollenberger | 8872b38 | 2014-06-23 14:13:53 -0400 | [diff] [blame] | 179 | SkPath* path = reinterpret_cast<SkPath*>(pathHandle); |
| 180 | bool result = get_canvas(canvasHandle)->quickRejectPath(*path); |
| 181 | return result ? JNI_TRUE : JNI_FALSE; |
| 182 | } |
| 183 | |
Mike Reed | 6e49c9f | 2016-12-02 15:36:59 -0500 | [diff] [blame] | 184 | // SkRegion::Op and SkClipOp are numerically identical, so we can freely cast |
| 185 | // from one to the other (though SkClipOp is destined to become a strict subset) |
Mike Reed | 6c67f1d | 2016-12-14 10:29:54 -0500 | [diff] [blame] | 186 | static_assert(SkRegion::kDifference_Op == static_cast<SkRegion::Op>(SkClipOp::kDifference), ""); |
| 187 | static_assert(SkRegion::kIntersect_Op == static_cast<SkRegion::Op>(SkClipOp::kIntersect), ""); |
Mike Reed | a0a74d5 | 2017-03-13 13:26:00 -0400 | [diff] [blame] | 188 | static_assert(SkRegion::kUnion_Op == static_cast<SkRegion::Op>(SkClipOp::kUnion_deprecated), ""); |
| 189 | static_assert(SkRegion::kXOR_Op == static_cast<SkRegion::Op>(SkClipOp::kXOR_deprecated), ""); |
| 190 | static_assert(SkRegion::kReverseDifference_Op == static_cast<SkRegion::Op>(SkClipOp::kReverseDifference_deprecated), ""); |
| 191 | static_assert(SkRegion::kReplace_Op == static_cast<SkRegion::Op>(SkClipOp::kReplace_deprecated), ""); |
Mike Reed | 6e49c9f | 2016-12-02 15:36:59 -0500 | [diff] [blame] | 192 | |
| 193 | static SkClipOp opHandleToClipOp(jint opHandle) { |
| 194 | // The opHandle is defined in Canvas.java to be Region::Op |
| 195 | SkRegion::Op rgnOp = static_cast<SkRegion::Op>(opHandle); |
| 196 | |
| 197 | // In the future, when we no longer support the wide range of ops (e.g. Union, Xor) |
| 198 | // this function can perform a range check and throw an unsupported-exception. |
| 199 | // e.g. if (rgnOp != kIntersect && rgnOp != kDifference) throw... |
| 200 | |
| 201 | // Skia now takes a different type, SkClipOp, as the parameter to clipping calls |
| 202 | // This type is binary compatible with SkRegion::Op, so a static_cast<> is safe. |
| 203 | return static_cast<SkClipOp>(rgnOp); |
| 204 | } |
| 205 | |
Chris Craik | bfa0b29 | 2017-01-19 19:12:36 -0800 | [diff] [blame] | 206 | static jboolean clipRect(jlong canvasHandle, jfloat l, jfloat t, |
Derek Sollenberger | 8872b38 | 2014-06-23 14:13:53 -0400 | [diff] [blame] | 207 | jfloat r, jfloat b, jint opHandle) { |
Mike Reed | 6e49c9f | 2016-12-02 15:36:59 -0500 | [diff] [blame] | 208 | bool nonEmptyClip = get_canvas(canvasHandle)->clipRect(l, t, r, b, |
| 209 | opHandleToClipOp(opHandle)); |
Chris Craik | 5ec6a28 | 2015-06-23 15:42:12 -0700 | [diff] [blame] | 210 | return nonEmptyClip ? JNI_TRUE : JNI_FALSE; |
Derek Sollenberger | 8872b38 | 2014-06-23 14:13:53 -0400 | [diff] [blame] | 211 | } |
| 212 | |
Chris Craik | bfa0b29 | 2017-01-19 19:12:36 -0800 | [diff] [blame] | 213 | static jboolean clipPath(jlong canvasHandle, jlong pathHandle, |
Derek Sollenberger | 8872b38 | 2014-06-23 14:13:53 -0400 | [diff] [blame] | 214 | jint opHandle) { |
| 215 | SkPath* path = reinterpret_cast<SkPath*>(pathHandle); |
Mike Reed | 6e49c9f | 2016-12-02 15:36:59 -0500 | [diff] [blame] | 216 | bool nonEmptyClip = get_canvas(canvasHandle)->clipPath(path, opHandleToClipOp(opHandle)); |
Chris Craik | 5ec6a28 | 2015-06-23 15:42:12 -0700 | [diff] [blame] | 217 | return nonEmptyClip ? JNI_TRUE : JNI_FALSE; |
Derek Sollenberger | 8872b38 | 2014-06-23 14:13:53 -0400 | [diff] [blame] | 218 | } |
| 219 | |
Derek Sollenberger | 8872b38 | 2014-06-23 14:13:53 -0400 | [diff] [blame] | 220 | static void drawColor(JNIEnv* env, jobject, jlong canvasHandle, jint color, jint modeHandle) { |
Mike Reed | 260ab72 | 2016-10-07 15:59:20 -0400 | [diff] [blame] | 221 | SkBlendMode mode = static_cast<SkBlendMode>(modeHandle); |
Chris Craik | 1526a45 | 2015-03-06 18:42:15 +0000 | [diff] [blame] | 222 | get_canvas(canvasHandle)->drawColor(color, mode); |
Derek Sollenberger | 8872b38 | 2014-06-23 14:13:53 -0400 | [diff] [blame] | 223 | } |
| 224 | |
Leon Scroggins III | bee5e20 | 2019-01-11 13:36:39 -0500 | [diff] [blame] | 225 | static void drawColorLong(JNIEnv* env, jobject, jlong canvasHandle, jlong colorSpaceHandle, |
| 226 | jlong colorLong, jint modeHandle) { |
| 227 | SkColor4f color = GraphicsJNI::convertColorLong(colorLong); |
| 228 | sk_sp<SkColorSpace> cs = GraphicsJNI::getNativeColorSpace(colorSpaceHandle); |
| 229 | SkPaint p; |
| 230 | p.setColor4f(color, cs.get()); |
| 231 | |
| 232 | SkBlendMode mode = static_cast<SkBlendMode>(modeHandle); |
| 233 | p.setBlendMode(mode); |
| 234 | get_canvas(canvasHandle)->drawPaint(p); |
| 235 | } |
| 236 | |
Derek Sollenberger | 8872b38 | 2014-06-23 14:13:53 -0400 | [diff] [blame] | 237 | static void drawPaint(JNIEnv* env, jobject, jlong canvasHandle, jlong paintHandle) { |
Behdad Esfahbod | 6ba30b8 | 2014-07-15 16:22:32 -0400 | [diff] [blame] | 238 | Paint* paint = reinterpret_cast<Paint*>(paintHandle); |
Derek Sollenberger | 8872b38 | 2014-06-23 14:13:53 -0400 | [diff] [blame] | 239 | get_canvas(canvasHandle)->drawPaint(*paint); |
| 240 | } |
| 241 | |
| 242 | static void drawPoint(JNIEnv*, jobject, jlong canvasHandle, jfloat x, jfloat y, |
| 243 | jlong paintHandle) { |
Behdad Esfahbod | 6ba30b8 | 2014-07-15 16:22:32 -0400 | [diff] [blame] | 244 | const Paint* paint = reinterpret_cast<Paint*>(paintHandle); |
Derek Sollenberger | 8872b38 | 2014-06-23 14:13:53 -0400 | [diff] [blame] | 245 | get_canvas(canvasHandle)->drawPoint(x, y, *paint); |
| 246 | } |
| 247 | |
| 248 | static void drawPoints(JNIEnv* env, jobject, jlong canvasHandle, jfloatArray jptsArray, |
| 249 | jint offset, jint count, jlong paintHandle) { |
| 250 | NPE_CHECK_RETURN_VOID(env, jptsArray); |
| 251 | AutoJavaFloatArray autoPts(env, jptsArray); |
| 252 | float* floats = autoPts.ptr(); |
| 253 | const int length = autoPts.length(); |
| 254 | |
| 255 | if ((offset | count) < 0 || offset + count > length) { |
| 256 | doThrowAIOOBE(env); |
| 257 | return; |
| 258 | } |
| 259 | |
Behdad Esfahbod | 6ba30b8 | 2014-07-15 16:22:32 -0400 | [diff] [blame] | 260 | const Paint* paint = reinterpret_cast<Paint*>(paintHandle); |
Derek Sollenberger | 8872b38 | 2014-06-23 14:13:53 -0400 | [diff] [blame] | 261 | get_canvas(canvasHandle)->drawPoints(floats + offset, count, *paint); |
| 262 | } |
| 263 | |
| 264 | static void drawLine(JNIEnv* env, jobject, jlong canvasHandle, jfloat startX, jfloat startY, |
| 265 | jfloat stopX, jfloat stopY, jlong paintHandle) { |
Behdad Esfahbod | 6ba30b8 | 2014-07-15 16:22:32 -0400 | [diff] [blame] | 266 | Paint* paint = reinterpret_cast<Paint*>(paintHandle); |
Derek Sollenberger | 8872b38 | 2014-06-23 14:13:53 -0400 | [diff] [blame] | 267 | get_canvas(canvasHandle)->drawLine(startX, startY, stopX, stopY, *paint); |
| 268 | } |
| 269 | |
| 270 | static void drawLines(JNIEnv* env, jobject, jlong canvasHandle, jfloatArray jptsArray, |
| 271 | jint offset, jint count, jlong paintHandle) { |
| 272 | NPE_CHECK_RETURN_VOID(env, jptsArray); |
| 273 | AutoJavaFloatArray autoPts(env, jptsArray); |
| 274 | float* floats = autoPts.ptr(); |
| 275 | const int length = autoPts.length(); |
| 276 | |
| 277 | if ((offset | count) < 0 || offset + count > length) { |
| 278 | doThrowAIOOBE(env); |
| 279 | return; |
| 280 | } |
| 281 | |
Behdad Esfahbod | 6ba30b8 | 2014-07-15 16:22:32 -0400 | [diff] [blame] | 282 | const Paint* paint = reinterpret_cast<Paint*>(paintHandle); |
Derek Sollenberger | 8872b38 | 2014-06-23 14:13:53 -0400 | [diff] [blame] | 283 | get_canvas(canvasHandle)->drawLines(floats + offset, count, *paint); |
| 284 | } |
| 285 | |
| 286 | static void drawRect(JNIEnv* env, jobject, jlong canvasHandle, jfloat left, jfloat top, |
| 287 | jfloat right, jfloat bottom, jlong paintHandle) { |
Behdad Esfahbod | 6ba30b8 | 2014-07-15 16:22:32 -0400 | [diff] [blame] | 288 | const Paint* paint = reinterpret_cast<Paint*>(paintHandle); |
Derek Sollenberger | 8872b38 | 2014-06-23 14:13:53 -0400 | [diff] [blame] | 289 | get_canvas(canvasHandle)->drawRect(left, top, right, bottom, *paint); |
| 290 | } |
| 291 | |
Nader Jawad | adfe1d9 | 2018-09-27 12:27:36 -0700 | [diff] [blame] | 292 | static void drawDoubleRoundRectXY(JNIEnv* env, jobject, jlong canvasHandle, jfloat outerLeft, |
| 293 | jfloat outerTop, jfloat outerRight, jfloat outerBottom, jfloat outerRx, |
| 294 | jfloat outerRy, jfloat innerLeft, jfloat innerTop, jfloat innerRight, |
| 295 | jfloat innerBottom, jfloat innerRx, jfloat innerRy, jlong paintHandle) { |
| 296 | const Paint* paint = reinterpret_cast<Paint*>(paintHandle); |
| 297 | get_canvas(canvasHandle)->drawDoubleRoundRectXY( |
| 298 | outerLeft, outerTop, outerRight, outerBottom, outerRx, outerRy, |
| 299 | innerLeft, innerTop, innerRight, innerBottom, innerRx, innerRy, *paint); |
| 300 | } |
| 301 | |
| 302 | static void drawDoubleRoundRectRadii(JNIEnv* env, jobject, jlong canvasHandle, jfloat outerLeft, |
| 303 | jfloat outerTop, jfloat outerRight, jfloat outerBottom, jfloatArray jouterRadii, |
| 304 | jfloat innerLeft, jfloat innerTop, jfloat innerRight, |
| 305 | jfloat innerBottom, jfloatArray jinnerRadii, jlong paintHandle) { |
| 306 | const Paint* paint = reinterpret_cast<Paint*>(paintHandle); |
| 307 | |
| 308 | float outerRadii[8]; |
| 309 | float innerRadii[8]; |
| 310 | env->GetFloatArrayRegion(jouterRadii, 0, 8, outerRadii); |
| 311 | env->GetFloatArrayRegion(jinnerRadii, 0, 8, innerRadii); |
| 312 | get_canvas(canvasHandle)->drawDoubleRoundRectRadii( |
| 313 | outerLeft, outerTop, outerRight, outerBottom, outerRadii, |
| 314 | innerLeft, innerTop, innerRight, innerBottom, innerRadii, *paint); |
| 315 | |
| 316 | } |
| 317 | |
Derek Sollenberger | 94394b3 | 2015-07-10 09:58:41 -0400 | [diff] [blame] | 318 | static void drawRegion(JNIEnv* env, jobject, jlong canvasHandle, jlong regionHandle, |
| 319 | jlong paintHandle) { |
| 320 | const SkRegion* region = reinterpret_cast<SkRegion*>(regionHandle); |
| 321 | const Paint* paint = reinterpret_cast<Paint*>(paintHandle); |
| 322 | get_canvas(canvasHandle)->drawRegion(*region, *paint); |
| 323 | } |
| 324 | |
Derek Sollenberger | 8872b38 | 2014-06-23 14:13:53 -0400 | [diff] [blame] | 325 | static void drawRoundRect(JNIEnv* env, jobject, jlong canvasHandle, jfloat left, jfloat top, |
| 326 | jfloat right, jfloat bottom, jfloat rx, jfloat ry, jlong paintHandle) { |
Behdad Esfahbod | 6ba30b8 | 2014-07-15 16:22:32 -0400 | [diff] [blame] | 327 | const Paint* paint = reinterpret_cast<Paint*>(paintHandle); |
Derek Sollenberger | 8872b38 | 2014-06-23 14:13:53 -0400 | [diff] [blame] | 328 | get_canvas(canvasHandle)->drawRoundRect(left, top, right, bottom, rx, ry, *paint); |
| 329 | } |
| 330 | |
| 331 | static void drawCircle(JNIEnv* env, jobject, jlong canvasHandle, jfloat cx, jfloat cy, |
| 332 | jfloat radius, jlong paintHandle) { |
Behdad Esfahbod | 6ba30b8 | 2014-07-15 16:22:32 -0400 | [diff] [blame] | 333 | const Paint* paint = reinterpret_cast<Paint*>(paintHandle); |
Derek Sollenberger | 8872b38 | 2014-06-23 14:13:53 -0400 | [diff] [blame] | 334 | get_canvas(canvasHandle)->drawCircle(cx, cy, radius, *paint); |
| 335 | } |
| 336 | |
| 337 | static void drawOval(JNIEnv* env, jobject, jlong canvasHandle, jfloat left, jfloat top, |
| 338 | jfloat right, jfloat bottom, jlong paintHandle) { |
Behdad Esfahbod | 6ba30b8 | 2014-07-15 16:22:32 -0400 | [diff] [blame] | 339 | const Paint* paint = reinterpret_cast<Paint*>(paintHandle); |
Derek Sollenberger | 8872b38 | 2014-06-23 14:13:53 -0400 | [diff] [blame] | 340 | get_canvas(canvasHandle)->drawOval(left, top, right, bottom, *paint); |
| 341 | } |
| 342 | |
| 343 | static void drawArc(JNIEnv* env, jobject, jlong canvasHandle, jfloat left, jfloat top, |
| 344 | jfloat right, jfloat bottom, jfloat startAngle, jfloat sweepAngle, |
| 345 | jboolean useCenter, jlong paintHandle) { |
Behdad Esfahbod | 6ba30b8 | 2014-07-15 16:22:32 -0400 | [diff] [blame] | 346 | const Paint* paint = reinterpret_cast<Paint*>(paintHandle); |
Derek Sollenberger | 8872b38 | 2014-06-23 14:13:53 -0400 | [diff] [blame] | 347 | get_canvas(canvasHandle)->drawArc(left, top, right, bottom, startAngle, sweepAngle, |
| 348 | useCenter, *paint); |
| 349 | } |
| 350 | |
| 351 | static void drawPath(JNIEnv* env, jobject, jlong canvasHandle, jlong pathHandle, |
| 352 | jlong paintHandle) { |
| 353 | const SkPath* path = reinterpret_cast<SkPath*>(pathHandle); |
Behdad Esfahbod | 6ba30b8 | 2014-07-15 16:22:32 -0400 | [diff] [blame] | 354 | const Paint* paint = reinterpret_cast<Paint*>(paintHandle); |
Derek Sollenberger | 8872b38 | 2014-06-23 14:13:53 -0400 | [diff] [blame] | 355 | get_canvas(canvasHandle)->drawPath(*path, *paint); |
| 356 | } |
| 357 | |
| 358 | static void drawVertices(JNIEnv* env, jobject, jlong canvasHandle, |
Mike Reed | 826deef | 2017-04-04 15:32:04 -0400 | [diff] [blame] | 359 | jint modeHandle, jint floatCount, |
Derek Sollenberger | 8872b38 | 2014-06-23 14:13:53 -0400 | [diff] [blame] | 360 | jfloatArray jverts, jint vertIndex, |
| 361 | jfloatArray jtexs, jint texIndex, |
| 362 | jintArray jcolors, jint colorIndex, |
| 363 | jshortArray jindices, jint indexIndex, |
| 364 | jint indexCount, jlong paintHandle) { |
John Reck | d51e994 | 2018-08-01 13:34:37 -0700 | [diff] [blame] | 365 | |
| 366 | const int vertexCount = floatCount >> 1; // 2 floats per SkPoint |
| 367 | |
Mike Reed | 826deef | 2017-04-04 15:32:04 -0400 | [diff] [blame] | 368 | AutoJavaFloatArray vertA(env, jverts, vertIndex + floatCount); |
| 369 | AutoJavaFloatArray texA(env, jtexs, texIndex + floatCount); |
John Reck | d51e994 | 2018-08-01 13:34:37 -0700 | [diff] [blame] | 370 | AutoJavaIntArray colorA(env, jcolors, colorIndex + vertexCount); |
Derek Sollenberger | 8872b38 | 2014-06-23 14:13:53 -0400 | [diff] [blame] | 371 | AutoJavaShortArray indexA(env, jindices, indexIndex + indexCount); |
| 372 | |
| 373 | const float* verts = vertA.ptr() + vertIndex; |
| 374 | const float* texs = texA.ptr() + vertIndex; |
| 375 | const int* colors = NULL; |
| 376 | const uint16_t* indices = NULL; |
| 377 | |
| 378 | if (jcolors != NULL) { |
| 379 | colors = colorA.ptr() + colorIndex; |
| 380 | } |
| 381 | if (jindices != NULL) { |
| 382 | indices = (const uint16_t*)(indexA.ptr() + indexIndex); |
| 383 | } |
| 384 | |
Mike Reed | 826deef | 2017-04-04 15:32:04 -0400 | [diff] [blame] | 385 | SkVertices::VertexMode mode = static_cast<SkVertices::VertexMode>(modeHandle); |
Behdad Esfahbod | 6ba30b8 | 2014-07-15 16:22:32 -0400 | [diff] [blame] | 386 | const Paint* paint = reinterpret_cast<Paint*>(paintHandle); |
Mike Reed | 826deef | 2017-04-04 15:32:04 -0400 | [diff] [blame] | 387 | get_canvas(canvasHandle)->drawVertices(SkVertices::MakeCopy(mode, vertexCount, |
| 388 | reinterpret_cast<const SkPoint*>(verts), |
| 389 | reinterpret_cast<const SkPoint*>(texs), |
| 390 | reinterpret_cast<const SkColor*>(colors), |
| 391 | indexCount, indices).get(), |
| 392 | SkBlendMode::kModulate, *paint); |
Derek Sollenberger | 8872b38 | 2014-06-23 14:13:53 -0400 | [diff] [blame] | 393 | } |
| 394 | |
Derek Sollenberger | 4c5efe9 | 2015-07-10 13:56:39 -0400 | [diff] [blame] | 395 | static void drawNinePatch(JNIEnv* env, jobject, jlong canvasHandle, jlong bitmapHandle, |
| 396 | jlong chunkHandle, jfloat left, jfloat top, jfloat right, jfloat bottom, |
| 397 | jlong paintHandle, jint dstDensity, jint srcDensity) { |
| 398 | |
| 399 | Canvas* canvas = get_canvas(canvasHandle); |
Leon Scroggins III | 71fae62 | 2019-03-26 16:28:41 -0400 | [diff] [blame] | 400 | Bitmap& bitmap = android::bitmap::toBitmap(bitmapHandle); |
Derek Sollenberger | 4c5efe9 | 2015-07-10 13:56:39 -0400 | [diff] [blame] | 401 | const android::Res_png_9patch* chunk = reinterpret_cast<android::Res_png_9patch*>(chunkHandle); |
| 402 | const Paint* paint = reinterpret_cast<Paint*>(paintHandle); |
| 403 | |
| 404 | if (CC_LIKELY(dstDensity == srcDensity || dstDensity == 0 || srcDensity == 0)) { |
sergeyv | 5fd2a1c | 2016-10-20 15:04:28 -0700 | [diff] [blame] | 405 | canvas->drawNinePatch(bitmap, *chunk, left, top, right, bottom, paint); |
Derek Sollenberger | 4c5efe9 | 2015-07-10 13:56:39 -0400 | [diff] [blame] | 406 | } else { |
Florin Malita | eecff56 | 2015-12-21 10:43:01 -0500 | [diff] [blame] | 407 | canvas->save(SaveFlags::MatrixClip); |
Derek Sollenberger | 4c5efe9 | 2015-07-10 13:56:39 -0400 | [diff] [blame] | 408 | |
| 409 | SkScalar scale = dstDensity / (float)srcDensity; |
| 410 | canvas->translate(left, top); |
| 411 | canvas->scale(scale, scale); |
| 412 | |
| 413 | Paint filteredPaint; |
| 414 | if (paint) { |
| 415 | filteredPaint = *paint; |
| 416 | } |
| 417 | filteredPaint.setFilterQuality(kLow_SkFilterQuality); |
| 418 | |
sergeyv | 5fd2a1c | 2016-10-20 15:04:28 -0700 | [diff] [blame] | 419 | canvas->drawNinePatch(bitmap, *chunk, 0, 0, (right-left)/scale, (bottom-top)/scale, |
Derek Sollenberger | 4c5efe9 | 2015-07-10 13:56:39 -0400 | [diff] [blame] | 420 | &filteredPaint); |
| 421 | |
| 422 | canvas->restore(); |
| 423 | } |
| 424 | } |
| 425 | |
Leon Scroggins III | 71fae62 | 2019-03-26 16:28:41 -0400 | [diff] [blame] | 426 | static void drawBitmap(JNIEnv* env, jobject, jlong canvasHandle, jlong bitmapHandle, |
Derek Sollenberger | 8872b38 | 2014-06-23 14:13:53 -0400 | [diff] [blame] | 427 | jfloat left, jfloat top, jlong paintHandle, jint canvasDensity, |
| 428 | jint screenDensity, jint bitmapDensity) { |
| 429 | Canvas* canvas = get_canvas(canvasHandle); |
Leon Scroggins III | 71fae62 | 2019-03-26 16:28:41 -0400 | [diff] [blame] | 430 | Bitmap& bitmap = android::bitmap::toBitmap(bitmapHandle); |
Behdad Esfahbod | 6ba30b8 | 2014-07-15 16:22:32 -0400 | [diff] [blame] | 431 | const Paint* paint = reinterpret_cast<Paint*>(paintHandle); |
Derek Sollenberger | 8872b38 | 2014-06-23 14:13:53 -0400 | [diff] [blame] | 432 | |
| 433 | if (canvasDensity == bitmapDensity || canvasDensity == 0 || bitmapDensity == 0) { |
| 434 | if (screenDensity != 0 && screenDensity != bitmapDensity) { |
Behdad Esfahbod | 6ba30b8 | 2014-07-15 16:22:32 -0400 | [diff] [blame] | 435 | Paint filteredPaint; |
Derek Sollenberger | 8872b38 | 2014-06-23 14:13:53 -0400 | [diff] [blame] | 436 | if (paint) { |
| 437 | filteredPaint = *paint; |
| 438 | } |
Mike Reed | 2a1ce8a | 2015-03-16 11:16:09 -0400 | [diff] [blame] | 439 | filteredPaint.setFilterQuality(kLow_SkFilterQuality); |
John Reck | 7c103a3 | 2015-04-15 15:52:10 -0700 | [diff] [blame] | 440 | canvas->drawBitmap(bitmap, left, top, &filteredPaint); |
Derek Sollenberger | 8872b38 | 2014-06-23 14:13:53 -0400 | [diff] [blame] | 441 | } else { |
John Reck | 7c103a3 | 2015-04-15 15:52:10 -0700 | [diff] [blame] | 442 | canvas->drawBitmap(bitmap, left, top, paint); |
Derek Sollenberger | 8872b38 | 2014-06-23 14:13:53 -0400 | [diff] [blame] | 443 | } |
| 444 | } else { |
Florin Malita | eecff56 | 2015-12-21 10:43:01 -0500 | [diff] [blame] | 445 | canvas->save(SaveFlags::MatrixClip); |
Derek Sollenberger | 8872b38 | 2014-06-23 14:13:53 -0400 | [diff] [blame] | 446 | SkScalar scale = canvasDensity / (float)bitmapDensity; |
| 447 | canvas->translate(left, top); |
| 448 | canvas->scale(scale, scale); |
| 449 | |
Behdad Esfahbod | 6ba30b8 | 2014-07-15 16:22:32 -0400 | [diff] [blame] | 450 | Paint filteredPaint; |
Derek Sollenberger | 8872b38 | 2014-06-23 14:13:53 -0400 | [diff] [blame] | 451 | if (paint) { |
| 452 | filteredPaint = *paint; |
| 453 | } |
Mike Reed | 2a1ce8a | 2015-03-16 11:16:09 -0400 | [diff] [blame] | 454 | filteredPaint.setFilterQuality(kLow_SkFilterQuality); |
Derek Sollenberger | 8872b38 | 2014-06-23 14:13:53 -0400 | [diff] [blame] | 455 | |
John Reck | 7c103a3 | 2015-04-15 15:52:10 -0700 | [diff] [blame] | 456 | canvas->drawBitmap(bitmap, 0, 0, &filteredPaint); |
Derek Sollenberger | 8872b38 | 2014-06-23 14:13:53 -0400 | [diff] [blame] | 457 | canvas->restore(); |
| 458 | } |
| 459 | } |
| 460 | |
Leon Scroggins III | 71fae62 | 2019-03-26 16:28:41 -0400 | [diff] [blame] | 461 | static void drawBitmapMatrix(JNIEnv* env, jobject, jlong canvasHandle, jlong bitmapHandle, |
Derek Sollenberger | 8872b38 | 2014-06-23 14:13:53 -0400 | [diff] [blame] | 462 | jlong matrixHandle, jlong paintHandle) { |
Derek Sollenberger | 8872b38 | 2014-06-23 14:13:53 -0400 | [diff] [blame] | 463 | const SkMatrix* matrix = reinterpret_cast<SkMatrix*>(matrixHandle); |
Behdad Esfahbod | 6ba30b8 | 2014-07-15 16:22:32 -0400 | [diff] [blame] | 464 | const Paint* paint = reinterpret_cast<Paint*>(paintHandle); |
Leon Scroggins III | 71fae62 | 2019-03-26 16:28:41 -0400 | [diff] [blame] | 465 | Bitmap& bitmap = android::bitmap::toBitmap(bitmapHandle); |
John Reck | 7c103a3 | 2015-04-15 15:52:10 -0700 | [diff] [blame] | 466 | get_canvas(canvasHandle)->drawBitmap(bitmap, *matrix, paint); |
Derek Sollenberger | 8872b38 | 2014-06-23 14:13:53 -0400 | [diff] [blame] | 467 | } |
| 468 | |
Leon Scroggins III | 71fae62 | 2019-03-26 16:28:41 -0400 | [diff] [blame] | 469 | static void drawBitmapRect(JNIEnv* env, jobject, jlong canvasHandle, jlong bitmapHandle, |
Derek Sollenberger | 8872b38 | 2014-06-23 14:13:53 -0400 | [diff] [blame] | 470 | float srcLeft, float srcTop, float srcRight, float srcBottom, |
| 471 | float dstLeft, float dstTop, float dstRight, float dstBottom, |
| 472 | jlong paintHandle, jint screenDensity, jint bitmapDensity) { |
| 473 | Canvas* canvas = get_canvas(canvasHandle); |
Behdad Esfahbod | 6ba30b8 | 2014-07-15 16:22:32 -0400 | [diff] [blame] | 474 | const Paint* paint = reinterpret_cast<Paint*>(paintHandle); |
Derek Sollenberger | 8872b38 | 2014-06-23 14:13:53 -0400 | [diff] [blame] | 475 | |
Leon Scroggins III | 71fae62 | 2019-03-26 16:28:41 -0400 | [diff] [blame] | 476 | Bitmap& bitmap = android::bitmap::toBitmap(bitmapHandle); |
Derek Sollenberger | 8872b38 | 2014-06-23 14:13:53 -0400 | [diff] [blame] | 477 | if (screenDensity != 0 && screenDensity != bitmapDensity) { |
Behdad Esfahbod | 6ba30b8 | 2014-07-15 16:22:32 -0400 | [diff] [blame] | 478 | Paint filteredPaint; |
Derek Sollenberger | 8872b38 | 2014-06-23 14:13:53 -0400 | [diff] [blame] | 479 | if (paint) { |
| 480 | filteredPaint = *paint; |
| 481 | } |
Mike Reed | 2a1ce8a | 2015-03-16 11:16:09 -0400 | [diff] [blame] | 482 | filteredPaint.setFilterQuality(kLow_SkFilterQuality); |
John Reck | 7c103a3 | 2015-04-15 15:52:10 -0700 | [diff] [blame] | 483 | canvas->drawBitmap(bitmap, srcLeft, srcTop, srcRight, srcBottom, |
Derek Sollenberger | 8872b38 | 2014-06-23 14:13:53 -0400 | [diff] [blame] | 484 | dstLeft, dstTop, dstRight, dstBottom, &filteredPaint); |
| 485 | } else { |
John Reck | 7c103a3 | 2015-04-15 15:52:10 -0700 | [diff] [blame] | 486 | canvas->drawBitmap(bitmap, srcLeft, srcTop, srcRight, srcBottom, |
Derek Sollenberger | 8872b38 | 2014-06-23 14:13:53 -0400 | [diff] [blame] | 487 | dstLeft, dstTop, dstRight, dstBottom, paint); |
| 488 | } |
| 489 | } |
| 490 | |
| 491 | static void drawBitmapArray(JNIEnv* env, jobject, jlong canvasHandle, |
| 492 | jintArray jcolors, jint offset, jint stride, |
| 493 | jfloat x, jfloat y, jint width, jint height, |
| 494 | jboolean hasAlpha, jlong paintHandle) { |
| 495 | // Note: If hasAlpha is false, kRGB_565_SkColorType will be used, which will |
| 496 | // correct the alphaType to kOpaque_SkAlphaType. |
John Reck | e9048f3 | 2018-03-30 13:44:35 -0700 | [diff] [blame] | 497 | SkImageInfo info = SkImageInfo::Make(width, height, |
| 498 | hasAlpha ? kN32_SkColorType : kRGB_565_SkColorType, |
| 499 | kPremul_SkAlphaType); |
Derek Sollenberger | 8872b38 | 2014-06-23 14:13:53 -0400 | [diff] [blame] | 500 | SkBitmap bitmap; |
Derek Sollenberger | 3d4eed7 | 2014-12-04 15:20:29 -0500 | [diff] [blame] | 501 | bitmap.setInfo(info); |
Leon Scroggins III | f51a80d | 2017-07-12 10:46:35 -0400 | [diff] [blame] | 502 | sk_sp<Bitmap> androidBitmap = Bitmap::allocateHeapBitmap(&bitmap); |
sergeyv | c1c5406 | 2016-10-19 18:47:26 -0700 | [diff] [blame] | 503 | if (!androidBitmap) { |
Derek Sollenberger | 8872b38 | 2014-06-23 14:13:53 -0400 | [diff] [blame] | 504 | return; |
| 505 | } |
| 506 | |
Brian Osman | 91c9c28 | 2018-08-17 16:57:15 -0400 | [diff] [blame] | 507 | if (!GraphicsJNI::SetPixels(env, jcolors, offset, stride, 0, 0, width, height, &bitmap)) { |
Derek Sollenberger | 8872b38 | 2014-06-23 14:13:53 -0400 | [diff] [blame] | 508 | return; |
| 509 | } |
| 510 | |
Behdad Esfahbod | 6ba30b8 | 2014-07-15 16:22:32 -0400 | [diff] [blame] | 511 | const Paint* paint = reinterpret_cast<Paint*>(paintHandle); |
sergeyv | aed7f58 | 2016-10-14 16:30:21 -0700 | [diff] [blame] | 512 | get_canvas(canvasHandle)->drawBitmap(*androidBitmap, x, y, paint); |
Derek Sollenberger | 8872b38 | 2014-06-23 14:13:53 -0400 | [diff] [blame] | 513 | } |
| 514 | |
Leon Scroggins III | 71fae62 | 2019-03-26 16:28:41 -0400 | [diff] [blame] | 515 | static void drawBitmapMesh(JNIEnv* env, jobject, jlong canvasHandle, jlong bitmapHandle, |
Derek Sollenberger | 8872b38 | 2014-06-23 14:13:53 -0400 | [diff] [blame] | 516 | jint meshWidth, jint meshHeight, jfloatArray jverts, |
| 517 | jint vertIndex, jintArray jcolors, jint colorIndex, jlong paintHandle) { |
Mike Reed | 322bc57 | 2018-03-20 13:37:04 -0400 | [diff] [blame] | 518 | if (Canvas::GetApiLevel() < __ANDROID_API_P__) { |
| 519 | // Before P we forgot to respect these. Now that we do respect them, explicitly |
| 520 | // zero them for backward compatibility. |
| 521 | vertIndex = 0; |
| 522 | colorIndex = 0; |
| 523 | } |
| 524 | |
Derek Sollenberger | 8872b38 | 2014-06-23 14:13:53 -0400 | [diff] [blame] | 525 | const int ptCount = (meshWidth + 1) * (meshHeight + 1); |
| 526 | AutoJavaFloatArray vertA(env, jverts, vertIndex + (ptCount << 1)); |
| 527 | AutoJavaIntArray colorA(env, jcolors, colorIndex + ptCount); |
| 528 | |
Behdad Esfahbod | 6ba30b8 | 2014-07-15 16:22:32 -0400 | [diff] [blame] | 529 | const Paint* paint = reinterpret_cast<Paint*>(paintHandle); |
Leon Scroggins III | 71fae62 | 2019-03-26 16:28:41 -0400 | [diff] [blame] | 530 | Bitmap& bitmap = android::bitmap::toBitmap(bitmapHandle); |
John Reck | 7c103a3 | 2015-04-15 15:52:10 -0700 | [diff] [blame] | 531 | get_canvas(canvasHandle)->drawBitmapMesh(bitmap, meshWidth, meshHeight, |
Mike Reed | 322bc57 | 2018-03-20 13:37:04 -0400 | [diff] [blame] | 532 | vertA.ptr() + vertIndex*2, |
| 533 | colorA.ptr() + colorIndex, paint); |
Derek Sollenberger | 8872b38 | 2014-06-23 14:13:53 -0400 | [diff] [blame] | 534 | } |
| 535 | |
Seigo Nonaka | 3a4217f | 2018-05-02 12:56:16 -0700 | [diff] [blame] | 536 | static void drawTextChars(JNIEnv* env, jobject, jlong canvasHandle, jcharArray charArray, |
Derek Sollenberger | 8872b38 | 2014-06-23 14:13:53 -0400 | [diff] [blame] | 537 | jint index, jint count, jfloat x, jfloat y, jint bidiFlags, |
Seigo Nonaka | 318ca04 | 2017-08-01 16:36:18 -0700 | [diff] [blame] | 538 | jlong paintHandle) { |
Behdad Esfahbod | 6ba30b8 | 2014-07-15 16:22:32 -0400 | [diff] [blame] | 539 | Paint* paint = reinterpret_cast<Paint*>(paintHandle); |
Seigo Nonaka | 318ca04 | 2017-08-01 16:36:18 -0700 | [diff] [blame] | 540 | const Typeface* typeface = paint->getAndroidTypeface(); |
Seigo Nonaka | 3a4217f | 2018-05-02 12:56:16 -0700 | [diff] [blame] | 541 | ScopedCharArrayRO text(env, charArray); |
Seigo Nonaka | f307adc | 2018-10-19 19:10:02 -0700 | [diff] [blame] | 542 | // drawTextString and drawTextChars doesn't use context info |
Seigo Nonaka | 3a4217f | 2018-05-02 12:56:16 -0700 | [diff] [blame] | 543 | get_canvas(canvasHandle)->drawText( |
Seigo Nonaka | f307adc | 2018-10-19 19:10:02 -0700 | [diff] [blame] | 544 | text.get() + index, count, // text buffer |
| 545 | 0, count, // draw range |
| 546 | 0, count, // context range |
Seigo Nonaka | 3a4217f | 2018-05-02 12:56:16 -0700 | [diff] [blame] | 547 | x, y, // draw position |
| 548 | static_cast<minikin::Bidi>(bidiFlags), *paint, typeface, nullptr /* measured text */); |
Derek Sollenberger | 8872b38 | 2014-06-23 14:13:53 -0400 | [diff] [blame] | 549 | } |
| 550 | |
Seigo Nonaka | 3a4217f | 2018-05-02 12:56:16 -0700 | [diff] [blame] | 551 | static void drawTextString(JNIEnv* env, jobject, jlong canvasHandle, jstring strObj, |
Derek Sollenberger | 8872b38 | 2014-06-23 14:13:53 -0400 | [diff] [blame] | 552 | jint start, jint end, jfloat x, jfloat y, jint bidiFlags, |
Seigo Nonaka | 318ca04 | 2017-08-01 16:36:18 -0700 | [diff] [blame] | 553 | jlong paintHandle) { |
Seigo Nonaka | 3a4217f | 2018-05-02 12:56:16 -0700 | [diff] [blame] | 554 | ScopedStringChars text(env, strObj); |
Behdad Esfahbod | 6ba30b8 | 2014-07-15 16:22:32 -0400 | [diff] [blame] | 555 | Paint* paint = reinterpret_cast<Paint*>(paintHandle); |
Seigo Nonaka | 318ca04 | 2017-08-01 16:36:18 -0700 | [diff] [blame] | 556 | const Typeface* typeface = paint->getAndroidTypeface(); |
Seigo Nonaka | f307adc | 2018-10-19 19:10:02 -0700 | [diff] [blame] | 557 | const int count = end - start; |
| 558 | // drawTextString and drawTextChars doesn't use context info |
Seigo Nonaka | 3a4217f | 2018-05-02 12:56:16 -0700 | [diff] [blame] | 559 | get_canvas(canvasHandle)->drawText( |
Seigo Nonaka | f307adc | 2018-10-19 19:10:02 -0700 | [diff] [blame] | 560 | text.get() + start, count, // text buffer |
| 561 | 0, count, // draw range |
| 562 | 0, count, // context range |
Seigo Nonaka | 3a4217f | 2018-05-02 12:56:16 -0700 | [diff] [blame] | 563 | x, y, // draw position |
| 564 | static_cast<minikin::Bidi>(bidiFlags), *paint, typeface, nullptr /* measured text */); |
Derek Sollenberger | 8872b38 | 2014-06-23 14:13:53 -0400 | [diff] [blame] | 565 | } |
| 566 | |
Seigo Nonaka | 3a4217f | 2018-05-02 12:56:16 -0700 | [diff] [blame] | 567 | static void drawTextRunChars(JNIEnv* env, jobject, jlong canvasHandle, jcharArray charArray, |
| 568 | jint index, jint count, jint contextIndex, jint contextCount, |
| 569 | jfloat x, jfloat y, jboolean isRtl, jlong paintHandle, |
| 570 | jlong mtHandle) { |
Seigo Nonaka | 783f961 | 2018-01-20 12:11:13 -0800 | [diff] [blame] | 571 | minikin::MeasuredText* mt = reinterpret_cast<minikin::MeasuredText*>(mtHandle); |
Seigo Nonaka | 7c93e86 | 2017-10-25 16:34:48 -0700 | [diff] [blame] | 572 | const minikin::Bidi bidiFlags = isRtl ? minikin::Bidi::FORCE_RTL : minikin::Bidi::FORCE_LTR; |
Seigo Nonaka | 3a4217f | 2018-05-02 12:56:16 -0700 | [diff] [blame] | 573 | |
| 574 | ScopedCharArrayRO text(env, charArray); |
| 575 | Paint* paint = reinterpret_cast<Paint*>(paintHandle); |
| 576 | const Typeface* typeface = paint->getAndroidTypeface(); |
| 577 | get_canvas(canvasHandle)->drawText( |
| 578 | text.get(), text.size(), // text buffer |
| 579 | index, count, // draw range |
| 580 | contextIndex, contextCount, // context range, |
| 581 | x, y, // draw position |
| 582 | bidiFlags, *paint, typeface, mt); |
Derek Sollenberger | 8872b38 | 2014-06-23 14:13:53 -0400 | [diff] [blame] | 583 | } |
| 584 | |
Seigo Nonaka | 3a4217f | 2018-05-02 12:56:16 -0700 | [diff] [blame] | 585 | static void drawTextRunString(JNIEnv* env, jobject obj, jlong canvasHandle, jstring strObj, |
Derek Sollenberger | 8872b38 | 2014-06-23 14:13:53 -0400 | [diff] [blame] | 586 | jint start, jint end, jint contextStart, jint contextEnd, |
Seigo Nonaka | 318ca04 | 2017-08-01 16:36:18 -0700 | [diff] [blame] | 587 | jfloat x, jfloat y, jboolean isRtl, jlong paintHandle) { |
Seigo Nonaka | 3a4217f | 2018-05-02 12:56:16 -0700 | [diff] [blame] | 588 | const minikin::Bidi bidiFlags = isRtl ? minikin::Bidi::FORCE_RTL : minikin::Bidi::FORCE_LTR; |
| 589 | |
| 590 | ScopedStringChars text(env, strObj); |
Behdad Esfahbod | 6ba30b8 | 2014-07-15 16:22:32 -0400 | [diff] [blame] | 591 | Paint* paint = reinterpret_cast<Paint*>(paintHandle); |
Seigo Nonaka | 318ca04 | 2017-08-01 16:36:18 -0700 | [diff] [blame] | 592 | const Typeface* typeface = paint->getAndroidTypeface(); |
Seigo Nonaka | 3a4217f | 2018-05-02 12:56:16 -0700 | [diff] [blame] | 593 | get_canvas(canvasHandle)->drawText( |
| 594 | text.get(), text.size(), // text buffer |
| 595 | start, end - start, // draw range |
| 596 | contextStart, contextEnd - contextStart, // context range |
| 597 | x, y, // draw position |
| 598 | bidiFlags, *paint, typeface, nullptr /* measured text */); |
Derek Sollenberger | 8872b38 | 2014-06-23 14:13:53 -0400 | [diff] [blame] | 599 | } |
| 600 | |
Derek Sollenberger | 8872b38 | 2014-06-23 14:13:53 -0400 | [diff] [blame] | 601 | static void drawTextOnPathChars(JNIEnv* env, jobject, jlong canvasHandle, jcharArray text, |
| 602 | jint index, jint count, jlong pathHandle, jfloat hOffset, |
Seigo Nonaka | 318ca04 | 2017-08-01 16:36:18 -0700 | [diff] [blame] | 603 | jfloat vOffset, jint bidiFlags, jlong paintHandle) { |
Derek Sollenberger | 8872b38 | 2014-06-23 14:13:53 -0400 | [diff] [blame] | 604 | SkPath* path = reinterpret_cast<SkPath*>(pathHandle); |
Behdad Esfahbod | 6ba30b8 | 2014-07-15 16:22:32 -0400 | [diff] [blame] | 605 | Paint* paint = reinterpret_cast<Paint*>(paintHandle); |
Seigo Nonaka | 318ca04 | 2017-08-01 16:36:18 -0700 | [diff] [blame] | 606 | const Typeface* typeface = paint->getAndroidTypeface(); |
Derek Sollenberger | 8872b38 | 2014-06-23 14:13:53 -0400 | [diff] [blame] | 607 | |
| 608 | jchar* jchars = env->GetCharArrayElements(text, NULL); |
| 609 | |
Seigo Nonaka | 7c93e86 | 2017-10-25 16:34:48 -0700 | [diff] [blame] | 610 | get_canvas(canvasHandle)->drawTextOnPath(jchars + index, count, |
| 611 | static_cast<minikin::Bidi>(bidiFlags), *path, hOffset, vOffset, *paint, typeface); |
Derek Sollenberger | 8872b38 | 2014-06-23 14:13:53 -0400 | [diff] [blame] | 612 | |
| 613 | env->ReleaseCharArrayElements(text, jchars, 0); |
| 614 | } |
| 615 | |
| 616 | static void drawTextOnPathString(JNIEnv* env, jobject, jlong canvasHandle, jstring text, |
| 617 | jlong pathHandle, jfloat hOffset, jfloat vOffset, |
Seigo Nonaka | 318ca04 | 2017-08-01 16:36:18 -0700 | [diff] [blame] | 618 | jint bidiFlags, jlong paintHandle) { |
Derek Sollenberger | 8872b38 | 2014-06-23 14:13:53 -0400 | [diff] [blame] | 619 | SkPath* path = reinterpret_cast<SkPath*>(pathHandle); |
Behdad Esfahbod | 6ba30b8 | 2014-07-15 16:22:32 -0400 | [diff] [blame] | 620 | Paint* paint = reinterpret_cast<Paint*>(paintHandle); |
Seigo Nonaka | 318ca04 | 2017-08-01 16:36:18 -0700 | [diff] [blame] | 621 | const Typeface* typeface = paint->getAndroidTypeface(); |
Derek Sollenberger | 8872b38 | 2014-06-23 14:13:53 -0400 | [diff] [blame] | 622 | |
| 623 | const jchar* jchars = env->GetStringChars(text, NULL); |
| 624 | int count = env->GetStringLength(text); |
| 625 | |
Seigo Nonaka | 7c93e86 | 2017-10-25 16:34:48 -0700 | [diff] [blame] | 626 | get_canvas(canvasHandle)->drawTextOnPath(jchars, count, static_cast<minikin::Bidi>(bidiFlags), |
| 627 | *path, hOffset, vOffset, *paint, typeface); |
Derek Sollenberger | 8872b38 | 2014-06-23 14:13:53 -0400 | [diff] [blame] | 628 | |
| 629 | env->ReleaseStringChars(text, jchars); |
| 630 | } |
| 631 | |
Ben Wagner | 0ed10be | 2018-06-28 17:08:16 -0400 | [diff] [blame] | 632 | static void setPaintFilter(jlong canvasHandle, jlong filterHandle) { |
| 633 | PaintFilter* paintFilter = reinterpret_cast<PaintFilter*>(filterHandle); |
| 634 | get_canvas(canvasHandle)->setPaintFilter(sk_ref_sp(paintFilter)); |
Derek Sollenberger | 8872b38 | 2014-06-23 14:13:53 -0400 | [diff] [blame] | 635 | } |
| 636 | |
| 637 | static void freeCaches(JNIEnv* env, jobject) { |
| 638 | SkGraphics::PurgeFontCache(); |
| 639 | } |
| 640 | |
| 641 | static void freeTextLayoutCaches(JNIEnv* env, jobject) { |
Seigo Nonaka | ae1aa85 | 2016-06-09 19:42:51 +0900 | [diff] [blame] | 642 | minikin::Layout::purgeCaches(); |
Derek Sollenberger | 8872b38 | 2014-06-23 14:13:53 -0400 | [diff] [blame] | 643 | } |
| 644 | |
Stan Iliev | 7717e22 | 2018-02-05 18:04:11 -0500 | [diff] [blame] | 645 | static void setCompatibilityVersion(JNIEnv* env, jobject, jint apiLevel) { |
| 646 | Canvas::setCompatibilityVersion(apiLevel); |
| 647 | } |
| 648 | |
| 649 | |
Derek Sollenberger | 8872b38 | 2014-06-23 14:13:53 -0400 | [diff] [blame] | 650 | }; // namespace CanvasJNI |
| 651 | |
Daniel Micay | 76f6a86 | 2015-09-19 17:31:01 -0400 | [diff] [blame] | 652 | static const JNINativeMethod gMethods[] = { |
John Reck | caa08ff | 2016-10-07 13:21:36 -0700 | [diff] [blame] | 653 | {"nGetNativeFinalizer", "()J", (void*) CanvasJNI::getNativeFinalizer}, |
John Reck | caa08ff | 2016-10-07 13:21:36 -0700 | [diff] [blame] | 654 | {"nFreeCaches", "()V", (void*) CanvasJNI::freeCaches}, |
| 655 | {"nFreeTextLayoutCaches", "()V", (void*) CanvasJNI::freeTextLayoutCaches}, |
Stan Iliev | 7717e22 | 2018-02-05 18:04:11 -0500 | [diff] [blame] | 656 | {"nSetCompatibilityVersion", "(I)V", (void*) CanvasJNI::setCompatibilityVersion}, |
John Reck | 5cb74bc | 2016-10-07 11:24:44 -0700 | [diff] [blame] | 657 | |
| 658 | // ------------ @FastNative ---------------- |
Leon Scroggins III | 71fae62 | 2019-03-26 16:28:41 -0400 | [diff] [blame] | 659 | {"nInitRaster", "(J)J", (void*) CanvasJNI::initRaster}, |
| 660 | {"nSetBitmap", "(JJ)V", (void*) CanvasJNI::setBitmap}, |
Chris Craik | bfa0b29 | 2017-01-19 19:12:36 -0800 | [diff] [blame] | 661 | {"nGetClipBounds","(JLandroid/graphics/Rect;)Z", (void*) CanvasJNI::getClipBounds}, |
| 662 | |
| 663 | // ------------ @CriticalNative ---------------- |
John Reck | caa08ff | 2016-10-07 13:21:36 -0700 | [diff] [blame] | 664 | {"nIsOpaque","(J)Z", (void*) CanvasJNI::isOpaque}, |
| 665 | {"nGetWidth","(J)I", (void*) CanvasJNI::getWidth}, |
| 666 | {"nGetHeight","(J)I", (void*) CanvasJNI::getHeight}, |
John Reck | caa08ff | 2016-10-07 13:21:36 -0700 | [diff] [blame] | 667 | {"nSave","(JI)I", (void*) CanvasJNI::save}, |
| 668 | {"nSaveLayer","(JFFFFJI)I", (void*) CanvasJNI::saveLayer}, |
| 669 | {"nSaveLayerAlpha","(JFFFFII)I", (void*) CanvasJNI::saveLayerAlpha}, |
Derek Sollenberger | 24fc901 | 2018-12-07 14:12:12 -0500 | [diff] [blame] | 670 | {"nSaveUnclippedLayer","(JIIII)I", (void*) CanvasJNI::saveUnclippedLayer}, |
John Reck | caa08ff | 2016-10-07 13:21:36 -0700 | [diff] [blame] | 671 | {"nGetSaveCount","(J)I", (void*) CanvasJNI::getSaveCount}, |
Chris Craik | bfa0b29 | 2017-01-19 19:12:36 -0800 | [diff] [blame] | 672 | {"nRestore","(J)Z", (void*) CanvasJNI::restore}, |
| 673 | {"nRestoreToCount","(JI)V", (void*) CanvasJNI::restoreToCount}, |
| 674 | {"nGetMatrix", "(JJ)V", (void*)CanvasJNI::getMatrix}, |
John Reck | caa08ff | 2016-10-07 13:21:36 -0700 | [diff] [blame] | 675 | {"nSetMatrix","(JJ)V", (void*) CanvasJNI::setMatrix}, |
| 676 | {"nConcat","(JJ)V", (void*) CanvasJNI::concat}, |
| 677 | {"nRotate","(JF)V", (void*) CanvasJNI::rotate}, |
| 678 | {"nScale","(JFF)V", (void*) CanvasJNI::scale}, |
| 679 | {"nSkew","(JFF)V", (void*) CanvasJNI::skew}, |
| 680 | {"nTranslate","(JFF)V", (void*) CanvasJNI::translate}, |
John Reck | caa08ff | 2016-10-07 13:21:36 -0700 | [diff] [blame] | 681 | {"nQuickReject","(JJ)Z", (void*) CanvasJNI::quickRejectPath}, |
| 682 | {"nQuickReject","(JFFFF)Z", (void*)CanvasJNI::quickRejectRect}, |
| 683 | {"nClipRect","(JFFFFI)Z", (void*) CanvasJNI::clipRect}, |
| 684 | {"nClipPath","(JJI)Z", (void*) CanvasJNI::clipPath}, |
Ben Wagner | 0ed10be | 2018-06-28 17:08:16 -0400 | [diff] [blame] | 685 | {"nSetDrawFilter", "(JJ)V", (void*) CanvasJNI::setPaintFilter}, |
John Reck | caa08ff | 2016-10-07 13:21:36 -0700 | [diff] [blame] | 686 | }; |
| 687 | |
| 688 | // If called from Canvas these are regular JNI |
| 689 | // If called from DisplayListCanvas they are @FastNative |
| 690 | static const JNINativeMethod gDrawMethods[] = { |
| 691 | {"nDrawColor","(JII)V", (void*) CanvasJNI::drawColor}, |
Leon Scroggins III | bee5e20 | 2019-01-11 13:36:39 -0500 | [diff] [blame] | 692 | {"nDrawColor","(JJJI)V", (void*) CanvasJNI::drawColorLong}, |
John Reck | caa08ff | 2016-10-07 13:21:36 -0700 | [diff] [blame] | 693 | {"nDrawPaint","(JJ)V", (void*) CanvasJNI::drawPaint}, |
| 694 | {"nDrawPoint", "(JFFJ)V", (void*) CanvasJNI::drawPoint}, |
| 695 | {"nDrawPoints", "(J[FIIJ)V", (void*) CanvasJNI::drawPoints}, |
| 696 | {"nDrawLine", "(JFFFFJ)V", (void*) CanvasJNI::drawLine}, |
| 697 | {"nDrawLines", "(J[FIIJ)V", (void*) CanvasJNI::drawLines}, |
| 698 | {"nDrawRect","(JFFFFJ)V", (void*) CanvasJNI::drawRect}, |
| 699 | {"nDrawRegion", "(JJJ)V", (void*) CanvasJNI::drawRegion }, |
| 700 | {"nDrawRoundRect","(JFFFFFFJ)V", (void*) CanvasJNI::drawRoundRect}, |
Nader Jawad | adfe1d9 | 2018-09-27 12:27:36 -0700 | [diff] [blame] | 701 | {"nDrawDoubleRoundRect", "(JFFFFFFFFFFFFJ)V", (void*) CanvasJNI::drawDoubleRoundRectXY}, |
| 702 | {"nDrawDoubleRoundRect", "(JFFFF[FFFFF[FJ)V", (void*) CanvasJNI::drawDoubleRoundRectRadii}, |
John Reck | caa08ff | 2016-10-07 13:21:36 -0700 | [diff] [blame] | 703 | {"nDrawCircle","(JFFFJ)V", (void*) CanvasJNI::drawCircle}, |
| 704 | {"nDrawOval","(JFFFFJ)V", (void*) CanvasJNI::drawOval}, |
| 705 | {"nDrawArc","(JFFFFFFZJ)V", (void*) CanvasJNI::drawArc}, |
| 706 | {"nDrawPath","(JJJ)V", (void*) CanvasJNI::drawPath}, |
| 707 | {"nDrawVertices", "(JII[FI[FI[II[SIIJ)V", (void*)CanvasJNI::drawVertices}, |
| 708 | {"nDrawNinePatch", "(JJJFFFFJII)V", (void*)CanvasJNI::drawNinePatch}, |
Leon Scroggins III | 71fae62 | 2019-03-26 16:28:41 -0400 | [diff] [blame] | 709 | {"nDrawBitmapMatrix", "(JJJJ)V", (void*)CanvasJNI::drawBitmapMatrix}, |
| 710 | {"nDrawBitmapMesh", "(JJII[FI[IIJ)V", (void*)CanvasJNI::drawBitmapMesh}, |
| 711 | {"nDrawBitmap","(JJFFJIII)V", (void*) CanvasJNI::drawBitmap}, |
| 712 | {"nDrawBitmap","(JJFFFFFFFFJII)V", (void*) CanvasJNI::drawBitmapRect}, |
John Reck | caa08ff | 2016-10-07 13:21:36 -0700 | [diff] [blame] | 713 | {"nDrawBitmap", "(J[IIIFFIIZJ)V", (void*)CanvasJNI::drawBitmapArray}, |
Seigo Nonaka | 318ca04 | 2017-08-01 16:36:18 -0700 | [diff] [blame] | 714 | {"nDrawText","(J[CIIFFIJ)V", (void*) CanvasJNI::drawTextChars}, |
| 715 | {"nDrawText","(JLjava/lang/String;IIFFIJ)V", (void*) CanvasJNI::drawTextString}, |
Seigo Nonaka | 83143d0 | 2018-03-14 17:08:28 -0700 | [diff] [blame] | 716 | {"nDrawTextRun","(J[CIIIIFFZJJ)V", (void*) CanvasJNI::drawTextRunChars}, |
Seigo Nonaka | 318ca04 | 2017-08-01 16:36:18 -0700 | [diff] [blame] | 717 | {"nDrawTextRun","(JLjava/lang/String;IIIIFFZJ)V", (void*) CanvasJNI::drawTextRunString}, |
| 718 | {"nDrawTextOnPath","(J[CIIJFFIJ)V", (void*) CanvasJNI::drawTextOnPathChars}, |
| 719 | {"nDrawTextOnPath","(JLjava/lang/String;JFFIJ)V", (void*) CanvasJNI::drawTextOnPathString}, |
Derek Sollenberger | 8872b38 | 2014-06-23 14:13:53 -0400 | [diff] [blame] | 720 | }; |
| 721 | |
| 722 | int register_android_graphics_Canvas(JNIEnv* env) { |
John Reck | caa08ff | 2016-10-07 13:21:36 -0700 | [diff] [blame] | 723 | int ret = 0; |
| 724 | ret |= RegisterMethodsOrDie(env, "android/graphics/Canvas", gMethods, NELEM(gMethods)); |
| 725 | ret |= RegisterMethodsOrDie(env, "android/graphics/BaseCanvas", gDrawMethods, NELEM(gDrawMethods)); |
John Reck | 6b16440 | 2018-09-24 15:25:42 -0700 | [diff] [blame] | 726 | ret |= RegisterMethodsOrDie(env, "android/graphics/BaseRecordingCanvas", gDrawMethods, NELEM(gDrawMethods)); |
John Reck | caa08ff | 2016-10-07 13:21:36 -0700 | [diff] [blame] | 727 | return ret; |
| 728 | |
Derek Sollenberger | 8872b38 | 2014-06-23 14:13:53 -0400 | [diff] [blame] | 729 | } |
| 730 | |
| 731 | }; // namespace android |