-
Notifications
You must be signed in to change notification settings - Fork 35
/
Copy pathCanvas.java
1455 lines (1352 loc) · 67.7 KB
/
Canvas.java
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
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
package io.github.humbleui.skija;
import org.jetbrains.annotations.*;
import io.github.humbleui.skija.impl.*;
import io.github.humbleui.types.*;
public class Canvas extends Managed {
static { Library.staticLoad(); }
@ApiStatus.Internal
public final Object _owner;
@ApiStatus.Internal
public Canvas(long ptr, boolean managed, Object owner) {
super(ptr, _FinalizerHolder.PTR, managed);
this._owner = owner;
}
/**
* <p>Constructs a canvas that draws into bitmap.
* Sets default pixel geometry in constructed Surface.</p>
*
* <p>Bitmap is copied so that subsequently editing bitmap will not affect
* constructed Canvas.</p>
*
* <p>May be deprecated in the future.</p>
*
* @param bitmap width, height, ColorType, ColorAlphaType, and pixel
* storage of raster surface
*
* @see <a href="https://fiddle.skia.org/c/@Canvas_copy_const_SkBitmap">https://fiddle.skia.org/c/@Canvas_copy_const_SkBitmap</a>
*/
public Canvas(@NotNull Bitmap bitmap) {
this(bitmap, new SurfaceProps());
}
/**
* <p>Constructs a canvas that draws into bitmap.
* Use props to match the device characteristics, like LCD striping.</p>
*
* <p>Bitmap is copied so that subsequently editing bitmap will not affect
* constructed Canvas.</p>
*
* @param bitmap width, height, ColorType, ColorAlphaType, and pixel
* storage of raster surface
* @param surfaceProps order and orientation of RGB striping; and whether to use
* device independent fonts
*
* @see <a href="https://fiddle.skia.org/c/@Canvas_const_SkBitmap_const_SkSurfaceProps">https://fiddle.skia.org/c/@Canvas_const_SkBitmap_const_SkSurfaceProps</a>
*/
public Canvas(@NotNull Bitmap bitmap, @NotNull SurfaceProps surfaceProps) {
this(_nMakeFromBitmap(bitmap._ptr, surfaceProps._getFlags(), surfaceProps._pixelGeometry.ordinal()), true, bitmap);
Stats.onNativeCall();
ReferenceUtil.reachabilityFence(bitmap);
}
/**
* Returns the SurfaceProps associated with the canvas (i.e., at the base of the layer
* stack).
*
* @return SurfaceProps
*/
@NotNull
public SurfaceProps getBaseProps() {
try {
Stats.onNativeCall();
return _nGetBaseProps(_ptr);
} finally {
ReferenceUtil.reachabilityFence(this);
}
}
/**
* Returns the SurfaceProps associated with the canvas that are currently active (i.e., at
* the top of the layer stack). This can differ from {getBaseProps()} depending on the flags
* passed to saveLayer.
*
* @return SurfaceProps active in the current/top layer
*/
@NotNull
public SurfaceProps getTopProps() {
try {
Stats.onNativeCall();
return _nGetTopProps(_ptr);
} finally {
ReferenceUtil.reachabilityFence(this);
}
}
@Nullable
public Surface getSurface() {
try {
Stats.onNativeCall();
long ptr = _nGetSurface(_ptr);
return ptr == 0 ? null : new Surface(ptr);
} finally {
ReferenceUtil.reachabilityFence(this);
}
}
@NotNull @Contract("_, _, _ -> this")
public Canvas drawPoint(float x, float y, @NotNull Paint paint) {
assert paint != null : "Can’t drawPoint with paint == null";
Stats.onNativeCall();
_nDrawPoint(_ptr, x, y, Native.getPtr(paint));
ReferenceUtil.reachabilityFence(paint);
return this;
}
/**
* <p>Draws pts using clip, Matrix and Paint paint.</p>
*
* <p>The shape of point drawn depends on paint
* PaintStrokeCap. If paint is set to {@link PaintStrokeCap#ROUND}, each point draws a
* circle of diameter Paint stroke width. If paint is set to {@link PaintStrokeCap#SQUARE}
* or {@link PaintStrokeCap#BUTT}, each point draws a square of width and height
* Paint stroke width.</p>
*
* <p>Each line segment respects paint PaintStrokeCap and Paint stroke width.
* PaintMode is ignored, as if were set to {@link PaintMode#STROKE}.</p>
*
* <p>Always draws each element one at a time; is not affected by
* PaintStrokeJoin, and unlike drawPath(), does not create a mask from all points
* and lines before drawing.</p>
*
* @param coords array of points to draw
* @param paint stroke, blend, color, and so on, used to draw
*
* @see <a href="https://fiddle.skia.org/c/@Canvas_drawPoints">https://fiddle.skia.org/c/@Canvas_drawPoints</a>
*/
@NotNull @Contract("_, _ -> this")
public Canvas drawPoints(@NotNull Point[] coords, @NotNull Paint paint) {
return drawPoints(Point.flattenArray(coords), paint);
}
/**
* <p>Draws pts using clip, Matrix and Paint paint.</p>
*
* <p>The shape of point drawn depends on paint
* PaintStrokeCap. If paint is set to {@link PaintStrokeCap#ROUND}, each point draws a
* circle of diameter Paint stroke width. If paint is set to {@link PaintStrokeCap#SQUARE}
* or {@link PaintStrokeCap#BUTT}, each point draws a square of width and height
* Paint stroke width.</p>
*
* <p>Each line segment respects paint PaintStrokeCap and Paint stroke width.
* PaintMode is ignored, as if were set to {@link PaintMode#STROKE}.</p>
*
* <p>Always draws each element one at a time; is not affected by
* PaintStrokeJoin, and unlike drawPath(), does not create a mask from all points
* and lines before drawing.</p>
*
* @param coords array of points to draw
* @param paint stroke, blend, color, and so on, used to draw
*
* @see <a href="https://fiddle.skia.org/c/@Canvas_drawPoints">https://fiddle.skia.org/c/@Canvas_drawPoints</a>
*/
@NotNull @Contract("_, _ -> this")
public Canvas drawPoints(@NotNull float[] coords, @NotNull Paint paint) {
assert coords != null : "Can’t drawPoints with coords == null";
assert paint != null : "Can’t drawPoints with paint == null";
Stats.onNativeCall();
_nDrawPoints(_ptr, 0 /* SkCanvas::PointMode::kPoints_PointMode */, coords, Native.getPtr(paint));
ReferenceUtil.reachabilityFence(paint);
return this;
}
/**
* <p>Draws pts using clip, Matrix and Paint paint.</p>
*
* <p>Each pair of points draws a line segment.
* One line is drawn for every two points; each point is used once. If count is odd,
* the final point is ignored.</p>
*
* <p>Each line segment respects paint PaintStrokeCap and Paint stroke width.
* PaintMode is ignored, as if were set to {@link PaintMode#STROKE}.</p>
*
* <p>Always draws each element one at a time; is not affected by
* PaintStrokeJoin, and unlike drawPath(), does not create a mask from all points
* and lines before drawing.</p>
*
* @param coords array of points to draw
* @param paint stroke, blend, color, and so on, used to draw
*
* @see <a href="https://fiddle.skia.org/c/@Canvas_drawPoints">https://fiddle.skia.org/c/@Canvas_drawPoints</a>
*/
@NotNull @Contract("_, _ -> this")
public Canvas drawLines(@NotNull Point[] coords, @NotNull Paint paint) {
return drawLines(Point.flattenArray(coords), paint);
}
/**
* <p>Draws pts using clip, Matrix and Paint paint.</p>
*
* <p>Each pair of points draws a line segment.
* One line is drawn for every two points; each point is used once. If count is odd,
* the final point is ignored.</p>
*
* <p>Each line segment respects paint PaintStrokeCap and Paint stroke width.
* PaintMode is ignored, as if were set to {@link PaintMode#STROKE}.</p>
*
* <p>Always draws each element one at a time; is not affected by
* PaintStrokeJoin, and unlike drawPath(), does not create a mask from all points
* and lines before drawing.</p>
*
* @param coords array of points to draw
* @param paint stroke, blend, color, and so on, used to draw
*
* @see <a href="https://fiddle.skia.org/c/@Canvas_drawPoints">https://fiddle.skia.org/c/@Canvas_drawPoints</a>
*/
@NotNull @Contract("_, _ -> this")
public Canvas drawLines(@NotNull float[] coords, @NotNull Paint paint) {
assert coords != null : "Can’t drawLines with coords == null";
assert paint != null : "Can’t drawLines with paint == null";
Stats.onNativeCall();
_nDrawPoints(_ptr, 1 /* SkCanvas::PointMode::kLines_PointMode */, coords, Native.getPtr(paint));
ReferenceUtil.reachabilityFence(paint);
return this;
}
/**
* <p>Draws pts using clip, Matrix and Paint paint.</p>
*
* <p>Each adjacent pair of points draws a line segment.
* count minus one lines are drawn; the first and last point are used once.</p>
*
* <p>Each line segment respects paint PaintStrokeCap and Paint stroke width.
* PaintMode is ignored, as if were set to {@link PaintMode#STROKE}.</p>
*
* <p>Always draws each element one at a time; is not affected by
* PaintStrokeJoin, and unlike drawPath(), does not create a mask from all points
* and lines before drawing.</p>
*
* @param coords array of points to draw
* @param paint stroke, blend, color, and so on, used to draw
*
* @see <a href="https://fiddle.skia.org/c/@Canvas_drawPoints">https://fiddle.skia.org/c/@Canvas_drawPoints</a>
*/
@NotNull @Contract("_, _ -> this")
public Canvas drawPolygon(@NotNull Point[] coords, @NotNull Paint paint) {
return drawPolygon(Point.flattenArray(coords), paint);
}
/**
* <p>Draws pts using clip, Matrix and Paint paint.</p>
*
* <p>Each adjacent pair of points draws a line segment.
* count minus one lines are drawn; the first and last point are used once.</p>
*
* <p>Each line segment respects paint PaintStrokeCap and Paint stroke width.
* PaintMode is ignored, as if were set to {@link PaintMode#STROKE}.</p>
*
* <p>Always draws each element one at a time; is not affected by
* PaintStrokeJoin, and unlike drawPath(), does not create a mask from all points
* and lines before drawing.</p>
*
* @param coords array of points to draw
* @param paint stroke, blend, color, and so on, used to draw
*
* @see <a href="https://fiddle.skia.org/c/@Canvas_drawPoints">https://fiddle.skia.org/c/@Canvas_drawPoints</a>
*/
@NotNull @Contract("_, _ -> this")
public Canvas drawPolygon(@NotNull float[] coords, @NotNull Paint paint) {
assert coords != null : "Can’t drawPolygon with coords == null";
assert paint != null : "Can’t drawPolygon with paint == null";
Stats.onNativeCall();
_nDrawPoints(_ptr, 2 /* SkCanvas::PointMode::kPolygon_PointMode */, coords, Native.getPtr(paint));
ReferenceUtil.reachabilityFence(paint);
return this;
}
@NotNull @Contract("_, _, _, _, _ -> this")
public Canvas drawLine(float x0, float y0, float x1, float y1, @NotNull Paint paint) {
assert paint != null : "Can’t drawLine with paint == null";
Stats.onNativeCall();
_nDrawLine(_ptr, x0, y0, x1, y1, Native.getPtr(paint));
ReferenceUtil.reachabilityFence(paint);
return this;
}
@NotNull @Contract("_, _, _, _, _, _, _, _ -> this")
public Canvas drawArc(float left, float top, float right, float bottom, float startAngle, float sweepAngle, boolean includeCenter, @NotNull Paint paint) {
assert paint != null : "Can’t drawArc with paint == null";
Stats.onNativeCall();
_nDrawArc(_ptr, left, top, right, bottom, startAngle, sweepAngle, includeCenter, Native.getPtr(paint));
ReferenceUtil.reachabilityFence(paint);
return this;
}
@NotNull @Contract("_, _ -> this")
public Canvas drawRect(@NotNull Rect r, @NotNull Paint paint) {
assert r != null : "Can’t drawRect with r == null";
assert paint != null : "Can’t drawRect with paint == null";
Stats.onNativeCall();
_nDrawRect(_ptr, r._left, r._top, r._right, r._bottom, Native.getPtr(paint));
ReferenceUtil.reachabilityFence(paint);
return this;
}
@NotNull @Contract("_, _ -> this")
public Canvas drawOval(@NotNull Rect r, @NotNull Paint paint) {
assert r != null : "Can’t drawOval with r == null";
assert paint != null : "Can’t drawOval with paint == null";
Stats.onNativeCall();
_nDrawOval(_ptr, r._left, r._top, r._right, r._bottom, Native.getPtr(paint));
ReferenceUtil.reachabilityFence(paint);
return this;
}
@NotNull @Contract("_, _, _, _ -> this")
public Canvas drawCircle(float x, float y, float radius, @NotNull Paint paint) {
assert paint != null : "Can’t drawCircle with paint == null";
Stats.onNativeCall();
_nDrawOval(_ptr, x - radius, y - radius, x + radius, y + radius, Native.getPtr(paint));
ReferenceUtil.reachabilityFence(paint);
return this;
}
@NotNull @Contract("_, _ -> this")
public Canvas drawRRect(@NotNull RRect r, @NotNull Paint paint) {
assert r != null : "Can’t drawRRect with r == null";
assert paint != null : "Can’t drawRRect with paint == null";
Stats.onNativeCall();
_nDrawRRect(_ptr, r._left, r._top, r._right, r._bottom, r._radii, Native.getPtr(paint));
ReferenceUtil.reachabilityFence(paint);
return this;
}
@NotNull @Contract("_ -> this")
public boolean quickReject(@NotNull Rect r) {
try {
assert r != null : "Can’t quickReject with r == null";
Stats.onNativeCall();
return _nQuickReject(_ptr, r._left, r._top, r._right, r._bottom);
} finally {
ReferenceUtil.reachabilityFence(this);
}
}
@NotNull @Contract("_ -> this")
public boolean quickReject(@NotNull Path path) {
try {
assert path != null : "Can’t quickReject with path == null";
Stats.onNativeCall();
return _nQuickRejectPath(_ptr, Native.getPtr(path));
} finally {
ReferenceUtil.reachabilityFence(this);
ReferenceUtil.reachabilityFence(path);
}
}
@NotNull @Contract("_, _, _ -> this")
public Canvas drawDRRect(@NotNull RRect outer, @NotNull RRect inner, @NotNull Paint paint) {
assert outer != null : "Can’t drawDRRect with outer == null";
assert inner != null : "Can’t drawDRRect with inner == null";
assert paint != null : "Can’t drawDRRect with paint == null";
Stats.onNativeCall();
_nDrawDRRect(_ptr, outer._left, outer._top, outer._right, outer._bottom, outer._radii, inner._left, inner._top, inner._right, inner._bottom, inner._radii, Native.getPtr(paint));
ReferenceUtil.reachabilityFence(paint);
return this;
}
@NotNull @Contract("_, _ -> this")
public Canvas drawRectShadow(@NotNull Rect r, float dx, float dy, float blur, int color) {
return drawRectShadow(r, dx, dy, blur, 0f, color);
}
@NotNull @Contract("_, _ -> this")
public Canvas drawRectShadow(@NotNull Rect r, float dx, float dy, float blur, float spread, int color) {
assert r != null : "Can’t drawRectShadow with r == null";
Rect insides = r.inflate(-1);
if (!insides.isEmpty()) {
save();
if (insides instanceof RRect)
clipRRect((RRect) insides, ClipMode.DIFFERENCE);
else
clipRect(insides, ClipMode.DIFFERENCE);
drawRectShadowNoclip(r, dx, dy, blur, spread, color);
restore();
} else
drawRectShadowNoclip(r, dx, dy, blur, spread, color);
return this;
}
@NotNull @Contract("_, _ -> this")
public Canvas drawRectShadowNoclip(@NotNull Rect r, float dx, float dy, float blur, float spread, int color) {
assert r != null : "Can’t drawRectShadow with r == null";
Rect outline = r.inflate(spread);
try (ImageFilter f = ImageFilter.makeDropShadowOnly(dx, dy, blur / 2f, blur / 2f, color);
Paint p = new Paint();) {
p.setImageFilter(f);
if (outline instanceof RRect)
drawRRect((RRect) outline, p);
else
drawRect(outline, p);
}
return this;
}
@NotNull @Contract("_, _ -> this")
public Canvas drawPath(@NotNull Path path, @NotNull Paint paint) {
assert path != null : "Can’t drawPath with path == null";
assert paint != null : "Can’t drawPath with paint == null";
Stats.onNativeCall();
_nDrawPath(_ptr, Native.getPtr(path), Native.getPtr(paint));
ReferenceUtil.reachabilityFence(path);
ReferenceUtil.reachabilityFence(paint);
return this;
}
@NotNull @Contract("_, _, _ -> this")
public Canvas drawImage(@NotNull Image image, float left, float top) {
return drawImageRect(image, Rect.makeWH(image.getWidth(), image.getHeight()), Rect.makeXYWH(left, top, image.getWidth(), image.getHeight()), SamplingMode.DEFAULT, null, true);
}
@NotNull @Contract("_, _, _, _ -> this")
public Canvas drawImage(@NotNull Image image, float left, float top, @Nullable Paint paint) {
return drawImageRect(image, Rect.makeWH(image.getWidth(), image.getHeight()), Rect.makeXYWH(left, top, image.getWidth(), image.getHeight()), SamplingMode.DEFAULT, paint, true);
}
@NotNull @Contract("_, _ -> this")
public Canvas drawImageRect(@NotNull Image image, @NotNull Rect dst) {
return drawImageRect(image, Rect.makeWH(image.getWidth(), image.getHeight()), dst, SamplingMode.DEFAULT, null, true);
}
@NotNull @Contract("_, _, _ -> this")
public Canvas drawImageRect(@NotNull Image image, @NotNull Rect dst, @Nullable Paint paint) {
return drawImageRect(image, Rect.makeWH(image.getWidth(), image.getHeight()), dst, SamplingMode.DEFAULT, paint, true);
}
@NotNull @Contract("_, _, _, _ -> this")
public Canvas drawImageRect(@NotNull Image image, @NotNull Rect src, @NotNull Rect dst) {
return drawImageRect(image, src, dst, SamplingMode.DEFAULT, null, true);
}
@NotNull @Contract("_, _, _, _ -> this")
public Canvas drawImageRect(@NotNull Image image, @NotNull Rect src, @NotNull Rect dst, @Nullable Paint paint) {
return drawImageRect(image, src, dst, SamplingMode.DEFAULT, paint, true);
}
@NotNull @Contract("_, _, _, _, _ -> this")
public Canvas drawImageRect(@NotNull Image image, @NotNull Rect src, @NotNull Rect dst, @Nullable Paint paint, boolean strict) {
return drawImageRect(image, src, dst, SamplingMode.DEFAULT, paint, strict);
}
@NotNull @Contract("_, _, _, _, _ -> this")
public Canvas drawImageRect(@NotNull Image image, @NotNull Rect src, @NotNull Rect dst, @NotNull SamplingMode samplingMode, @Nullable Paint paint, boolean strict) {
assert image != null : "Can’t drawImageRect with image == null";
assert src != null : "Can’t drawImageRect with src == null";
assert dst != null : "Can’t drawImageRect with dst == null";
assert samplingMode != null : "Can’t drawImageRect with samplingMode == null";
Stats.onNativeCall();
_nDrawImageRect(_ptr, Native.getPtr(image), src._left, src._top, src._right, src._bottom, dst._left, dst._top, dst._right, dst._bottom, samplingMode._pack(), Native.getPtr(paint), strict);
ReferenceUtil.reachabilityFence(image);
ReferenceUtil.reachabilityFence(paint);
return this;
}
@NotNull @Contract("_, _, _, _, _ -> this")
public Canvas drawImageNine(@NotNull Image image, @NotNull IRect center, @NotNull Rect dst, @NotNull FilterMode filterMode, @Nullable Paint paint) {
assert image != null : "Can’t drawImageNine with image == null";
assert center != null : "Can’t drawImageNine with center == null";
assert dst != null : "Can’t drawImageNine with dst == null";
assert filterMode != null : "Can’t drawImageNine with filterMode == null";
Stats.onNativeCall();
_nDrawImageNine(_ptr, Native.getPtr(image), center._left, center._top, center._right, center._bottom, dst._left, dst._top, dst._right, dst._bottom, filterMode.ordinal(), Native.getPtr(paint));
ReferenceUtil.reachabilityFence(image);
ReferenceUtil.reachabilityFence(paint);
return this;
}
@NotNull @Contract("_, _ -> this")
public Canvas drawRegion(@NotNull Region r, @NotNull Paint paint) {
assert r != null : "Can’t drawRegion with r == null";
assert paint != null : "Can’t drawRegion with paint == null";
Stats.onNativeCall();
_nDrawRegion(_ptr, Native.getPtr(r), Native.getPtr(paint));
ReferenceUtil.reachabilityFence(r);
ReferenceUtil.reachabilityFence(paint);
return this;
}
@NotNull @Contract("_, _, _, _, _ -> this")
public Canvas drawString(@NotNull String s, float x, float y, Font font, @NotNull Paint paint) {
assert s != null : "Can’t drawString with s == null";
assert paint != null : "Can’t drawString with paint == null";
Stats.onNativeCall();
_nDrawString(_ptr, s, x, y, Native.getPtr(font), Native.getPtr(paint));
ReferenceUtil.reachabilityFence(font);
ReferenceUtil.reachabilityFence(paint);
return this;
}
@NotNull @Contract("_, _, _, _ -> this")
public Canvas drawTextBlob(@NotNull TextBlob blob, float x, float y, @NotNull Paint paint) {
assert blob != null : "Can’t drawTextBlob with blob == null";
assert paint != null : "Can’t drawTextBlob with paint == null";
Stats.onNativeCall();
_nDrawTextBlob(_ptr, Native.getPtr(blob), x, y, Native.getPtr(paint));
ReferenceUtil.reachabilityFence(blob);
ReferenceUtil.reachabilityFence(paint);
return this;
}
@NotNull @Contract("_, _, _, _ -> this")
public Canvas drawTextLine(@NotNull TextLine line, float x, float y, @NotNull Paint paint) {
assert line != null : "Can’t drawTextLine with line == null";
assert paint != null : "Can’t drawTextLine with paint == null";
try (TextBlob blob = line.getTextBlob();) {
if (blob != null)
drawTextBlob(blob, x, y, paint);
}
return this;
}
@NotNull @Contract("_ -> this")
public Canvas drawPicture(@NotNull Picture picture) {
return drawPicture(picture, null, null);
}
@NotNull @Contract("_, _, _ -> this")
public Canvas drawPicture(@NotNull Picture picture, @Nullable Matrix33 matrix, @Nullable Paint paint) {
assert picture != null : "Can’t drawPicture with picture == null";
Stats.onNativeCall();
_nDrawPicture(_ptr, Native.getPtr(picture), matrix == null ? null : matrix._mat, Native.getPtr(paint));
ReferenceUtil.reachabilityFence(picture);
ReferenceUtil.reachabilityFence(paint);
return this;
}
/**
* <p>Draws a triangle mesh, using clip and Matrix.</p>
*
* <p>If paint contains an Shader, the shader is mapped using the vertices' positions.</p>
*
* <p>If vertices colors are defined in vertices, and Paint paint contains Shader,
* BlendMode mode combines vertices colors with Shader.</p>
*
* @param positions triangle mesh to draw
* @param colors color array, one for each corner; may be null
* @param paint specifies the Shader, used as Vertices texture
*
* @see <a href="https://fiddle.skia.org/c/@Canvas_drawVertices">https://fiddle.skia.org/c/@Canvas_drawVertices</a>
* @see <a href="https://fiddle.skia.org/c/@Canvas_drawVertices_2">https://fiddle.skia.org/c/@Canvas_drawVertices_2</a>
*/
@NotNull @Contract("_, _, _ -> this")
public Canvas drawTriangles(@NotNull Point[] positions, @Nullable int[] colors, @NotNull Paint paint) {
return drawTriangles(positions, colors, null, null, BlendMode.MODULATE, paint);
}
/**
* <p>Draws a triangle mesh, using clip and Matrix.</p>
*
* <p>If paint contains an Shader and vertices does not contain texCoords, the shader
* is mapped using the vertices' positions.</p>
*
* <p>If vertices colors are defined in vertices, and Paint paint contains Shader,
* BlendMode mode combines vertices colors with Shader.</p>
*
* @param positions triangle mesh to draw
* @param colors color array, one for each corner; may be null
* @param texCoords Point array of texture coordinates, mapping Shader to corners; may be null
* @param indices with which indices points should be drawn; may be null
* @param paint specifies the Shader, used as Vertices texture
*
* @see <a href="https://fiddle.skia.org/c/@Canvas_drawVertices">https://fiddle.skia.org/c/@Canvas_drawVertices</a>
* @see <a href="https://fiddle.skia.org/c/@Canvas_drawVertices_2">https://fiddle.skia.org/c/@Canvas_drawVertices_2</a>
*/
@NotNull @Contract("_, _, _, _, _ -> this")
public Canvas drawTriangles(@NotNull Point[] positions, @Nullable int[] colors, @Nullable Point[] texCoords, @Nullable short[] indices, @NotNull Paint paint) {
return drawTriangles(positions, colors, texCoords, indices, BlendMode.MODULATE, paint);
}
/**
* <p>Draws a triangle mesh, using clip and Matrix.</p>
*
* <p>If paint contains an Shader and vertices does not contain texCoords, the shader
* is mapped using the vertices' positions.</p>
*
* <p>If vertices colors are defined in vertices, and Paint paint contains Shader,
* BlendMode mode combines vertices colors with Shader.</p>
*
* @param positions triangle mesh to draw
* @param colors color array, one for each corner; may be null
* @param texCoords Point array of texture coordinates, mapping Shader to corners; may be null
* @param indices with which indices points should be drawn; may be null
* @param mode combines vertices colors with Shader, if both are present
* @param paint specifies the Shader, used as Vertices texture
*
* @see <a href="https://fiddle.skia.org/c/@Canvas_drawVertices">https://fiddle.skia.org/c/@Canvas_drawVertices</a>
* @see <a href="https://fiddle.skia.org/c/@Canvas_drawVertices_2">https://fiddle.skia.org/c/@Canvas_drawVertices_2</a>
*/
@NotNull @Contract("_, _, _, _, _, _ -> this")
public Canvas drawTriangles(@NotNull Point[] positions, @Nullable int[] colors, @Nullable Point[] texCoords, @Nullable short[] indices, @NotNull BlendMode mode, @NotNull Paint paint) {
assert positions != null : "Can’t drawTriangles with positions == null";
assert positions.length % 3 == 0 : "Expected positions.length % 3 == 0, got: " + positions.length;
assert colors == null || colors.length == positions.length : "Expected colors.length == positions.length, got: " + colors.length + " != " + positions.length;
assert texCoords == null || texCoords.length == positions.length : "Expected texCoords.length == positions.length, got: " + texCoords.length + " != " + positions.length;
assert paint != null : "Can’t drawTriangles with paint == null";
Stats.onNativeCall();
_nDrawVertices(_ptr, 0 /* kTriangles_VertexMode */, Point.flattenArray(positions), colors, Point.flattenArray(texCoords), indices, mode.ordinal(), Native.getPtr(paint));
ReferenceUtil.reachabilityFence(paint);
return this;
}
/**
* <p>Draws a triangle strip mesh, using clip and Matrix.</p>
*
* <p>If paint contains an Shader, the shader is mapped using the vertices' positions.</p>
*
* <p>If vertices colors are defined in vertices, and Paint paint contains Shader,
* BlendMode mode combines vertices colors with Shader.</p>
*
* @param positions triangle mesh to draw
* @param colors color array, one for each corner; may be null
* @param paint specifies the Shader, used as Vertices texture
*
* @see <a href="https://fiddle.skia.org/c/@Canvas_drawVertices">https://fiddle.skia.org/c/@Canvas_drawVertices</a>
* @see <a href="https://fiddle.skia.org/c/@Canvas_drawVertices_2">https://fiddle.skia.org/c/@Canvas_drawVertices_2</a>
*/
@NotNull @Contract("_, _, _ -> this")
public Canvas drawTriangleStrip(@NotNull Point[] positions, @Nullable int[] colors, @NotNull Paint paint) {
return drawTriangleStrip(positions, colors, null, null, BlendMode.MODULATE, paint);
}
/**
* <p>Draws a triangle strip mesh, using clip and Matrix.</p>
*
* <p>If paint contains an Shader and vertices does not contain texCoords, the shader
* is mapped using the vertices' positions.</p>
*
* <p>If vertices colors are defined in vertices, and Paint paint contains Shader,
* BlendMode mode combines vertices colors with Shader.</p>
*
* @param positions triangle mesh to draw
* @param colors color array, one for each corner; may be null
* @param texCoords Point array of texture coordinates, mapping Shader to corners; may be null
* @param indices with which indices points should be drawn; may be null
* @param paint specifies the Shader, used as Vertices texture
*
* @see <a href="https://fiddle.skia.org/c/@Canvas_drawVertices">https://fiddle.skia.org/c/@Canvas_drawVertices</a>
* @see <a href="https://fiddle.skia.org/c/@Canvas_drawVertices_2">https://fiddle.skia.org/c/@Canvas_drawVertices_2</a>
*/
@NotNull @Contract("_, _, _, _, _ -> this")
public Canvas drawTriangleStrip(@NotNull Point[] positions, @Nullable int[] colors, @Nullable Point[] texCoords, @Nullable short[] indices, @NotNull Paint paint) {
return drawTriangleStrip(positions, colors, texCoords, indices, BlendMode.MODULATE, paint);
}
/**
* <p>Draws a triangle strip mesh, using clip and Matrix.</p>
*
* <p>If paint contains an Shader and vertices does not contain texCoords, the shader
* is mapped using the vertices' positions.</p>
*
* <p>If vertices colors are defined in vertices, and Paint paint contains Shader,
* BlendMode mode combines vertices colors with Shader.</p>
*
* @param positions triangle mesh to draw
* @param colors color array, one for each corner; may be null
* @param texCoords Point array of texture coordinates, mapping Shader to corners; may be null
* @param indices with which indices points should be drawn; may be null
* @param mode combines vertices colors with Shader, if both are present
* @param paint specifies the Shader, used as Vertices texture
*
* @see <a href="https://fiddle.skia.org/c/@Canvas_drawVertices">https://fiddle.skia.org/c/@Canvas_drawVertices</a>
* @see <a href="https://fiddle.skia.org/c/@Canvas_drawVertices_2">https://fiddle.skia.org/c/@Canvas_drawVertices_2</a>
*/
@NotNull @Contract("_, _, _, _, _, _ -> this")
public Canvas drawTriangleStrip(@NotNull Point[] positions, @Nullable int[] colors, @Nullable Point[] texCoords, @Nullable short[] indices, @NotNull BlendMode mode, @NotNull Paint paint) {
assert positions != null : "Can’t drawTriangleStrip with positions == null";
assert colors == null || colors.length == positions.length : "Expected colors.length == positions.length, got: " + colors.length + " != " + positions.length;
assert texCoords == null || texCoords.length == positions.length : "Expected texCoords.length == positions.length, got: " + texCoords.length + " != " + positions.length;
assert mode != null : "Can’t drawTriangles with mode == null";
assert paint != null : "Can’t drawTriangles with paint == null";
Stats.onNativeCall();
_nDrawVertices(_ptr, 1 /* kTriangleStrip_VertexMode */, Point.flattenArray(positions), colors, Point.flattenArray(texCoords), indices, mode.ordinal(), Native.getPtr(paint));
ReferenceUtil.reachabilityFence(paint);
return this;
}
/**
* <p>Draws a triangle fan mesh, using clip and Matrix.</p>
*
* <p>If paint contains an Shader, the shader is mapped using the vertices' positions.</p>
*
* <p>If vertices colors are defined in vertices, and Paint paint contains Shader,
* BlendMode mode combines vertices colors with Shader.</p>
*
* @param positions triangle mesh to draw
* @param colors color array, one for each corner; may be null
* @param paint specifies the Shader, used as Vertices texture
*
* @see <a href="https://fiddle.skia.org/c/@Canvas_drawVertices">https://fiddle.skia.org/c/@Canvas_drawVertices</a>
* @see <a href="https://fiddle.skia.org/c/@Canvas_drawVertices_2">https://fiddle.skia.org/c/@Canvas_drawVertices_2</a>
*/
@NotNull @Contract("_, _, _ -> this")
public Canvas drawTriangleFan(@NotNull Point[] positions, @Nullable int[] colors, @NotNull Paint paint) {
return drawTriangleFan(positions, colors, null, null, BlendMode.MODULATE, paint);
}
/**
* <p>Draws a triangle fan mesh, using clip and Matrix.</p>
*
* <p>If paint contains an Shader and vertices does not contain texCoords, the shader
* is mapped using the vertices' positions.</p>
*
* <p>If vertices colors are defined in vertices, and Paint paint contains Shader,
* BlendMode mode combines vertices colors with Shader.</p>
*
* @param positions triangle mesh to draw
* @param colors color array, one for each corner; may be null
* @param texCoords Point array of texture coordinates, mapping Shader to corners; may be null
* @param indices with which indices points should be drawn; may be null
* @param paint specifies the Shader, used as Vertices texture
*
* @see <a href="https://fiddle.skia.org/c/@Canvas_drawVertices">https://fiddle.skia.org/c/@Canvas_drawVertices</a>
* @see <a href="https://fiddle.skia.org/c/@Canvas_drawVertices_2">https://fiddle.skia.org/c/@Canvas_drawVertices_2</a>
*/
@NotNull @Contract("_, _, _, _, _ -> this")
public Canvas drawTriangleFan(@NotNull Point[] positions, @Nullable int[] colors, @Nullable Point[] texCoords, @Nullable short[] indices, @NotNull Paint paint) {
return drawTriangleFan(positions, colors, texCoords, indices, BlendMode.MODULATE, paint);
}
/**
* <p>Draws a triangle fan mesh, using clip and Matrix.</p>
*
* <p>If paint contains an Shader and vertices does not contain texCoords, the shader
* is mapped using the vertices' positions.</p>
*
* <p>If vertices colors are defined in vertices, and Paint paint contains Shader,
* BlendMode mode combines vertices colors with Shader.</p>
*
* @param positions triangle mesh to draw
* @param colors color array, one for each corner; may be null
* @param texCoords Point array of texture coordinates, mapping Shader to corners; may be null
* @param indices with which indices points should be drawn; may be null
* @param mode combines vertices colors with Shader, if both are present
* @param paint specifies the Shader, used as Vertices texture
*
* @see <a href="https://fiddle.skia.org/c/@Canvas_drawVertices">https://fiddle.skia.org/c/@Canvas_drawVertices</a>
* @see <a href="https://fiddle.skia.org/c/@Canvas_drawVertices_2">https://fiddle.skia.org/c/@Canvas_drawVertices_2</a>
*/
@NotNull @Contract("_, _, _, _, _, _ -> this")
public Canvas drawTriangleFan(@NotNull Point[] positions, @Nullable int[] colors, @Nullable Point[] texCoords, @Nullable short[] indices, @NotNull BlendMode mode, @NotNull Paint paint) {
assert positions != null : "Can’t drawTriangleFan with positions == null";
assert colors == null || colors.length == positions.length : "Expected colors.length == positions.length, got: " + colors.length + " != " + positions.length;
assert texCoords == null || texCoords.length == positions.length : "Expected texCoords.length == positions.length, got: " + texCoords.length + " != " + positions.length;
assert mode != null : "Can’t drawTriangleFan with mode == null";
assert paint != null : "Can’t drawTriangleFan with paint == null";
Stats.onNativeCall();
_nDrawVertices(_ptr, 2 /* kTriangleFan_VertexMode */, Point.flattenArray(positions), colors, Point.flattenArray(texCoords), indices, mode.ordinal(), Native.getPtr(paint));
ReferenceUtil.reachabilityFence(paint);
return this;
}
/**
* <p>Draws a Coons patch: the interpolation of four cubics with shared corners,
* associating a color, and optionally a texture SkPoint, with each corner.</p>
*
* <p>Coons patch uses clip and Matrix, paint Shader, ColorFilter,
* alpha, ImageFilter, and BlendMode. If Shader is provided it is treated
* as Coons patch texture.</p>
*
* <p>Point array cubics specifies four Path cubic starting at the top-left corner,
* in clockwise order, sharing every fourth point. The last Path cubic ends at the
* first point.</p>
*
* <p>Color array color associates colors with corners in top-left, top-right,
* bottom-right, bottom-left order.</p>
*
*
* @param cubics Path cubic array, sharing common points
* @param colors color array, one for each corner
* @param paint Shader, ColorFilter, BlendMode, used to draw
* @return this
*
* @see <a href="https://fiddle.skia.org/c/4cf70f8d194867d053d7e177e5088445">https://fiddle.skia.org/c/4cf70f8d194867d053d7e177e5088445</a>
*/
@NotNull @Contract("_, _, _ -> this")
public Canvas drawPatch(@NotNull Point[] cubics, @NotNull int[] colors, @NotNull Paint paint) {
return drawPatch(cubics, colors, null, paint);
}
/**
* <p>Draws a Coons patch: the interpolation of four cubics with shared corners,
* associating a color, and optionally a texture SkPoint, with each corner.</p>
*
* <p>Coons patch uses clip and Matrix, paint Shader, ColorFilter,
* alpha, ImageFilter, and BlendMode. If Shader is provided it is treated
* as Coons patch texture.</p>
*
* <p>Point array cubics specifies four Path cubic starting at the top-left corner,
* in clockwise order, sharing every fourth point. The last Path cubic ends at the
* first point.</p>
*
* <p>Color array color associates colors with corners in top-left, top-right,
* bottom-right, bottom-left order.</p>
*
* <p>If paint contains Shader, Point array texCoords maps Shader as texture to
* corners in top-left, top-right, bottom-right, bottom-left order. If texCoords is
* nullptr, Shader is mapped using positions (derived from cubics).</p>
*
* @param cubics Path cubic array, sharing common points
* @param colors color array, one for each corner
* @param texCoords Point array of texture coordinates, mapping Shader to corners;
* may be null
* @param paint Shader, ColorFilter, BlendMode, used to draw
* @return this
*
* @see <a href="https://fiddle.skia.org/c/4cf70f8d194867d053d7e177e5088445">https://fiddle.skia.org/c/4cf70f8d194867d053d7e177e5088445</a>
*/
@NotNull @Contract("_, _, _, _ -> this")
public Canvas drawPatch(@NotNull Point[] cubics, @NotNull int[] colors, @Nullable Point[] texCoords, @NotNull Paint paint) {
return drawPatch(cubics, colors, texCoords, BlendMode.MODULATE, paint);
}
/**
* <p>Draws a Coons patch: the interpolation of four cubics with shared corners,
* associating a color, and optionally a texture SkPoint, with each corner.</p>
*
* <p>Coons patch uses clip and Matrix, paint Shader, ColorFilter,
* alpha, ImageFilter, and BlendMode. If Shader is provided it is treated
* as Coons patch texture; BlendMode mode combines color colors and Shader if
* both are provided.</p>
*
* <p>Point array cubics specifies four Path cubic starting at the top-left corner,
* in clockwise order, sharing every fourth point. The last Path cubic ends at the
* first point.</p>
*
* <p>Color array color associates colors with corners in top-left, top-right,
* bottom-right, bottom-left order.</p>
*
* <p>If paint contains Shader, Point array texCoords maps Shader as texture to
* corners in top-left, top-right, bottom-right, bottom-left order. If texCoords is
* nullptr, Shader is mapped using positions (derived from cubics).</p>
*
* @param cubics Path cubic array, sharing common points
* @param colors color array, one for each corner
* @param texCoords Point array of texture coordinates, mapping Shader to corners;
* may be null
* @param mode BlendMode for colors, and for Shader if paint has one
* @param paint Shader, ColorFilter, BlendMode, used to draw
* @return this
*
* @see <a href="https://fiddle.skia.org/c/4cf70f8d194867d053d7e177e5088445">https://fiddle.skia.org/c/4cf70f8d194867d053d7e177e5088445</a>
*/
@NotNull @Contract("_, _, _, _, _ -> this")
public Canvas drawPatch(@NotNull Point[] cubics, @NotNull int[] colors, @Nullable Point[] texCoords, @NotNull BlendMode mode, @NotNull Paint paint) {
assert cubics != null : "Can’t drawPatch with cubics == null";
assert cubics.length == 12 : "Expected cubics.length == 12, got: " + cubics.length;
assert colors != null : "Can’t drawPatch with colors == null";
assert colors.length == 4 : "Expected colors.length == 4, got: " + colors.length;
assert texCoords == null || texCoords.length == 4 : "Expected texCoords.length == 4, got: " + texCoords.length;
assert mode != null : "Can’t drawPatch with mode == null";
assert paint != null : "Can’t drawPatch with paint == null";
Stats.onNativeCall();
_nDrawPatch(_ptr, Point.flattenArray(cubics), colors, Point.flattenArray(texCoords), mode.ordinal(), Native.getPtr(paint));
ReferenceUtil.reachabilityFence(paint);
return this;
}
/**
* <p>Draws Drawable drawable using clip and matrix.</p>
*
* <p>If Canvas has an asynchronous implementation, as is the case
* when it is recording into Picture, then drawable will be referenced,
* so that Drawable::draw() can be called when the operation is finalized. To force
* immediate drawing, call Drawable::draw() instead.</p>
*
* @param drawable custom struct encapsulating drawing commands
* @return this
*/
@NotNull @Contract("_ -> this")
public Canvas drawDrawable(@NotNull Drawable drawable) {
return drawDrawable(drawable, null);
}
/**
* <p>Draws Drawable drawable using clip and matrix, offset by (x, y).</p>
*
* <p>If Canvas has an asynchronous implementation, as is the case
* when it is recording into Picture, then drawable will be referenced,
* so that Drawable::draw() can be called when the operation is finalized. To force
* immediate drawing, call Drawable::draw() instead.</p>
*
* @param drawable custom struct encapsulating drawing commands
* @param x offset into Canvas writable pixels on x-axis
* @param y offset into Canvas writable pixels on y-axis
* @return this
*
* @see <a href="https://fiddle.skia.org/c/@Canvas_drawDrawable_2">https://fiddle.skia.org/c/@Canvas_drawDrawable_2</a>
*/
@NotNull @Contract("_, _, _ -> this")
public Canvas drawDrawable(@NotNull Drawable drawable, float x, float y) {
return drawDrawable(drawable, Matrix33.makeTranslate(x, y));
}
/**
* <p>Draws Drawable drawable using clip and matrix, concatenated with
* optional matrix.</p>
*
* <p>If Canvas has an asynchronous implementation, as is the case
* when it is recording into Picture, then drawable will be referenced,
* so that Drawable::draw() can be called when the operation is finalized. To force
* immediate drawing, call Drawable::draw() instead.</p>
*
* @param drawable custom struct encapsulating drawing commands
* @param matrix transformation applied to drawing; may be null
* @return this
*
* @see <a href="https://fiddle.skia.org/c/@Canvas_drawDrawable">https://fiddle.skia.org/c/@Canvas_drawDrawable</a>
*/
@NotNull @Contract("_, _ -> this")
public Canvas drawDrawable(@NotNull Drawable drawable, @Nullable Matrix33 matrix) {
assert drawable != null : "Can’t drawDrawable with drawable == null";
Stats.onNativeCall();
_nDrawDrawable(_ptr, Native.getPtr(drawable), matrix == null ? null : matrix._mat);
ReferenceUtil.reachabilityFence(drawable);
return this;
}
@NotNull @Contract("_ -> this")
public Canvas drawColor(int color) {
return drawColor(color, BlendMode.SRC_OVER);
}
@NotNull @Contract("_, _ -> this")
public Canvas drawColor(int color, @NotNull BlendMode mode) {
Stats.onNativeCall();
_nDrawColor(_ptr, color, mode.ordinal());
return this;
}
@NotNull @Contract("_ -> this")
public Canvas drawColor(@NotNull Color4f color) {
return drawColor(color, BlendMode.SRC_OVER);
}
@NotNull @Contract("_, _ -> this")
public Canvas drawColor(@NotNull Color4f color, @NotNull BlendMode mode) {
Stats.onNativeCall();
_nDrawColor4f(_ptr, color._r, color._g, color._b, color._a, mode.ordinal());
return this;
}
@NotNull @Contract("_ -> this")
public Canvas clear(int color) {
Stats.onNativeCall();
_nClear(_ptr, color);
return this;
}
@NotNull @Contract("_ -> this")
public Canvas drawPaint(@NotNull Paint paint) {
assert paint != null : "Can’t drawPaint with paint == null";
Stats.onNativeCall();
_nDrawPaint(_ptr, Native.getPtr(paint));
ReferenceUtil.reachabilityFence(paint);
return this;
}
/**
* Replaces Matrix with matrix.
* Unlike concat(), any prior matrix state is overwritten.
*
* @param matrix matrix to copy, replacing existing Matrix
*
* @see <a href="https://fiddle.skia.org/c/@Canvas_setMatrix">https://fiddle.skia.org/c/@Canvas_setMatrix</a>
*/
@NotNull @Contract("_ -> this")
public Canvas setMatrix(@NotNull Matrix33 matrix) {
assert matrix != null : "Can’t setMatrix with matrix == null";
Stats.onNativeCall();
_nSetMatrix(_ptr, matrix._mat);
return this;
}
/**
* Replaces Matrix with matrix.
* Unlike concat(), any prior matrix state is overwritten.
*
* @param matrix matrix to copy, replacing existing Matrix
*
* @see <a href="https://fiddle.skia.org/c/@Canvas_setMatrix">https://fiddle.skia.org/c/@Canvas_setMatrix</a>
*/
@NotNull @Contract("_ -> this")
public Canvas setMatrix(@NotNull Matrix44 matrix) {
assert matrix != null : "Can’t setMatrix with matrix == null";
Stats.onNativeCall();
_nSetMatrix44(_ptr, matrix._mat);
return this;
}
/**
* Sets SkMatrix to the identity matrix.
* Any prior matrix state is overwritten.
*
* @see <a href="https://fiddle.skia.org/c/@Canvas_resetMatrix">https://fiddle.skia.org/c/@Canvas_resetMatrix</a>
*/
@NotNull @Contract("-> this")