forked from flutter/engine
-
Notifications
You must be signed in to change notification settings - Fork 2
/
canvaskit_api.dart
2811 lines (2425 loc) · 73.8 KB
/
canvaskit_api.dart
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
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
/// Bindings for CanvasKit JavaScript API.
///
/// Prefer keeping the original CanvasKit names so it is easier to locate
/// the API behind these bindings in the Skia source code.
// ignore_for_file: non_constant_identifier_names
@JS()
library canvaskit_api;
import 'dart:async';
import 'dart:convert';
import 'dart:js_util' as js_util;
import 'dart:typed_data';
import 'package:js/js.dart';
import 'package:meta/meta.dart';
import 'package:ui/ui.dart' as ui;
import '../browser_detection.dart';
import '../configuration.dart';
import '../dom.dart';
import '../profiler.dart';
import 'renderer.dart';
/// Entrypoint into the CanvasKit API.
late CanvasKit canvasKit;
late CanvasKitVariant _canvasKitVariant;
/// Which variant of CanvasKit we are using.
CanvasKitVariant get canvasKitVariant => _canvasKitVariant;
set canvasKitVariant(CanvasKitVariant value) {
if (value == CanvasKitVariant.auto) {
throw ArgumentError.value(
value,
'value',
'CanvasKitVariant.auto is not a valid value for canvasKitVariant',
);
}
_canvasKitVariant = value;
}
/// Sets the [CanvasKit] object on `window` so we can use `@JS()` to bind to
/// static APIs.
///
/// See, e.g. [SkPaint].
///
/// This also acts as a cache of an initialized CanvasKit instance. We can use
/// this, for example, to perform a hot restart without needing to redownload
/// and reinitialize CanvasKit.
@JS('window.flutterCanvasKit')
external set windowFlutterCanvasKit(CanvasKit? value);
@JS('window.flutterCanvasKit')
external CanvasKit? get windowFlutterCanvasKit;
@JS()
@anonymous
@staticInterop
class CanvasKit {}
extension CanvasKitExtension on CanvasKit {
external SkBlendModeEnum get BlendMode;
external SkPaintStyleEnum get PaintStyle;
external SkStrokeCapEnum get StrokeCap;
external SkStrokeJoinEnum get StrokeJoin;
external SkBlurStyleEnum get BlurStyle;
external SkTileModeEnum get TileMode;
external SkFilterModeEnum get FilterMode;
external SkMipmapModeEnum get MipmapMode;
external SkFillTypeEnum get FillType;
external SkAlphaTypeEnum get AlphaType;
external SkColorTypeEnum get ColorType;
external SkPathOpEnum get PathOp;
external SkClipOpEnum get ClipOp;
external SkPointModeEnum get PointMode;
external SkVertexModeEnum get VertexMode;
external SkRectHeightStyleEnum get RectHeightStyle;
external SkRectWidthStyleEnum get RectWidthStyle;
external SkAffinityEnum get Affinity;
external SkTextAlignEnum get TextAlign;
external SkTextHeightBehaviorEnum get TextHeightBehavior;
external SkTextDirectionEnum get TextDirection;
external SkFontWeightEnum get FontWeight;
external SkFontSlantEnum get FontSlant;
external SkAnimatedImage? MakeAnimatedImageFromEncoded(Uint8List imageData);
external SkShaderNamespace get Shader;
external SkMaskFilterNamespace get MaskFilter;
external SkColorFilterNamespace get ColorFilter;
external SkImageFilterNamespace get ImageFilter;
external SkPathNamespace get Path;
external SkTonalColors computeTonalColors(SkTonalColors inTonalColors);
external SkVertices MakeVertices(
SkVertexMode mode,
Float32List positions,
Float32List? textureCoordinates,
Uint32List? colors,
Uint16List? indices,
);
external SkParagraphBuilderNamespace get ParagraphBuilder;
external SkParagraphStyle ParagraphStyle(
SkParagraphStyleProperties properties);
external SkTextStyle TextStyle(SkTextStyleProperties properties);
external SkSurface MakeWebGLCanvasSurface(DomCanvasElement canvas);
external SkSurface MakeSurface(
double width,
double height,
);
external Uint8List getDataBytes(
SkData skData,
);
// Text decoration enum is embedded in the CanvasKit object itself.
external double get NoDecoration;
external double get UnderlineDecoration;
external double get OverlineDecoration;
external double get LineThroughDecoration;
// End of text decoration enum.
external SkTextDecorationStyleEnum get DecorationStyle;
external SkTextBaselineEnum get TextBaseline;
external SkPlaceholderAlignmentEnum get PlaceholderAlignment;
external SkFontMgrNamespace get FontMgr;
external TypefaceFontProviderNamespace get TypefaceFontProvider;
external SkTypefaceFactory get Typeface;
external double GetWebGLContext(
DomCanvasElement canvas, SkWebGLContextOptions options);
external SkGrContext MakeGrContext(double glContext);
external SkSurface? MakeOnScreenGLSurface(
SkGrContext grContext,
double width,
double height,
ColorSpace colorSpace,
int sampleCount,
int stencil,
);
external SkSurface? MakeRenderTarget(
SkGrContext grContext,
int width,
int height,
);
external SkSurface MakeSWCanvasSurface(DomCanvasElement canvas);
/// Creates an image from decoded pixels represented as a list of bytes.
///
/// The pixel data must be encoded according to the image info in [info].
///
/// Typically pixel data is obtained using [SkImage.readPixels]. The
/// parameters specified in [SkImageInfo] passed [SkImage.readPixels] must
/// match [info].
external SkImage? MakeImage(
SkImageInfo info,
Uint8List pixels,
double bytesPerRow,
);
external SkImage? MakeLazyImageFromTextureSource(
Object src,
SkPartialImageInfo info,
);
}
@JS('window.CanvasKitInit')
external Object _CanvasKitInit(CanvasKitInitOptions options);
Future<CanvasKit> CanvasKitInit(CanvasKitInitOptions options) {
return js_util.promiseToFuture<CanvasKit>(_CanvasKitInit(options));
}
typedef LocateFileCallback = String Function(String file, String unusedBase);
@JS()
@anonymous
@staticInterop
class CanvasKitInitOptions {
external factory CanvasKitInitOptions({
required LocateFileCallback locateFile,
});
}
@JS('window.flutterCanvasKit.ColorSpace.SRGB')
external ColorSpace get SkColorSpaceSRGB;
@JS()
@staticInterop
class ColorSpace {}
@JS()
@anonymous
@staticInterop
class SkWebGLContextOptions {
external factory SkWebGLContextOptions({
required double antialias,
// WebGL version: 1 or 2.
required double majorVersion,
});
}
@JS('window.flutterCanvasKit.Surface')
@staticInterop
class SkSurface {}
extension SkSurfaceExtension on SkSurface {
external SkCanvas getCanvas();
external void flush();
external double width();
external double height();
external void dispose();
external SkImage makeImageSnapshot();
}
@JS()
@staticInterop
class SkGrContext {}
extension SkGrContextExtension on SkGrContext {
external void setResourceCacheLimitBytes(double limit);
external void releaseResourcesAndAbandonContext();
external void delete();
}
@JS()
@anonymous
@staticInterop
class SkFontSlantEnum {}
extension SkFontSlantEnumExtension on SkFontSlantEnum {
external SkFontSlant get Upright;
external SkFontSlant get Italic;
}
@JS('window.flutterCanvasKit.FontSlant')
@staticInterop
class SkFontSlant {}
extension SkFontSlantExtension on SkFontSlant {
external double get value;
}
final List<SkFontSlant> _skFontSlants = <SkFontSlant>[
canvasKit.FontSlant.Upright,
canvasKit.FontSlant.Italic,
];
SkFontSlant toSkFontSlant(ui.FontStyle style) {
return _skFontSlants[style.index];
}
@JS()
@anonymous
@staticInterop
class SkFontWeightEnum {}
extension SkFontWeightEnumExtension on SkFontWeightEnum {
external SkFontWeight get Thin;
external SkFontWeight get ExtraLight;
external SkFontWeight get Light;
external SkFontWeight get Normal;
external SkFontWeight get Medium;
external SkFontWeight get SemiBold;
external SkFontWeight get Bold;
external SkFontWeight get ExtraBold;
external SkFontWeight get ExtraBlack;
}
@JS()
@staticInterop
class SkFontWeight {}
extension SkFontWeightExtension on SkFontWeight {
external double get value;
}
final List<SkFontWeight> _skFontWeights = <SkFontWeight>[
canvasKit.FontWeight.Thin,
canvasKit.FontWeight.ExtraLight,
canvasKit.FontWeight.Light,
canvasKit.FontWeight.Normal,
canvasKit.FontWeight.Medium,
canvasKit.FontWeight.SemiBold,
canvasKit.FontWeight.Bold,
canvasKit.FontWeight.ExtraBold,
canvasKit.FontWeight.ExtraBlack,
];
SkFontWeight toSkFontWeight(ui.FontWeight weight) {
return _skFontWeights[weight.index];
}
@JS()
@staticInterop
class SkAffinityEnum {}
extension SkAffinityEnumExtension on SkAffinityEnum {
external SkAffinity get Upstream;
external SkAffinity get Downstream;
}
@JS()
@staticInterop
class SkAffinity {}
extension SkAffinityExtension on SkAffinity {
external double get value;
}
final List<SkAffinity> _skAffinitys = <SkAffinity>[
canvasKit.Affinity.Upstream,
canvasKit.Affinity.Downstream,
];
SkAffinity toSkAffinity(ui.TextAffinity affinity) {
return _skAffinitys[affinity.index];
}
@JS()
@staticInterop
class SkTextDirectionEnum {}
extension SkTextDirectionEnumExtension on SkTextDirectionEnum {
external SkTextDirection get RTL;
external SkTextDirection get LTR;
}
@JS()
@staticInterop
class SkTextDirection {}
extension SkTextDirectionExtension on SkTextDirection {
external double get value;
}
// Flutter enumerates text directions as RTL, LTR, while CanvasKit
// enumerates them LTR, RTL.
final List<SkTextDirection> _skTextDirections = <SkTextDirection>[
canvasKit.TextDirection.RTL,
canvasKit.TextDirection.LTR,
];
SkTextDirection toSkTextDirection(ui.TextDirection direction) {
return _skTextDirections[direction.index];
}
@JS()
@staticInterop
class SkTextAlignEnum {}
extension SkTextAlignEnumExtension on SkTextAlignEnum {
external SkTextAlign get Left;
external SkTextAlign get Right;
external SkTextAlign get Center;
external SkTextAlign get Justify;
external SkTextAlign get Start;
external SkTextAlign get End;
}
@JS()
@staticInterop
class SkTextAlign {}
extension SkTextAlignExtension on SkTextAlign {
external double get value;
}
final List<SkTextAlign> _skTextAligns = <SkTextAlign>[
canvasKit.TextAlign.Left,
canvasKit.TextAlign.Right,
canvasKit.TextAlign.Center,
canvasKit.TextAlign.Justify,
canvasKit.TextAlign.Start,
canvasKit.TextAlign.End,
];
SkTextAlign toSkTextAlign(ui.TextAlign align) {
return _skTextAligns[align.index];
}
@JS()
@staticInterop
class SkTextHeightBehaviorEnum {}
extension SkTextHeightBehaviorEnumExtension on SkTextHeightBehaviorEnum {
external SkTextHeightBehavior get All;
external SkTextHeightBehavior get DisableFirstAscent;
external SkTextHeightBehavior get DisableLastDescent;
external SkTextHeightBehavior get DisableAll;
}
@JS()
@staticInterop
class SkTextHeightBehavior {}
extension SkTextHeightBehaviorExtension on SkTextHeightBehavior {
external double get value;
}
final List<SkTextHeightBehavior> _skTextHeightBehaviors =
<SkTextHeightBehavior>[
canvasKit.TextHeightBehavior.All,
canvasKit.TextHeightBehavior.DisableFirstAscent,
canvasKit.TextHeightBehavior.DisableLastDescent,
canvasKit.TextHeightBehavior.DisableAll,
];
SkTextHeightBehavior toSkTextHeightBehavior(ui.TextHeightBehavior behavior) {
final int index = (behavior.applyHeightToFirstAscent ? 0 : 1 << 0) |
(behavior.applyHeightToLastDescent ? 0 : 1 << 1);
return _skTextHeightBehaviors[index];
}
@JS()
@staticInterop
class SkRectHeightStyleEnum {}
extension SkRectHeightStyleEnumExtension on SkRectHeightStyleEnum {
external SkRectHeightStyle get Tight;
external SkRectHeightStyle get Max;
external SkRectHeightStyle get IncludeLineSpacingMiddle;
external SkRectHeightStyle get IncludeLineSpacingTop;
external SkRectHeightStyle get IncludeLineSpacingBottom;
external SkRectHeightStyle get Strut;
}
@JS()
@staticInterop
class SkRectHeightStyle {}
extension SkRectHeightStyleExtension on SkRectHeightStyle {
external double get value;
}
final List<SkRectHeightStyle> _skRectHeightStyles = <SkRectHeightStyle>[
canvasKit.RectHeightStyle.Tight,
canvasKit.RectHeightStyle.Max,
canvasKit.RectHeightStyle.IncludeLineSpacingMiddle,
canvasKit.RectHeightStyle.IncludeLineSpacingTop,
canvasKit.RectHeightStyle.IncludeLineSpacingBottom,
canvasKit.RectHeightStyle.Strut,
];
SkRectHeightStyle toSkRectHeightStyle(ui.BoxHeightStyle style) {
return _skRectHeightStyles[style.index];
}
@JS()
@staticInterop
class SkRectWidthStyleEnum {}
extension SkRectWidthStyleEnumExtension on SkRectWidthStyleEnum {
external SkRectWidthStyle get Tight;
external SkRectWidthStyle get Max;
}
@JS()
@staticInterop
class SkRectWidthStyle {}
extension SkRectWidthStyleExtension on SkRectWidthStyle {
external double get value;
}
final List<SkRectWidthStyle> _skRectWidthStyles = <SkRectWidthStyle>[
canvasKit.RectWidthStyle.Tight,
canvasKit.RectWidthStyle.Max,
];
SkRectWidthStyle toSkRectWidthStyle(ui.BoxWidthStyle style) {
final int index = style.index;
return _skRectWidthStyles[index < 2 ? index : 0];
}
@JS()
@staticInterop
class SkVertexModeEnum {}
extension SkVertexModeEnumExtension on SkVertexModeEnum {
external SkVertexMode get Triangles;
external SkVertexMode get TrianglesStrip;
external SkVertexMode get TriangleFan;
}
@JS()
@staticInterop
class SkVertexMode {}
extension SkVertexModeExtension on SkVertexMode {
external double get value;
}
final List<SkVertexMode> _skVertexModes = <SkVertexMode>[
canvasKit.VertexMode.Triangles,
canvasKit.VertexMode.TrianglesStrip,
canvasKit.VertexMode.TriangleFan,
];
SkVertexMode toSkVertexMode(ui.VertexMode mode) {
return _skVertexModes[mode.index];
}
@JS()
@staticInterop
class SkPointModeEnum {}
extension SkPointModeEnumExtension on SkPointModeEnum {
external SkPointMode get Points;
external SkPointMode get Lines;
external SkPointMode get Polygon;
}
@JS()
@staticInterop
class SkPointMode {}
extension SkPointModeExtension on SkPointMode {
external double get value;
}
final List<SkPointMode> _skPointModes = <SkPointMode>[
canvasKit.PointMode.Points,
canvasKit.PointMode.Lines,
canvasKit.PointMode.Polygon,
];
SkPointMode toSkPointMode(ui.PointMode mode) {
return _skPointModes[mode.index];
}
@JS()
@staticInterop
class SkClipOpEnum {}
extension SkClipOpEnumExtension on SkClipOpEnum {
external SkClipOp get Difference;
external SkClipOp get Intersect;
}
@JS()
@staticInterop
class SkClipOp {}
extension SkClipOpExtension on SkClipOp {
external double get value;
}
final List<SkClipOp> _skClipOps = <SkClipOp>[
canvasKit.ClipOp.Difference,
canvasKit.ClipOp.Intersect,
];
SkClipOp toSkClipOp(ui.ClipOp clipOp) {
return _skClipOps[clipOp.index];
}
@JS()
@staticInterop
class SkFillTypeEnum {}
extension SkFillTypeEnumExtension on SkFillTypeEnum {
external SkFillType get Winding;
external SkFillType get EvenOdd;
}
@JS()
@staticInterop
class SkFillType {}
extension SkFillTypeExtension on SkFillType {
external double get value;
}
final List<SkFillType> _skFillTypes = <SkFillType>[
canvasKit.FillType.Winding,
canvasKit.FillType.EvenOdd,
];
SkFillType toSkFillType(ui.PathFillType fillType) {
return _skFillTypes[fillType.index];
}
@JS()
@staticInterop
class SkPathOpEnum {}
extension SkPathOpEnumExtension on SkPathOpEnum {
external SkPathOp get Difference;
external SkPathOp get Intersect;
external SkPathOp get Union;
external SkPathOp get XOR;
external SkPathOp get ReverseDifference;
}
@JS()
@staticInterop
class SkPathOp {}
extension SkPathOpExtension on SkPathOp {
external double get value;
}
final List<SkPathOp> _skPathOps = <SkPathOp>[
canvasKit.PathOp.Difference,
canvasKit.PathOp.Intersect,
canvasKit.PathOp.Union,
canvasKit.PathOp.XOR,
canvasKit.PathOp.ReverseDifference,
];
SkPathOp toSkPathOp(ui.PathOperation pathOp) {
return _skPathOps[pathOp.index];
}
@JS()
@staticInterop
class SkBlurStyleEnum {}
extension SkBlurStyleEnumExtension on SkBlurStyleEnum {
external SkBlurStyle get Normal;
external SkBlurStyle get Solid;
external SkBlurStyle get Outer;
external SkBlurStyle get Inner;
}
@JS()
@staticInterop
class SkBlurStyle {}
extension SkBlurStyleExtension on SkBlurStyle {
external double get value;
}
final List<SkBlurStyle> _skBlurStyles = <SkBlurStyle>[
canvasKit.BlurStyle.Normal,
canvasKit.BlurStyle.Solid,
canvasKit.BlurStyle.Outer,
canvasKit.BlurStyle.Inner,
];
SkBlurStyle toSkBlurStyle(ui.BlurStyle style) {
return _skBlurStyles[style.index];
}
@JS()
@staticInterop
class SkStrokeCapEnum {}
extension SkStrokeCapEnumExtension on SkStrokeCapEnum {
external SkStrokeCap get Butt;
external SkStrokeCap get Round;
external SkStrokeCap get Square;
}
@JS()
@staticInterop
class SkStrokeCap {}
extension SkStrokeCapExtension on SkStrokeCap {
external double get value;
}
final List<SkStrokeCap> _skStrokeCaps = <SkStrokeCap>[
canvasKit.StrokeCap.Butt,
canvasKit.StrokeCap.Round,
canvasKit.StrokeCap.Square,
];
SkStrokeCap toSkStrokeCap(ui.StrokeCap strokeCap) {
return _skStrokeCaps[strokeCap.index];
}
@JS()
@staticInterop
class SkPaintStyleEnum {}
extension SkPaintStyleEnumExtension on SkPaintStyleEnum {
external SkPaintStyle get Stroke;
external SkPaintStyle get Fill;
}
@JS()
@staticInterop
class SkPaintStyle {}
extension SkPaintStyleExtension on SkPaintStyle {
external double get value;
}
final List<SkPaintStyle> _skPaintStyles = <SkPaintStyle>[
canvasKit.PaintStyle.Fill,
canvasKit.PaintStyle.Stroke,
];
SkPaintStyle toSkPaintStyle(ui.PaintingStyle paintStyle) {
return _skPaintStyles[paintStyle.index];
}
@JS()
@staticInterop
class SkBlendModeEnum {}
extension SkBlendModeEnumExtension on SkBlendModeEnum {
external SkBlendMode get Clear;
external SkBlendMode get Src;
external SkBlendMode get Dst;
external SkBlendMode get SrcOver;
external SkBlendMode get DstOver;
external SkBlendMode get SrcIn;
external SkBlendMode get DstIn;
external SkBlendMode get SrcOut;
external SkBlendMode get DstOut;
external SkBlendMode get SrcATop;
external SkBlendMode get DstATop;
external SkBlendMode get Xor;
external SkBlendMode get Plus;
external SkBlendMode get Modulate;
external SkBlendMode get Screen;
external SkBlendMode get Overlay;
external SkBlendMode get Darken;
external SkBlendMode get Lighten;
external SkBlendMode get ColorDodge;
external SkBlendMode get ColorBurn;
external SkBlendMode get HardLight;
external SkBlendMode get SoftLight;
external SkBlendMode get Difference;
external SkBlendMode get Exclusion;
external SkBlendMode get Multiply;
external SkBlendMode get Hue;
external SkBlendMode get Saturation;
external SkBlendMode get Color;
external SkBlendMode get Luminosity;
}
@JS()
@staticInterop
class SkBlendMode {}
extension SkBlendModeExtension on SkBlendMode {
external double get value;
}
final List<SkBlendMode> _skBlendModes = <SkBlendMode>[
canvasKit.BlendMode.Clear,
canvasKit.BlendMode.Src,
canvasKit.BlendMode.Dst,
canvasKit.BlendMode.SrcOver,
canvasKit.BlendMode.DstOver,
canvasKit.BlendMode.SrcIn,
canvasKit.BlendMode.DstIn,
canvasKit.BlendMode.SrcOut,
canvasKit.BlendMode.DstOut,
canvasKit.BlendMode.SrcATop,
canvasKit.BlendMode.DstATop,
canvasKit.BlendMode.Xor,
canvasKit.BlendMode.Plus,
canvasKit.BlendMode.Modulate,
canvasKit.BlendMode.Screen,
canvasKit.BlendMode.Overlay,
canvasKit.BlendMode.Darken,
canvasKit.BlendMode.Lighten,
canvasKit.BlendMode.ColorDodge,
canvasKit.BlendMode.ColorBurn,
canvasKit.BlendMode.HardLight,
canvasKit.BlendMode.SoftLight,
canvasKit.BlendMode.Difference,
canvasKit.BlendMode.Exclusion,
canvasKit.BlendMode.Multiply,
canvasKit.BlendMode.Hue,
canvasKit.BlendMode.Saturation,
canvasKit.BlendMode.Color,
canvasKit.BlendMode.Luminosity,
];
SkBlendMode toSkBlendMode(ui.BlendMode blendMode) {
return _skBlendModes[blendMode.index];
}
@JS()
@staticInterop
class SkStrokeJoinEnum {}
extension SkStrokeJoinEnumExtension on SkStrokeJoinEnum {
external SkStrokeJoin get Miter;
external SkStrokeJoin get Round;
external SkStrokeJoin get Bevel;
}
@JS()
@staticInterop
class SkStrokeJoin {}
extension SkStrokeJoinExtension on SkStrokeJoin {
external double get value;
}
final List<SkStrokeJoin> _skStrokeJoins = <SkStrokeJoin>[
canvasKit.StrokeJoin.Miter,
canvasKit.StrokeJoin.Round,
canvasKit.StrokeJoin.Bevel,
];
SkStrokeJoin toSkStrokeJoin(ui.StrokeJoin strokeJoin) {
return _skStrokeJoins[strokeJoin.index];
}
@JS()
@staticInterop
class SkTileModeEnum {}
extension SkTileModeEnumExtension on SkTileModeEnum {
external SkTileMode get Clamp;
external SkTileMode get Repeat;
external SkTileMode get Mirror;
external SkTileMode get Decal;
}
@JS()
@staticInterop
class SkTileMode {}
extension SkTileModeExtension on SkTileMode {
external double get value;
}
final List<SkTileMode> _skTileModes = <SkTileMode>[
canvasKit.TileMode.Clamp,
canvasKit.TileMode.Repeat,
canvasKit.TileMode.Mirror,
canvasKit.TileMode.Decal,
];
SkTileMode toSkTileMode(ui.TileMode mode) {
return _skTileModes[mode.index];
}
@JS()
@staticInterop
class SkFilterModeEnum {}
extension SkFilterModeEnumExtension on SkFilterModeEnum {
external SkFilterMode get Nearest;
external SkFilterMode get Linear;
}
@JS()
@staticInterop
class SkFilterMode {}
extension SkFilterModeExtension on SkFilterMode {
external double get value;
}
SkFilterMode toSkFilterMode(ui.FilterQuality filterQuality) {
return filterQuality == ui.FilterQuality.none
? canvasKit.FilterMode.Nearest
: canvasKit.FilterMode.Linear;
}
@JS()
@staticInterop
class SkMipmapModeEnum {}
extension SkMipmapModeEnumExtension on SkMipmapModeEnum {
external SkMipmapMode get None;
external SkMipmapMode get Nearest;
external SkMipmapMode get Linear;
}
@JS()
@staticInterop
class SkMipmapMode {}
extension SkMipmapModeExtension on SkMipmapMode {
external double get value;
}
SkMipmapMode toSkMipmapMode(ui.FilterQuality filterQuality) {
return filterQuality == ui.FilterQuality.medium
? canvasKit.MipmapMode.Linear
: canvasKit.MipmapMode.None;
}
@JS()
@staticInterop
class SkAlphaTypeEnum {}
extension SkAlphaTypeEnumExtension on SkAlphaTypeEnum {
external SkAlphaType get Opaque;
external SkAlphaType get Premul;
external SkAlphaType get Unpremul;
}
@JS()
@staticInterop
class SkAlphaType {}
extension SkAlphaTypeExtension on SkAlphaType {
external double get value;
}
@JS()
@staticInterop
class SkColorTypeEnum {}
extension SkColorTypeEnumExtension on SkColorTypeEnum {
external SkColorType get Alpha_8;
external SkColorType get RGB_565;
external SkColorType get ARGB_4444;
external SkColorType get RGBA_8888;
external SkColorType get RGB_888x;
external SkColorType get BGRA_8888;
external SkColorType get RGBA_1010102;
external SkColorType get RGB_101010x;
external SkColorType get Gray_8;
external SkColorType get RGBA_F16;
external SkColorType get RGBA_F32;
}
@JS()
@staticInterop
class SkColorType {}
extension SkColorTypeExtension on SkColorType {
external double get value;
}
@JS()
@anonymous
@staticInterop
class SkAnimatedImage {}
extension SkAnimatedImageExtension on SkAnimatedImage {
external double getFrameCount();
external double getRepetitionCount();
/// Returns duration in milliseconds.
external double currentFrameDuration();
/// Advances to the next frame and returns its duration in milliseconds.
external double decodeNextFrame();
external SkImage makeImageAtCurrentFrame();
external double width();
external double height();
/// Deletes the C++ object.
///
/// This object is no longer usable after calling this method.
external void delete();
external bool isDeleted();
}
@JS()
@anonymous
@staticInterop
class SkImage {}
extension SkImageExtension on SkImage {
external void delete();
external double width();
external double height();
external SkShader makeShaderCubic(
SkTileMode tileModeX,
SkTileMode tileModeY,
double B,
double C,
Float32List? matrix, // 3x3 matrix
);
external SkShader makeShaderOptions(
SkTileMode tileModeX,
SkTileMode tileModeY,
SkFilterMode filterMode,
SkMipmapMode mipmapMode,
Float32List? matrix, // 3x3 matrix
);
external Uint8List readPixels(double srcX, double srcY, SkImageInfo imageInfo);
external Uint8List? encodeToBytes();
external bool isAliasOf(SkImage other);
external bool isDeleted();
}
@JS()
@staticInterop
class SkShaderNamespace {}
extension SkShaderNamespaceExtension on SkShaderNamespace {
external SkShader MakeLinearGradient(
Float32List from, // 2-element array
Float32List to, // 2-element array
Uint32List colors,
Float32List colorStops,
SkTileMode tileMode,
Float32List? matrix,
);
external SkShader MakeRadialGradient(
Float32List center, // 2-element array