@shopify/react-native-skia 2.0.0-next.2 → 2.0.0-next.4

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 (175) hide show
  1. package/android/build.gradle +14 -10
  2. package/cpp/api/JsiSkCanvas.h +45 -2
  3. package/cpp/api/recorder/Drawings.h +31 -2
  4. package/cpp/api/recorder/Shaders.h +40 -0
  5. package/cpp/skia/include/codec/SkCodec.h +39 -1
  6. package/cpp/skia/include/config/SkUserConfig.h +1 -10
  7. package/cpp/skia/include/core/SkCanvas.h +8 -4
  8. package/cpp/skia/include/core/SkContourMeasure.h +2 -2
  9. package/cpp/skia/include/core/SkMilestone.h +1 -1
  10. package/cpp/skia/include/core/SkPaint.h +8 -5
  11. package/cpp/skia/include/core/SkStream.h +8 -3
  12. package/cpp/skia/include/core/SkTextBlob.h +9 -9
  13. package/cpp/skia/include/core/SkTypeface.h +4 -6
  14. package/cpp/skia/include/core/SkTypes.h +5 -0
  15. package/cpp/skia/include/docs/SkPDFDocument.h +47 -2
  16. package/cpp/skia/include/docs/SkPDFJpegHelpers.h +41 -0
  17. package/cpp/skia/include/effects/SkRuntimeEffect.h +5 -1
  18. package/cpp/skia/include/effects/SkTableMaskFilter.h +4 -0
  19. package/cpp/skia/include/gpu/graphite/BackendTexture.h +0 -2
  20. package/cpp/skia/include/gpu/graphite/ContextOptions.h +17 -0
  21. package/cpp/skia/include/gpu/graphite/GraphiteTypes.h +21 -18
  22. package/cpp/skia/include/gpu/graphite/PrecompileContext.h +24 -0
  23. package/cpp/skia/include/gpu/graphite/TextureInfo.h +87 -42
  24. package/cpp/skia/include/gpu/graphite/YUVABackendTextures.h +13 -4
  25. package/cpp/skia/include/gpu/graphite/dawn/DawnBackendContext.h +9 -0
  26. package/cpp/skia/include/gpu/graphite/dawn/DawnGraphiteTypes.h +166 -0
  27. package/cpp/skia/include/gpu/graphite/dawn/DawnTypes.h +3 -141
  28. package/cpp/skia/include/gpu/graphite/dawn/DawnUtils.h +2 -21
  29. package/cpp/skia/include/gpu/graphite/mtl/MtlBackendContext.h +4 -0
  30. package/cpp/skia/include/gpu/graphite/mtl/MtlGraphiteTypes.h +30 -6
  31. package/cpp/skia/include/gpu/graphite/mtl/MtlGraphiteTypesUtils.h +4 -42
  32. package/cpp/skia/include/gpu/graphite/mtl/MtlGraphiteTypes_cpp.h +50 -0
  33. package/cpp/skia/include/gpu/graphite/mtl/MtlGraphiteUtils.h +2 -20
  34. package/cpp/skia/include/gpu/graphite/precompile/Precompile.h +14 -4
  35. package/cpp/skia/include/gpu/graphite/precompile/PrecompileShader.h +14 -6
  36. package/cpp/skia/include/gpu/graphite/vk/VulkanGraphiteContext.h +31 -0
  37. package/cpp/skia/include/gpu/graphite/vk/VulkanGraphiteTypes.h +36 -14
  38. package/cpp/skia/include/gpu/graphite/vk/VulkanGraphiteUtils.h +3 -21
  39. package/cpp/skia/include/ports/SkTypeface_fontations.h +3 -0
  40. package/cpp/skia/include/private/SkJpegMetadataDecoder.h +7 -0
  41. package/cpp/skia/include/private/base/SkAnySubclass.h +6 -0
  42. package/cpp/skia/include/private/chromium/SkPMColor.h +38 -0
  43. package/cpp/skia/modules/skparagraph/include/Paragraph.h +2 -2
  44. package/cpp/skia/modules/skunicode/include/SkUnicode.h +10 -6
  45. package/cpp/skia/modules/svg/include/SkSVGDOM.h +1 -3
  46. package/cpp/skia/src/base/SkTInternalLList.h +1 -1
  47. package/cpp/skia/src/core/SkLRUCache.h +6 -3
  48. package/lib/commonjs/external/reanimated/textures.d.ts +2 -4
  49. package/lib/commonjs/external/reanimated/textures.js +8 -15
  50. package/lib/commonjs/external/reanimated/textures.js.map +1 -1
  51. package/lib/commonjs/renderer/Canvas.d.ts +1 -2
  52. package/lib/commonjs/renderer/Canvas.js.map +1 -1
  53. package/lib/commonjs/sksg/HostConfig.js +2 -1
  54. package/lib/commonjs/sksg/HostConfig.js.map +1 -1
  55. package/lib/commonjs/sksg/Recorder/Player.d.ts +1 -1
  56. package/lib/commonjs/sksg/Recorder/Player.js.map +1 -1
  57. package/lib/commonjs/sksg/Recorder/commands/Box.js +2 -2
  58. package/lib/commonjs/sksg/Recorder/commands/Box.js.map +1 -1
  59. package/lib/commonjs/sksg/Recorder/commands/Drawing.d.ts +1 -3
  60. package/lib/commonjs/sksg/Recorder/commands/Drawing.js +1 -58
  61. package/lib/commonjs/sksg/Recorder/commands/Drawing.js.map +1 -1
  62. package/lib/module/external/reanimated/textures.d.ts +2 -4
  63. package/lib/module/external/reanimated/textures.js +7 -12
  64. package/lib/module/external/reanimated/textures.js.map +1 -1
  65. package/lib/module/renderer/Canvas.d.ts +1 -2
  66. package/lib/module/renderer/Canvas.js.map +1 -1
  67. package/lib/module/sksg/HostConfig.js +2 -1
  68. package/lib/module/sksg/HostConfig.js.map +1 -1
  69. package/lib/module/sksg/Recorder/Player.d.ts +1 -1
  70. package/lib/module/sksg/Recorder/Player.js.map +1 -1
  71. package/lib/module/sksg/Recorder/commands/Box.js +2 -2
  72. package/lib/module/sksg/Recorder/commands/Box.js.map +1 -1
  73. package/lib/module/sksg/Recorder/commands/Drawing.d.ts +1 -3
  74. package/lib/module/sksg/Recorder/commands/Drawing.js +2 -58
  75. package/lib/module/sksg/Recorder/commands/Drawing.js.map +1 -1
  76. package/lib/typescript/lib/commonjs/external/reanimated/textures.d.ts +1 -3
  77. package/lib/typescript/lib/commonjs/sksg/HostConfig.d.ts +1 -1
  78. package/lib/typescript/lib/commonjs/sksg/Recorder/commands/Drawing.d.ts +0 -1
  79. package/lib/typescript/lib/module/external/reanimated/textures.d.ts +1 -3
  80. package/lib/typescript/lib/module/sksg/HostConfig.d.ts +1 -1
  81. package/lib/typescript/lib/module/sksg/Recorder/commands/Drawing.d.ts +0 -1
  82. package/lib/typescript/src/external/reanimated/textures.d.ts +2 -4
  83. package/lib/typescript/src/renderer/Canvas.d.ts +1 -2
  84. package/lib/typescript/src/sksg/Recorder/Player.d.ts +1 -1
  85. package/lib/typescript/src/sksg/Recorder/commands/Drawing.d.ts +1 -3
  86. package/libs/android/arm64-v8a/libskia.a +0 -0
  87. package/libs/android/arm64-v8a/libskottie.a +0 -0
  88. package/libs/android/arm64-v8a/libskparagraph.a +0 -0
  89. package/libs/android/arm64-v8a/libsksg.a +0 -0
  90. package/libs/android/arm64-v8a/libskshaper.a +0 -0
  91. package/libs/android/arm64-v8a/libskunicode_icu.a +0 -0
  92. package/libs/android/arm64-v8a/libsvg.a +0 -0
  93. package/libs/android/armeabi-v7a/libskia.a +0 -0
  94. package/libs/android/armeabi-v7a/libskottie.a +0 -0
  95. package/libs/android/armeabi-v7a/libskparagraph.a +0 -0
  96. package/libs/android/armeabi-v7a/libsksg.a +0 -0
  97. package/libs/android/armeabi-v7a/libskshaper.a +0 -0
  98. package/libs/android/armeabi-v7a/libskunicode_icu.a +0 -0
  99. package/libs/android/armeabi-v7a/libsvg.a +0 -0
  100. package/libs/android/x86/libskia.a +0 -0
  101. package/libs/android/x86/libskottie.a +0 -0
  102. package/libs/android/x86/libskparagraph.a +0 -0
  103. package/libs/android/x86/libsksg.a +0 -0
  104. package/libs/android/x86/libskshaper.a +0 -0
  105. package/libs/android/x86/libskunicode_icu.a +0 -0
  106. package/libs/android/x86/libsvg.a +0 -0
  107. package/libs/android/x86_64/libskia.a +0 -0
  108. package/libs/android/x86_64/libskottie.a +0 -0
  109. package/libs/android/x86_64/libskparagraph.a +0 -0
  110. package/libs/android/x86_64/libsksg.a +0 -0
  111. package/libs/android/x86_64/libskshaper.a +0 -0
  112. package/libs/android/x86_64/libskunicode_icu.a +0 -0
  113. package/libs/android/x86_64/libsvg.a +0 -0
  114. package/libs/apple/libskia.xcframework/Info.plist +15 -15
  115. package/libs/apple/libskia.xcframework/ios-arm64_arm64e/libskia.a +0 -0
  116. package/libs/apple/libskia.xcframework/ios-arm64_arm64e_x86_64-simulator/libskia.a +0 -0
  117. package/libs/apple/libskia.xcframework/macos-arm64_x86_64/libskia.a +0 -0
  118. package/libs/apple/libskia.xcframework/tvos-arm64_arm64e/libskia.a +0 -0
  119. package/libs/apple/libskia.xcframework/tvos-arm64_arm64e_x86_64-simulator/libskia.a +0 -0
  120. package/libs/apple/libskottie.xcframework/Info.plist +7 -7
  121. package/libs/apple/libskottie.xcframework/ios-arm64_arm64e/libskottie.a +0 -0
  122. package/libs/apple/libskottie.xcframework/ios-arm64_arm64e_x86_64-simulator/libskottie.a +0 -0
  123. package/libs/apple/libskottie.xcframework/macos-arm64_x86_64/libskottie.a +0 -0
  124. package/libs/apple/libskottie.xcframework/tvos-arm64_arm64e/libskottie.a +0 -0
  125. package/libs/apple/libskottie.xcframework/tvos-arm64_arm64e_x86_64-simulator/libskottie.a +0 -0
  126. package/libs/apple/libskparagraph.xcframework/Info.plist +13 -13
  127. package/libs/apple/libskparagraph.xcframework/ios-arm64_arm64e/libskparagraph.a +0 -0
  128. package/libs/apple/libskparagraph.xcframework/ios-arm64_arm64e_x86_64-simulator/libskparagraph.a +0 -0
  129. package/libs/apple/libskparagraph.xcframework/macos-arm64_x86_64/libskparagraph.a +0 -0
  130. package/libs/apple/libskparagraph.xcframework/tvos-arm64_arm64e/libskparagraph.a +0 -0
  131. package/libs/apple/libskparagraph.xcframework/tvos-arm64_arm64e_x86_64-simulator/libskparagraph.a +0 -0
  132. package/libs/apple/libsksg.xcframework/Info.plist +13 -13
  133. package/libs/apple/libsksg.xcframework/ios-arm64_arm64e/libsksg.a +0 -0
  134. package/libs/apple/libsksg.xcframework/ios-arm64_arm64e_x86_64-simulator/libsksg.a +0 -0
  135. package/libs/apple/libsksg.xcframework/macos-arm64_x86_64/libsksg.a +0 -0
  136. package/libs/apple/libsksg.xcframework/tvos-arm64_arm64e/libsksg.a +0 -0
  137. package/libs/apple/libsksg.xcframework/tvos-arm64_arm64e_x86_64-simulator/libsksg.a +0 -0
  138. package/libs/apple/libskshaper.xcframework/Info.plist +14 -14
  139. package/libs/apple/libskshaper.xcframework/ios-arm64_arm64e/libskshaper.a +0 -0
  140. package/libs/apple/libskshaper.xcframework/ios-arm64_arm64e_x86_64-simulator/libskshaper.a +0 -0
  141. package/libs/apple/libskshaper.xcframework/macos-arm64_x86_64/libskshaper.a +0 -0
  142. package/libs/apple/libskshaper.xcframework/tvos-arm64_arm64e/libskshaper.a +0 -0
  143. package/libs/apple/libskshaper.xcframework/tvos-arm64_arm64e_x86_64-simulator/libskshaper.a +0 -0
  144. package/libs/apple/libskunicode_core.xcframework/Info.plist +12 -12
  145. package/libs/apple/libskunicode_core.xcframework/ios-arm64_arm64e/libskunicode_core.a +0 -0
  146. package/libs/apple/libskunicode_core.xcframework/ios-arm64_arm64e_x86_64-simulator/libskunicode_core.a +0 -0
  147. package/libs/apple/libskunicode_core.xcframework/macos-arm64_x86_64/libskunicode_core.a +0 -0
  148. package/libs/apple/libskunicode_core.xcframework/tvos-arm64_arm64e/libskunicode_core.a +0 -0
  149. package/libs/apple/libskunicode_core.xcframework/tvos-arm64_arm64e_x86_64-simulator/libskunicode_core.a +0 -0
  150. package/libs/apple/libskunicode_libgrapheme.xcframework/Info.plist +15 -15
  151. package/libs/apple/libskunicode_libgrapheme.xcframework/ios-arm64_arm64e/libskunicode_libgrapheme.a +0 -0
  152. package/libs/apple/libskunicode_libgrapheme.xcframework/ios-arm64_arm64e_x86_64-simulator/libskunicode_libgrapheme.a +0 -0
  153. package/libs/apple/libskunicode_libgrapheme.xcframework/macos-arm64_x86_64/libskunicode_libgrapheme.a +0 -0
  154. package/libs/apple/libskunicode_libgrapheme.xcframework/tvos-arm64_arm64e/libskunicode_libgrapheme.a +0 -0
  155. package/libs/apple/libskunicode_libgrapheme.xcframework/tvos-arm64_arm64e_x86_64-simulator/libskunicode_libgrapheme.a +0 -0
  156. package/libs/apple/libsvg.xcframework/Info.plist +8 -8
  157. package/libs/apple/libsvg.xcframework/ios-arm64_arm64e/libsvg.a +0 -0
  158. package/libs/apple/libsvg.xcframework/ios-arm64_arm64e_x86_64-simulator/libsvg.a +0 -0
  159. package/libs/apple/libsvg.xcframework/macos-arm64_x86_64/libsvg.a +0 -0
  160. package/libs/apple/libsvg.xcframework/tvos-arm64_arm64e/libsvg.a +0 -0
  161. package/libs/apple/libsvg.xcframework/tvos-arm64_arm64e_x86_64-simulator/libsvg.a +0 -0
  162. package/package.json +3 -3
  163. package/src/__tests__/snapshots/box/box-shadow-opacity.png +0 -0
  164. package/src/__tests__/snapshots/platform-buffer.png +0 -0
  165. package/src/__tests__/snapshots/screens/snapshot2-android-ci.png +0 -0
  166. package/src/external/reanimated/textures.tsx +12 -20
  167. package/src/renderer/Canvas.tsx +1 -1
  168. package/src/renderer/__tests__/e2e/Box.spec.tsx +22 -0
  169. package/src/renderer/__tests__/e2e/NativeBuffer.spec.tsx +2 -0
  170. package/src/sksg/HostConfig.ts +2 -1
  171. package/src/sksg/Recorder/Player.ts +1 -1
  172. package/src/sksg/Recorder/commands/Box.ts +2 -2
  173. package/src/sksg/Recorder/commands/Drawing.ts +0 -65
  174. package/cpp/skia/include/core/SkColorPriv.h +0 -165
  175. package/cpp/skia/include/private/SkColorData.h +0 -385
@@ -0,0 +1,41 @@
1
+ /*
2
+ * Copyright 2024 Google LLC
3
+ *
4
+ * Use of this source code is governed by a BSD-style license that can be
5
+ * found in the LICENSE file.
6
+ */
7
+ #ifndef SkPDFJPEGHelpers_DEFINED
8
+ #define SkPDFJPEGHelpers_DEFINED
9
+
10
+ #include "include/codec/SkJpegDecoder.h"
11
+ #include "include/core/SkData.h"
12
+ #include "include/core/SkRefCnt.h"
13
+ #include "include/docs/SkPDFDocument.h"
14
+ #include "include/encode/SkJpegEncoder.h"
15
+
16
+ class SkPixmap;
17
+ class SkWStream;
18
+
19
+ #include <memory>
20
+
21
+ namespace SkPDF::JPEG {
22
+ inline std::unique_ptr<SkCodec> Decode(sk_sp<SkData> data) {
23
+ return SkJpegDecoder::Decode(data, nullptr, nullptr);
24
+ }
25
+
26
+ inline bool Encode(SkWStream* dst, const SkPixmap& src, int quality) {
27
+ SkJpegEncoder::Options jOpts;
28
+ jOpts.fQuality = quality;
29
+ return SkJpegEncoder::Encode(dst, src, jOpts);
30
+ }
31
+
32
+ inline SkPDF::Metadata MetadataWithCallbacks() {
33
+ SkPDF::Metadata m;
34
+ m.jpegDecoder = SkPDF::JPEG::Decode;
35
+ m.jpegEncoder = SkPDF::JPEG::Encode;
36
+ return m;
37
+ }
38
+
39
+ } // namespace SkPDF::JPEG
40
+
41
+ #endif
@@ -126,6 +126,8 @@ public:
126
126
  // don't run the inliner directly, but they still get an inlining pass once they are
127
127
  // painted.)
128
128
  bool forceUnoptimized = false;
129
+ // When possible this name will be used to identify the created runtime effect.
130
+ std::string_view fName;
129
131
 
130
132
  private:
131
133
  friend class SkRuntimeEffect;
@@ -317,7 +319,9 @@ private:
317
319
  friend class SkRuntimeEffectPriv;
318
320
 
319
321
  uint32_t fHash;
320
- uint32_t fStableKey;
322
+ // When not 0, this field holds a StableKey value or a user-defined stable key
323
+ uint32_t fStableKey = 0;
324
+ SkString fName;
321
325
 
322
326
  std::unique_ptr<SkSL::Program> fBaseProgram;
323
327
  std::unique_ptr<SkSL::RP::Program> fRPProgram;
@@ -38,6 +38,10 @@ public:
38
38
  static SkMaskFilter* CreateClip(uint8_t min, uint8_t max);
39
39
 
40
40
  SkTableMaskFilter() = delete;
41
+
42
+ private:
43
+ static void RegisterFlattenables();
44
+ friend class SkFlattenable;
41
45
  };
42
46
 
43
47
  #endif
@@ -17,7 +17,6 @@
17
17
  namespace skgpu::graphite {
18
18
 
19
19
  class BackendTextureData;
20
- struct VulkanTextureInfo;
21
20
 
22
21
  class SK_API BackendTexture {
23
22
  public:
@@ -61,4 +60,3 @@ private:
61
60
  } // namespace skgpu::graphite
62
61
 
63
62
  #endif // skgpu_graphite_BackendTexture_DEFINED
64
-
@@ -9,12 +9,14 @@
9
9
  #define skgpu_graphite_ContextOptions_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
14
  #include "include/private/base/SkMath.h"
14
15
 
15
16
  #include <optional>
16
17
 
17
18
  class SkData;
19
+ class SkRuntimeEffect;
18
20
  namespace skgpu { class ShaderErrorHandler; }
19
21
 
20
22
  namespace skgpu::graphite {
@@ -136,6 +138,21 @@ struct SK_API ContextOptions {
136
138
  PipelineCallbackContext fPipelineCallbackContext = nullptr;
137
139
  PipelineCallback fPipelineCallback = nullptr;
138
140
 
141
+ /**
142
+ * The runtime effects provided here will be registered as user-defined *known* runtime
143
+ * effects and will be given a stable key. Such runtime effects can then be used in
144
+ * serialized pipeline keys (c.f. PrecompileContext::precompile).
145
+ *
146
+ * Graphite will take a ref on the provided runtime effects and they will persist for as long
147
+ * as the Context exists. Rather than recreating new SkRuntimeEffects using the same SkSL,
148
+ * clients should use the existing SkRuntimeEffects provided here.
149
+ *
150
+ * Warning: Registering runtime effects here does obligate users to clear out their caches
151
+ * of serialized pipeline keys if the provided runtime effects ever change in a meaningful way.
152
+ * This includes adding, removing or reordering the effects provided here.
153
+ */
154
+ SkSpan<sk_sp<SkRuntimeEffect>> fUserDefinedKnownRuntimeEffects;
155
+
139
156
  /**
140
157
  * Private options that are only meant for testing within Skia's tools.
141
158
  */
@@ -140,44 +140,47 @@ enum class DepthStencilFlags : int {
140
140
  */
141
141
  enum DrawTypeFlags : uint16_t {
142
142
 
143
- kNone = 0b000000000,
143
+ kNone = 0,
144
144
 
145
145
  // kBitmapText_Mask should be used for the BitmapTextRenderStep[mask] RenderStep
146
- kBitmapText_Mask = 0b00000001,
146
+ kBitmapText_Mask = 1 << 0,
147
147
  // kBitmapText_LCD should be used for the BitmapTextRenderStep[LCD] RenderStep
148
- kBitmapText_LCD = 0b00000010,
148
+ kBitmapText_LCD = 1 << 1,
149
149
  // kBitmapText_Color should be used for the BitmapTextRenderStep[color] RenderStep
150
- kBitmapText_Color = 0b00000100,
150
+ kBitmapText_Color = 1 << 2,
151
151
  // kSDFText should be used for the SDFTextRenderStep RenderStep
152
- kSDFText = 0b00001000,
152
+ kSDFText = 1 << 3,
153
153
  // kSDFText_LCD should be used for the SDFTextLCDRenderStep RenderStep
154
- kSDFText_LCD = 0b00010000,
154
+ kSDFText_LCD = 1 << 4,
155
155
 
156
156
  // kDrawVertices should be used to generate Pipelines that use the following RenderSteps:
157
157
  // VerticesRenderStep[*] for:
158
- // [tris], [tris-texCoords], [tris-color], [tris-color-texCoords],
159
- // [tristrips], [tristrips-texCoords], [tristrips-color], [tristrips-color-texCoords]
160
- kDrawVertices = 0b00100000,
158
+ // [Tris], [TrisTexCoords], [TrisColor], [TrisColorTexCoords],
159
+ // [Tristrips], [TristripsTexCoords], [TristripsColor], [TristripsColorTexCoords]
160
+ kDrawVertices = 1 << 5,
161
+
162
+ // kCircularArc renders filled circular arcs, with or without the center included, and
163
+ // stroked circular arcs with butt or round caps that don't include the center point.
164
+ // It corresponds to the CircularArcRenderStep.
165
+ kCircularArc = 1 << 6,
161
166
 
162
167
  // kSimpleShape should be used to generate Pipelines that use the following RenderSteps:
163
- // AnalyticBlurRenderStep
164
168
  // AnalyticRRectRenderStep
165
169
  // PerEdgeAAQuadRenderStep
166
- // CoverBoundsRenderStep[non-aa-fill]
167
- kSimpleShape = 0b01000000,
170
+ // CoverBoundsRenderStep[NonAAFill]
171
+ kSimpleShape = 1 << 7,
168
172
 
169
173
  // kNonSimpleShape should be used to generate Pipelines that use the following RenderSteps:
170
174
  // CoverageMaskRenderStep
171
- // CoverBoundsRenderStep[*] for [inverse-cover], [regular-cover]
175
+ // CoverBoundsRenderStep[*] for [InverseCover], [RegularCover]
172
176
  // TessellateStrokeRenderStep
173
- // TessellateWedgesRenderStep[*] for [convex], [evenodd], [winding]
174
- // TessellateCurvesRenderStep[*] for [even-odd], [winding]
175
- // MiddleOutFanRenderStep[*] for [even-odd], [winding]
176
- kNonSimpleShape = 0b10000000,
177
+ // TessellateWedgesRenderStep[*] for [Convex], [EvenOdd], [Winding]
178
+ // TessellateCurvesRenderStep[*] for [EvenOdd], [Winding]
179
+ // MiddleOutFanRenderStep[*] for [EvenOdd], [Winding]
180
+ kNonSimpleShape = 1 << 8,
177
181
 
178
182
  kLast = kNonSimpleShape,
179
183
  };
180
- static constexpr int kDrawTypeFlagsCnt = static_cast<int>(DrawTypeFlags::kLast) + 1;
181
184
 
182
185
  } // namespace skgpu::graphite
183
186
 
@@ -14,6 +14,8 @@
14
14
  #include <chrono>
15
15
  #include <memory>
16
16
 
17
+ class SkData;
18
+
17
19
  namespace skgpu::graphite {
18
20
 
19
21
  class SharedContext;
@@ -32,6 +34,28 @@ public:
32
34
  */
33
35
  void purgePipelinesNotUsedInMs(std::chrono::milliseconds msNotUsed);
34
36
 
37
+ /**
38
+ * Emit histograms (using the SK_HISTOGRAM* macros) for Skia's Pipeline usage.
39
+ */
40
+ void reportPipelineStats();
41
+
42
+ /**
43
+ * Precompile one specific Pipeline that has been previously serialized. Serialized pipeline
44
+ * keys can be acquired via the ContextOptions::PipelineCallback.
45
+ *
46
+ * @param serializedPipelineKey serialized Pipeline key.
47
+ * @return true if a Pipeline was created from the key; false otherwise
48
+ */
49
+ bool precompile(sk_sp<SkData> serializedPipelineKey);
50
+
51
+ /**
52
+ * Get a human-readable version of a serialized pipeline key.
53
+ *
54
+ * @param serializedPipelineKey serialized Pipeline key.
55
+ * @return A human-readable version of the provided key; "" on failure.
56
+ */
57
+ std::string getPipelineLabel(sk_sp<SkData> serializedPipelineKey);
58
+
35
59
  // Provides access to functions that aren't part of the public API.
36
60
  PrecompileContextPriv priv();
37
61
  const PrecompileContextPriv priv() const; // NOLINT(readability-const-return-type)
@@ -18,70 +18,115 @@ struct SkISize;
18
18
 
19
19
  namespace skgpu::graphite {
20
20
 
21
- class TextureInfoData;
21
+ enum class TextureFormat : uint8_t;
22
22
 
23
+ /**
24
+ * TextureInfo is a backend-agnostic wrapper around the properties of a texture, sans dimensions.
25
+ * It is designed this way to be compilable w/o bringing in a specific backend's build files, and
26
+ * without requiring heap allocations of virtual types.
27
+ */
23
28
  class SK_API TextureInfo {
29
+ private:
30
+ class Data;
31
+ friend class MtlTextureInfo;
32
+ friend class DawnTextureInfo;
33
+ friend class VulkanTextureInfo;
34
+
35
+ // Size is the largest of the Data subclasses assuming a 64-bit compiler.
36
+ inline constexpr static size_t kMaxSubclassSize = 112;
37
+ using AnyTextureInfoData = SkAnySubclass<Data, kMaxSubclassSize>;
38
+
39
+ // Base properties for all backend-specific properties. Clients managing textures directly
40
+ // should use the public subclasses of Data directly, e.g. MtlTextureInfo/DawnTextureInfo.
41
+ //
42
+ // Each backend subclass must expose to TextureInfo[Priv]:
43
+ // static constexpr BackendApi kBackend;
44
+ // Protected isProtected() const;
45
+ // TextureFormat viewFormat() const;
46
+ // bool serialize(SkWStream*) const;
47
+ // bool deserialize(SkStream*);
48
+ class Data {
49
+ public:
50
+ virtual ~Data() = default;
51
+
52
+ Data(uint32_t sampleCount, skgpu::Mipmapped mipmapped)
53
+ : fSampleCount(sampleCount)
54
+ , fMipmapped(mipmapped) {}
55
+
56
+ Data() = default;
57
+ Data(const Data&) = default;
58
+
59
+ Data& operator=(const Data&) = default;
60
+
61
+ // NOTE: These fields are accessible via the backend-specific subclasses.
62
+ uint32_t fSampleCount = 1;
63
+ Mipmapped fMipmapped = Mipmapped::kNo;
64
+
65
+ private:
66
+ friend class TextureInfo;
67
+ friend class TextureInfoPriv;
68
+
69
+ virtual SkString toBackendString() const = 0;
70
+
71
+ virtual void copyTo(AnyTextureInfoData&) const = 0;
72
+ // Passed in TextureInfo will have data of the same backend type and subclass, and
73
+ // base properties of Data have already been checked for equality/compatibility.
74
+ virtual bool isCompatible(const TextureInfo& that, bool requireExact) const = 0;
75
+ };
76
+
24
77
  public:
25
- TextureInfo();
26
- ~TextureInfo();
78
+ TextureInfo() = default;
79
+ ~TextureInfo() = default;
80
+
27
81
  TextureInfo(const TextureInfo&);
28
82
  TextureInfo& operator=(const TextureInfo&);
29
83
 
30
- bool operator==(const TextureInfo&) const;
84
+ bool operator==(const TextureInfo& that) const {
85
+ return this->isCompatible(that, /*requireExact=*/true);
86
+ }
31
87
  bool operator!=(const TextureInfo& that) const { return !(*this == that); }
32
88
 
33
- bool isValid() const { return fValid; }
34
- BackendApi backend() const { return fBackend; }
89
+ bool isValid() const { return fData.has_value(); }
90
+ BackendApi backend() const {
91
+ SkASSERT(fData.has_value() || fBackend == BackendApi::kUnsupported);
92
+ return fBackend;
93
+ }
35
94
 
36
- uint32_t numSamples() const { return fSampleCount; }
37
- Mipmapped mipmapped() const { return fMipmapped; }
95
+ uint32_t numSamples() const { return fData.has_value() ? fData->fSampleCount : 1; }
96
+ Mipmapped mipmapped() const { return fData.has_value() ? fData->fMipmapped : Mipmapped::kNo; }
38
97
  Protected isProtected() const { return fProtected; }
39
- SkTextureCompressionType compressionType() const;
40
- bool isMemoryless() const;
41
98
 
42
- bool isCompatible(const TextureInfo& that) const;
99
+ // Return true if `that` describes a texture that is compatible with this info and can validly
100
+ // be used to fulfill a promise image that was created with this TextureInfo.
101
+ bool canBeFulfilledBy(const TextureInfo& that) const {
102
+ return this->isCompatible(that, /*requireExact=*/false);
103
+ }
104
+
43
105
  // Return a string containing the full description of this TextureInfo.
44
106
  SkString toString() const;
45
- // Return a string containing only the info relevant for its use as a RenderPass attachment.
46
- SkString toRPAttachmentString() const;
47
107
 
48
108
  private:
49
- friend class TextureInfoData;
50
109
  friend class TextureInfoPriv;
51
110
 
52
- // Size determined by looking at the TextureInfoData subclasses, then guessing-and-checking.
53
- // Compiler will complain if this is too small - in that case, just increase the number.
54
- inline constexpr static size_t kMaxSubclassSize = 112;
55
- using AnyTextureInfoData = SkAnySubclass<TextureInfoData, kMaxSubclassSize>;
56
-
57
- template <typename SomeTextureInfoData>
58
- TextureInfo(BackendApi backend,
59
- uint32_t sampleCount,
60
- skgpu::Mipmapped mipped,
61
- skgpu::Protected isProtected,
62
- const SomeTextureInfoData& textureInfoData)
63
- : fBackend(backend)
64
- , fValid(true)
65
- , fSampleCount(sampleCount)
66
- , fMipmapped(mipped)
67
- , fProtected(isProtected) {
68
- fTextureInfoData.emplace<SomeTextureInfoData>(textureInfoData);
111
+ template <typename BackendTextureData,
112
+ std::enable_if_t<std::is_base_of_v<Data, BackendTextureData>, bool> = true>
113
+ explicit TextureInfo(const BackendTextureData& data)
114
+ : fBackend(BackendTextureData::kBackend)
115
+ , fViewFormat(data.viewFormat())
116
+ , fProtected(data.isProtected()) {
117
+ fData.emplace<BackendTextureData>(data);
69
118
  }
70
119
 
71
- friend size_t ComputeSize(SkISize dimensions, const TextureInfo&); // for bytesPerPixel
72
-
73
- size_t bytesPerPixel() const;
120
+ bool isCompatible(const TextureInfo& that, bool requireExact) const;
74
121
 
75
- BackendApi fBackend = BackendApi::kMock;
76
- bool fValid = false;
122
+ skgpu::BackendApi fBackend = BackendApi::kUnsupported;
123
+ AnyTextureInfoData fData;
77
124
 
78
- uint32_t fSampleCount = 1;
79
- Mipmapped fMipmapped = Mipmapped::kNo;
125
+ // Derived properties from the backend data, cached to avoid a virtual function call
126
+ TextureFormat fViewFormat;
80
127
  Protected fProtected = Protected::kNo;
81
-
82
- AnyTextureInfoData fTextureInfoData;
83
128
  };
84
129
 
85
- } // namespace skgpu::graphite
130
+ } // namespace skgpu::graphite
86
131
 
87
- #endif //skgpu_graphite_TextureInfo_DEFINED
132
+ #endif // skgpu_graphite_TextureInfo_DEFINED
@@ -37,10 +37,15 @@ public:
37
37
  * by Mipmapped. This will produce an invalid result (return false from isValid()) if the
38
38
  * passed formats' channels don't agree with SkYUVAInfo.
39
39
  */
40
- YUVABackendTextureInfo(const Recorder*,
41
- const SkYUVAInfo&,
40
+ YUVABackendTextureInfo(const SkYUVAInfo&,
42
41
  SkSpan<const TextureInfo>,
43
42
  Mipmapped);
43
+ // DEPRECATED: No more need for a Recorder to construct YUVABackendTextureInfo
44
+ YUVABackendTextureInfo(Recorder*,
45
+ const SkYUVAInfo& yuvaInfo,
46
+ SkSpan<const TextureInfo> textures,
47
+ Mipmapped mipmapped)
48
+ : YUVABackendTextureInfo(yuvaInfo, textures, mipmapped) {}
44
49
 
45
50
  bool operator==(const YUVABackendTextureInfo&) const;
46
51
  bool operator!=(const YUVABackendTextureInfo& that) const { return !(*this == that); }
@@ -95,9 +100,13 @@ public:
95
100
  * indicated by the SkYUVAInfo. This will produce an invalid result (return false from
96
101
  * isValid()) if the passed texture formats' channels don't agree with SkYUVAInfo.
97
102
  */
98
- YUVABackendTextures(const Recorder*,
99
- const SkYUVAInfo&,
103
+ YUVABackendTextures(const SkYUVAInfo&,
100
104
  SkSpan<const BackendTexture>);
105
+ // DEPRECATED: No more need for a Recorder to construct YUVABackendTextureInfo
106
+ YUVABackendTextures(Recorder*,
107
+ const SkYUVAInfo& yuvaInfo,
108
+ SkSpan<const BackendTexture> textures)
109
+ : YUVABackendTextures(yuvaInfo, textures) {}
101
110
 
102
111
  SkSpan<const BackendTexture> planeTextures() const {
103
112
  return SkSpan<const BackendTexture>(fPlaneTextures);
@@ -11,8 +11,13 @@
11
11
  #include "include/core/SkTypes.h"
12
12
  #include "webgpu/webgpu_cpp.h" // NO_G3_REWRITE
13
13
 
14
+ #include <memory>
15
+
14
16
  namespace skgpu::graphite {
15
17
 
18
+ class Context;
19
+ struct ContextOptions;
20
+
16
21
  /**
17
22
  * WebGPU needs to allow the main thread loop to run to detect GPU progress. Dawn native has a
18
23
  * function wgpu::Instance::ProcessEvents, not (currently) present in WebGPU, that can be used to
@@ -63,6 +68,10 @@ struct SK_API DawnBackendContext {
63
68
  #endif
64
69
  };
65
70
 
71
+ namespace ContextFactory {
72
+ SK_API std::unique_ptr<Context> MakeDawn(const DawnBackendContext&, const ContextOptions&);
73
+ } // namespace ContextFactory
74
+
66
75
  } // namespace skgpu::graphite
67
76
 
68
77
  #endif // skgpu_graphite_DawnBackendContext_DEFINED
@@ -0,0 +1,166 @@
1
+ /*
2
+ * Copyright 2025 Google LLC
3
+ *
4
+ * Use of this source code is governed by a BSD-style license that can be
5
+ * found in the LICENSE file.
6
+ */
7
+
8
+ #ifndef skgpu_graphite_DawnTypes_DEFINED
9
+ #define skgpu_graphite_DawnTypes_DEFINED
10
+
11
+ #include "include/core/SkSize.h"
12
+ #include "include/gpu/graphite/GraphiteTypes.h"
13
+ #include "include/gpu/graphite/TextureInfo.h"
14
+ #include "include/private/base/SkAPI.h"
15
+
16
+ #include "webgpu/webgpu_cpp.h" // NO_G3_REWRITE
17
+
18
+ class SkStream;
19
+ class SkWStream;
20
+
21
+ namespace skgpu::graphite {
22
+ class BackendTexture;
23
+
24
+ class SK_API DawnTextureInfo final : public TextureInfo::Data {
25
+ public:
26
+ // wgpu::TextureDescriptor properties
27
+ wgpu::TextureFormat fFormat = wgpu::TextureFormat::Undefined;
28
+ // `fViewFormat` for multiplanar formats corresponds to the plane TextureView's format.
29
+ wgpu::TextureFormat fViewFormat = wgpu::TextureFormat::Undefined;
30
+ wgpu::TextureUsage fUsage = wgpu::TextureUsage::None;
31
+ // TODO(b/308944094): Migrate aspect information to BackendTextureViews.
32
+ wgpu::TextureAspect fAspect = wgpu::TextureAspect::All;
33
+ uint32_t fSlice = 0;
34
+
35
+ #if !defined(__EMSCRIPTEN__)
36
+ // The descriptor of the YCbCr info (if any) for this texture. Dawn's YCbCr
37
+ // sampling will be used for this texture if this info is set. Setting the
38
+ // info is supported only on Android and only if using Vulkan as the
39
+ // underlying GPU driver.
40
+ wgpu::YCbCrVkDescriptor fYcbcrVkDescriptor = {};
41
+ #endif
42
+
43
+ wgpu::TextureFormat getViewFormat() const {
44
+ return fViewFormat != wgpu::TextureFormat::Undefined ? fViewFormat : fFormat;
45
+ }
46
+
47
+ DawnTextureInfo() = default;
48
+
49
+ DawnTextureInfo(WGPUTexture texture);
50
+
51
+ DawnTextureInfo(uint32_t sampleCount,
52
+ Mipmapped mipmapped,
53
+ wgpu::TextureFormat format,
54
+ wgpu::TextureUsage usage,
55
+ wgpu::TextureAspect aspect)
56
+ : DawnTextureInfo(sampleCount,
57
+ mipmapped,
58
+ /*format=*/format,
59
+ /*viewFormat=*/format,
60
+ usage,
61
+ aspect,
62
+ /*slice=*/0) {}
63
+
64
+ DawnTextureInfo(uint32_t sampleCount,
65
+ Mipmapped mipmapped,
66
+ wgpu::TextureFormat format,
67
+ wgpu::TextureFormat viewFormat,
68
+ wgpu::TextureUsage usage,
69
+ wgpu::TextureAspect aspect,
70
+ uint32_t slice)
71
+ : Data(sampleCount, mipmapped)
72
+ , fFormat(format)
73
+ , fViewFormat(viewFormat)
74
+ , fUsage(usage)
75
+ , fAspect(aspect)
76
+ , fSlice(slice) {}
77
+
78
+ #if !defined(__EMSCRIPTEN__)
79
+ DawnTextureInfo(uint32_t sampleCount,
80
+ Mipmapped mipmapped,
81
+ wgpu::TextureFormat format,
82
+ wgpu::TextureFormat viewFormat,
83
+ wgpu::TextureUsage usage,
84
+ wgpu::TextureAspect aspect,
85
+ uint32_t slice,
86
+ wgpu::YCbCrVkDescriptor ycbcrVkDescriptor)
87
+ : Data(sampleCount, mipmapped)
88
+ , fFormat(format)
89
+ , fViewFormat(viewFormat)
90
+ , fUsage(usage)
91
+ , fAspect(aspect)
92
+ , fSlice(slice)
93
+ , fYcbcrVkDescriptor(ycbcrVkDescriptor) {}
94
+ #endif
95
+
96
+ private:
97
+ friend class TextureInfo;
98
+ friend class TextureInfoPriv;
99
+
100
+ // Non-virtual template API for TextureInfo::Data accessed directly when backend type is known.
101
+ static constexpr skgpu::BackendApi kBackend = skgpu::BackendApi::kDawn;
102
+
103
+ Protected isProtected() const { return Protected::kNo; }
104
+ TextureFormat viewFormat() const;
105
+
106
+ bool serialize(SkWStream*) const;
107
+ bool deserialize(SkStream*);
108
+
109
+ // Virtual API when the specific backend type is not available.
110
+ SkString toBackendString() const override;
111
+
112
+ void copyTo(TextureInfo::AnyTextureInfoData& dstData) const override {
113
+ dstData.emplace<DawnTextureInfo>(*this);
114
+ }
115
+ bool isCompatible(const TextureInfo& that, bool requireExact) const override;
116
+ };
117
+
118
+ namespace TextureInfos {
119
+ SK_API TextureInfo MakeDawn(const DawnTextureInfo& dawnInfo);
120
+
121
+ SK_API bool GetDawnTextureInfo(const TextureInfo&, DawnTextureInfo*);
122
+ } // namespace TextureInfos
123
+
124
+ namespace BackendTextures {
125
+ // Create a BackendTexture from a WGPUTexture. Texture info will be queried from the texture.
126
+ //
127
+ // This is the recommended way of specifying a BackendTexture for Dawn. See the note below on
128
+ // the constructor that takes a WGPUTextureView for a fuller explanation.
129
+ //
130
+ // The BackendTexture will not call retain or release on the passed in WGPUTexture. Thus, the
131
+ // client must keep the WGPUTexture valid until they are no longer using the BackendTexture.
132
+ // However, any SkImage or SkSurface that wraps the BackendTexture *will* retain and release
133
+ // the WGPUTexture.
134
+ SK_API BackendTexture MakeDawn(WGPUTexture);
135
+
136
+ // Create a BackendTexture from a WGPUTexture. Texture planeDimensions, plane aspect and
137
+ // info have to be provided. This is intended to be used only when accessing a plane
138
+ // of a WGPUTexture.
139
+ //
140
+ // The BackendTexture will not call retain or release on the passed in WGPUTexture. Thus, the
141
+ // client must keep the WGPUTexture valid until they are no longer using the BackendTexture.
142
+ // However, any SkImage or SkSurface that wraps the BackendTexture *will* retain and release
143
+ // the WGPUTexture.
144
+ SK_API BackendTexture MakeDawn(SkISize planeDimensions, const DawnTextureInfo&, WGPUTexture);
145
+
146
+ // Create a BackendTexture from a WGPUTextureView. Texture dimensions and
147
+ // info have to be provided.
148
+ //
149
+ // Using a WGPUTextureView rather than a WGPUTexture is less effecient for operations that
150
+ // require buffer transfers to or from the texture (e.g. methods on graphite::Context that read
151
+ // pixels or SkSurface::writePixels). In such cases an intermediate copy to or from a
152
+ // WGPUTexture is required. Thus, it is recommended to use this functionality only for cases
153
+ // where a WGPUTexture is unavailable, in particular when using wgpu::SwapChain.
154
+ //
155
+ // The BackendTexture will not call retain or release on the passed in WGPUTextureView. Thus,
156
+ // the client must keep the WGPUTextureView valid until they are no longer using the
157
+ // BackendTexture. However, any SkImage or SkSurface that wraps the BackendTexture *will* retain
158
+ // and release the WGPUTextureView.
159
+ SK_API BackendTexture MakeDawn(SkISize dimensions,
160
+ const DawnTextureInfo& info,
161
+ WGPUTextureView textureView);
162
+ } // namespace BackendTextures
163
+
164
+ } // namespace skgpu::graphite
165
+
166
+ #endif // skgpu_graphite_DawnTypes_DEFINED