Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Paint.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2021 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8#include <jni.h>
9
14
15namespace {
16
17static jlong Paint_Create(JNIEnv*, jobject) {
18 return reinterpret_cast<jlong>(new SkPaint);
19}
20
21static void Paint_Release(JNIEnv*, jobject, jlong native_paint) {
22 delete reinterpret_cast<SkPaint*>(native_paint);
23}
24
25static void Paint_SetColor(JNIEnv*, jobject, jlong native_paint,
26 float r, float g, float b, float a) {
27 if (auto* paint = reinterpret_cast<SkPaint*>(native_paint)) {
28 paint->setColor4f({r, g, b, a});
29 }
30}
31
32static void Paint_SetStroke(JNIEnv*, jobject, jlong native_paint, jboolean stroke) {
33 if (auto* paint = reinterpret_cast<SkPaint*>(native_paint)) {
34 paint->setStroke(stroke);
35 }
36}
37
38static void Paint_SetStrokeWidth(JNIEnv*, jobject, jlong native_paint, jfloat width) {
39 if (auto* paint = reinterpret_cast<SkPaint*>(native_paint)) {
40 paint->setStrokeWidth(width);
41 }
42}
43
44static void Paint_SetStrokeCap(JNIEnv* env, jobject, jlong native_paint, jint native_cap) {
45 if (auto* paint = reinterpret_cast<SkPaint*>(native_paint)) {
46 switch (native_cap)
47 {
48 case 0:
49 paint->setStrokeCap(SkPaint::kButt_Cap);
50 break;
51 case 1:
52 paint->setStrokeCap(SkPaint::kRound_Cap);
53 break;
54 case 2:
55 paint->setStrokeCap(SkPaint::kSquare_Cap);
56 break;
57 default:
58 break;
59 }
60 }
61}
62
63static void Paint_SetStrokeJoin(JNIEnv* env, jobject, jlong native_paint, jint native_join) {
64 if (auto* paint = reinterpret_cast<SkPaint*>(native_paint)) {
65 switch (native_join)
66 {
67 case 0:
68 paint->setStrokeJoin(SkPaint::kMiter_Join);
69 break;
70 case 1:
71 paint->setStrokeJoin(SkPaint::kRound_Join);
72 break;
73 case 2:
74 paint->setStrokeJoin(SkPaint::kBevel_Join);
75 break;
76 default:
77 break;
78 }
79 }
80}
81
82static void Paint_SetStrokeMiter(JNIEnv* env, jobject, jlong native_paint, jfloat limit) {
83 if (auto* paint = reinterpret_cast<SkPaint*>(native_paint)) {
84 paint->setStrokeMiter(limit);
85 }
86}
87
88static void Paint_SetColorFilter(JNIEnv*, jobject, jlong native_paint, jlong native_cf) {
89 if (auto* paint = reinterpret_cast<SkPaint*>(native_paint)) {
90 paint->setColorFilter(sk_ref_sp(reinterpret_cast<SkColorFilter*>(native_cf)));
91 }
92}
93
94static void Paint_SetShader(JNIEnv*, jobject, jlong native_paint, jlong native_shader) {
95 if (auto* paint = reinterpret_cast<SkPaint*>(native_paint)) {
96 paint->setShader(sk_ref_sp(reinterpret_cast<SkShader*>(native_shader)));
97 }
98}
99
100static void Paint_SetImageFilter(JNIEnv*, jobject, jlong native_paint, jlong native_filter) {
101 if (auto* paint = reinterpret_cast<SkPaint*>(native_paint)) {
102 paint->setImageFilter(sk_ref_sp(reinterpret_cast<SkImageFilter*>(native_filter)));
103 }
104}
105
106} // namespace
107
109 static const JNINativeMethod methods[] = {
110 {"nCreate" , "()J" , reinterpret_cast<void*>(Paint_Create)},
111 {"nRelease" , "(J)V" , reinterpret_cast<void*>(Paint_Release)},
112 {"nSetColor" , "(JFFFF)V", reinterpret_cast<void*>(Paint_SetColor)},
113 {"nSetStroke" , "(JZ)V" , reinterpret_cast<void*>(Paint_SetStroke)},
114 {"nSetStrokeWidth" , "(JF)V" , reinterpret_cast<void*>(Paint_SetStrokeWidth)},
115 {"nSetStrokeCap" , "(JI)V" , reinterpret_cast<void*>(Paint_SetStrokeCap)},
116 {"nSetStrokeJoin" , "(JI)V" , reinterpret_cast<void*>(Paint_SetStrokeJoin)},
117 {"nSetStrokeMiter" , "(JF)V" , reinterpret_cast<void*>(Paint_SetStrokeMiter)},
118 {"nSetColorFilter" , "(JJ)V" , reinterpret_cast<void*>(Paint_SetColorFilter)},
119 {"nSetShader" , "(JJ)V" , reinterpret_cast<void*>(Paint_SetShader)},
120 {"nSetImageFilter" , "(JJ)V" , reinterpret_cast<void*>(Paint_SetImageFilter)},
121 };
122
123 const auto clazz = env->FindClass("org/skia/jetski/Paint");
124 return clazz
125 ? env->RegisterNatives(clazz, methods, std::size(methods))
126 : JNI_ERR;
127}
int register_jetski_Paint(JNIEnv *env)
Definition Paint.cpp:108
sk_sp< T > sk_ref_sp(T *obj)
Definition SkRefCnt.h:381
@ kRound_Cap
adds circle
Definition SkPaint.h:335
@ kButt_Cap
no stroke extension
Definition SkPaint.h:334
@ kSquare_Cap
adds square
Definition SkPaint.h:336
@ kRound_Join
adds circle
Definition SkPaint.h:360
@ kMiter_Join
extends to miter limit
Definition SkPaint.h:359
@ kBevel_Join
connects outside edges
Definition SkPaint.h:361
const Paint & paint
static bool b
struct MyStruct a[10]
Definition __init__.py:1
int32_t width