@shopify/react-native-skia 2.0.5 → 2.0.6

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 (180) hide show
  1. package/android/CMakeLists.txt +10 -0
  2. package/android/build.gradle +2 -1
  3. package/apple/SkiaCVPixelBufferUtils.mm +8 -4
  4. package/cpp/api/JsiSkCanvas.h +10 -8
  5. package/cpp/api/JsiSkFont.h +14 -18
  6. package/cpp/api/JsiSkPath.h +4 -2
  7. package/cpp/api/JsiSkPathEffectFactory.h +2 -2
  8. package/cpp/api/JsiSkTextBlobFactory.h +5 -3
  9. package/cpp/api/JsiSkTypeface.h +5 -4
  10. package/cpp/api/recorder/Drawings.h +26 -20
  11. package/cpp/api/recorder/PathEffects.h +3 -2
  12. package/cpp/skia/include/android/SkAndroidFrameworkUtils.h +1 -1
  13. package/cpp/skia/include/android/SkImageAndroid.h +1 -8
  14. package/cpp/skia/include/config/SkUserConfig.h +9 -0
  15. package/cpp/skia/include/core/SkCPUContext.h +31 -0
  16. package/cpp/skia/include/core/SkCPURecorder.h +69 -0
  17. package/cpp/skia/include/core/SkCanvas.h +57 -13
  18. package/cpp/skia/include/core/SkContourMeasure.h +1 -1
  19. package/cpp/skia/include/core/SkData.h +63 -37
  20. package/cpp/skia/include/core/SkFont.h +94 -65
  21. package/cpp/skia/include/core/SkImage.h +10 -9
  22. package/cpp/skia/include/core/SkImageGenerator.h +3 -0
  23. package/cpp/skia/include/core/SkMatrix.h +102 -116
  24. package/cpp/skia/include/core/SkMilestone.h +1 -1
  25. package/cpp/skia/include/core/SkPath.h +163 -60
  26. package/cpp/skia/include/core/SkPathBuilder.h +713 -30
  27. package/cpp/skia/include/core/SkPathTypes.h +5 -1
  28. package/cpp/skia/include/core/SkPictureRecorder.h +6 -6
  29. package/cpp/skia/include/core/SkRecorder.h +35 -0
  30. package/cpp/skia/include/core/SkRect.h +57 -27
  31. package/cpp/skia/include/core/SkRegion.h +1 -1
  32. package/cpp/skia/include/core/SkSurface.h +8 -1
  33. package/cpp/skia/include/core/SkTextBlob.h +50 -6
  34. package/cpp/skia/include/core/SkTraceMemoryDump.h +7 -0
  35. package/cpp/skia/include/core/SkTypeface.h +53 -26
  36. package/cpp/skia/include/core/SkTypes.h +6 -0
  37. package/cpp/skia/include/effects/SkDashPathEffect.h +9 -3
  38. package/cpp/skia/include/effects/SkRuntimeEffect.h +1 -1
  39. package/cpp/skia/include/encode/SkEncoder.h +1 -1
  40. package/cpp/skia/include/encode/SkICC.h +1 -1
  41. package/cpp/skia/include/gpu/ganesh/GrDirectContext.h +23 -0
  42. package/cpp/skia/include/gpu/ganesh/GrRecordingContext.h +12 -0
  43. package/cpp/skia/include/gpu/graphite/Context.h +32 -8
  44. package/cpp/skia/include/gpu/graphite/ContextOptions.h +22 -4
  45. package/cpp/skia/include/gpu/graphite/GraphiteTypes.h +21 -4
  46. package/cpp/skia/include/gpu/graphite/PrecompileContext.h +16 -2
  47. package/cpp/skia/include/gpu/graphite/Recorder.h +30 -10
  48. package/cpp/skia/include/gpu/graphite/Recording.h +7 -3
  49. package/cpp/skia/include/gpu/graphite/TextureInfo.h +3 -3
  50. package/cpp/skia/include/gpu/graphite/precompile/PaintOptions.h +15 -0
  51. package/cpp/skia/include/gpu/graphite/precompile/PrecompileShader.h +89 -13
  52. package/cpp/skia/include/gpu/graphite/vk/precompile/VulkanPrecompileShader.h +39 -0
  53. package/cpp/skia/include/gpu/vk/VulkanBackendContext.h +1 -1
  54. package/cpp/skia/include/gpu/vk/VulkanPreferredFeatures.h +214 -0
  55. package/cpp/skia/include/pathops/SkPathOps.h +7 -111
  56. package/cpp/skia/include/ports/SkFontMgr_fontconfig.h +3 -0
  57. package/cpp/skia/include/private/SkGainmapShader.h +10 -4
  58. package/cpp/skia/include/private/SkPathRef.h +6 -2
  59. package/cpp/skia/include/private/base/SkAlign.h +11 -0
  60. package/cpp/skia/include/private/gpu/ganesh/GrTypesPriv.h +1 -1
  61. package/cpp/skia/include/third_party/vulkan/vulkan/vk_icd.h +255 -0
  62. package/cpp/skia/include/third_party/vulkan/vulkan/vk_layer.h +203 -0
  63. package/cpp/skia/include/third_party/vulkan/vulkan/vk_platform.h +1 -2
  64. package/cpp/skia/include/third_party/vulkan/vulkan/vk_video/vulkan_video_codec_av1std.h +390 -0
  65. package/cpp/skia/include/third_party/vulkan/vulkan/vk_video/vulkan_video_codec_av1std_decode.h +106 -0
  66. package/cpp/skia/include/third_party/vulkan/vulkan/vk_video/vulkan_video_codec_av1std_encode.h +140 -0
  67. package/cpp/skia/include/third_party/vulkan/vulkan/vk_video/vulkan_video_codec_h264std.h +1 -1
  68. package/cpp/skia/include/third_party/vulkan/vulkan/vk_video/vulkan_video_codec_h264std_decode.h +1 -1
  69. package/cpp/skia/include/third_party/vulkan/vulkan/vk_video/vulkan_video_codec_h264std_encode.h +144 -0
  70. package/cpp/skia/include/third_party/vulkan/vulkan/vk_video/vulkan_video_codec_h265std.h +1 -1
  71. package/cpp/skia/include/third_party/vulkan/vulkan/vk_video/vulkan_video_codec_h265std_decode.h +1 -1
  72. package/cpp/skia/include/third_party/vulkan/vulkan/vk_video/vulkan_video_codec_h265std_encode.h +158 -0
  73. package/cpp/skia/include/third_party/vulkan/vulkan/vk_video/vulkan_video_codecs_common.h +1 -1
  74. package/cpp/skia/include/third_party/vulkan/vulkan/vulkan.h +1 -1
  75. package/cpp/skia/include/third_party/vulkan/vulkan/vulkan_android.h +1 -1
  76. package/cpp/skia/include/third_party/vulkan/vulkan/vulkan_beta.h +242 -0
  77. package/cpp/skia/include/third_party/vulkan/vulkan/vulkan_core.h +10094 -5707
  78. package/cpp/skia/include/third_party/vulkan/vulkan/vulkan_directfb.h +55 -0
  79. package/cpp/skia/include/third_party/vulkan/vulkan/vulkan_fuchsia.h +288 -0
  80. package/cpp/skia/include/third_party/vulkan/vulkan/vulkan_ggp.h +59 -0
  81. package/cpp/skia/include/third_party/vulkan/vulkan/vulkan_ios.h +1 -1
  82. package/cpp/skia/include/third_party/vulkan/vulkan/vulkan_macos.h +1 -1
  83. package/cpp/skia/include/third_party/vulkan/vulkan/vulkan_metal.h +238 -0
  84. package/cpp/skia/include/third_party/vulkan/vulkan/vulkan_screen.h +110 -0
  85. package/cpp/skia/include/third_party/vulkan/vulkan/vulkan_vi.h +47 -0
  86. package/cpp/skia/include/third_party/vulkan/vulkan/vulkan_wayland.h +55 -0
  87. package/cpp/skia/include/third_party/vulkan/vulkan/vulkan_win32.h +1 -1
  88. package/cpp/skia/include/third_party/vulkan/vulkan/vulkan_xcb.h +1 -1
  89. package/cpp/skia/include/third_party/vulkan/vulkan/vulkan_xlib.h +60 -0
  90. package/cpp/skia/include/third_party/vulkan/vulkan/vulkan_xlib_xrandr.h +46 -0
  91. package/cpp/skia/modules/pathops/include/SkPathOps.h +121 -0
  92. package/cpp/skia/modules/skcms/src/skcms_internals.h +10 -2
  93. package/cpp/skia/modules/skcms/src/skcms_public.h +39 -10
  94. package/libs/android/arm64-v8a/libpathops.a +0 -0
  95. package/libs/android/arm64-v8a/libskia.a +0 -0
  96. package/libs/android/arm64-v8a/libskottie.a +0 -0
  97. package/libs/android/arm64-v8a/libskparagraph.a +0 -0
  98. package/libs/android/arm64-v8a/libsksg.a +0 -0
  99. package/libs/android/arm64-v8a/libskshaper.a +0 -0
  100. package/libs/android/arm64-v8a/libskunicode_icu.a +0 -0
  101. package/libs/android/arm64-v8a/libsvg.a +0 -0
  102. package/libs/android/armeabi-v7a/libpathops.a +0 -0
  103. package/libs/android/armeabi-v7a/libskia.a +0 -0
  104. package/libs/android/armeabi-v7a/libskottie.a +0 -0
  105. package/libs/android/armeabi-v7a/libskparagraph.a +0 -0
  106. package/libs/android/armeabi-v7a/libsksg.a +0 -0
  107. package/libs/android/armeabi-v7a/libskshaper.a +0 -0
  108. package/libs/android/armeabi-v7a/libskunicode_icu.a +0 -0
  109. package/libs/android/armeabi-v7a/libsvg.a +0 -0
  110. package/libs/android/x86/libpathops.a +0 -0
  111. package/libs/android/x86/libskia.a +0 -0
  112. package/libs/android/x86/libskottie.a +0 -0
  113. package/libs/android/x86/libskparagraph.a +0 -0
  114. package/libs/android/x86/libsksg.a +0 -0
  115. package/libs/android/x86/libskshaper.a +0 -0
  116. package/libs/android/x86/libskunicode_icu.a +0 -0
  117. package/libs/android/x86/libsvg.a +0 -0
  118. package/libs/android/x86_64/libpathops.a +0 -0
  119. package/libs/android/x86_64/libskia.a +0 -0
  120. package/libs/android/x86_64/libskottie.a +0 -0
  121. package/libs/android/x86_64/libskparagraph.a +0 -0
  122. package/libs/android/x86_64/libsksg.a +0 -0
  123. package/libs/android/x86_64/libskshaper.a +0 -0
  124. package/libs/android/x86_64/libskunicode_icu.a +0 -0
  125. package/libs/android/x86_64/libsvg.a +0 -0
  126. package/libs/apple/libpathops.xcframework/Info.plist +94 -0
  127. package/libs/apple/libpathops.xcframework/ios-arm64_arm64e/libpathops.a +0 -0
  128. package/libs/apple/libpathops.xcframework/ios-arm64_arm64e_x86_64-simulator/libpathops.a +0 -0
  129. package/libs/apple/libpathops.xcframework/macos-arm64_x86_64/libpathops.a +0 -0
  130. package/libs/apple/libpathops.xcframework/tvos-arm64_arm64e/libpathops.a +0 -0
  131. package/libs/apple/libpathops.xcframework/tvos-arm64_arm64e_x86_64-simulator/libpathops.a +0 -0
  132. package/libs/apple/libskia.xcframework/Info.plist +7 -7
  133. package/libs/apple/libskia.xcframework/ios-arm64_arm64e/libskia.a +0 -0
  134. package/libs/apple/libskia.xcframework/ios-arm64_arm64e_x86_64-simulator/libskia.a +0 -0
  135. package/libs/apple/libskia.xcframework/macos-arm64_x86_64/libskia.a +0 -0
  136. package/libs/apple/libskia.xcframework/tvos-arm64_arm64e/libskia.a +0 -0
  137. package/libs/apple/libskia.xcframework/tvos-arm64_arm64e_x86_64-simulator/libskia.a +0 -0
  138. package/libs/apple/libskottie.xcframework/Info.plist +10 -10
  139. package/libs/apple/libskottie.xcframework/ios-arm64_arm64e/libskottie.a +0 -0
  140. package/libs/apple/libskottie.xcframework/ios-arm64_arm64e_x86_64-simulator/libskottie.a +0 -0
  141. package/libs/apple/libskottie.xcframework/macos-arm64_x86_64/libskottie.a +0 -0
  142. package/libs/apple/libskottie.xcframework/tvos-arm64_arm64e/libskottie.a +0 -0
  143. package/libs/apple/libskottie.xcframework/tvos-arm64_arm64e_x86_64-simulator/libskottie.a +0 -0
  144. package/libs/apple/libskparagraph.xcframework/Info.plist +13 -13
  145. package/libs/apple/libskparagraph.xcframework/ios-arm64_arm64e/libskparagraph.a +0 -0
  146. package/libs/apple/libskparagraph.xcframework/ios-arm64_arm64e_x86_64-simulator/libskparagraph.a +0 -0
  147. package/libs/apple/libskparagraph.xcframework/macos-arm64_x86_64/libskparagraph.a +0 -0
  148. package/libs/apple/libskparagraph.xcframework/tvos-arm64_arm64e/libskparagraph.a +0 -0
  149. package/libs/apple/libskparagraph.xcframework/tvos-arm64_arm64e_x86_64-simulator/libskparagraph.a +0 -0
  150. package/libs/apple/libsksg.xcframework/Info.plist +11 -11
  151. package/libs/apple/libsksg.xcframework/ios-arm64_arm64e/libsksg.a +0 -0
  152. package/libs/apple/libsksg.xcframework/ios-arm64_arm64e_x86_64-simulator/libsksg.a +0 -0
  153. package/libs/apple/libsksg.xcframework/macos-arm64_x86_64/libsksg.a +0 -0
  154. package/libs/apple/libsksg.xcframework/tvos-arm64_arm64e/libsksg.a +0 -0
  155. package/libs/apple/libsksg.xcframework/tvos-arm64_arm64e_x86_64-simulator/libsksg.a +0 -0
  156. package/libs/apple/libskshaper.xcframework/Info.plist +12 -12
  157. package/libs/apple/libskshaper.xcframework/ios-arm64_arm64e/libskshaper.a +0 -0
  158. package/libs/apple/libskshaper.xcframework/ios-arm64_arm64e_x86_64-simulator/libskshaper.a +0 -0
  159. package/libs/apple/libskshaper.xcframework/macos-arm64_x86_64/libskshaper.a +0 -0
  160. package/libs/apple/libskshaper.xcframework/tvos-arm64_arm64e/libskshaper.a +0 -0
  161. package/libs/apple/libskshaper.xcframework/tvos-arm64_arm64e_x86_64-simulator/libskshaper.a +0 -0
  162. package/libs/apple/libskunicode_core.xcframework/Info.plist +14 -14
  163. package/libs/apple/libskunicode_core.xcframework/ios-arm64_arm64e_x86_64-simulator/libskunicode_core.a +0 -0
  164. package/libs/apple/libskunicode_core.xcframework/macos-arm64_x86_64/libskunicode_core.a +0 -0
  165. package/libs/apple/libskunicode_core.xcframework/tvos-arm64_arm64e_x86_64-simulator/libskunicode_core.a +0 -0
  166. package/libs/apple/libskunicode_libgrapheme.xcframework/Info.plist +13 -13
  167. package/libs/apple/libskunicode_libgrapheme.xcframework/ios-arm64_arm64e/libskunicode_libgrapheme.a +0 -0
  168. package/libs/apple/libskunicode_libgrapheme.xcframework/ios-arm64_arm64e_x86_64-simulator/libskunicode_libgrapheme.a +0 -0
  169. package/libs/apple/libskunicode_libgrapheme.xcframework/macos-arm64_x86_64/libskunicode_libgrapheme.a +0 -0
  170. package/libs/apple/libskunicode_libgrapheme.xcframework/tvos-arm64_arm64e/libskunicode_libgrapheme.a +0 -0
  171. package/libs/apple/libskunicode_libgrapheme.xcframework/tvos-arm64_arm64e_x86_64-simulator/libskunicode_libgrapheme.a +0 -0
  172. package/libs/apple/libsvg.xcframework/Info.plist +17 -17
  173. package/libs/apple/libsvg.xcframework/ios-arm64_arm64e/libsvg.a +0 -0
  174. package/libs/apple/libsvg.xcframework/ios-arm64_arm64e_x86_64-simulator/libsvg.a +0 -0
  175. package/libs/apple/libsvg.xcframework/macos-arm64_x86_64/libsvg.a +0 -0
  176. package/libs/apple/libsvg.xcframework/tvos-arm64_arm64e/libsvg.a +0 -0
  177. package/libs/apple/libsvg.xcframework/tvos-arm64_arm64e_x86_64-simulator/libsvg.a +0 -0
  178. package/package.json +1 -1
  179. package/react-native-skia.podspec +2 -1
  180. package/src/renderer/__tests__/e2e/BackdropFilters.spec.tsx +23 -0
@@ -19,6 +19,7 @@
19
19
  #include "include/core/SkMatrix.h"
20
20
  #include "include/core/SkPaint.h"
21
21
  #include "include/core/SkPoint.h"
22
+ #include "include/core/SkRSXform.h" // IWYU pragma: keep (for unspanned apis)
22
23
  #include "include/core/SkRasterHandleAllocator.h"
23
24
  #include "include/core/SkRect.h"
24
25
  #include "include/core/SkRefCnt.h"
@@ -68,6 +69,7 @@ class SkPicture;
68
69
  class SkPixmap;
69
70
  class SkRRect;
70
71
  class SkRegion;
72
+ class SkRecorder;
71
73
  class SkShader;
72
74
  class SkSpecialImage;
73
75
  class SkSurface;
@@ -75,7 +77,6 @@ class SkSurface_Base;
75
77
  class SkTextBlob;
76
78
  class SkVertices;
77
79
  struct SkDrawShadowRec;
78
- struct SkRSXform;
79
80
 
80
81
  template<typename E>
81
82
  class SkEnumBitMask;
@@ -327,13 +328,18 @@ public:
327
328
  */
328
329
  virtual GrRecordingContext* recordingContext() const;
329
330
 
330
-
331
331
  /** Returns Recorder for the GPU surface associated with SkCanvas.
332
332
 
333
333
  @return Recorder, if available; nullptr otherwise
334
334
  */
335
335
  virtual skgpu::graphite::Recorder* recorder() const;
336
336
 
337
+ /** Returns Recorder for the surface associated with SkCanvas.
338
+
339
+ @return Recorder, should be non-null
340
+ */
341
+ virtual SkRecorder* baseRecorder() const;
342
+
337
343
  /** Sometimes a canvas is owned by a surface. If it is, getSurface() will return a bare
338
344
  * pointer to that surface, else this will return nullptr.
339
345
  */
@@ -1321,7 +1327,12 @@ public:
1321
1327
 
1322
1328
  example: https://fiddle.skia.org/c/@Canvas_drawPoints
1323
1329
  */
1324
- void drawPoints(PointMode mode, size_t count, const SkPoint pts[], const SkPaint& paint);
1330
+ void drawPoints(PointMode mode, SkSpan<const SkPoint>, const SkPaint& paint);
1331
+ #ifdef SK_SUPPORT_UNSPANNED_APIS
1332
+ void drawPoints(PointMode mode, size_t count, const SkPoint pts[], const SkPaint& paint) {
1333
+ this->drawPoints(mode, {pts, count}, paint);
1334
+ }
1335
+ #endif
1325
1336
 
1326
1337
  /** Draws point at (x, y) using clip, SkMatrix and SkPaint paint.
1327
1338
 
@@ -1893,19 +1904,28 @@ public:
1893
1904
  SkColorFilter, and SkImageFilter; apply to text. By
1894
1905
  default, draws filled black glyphs.
1895
1906
 
1896
- @param count number of glyphs to draw
1897
- @param glyphs the array of glyphIDs to draw
1907
+ @param glyphs the span of glyphIDs to draw
1898
1908
  @param positions where to draw each glyph relative to origin
1899
- @param clusters array of size count of cluster information
1900
- @param textByteCount size of the utf8text
1909
+ @param clusters cluster information
1901
1910
  @param utf8text utf8text supporting information for the glyphs
1902
1911
  @param origin the origin of all the positions
1903
1912
  @param font typeface, text size and so, used to describe the text
1904
1913
  @param paint blend, color, and so on, used to draw
1905
1914
  */
1915
+ void drawGlyphs(SkSpan<const SkGlyphID> glyphs, SkSpan<const SkPoint> positions,
1916
+ SkSpan<const uint32_t> clusters, SkSpan<const char> utf8text,
1917
+ SkPoint origin, const SkFont& font, const SkPaint& paint);
1918
+ #ifdef SK_SUPPORT_UNSPANNED_APIS
1906
1919
  void drawGlyphs(int count, const SkGlyphID glyphs[], const SkPoint positions[],
1907
1920
  const uint32_t clusters[], int textByteCount, const char utf8text[],
1908
- SkPoint origin, const SkFont& font, const SkPaint& paint);
1921
+ SkPoint origin, const SkFont& font, const SkPaint& paint) {
1922
+ this->drawGlyphs({glyphs, count},
1923
+ {positions, count},
1924
+ {clusters, count},
1925
+ {utf8text, textByteCount},
1926
+ origin, font, paint);
1927
+ }
1928
+ #endif
1909
1929
 
1910
1930
  /** Draws count glyphs, at positions relative to origin styled with font and paint.
1911
1931
 
@@ -1925,8 +1945,14 @@ public:
1925
1945
  @param font typeface, text size and so, used to describe the text
1926
1946
  @param paint blend, color, and so on, used to draw
1927
1947
  */
1928
- void drawGlyphs(int count, const SkGlyphID glyphs[], const SkPoint positions[],
1948
+ void drawGlyphs(SkSpan<const SkGlyphID> glyphs, SkSpan<const SkPoint> positions,
1929
1949
  SkPoint origin, const SkFont& font, const SkPaint& paint);
1950
+ #ifdef SK_SUPPORT_UNSPANNED_APIS
1951
+ void drawGlyphs(int count, const SkGlyphID glyphs[], const SkPoint positions[],
1952
+ SkPoint origin, const SkFont& font, const SkPaint& paint) {
1953
+ this->drawGlyphs({glyphs, count}, {positions, count}, origin, font, paint);
1954
+ }
1955
+ #endif
1930
1956
 
1931
1957
  /** Draws count glyphs, at positions relative to origin styled with font and paint.
1932
1958
 
@@ -1947,8 +1973,14 @@ public:
1947
1973
  @param font typeface, text size and so, used to describe the text
1948
1974
  @param paint blend, color, and so on, used to draw
1949
1975
  */
1976
+ void drawGlyphsRSXform(SkSpan<const SkGlyphID> glyphs, SkSpan<const SkRSXform> xforms,
1977
+ SkPoint origin, const SkFont& font, const SkPaint& paint);
1978
+ #ifdef SK_SUPPORT_UNSPANNED_APIS
1950
1979
  void drawGlyphs(int count, const SkGlyphID glyphs[], const SkRSXform xforms[],
1951
- SkPoint origin, const SkFont& font, const SkPaint& paint);
1980
+ SkPoint origin, const SkFont& font, const SkPaint& paint) {
1981
+ this->drawGlyphsRSXform({glyphs, count}, {xforms, count}, origin, font, paint);
1982
+ }
1983
+ #endif
1952
1984
 
1953
1985
  /** Draws SkTextBlob blob at (x, y), using clip, SkMatrix, and SkPaint paint.
1954
1986
 
@@ -2155,7 +2187,9 @@ public:
2155
2187
 
2156
2188
  SkMaskFilter and SkPathEffect on paint are ignored.
2157
2189
 
2158
- xform, tex, and colors if present, must contain count entries.
2190
+ For non-empty spans, the number of draws will be the min of
2191
+ xform.size(), tex.size(), and (if not empty) colors.size().
2192
+
2159
2193
  Optional colors are applied for each sprite using SkBlendMode mode, treating
2160
2194
  sprite as source and colors as destination.
2161
2195
  Optional cullRect is a conservative bounds of all transformed sprites.
@@ -2167,15 +2201,25 @@ public:
2167
2201
  @param xform SkRSXform mappings for sprites in atlas
2168
2202
  @param tex SkRect locations of sprites in atlas
2169
2203
  @param colors one per sprite, blended with sprite using SkBlendMode; may be nullptr
2170
- @param count number of sprites to draw
2171
2204
  @param mode SkBlendMode combining colors and sprites
2172
2205
  @param sampling SkSamplingOptions used when sampling from the atlas image
2173
2206
  @param cullRect bounds of transformed sprites for efficient clipping; may be nullptr
2174
2207
  @param paint SkColorFilter, SkImageFilter, SkBlendMode, and so on; may be nullptr
2175
2208
  */
2209
+ void drawAtlas(const SkImage* atlas, SkSpan<const SkRSXform> xform,
2210
+ SkSpan<const SkRect> tex, SkSpan<const SkColor> colors, SkBlendMode mode,
2211
+ const SkSamplingOptions& sampling, const SkRect* cullRect, const SkPaint* paint);
2212
+ #ifdef SK_SUPPORT_UNSPANNED_APIS
2176
2213
  void drawAtlas(const SkImage* atlas, const SkRSXform xform[], const SkRect tex[],
2177
2214
  const SkColor colors[], int count, SkBlendMode mode,
2178
- const SkSamplingOptions& sampling, const SkRect* cullRect, const SkPaint* paint);
2215
+ const SkSamplingOptions& samp, const SkRect* cullRect, const SkPaint* paint) {
2216
+ this->drawAtlas(atlas,
2217
+ {xform, count},
2218
+ {tex, tex ? count : 0},
2219
+ {colors, colors ? count : 0},
2220
+ mode, samp, cullRect, paint);
2221
+ }
2222
+ #endif
2179
2223
 
2180
2224
  /** Draws SkDrawable drawable using clip and SkMatrix, concatenated with
2181
2225
  optional matrix.
@@ -8,6 +8,7 @@
8
8
  #ifndef SkContourMeasure_DEFINED
9
9
  #define SkContourMeasure_DEFINED
10
10
 
11
+ #include "include/core/SkPathTypes.h" // IWYU pragma: keep
11
12
  #include "include/core/SkPoint.h"
12
13
  #include "include/core/SkRefCnt.h"
13
14
  #include "include/core/SkScalar.h"
@@ -21,7 +22,6 @@
21
22
 
22
23
  class SkMatrix;
23
24
  class SkPath;
24
- enum class SkPathVerb;
25
25
 
26
26
  class SK_API SkContourMeasure : public SkRefCnt {
27
27
  public:
@@ -9,68 +9,83 @@
9
9
  #define SkData_DEFINED
10
10
 
11
11
  #include "include/core/SkRefCnt.h"
12
+ #include "include/core/SkSpan.h"
12
13
  #include "include/private/base/SkAPI.h"
13
- #include "include/private/base/SkAssert.h"
14
14
 
15
+ #include <cstddef>
15
16
  #include <cstdint>
16
17
  #include <cstdio>
17
18
 
18
19
  class SkStream;
19
20
 
20
21
  /**
21
- * SkData holds an immutable data buffer. Not only is the data immutable,
22
- * but the actual ptr that is returned (by data() or bytes()) is guaranteed
23
- * to always be the same for the life of this instance.
22
+ * SkData holds a data buffer. It can be created to allocate its own buffer
23
+ * for the contents, or to share a pointer to the client's buffer. The size and
24
+ * address of the contents never change for the lifetime of the data object.
24
25
  */
25
26
  class SK_API SkData final : public SkNVRefCnt<SkData> {
26
27
  public:
27
28
  /**
28
- * Returns the number of bytes stored.
29
+ * Returns true if this and rhs are the same size, and contain the same contents.
30
+ * All empty objects compare as equal.
29
31
  */
30
- size_t size() const { return fSize; }
32
+ bool operator==(const SkData& rhs) const;
33
+ bool operator!=(const SkData& rhs) const { return !(*this == rhs); }
31
34
 
32
- bool isEmpty() const { return 0 == fSize; }
35
+ /**
36
+ * Calls == operator, but first checks if other is null (in which case it returns false)
37
+ */
38
+ bool equals(const SkData* other) const {
39
+ return (other != nullptr) && *this == *other;
40
+ }
33
41
 
34
42
  /**
35
- * Returns the ptr to the data.
43
+ * Returns the number of bytes stored.
36
44
  */
37
- const void* data() const { return fPtr; }
45
+ size_t size() const { return fSpan.size(); }
38
46
 
39
47
  /**
40
- * Like data(), returns a read-only ptr into the data, but in this case
41
- * it is cast to uint8_t*, to make it easy to add an offset to it.
48
+ * Returns the ptr to the data.
42
49
  */
43
- const uint8_t* bytes() const {
44
- return reinterpret_cast<const uint8_t*>(fPtr);
45
- }
50
+ const void* data() const { return fSpan.data(); }
51
+
52
+ bool empty() const { return fSpan.empty(); }
53
+
54
+ const uint8_t* bytes() const { return reinterpret_cast<const uint8_t*>(this->data()); }
55
+
56
+ SkSpan<const uint8_t> byteSpan() const { return {this->bytes(), this->size()}; }
46
57
 
47
58
  /**
48
59
  * USE WITH CAUTION.
49
- * This call will assert that the refcnt is 1, as a precaution against modifying the
50
- * contents when another client/thread has access to the data.
60
+ * Be sure other 'owners' of this object are not accessing it in aother thread.
51
61
  */
52
62
  void* writable_data() {
53
- if (fSize) {
54
- // only assert we're unique if we're not empty
55
- SkASSERT(this->unique());
56
- }
57
- return const_cast<void*>(fPtr);
63
+ return fSpan.data();
58
64
  }
59
65
 
66
+ /** Attempt to create a deep copy of the original data, using the default allocator.
67
+ *
68
+ * If offset+length > this->size(), then this returns nullptr.
69
+ */
70
+ sk_sp<SkData> copySubset(size_t offset, size_t length) const;
71
+
72
+ /** Attempt to return a data that is a reference to a subset of the original data,
73
+ * This will never make a deep copy of the contents, but will retain a reference
74
+ * to the original data object.
75
+ *
76
+ * If offset+length > this->size(), then this returns nullptr.
77
+ */
78
+ sk_sp<SkData> shareSubset(size_t offset, size_t length);
79
+ sk_sp<const SkData> shareSubset(size_t offset, size_t length) const;
80
+
60
81
  /**
61
82
  * Helper to copy a range of the data into a caller-provided buffer.
62
83
  * Returns the actual number of bytes copied, after clamping offset and
63
- * length to the size of the data. If buffer is NULL, it is ignored, and
84
+ * length to the size of this data. If buffer is NULL, it is ignored, and
64
85
  * only the computed number of bytes is returned.
65
86
  */
66
87
  size_t copyRange(size_t offset, size_t length, void* buffer) const;
67
88
 
68
- /**
69
- * Returns true if these two objects have the same length and contents,
70
- * effectively returning 0 == memcmp(...)
71
- */
72
- bool equals(const SkData* other) const;
73
-
74
89
  /**
75
90
  * Function that, if provided, will be called when the SkData goes out
76
91
  * of scope, allowing for custom allocation/freeing of the data's contents.
@@ -111,7 +126,7 @@ public:
111
126
 
112
127
  /**
113
128
  * Call this when the data parameter is already const and will outlive the lifetime of the
114
- * SkData. Suitable for with const globals.
129
+ * SkData. Suitable for globals.
115
130
  */
116
131
  static sk_sp<SkData> MakeWithoutCopy(const void* data, size_t length) {
117
132
  return MakeWithProc(data, length, NoopReleaseProc, nullptr);
@@ -155,10 +170,17 @@ public:
155
170
  static sk_sp<SkData> MakeFromStream(SkStream*, size_t size);
156
171
 
157
172
  /**
158
- * Create a new dataref using a subset of the data in the specified
159
- * src dataref.
173
+ * DEPRECATED variant of src->shareSubset(offset, length)
174
+ *
175
+ * This variant checks if shaerSubset() returned null (because offset or length were out-of-range)
176
+ * and returns an empty SkData, rather than returning null.
160
177
  */
161
- static sk_sp<SkData> MakeSubset(const SkData* src, size_t offset, size_t length);
178
+ static sk_sp<SkData> MakeSubset(const SkData* src, size_t offset, size_t length) {
179
+ if (sk_sp<SkData> dst = const_cast<SkData*>(src)->shareSubset(offset, length)) {
180
+ return dst;
181
+ }
182
+ return SkData::MakeEmpty();
183
+ }
162
184
 
163
185
  /**
164
186
  * Returns a new empty dataref (or a reference to a shared empty dataref).
@@ -166,14 +188,18 @@ public:
166
188
  */
167
189
  static sk_sp<SkData> MakeEmpty();
168
190
 
191
+ /**
192
+ * DEPRECATED -- use empty()
193
+ */
194
+ bool isEmpty() const { return fSpan.empty(); }
195
+
169
196
  private:
170
197
  friend class SkNVRefCnt<SkData>;
171
- ReleaseProc fReleaseProc;
172
- void* fReleaseProcContext;
173
- const void* fPtr;
174
- size_t fSize;
198
+ ReleaseProc fReleaseProc;
199
+ void* fReleaseProcContext;
200
+ SkSpan<std::byte> fSpan;
175
201
 
176
- SkData(const void* ptr, size_t size, ReleaseProc, void* context);
202
+ SkData(SkSpan<std::byte>, ReleaseProc, void* context);
177
203
  explicit SkData(size_t size); // inplace new/delete
178
204
  ~SkData();
179
205
 
@@ -8,9 +8,11 @@
8
8
  #ifndef SkFont_DEFINED
9
9
  #define SkFont_DEFINED
10
10
 
11
+ #include "include/core/SkPoint.h" // IWYU pragma: keep (for unspanned apis)
11
12
  #include "include/core/SkRect.h"
12
13
  #include "include/core/SkRefCnt.h"
13
14
  #include "include/core/SkScalar.h"
15
+ #include "include/core/SkSpan.h"
14
16
  #include "include/core/SkTypeface.h"
15
17
  #include "include/core/SkTypes.h"
16
18
  #include "include/private/base/SkTo.h"
@@ -18,7 +20,6 @@
18
20
 
19
21
  #include <cstddef>
20
22
  #include <cstdint>
21
- #include <type_traits>
22
23
  #include <vector>
23
24
 
24
25
  class SkMatrix;
@@ -27,7 +28,6 @@ class SkPath;
27
28
  enum class SkFontHinting;
28
29
  enum class SkTextEncoding;
29
30
  struct SkFontMetrics;
30
- struct SkPoint;
31
31
 
32
32
  /** \class SkFont
33
33
  SkFont controls options applied when drawing and measuring text.
@@ -271,7 +271,7 @@ public:
271
271
  /** Converts text into glyph indices.
272
272
  Returns the number of glyph indices represented by text.
273
273
  SkTextEncoding specifies how text represents characters or glyphs.
274
- glyphs may be nullptr, to compute the glyph count.
274
+ glyphs may be empty, to compute the glyph count.
275
275
 
276
276
  Does not check text for valid character codes or valid glyph indices.
277
277
 
@@ -287,17 +287,16 @@ public:
287
287
  mapping from the SkTypeface and maps characters not found in the
288
288
  SkTypeface to zero.
289
289
 
290
- If maxGlyphCount is not sufficient to store all the glyphs, no glyphs are copied.
290
+ If glyphs.size() is not sufficient to store all the glyphs, no glyphs are copied.
291
291
  The total glyph count is returned for subsequent buffer reallocation.
292
292
 
293
293
  @param text character storage encoded with SkTextEncoding
294
294
  @param byteLength length of character storage in bytes
295
- @param glyphs storage for glyph indices; may be nullptr
296
- @param maxGlyphCount storage capacity
297
- @return number of glyphs represented by text of length byteLength
295
+ @param glyphs storage for glyph indices; may be empty
296
+ @return number of glyphs represented by text of length byteLength
298
297
  */
299
- int textToGlyphs(const void* text, size_t byteLength, SkTextEncoding encoding,
300
- SkGlyphID glyphs[], int maxGlyphCount) const;
298
+ size_t textToGlyphs(const void* text, size_t byteLength, SkTextEncoding encoding,
299
+ SkSpan<SkGlyphID> glyphs) const;
301
300
 
302
301
  /** Returns glyph index for Unicode character.
303
302
 
@@ -308,7 +307,7 @@ public:
308
307
  */
309
308
  SkGlyphID unicharToGlyph(SkUnichar uni) const;
310
309
 
311
- void unicharsToGlyphs(const SkUnichar uni[], int count, SkGlyphID glyphs[]) const;
310
+ void unicharsToGlyphs(SkSpan<const SkUnichar> src, SkSpan<SkGlyphID> dst) const;
312
311
 
313
312
  /** Returns number of glyphs represented by text.
314
313
 
@@ -320,8 +319,8 @@ public:
320
319
  @param byteLength length of character storage in bytes
321
320
  @return number of glyphs represented by text of length byteLength
322
321
  */
323
- int countText(const void* text, size_t byteLength, SkTextEncoding encoding) const {
324
- return this->textToGlyphs(text, byteLength, encoding, nullptr, 0);
322
+ size_t countText(const void* text, size_t byteLength, SkTextEncoding encoding) const {
323
+ return this->textToGlyphs(text, byteLength, encoding, {});
325
324
  }
326
325
 
327
326
  /** Returns the advance width of text.
@@ -352,99 +351,80 @@ public:
352
351
  SkScalar measureText(const void* text, size_t byteLength, SkTextEncoding encoding,
353
352
  SkRect* bounds, const SkPaint* paint) const;
354
353
 
355
- /** DEPRECATED
356
- Retrieves the advance and bounds for each glyph in glyphs.
357
- Both widths and bounds may be nullptr.
358
- If widths is not nullptr, widths must be an array of count entries.
359
- if bounds is not nullptr, bounds must be an array of count entries.
360
-
361
- @param glyphs array of glyph indices to be measured
362
- @param count number of glyphs
363
- @param widths returns text advances for each glyph; may be nullptr
364
- @param bounds returns bounds for each glyph relative to (0, 0); may be nullptr
365
- */
366
- void getWidths(const SkGlyphID glyphs[], int count, SkScalar widths[], SkRect bounds[]) const {
367
- this->getWidthsBounds(glyphs, count, widths, bounds, nullptr);
368
- }
369
-
370
- // DEPRECATED
371
- void getWidths(const SkGlyphID glyphs[], int count, SkScalar widths[], std::nullptr_t) const {
372
- this->getWidths(glyphs, count, widths);
373
- }
374
-
375
354
  /** Retrieves the advance and bounds for each glyph in glyphs.
376
- Both widths and bounds may be nullptr.
377
- If widths is not nullptr, widths must be an array of count entries.
378
- if bounds is not nullptr, bounds must be an array of count entries.
355
+ widths receives min(widths.size(), glyphs.size()) values.
356
+ bounds receives min(bounds.size(), glyphs.size()) values.
379
357
 
380
358
  @param glyphs array of glyph indices to be measured
381
- @param count number of glyphs
382
359
  @param widths returns text advances for each glyph
360
+ @param bounds returns bounds for each glyph relative to (0, 0)
361
+ @param paint optional, specifies stroking, SkPathEffect and SkMaskFilter
383
362
  */
384
- void getWidths(const SkGlyphID glyphs[], int count, SkScalar widths[]) const {
385
- this->getWidthsBounds(glyphs, count, widths, nullptr, nullptr);
386
- }
363
+ void getWidthsBounds(SkSpan<const SkGlyphID> glyphs, SkSpan<SkScalar> widths, SkSpan<SkRect> bounds,
364
+ const SkPaint* paint) const;
387
365
 
388
366
  /** Retrieves the advance and bounds for each glyph in glyphs.
389
- Both widths and bounds may be nullptr.
390
- If widths is not nullptr, widths must be an array of count entries.
391
- if bounds is not nullptr, bounds must be an array of count entries.
367
+ widths receives min(widths.size(), glyphs.size()) values.
392
368
 
393
369
  @param glyphs array of glyph indices to be measured
394
- @param count number of glyphs
395
- @param widths returns text advances for each glyph; may be nullptr
396
- @param bounds returns bounds for each glyph relative to (0, 0); may be nullptr
397
- @param paint optional, specifies stroking, SkPathEffect and SkMaskFilter
370
+ @param widths returns text advances for each glyph
398
371
  */
399
- void getWidthsBounds(const SkGlyphID glyphs[], int count, SkScalar widths[], SkRect bounds[],
400
- const SkPaint* paint) const;
401
-
372
+ void getWidths(SkSpan<const SkGlyphID> glyphs, SkSpan<SkScalar> widths) const {
373
+ this->getWidthsBounds(glyphs, widths, {}, nullptr);
374
+ }
375
+ SkScalar getWidth(SkGlyphID glyph) const {
376
+ SkScalar width;
377
+ this->getWidthsBounds({&glyph, 1}, {&width, 1}, {}, nullptr);
378
+ return width;
379
+ }
402
380
 
403
381
  /** Retrieves the bounds for each glyph in glyphs.
404
- bounds must be an array of count entries.
382
+ bounds receives min(bounds.size(), glyphs.size()) values.
405
383
  If paint is not nullptr, its stroking, SkPathEffect, and SkMaskFilter fields are respected.
406
384
 
407
385
  @param glyphs array of glyph indices to be measured
408
- @param count number of glyphs
409
386
  @param bounds returns bounds for each glyph relative to (0, 0); may be nullptr
410
387
  @param paint optional, specifies stroking, SkPathEffect, and SkMaskFilter
411
388
  */
412
- void getBounds(const SkGlyphID glyphs[], int count, SkRect bounds[],
389
+ void getBounds(SkSpan<const SkGlyphID> glyphs, SkSpan<SkRect> bounds,
413
390
  const SkPaint* paint) const {
414
- this->getWidthsBounds(glyphs, count, nullptr, bounds, paint);
391
+ this->getWidthsBounds(glyphs, {}, bounds, paint);
392
+ }
393
+ SkRect getBounds(SkGlyphID glyph, const SkPaint* paint) const {
394
+ SkRect bounds;
395
+ this->getBounds({&glyph, 1}, {&bounds, 1}, paint);
396
+ return bounds;
415
397
  }
416
398
 
417
- /** Retrieves the positions for each glyph, beginning at the specified origin. The caller
418
- must allocated at least count number of elements in the pos[] array.
399
+ /** Retrieves the positions for each glyph, beginning at the specified origin.
400
+ pos receives min(pos.size(), glyphs.size()) values.
419
401
 
420
402
  @param glyphs array of glyph indices to be positioned
421
- @param count number of glyphs
422
403
  @param pos returns glyphs positions
423
404
  @param origin location of the first glyph. Defaults to {0, 0}.
424
405
  */
425
- void getPos(const SkGlyphID glyphs[], int count, SkPoint pos[], SkPoint origin = {0, 0}) const;
406
+ void getPos(SkSpan<const SkGlyphID> glyphs, SkSpan<SkPoint> pos, SkPoint origin = {0, 0}) const;
426
407
 
427
- /** Retrieves the x-positions for each glyph, beginning at the specified origin. The caller
428
- must allocated at least count number of elements in the xpos[] array.
408
+ /** Retrieves the x-positions for each glyph, beginning at the specified origin.
409
+ xpos receives min(xpos.size(), glyphs.size()) values.
429
410
 
430
411
  @param glyphs array of glyph indices to be positioned
431
- @param count number of glyphs
432
412
  @param xpos returns glyphs x-positions
433
413
  @param origin x-position of the first glyph. Defaults to 0.
434
414
  */
435
- void getXPos(const SkGlyphID glyphs[], int count, SkScalar xpos[], SkScalar origin = 0) const;
415
+ void getXPos(SkSpan<const SkGlyphID> glyphs, SkSpan<SkScalar> xpos, SkScalar origin = 0) const;
436
416
 
437
417
  /** Returns intervals [start, end] describing lines parallel to the advance that intersect
438
418
  * with the glyphs.
439
419
  *
440
420
  * @param glyphs the glyphs to intersect
441
- * @param count the number of glyphs and positions
442
421
  * @param pos the position of each glyph
443
422
  * @param top the top of the line intersecting
444
423
  * @param bottom the bottom of the line intersecting
445
424
  @return array of pairs of x values [start, end]. May be empty.
446
425
  */
447
- std::vector<SkScalar> getIntercepts(const SkGlyphID glyphs[], int count, const SkPoint pos[],
426
+ std::vector<SkScalar> getIntercepts(SkSpan<const SkGlyphID> glyphs,
427
+ SkSpan<const SkPoint> pos,
448
428
  SkScalar top, SkScalar bottom,
449
429
  const SkPaint* = nullptr) const;
450
430
 
@@ -462,11 +442,10 @@ public:
462
442
  /** Returns path corresponding to glyph array.
463
443
 
464
444
  @param glyphIDs array of glyph indices
465
- @param count number of glyphs
466
445
  @param glyphPathProc function returning one glyph description as path
467
446
  @param ctx function context
468
447
  */
469
- void getPaths(const SkGlyphID glyphIDs[], int count,
448
+ void getPaths(SkSpan<const SkGlyphID> glyphIDs,
470
449
  void (*glyphPathProc)(const SkPath* pathOrNull, const SkMatrix& mx, void* ctx),
471
450
  void* ctx) const;
472
451
 
@@ -500,6 +479,56 @@ public:
500
479
 
501
480
  using sk_is_trivially_relocatable = std::true_type;
502
481
 
482
+ #ifdef SK_SUPPORT_UNSPANNED_APIS
483
+ int textToGlyphs(const void* text, size_t byteLength, SkTextEncoding encoding,
484
+ SkGlyphID glyphs[], int maxGlyphCount) const {
485
+ return (int)this->textToGlyphs(text, byteLength, encoding, {glyphs, maxGlyphCount});
486
+ }
487
+ void unicharsToGlyphs(const SkUnichar uni[], int count, SkGlyphID glyphs[]) const {
488
+ this->unicharsToGlyphs({uni, count}, {glyphs, count});
489
+ }
490
+
491
+ void getPos(const SkGlyphID glyphs[], int count, SkPoint pos[], SkPoint origin = {0, 0}) const {
492
+ this->getPos({glyphs, count}, {pos, count}, origin);
493
+ }
494
+ void getXPos(const SkGlyphID glyphs[], int count, SkScalar xpos[], SkScalar origin = 0) const {
495
+ this->getXPos({glyphs, count}, {xpos, count}, origin);
496
+ }
497
+ void getPaths(const SkGlyphID glyphIDs[], int count,
498
+ void (*glyphPathProc)(const SkPath* pathOrNull, const SkMatrix& mx, void* ctx),
499
+ void* ctx) const {
500
+ this->getPaths({glyphIDs, count}, glyphPathProc, ctx);
501
+ }
502
+ void getWidthsBounds(const SkGlyphID glyphs[], int count, SkScalar widths[], SkRect bounds[],
503
+ const SkPaint* paint) const {
504
+ const auto nw = widths ? count : 0;
505
+ const auto nb = bounds ? count : 0;
506
+ this->getWidthsBounds({glyphs, count}, {widths, nw}, {bounds, nb}, paint);
507
+ }
508
+ void getWidths(const SkGlyphID glyphs[], int count, SkScalar widths[], SkRect bounds[]) const {
509
+ const auto nw = widths ? count : 0;
510
+ const auto nb = bounds ? count : 0;
511
+ this->getWidthsBounds({glyphs, count}, {widths, nw}, {bounds, nb}, nullptr);
512
+ }
513
+ void getWidths(const SkGlyphID glyphs[], int count, SkScalar widths[], std::nullptr_t) const {
514
+ this->getWidthsBounds({glyphs, count}, {widths, count}, {}, nullptr);
515
+ }
516
+ void getWidths(const SkGlyphID glyphs[], int count, SkScalar widths[]) const {
517
+ this->getWidthsBounds({glyphs, count}, {widths, count}, {}, nullptr);
518
+ }
519
+ void getBounds(const SkGlyphID glyphs[], int count, SkRect bounds[],
520
+ const SkPaint* paint) const {
521
+ this->getWidthsBounds({glyphs, count}, {}, {bounds, count}, paint);
522
+ }
523
+
524
+ std::vector<SkScalar> getIntercepts(const SkGlyphID glyphs[], int count, const SkPoint pos[],
525
+ SkScalar top, SkScalar bottom,
526
+ const SkPaint* paint = nullptr) const {
527
+ return this->getIntercepts({glyphs, count}, {pos, count}, top, bottom, paint);
528
+ }
529
+ #endif
530
+
531
+
503
532
  private:
504
533
  enum PrivFlags {
505
534
  kForceAutoHinting_PrivFlag = 1 << 0,