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