@shopify/react-native-skia 2.4.7 → 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 (117) 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/RNSkPlatformContext.h +16 -0
  11. package/cpp/skia/include/codec/SkAndroidCodec.h +3 -2
  12. package/cpp/skia/include/codec/SkAvifDecoder.h +2 -2
  13. package/cpp/skia/include/codec/SkBmpDecoder.h +1 -1
  14. package/cpp/skia/include/codec/SkCodec.h +2 -8
  15. package/cpp/skia/include/codec/SkEncodedOrigin.h +17 -0
  16. package/cpp/skia/include/codec/SkGifDecoder.h +1 -1
  17. package/cpp/skia/include/codec/SkIcoDecoder.h +1 -1
  18. package/cpp/skia/include/codec/SkJpegDecoder.h +8 -1
  19. package/cpp/skia/include/codec/SkJpegxlDecoder.h +1 -1
  20. package/cpp/skia/include/codec/SkPngDecoder.h +8 -1
  21. package/cpp/skia/include/codec/SkRawDecoder.h +1 -1
  22. package/cpp/skia/include/codec/SkWbmpDecoder.h +1 -1
  23. package/cpp/skia/include/codec/SkWebpDecoder.h +8 -1
  24. package/cpp/skia/include/core/SkCPURecorder.h +1 -0
  25. package/cpp/skia/include/core/SkCanvas.h +3 -2
  26. package/cpp/skia/include/core/SkColorTable.h +1 -1
  27. package/cpp/skia/include/core/SkColorType.h +4 -0
  28. package/cpp/skia/include/core/SkDocument.h +1 -1
  29. package/cpp/skia/include/core/SkGraphics.h +7 -2
  30. package/cpp/skia/include/core/SkImage.h +5 -1
  31. package/cpp/skia/include/core/SkImageGenerator.h +5 -3
  32. package/cpp/skia/include/core/SkM44.h +3 -3
  33. package/cpp/skia/include/core/SkMatrix.h +0 -23
  34. package/cpp/skia/include/core/SkMilestone.h +1 -1
  35. package/cpp/skia/include/core/SkOverdrawCanvas.h +1 -1
  36. package/cpp/skia/include/core/SkPath.h +216 -185
  37. package/cpp/skia/include/core/SkPathBuilder.h +97 -47
  38. package/cpp/skia/include/core/SkPathTypes.h +7 -1
  39. package/cpp/skia/include/core/SkPixmap.h +8 -8
  40. package/cpp/skia/include/core/SkRRect.h +24 -3
  41. package/cpp/skia/include/core/SkRecorder.h +3 -1
  42. package/cpp/skia/include/core/SkScalar.h +1 -1
  43. package/cpp/skia/include/core/SkSerialProcs.h +8 -4
  44. package/cpp/skia/include/core/SkStream.h +16 -9
  45. package/cpp/skia/include/core/SkString.h +1 -1
  46. package/cpp/skia/include/core/SkStrokeRec.h +1 -1
  47. package/cpp/skia/include/core/SkYUVAInfo.h +3 -0
  48. package/cpp/skia/include/docs/SkPDFDocument.h +1 -1
  49. package/cpp/skia/include/docs/SkPDFJpegHelpers.h +1 -1
  50. package/cpp/skia/include/docs/SkXPSDocument.h +18 -2
  51. package/cpp/skia/include/effects/SkRuntimeEffect.h +3 -1
  52. package/cpp/skia/include/encode/SkPngRustEncoder.h +18 -0
  53. package/cpp/skia/include/gpu/ganesh/GrBackendSurface.h +1 -1
  54. package/cpp/skia/include/gpu/ganesh/GrExternalTextureGenerator.h +1 -1
  55. package/cpp/skia/include/gpu/ganesh/GrRecordingContext.h +7 -6
  56. package/cpp/skia/include/gpu/ganesh/gl/GrGLBackendSurface.h +6 -0
  57. package/cpp/skia/include/gpu/ganesh/vk/GrBackendDrawableInfo.h +2 -4
  58. package/cpp/skia/include/gpu/graphite/Context.h +15 -1
  59. package/cpp/skia/include/gpu/graphite/ContextOptions.h +52 -11
  60. package/cpp/skia/include/gpu/graphite/GraphiteTypes.h +44 -0
  61. package/cpp/skia/include/gpu/graphite/LogPriority.h +1 -1
  62. package/cpp/skia/include/gpu/graphite/PersistentPipelineStorage.h +45 -0
  63. package/cpp/skia/include/gpu/graphite/PrecompileContext.h +1 -1
  64. package/cpp/skia/include/gpu/graphite/Recorder.h +14 -0
  65. package/cpp/skia/include/gpu/graphite/TextureInfo.h +13 -5
  66. package/cpp/skia/include/gpu/graphite/dawn/DawnGraphiteTypes.h +1 -4
  67. package/cpp/skia/include/gpu/graphite/mtl/MtlGraphiteTypes.h +1 -4
  68. package/cpp/skia/include/gpu/graphite/vk/VulkanGraphiteTypes.h +2 -8
  69. package/cpp/skia/include/gpu/vk/VulkanExtensions.h +1 -1
  70. package/cpp/skia/include/gpu/vk/VulkanTypes.h +124 -9
  71. package/cpp/skia/include/ports/SkFontMgr_fuchsia.h +3 -1
  72. package/cpp/skia/include/ports/SkImageGeneratorCG.h +1 -1
  73. package/cpp/skia/include/ports/SkImageGeneratorNDK.h +1 -1
  74. package/cpp/skia/include/ports/SkImageGeneratorWIC.h +1 -1
  75. package/cpp/skia/include/ports/SkTypeface_fontations.h +1 -1
  76. package/cpp/skia/include/private/SkEncodedInfo.h +38 -29
  77. package/cpp/skia/include/private/SkJpegMetadataDecoder.h +18 -13
  78. package/cpp/skia/include/private/SkPathRef.h +3 -6
  79. package/cpp/skia/include/private/base/SkAlign.h +3 -7
  80. package/cpp/skia/include/private/base/SkContainers.h +1 -1
  81. package/cpp/skia/include/private/base/SkSpan_impl.h +29 -0
  82. package/cpp/skia/include/private/base/SkTArray.h +7 -8
  83. package/cpp/skia/include/private/base/SkTDArray.h +4 -4
  84. package/cpp/skia/include/private/base/SkTemplates.h +5 -5
  85. package/cpp/skia/include/private/chromium/GrDeferredDisplayListRecorder.h +1 -1
  86. package/cpp/skia/include/private/gpu/ganesh/GrContext_Base.h +1 -1
  87. package/cpp/skia/include/private/gpu/ganesh/GrImageContext.h +1 -1
  88. package/cpp/skia/include/private/gpu/ganesh/GrTypesPriv.h +6 -5
  89. package/cpp/skia/include/svg/SkSVGCanvas.h +21 -1
  90. package/cpp/skia/include/utils/SkNoDrawCanvas.h +1 -1
  91. package/cpp/skia/include/utils/SkPaintFilterCanvas.h +1 -1
  92. package/cpp/skia/modules/skcms/src/skcms_public.h +29 -4
  93. package/cpp/skia/modules/skottie/include/Skottie.h +11 -0
  94. package/cpp/skia/modules/skottie/include/SlotManager.h +1 -1
  95. package/cpp/skia/modules/skparagraph/include/Metrics.h +1 -1
  96. package/cpp/skia/modules/skparagraph/include/Paragraph.h +1 -1
  97. package/cpp/skia/modules/sksg/include/SkSGMerge.h +1 -1
  98. package/cpp/skia/modules/sksg/include/SkSGPath.h +1 -1
  99. package/cpp/skia/modules/skshaper/include/SkShaper.h +2 -0
  100. package/cpp/skia/modules/skunicode/include/SkUnicode.h +4 -4
  101. package/cpp/skia/modules/svg/include/SkSVGAttributeParser.h +1 -1
  102. package/cpp/skia/modules/svg/include/SkSVGFeComponentTransfer.h +1 -1
  103. package/cpp/skia/modules/svg/include/SkSVGNode.h +1 -1
  104. package/cpp/skia/modules/svg/include/SkSVGPoly.h +1 -1
  105. package/cpp/skia/modules/svg/include/SkSVGShape.h +1 -1
  106. package/cpp/skia/modules/svg/include/SkSVGTransformableNode.h +1 -1
  107. package/cpp/skia/modules/svg/include/SkSVGValue.h +1 -1
  108. package/lib/commonjs/skia/core/Font.js +7 -1
  109. package/lib/commonjs/skia/core/Font.js.map +1 -1
  110. package/lib/module/skia/core/Font.js +7 -1
  111. package/lib/module/skia/core/Font.js.map +1 -1
  112. package/lib/typescript/lib/commonjs/skia/core/Font.d.ts +1 -1
  113. package/lib/typescript/lib/module/mock/index.d.ts +1 -1
  114. package/lib/typescript/lib/module/skia/core/Font.d.ts +1 -1
  115. package/package.json +8 -8
  116. package/scripts/install-skia.mjs +74 -1
  117. package/src/skia/core/Font.ts +9 -4
@@ -25,8 +25,10 @@
25
25
  #include <optional>
26
26
  #include <tuple>
27
27
 
28
+ class SkPathData;
28
29
  class SkRRect;
29
30
  struct SkPathRaw;
31
+ class SkString;
30
32
 
31
33
  class SK_API SkPathBuilder {
32
34
  public:
@@ -43,7 +45,7 @@ public:
43
45
  @param fillType SkPathFillType to set on the SkPathBuilder.
44
46
  @return empty SkPathBuilder
45
47
  */
46
- SkPathBuilder(SkPathFillType fillType);
48
+ explicit SkPathBuilder(SkPathFillType fillType);
47
49
 
48
50
  /** Constructs an SkPathBuilder that is a copy of an existing SkPath.
49
51
  Copies the FillType and replays all of the verbs from the SkPath into the SkPathBuilder.
@@ -51,7 +53,7 @@ public:
51
53
  @param path SkPath to copy
52
54
  @return SkPathBuilder
53
55
  */
54
- SkPathBuilder(const SkPath& path);
56
+ explicit SkPathBuilder(const SkPath& path);
55
57
 
56
58
  SkPathBuilder(const SkPathBuilder&) = default;
57
59
  ~SkPathBuilder();
@@ -63,9 +65,11 @@ public:
63
65
  @return SkPathBuilder
64
66
  */
65
67
  SkPathBuilder& operator=(const SkPath&);
66
-
67
68
  SkPathBuilder& operator=(const SkPathBuilder&) = default;
68
69
 
70
+ bool operator==(const SkPathBuilder&) const;
71
+ bool operator!=(const SkPathBuilder& o) const { return !(*this == o); }
72
+
69
73
  /** Returns SkPathFillType, the rule used to fill SkPath.
70
74
 
71
75
  @return current SkPathFillType setting
@@ -73,15 +77,32 @@ public:
73
77
  SkPathFillType fillType() const { return fFillType; }
74
78
 
75
79
  /** Returns minimum and maximum axes values of SkPoint array.
76
- Returns (0, 0, 0, 0) if SkPathBuilder contains no points. Returned bounds width and height
77
- may be larger or smaller than area affected when SkPath is drawn.
80
+ Returns (0, 0, 0, 0) if SkPathBuilder contains no points.
78
81
 
79
82
  SkRect returned includes all SkPoint added to SkPathBuilder, including SkPoint associated
80
83
  with kMove_Verb that define empty contours.
81
84
 
82
- @return bounds of all SkPoint in SkPoint array
85
+ If any of the points are non-finite, returns {}.
86
+
87
+ @return bounds of all SkPoint in SkPoint array, or {}.
83
88
  */
84
- SkRect computeBounds() const;
89
+ std::optional<SkRect> computeFiniteBounds() const {
90
+ return SkRect::Bounds(fPts);
91
+ }
92
+
93
+ /** Like computeFiniteBounds() but returns a 'tight' bounds, meaning when there are curve
94
+ * segments, this computes the X/Y limits of the curve itself, not the curve's control
95
+ * point(s). For a polygon, this returns the same as computeFiniteBounds().
96
+ */
97
+ std::optional<SkRect> computeTightBounds() const;
98
+
99
+ // DEPRECATED -- returns "empty" if the bounds are non-finite
100
+ SkRect computeBounds() const {
101
+ if (auto bounds = this->computeFiniteBounds()) {
102
+ return *bounds;
103
+ }
104
+ return SkRect::MakeEmpty();
105
+ }
85
106
 
86
107
  /** Returns an SkPath representing the current state of the SkPathBuilder. The builder is
87
108
  unchanged after returning the path.
@@ -99,6 +120,9 @@ public:
99
120
  */
100
121
  SkPath detach(const SkMatrix* mx = nullptr);
101
122
 
123
+ sk_sp<SkPathData> snapshotData() const;
124
+ sk_sp<SkPathData> detachData();
125
+
102
126
  /** Sets SkPathFillType, the rule used to fill SkPath. While there is no
103
127
  check that ft is legal, values outside of SkPathFillType are not supported.
104
128
 
@@ -127,7 +151,7 @@ public:
127
151
 
128
152
  /** Sets SkPathBuilder to its initial state.
129
153
  Removes verb array, SkPoint array, and weights, and sets FillType to kWinding.
130
- Internal storage associated with SkPathBuilder is released.
154
+ Internal storage associated with SkPathBuilder is preserved.
131
155
 
132
156
  @return reference to SkPathBuilder
133
157
  */
@@ -367,7 +391,20 @@ public:
367
391
 
368
392
  example: https://fiddle.skia.org/c/@Path_rMoveTo
369
393
  */
370
- SkPathBuilder& rMoveTo(SkPoint pt);
394
+ SkPathBuilder& rMoveTo(SkVector pt);
395
+
396
+ /** Adds beginning of contour relative to last point.
397
+ If SkPathBuilder is empty, starts contour at (dx, dy).
398
+ Otherwise, start contour at last point offset by (dx, dy).
399
+ Function name stands for "relative move to".
400
+
401
+ @param dx offset from last point to contour start on x-axis
402
+ @param dy offset from last point to contour start on y-axis
403
+ @return reference to SkPathBuilder
404
+
405
+ example: https://fiddle.skia.org/c/@Path_rMoveTo
406
+ */
407
+ SkPathBuilder& rMoveTo(SkScalar dx, SkScalar dy) { return this->rMoveTo({dx, dy}); }
371
408
 
372
409
  /** Adds line from last point to vector given by pt. If SkPathBuilder is empty, or last
373
410
  SkPath::Verb is kClose_Verb, last point is set to (0, 0) before adding line.
@@ -380,7 +417,7 @@ public:
380
417
  @param pt vector offset from last point to line end
381
418
  @return reference to SkPathBuilder
382
419
  */
383
- SkPathBuilder& rLineTo(SkPoint pt);
420
+ SkPathBuilder& rLineTo(SkVector pt);
384
421
 
385
422
  /** Adds line from last point to vector (dx, dy). If SkPathBuilder is empty, or last
386
423
  SkPath::Verb is kClose_Verb, last point is set to (0, 0) before adding line.
@@ -394,7 +431,7 @@ public:
394
431
  @param dy offset from last point to line end on y-axis
395
432
  @return reference to SkPathBuilder
396
433
  */
397
- SkPathBuilder& rLineTo(SkScalar x, SkScalar y) { return this->rLineTo({x, y}); }
434
+ SkPathBuilder& rLineTo(SkScalar dx, SkScalar dy) { return this->rLineTo({dx, dy}); }
398
435
 
399
436
  /** Adds quad from last point towards vector pt1, to vector pt2.
400
437
  If SkPathBuilder is empty, or last SkPath::Verb
@@ -411,7 +448,7 @@ public:
411
448
  @param pt2 offset vector from last point to quad end
412
449
  @return reference to SkPathBuilder
413
450
  */
414
- SkPathBuilder& rQuadTo(SkPoint pt1, SkPoint pt2);
451
+ SkPathBuilder& rQuadTo(SkVector pt1, SkVector pt2);
415
452
 
416
453
  /** Adds quad from last point towards vector (dx1, dy1), to vector (dx2, dy2).
417
454
  If SkPathBuilder is empty, or last SkPath::Verb
@@ -430,8 +467,8 @@ public:
430
467
  @param dy2 offset from last point to quad end on y-axis
431
468
  @return reference to SkPathBuilder
432
469
  */
433
- SkPathBuilder& rQuadTo(SkScalar x1, SkScalar y1, SkScalar x2, SkScalar y2) {
434
- return this->rQuadTo({x1, y1}, {x2, y2});
470
+ SkPathBuilder& rQuadTo(SkScalar dx1, SkScalar dy1, SkScalar dx2, SkScalar dy2) {
471
+ return this->rQuadTo({dx1, dy1}, {dx2, dy2});
435
472
  }
436
473
 
437
474
  /** Adds conic from last point towards vector p1, to vector p2,
@@ -457,7 +494,7 @@ public:
457
494
  @param w weight of added conic
458
495
  @return reference to SkPathBuilder
459
496
  */
460
- SkPathBuilder& rConicTo(SkPoint p1, SkPoint p2, SkScalar w);
497
+ SkPathBuilder& rConicTo(SkVector p1, SkVector p2, SkScalar w);
461
498
 
462
499
  /** Adds conic from last point towards vector (dx1, dy1), to vector (dx2, dy2),
463
500
  weighted by w. If SkPathBuilder is empty, or last SkPath::Verb
@@ -484,8 +521,8 @@ public:
484
521
  @param w weight of added conic
485
522
  @return reference to SkPathBuilder
486
523
  */
487
- SkPathBuilder& rConicTo(SkScalar x1, SkScalar y1, SkScalar x2, SkScalar y2, SkScalar w) {
488
- return this->rConicTo({x1, y1}, {x2, y2}, w);
524
+ SkPathBuilder& rConicTo(SkScalar dx1, SkScalar dy1, SkScalar dx2, SkScalar dy2, SkScalar w) {
525
+ return this->rConicTo({dx1, dy1}, {dx2, dy2}, w);
489
526
  }
490
527
 
491
528
  /** Adds cubic from last point towards vector pt1, then towards
@@ -505,7 +542,7 @@ public:
505
542
  @param pt3 offset vector from last point to cubic end
506
543
  @return reference to SkPathBuilder
507
544
  */
508
- SkPathBuilder& rCubicTo(SkPoint pt1, SkPoint pt2, SkPoint pt3);
545
+ SkPathBuilder& rCubicTo(SkVector pt1, SkVector pt2, SkVector pt3);
509
546
 
510
547
  /** Adds cubic from last point towards vector (dx1, dy1), then towards
511
548
  vector (dx2, dy2), to vector (dx3, dy3).
@@ -527,10 +564,14 @@ public:
527
564
  @param dy3 offset from last point to cubic end on y-axis
528
565
  @return reference to SkPathBuilder
529
566
  */
530
- SkPathBuilder& rCubicTo(SkScalar x1, SkScalar y1, SkScalar x2, SkScalar y2, SkScalar x3, SkScalar y3) {
531
- return this->rCubicTo({x1, y1}, {x2, y2}, {x3, y3});
567
+ SkPathBuilder& rCubicTo(SkScalar dx1, SkScalar dy1,
568
+ SkScalar dx2, SkScalar dy2,
569
+ SkScalar dx3, SkScalar dy3) {
570
+ return this->rCubicTo({dx1, dy1}, {dx2, dy2}, {dx3, dy3});
532
571
  }
533
572
 
573
+ // Arcs
574
+
534
575
  enum ArcSize {
535
576
  kSmall_ArcSize, //!< smaller of arc pair
536
577
  kLarge_ArcSize, //!< larger of arc pair
@@ -553,19 +594,15 @@ public:
553
594
  opposite the integer value of sweep; SVG "sweep-flag" uses 1 for clockwise, while
554
595
  kCW_Direction cast to int is zero.
555
596
 
556
- @param rx radius before x-axis rotation
557
- @param ry radius before x-axis rotation
597
+ @param r radii on axes before x-axis rotation
558
598
  @param xAxisRotate x-axis rotation in degrees; positive values are clockwise
559
599
  @param largeArc chooses smaller or larger arc
560
600
  @param sweep chooses clockwise or counterclockwise arc
561
- @param dx x-axis offset end of arc from last SkPath SkPoint
562
- @param dy y-axis offset end of arc from last SkPath SkPoint
601
+ @param dxdy offset end of arc from last SkPath point
563
602
  @return reference to SkPath
564
603
  */
565
- SkPathBuilder& rArcTo(SkScalar rx, SkScalar ry, SkScalar xAxisRotate, ArcSize largeArc,
566
- SkPathDirection sweep, SkScalar dx, SkScalar dy);
567
-
568
- // Arcs
604
+ SkPathBuilder& rArcTo(SkPoint r, SkScalar xAxisRotate, ArcSize largeArc,
605
+ SkPathDirection sweep, SkVector dxdy);
569
606
 
570
607
  /** Appends arc to the builder. Arc added is part of ellipse
571
608
  bounded by oval, from startAngle through sweepAngle. Both startAngle and
@@ -805,9 +842,7 @@ public:
805
842
  */
806
843
  SkPathBuilder& addPath(const SkPath& src,
807
844
  SkPath::AddPathMode mode = SkPath::kAppend_AddPathMode) {
808
- SkMatrix m;
809
- m.reset();
810
- return this->addPath(src, m, mode);
845
+ return this->addPath(src, SkMatrix::I(), mode);
811
846
  }
812
847
 
813
848
  /** Appends src to SkPathBuilder, transformed by matrix. Transformed curves may have different
@@ -831,10 +866,11 @@ public:
831
866
  May improve performance and use less memory by
832
867
  reducing the number and size of allocations when creating SkPathBuilder.
833
868
 
834
- @param extraPtCount number of additional SkPoint to allocate
835
- @param extraVerbCount number of additional verbs
869
+ @param extraPtCount number of additional SkPoint to allocate
870
+ @param extraVerbCount number of additional verbs
871
+ @param extraConicCount number of additional conic weights
836
872
  */
837
- void incReserve(int extraPtCount, int extraVerbCount);
873
+ void incReserve(int extraPtCount, int extraVerbCount, int extraConicCount);
838
874
 
839
875
  /** Grows SkPathBuilder verb array and SkPoint array to contain additional space.
840
876
  May improve performance and use less memory by
@@ -843,7 +879,7 @@ public:
843
879
  @param extraPtCount number of additional SkPoints and verbs to allocate
844
880
  */
845
881
  void incReserve(int extraPtCount) {
846
- this->incReserve(extraPtCount, extraPtCount);
882
+ this->incReserve(extraPtCount, extraPtCount, 0);
847
883
  }
848
884
 
849
885
  /** Offsets SkPoint array by (dx, dy).
@@ -861,12 +897,6 @@ public:
861
897
  */
862
898
  SkPathBuilder& transform(const SkMatrix& matrix);
863
899
 
864
- #ifdef SK_SUPPORT_LEGACY_APPLYPERSPECTIVECLIP
865
- SkPathBuilder& transform(const SkMatrix& matrix, SkApplyPerspectiveClip) {
866
- return this->transform(matrix);
867
- }
868
- #endif
869
-
870
900
  /*
871
901
  * Returns true if the builder is empty, or all of its points are finite.
872
902
  */
@@ -876,7 +906,7 @@ public:
876
906
  unmodified by the original SkPathFillType.
877
907
  */
878
908
  SkPathBuilder& toggleInverseFillType() {
879
- fFillType = (SkPathFillType)((unsigned)fFillType ^ 2);
909
+ fFillType = SkPathFillType_ToggleInverse(fFillType);
880
910
  return *this;
881
911
  }
882
912
 
@@ -896,6 +926,14 @@ public:
896
926
  */
897
927
  std::optional<SkPoint> getLastPt() const;
898
928
 
929
+ /** Change the point at the specified index (see countPoints()).
930
+ * If index is out of range, the call does nothing.
931
+ *
932
+ * @param index which point to replace
933
+ * @param p the new point value
934
+ */
935
+ void setPoint(size_t index, SkPoint p);
936
+
899
937
  /** Sets the last point on the path. If SkPoint array is empty, append kMove_Verb to
900
938
  verb array and append p to SkPoint array.
901
939
 
@@ -941,6 +979,18 @@ public:
941
979
 
942
980
  SkPathIter iter() const;
943
981
 
982
+ enum class DumpFormat {
983
+ kDecimal,
984
+ kHex,
985
+ };
986
+ SkString dumpToString(DumpFormat = DumpFormat::kDecimal) const;
987
+ void dump(DumpFormat) const;
988
+ // can't use default argument easily in debugger, so we name this
989
+ // helper explicitly.
990
+ void dump() const { this->dump(DumpFormat::kDecimal); }
991
+
992
+ bool contains(SkPoint) const;
993
+
944
994
  private:
945
995
  SkPathRef::PointsArray fPts;
946
996
  SkPathRef::VerbsArray fVerbs;
@@ -951,9 +1001,7 @@ private:
951
1001
  SkPathConvexity fConvexity;
952
1002
 
953
1003
  unsigned fSegmentMask;
954
- SkPoint fLastMovePoint;
955
1004
  int fLastMoveIndex; // only needed until SkPath is immutable
956
- bool fNeedsMoveVerb;
957
1005
 
958
1006
  SkPathIsAType fType = SkPathIsAType::kGeneral;
959
1007
  SkPathIsAData fIsA {};
@@ -961,8 +1009,10 @@ private:
961
1009
  // called right before we add a (non-move) verb
962
1010
  void ensureMove() {
963
1011
  fType = SkPathIsAType::kGeneral;
964
- if (fNeedsMoveVerb) {
965
- this->moveTo(fLastMovePoint);
1012
+ if (fVerbs.empty()) {
1013
+ this->moveTo({0, 0});
1014
+ } else if (fVerbs.back() == SkPathVerb::kClose) {
1015
+ this->moveTo(fPts[fLastMoveIndex]);
966
1016
  }
967
1017
  }
968
1018
 
@@ -973,7 +1023,7 @@ private:
973
1023
  SkPathBuilder& privateReverseAddPath(const SkPath&);
974
1024
  SkPathBuilder& privateReversePathTo(const SkPath&);
975
1025
 
976
- std::tuple<SkPoint*, SkScalar*> growForVerbsInPath(const SkPathRef& path);
1026
+ std::tuple<SkPoint*, SkScalar*> growForVerbsInPath(const SkPath& path);
977
1027
 
978
1028
  friend class SkPathPriv;
979
1029
  friend class SkStroke;
@@ -33,6 +33,10 @@ static inline bool SkPathFillType_IsInverse(SkPathFillType ft) {
33
33
  return (static_cast<int>(ft) & 2) != 0;
34
34
  }
35
35
 
36
+ static inline SkPathFillType SkPathFillType_ToggleInverse(SkPathFillType ft) {
37
+ return static_cast<SkPathFillType>(static_cast<int>(ft) ^ 2);
38
+ }
39
+
36
40
  static inline SkPathFillType SkPathFillType_ConvertToNonInverse(SkPathFillType ft) {
37
41
  return static_cast<SkPathFillType>(static_cast<int>(ft) & 1);
38
42
  }
@@ -59,7 +63,9 @@ enum class SkPathVerb : uint8_t {
59
63
  kQuad, //!< SkPath::RawIter returns 3 points
60
64
  kConic, //!< SkPath::RawIter returns 3 points + 1 weight
61
65
  kCubic, //!< SkPath::RawIter returns 4 points
62
- kClose //!< SkPath::RawIter returns 0 points
66
+ kClose, //!< SkPath::RawIter returns 0 points
67
+
68
+ kLast_Verb = kClose,
63
69
  };
64
70
 
65
71
  #endif
@@ -396,8 +396,8 @@ public:
396
396
  @return readable unsigned 8-bit pointer to pixel at (x, y)
397
397
  */
398
398
  const uint8_t* addr8(int x, int y) const {
399
- SkASSERT((unsigned)x < (unsigned)fInfo.width());
400
- SkASSERT((unsigned)y < (unsigned)fInfo.height());
399
+ SkASSERTF(x >= 0 && x < this->width(), "x=%d; width=%d\n", x, fInfo.width());
400
+ SkASSERTF(y >= 0 && y < this->height(), "y=%d; height=%d\n", y, fInfo.height());
401
401
  return (const uint8_t*)((const char*)this->addr8() + (size_t)y * fRowBytes + (x << 0));
402
402
  }
403
403
 
@@ -414,8 +414,8 @@ public:
414
414
  @return readable unsigned 16-bit pointer to pixel at (x, y)
415
415
  */
416
416
  const uint16_t* addr16(int x, int y) const {
417
- SkASSERT((unsigned)x < (unsigned)fInfo.width());
418
- SkASSERT((unsigned)y < (unsigned)fInfo.height());
417
+ SkASSERTF(x >= 0 && x < this->width(), "x=%d; width=%d\n", x, fInfo.width());
418
+ SkASSERTF(y >= 0 && y < this->height(), "y=%d; height=%d\n", y, fInfo.height());
419
419
  return (const uint16_t*)((const char*)this->addr16() + (size_t)y * fRowBytes + (x << 1));
420
420
  }
421
421
 
@@ -432,8 +432,8 @@ public:
432
432
  @return readable unsigned 32-bit pointer to pixel at (x, y)
433
433
  */
434
434
  const uint32_t* addr32(int x, int y) const {
435
- SkASSERT((unsigned)x < (unsigned)fInfo.width());
436
- SkASSERT((unsigned)y < (unsigned)fInfo.height());
435
+ SkASSERTF(x >= 0 && x < this->width(), "x=%d; width=%d\n", x, fInfo.width());
436
+ SkASSERTF(y >= 0 && y < this->height(), "y=%d; height=%d\n", y, fInfo.height());
437
437
  return (const uint32_t*)((const char*)this->addr32() + (size_t)y * fRowBytes + (x << 2));
438
438
  }
439
439
 
@@ -450,8 +450,8 @@ public:
450
450
  @return readable unsigned 64-bit pointer to pixel at (x, y)
451
451
  */
452
452
  const uint64_t* addr64(int x, int y) const {
453
- SkASSERT((unsigned)x < (unsigned)fInfo.width());
454
- SkASSERT((unsigned)y < (unsigned)fInfo.height());
453
+ SkASSERTF(x >= 0 && x < this->width(), "x=%d; width=%d\n", x, fInfo.width());
454
+ SkASSERTF(y >= 0 && y < this->height(), "y=%d; height=%d\n", y, fInfo.height());
455
455
  return (const uint64_t*)((const char*)this->addr64() + (size_t)y * fRowBytes + (x << 3));
456
456
  }
457
457
 
@@ -156,7 +156,7 @@ public:
156
156
  return rr;
157
157
  }
158
158
 
159
- /** Sets bounds to oval, x-axis radii to half oval.width(), and all y-axis radii
159
+ /** Initializes to oval, x-axis radii to half oval.width(), and all y-axis radii
160
160
  to half oval.height(). If oval bounds is empty, sets to kEmpty_Type.
161
161
  Otherwise, sets to kOval_Type.
162
162
 
@@ -169,7 +169,7 @@ public:
169
169
  return rr;
170
170
  }
171
171
 
172
- /** Sets to rounded rectangle with the same radii for all four corners.
172
+ /** Initializes to rounded rectangle with the same radii for all four corners.
173
173
  If rect is empty, sets to kEmpty_Type.
174
174
  Otherwise, if xRad and yRad are zero, sets to kRect_Type.
175
175
  Otherwise, if xRad is at least half rect.width() and yRad is at least half
@@ -187,6 +187,27 @@ public:
187
187
  return rr;
188
188
  }
189
189
 
190
+ /** Initializes to rounded rectangle with a radii array for individual control
191
+ of all four corners.
192
+
193
+ If rect is empty, sets to kEmpty_Type.
194
+ Otherwise, if one of each corner radii are zero, sets to kRect_Type.
195
+ Otherwise, if all x-axis radii are equal and at least half rect.width(), and
196
+ all y-axis radii are equal at least half rect.height(), sets to kOval_Type.
197
+ Otherwise, if all x-axis radii are equal, and all y-axis radii are equal,
198
+ sets to kSimple_Type. Otherwise, sets to kNinePatch_Type.
199
+
200
+ @param rect bounds of rounded rectangle
201
+ @param radii corner x-axis and y-axis radii
202
+
203
+ example: https://fiddle.skia.org/c/@RRect_setRectRadii
204
+ */
205
+ static SkRRect MakeRectRadii(const SkRect& rect, const SkVector radii[4]) {
206
+ SkRRect rr;
207
+ rr.setRectRadii(rect, radii);
208
+ return rr;
209
+ }
210
+
190
211
  /** Sets bounds to oval, x-axis radii to half oval.width(), and all y-axis radii
191
212
  to half oval.height(). If oval bounds is empty, sets to kEmpty_Type.
192
213
  Otherwise, sets to kOval_Type.
@@ -233,7 +254,7 @@ public:
233
254
  void setNinePatch(const SkRect& rect, SkScalar leftRad, SkScalar topRad,
234
255
  SkScalar rightRad, SkScalar bottomRad);
235
256
 
236
- /** Sets bounds to rect. Sets radii array for individual control of all for corners.
257
+ /** Sets bounds to rect. Sets radii array for individual control of all four corners.
237
258
 
238
259
  If rect is empty, sets to kEmpty_Type.
239
260
  Otherwise, if one of each corner radii are zero, sets to kRect_Type.
@@ -10,6 +10,7 @@
10
10
  #include "include/private/base/SkAPI.h"
11
11
 
12
12
  class SkCanvas;
13
+ class SkSurface;
13
14
 
14
15
  namespace skcpu {
15
16
  class Recorder;
@@ -40,8 +41,9 @@ private:
40
41
  * Returns nullptr if capture is not enabled.
41
42
  */
42
43
  virtual SkCanvas* makeCaptureCanvas(SkCanvas*) = 0;
44
+ virtual void createCaptureBreakpoint(SkSurface*) = 0;
43
45
 
44
- friend class SkSurface_Base;
46
+ friend class SkSurface_Base; // for capture functionality
45
47
  };
46
48
 
47
49
  #endif
@@ -71,8 +71,8 @@ static inline SkScalar SkScalarFraction(SkScalar x) {
71
71
  static inline SkScalar SkScalarSquare(SkScalar x) { return x * x; }
72
72
 
73
73
  #define SkScalarInvert(x) (SK_Scalar1 / (x))
74
- #define SkScalarAve(a, b) (((a) + (b)) * SK_ScalarHalf)
75
74
  #define SkScalarHalf(a) ((a) * SK_ScalarHalf)
75
+ #define SkScalarAve(a, b) sk_float_midpoint(a, b)
76
76
 
77
77
  #define SkDegreesToRadians(degrees) ((degrees) * (SK_ScalarPI / 180))
78
78
  #define SkRadiansToDegrees(radians) ((radians) * (180 / SK_ScalarPI))
@@ -24,6 +24,11 @@ namespace sktext::gpu {
24
24
  class Slug;
25
25
  }
26
26
 
27
+ #if defined(SK_DISABLE_LEGACY_NONCONST_SERIAL_PROCS)
28
+ using SkSerialReturnType = sk_sp<const SkData>;
29
+ #else
30
+ using SkSerialReturnType = sk_sp<SkData>;
31
+ #endif
27
32
  /**
28
33
  * A serial-proc is asked to serialize the specified object (e.g. picture or image).
29
34
  * If a data object is returned, it will be used (even if it is zero-length).
@@ -33,10 +38,9 @@ namespace sktext::gpu {
33
38
  * The default action for images is to encode either in its native format or PNG.
34
39
  * The default action for typefaces is to use Skia's internal format.
35
40
  */
36
-
37
- using SkSerialPictureProc = sk_sp<SkData> (*)(SkPicture*, void* ctx);
38
- using SkSerialImageProc = sk_sp<SkData> (*)(SkImage*, void* ctx);
39
- using SkSerialTypefaceProc = sk_sp<SkData> (*)(SkTypeface*, void* ctx);
41
+ using SkSerialPictureProc = SkSerialReturnType (*)(SkPicture*, void* ctx);
42
+ using SkSerialImageProc = SkSerialReturnType (*)(SkImage*, void* ctx);
43
+ using SkSerialTypefaceProc = SkSerialReturnType (*)(SkTypeface*, void* ctx);
40
44
 
41
45
  /**
42
46
  * Called with the encoded form of a picture (previously written with a custom
@@ -20,6 +20,8 @@
20
20
  #include <cstring>
21
21
  #include <memory>
22
22
  #include <utility>
23
+ #include <vector>
24
+
23
25
  class SkStreamAsset;
24
26
 
25
27
  /**
@@ -141,7 +143,7 @@ public:
141
143
  //SkStreamMemory
142
144
  /** Returns the starting address for the data. If this cannot be done, returns NULL. */
143
145
  virtual const void* getMemoryBase() { return nullptr; }
144
- virtual sk_sp<SkData> getData() const { return nullptr; }
146
+ virtual sk_sp<const SkData> getData() const { return nullptr; }
145
147
 
146
148
  private:
147
149
  virtual SkStream* onDuplicate() const { return nullptr; }
@@ -363,18 +365,19 @@ private:
363
365
  using INHERITED = SkStreamAsset;
364
366
  };
365
367
 
368
+ // A read only view into a block of memory.
366
369
  class SK_API SkMemoryStream : public SkStreamMemory {
367
370
  public:
368
371
  SkMemoryStream();
369
372
 
370
373
  /** We allocate (and free) the memory. Write to it via getMemoryBase() */
371
- SkMemoryStream(size_t length);
374
+ explicit SkMemoryStream(size_t length);
372
375
 
373
376
  /** If copyData is true, the stream makes a private copy of the data. */
374
377
  SkMemoryStream(const void* data, size_t length, bool copyData = false);
375
378
 
376
379
  /** Creates the stream to read from the specified data */
377
- SkMemoryStream(sk_sp<SkData> data);
380
+ explicit SkMemoryStream(sk_sp<const SkData> data);
378
381
 
379
382
  /** Returns a stream with a copy of the input data. */
380
383
  static std::unique_ptr<SkMemoryStream> MakeCopy(const void* data, size_t length);
@@ -383,7 +386,7 @@ public:
383
386
  static std::unique_ptr<SkMemoryStream> MakeDirect(const void* data, size_t length);
384
387
 
385
388
  /** Returns a stream with a shared reference to the input data. */
386
- static std::unique_ptr<SkMemoryStream> Make(sk_sp<SkData> data);
389
+ static std::unique_ptr<SkMemoryStream> Make(sk_sp<const SkData> data);
387
390
 
388
391
  /** Resets the stream to the specified data and length,
389
392
  just like the constructor.
@@ -397,8 +400,9 @@ public:
397
400
  */
398
401
  void setMemoryOwned(const void* data, size_t length);
399
402
 
400
- sk_sp<SkData> getData() const override { return fData; }
401
- void setData(sk_sp<SkData> data);
403
+ sk_sp<const SkData> getData() const override { return fData; }
404
+
405
+ void setData(sk_sp<const SkData> data);
402
406
 
403
407
  const void* getAtPos();
404
408
 
@@ -429,8 +433,8 @@ private:
429
433
  SkMemoryStream* onDuplicate() const override;
430
434
  SkMemoryStream* onFork() const override;
431
435
 
432
- sk_sp<SkData> fData;
433
- size_t fOffset;
436
+ sk_sp<const SkData> fData;
437
+ size_t fOffset;
434
438
 
435
439
  using INHERITED = SkStreamMemory;
436
440
  };
@@ -439,7 +443,7 @@ private:
439
443
 
440
444
  class SK_API SkFILEWStream : public SkWStream {
441
445
  public:
442
- SkFILEWStream(const char path[]);
446
+ explicit SkFILEWStream(const char path[]);
443
447
  ~SkFILEWStream() override;
444
448
 
445
449
  /** Returns true if the current path could be opened.
@@ -489,6 +493,9 @@ public:
489
493
  /** Return the contents as SkData, and then reset the stream. */
490
494
  sk_sp<SkData> detachAsData();
491
495
 
496
+ /** Return the contents as vector, and then reset the stream. */
497
+ std::vector<uint8_t> detachAsVector();
498
+
492
499
  /** Reset, returning a reader stream with the current content. */
493
500
  std::unique_ptr<SkStreamAsset> detachAsStream();
494
501
 
@@ -237,7 +237,7 @@ public:
237
237
 
238
238
  SkString& operator+=(const SkString& s) { this->append(s); return *this; }
239
239
  SkString& operator+=(const char text[]) { this->append(text); return *this; }
240
- SkString& operator+=(const char c) { this->append(&c, 1); return *this; }
240
+ SkString& operator+=(char c) { this->append(&c, 1); return *this; }
241
241
 
242
242
  /**
243
243
  * Swap contents between this and other. This function is guaranteed
@@ -26,7 +26,7 @@ public:
26
26
  kHairline_InitStyle,
27
27
  kFill_InitStyle
28
28
  };
29
- SkStrokeRec(InitStyle style);
29
+ explicit SkStrokeRec(InitStyle style);
30
30
  SkStrokeRec(const SkPaint&, SkPaint::Style, SkScalar resScale = 1);
31
31
  explicit SkStrokeRec(const SkPaint&, SkScalar resScale = 1);
32
32
 
@@ -181,6 +181,9 @@ public:
181
181
  SkMatrix originMatrix() const {
182
182
  return SkEncodedOriginToMatrix(fOrigin, this->width(), this->height());
183
183
  }
184
+ SkMatrix inverseOriginMatrix() const {
185
+ return SkEncodedOriginToMatrixInverse(fOrigin, this->width(), this->height());
186
+ }
184
187
 
185
188
  bool hasAlpha() const { return HasAlpha(fPlaneConfig); }
186
189
 
@@ -83,7 +83,7 @@ struct DateTime {
83
83
  void toISO8601(SkString* dst) const;
84
84
  };
85
85
 
86
- using DecodeJpegCallback = std::unique_ptr<SkCodec> (*)(sk_sp<SkData>);
86
+ using DecodeJpegCallback = std::unique_ptr<SkCodec> (*)(sk_sp<const SkData>);
87
87
  using EncodeJpegCallback = bool (*)(SkWStream* dst, const SkPixmap& src, int quality);
88
88
 
89
89
  /** Optional metadata to be passed into the PDF factory function.
@@ -19,7 +19,7 @@ class SkWStream;
19
19
  #include <memory>
20
20
 
21
21
  namespace SkPDF::JPEG {
22
- inline std::unique_ptr<SkCodec> Decode(sk_sp<SkData> data) {
22
+ inline std::unique_ptr<SkCodec> Decode(sk_sp<const SkData> data) {
23
23
  return SkJpegDecoder::Decode(data, nullptr, nullptr);
24
24
  }
25
25