1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
|
#include <jni.h>
#include "GraphicsJNI.h"
#include "SkShader.h"
#include "SkGradientShader.h"
#include "SkPorterDuff.h"
#include "SkComposeShader.h"
#include "SkTemplates.h"
#include "SkXfermode.h"
#include <SkiaShader.h>
#include <Caches.h>
using namespace android::uirenderer;
static struct {
jclass clazz;
jfieldID shader;
} gShaderClassInfo;
static void ThrowIAE_IfNull(JNIEnv* env, void* ptr) {
if (NULL == ptr) {
doThrowIAE(env);
}
}
static void Color_RGBToHSV(JNIEnv* env, jobject, jint red, jint green, jint blue, jfloatArray hsvArray)
{
SkScalar hsv[3];
SkRGBToHSV(red, green, blue, hsv);
AutoJavaFloatArray autoHSV(env, hsvArray, 3);
float* values = autoHSV.ptr();
for (int i = 0; i < 3; i++) {
values[i] = SkScalarToFloat(hsv[i]);
}
}
static jint Color_HSVToColor(JNIEnv* env, jobject, jint alpha, jfloatArray hsvArray)
{
AutoJavaFloatArray autoHSV(env, hsvArray, 3);
#ifdef SK_SCALAR_IS_FLOAT
SkScalar* hsv = autoHSV.ptr();
#else
#error Need to convert float array to SkScalar array before calling the following function.
#endif
return static_cast<jint>(SkHSVToColor(alpha, hsv));
}
///////////////////////////////////////////////////////////////////////////////////////////////
static void Shader_destructor(JNIEnv* env, jobject o, jlong shaderHandle, jlong skiaShaderHandle)
{
SkShader* shader = reinterpret_cast<SkShader*>(shaderHandle);
SkiaShader* skiaShader = reinterpret_cast<SkiaShader*>(skiaShaderHandle);
SkSafeUnref(shader);
// skiaShader == NULL when not !USE_OPENGL_RENDERER, so no need to delete it outside the ifdef
#ifdef USE_OPENGL_RENDERER
if (android::uirenderer::Caches::hasInstance()) {
android::uirenderer::Caches::getInstance().resourceCache.destructor(skiaShader);
} else {
delete skiaShader;
}
#endif
}
static void Shader_setLocalMatrix(JNIEnv* env, jobject o, jlong shaderHandle,
jlong skiaShaderHandle, jlong matrixHandle)
{
SkShader* shader = reinterpret_cast<SkShader*>(shaderHandle);
SkiaShader* skiaShader = reinterpret_cast<SkiaShader*>(skiaShaderHandle);
const SkMatrix* matrix = reinterpret_cast<SkMatrix*>(matrixHandle);
if (shader) {
if (NULL == matrix) {
shader->resetLocalMatrix();
}
else {
shader->setLocalMatrix(*matrix);
}
#ifdef USE_OPENGL_RENDERER
skiaShader->setMatrix(const_cast<SkMatrix*>(matrix));
#endif
}
}
///////////////////////////////////////////////////////////////////////////////////////////////
static jlong BitmapShader_constructor(JNIEnv* env, jobject o, jlong bitmapHandle,
jint tileModeX, jint tileModeY)
{
const SkBitmap* bitmap = reinterpret_cast<SkBitmap*>(bitmapHandle);
SkShader* s = SkShader::CreateBitmapShader(*bitmap,
(SkShader::TileMode)tileModeX,
(SkShader::TileMode)tileModeY);
ThrowIAE_IfNull(env, s);
return reinterpret_cast<jlong>(s);
}
static jlong BitmapShader_postConstructor(JNIEnv* env, jobject o, jlong shaderHandle,
jlong bitmapHandle, jint tileModeX, jint tileModeY) {
SkShader* shader = reinterpret_cast<SkShader*>(shaderHandle);
SkBitmap* bitmap = reinterpret_cast<SkBitmap*>(bitmapHandle);
#ifdef USE_OPENGL_RENDERER
SkiaShader* skiaShader = new SkiaBitmapShader(bitmap, shader,
static_cast<SkShader::TileMode>(tileModeX), static_cast<SkShader::TileMode>(tileModeY),
NULL, !shader->isOpaque());
return reinterpret_cast<jlong>(skiaShader);
#else
return NULL;
#endif
}
///////////////////////////////////////////////////////////////////////////////////////////////
static jlong LinearGradient_create1(JNIEnv* env, jobject o,
jfloat x0, jfloat y0, jfloat x1, jfloat y1,
jintArray colorArray, jfloatArray posArray, jint tileMode)
{
SkPoint pts[2];
pts[0].set(x0, y0);
pts[1].set(x1, y1);
size_t count = env->GetArrayLength(colorArray);
const jint* colorValues = env->GetIntArrayElements(colorArray, NULL);
AutoJavaFloatArray autoPos(env, posArray, count);
#ifdef SK_SCALAR_IS_FLOAT
SkScalar* pos = autoPos.ptr();
#else
#error Need to convert float array to SkScalar array before calling the following function.
#endif
SkShader* shader = SkGradientShader::CreateLinear(pts,
reinterpret_cast<const SkColor*>(colorValues), pos, count,
static_cast<SkShader::TileMode>(tileMode));
env->ReleaseIntArrayElements(colorArray, const_cast<jint*>(colorValues), JNI_ABORT);
ThrowIAE_IfNull(env, shader);
return reinterpret_cast<jlong>(shader);
}
static jlong LinearGradient_postCreate1(JNIEnv* env, jobject o, jlong shaderHandle,
jfloat x0, jfloat y0, jfloat x1, jfloat y1, jintArray colorArray,
jfloatArray posArray, jint tileMode) {
#ifdef USE_OPENGL_RENDERER
SkShader* shader = reinterpret_cast<SkShader*>(shaderHandle);
size_t count = env->GetArrayLength(colorArray);
const jint* colorValues = env->GetIntArrayElements(colorArray, NULL);
jfloat* storedBounds = new jfloat[4];
storedBounds[0] = x0; storedBounds[1] = y0;
storedBounds[2] = x1; storedBounds[3] = y1;
bool missFirst = false;
bool missLast = false;
size_t stopCount = count;
jfloat* storedPositions = NULL;
if (posArray) {
AutoJavaFloatArray autoPos(env, posArray, count);
const float* posValues = autoPos.ptr();
missFirst = posValues[0] != 0.0f;
missLast = posValues[count - 1] != 1.0f;
stopCount += missFirst + missLast;
storedPositions = new jfloat[stopCount];
if (missFirst) {
storedPositions[0] = 0.0f;
}
for (size_t i = missFirst; i < count + missFirst; i++) {
storedPositions[i] = posValues[i - missFirst];
}
if (missLast) {
storedPositions[stopCount - 1] = 1.0f;
}
} else {
storedPositions = new jfloat[count];
storedPositions[0] = 0.0f;
const jfloat step = 1.0f / (count - 1);
for (size_t i = 1; i < count - 1; i++) {
storedPositions[i] = step * i;
}
storedPositions[count - 1] = 1.0f;
}
uint32_t* storedColors = new uint32_t[stopCount];
if (missFirst) {
storedColors[0] = static_cast<uint32_t>(colorValues[0]);
}
for (size_t i = missFirst; i < count + missFirst; i++) {
storedColors[i] = static_cast<uint32_t>(colorValues[i - missFirst]);
}
if (missLast) {
storedColors[stopCount - 1] = static_cast<uint32_t>(colorValues[count - 1]);
}
SkiaShader* skiaShader = new SkiaLinearGradientShader(storedBounds, storedColors,
storedPositions, stopCount, shader, static_cast<SkShader::TileMode>(tileMode), NULL,
!shader->isOpaque());
env->ReleaseIntArrayElements(colorArray, const_cast<jint*>(colorValues), JNI_ABORT);
return reinterpret_cast<jlong>(skiaShader);
#else
return NULL;
#endif
}
static jlong LinearGradient_postCreate2(JNIEnv* env, jobject o, jlong shaderHandle,
jfloat x0, jfloat y0, jfloat x1, jfloat y1, jint color0, jint color1, jint tileMode) {
#ifdef USE_OPENGL_RENDERER
SkShader* shader = reinterpret_cast<SkShader*>(shaderHandle);
float* storedBounds = new float[4];
storedBounds[0] = x0; storedBounds[1] = y0;
storedBounds[2] = x1; storedBounds[3] = y1;
float* storedPositions = new float[2];
storedPositions[0] = 0.0f;
storedPositions[1] = 1.0f;
uint32_t* storedColors = new uint32_t[2];
storedColors[0] = static_cast<uint32_t>(color0);
storedColors[1] = static_cast<uint32_t>(color1);
SkiaShader* skiaShader = new SkiaLinearGradientShader(storedBounds, storedColors,
storedPositions, 2, shader, static_cast<SkShader::TileMode>(tileMode), NULL,
!shader->isOpaque());
return reinterpret_cast<jlong>(skiaShader);
#else
return NULL;
#endif
}
static jlong LinearGradient_create2(JNIEnv* env, jobject o,
jfloat x0, jfloat y0, jfloat x1, jfloat y1,
jint color0, jint color1, jint tileMode)
{
SkPoint pts[2];
pts[0].set(x0, y0);
pts[1].set(x1, y1);
SkColor colors[2];
colors[0] = color0;
colors[1] = color1;
SkShader* s = SkGradientShader::CreateLinear(pts, colors, NULL, 2, (SkShader::TileMode)tileMode);
ThrowIAE_IfNull(env, s);
return reinterpret_cast<jlong>(s);
}
///////////////////////////////////////////////////////////////////////////////////////////////
static jlong RadialGradient_create1(JNIEnv* env, jobject, jfloat x, jfloat y, jfloat radius,
jintArray colorArray, jfloatArray posArray, jint tileMode) {
SkPoint center;
center.set(x, y);
size_t count = env->GetArrayLength(colorArray);
const jint* colorValues = env->GetIntArrayElements(colorArray, NULL);
AutoJavaFloatArray autoPos(env, posArray, count);
#ifdef SK_SCALAR_IS_FLOAT
SkScalar* pos = autoPos.ptr();
#else
#error Need to convert float array to SkScalar array before calling the following function.
#endif
SkShader* shader = SkGradientShader::CreateRadial(center, radius,
reinterpret_cast<const SkColor*>(colorValues), pos, count,
static_cast<SkShader::TileMode>(tileMode));
env->ReleaseIntArrayElements(colorArray, const_cast<jint*>(colorValues),
JNI_ABORT);
ThrowIAE_IfNull(env, shader);
return reinterpret_cast<jlong>(shader);
}
static jlong RadialGradient_create2(JNIEnv* env, jobject, jfloat x, jfloat y, jfloat radius,
jint color0, jint color1, jint tileMode) {
SkPoint center;
center.set(x, y);
SkColor colors[2];
colors[0] = color0;
colors[1] = color1;
SkShader* s = SkGradientShader::CreateRadial(center, radius, colors, NULL, 2,
(SkShader::TileMode)tileMode);
ThrowIAE_IfNull(env, s);
return reinterpret_cast<jlong>(s);
}
static jlong RadialGradient_postCreate1(JNIEnv* env, jobject o, jlong shaderHandle,
jfloat x, jfloat y, jfloat radius, jintArray colorArray, jfloatArray posArray, jint tileMode) {
#ifdef USE_OPENGL_RENDERER
SkShader* shader = reinterpret_cast<SkShader*>(shaderHandle);
size_t count = env->GetArrayLength(colorArray);
const jint* colorValues = env->GetIntArrayElements(colorArray, NULL);
jfloat* storedPositions = new jfloat[count];
uint32_t* storedColors = new uint32_t[count];
for (size_t i = 0; i < count; i++) {
storedColors[i] = static_cast<uint32_t>(colorValues[i]);
}
if (posArray) {
AutoJavaFloatArray autoPos(env, posArray, count);
const float* posValues = autoPos.ptr();
for (size_t i = 0; i < count; i++) {
storedPositions[i] = posValues[i];
}
} else {
storedPositions[0] = 0.0f;
const jfloat step = 1.0f / (count - 1);
for (size_t i = 1; i < count - 1; i++) {
storedPositions[i] = step * i;
}
storedPositions[count - 1] = 1.0f;
}
SkiaShader* skiaShader = new SkiaCircularGradientShader(x, y, radius, storedColors,
storedPositions, count, shader, (SkShader::TileMode) tileMode, NULL,
!shader->isOpaque());
env->ReleaseIntArrayElements(colorArray, const_cast<jint*>(colorValues), JNI_ABORT);
return reinterpret_cast<jlong>(skiaShader);
#else
return NULL;
#endif
}
static jlong RadialGradient_postCreate2(JNIEnv* env, jobject o, jlong shaderHandle,
jfloat x, jfloat y, jfloat radius, jint color0, jint color1, jint tileMode) {
#ifdef USE_OPENGL_RENDERER
SkShader* shader = reinterpret_cast<SkShader*>(shaderHandle);
float* storedPositions = new float[2];
storedPositions[0] = 0.0f;
storedPositions[1] = 1.0f;
uint32_t* storedColors = new uint32_t[2];
storedColors[0] = static_cast<uint32_t>(color0);
storedColors[1] = static_cast<uint32_t>(color1);
SkiaShader* skiaShader = new SkiaCircularGradientShader(x, y, radius, storedColors,
storedPositions, 2, shader, (SkShader::TileMode) tileMode, NULL,
!shader->isOpaque());
return reinterpret_cast<jlong>(skiaShader);
#else
return NULL;
#endif
}
///////////////////////////////////////////////////////////////////////////////
static jlong SweepGradient_create1(JNIEnv* env, jobject, jfloat x, jfloat y,
jintArray jcolors, jfloatArray jpositions) {
size_t count = env->GetArrayLength(jcolors);
const jint* colors = env->GetIntArrayElements(jcolors, NULL);
AutoJavaFloatArray autoPos(env, jpositions, count);
#ifdef SK_SCALAR_IS_FLOAT
SkScalar* pos = autoPos.ptr();
#else
#error Need to convert float array to SkScalar array before calling the following function.
#endif
SkShader* shader = SkGradientShader::CreateSweep(x, y,
reinterpret_cast<const SkColor*>(colors), pos, count);
env->ReleaseIntArrayElements(jcolors, const_cast<jint*>(colors),
JNI_ABORT);
ThrowIAE_IfNull(env, shader);
return reinterpret_cast<jlong>(shader);
}
static jlong SweepGradient_create2(JNIEnv* env, jobject, jfloat x, jfloat y,
int color0, int color1) {
SkColor colors[2];
colors[0] = color0;
colors[1] = color1;
SkShader* s = SkGradientShader::CreateSweep(x, y, colors, NULL, 2);
ThrowIAE_IfNull(env, s);
return reinterpret_cast<jlong>(s);
}
static jlong SweepGradient_postCreate1(JNIEnv* env, jobject o, jlong shaderHandle,
jfloat x, jfloat y, jintArray colorArray, jfloatArray posArray) {
#ifdef USE_OPENGL_RENDERER
SkShader* shader = reinterpret_cast<SkShader*>(shaderHandle);
size_t count = env->GetArrayLength(colorArray);
const jint* colorValues = env->GetIntArrayElements(colorArray, NULL);
jfloat* storedPositions = new jfloat[count];
uint32_t* storedColors = new uint32_t[count];
for (size_t i = 0; i < count; i++) {
storedColors[i] = static_cast<uint32_t>(colorValues[i]);
}
if (posArray) {
AutoJavaFloatArray autoPos(env, posArray, count);
const float* posValues = autoPos.ptr();
for (size_t i = 0; i < count; i++) {
storedPositions[i] = posValues[i];
}
} else {
storedPositions[0] = 0.0f;
const jfloat step = 1.0f / (count - 1);
for (size_t i = 1; i < count - 1; i++) {
storedPositions[i] = step * i;
}
storedPositions[count - 1] = 1.0f;
}
SkiaShader* skiaShader = new SkiaSweepGradientShader(x, y, storedColors, storedPositions, count,
shader, NULL, !shader->isOpaque());
env->ReleaseIntArrayElements(colorArray, const_cast<jint*>(colorValues), JNI_ABORT);
return reinterpret_cast<jlong>(skiaShader);
#else
return NULL;
#endif
}
static jlong SweepGradient_postCreate2(JNIEnv* env, jobject o, jlong shaderHandle,
jfloat x, jfloat y, jint color0, jint color1) {
#ifdef USE_OPENGL_RENDERER
SkShader* shader = reinterpret_cast<SkShader*>(shaderHandle);
float* storedPositions = new float[2];
storedPositions[0] = 0.0f;
storedPositions[1] = 1.0f;
uint32_t* storedColors = new uint32_t[2];
storedColors[0] = static_cast<uint32_t>(color0);
storedColors[1] = static_cast<uint32_t>(color1);
SkiaShader* skiaShader = new SkiaSweepGradientShader(x, y, storedColors, storedPositions, 2,
shader, NULL, !shader->isOpaque());
return reinterpret_cast<jlong>(skiaShader);
#else
return NULL;
#endif
}
///////////////////////////////////////////////////////////////////////////////////////////////
static jlong ComposeShader_create1(JNIEnv* env, jobject o,
jlong shaderAHandle, jlong shaderBHandle, jlong modeHandle)
{
SkShader* shaderA = reinterpret_cast<SkShader *>(shaderAHandle);
SkShader* shaderB = reinterpret_cast<SkShader *>(shaderBHandle);
SkXfermode* mode = reinterpret_cast<SkXfermode *>(modeHandle);
SkShader* shader = new SkComposeShader(shaderA, shaderB, mode);
return reinterpret_cast<jlong>(shader);
}
static jlong ComposeShader_create2(JNIEnv* env, jobject o,
jlong shaderAHandle, jlong shaderBHandle, jint porterDuffModeHandle)
{
SkShader* shaderA = reinterpret_cast<SkShader *>(shaderAHandle);
SkShader* shaderB = reinterpret_cast<SkShader *>(shaderBHandle);
SkPorterDuff::Mode porterDuffMode = static_cast<SkPorterDuff::Mode>(porterDuffModeHandle);
SkAutoUnref au(SkPorterDuff::CreateXfermode(porterDuffMode));
SkXfermode* mode = (SkXfermode*) au.get();
SkShader* shader = new SkComposeShader(shaderA, shaderB, mode);
return reinterpret_cast<jlong>(shader);
}
static jlong ComposeShader_postCreate2(JNIEnv* env, jobject o, jlong shaderHandle,
jlong shaderAHandle, jlong shaderBHandle, jint porterDuffModeHandle) {
#ifdef USE_OPENGL_RENDERER
SkShader* shader = reinterpret_cast<SkShader *>(shaderHandle);
SkiaShader* shaderA = reinterpret_cast<SkiaShader *>(shaderAHandle);
SkiaShader* shaderB = reinterpret_cast<SkiaShader *>(shaderBHandle);
SkPorterDuff::Mode porterDuffMode = static_cast<SkPorterDuff::Mode>(porterDuffModeHandle);
SkXfermode::Mode mode = SkPorterDuff::ToXfermodeMode(porterDuffMode);
SkiaShader* skiaShader = new SkiaComposeShader(shaderA, shaderB, mode, shader);
return reinterpret_cast<jlong>(skiaShader);
#else
return NULL;
#endif
}
static jlong ComposeShader_postCreate1(JNIEnv* env, jobject o, jlong shaderHandle,
jlong shaderAHandle, jlong shaderBHandle, jlong modeHandle) {
#ifdef USE_OPENGL_RENDERER
SkShader* shader = reinterpret_cast<SkShader *>(shaderHandle);
SkiaShader* shaderA = reinterpret_cast<SkiaShader *>(shaderAHandle);
SkiaShader* shaderB = reinterpret_cast<SkiaShader *>(shaderBHandle);
SkXfermode* mode = reinterpret_cast<SkXfermode *>(modeHandle);
SkXfermode::Mode skiaMode;
if (!SkXfermode::AsMode(mode, &skiaMode)) {
// TODO: Support other modes
skiaMode = SkXfermode::kSrcOver_Mode;
}
SkiaShader* skiaShader = new SkiaComposeShader(shaderA, shaderB, skiaMode, shader);
return reinterpret_cast<jlong>(skiaShader);
#else
return NULL;
#endif
}
///////////////////////////////////////////////////////////////////////////////////////////////
static JNINativeMethod gColorMethods[] = {
{ "nativeRGBToHSV", "(III[F)V", (void*)Color_RGBToHSV },
{ "nativeHSVToColor", "(I[F)I", (void*)Color_HSVToColor }
};
static JNINativeMethod gShaderMethods[] = {
{ "nativeDestructor", "(JJ)V", (void*)Shader_destructor },
{ "nativeSetLocalMatrix", "(JJJ)V", (void*)Shader_setLocalMatrix }
};
static JNINativeMethod gBitmapShaderMethods[] = {
{ "nativeCreate", "(JII)J", (void*)BitmapShader_constructor },
{ "nativePostCreate", "(JJII)J", (void*)BitmapShader_postConstructor }
};
static JNINativeMethod gLinearGradientMethods[] = {
{ "nativeCreate1", "(FFFF[I[FI)J", (void*)LinearGradient_create1 },
{ "nativeCreate2", "(FFFFIII)J", (void*)LinearGradient_create2 },
{ "nativePostCreate1", "(JFFFF[I[FI)J", (void*)LinearGradient_postCreate1 },
{ "nativePostCreate2", "(JFFFFIII)J", (void*)LinearGradient_postCreate2 }
};
static JNINativeMethod gRadialGradientMethods[] = {
{ "nativeCreate1", "(FFF[I[FI)J", (void*)RadialGradient_create1 },
{ "nativeCreate2", "(FFFIII)J", (void*)RadialGradient_create2 },
{ "nativePostCreate1", "(JFFF[I[FI)J", (void*)RadialGradient_postCreate1 },
{ "nativePostCreate2", "(JFFFIII)J", (void*)RadialGradient_postCreate2 }
};
static JNINativeMethod gSweepGradientMethods[] = {
{ "nativeCreate1", "(FF[I[F)J", (void*)SweepGradient_create1 },
{ "nativeCreate2", "(FFII)J", (void*)SweepGradient_create2 },
{ "nativePostCreate1", "(JFF[I[F)J", (void*)SweepGradient_postCreate1 },
{ "nativePostCreate2", "(JFFII)J", (void*)SweepGradient_postCreate2 }
};
static JNINativeMethod gComposeShaderMethods[] = {
{ "nativeCreate1", "(JJJ)J", (void*)ComposeShader_create1 },
{ "nativeCreate2", "(JJI)J", (void*)ComposeShader_create2 },
{ "nativePostCreate1", "(JJJJ)J", (void*)ComposeShader_postCreate1 },
{ "nativePostCreate2", "(JJJI)J", (void*)ComposeShader_postCreate2 }
};
#include <android_runtime/AndroidRuntime.h>
#define REG(env, name, array) \
result = android::AndroidRuntime::registerNativeMethods(env, name, array, SK_ARRAY_COUNT(array)); \
if (result < 0) return result
int register_android_graphics_Shader(JNIEnv* env)
{
int result;
REG(env, "android/graphics/Color", gColorMethods);
REG(env, "android/graphics/Shader", gShaderMethods);
REG(env, "android/graphics/BitmapShader", gBitmapShaderMethods);
REG(env, "android/graphics/LinearGradient", gLinearGradientMethods);
REG(env, "android/graphics/RadialGradient", gRadialGradientMethods);
REG(env, "android/graphics/SweepGradient", gSweepGradientMethods);
REG(env, "android/graphics/ComposeShader", gComposeShaderMethods);
return result;
}
|