@shopify/react-native-skia 2.4.6 → 2.4.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (143) hide show
  1. package/android/cpp/jni/JniPlatformContext.cpp +1 -1
  2. package/android/src/main/java/com/shopify/reactnative/skia/ViewScreenshotService.java +11 -1
  3. package/apple/RNSkApplePlatformContext.h +4 -0
  4. package/apple/RNSkApplePlatformContext.mm +69 -0
  5. package/apple/SkiaCVPixelBufferUtils.mm +8 -4
  6. package/cpp/api/JsiSkFontMgr.h +30 -6
  7. package/cpp/api/JsiSkImageFilterFactory.h +4 -2
  8. package/cpp/api/JsiSkPictureFactory.h +9 -6
  9. package/cpp/api/recorder/RNRecorder.h +33 -55
  10. package/cpp/rnskia/RNSkPictureView.h +7 -5
  11. package/cpp/rnskia/RNSkPlatformContext.h +16 -0
  12. package/cpp/skia/include/codec/SkAndroidCodec.h +3 -2
  13. package/cpp/skia/include/codec/SkAvifDecoder.h +2 -2
  14. package/cpp/skia/include/codec/SkBmpDecoder.h +1 -1
  15. package/cpp/skia/include/codec/SkCodec.h +2 -8
  16. package/cpp/skia/include/codec/SkEncodedOrigin.h +17 -0
  17. package/cpp/skia/include/codec/SkGifDecoder.h +1 -1
  18. package/cpp/skia/include/codec/SkIcoDecoder.h +1 -1
  19. package/cpp/skia/include/codec/SkJpegDecoder.h +8 -1
  20. package/cpp/skia/include/codec/SkJpegxlDecoder.h +1 -1
  21. package/cpp/skia/include/codec/SkPngDecoder.h +8 -1
  22. package/cpp/skia/include/codec/SkRawDecoder.h +1 -1
  23. package/cpp/skia/include/codec/SkWbmpDecoder.h +1 -1
  24. package/cpp/skia/include/codec/SkWebpDecoder.h +8 -1
  25. package/cpp/skia/include/core/SkCPURecorder.h +1 -0
  26. package/cpp/skia/include/core/SkCanvas.h +3 -2
  27. package/cpp/skia/include/core/SkColorTable.h +1 -1
  28. package/cpp/skia/include/core/SkColorType.h +4 -0
  29. package/cpp/skia/include/core/SkDocument.h +1 -1
  30. package/cpp/skia/include/core/SkGraphics.h +7 -2
  31. package/cpp/skia/include/core/SkImage.h +5 -1
  32. package/cpp/skia/include/core/SkImageGenerator.h +5 -3
  33. package/cpp/skia/include/core/SkM44.h +3 -3
  34. package/cpp/skia/include/core/SkMatrix.h +0 -23
  35. package/cpp/skia/include/core/SkMilestone.h +1 -1
  36. package/cpp/skia/include/core/SkOverdrawCanvas.h +1 -1
  37. package/cpp/skia/include/core/SkPath.h +216 -185
  38. package/cpp/skia/include/core/SkPathBuilder.h +97 -47
  39. package/cpp/skia/include/core/SkPathTypes.h +7 -1
  40. package/cpp/skia/include/core/SkPixmap.h +8 -8
  41. package/cpp/skia/include/core/SkRRect.h +24 -3
  42. package/cpp/skia/include/core/SkRecorder.h +3 -1
  43. package/cpp/skia/include/core/SkScalar.h +1 -1
  44. package/cpp/skia/include/core/SkSerialProcs.h +8 -4
  45. package/cpp/skia/include/core/SkStream.h +16 -9
  46. package/cpp/skia/include/core/SkString.h +1 -1
  47. package/cpp/skia/include/core/SkStrokeRec.h +1 -1
  48. package/cpp/skia/include/core/SkYUVAInfo.h +3 -0
  49. package/cpp/skia/include/docs/SkPDFDocument.h +1 -1
  50. package/cpp/skia/include/docs/SkPDFJpegHelpers.h +1 -1
  51. package/cpp/skia/include/docs/SkXPSDocument.h +18 -2
  52. package/cpp/skia/include/effects/SkRuntimeEffect.h +3 -1
  53. package/cpp/skia/include/encode/SkPngRustEncoder.h +18 -0
  54. package/cpp/skia/include/gpu/ganesh/GrBackendSurface.h +1 -1
  55. package/cpp/skia/include/gpu/ganesh/GrExternalTextureGenerator.h +1 -1
  56. package/cpp/skia/include/gpu/ganesh/GrRecordingContext.h +7 -6
  57. package/cpp/skia/include/gpu/ganesh/gl/GrGLBackendSurface.h +6 -0
  58. package/cpp/skia/include/gpu/ganesh/vk/GrBackendDrawableInfo.h +2 -4
  59. package/cpp/skia/include/gpu/graphite/Context.h +15 -1
  60. package/cpp/skia/include/gpu/graphite/ContextOptions.h +52 -11
  61. package/cpp/skia/include/gpu/graphite/GraphiteTypes.h +44 -0
  62. package/cpp/skia/include/gpu/graphite/LogPriority.h +1 -1
  63. package/cpp/skia/include/gpu/graphite/PersistentPipelineStorage.h +45 -0
  64. package/cpp/skia/include/gpu/graphite/PrecompileContext.h +1 -1
  65. package/cpp/skia/include/gpu/graphite/Recorder.h +14 -0
  66. package/cpp/skia/include/gpu/graphite/TextureInfo.h +13 -5
  67. package/cpp/skia/include/gpu/graphite/dawn/DawnGraphiteTypes.h +1 -4
  68. package/cpp/skia/include/gpu/graphite/mtl/MtlGraphiteTypes.h +1 -4
  69. package/cpp/skia/include/gpu/graphite/vk/VulkanGraphiteTypes.h +2 -8
  70. package/cpp/skia/include/gpu/vk/VulkanExtensions.h +1 -1
  71. package/cpp/skia/include/gpu/vk/VulkanTypes.h +124 -9
  72. package/cpp/skia/include/ports/SkFontMgr_fuchsia.h +3 -1
  73. package/cpp/skia/include/ports/SkImageGeneratorCG.h +1 -1
  74. package/cpp/skia/include/ports/SkImageGeneratorNDK.h +1 -1
  75. package/cpp/skia/include/ports/SkImageGeneratorWIC.h +1 -1
  76. package/cpp/skia/include/ports/SkTypeface_fontations.h +1 -1
  77. package/cpp/skia/include/private/SkEncodedInfo.h +38 -29
  78. package/cpp/skia/include/private/SkJpegMetadataDecoder.h +18 -13
  79. package/cpp/skia/include/private/SkPathRef.h +3 -6
  80. package/cpp/skia/include/private/base/SkAlign.h +3 -7
  81. package/cpp/skia/include/private/base/SkContainers.h +1 -1
  82. package/cpp/skia/include/private/base/SkSpan_impl.h +29 -0
  83. package/cpp/skia/include/private/base/SkTArray.h +7 -8
  84. package/cpp/skia/include/private/base/SkTDArray.h +4 -4
  85. package/cpp/skia/include/private/base/SkTemplates.h +5 -5
  86. package/cpp/skia/include/private/chromium/GrDeferredDisplayListRecorder.h +1 -1
  87. package/cpp/skia/include/private/gpu/ganesh/GrContext_Base.h +1 -1
  88. package/cpp/skia/include/private/gpu/ganesh/GrImageContext.h +1 -1
  89. package/cpp/skia/include/private/gpu/ganesh/GrTypesPriv.h +6 -5
  90. package/cpp/skia/include/svg/SkSVGCanvas.h +21 -1
  91. package/cpp/skia/include/utils/SkNoDrawCanvas.h +1 -1
  92. package/cpp/skia/include/utils/SkPaintFilterCanvas.h +1 -1
  93. package/cpp/skia/modules/skcms/src/skcms_public.h +29 -4
  94. package/cpp/skia/modules/skottie/include/Skottie.h +11 -0
  95. package/cpp/skia/modules/skottie/include/SlotManager.h +1 -1
  96. package/cpp/skia/modules/skparagraph/include/Metrics.h +1 -1
  97. package/cpp/skia/modules/skparagraph/include/Paragraph.h +1 -1
  98. package/cpp/skia/modules/sksg/include/SkSGMerge.h +1 -1
  99. package/cpp/skia/modules/sksg/include/SkSGPath.h +1 -1
  100. package/cpp/skia/modules/skshaper/include/SkShaper.h +2 -0
  101. package/cpp/skia/modules/skunicode/include/SkUnicode.h +4 -4
  102. package/cpp/skia/modules/svg/include/SkSVGAttributeParser.h +1 -1
  103. package/cpp/skia/modules/svg/include/SkSVGFeComponentTransfer.h +1 -1
  104. package/cpp/skia/modules/svg/include/SkSVGNode.h +1 -1
  105. package/cpp/skia/modules/svg/include/SkSVGPoly.h +1 -1
  106. package/cpp/skia/modules/svg/include/SkSVGShape.h +1 -1
  107. package/cpp/skia/modules/svg/include/SkSVGTransformableNode.h +1 -1
  108. package/cpp/skia/modules/svg/include/SkSVGValue.h +1 -1
  109. package/lib/commonjs/skia/core/Font.js +7 -1
  110. package/lib/commonjs/skia/core/Font.js.map +1 -1
  111. package/lib/commonjs/skia/web/JsiSkCanvas.d.ts +1 -1
  112. package/lib/commonjs/skia/web/JsiSkCanvas.js +1 -7
  113. package/lib/commonjs/skia/web/JsiSkCanvas.js.map +1 -1
  114. package/lib/commonjs/specs/SkiaPictureViewNativeComponent.web.d.ts +1 -1
  115. package/lib/commonjs/views/SkiaPictureView.web.d.ts +4 -1
  116. package/lib/commonjs/views/SkiaPictureView.web.js +7 -2
  117. package/lib/commonjs/views/SkiaPictureView.web.js.map +1 -1
  118. package/lib/module/skia/core/Font.js +7 -1
  119. package/lib/module/skia/core/Font.js.map +1 -1
  120. package/lib/module/skia/web/JsiSkCanvas.d.ts +1 -1
  121. package/lib/module/skia/web/JsiSkCanvas.js +1 -7
  122. package/lib/module/skia/web/JsiSkCanvas.js.map +1 -1
  123. package/lib/module/specs/SkiaPictureViewNativeComponent.web.d.ts +1 -1
  124. package/lib/module/views/SkiaPictureView.web.d.ts +4 -1
  125. package/lib/module/views/SkiaPictureView.web.js +7 -3
  126. package/lib/module/views/SkiaPictureView.web.js.map +1 -1
  127. package/lib/typescript/lib/commonjs/skia/core/Font.d.ts +1 -1
  128. package/lib/typescript/lib/commonjs/skia/web/JsiSkCanvas.d.ts +1 -1
  129. package/lib/typescript/lib/commonjs/specs/SkiaPictureViewNativeComponent.web.d.ts +1 -11
  130. package/lib/typescript/lib/commonjs/views/SkiaPictureView.web.d.ts +1 -1
  131. package/lib/typescript/lib/module/mock/index.d.ts +1 -1
  132. package/lib/typescript/lib/module/skia/core/Font.d.ts +1 -1
  133. package/lib/typescript/lib/module/skia/web/JsiSkCanvas.d.ts +1 -1
  134. package/lib/typescript/lib/module/specs/SkiaPictureViewNativeComponent.web.d.ts +1 -1
  135. package/lib/typescript/lib/module/views/SkiaPictureView.web.d.ts +1 -1
  136. package/lib/typescript/src/skia/web/JsiSkCanvas.d.ts +1 -1
  137. package/lib/typescript/src/specs/SkiaPictureViewNativeComponent.web.d.ts +1 -1
  138. package/lib/typescript/src/views/SkiaPictureView.web.d.ts +4 -1
  139. package/package.json +8 -8
  140. package/scripts/install-skia.mjs +74 -1
  141. package/src/skia/core/Font.ts +9 -4
  142. package/src/skia/web/JsiSkCanvas.ts +1 -3
  143. package/src/views/SkiaPictureView.web.tsx +8 -7
@@ -28,15 +28,33 @@
28
28
  #include <tuple>
29
29
 
30
30
  class SkData;
31
- class SkPathRef;
32
31
  class SkRRect;
33
32
  class SkWStream;
34
33
  enum class SkPathConvexity;
34
+ enum class SkResolveConvexity;
35
35
  struct SkPathRaw;
36
36
  struct SkPathVerbAnalysis;
37
+ struct SkPathOvalInfo;
38
+ struct SkPathRRectInfo;
37
39
 
38
40
  // WIP -- define this locally, and fix call-sites to use SkPathBuilder (skbug.com/40040287)
41
+ #ifndef SK_HIDE_PATH_EDIT_METHODS
39
42
  //#define SK_HIDE_PATH_EDIT_METHODS
43
+ #endif
44
+
45
+ // Migrate clients so this is unneeded
46
+ #define SK_LEGACY_PATH_ACCESSORS
47
+
48
+ #ifdef SK_HIDE_PATH_EDIT_METHODS
49
+ // enable this to try using SkPathData
50
+ #define SK_PATH_USES_PATHDATA
51
+ #endif
52
+
53
+ #ifdef SK_PATH_USES_PATHDATA
54
+ class SkPathData;
55
+ #else
56
+ class SkPathRef;
57
+ #endif
40
58
 
41
59
  /** \class SkPath
42
60
  SkPath contain geometry. SkPath may be empty, or contain one or more verbs that
@@ -82,8 +100,12 @@ public:
82
100
  SkSpan<const SkScalar> conics,
83
101
  SkPathFillType, bool isVolatile = false);
84
102
 
85
- static SkPath Rect(const SkRect&, SkPathDirection = SkPathDirection::kDefault,
103
+ static SkPath Rect(const SkRect&, SkPathFillType, SkPathDirection = SkPathDirection::kDefault,
86
104
  unsigned startIndex = 0);
105
+ static SkPath Rect(const SkRect& r, SkPathDirection direction = SkPathDirection::kDefault,
106
+ unsigned startIndex = 0) {
107
+ return Rect(r, SkPathFillType::kDefault, direction, startIndex);
108
+ }
87
109
  static SkPath Oval(const SkRect&, SkPathDirection = SkPathDirection::kDefault);
88
110
  static SkPath Oval(const SkRect&, SkPathDirection, unsigned startIndex);
89
111
  static SkPath Circle(SkScalar center_x, SkScalar center_y, SkScalar radius,
@@ -97,8 +119,8 @@ public:
97
119
  SkPathFillType fillType = SkPathFillType::kDefault,
98
120
  bool isVolatile = false);
99
121
 
100
- static SkPath Line(const SkPoint a, const SkPoint b) {
101
- return Polygon({a, b}, false);
122
+ static SkPath Line(SkPoint a, SkPoint b) {
123
+ return Polygon({{a, b}}, false);
102
124
  }
103
125
 
104
126
  // Deprecated: use Raw()
@@ -111,14 +133,15 @@ public:
111
133
  conics, fillType, isVolatile);
112
134
  }
113
135
 
114
- /** Constructs an empty SkPath. By default, SkPath has no verbs, no SkPoint, and no weights.
115
- FillType is set to kWinding.
136
+ /** Constructs an empty SkPath: no verbs, no points, no conic weights.
116
137
 
117
138
  @return empty SkPath
118
139
 
119
140
  example: https://fiddle.skia.org/c/@Path_empty_constructor
120
141
  */
121
- SkPath();
142
+ explicit SkPath(SkPathFillType);
143
+
144
+ SkPath() : SkPath(SkPathFillType::kDefault) {}
122
145
 
123
146
  /** Constructs a copy of an existing path.
124
147
  Copy constructor makes two paths identical by value. Internally, path and
@@ -183,6 +206,9 @@ public:
183
206
  return !(a == b);
184
207
  }
185
208
 
209
+ // Note: These 3 interpolate() methods no long use any private access/info,
210
+ // and could trivially be implemented directly by the client.
211
+
186
212
  /** Returns true if SkPath contain equal verbs and equal weights.
187
213
  If SkPath contain one or more conics, the weights must match.
188
214
 
@@ -219,6 +245,29 @@ public:
219
245
  */
220
246
  SkPath makeInterpolate(const SkPath& ending, SkScalar weight) const;
221
247
 
248
+ /** Interpolates between SkPath with SkPoint array of equal size.
249
+ Copy verb array and weights to out, and set out SkPoint array to a weighted
250
+ average of this SkPoint array and ending SkPoint array, using the formula:
251
+ (Path Point * weight) + ending Point * (1 - weight).
252
+
253
+ weight is most useful when between zero (ending SkPoint array) and
254
+ one (this Point_Array); will work with values outside of this
255
+ range.
256
+
257
+ interpolate() returns false and leaves out unchanged if SkPoint array is not
258
+ the same size as ending SkPoint array. Call isInterpolatable() to check SkPath
259
+ compatibility prior to calling interpolate().
260
+
261
+ @param ending SkPoint array averaged with this SkPoint array
262
+ @param weight contribution of this SkPoint array, and
263
+ one minus contribution of ending SkPoint array
264
+ @param out SkPath replaced by interpolated averages
265
+ @return true if SkPath contain same number of SkPoint
266
+
267
+ example: https://fiddle.skia.org/c/@Path_interpolate
268
+ */
269
+ bool interpolate(const SkPath& ending, SkScalar weight, SkPath* out) const;
270
+
222
271
  /** Returns SkPathFillType, the rule used to fill SkPath.
223
272
 
224
273
  @return current SkPathFillType setting
@@ -387,48 +436,53 @@ public:
387
436
  */
388
437
  bool isLine(SkPoint line[2]) const;
389
438
 
390
- /** Returns the number of points in SkPath.
391
- SkPoint count is initially zero.
439
+ /*
440
+ * Return a read-only view into the path's points.
441
+ */
442
+ SkSpan<const SkPoint> points() const;
392
443
 
393
- @return SkPath SkPoint array length
444
+ /*
445
+ * Return a read-only view into the path's verbs.
446
+ */
447
+ SkSpan<const SkPathVerb> verbs() const;
448
+
449
+ /*
450
+ * Return a read-only view into the path's conic-weights.
451
+ */
452
+ SkSpan<const float> conicWeights() const;
453
+
454
+ int countPoints() const { return SkToInt(this->points().size()); }
455
+ int countVerbs() const { return SkToInt(this->verbs().size()); }
394
456
 
395
- example: https://fiddle.skia.org/c/@Path_countPoints
457
+ /** Return the last point, or {}
458
+
459
+ @return The last if the path contains one or more SkPoint, else returns {}
460
+
461
+ example: https://fiddle.skia.org/c/@Path_getLastPt
396
462
  */
397
- int countPoints() const;
463
+ std::optional<SkPoint> getLastPt() const;
398
464
 
465
+ #ifdef SK_LEGACY_PATH_ACCESSORS
399
466
  /** Returns SkPoint at index in SkPoint array. Valid range for index is
400
467
  0 to countPoints() - 1.
401
468
  Returns (0, 0) if index is out of range.
402
-
469
+ DEPRECATED
403
470
  @param index SkPoint array element selector
404
471
  @return SkPoint array value or (0, 0)
405
-
406
- example: https://fiddle.skia.org/c/@Path_getPoint
407
472
  */
408
473
  SkPoint getPoint(int index) const;
409
474
 
410
475
  /** Returns number of points in SkPath.
411
476
  Copies N points from the path into the span, where N = min(#points, span capacity)
412
-
477
+ DEPRECATED
413
478
  @param points span to receive the points. may be empty
414
479
  @return the number of points in the path
415
-
416
- example: https://fiddle.skia.org/c/@Path_getPoints
417
480
  */
418
481
  size_t getPoints(SkSpan<SkPoint> points) const;
419
482
 
420
- /** Returns the number of verbs: kMove_Verb, kLine_Verb, kQuad_Verb, kConic_Verb,
421
- kCubic_Verb, and kClose_Verb; added to SkPath.
422
-
423
- @return length of verb array
424
-
425
- example: https://fiddle.skia.org/c/@Path_countVerbs
426
- */
427
- int countVerbs() const;
428
-
429
483
  /** Returns number of points in SkPath.
430
484
  Copies N points from the path into the span, where N = min(#points, span capacity)
431
-
485
+ DEPRECATED
432
486
  @param verbs span to store the verbs. may be empty.
433
487
  @return the number of verbs in the path
434
488
 
@@ -436,6 +490,21 @@ public:
436
490
  */
437
491
  size_t getVerbs(SkSpan<uint8_t> verbs) const;
438
492
 
493
+ // DEPRECATED
494
+ bool getLastPt(SkPoint* lastPt) const {
495
+ if (auto lp = this->getLastPt()) {
496
+ if (lastPt) {
497
+ *lastPt = *lp;
498
+ }
499
+ return true;
500
+ }
501
+ if (lastPt) {
502
+ *lastPt = {0, 0};
503
+ }
504
+ return false;
505
+ }
506
+ #endif
507
+
439
508
  /** Returns the approximate byte size of the SkPath in memory.
440
509
 
441
510
  @return approximate size
@@ -571,66 +640,49 @@ public:
571
640
  kExtend_AddPathMode,
572
641
  };
573
642
 
574
- /** Returns SkPath with SkPoint array offset by (dx, dy).
575
-
576
- @param dx offset added to SkPoint array x-axis coordinates
577
- @param dy offset added to SkPoint array y-axis coordinates
578
- */
579
- SkPath makeOffset(SkScalar dx, SkScalar dy) const {
580
- SkPath dst;
581
- this->offset(dx, dy, &dst);
582
- return dst;
583
- }
584
-
585
643
  /** Return a copy of SkPath with verb array, SkPoint array, and weight transformed
586
644
  by matrix. makeTransform may change verbs and increase their number.
587
645
 
646
+ If the resulting path has any non-finite values, returns {}.
647
+
588
648
  @param matrix SkMatrix to apply to SkPath
589
- @param pc whether to apply perspective clipping
590
- @return SkPath
649
+ @return SkPath if finite, or {}
591
650
  */
592
- SkPath makeTransform(const SkMatrix& matrix) const {
593
- SkPath dst;
594
- this->transform(matrix, &dst);
595
- return dst;
596
- }
651
+ std::optional<SkPath> tryMakeTransform(const SkMatrix& matrix) const;
597
652
 
598
- SkPath makeScale(SkScalar sx, SkScalar sy) const {
599
- return this->makeTransform(SkMatrix::Scale(sx, sy));
653
+ std::optional<SkPath> tryMakeOffset(float dx, float dy) const {
654
+ return this->tryMakeTransform(SkMatrix::Translate(dx, dy));
600
655
  }
601
656
 
602
- #ifdef SK_SUPPORT_LEGACY_APPLYPERSPECTIVECLIP
603
- void transform(const SkMatrix& matrix, SkPath* dst, SkApplyPerspectiveClip) const {
604
- this->transform(matrix, dst);
605
- }
606
- void transform(const SkMatrix& matrix, SkApplyPerspectiveClip) {
607
- this->transform(matrix);
608
- }
609
- SkPath makeTransform(const SkMatrix& m, SkApplyPerspectiveClip) const {
610
- return this->makeTransform(m);
657
+ std::optional<SkPath> tryMakeScale(float sx, float sy) const {
658
+ return this->tryMakeTransform(SkMatrix::Scale(sx, sy));
611
659
  }
612
- #endif
613
660
 
614
- /** Return the last point, or {}
661
+ /** Return a copy of SkPath with verb array, SkPoint array, and weight transformed
662
+ by matrix. makeTransform may change verbs and increase their number.
615
663
 
616
- @return The last if the path contains one or more SkPoint, else returns {}
664
+ If the resulting path has any non-finite values, this will still return a path
665
+ but that path will return true for isFinite().
617
666
 
618
- example: https://fiddle.skia.org/c/@Path_getLastPt
667
+ The newer pattern is to call tryMakeTransform(matrix) which will only return a
668
+ path if the result is finite.
669
+
670
+ @param matrix SkMatrix to apply to SkPath
671
+ @return SkPath
619
672
  */
620
- std::optional<SkPoint> getLastPt() const;
673
+ SkPath makeTransform(const SkMatrix& matrix) const;
621
674
 
622
- // DEPRECATED
623
- bool getLastPt(SkPoint* lastPt) const {
624
- if (auto lp = this->getLastPt()) {
625
- if (lastPt) {
626
- *lastPt = *lp;
627
- }
628
- return true;
629
- }
630
- if (lastPt) {
631
- *lastPt = {0, 0};
632
- }
633
- return false;
675
+ /** Returns SkPath with SkPoint array offset by (dx, dy).
676
+
677
+ @param dx offset added to SkPoint array x-axis coordinates
678
+ @param dy offset added to SkPoint array y-axis coordinates
679
+ */
680
+ SkPath makeOffset(SkScalar dx, SkScalar dy) const {
681
+ return this->makeTransform(SkMatrix::Translate(dx, dy));
682
+ }
683
+
684
+ SkPath makeScale(SkScalar sx, SkScalar sy) const {
685
+ return this->makeTransform(SkMatrix::Scale(sx, sy));
634
686
  }
635
687
 
636
688
  /** \enum SkPath::SegmentMask
@@ -703,51 +755,18 @@ public:
703
755
  */
704
756
  void swap(SkPath& other);
705
757
 
706
- /** Interpolates between SkPath with SkPoint array of equal size.
707
- Copy verb array and weights to out, and set out SkPoint array to a weighted
708
- average of this SkPoint array and ending SkPoint array, using the formula:
709
- (Path Point * weight) + ending Point * (1 - weight).
710
-
711
- weight is most useful when between zero (ending SkPoint array) and
712
- one (this Point_Array); will work with values outside of this
713
- range.
714
-
715
- interpolate() returns false and leaves out unchanged if SkPoint array is not
716
- the same size as ending SkPoint array. Call isInterpolatable() to check SkPath
717
- compatibility prior to calling interpolate().
718
-
719
- @param ending SkPoint array averaged with this SkPoint array
720
- @param weight contribution of this SkPoint array, and
721
- one minus contribution of ending SkPoint array
722
- @param out SkPath replaced by interpolated averages
723
- @return true if SkPath contain same number of SkPoint
724
-
725
- example: https://fiddle.skia.org/c/@Path_interpolate
726
- */
727
- bool interpolate(const SkPath& ending, SkScalar weight, SkPath* out) const;
728
-
729
758
  /** Sets SkPathFillType, the rule used to fill SkPath. While there is no
730
759
  check that ft is legal, values outside of SkPathFillType are not supported.
731
760
  */
732
761
  void setFillType(SkPathFillType ft) {
733
- fFillType = SkToU8(ft);
762
+ fFillType = ft;
734
763
  }
735
764
 
736
765
  /** Replaces SkPathFillType with its inverse. The inverse of SkPathFillType describes the area
737
766
  unmodified by the original SkPathFillType.
738
767
  */
739
768
  void toggleInverseFillType() {
740
- fFillType ^= 2;
741
- }
742
-
743
- #ifdef SK_HIDE_PATH_EDIT_METHODS
744
- private:
745
- #endif
746
- /** Returns a copy of this path in the current state, and resets the path to empty. */
747
- SkPath detach() {
748
- SkPath result = *this;
749
- this->reset();
750
- return result;
769
+ fFillType = SkPathFillType_ToggleInverse(fFillType);
751
770
  }
752
771
 
753
772
  /** Sets SkPath to its initial state.
@@ -760,6 +779,14 @@ private:
760
779
  */
761
780
  SkPath& reset();
762
781
 
782
+ #ifndef SK_HIDE_PATH_EDIT_METHODS
783
+ /** Returns a copy of this path in the current state, and resets the path to empty. */
784
+ SkPath detach() {
785
+ SkPath result = *this;
786
+ this->reset();
787
+ return result;
788
+ }
789
+
763
790
  /** Sets SkPath to its initial state, preserving internal storage.
764
791
  Removes verb array, SkPoint array, and weights, and sets FillType to kWinding.
765
792
  Internal storage associated with SkPath is retained.
@@ -1113,7 +1140,7 @@ private:
1113
1140
  @param radius distance from arc to circle center
1114
1141
  @return reference to SkPath
1115
1142
  */
1116
- SkPath& arcTo(const SkPoint p1, const SkPoint p2, SkScalar radius) {
1143
+ SkPath& arcTo(SkPoint p1, SkPoint p2, SkScalar radius) {
1117
1144
  return this->arcTo(p1.fX, p1.fY, p2.fX, p2.fY, radius);
1118
1145
  }
1119
1146
 
@@ -1167,8 +1194,11 @@ private:
1167
1194
  @param xy end of arc
1168
1195
  @return reference to SkPath
1169
1196
  */
1170
- SkPath& arcTo(const SkPoint r, SkScalar xAxisRotate, ArcSize largeArc, SkPathDirection sweep,
1171
- const SkPoint xy) {
1197
+ SkPath& arcTo(SkPoint r,
1198
+ SkScalar xAxisRotate,
1199
+ ArcSize largeArc,
1200
+ SkPathDirection sweep,
1201
+ const SkPoint xy) {
1172
1202
  return this->arcTo(r.fX, r.fY, xAxisRotate, largeArc, sweep, xy.fX, xy.fY);
1173
1203
  }
1174
1204
 
@@ -1445,6 +1475,31 @@ private:
1445
1475
  */
1446
1476
  SkPath& reverseAddPath(const SkPath& src);
1447
1477
 
1478
+ /** Sets last point to (x, y). If SkPoint array is empty, append kMove_Verb to
1479
+ verb array and append (x, y) to SkPoint array.
1480
+
1481
+ @param x set x-axis value of last point
1482
+ @param y set y-axis value of last point
1483
+
1484
+ example: https://fiddle.skia.org/c/@Path_setLastPt
1485
+ */
1486
+ void setLastPt(SkScalar x, SkScalar y);
1487
+
1488
+ /** Sets the last point on the path. If SkPoint array is empty, append kMove_Verb to
1489
+ verb array and append p to SkPoint array.
1490
+
1491
+ @param p set value of last point
1492
+ */
1493
+ void setLastPt(const SkPoint& p) {
1494
+ this->setLastPt(p.fX, p.fY);
1495
+ }
1496
+ #endif
1497
+
1498
+ #ifdef SK_HIDE_PATH_EDIT_METHODS
1499
+ private:
1500
+ #endif
1501
+
1502
+ #ifndef SK_PATH_USES_PATHDATA
1448
1503
  /** Offsets SkPoint array by (dx, dy). Offset SkPath replaces dst.
1449
1504
  If dst is nullptr, SkPath is replaced by offset data.
1450
1505
 
@@ -1490,29 +1545,12 @@ private:
1490
1545
  this->transform(matrix, this);
1491
1546
  return *this;
1492
1547
  }
1493
-
1494
- /** Sets last point to (x, y). If SkPoint array is empty, append kMove_Verb to
1495
- verb array and append (x, y) to SkPoint array.
1496
-
1497
- @param x set x-axis value of last point
1498
- @param y set y-axis value of last point
1499
-
1500
- example: https://fiddle.skia.org/c/@Path_setLastPt
1501
- */
1502
- void setLastPt(SkScalar x, SkScalar y);
1503
-
1504
- /** Sets the last point on the path. If SkPoint array is empty, append kMove_Verb to
1505
- verb array and append p to SkPoint array.
1506
-
1507
- @param p set value of last point
1508
- */
1509
- void setLastPt(const SkPoint& p) {
1510
- this->setLastPt(p.fX, p.fY);
1511
- }
1548
+ #endif
1512
1549
 
1513
1550
  #ifdef SK_HIDE_PATH_EDIT_METHODS
1514
1551
  public:
1515
1552
  #endif
1553
+
1516
1554
  #ifdef SK_SUPPORT_UNSPANNED_APIS
1517
1555
  static SkPath Make(const SkPoint points[], int pointCount,
1518
1556
  const uint8_t verbs[], int verbCount,
@@ -1534,6 +1572,7 @@ public:
1534
1572
  int getVerbs(uint8_t verbs[], int max) const {
1535
1573
  return (int)this->getVerbs({verbs, max});
1536
1574
  }
1575
+ #ifndef SK_HIDE_PATH_EDIT_METHODS
1537
1576
  SkPath& addRoundRect(const SkRect& rect, const SkScalar radii[],
1538
1577
  SkPathDirection dir = SkPathDirection::kCW) {
1539
1578
  return this->addRoundRect(rect, {radii, radii ? 8 : 0}, dir);
@@ -1541,7 +1580,8 @@ public:
1541
1580
  SkPath& addPoly(const SkPoint pts[], int count, bool close) {
1542
1581
  return this->addPoly({pts, count}, close);
1543
1582
  }
1544
- #endif
1583
+ #endif // SK_HIDE_PATH_EDIT_METHODS
1584
+ #endif // SK_SUPPORT_UNSPANNED_APIS
1545
1585
 
1546
1586
  SkPathIter iter() const;
1547
1587
 
@@ -1657,6 +1697,10 @@ public:
1657
1697
  };
1658
1698
 
1659
1699
  private:
1700
+ std::optional<SkPathOvalInfo> getOvalInfo() const;
1701
+ std::optional<SkPathRRectInfo> getRRectInfo() const;
1702
+ std::optional<SkPathRaw> raw(SkResolveConvexity) const;
1703
+
1660
1704
  /** \class SkPath::RangeIter
1661
1705
  Iterates through a raw range of path verbs, points, and conics. All values are returned
1662
1706
  unaltered.
@@ -1798,16 +1842,18 @@ public:
1798
1842
 
1799
1843
  };
1800
1844
 
1801
- /** Returns true if the point (x, y) is contained by SkPath, taking into
1845
+ /** Returns true if the point is contained by SkPath, taking into
1802
1846
  account FillType.
1803
1847
 
1804
- @param x x-axis value of containment test
1805
- @param y y-axis value of containment test
1806
- @return true if SkPoint is in SkPath
1807
-
1808
- example: https://fiddle.skia.org/c/@Path_contains
1848
+ @param point the point to test
1849
+ @return true if SkPoint is in SkPath
1809
1850
  */
1810
- bool contains(SkScalar x, SkScalar y) const;
1851
+ bool contains(SkPoint point) const;
1852
+
1853
+ // deprecated
1854
+ bool contains(SkScalar x, SkScalar y) const {
1855
+ return this->contains({x, y});
1856
+ }
1811
1857
 
1812
1858
  /** Writes text representation of SkPath to stream. If stream is nullptr, writes to
1813
1859
  standard output. Set dumpAsHex true to generate exact binary representations
@@ -1823,10 +1869,6 @@ public:
1823
1869
  void dump() const { this->dump(nullptr, false); }
1824
1870
  void dumpHex() const { this->dump(nullptr, true); }
1825
1871
 
1826
- // Like dump(), but outputs for the SkPath::Make() factory
1827
- void dumpArrays(SkWStream* stream, bool dumpAsHex) const;
1828
- void dumpArrays() const { this->dumpArrays(nullptr, false); }
1829
-
1830
1872
  /** Writes SkPath to buffer, returning the number of bytes written.
1831
1873
  Pass nullptr to obtain the storage size.
1832
1874
 
@@ -1906,13 +1948,23 @@ public:
1906
1948
  using sk_is_trivially_relocatable = std::true_type;
1907
1949
 
1908
1950
  private:
1951
+ #ifdef SK_PATH_USES_PATHDATA
1952
+ static SkPath MakeNullCheck(sk_sp<SkPathData>, SkPathFillType, bool isVolatile);
1953
+ static SkPathData* PeekErrorSingleton();
1954
+
1955
+ SkPath(sk_sp<SkPathData>, SkPathFillType, bool isVolatile);
1956
+
1957
+ sk_sp<SkPathData> fPathData;
1958
+ SkPathFillType fFillType;
1959
+ bool fIsVolatile;
1960
+ #else
1909
1961
  SkPath(sk_sp<SkPathRef>, SkPathFillType, bool isVolatile, SkPathConvexity);
1910
1962
 
1911
- sk_sp<SkPathRef> fPathRef;
1912
- int fLastMoveToIndex;
1913
- mutable std::atomic<uint8_t> fConvexity; // SkPathConvexity
1914
- uint8_t fFillType : 2;
1915
- uint8_t fIsVolatile : 1;
1963
+ sk_sp<SkPathRef> fPathRef;
1964
+ int fLastMoveToIndex;
1965
+ mutable std::atomic<uint8_t> fConvexity; // SkPathConvexity
1966
+ SkPathFillType fFillType;
1967
+ bool fIsVolatile;
1916
1968
 
1917
1969
  static_assert(::sk_is_trivially_relocatable<decltype(fPathRef)>::value);
1918
1970
 
@@ -1927,6 +1979,16 @@ private:
1927
1979
  */
1928
1980
  void copyFields(const SkPath& that);
1929
1981
 
1982
+ // Creates a new Path after the supplied arguments have been validated by
1983
+ // SkPathPriv::AnalyzeVerbs().
1984
+ static SkPath MakeInternal(const SkPathVerbAnalysis&,
1985
+ const SkPoint[],
1986
+ SkSpan<const SkPathVerb>,
1987
+ const float conics[],
1988
+ SkPathFillType,
1989
+ bool isVolatile);
1990
+ #endif
1991
+
1930
1992
  size_t writeToMemoryAsRRect(void* buffer) const;
1931
1993
  size_t readAsRRect(const void*, size_t);
1932
1994
 
@@ -1946,9 +2008,11 @@ private:
1946
2008
  // SkPath path; path.lineTo(...); <--- need a leading moveTo(0, 0)
1947
2009
  // SkPath path; ... path.close(); path.lineTo(...) <-- need a moveTo(previous moveTo)
1948
2010
  //
1949
- inline void injectMoveToIfNeeded();
2011
+ void injectMoveToIfNeeded();
1950
2012
 
1951
- inline bool hasOnlyMoveTos() const;
2013
+ bool hasOnlyMoveTos() const {
2014
+ return this->getSegmentMasks() == 0;
2015
+ }
1952
2016
 
1953
2017
  SkPathConvexity computeConvexity() const;
1954
2018
 
@@ -1976,10 +2040,6 @@ private:
1976
2040
 
1977
2041
  SkPath& dirtyAfterEdit();
1978
2042
 
1979
- // Bottlenecks for working with fConvexity and fFirstDirection.
1980
- // Notice the setters are const... these are mutable atomic fields.
1981
- void setConvexity(SkPathConvexity) const;
1982
-
1983
2043
  void addRaw(const SkPathRaw&);
1984
2044
 
1985
2045
  /** Returns the comvexity type, computing if needed. Never returns kUnknown.
@@ -1989,44 +2049,15 @@ private:
1989
2049
 
1990
2050
  SkPathConvexity getConvexityOrUnknown() const;
1991
2051
 
1992
- // Compares the cached value with a freshly computed one (computeConvexity())
1993
- bool isConvexityAccurate() const;
1994
-
1995
2052
  /** Stores a convexity type for this path. This is what will be returned if
1996
2053
  * getConvexityOrUnknown() is called. If you pass kUnknown, then if getContexityType()
1997
2054
  * is called, the real convexity will be computed.
1998
- *
1999
- * example: https://fiddle.skia.org/c/@Path_setConvexity
2000
- */
2001
- void setConvexity(SkPathConvexity convexity);
2002
-
2003
- /** Shrinks SkPath verb array and SkPoint array storage to discard unused capacity.
2004
- * May reduce the heap overhead for SkPath known to be fully constructed.
2005
- *
2006
- * NOTE: This may relocate the underlying buffers, and thus any Iterators referencing
2007
- * this path should be discarded after calling shrinkToFit().
2008
2055
  */
2009
- void shrinkToFit();
2010
-
2011
- // Creates a new Path after the supplied arguments have been validated by
2012
- // SkPathPriv::AnalyzeVerbs().
2013
- static SkPath MakeInternal(const SkPathVerbAnalysis& analsis,
2014
- const SkPoint points[],
2015
- SkSpan<const SkPathVerb> verbs,
2016
- const SkScalar conics[],
2017
- SkPathFillType fillType,
2018
- bool isVolatile);
2056
+ void setConvexity(SkPathConvexity) const;
2019
2057
 
2020
- friend class SkAutoAddSimpleShape;
2021
- friend class SkAutoDisableOvalCheck;
2058
+ friend class SkAutoAddSimpleShape; // setConvexity
2022
2059
  friend class SkPathBuilder;
2023
- friend class SkPathEdgeIter;
2024
- friend class SkPathWriter;
2025
- friend class SkOpBuilder;
2026
- friend class SkBench_AddPathTest; // perf test reversePathTo
2027
2060
  friend class PathTest_Private; // unit test reversePathTo
2028
- friend class ForceIsRRect_Private; // unit test isRRect
2029
- friend class FuzzPath; // for legacy access to validateRef
2030
2061
  };
2031
2062
 
2032
2063
  #endif