@shopify/react-native-skia 2.4.6 → 2.4.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (143) hide show
  1. package/android/cpp/jni/JniPlatformContext.cpp +1 -1
  2. package/android/src/main/java/com/shopify/reactnative/skia/ViewScreenshotService.java +11 -1
  3. package/apple/RNSkApplePlatformContext.h +4 -0
  4. package/apple/RNSkApplePlatformContext.mm +69 -0
  5. package/apple/SkiaCVPixelBufferUtils.mm +8 -4
  6. package/cpp/api/JsiSkFontMgr.h +30 -6
  7. package/cpp/api/JsiSkImageFilterFactory.h +4 -2
  8. package/cpp/api/JsiSkPictureFactory.h +9 -6
  9. package/cpp/api/recorder/RNRecorder.h +33 -55
  10. package/cpp/rnskia/RNSkPictureView.h +7 -5
  11. package/cpp/rnskia/RNSkPlatformContext.h +16 -0
  12. package/cpp/skia/include/codec/SkAndroidCodec.h +3 -2
  13. package/cpp/skia/include/codec/SkAvifDecoder.h +2 -2
  14. package/cpp/skia/include/codec/SkBmpDecoder.h +1 -1
  15. package/cpp/skia/include/codec/SkCodec.h +2 -8
  16. package/cpp/skia/include/codec/SkEncodedOrigin.h +17 -0
  17. package/cpp/skia/include/codec/SkGifDecoder.h +1 -1
  18. package/cpp/skia/include/codec/SkIcoDecoder.h +1 -1
  19. package/cpp/skia/include/codec/SkJpegDecoder.h +8 -1
  20. package/cpp/skia/include/codec/SkJpegxlDecoder.h +1 -1
  21. package/cpp/skia/include/codec/SkPngDecoder.h +8 -1
  22. package/cpp/skia/include/codec/SkRawDecoder.h +1 -1
  23. package/cpp/skia/include/codec/SkWbmpDecoder.h +1 -1
  24. package/cpp/skia/include/codec/SkWebpDecoder.h +8 -1
  25. package/cpp/skia/include/core/SkCPURecorder.h +1 -0
  26. package/cpp/skia/include/core/SkCanvas.h +3 -2
  27. package/cpp/skia/include/core/SkColorTable.h +1 -1
  28. package/cpp/skia/include/core/SkColorType.h +4 -0
  29. package/cpp/skia/include/core/SkDocument.h +1 -1
  30. package/cpp/skia/include/core/SkGraphics.h +7 -2
  31. package/cpp/skia/include/core/SkImage.h +5 -1
  32. package/cpp/skia/include/core/SkImageGenerator.h +5 -3
  33. package/cpp/skia/include/core/SkM44.h +3 -3
  34. package/cpp/skia/include/core/SkMatrix.h +0 -23
  35. package/cpp/skia/include/core/SkMilestone.h +1 -1
  36. package/cpp/skia/include/core/SkOverdrawCanvas.h +1 -1
  37. package/cpp/skia/include/core/SkPath.h +216 -185
  38. package/cpp/skia/include/core/SkPathBuilder.h +97 -47
  39. package/cpp/skia/include/core/SkPathTypes.h +7 -1
  40. package/cpp/skia/include/core/SkPixmap.h +8 -8
  41. package/cpp/skia/include/core/SkRRect.h +24 -3
  42. package/cpp/skia/include/core/SkRecorder.h +3 -1
  43. package/cpp/skia/include/core/SkScalar.h +1 -1
  44. package/cpp/skia/include/core/SkSerialProcs.h +8 -4
  45. package/cpp/skia/include/core/SkStream.h +16 -9
  46. package/cpp/skia/include/core/SkString.h +1 -1
  47. package/cpp/skia/include/core/SkStrokeRec.h +1 -1
  48. package/cpp/skia/include/core/SkYUVAInfo.h +3 -0
  49. package/cpp/skia/include/docs/SkPDFDocument.h +1 -1
  50. package/cpp/skia/include/docs/SkPDFJpegHelpers.h +1 -1
  51. package/cpp/skia/include/docs/SkXPSDocument.h +18 -2
  52. package/cpp/skia/include/effects/SkRuntimeEffect.h +3 -1
  53. package/cpp/skia/include/encode/SkPngRustEncoder.h +18 -0
  54. package/cpp/skia/include/gpu/ganesh/GrBackendSurface.h +1 -1
  55. package/cpp/skia/include/gpu/ganesh/GrExternalTextureGenerator.h +1 -1
  56. package/cpp/skia/include/gpu/ganesh/GrRecordingContext.h +7 -6
  57. package/cpp/skia/include/gpu/ganesh/gl/GrGLBackendSurface.h +6 -0
  58. package/cpp/skia/include/gpu/ganesh/vk/GrBackendDrawableInfo.h +2 -4
  59. package/cpp/skia/include/gpu/graphite/Context.h +15 -1
  60. package/cpp/skia/include/gpu/graphite/ContextOptions.h +52 -11
  61. package/cpp/skia/include/gpu/graphite/GraphiteTypes.h +44 -0
  62. package/cpp/skia/include/gpu/graphite/LogPriority.h +1 -1
  63. package/cpp/skia/include/gpu/graphite/PersistentPipelineStorage.h +45 -0
  64. package/cpp/skia/include/gpu/graphite/PrecompileContext.h +1 -1
  65. package/cpp/skia/include/gpu/graphite/Recorder.h +14 -0
  66. package/cpp/skia/include/gpu/graphite/TextureInfo.h +13 -5
  67. package/cpp/skia/include/gpu/graphite/dawn/DawnGraphiteTypes.h +1 -4
  68. package/cpp/skia/include/gpu/graphite/mtl/MtlGraphiteTypes.h +1 -4
  69. package/cpp/skia/include/gpu/graphite/vk/VulkanGraphiteTypes.h +2 -8
  70. package/cpp/skia/include/gpu/vk/VulkanExtensions.h +1 -1
  71. package/cpp/skia/include/gpu/vk/VulkanTypes.h +124 -9
  72. package/cpp/skia/include/ports/SkFontMgr_fuchsia.h +3 -1
  73. package/cpp/skia/include/ports/SkImageGeneratorCG.h +1 -1
  74. package/cpp/skia/include/ports/SkImageGeneratorNDK.h +1 -1
  75. package/cpp/skia/include/ports/SkImageGeneratorWIC.h +1 -1
  76. package/cpp/skia/include/ports/SkTypeface_fontations.h +1 -1
  77. package/cpp/skia/include/private/SkEncodedInfo.h +38 -29
  78. package/cpp/skia/include/private/SkJpegMetadataDecoder.h +18 -13
  79. package/cpp/skia/include/private/SkPathRef.h +3 -6
  80. package/cpp/skia/include/private/base/SkAlign.h +3 -7
  81. package/cpp/skia/include/private/base/SkContainers.h +1 -1
  82. package/cpp/skia/include/private/base/SkSpan_impl.h +29 -0
  83. package/cpp/skia/include/private/base/SkTArray.h +7 -8
  84. package/cpp/skia/include/private/base/SkTDArray.h +4 -4
  85. package/cpp/skia/include/private/base/SkTemplates.h +5 -5
  86. package/cpp/skia/include/private/chromium/GrDeferredDisplayListRecorder.h +1 -1
  87. package/cpp/skia/include/private/gpu/ganesh/GrContext_Base.h +1 -1
  88. package/cpp/skia/include/private/gpu/ganesh/GrImageContext.h +1 -1
  89. package/cpp/skia/include/private/gpu/ganesh/GrTypesPriv.h +6 -5
  90. package/cpp/skia/include/svg/SkSVGCanvas.h +21 -1
  91. package/cpp/skia/include/utils/SkNoDrawCanvas.h +1 -1
  92. package/cpp/skia/include/utils/SkPaintFilterCanvas.h +1 -1
  93. package/cpp/skia/modules/skcms/src/skcms_public.h +29 -4
  94. package/cpp/skia/modules/skottie/include/Skottie.h +11 -0
  95. package/cpp/skia/modules/skottie/include/SlotManager.h +1 -1
  96. package/cpp/skia/modules/skparagraph/include/Metrics.h +1 -1
  97. package/cpp/skia/modules/skparagraph/include/Paragraph.h +1 -1
  98. package/cpp/skia/modules/sksg/include/SkSGMerge.h +1 -1
  99. package/cpp/skia/modules/sksg/include/SkSGPath.h +1 -1
  100. package/cpp/skia/modules/skshaper/include/SkShaper.h +2 -0
  101. package/cpp/skia/modules/skunicode/include/SkUnicode.h +4 -4
  102. package/cpp/skia/modules/svg/include/SkSVGAttributeParser.h +1 -1
  103. package/cpp/skia/modules/svg/include/SkSVGFeComponentTransfer.h +1 -1
  104. package/cpp/skia/modules/svg/include/SkSVGNode.h +1 -1
  105. package/cpp/skia/modules/svg/include/SkSVGPoly.h +1 -1
  106. package/cpp/skia/modules/svg/include/SkSVGShape.h +1 -1
  107. package/cpp/skia/modules/svg/include/SkSVGTransformableNode.h +1 -1
  108. package/cpp/skia/modules/svg/include/SkSVGValue.h +1 -1
  109. package/lib/commonjs/skia/core/Font.js +7 -1
  110. package/lib/commonjs/skia/core/Font.js.map +1 -1
  111. package/lib/commonjs/skia/web/JsiSkCanvas.d.ts +1 -1
  112. package/lib/commonjs/skia/web/JsiSkCanvas.js +1 -7
  113. package/lib/commonjs/skia/web/JsiSkCanvas.js.map +1 -1
  114. package/lib/commonjs/specs/SkiaPictureViewNativeComponent.web.d.ts +1 -1
  115. package/lib/commonjs/views/SkiaPictureView.web.d.ts +4 -1
  116. package/lib/commonjs/views/SkiaPictureView.web.js +7 -2
  117. package/lib/commonjs/views/SkiaPictureView.web.js.map +1 -1
  118. package/lib/module/skia/core/Font.js +7 -1
  119. package/lib/module/skia/core/Font.js.map +1 -1
  120. package/lib/module/skia/web/JsiSkCanvas.d.ts +1 -1
  121. package/lib/module/skia/web/JsiSkCanvas.js +1 -7
  122. package/lib/module/skia/web/JsiSkCanvas.js.map +1 -1
  123. package/lib/module/specs/SkiaPictureViewNativeComponent.web.d.ts +1 -1
  124. package/lib/module/views/SkiaPictureView.web.d.ts +4 -1
  125. package/lib/module/views/SkiaPictureView.web.js +7 -3
  126. package/lib/module/views/SkiaPictureView.web.js.map +1 -1
  127. package/lib/typescript/lib/commonjs/skia/core/Font.d.ts +1 -1
  128. package/lib/typescript/lib/commonjs/skia/web/JsiSkCanvas.d.ts +1 -1
  129. package/lib/typescript/lib/commonjs/specs/SkiaPictureViewNativeComponent.web.d.ts +1 -11
  130. package/lib/typescript/lib/commonjs/views/SkiaPictureView.web.d.ts +1 -1
  131. package/lib/typescript/lib/module/mock/index.d.ts +1 -1
  132. package/lib/typescript/lib/module/skia/core/Font.d.ts +1 -1
  133. package/lib/typescript/lib/module/skia/web/JsiSkCanvas.d.ts +1 -1
  134. package/lib/typescript/lib/module/specs/SkiaPictureViewNativeComponent.web.d.ts +1 -1
  135. package/lib/typescript/lib/module/views/SkiaPictureView.web.d.ts +1 -1
  136. package/lib/typescript/src/skia/web/JsiSkCanvas.d.ts +1 -1
  137. package/lib/typescript/src/specs/SkiaPictureViewNativeComponent.web.d.ts +1 -1
  138. package/lib/typescript/src/views/SkiaPictureView.web.d.ts +4 -1
  139. package/package.json +8 -8
  140. package/scripts/install-skia.mjs +74 -1
  141. package/src/skia/core/Font.ts +9 -4
  142. package/src/skia/web/JsiSkCanvas.ts +1 -3
  143. package/src/views/SkiaPictureView.web.tsx +8 -7
@@ -15,13 +15,29 @@
15
15
  #include "include/core/SkDocument.h"
16
16
 
17
17
  struct IXpsOMObjectFactory;
18
+ class SKWStream;
19
+ class SkPixmap;
18
20
 
19
21
  namespace SkXPS {
20
22
 
23
+ using EncodePngCallback = bool (*)(SkWStream* dst, const SkPixmap& src);
24
+
25
+ struct Options {
26
+ float dpi = SK_ScalarDefaultRasterDPI;
27
+
28
+ /** Clients can provide a way to encode png. */
29
+ EncodePngCallback pngEncoder = nullptr;
30
+
31
+ /** Skia's XPS support depends on having a png encoder registered to handle
32
+ * XPS image brushes. Clients that create XPS documents without images may
33
+ * set `allowNoPngs` to true to acknowledge this.
34
+ */
35
+ bool allowNoPngs = false;
36
+ };
37
+
21
38
  SK_API sk_sp<SkDocument> MakeDocument(SkWStream* stream,
22
39
  IXpsOMObjectFactory* xpsFactory,
23
- SkScalar dpi = SK_ScalarDefaultRasterDPI);
24
-
40
+ Options opts);
25
41
  } // namespace SkXPS
26
42
  #endif // SK_BUILD_FOR_WIN
27
43
  #endif // SkXPSDocument_DEFINED
@@ -189,6 +189,7 @@ public:
189
189
  class SK_API ChildPtr {
190
190
  public:
191
191
  ChildPtr() = default;
192
+ // Intentionally don't declare these to be explicit for convenience.
192
193
  ChildPtr(sk_sp<SkShader> s) : fChild(std::move(s)) {}
193
194
  ChildPtr(sk_sp<SkColorFilter> cf) : fChild(std::move(cf)) {}
194
195
  ChildPtr(sk_sp<SkBlender> b) : fChild(std::move(b)) {}
@@ -433,7 +434,8 @@ public:
433
434
  if (!fChild) {
434
435
  SkDEBUGFAIL("Assigning to missing child");
435
436
  } else {
436
- fOwner->fChildren[(size_t)fChild->index] = std::move(val);
437
+ fOwner->fChildren[(size_t)fChild->index] =
438
+ SkRuntimeEffect::ChildPtr(std::move(val));
437
439
  }
438
440
  return *this;
439
441
  }
@@ -14,7 +14,10 @@
14
14
  #include "include/core/SkRefCnt.h"
15
15
  #include "include/private/base/SkAPI.h"
16
16
 
17
+ class GrDirectContext;
18
+ class SkData;
17
19
  class SkEncoder;
20
+ class SkImage;
18
21
  class SkPixmap;
19
22
  class SkWStream;
20
23
 
@@ -71,6 +74,21 @@ struct Options {
71
74
  */
72
75
  SK_API bool Encode(SkWStream* dst, const SkPixmap& src, const Options& options);
73
76
 
77
+ /**
78
+ * Returns the encoded data for the pixmap, or nullptr on failure.
79
+ */
80
+ SK_API sk_sp<SkData> Encode(const SkPixmap& src, const Options& options);
81
+
82
+ /**
83
+ * Encode the provided image and return the resulting bytes. If the image was created as
84
+ * a texture-backed image on a GPU context, that |ctx| must be provided so the pixels
85
+ * can be read before being encoded. For raster-backed images, |ctx| can be nullptr.
86
+ * |options| may be used to control the encoding behavior.
87
+ *
88
+ * Returns nullptr if the pixels could not be read or encoding otherwise fails.
89
+ */
90
+ SK_API sk_sp<SkData> Encode(GrDirectContext* ctx, const SkImage* img, const Options& options);
91
+
74
92
  /**
75
93
  * Create a png encoder that will encode the |src| pixels to the |dst| stream.
76
94
  * |options| may be used to control the encoding behavior.
@@ -120,7 +120,7 @@ private:
120
120
  }
121
121
 
122
122
  #ifdef SK_DIRECT3D
123
- GrBackendFormat(DXGI_FORMAT dxgiFormat);
123
+ explicit GrBackendFormat(DXGI_FORMAT dxgiFormat);
124
124
  #endif
125
125
 
126
126
  GrBackendFormat(GrColorType, SkTextureCompressionType, bool isStencilFormat);
@@ -31,7 +31,7 @@ public:
31
31
 
32
32
  class SK_API GrExternalTextureGenerator : public GrTextureGenerator {
33
33
  public:
34
- GrExternalTextureGenerator(const SkImageInfo& info);
34
+ explicit GrExternalTextureGenerator(const SkImageInfo& info);
35
35
 
36
36
  GrSurfaceProxyView onGenerateTexture(GrRecordingContext*,
37
37
  const SkImageInfo&,
@@ -63,12 +63,13 @@ public:
63
63
  * use maxSurfaceSampleCountForColorType().
64
64
  */
65
65
  SK_API bool colorTypeSupportedAsSurface(SkColorType colorType) const {
66
- if (kR16G16_unorm_SkColorType == colorType ||
67
- kA16_unorm_SkColorType == colorType ||
68
- kA16_float_SkColorType == colorType ||
69
- kR16G16_float_SkColorType == colorType ||
70
- kR16G16B16A16_unorm_SkColorType == colorType ||
71
- kGray_8_SkColorType == colorType) {
66
+ if (colorType == kR16G16_unorm_SkColorType ||
67
+ colorType == kA16_unorm_SkColorType ||
68
+ colorType == kA16_float_SkColorType ||
69
+ colorType == kR16_unorm_SkColorType ||
70
+ colorType == kR16G16_float_SkColorType ||
71
+ colorType == kR16G16B16A16_unorm_SkColorType ||
72
+ colorType == kGray_8_SkColorType) {
72
73
  return false;
73
74
  }
74
75
 
@@ -20,8 +20,14 @@ class GrBackendRenderTarget;
20
20
  namespace skgpu { enum class Mipmapped : bool; }
21
21
 
22
22
  namespace GrBackendFormats {
23
+
24
+ // DEPRECATED: Prefer MakeGL(format) for GL_TEXTURE_2D targets and MakeGLExternal() for
25
+ // GL_TEXTURE_EXTERNAL targets.
23
26
  SK_API GrBackendFormat MakeGL(GrGLenum format, GrGLenum target);
24
27
 
28
+ SK_API GrBackendFormat MakeGL(GrGLenum format); // For GL_TEXTURE_2D textures
29
+ SK_API GrBackendFormat MakeGLExternal(); // For GL_TEXTURE_EXTERNAL textures
30
+
25
31
  SK_API GrGLFormat AsGLFormat(const GrBackendFormat&);
26
32
  SK_API GrGLenum AsGLFormatEnum(const GrBackendFormat&);
27
33
  } // namespace GrBackendFormats
@@ -19,10 +19,8 @@ public:
19
19
  // Creates an invalid backend drawable info.
20
20
  GrBackendDrawableInfo() : fIsValid(false) {}
21
21
 
22
- GrBackendDrawableInfo(const GrVkDrawableInfo& info)
23
- : fIsValid(true)
24
- , fBackend(GrBackendApi::kVulkan)
25
- , fVkInfo(info) {}
22
+ explicit GrBackendDrawableInfo(const GrVkDrawableInfo& info)
23
+ : fIsValid(true), fBackend(GrBackendApi::kVulkan), fVkInfo(info) {}
26
24
 
27
25
  // Returns true if the backend texture has been initialized.
28
26
  bool isValid() const { return fIsValid; }
@@ -31,6 +31,7 @@
31
31
 
32
32
  class SkColorInfo;
33
33
  class SkSurface;
34
+ class SkCapture;
34
35
  enum SkYUVColorSpace : int;
35
36
  class SkColorSpace;
36
37
  class SkTraceMemoryDump;
@@ -54,6 +55,7 @@ class Buffer;
54
55
  class ClientMappedBufferManager;
55
56
  class ContextPriv;
56
57
  struct ContextOptions;
58
+ class PersistentPipelineStorage;
57
59
  class PrecompileContext;
58
60
  class QueueManager;
59
61
  class ResourceProvider;
@@ -277,6 +279,16 @@ public:
277
279
  */
278
280
  GpuStatsFlags supportedGpuStats() const;
279
281
 
282
+ /**
283
+ * If supported by the backend, stores the current pipeline cache data into the
284
+ * PersistentPipelineStorage-derived object passed into Graphite via
285
+ * ContextOptions::fPersistentPipelineStorage. The amount stored is limited to 'maxSize'.
286
+ *
287
+ * Skia attempts to only call store() on the PersistentPipelineStorage object when the data
288
+ * is likely to be different from what was last sync'ed.
289
+ */
290
+ void syncPipelineData(size_t maxSize = SIZE_MAX);
291
+
280
292
  /*
281
293
  * TODO (b/412351769): Do not use startCapture() or endCapture() as the feature is still under
282
294
  * development.
@@ -288,7 +300,7 @@ public:
288
300
  /*
289
301
  * Ends the SkCapture and returns the collected draws and surface creation.
290
302
  */
291
- void endCapture();
303
+ sk_sp<SkCapture> endCapture();
292
304
 
293
305
  // Provides access to functions that aren't part of the public API.
294
306
  ContextPriv priv();
@@ -395,6 +407,8 @@ private:
395
407
  std::unique_ptr<ClientMappedBufferManager> fMappedBufferManager;
396
408
  std::unique_ptr<const skcpu::ContextImpl> fCPUContext;
397
409
 
410
+ PersistentPipelineStorage* fPersistentPipelineStorage;
411
+
398
412
  // In debug builds we guard against improper thread handling. This guard is passed to the
399
413
  // ResourceCache for the Context.
400
414
  mutable SingleOwner fSingleOwner;
@@ -15,6 +15,7 @@
15
15
  #include "include/private/base/SkMath.h"
16
16
 
17
17
  #include <optional>
18
+ #include <string>
18
19
 
19
20
  class SkData;
20
21
  class SkExecutor;
@@ -24,6 +25,7 @@ namespace skgpu { class ShaderErrorHandler; }
24
25
  namespace skgpu::graphite {
25
26
 
26
27
  struct ContextOptionsPriv;
28
+ class PersistentPipelineStorage;
27
29
 
28
30
  struct SK_API ContextOptions {
29
31
  ContextOptions() {}
@@ -141,7 +143,7 @@ struct SK_API ContextOptions {
141
143
  /**
142
144
  * If Skia is creating a default VMA allocator for the Vulkan backend this value will be used
143
145
  * for the preferredLargeHeapBlockSize. If the value is not set, then Skia will use an
144
- * inernally defined default size.
146
+ * internally defined default size.
145
147
  *
146
148
  * However, it is highly discouraged to have Skia make a default allocator (and support for
147
149
  * doing so will be removed soon, b/321962001). Instead clients should create their own
@@ -149,20 +151,52 @@ struct SK_API ContextOptions {
149
151
  */
150
152
  std::optional<uint64_t> fVulkanVMALargeHeapBlockSize;
151
153
 
152
- /** Client-provided context that is passed to client-provided PipelineCallback. */
154
+ /**
155
+ * Client-provided context that is passed to the client-provided PipelineCachingCallback
156
+ * and the (deprecated) PipelineCallback.
157
+ */
153
158
  using PipelineCallbackContext = void*;
154
- /** Client-provided callback that is called whenever Graphite encounters a new Pipeline. */
155
- using PipelineCallback = void (*)(PipelineCallbackContext context, sk_sp<SkData> pipelineData);
159
+
160
+ PipelineCallbackContext fPipelineCallbackContext = nullptr;
161
+
162
+ enum class PipelineCacheOp {
163
+ kAddingPipeline,
164
+ kPipelineFound,
165
+ };
166
+
167
+ using PipelineCachingCallback = void (*)(PipelineCallbackContext context,
168
+ PipelineCacheOp op,
169
+ const std::string& label,
170
+ uint32_t uniqueKeyHash,
171
+ bool fromPrecompile,
172
+ sk_sp<SkData> pipelineData);
173
+
174
+ /**
175
+ * This member variable allows a client to register a callback that will be invoked
176
+ * whenever Graphite either adds a Pipeline to its cache (kAddingPipeline op) or finds an
177
+ * existing Pipeline in its cache (kPipelineFound op). Together this allows clients
178
+ * to determine the frequency of a given Pipeline's use and which precompiled Pipelines
179
+ * are unused. The callback is also passed:
180
+ * a human-readable label that describes the Pipeline
181
+ * a 32-bit hash code that can be used rather than rehashing the provided data
182
+ * a Boolean indicating if the Pipeline had been generated via Precompilation
183
+ * Additionally, for kAddingPipeline ops:
184
+ * an SkData version of the Pipeline that a client can take ownership of and serialize.
185
+ * Not all Pipelines can be serialized, however, and nullptr will be passed in such cases.
186
+ *
187
+ * When provided, the SkData contains all the information Graphite requires to recreate
188
+ * the Pipeline at a later date, but it is versioned so recreation can fail if it's
189
+ * incompatible with a newer version of Skia.
190
+ */
191
+ PipelineCachingCallback fPipelineCachingCallback = nullptr;
156
192
 
157
193
  /**
158
- * These two members allow a client to register a callback that will be invoked
159
- * whenever Graphite encounters a new Pipeline. The callback will be passed an
160
- * sk_sp<SkData> that a client can take ownership of and serialize. The SkData
161
- * contains all the information Graphite requires to recreate the Pipeline at
162
- * a later date. The SkData is versioned however, so must be regenerated and
163
- * re-serialized when it becomes out of date.
194
+ * Deprecated version of the Pipeline callback. This callback is only invoked for
195
+ * PipelineCacheOp::kAddingPipeline ops and when the key is serializable. It is ignored
196
+ * if fPipelineCachingCallback is set.
164
197
  */
165
- PipelineCallbackContext fPipelineCallbackContext = nullptr;
198
+ using PipelineCallback = void (*)(PipelineCallbackContext context, sk_sp<SkData> pipelineData);
199
+
166
200
  PipelineCallback fPipelineCallback = nullptr;
167
201
 
168
202
  /**
@@ -189,6 +223,13 @@ struct SK_API ContextOptions {
189
223
  */
190
224
  SkExecutor* fExecutor = nullptr;
191
225
 
226
+ /**
227
+ * Allows Graphite to store Pipeline data across Context lifetimes. It is up to the
228
+ * client to ensure the PersistentPipelineStorage object remains valid throughout the lifetime
229
+ * of the Context(s).
230
+ */
231
+ PersistentPipelineStorage* fPersistentPipelineStorage = nullptr;
232
+
192
233
  /**
193
234
  * An experimental flag in development. Behavior and performance is subject to change.
194
235
  *
@@ -209,6 +209,50 @@ enum class DepthStencilFlags : int {
209
209
  kDepthStencil = kDepth | kStencil,
210
210
  };
211
211
 
212
+ // NOTE: This can be converted to just an `enum class SampleCount {}` once clients are migrated
213
+ // off of writing integer values into backend TextureInfo fields or ContextOptions.
214
+ class SampleCount {
215
+ public:
216
+ // Do not refer to V directly; use these constants as if SampleCount were a class enum, e.g.
217
+ // SampleCount::k4.
218
+ enum V : uint8_t {
219
+ k1 = 1,
220
+ k2 = 2,
221
+ k4 = 4,
222
+ k8 = 8,
223
+ k16 = 16
224
+ };
225
+
226
+ constexpr SampleCount() : fValue(k1) {}
227
+ /*implicit*/ constexpr SampleCount(V v) : fValue(v) {}
228
+
229
+ // Behave like an enum
230
+ constexpr bool operator ==(const SampleCount& o) const { return fValue == o.fValue; }
231
+ constexpr bool operator <(const SampleCount& o) const { return fValue < o.fValue; }
232
+ constexpr bool operator <=(const SampleCount& o) const { return fValue <= o.fValue; }
233
+ constexpr bool operator >(const SampleCount& o) const { return fValue > o.fValue; }
234
+ constexpr bool operator >=(const SampleCount& o) const { return fValue >= o.fValue; }
235
+
236
+ // This needs to be explicit so that ternaries that return constants mixed with variables aren't
237
+ // ambiguous; internal code can cast for switch statements.
238
+ explicit constexpr operator SampleCount::V() const { return fValue; }
239
+ explicit constexpr operator uint8_t() const { return (uint8_t) fValue; }
240
+ explicit constexpr operator unsigned int() const { return (unsigned int) fValue; }
241
+
242
+ // Assist migration from old code that would assign integers to sample count fields that used
243
+ // to be uint8_t and are now more strictly typed to SampleCount. Asserts if the value doesn't
244
+ // match a SampleCount value.
245
+ /*implicit*/ constexpr SampleCount(uint8_t v) : fValue((V) v) {
246
+ SkASSERT(v == 1 || v == 2 || v == 4 || v == 8 || v == 16);
247
+ }
248
+ constexpr SampleCount& operator=(uint8_t sampleCount) {
249
+ return (*this = SampleCount(sampleCount));
250
+ }
251
+
252
+ private:
253
+ V fValue;
254
+ };
255
+
212
256
  /*
213
257
  * This enum allows mapping from a set of observed RenderSteps (e.g., from a GraphicsPipeline
214
258
  * printout) to the correct 'drawTypes' parameter needed by the Precompilation API.
@@ -31,6 +31,6 @@ enum class LogPriority : int {
31
31
  kWarning = 2,
32
32
  kDebug = 3,
33
33
  };
34
- }; // namespace skgpu::graphite
34
+ } // namespace skgpu::graphite
35
35
 
36
36
  #endif // skgpu_graphite_LogPriority_DEFINED
@@ -0,0 +1,45 @@
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_PersistentPipelineStorage_DEFINED
9
+ #define skgpu_graphite_PersistentPipelineStorage_DEFINED
10
+
11
+ #include "include/core/SkRefCnt.h"
12
+ #include "include/private/base/SkAPI.h"
13
+
14
+ class SkData;
15
+
16
+ namespace skgpu::graphite {
17
+
18
+ /**
19
+ * Abstract class which can be implemented to allow Graphite to persist Pipeline data across
20
+ * Context lifetimes
21
+ */
22
+ class SK_API PersistentPipelineStorage {
23
+ public:
24
+ virtual ~PersistentPipelineStorage() = default;
25
+
26
+ /**
27
+ * Should return the data that had been previously stored. It should return null if there
28
+ * is no prior data.
29
+ */
30
+ virtual sk_sp<SkData> load() = 0;
31
+
32
+ /**
33
+ * Should persist the provided Pipeline data.
34
+ */
35
+ virtual void store(const SkData& data) = 0;
36
+
37
+ protected:
38
+ PersistentPipelineStorage() = default;
39
+ PersistentPipelineStorage(const PersistentPipelineStorage&) = delete;
40
+ PersistentPipelineStorage& operator=(const PersistentPipelineStorage&) = delete;
41
+ };
42
+
43
+ } // namespace skgpu::graphite
44
+
45
+ #endif // skgpu_graphite_PersistentPipelineStorage_DEFINED
@@ -78,7 +78,7 @@ private:
78
78
  friend class PrecompileContextPriv;
79
79
  friend class Context; // for ctor
80
80
 
81
- PrecompileContext(sk_sp<SharedContext>);
81
+ explicit PrecompileContext(sk_sp<SharedContext>);
82
82
 
83
83
  mutable SingleOwner fSingleOwner;
84
84
  sk_sp<SharedContext> fSharedContext;
@@ -11,6 +11,7 @@
11
11
  #include "include/core/SkCPURecorder.h"
12
12
  #include "include/core/SkRecorder.h"
13
13
  #include "include/core/SkRefCnt.h"
14
+ #include "include/core/SkSurface.h"
14
15
  #include "include/gpu/graphite/GraphiteTypes.h"
15
16
  #include "include/gpu/graphite/Recording.h"
16
17
  #include "include/private/base/SingleOwner.h"
@@ -54,6 +55,8 @@ class Device;
54
55
  class DrawBufferManager;
55
56
  class FloatStorageManager;
56
57
  class ImageProvider;
58
+ class PaintParamsKeyBuilder;
59
+ class PipelineDataGatherer;
57
60
  class ProxyReadCountMap;
58
61
  class RecorderPriv;
59
62
  class ResourceProvider;
@@ -66,6 +69,8 @@ class UploadList;
66
69
 
67
70
  struct RecorderOptionsPriv;
68
71
 
72
+ using KeyAndDataBuilder = std::pair<PipelineDataGatherer, PaintParamsKeyBuilder>;
73
+
69
74
  struct SK_API RecorderOptions final {
70
75
  RecorderOptions();
71
76
  RecorderOptions(const RecorderOptions&);
@@ -242,6 +247,8 @@ public:
242
247
  const RecorderPriv priv() const; // NOLINT(readability-const-return-type)
243
248
 
244
249
  private:
250
+ static constexpr int kMaxKeyAndDataBuilders = 2;
251
+
245
252
  friend class Context; // For ctor
246
253
  friend class Device; // For registering and deregistering Devices;
247
254
  friend class RecorderPriv; // for ctor and hidden methods
@@ -274,6 +281,7 @@ private:
274
281
  void deregisterDevice(const Device*);
275
282
 
276
283
  SkCanvas* makeCaptureCanvas(SkCanvas*) override;
284
+ void createCaptureBreakpoint(SkSurface*) override;
277
285
 
278
286
  sk_sp<SharedContext> fSharedContext;
279
287
  ResourceProvider* fResourceProvider; // May point to the Context's resource provider
@@ -291,6 +299,9 @@ private:
291
299
  sk_sp<FloatStorageManager> fFloatStorageManager;
292
300
  std::unique_ptr<ProxyReadCountMap> fProxyReadCounts;
293
301
 
302
+ skia_private::STArray<kMaxKeyAndDataBuilders, std::unique_ptr<KeyAndDataBuilder>>
303
+ fKeyAndDataBuilders;
304
+
294
305
  // Iterating over tracked devices in flushTrackedDevices() needs to be re-entrant and support
295
306
  // additions to fTrackedDevices if registerDevice() is triggered by a temporary device during
296
307
  // flushing. Removals are handled by setting elements to null; final clean up is handled at the
@@ -319,6 +330,9 @@ private:
319
330
 
320
331
  skia_private::TArray<sk_sp<RefCntedCallback>> fFinishedProcs;
321
332
 
333
+ // Tracks the flushing state to ensure recursive flushing does not occur.
334
+ SkDEBUGCODE(bool fIsFlushingTrackedDevices = false;)
335
+
322
336
  #if defined(GPU_TEST_UTILS)
323
337
  // For testing use only -- the Context used to create this Recorder
324
338
  Context* fContext = nullptr;
@@ -9,7 +9,6 @@
9
9
  #define skgpu_graphite_TextureInfo_DEFINED
10
10
 
11
11
  #include "include/core/SkString.h"
12
- #include "include/core/SkTextureCompressionType.h"
13
12
  #include "include/gpu/graphite/GraphiteTypes.h"
14
13
  #include "include/private/base/SkAPI.h"
15
14
  #include "include/private/base/SkAnySubclass.h"
@@ -43,8 +42,6 @@ private:
43
42
  // static constexpr BackendApi kBackend;
44
43
  // Protected isProtected() const;
45
44
  // TextureFormat viewFormat() const;
46
- // bool serialize(SkWStream*) const;
47
- // bool deserialize(SkStream*);
48
45
  class Data {
49
46
  public:
50
47
  virtual ~Data() = default;
@@ -59,6 +56,10 @@ private:
59
56
  Data& operator=(const Data&) = default;
60
57
 
61
58
  // NOTE: These fields are accessible via the backend-specific subclasses.
59
+
60
+ // Must be a valid SampleCount value, or TextureInfo creation will fail to wrap the backend
61
+ // specific data. This is not strongly typed so that it can be assigned directly from the
62
+ // backend GPU API's representation, which is often just an integer.
62
63
  uint8_t fSampleCount = 1;
63
64
  Mipmapped fMipmapped = Mipmapped::kNo;
64
65
 
@@ -92,9 +93,13 @@ public:
92
93
  return fBackend;
93
94
  }
94
95
 
95
- uint8_t numSamples() const { return fData.has_value() ? fData->fSampleCount : 1; }
96
- Mipmapped mipmapped() const { return fData.has_value() ? fData->fMipmapped : Mipmapped::kNo; }
97
96
  Protected isProtected() const { return fProtected; }
97
+ SampleCount sampleCount() const {
98
+ return fData.has_value() ? static_cast<SampleCount>(fData->fSampleCount) : SampleCount::k1;
99
+ }
100
+ Mipmapped mipmapped() const {
101
+ return fData.has_value() ? fData->fMipmapped : Mipmapped::kNo;
102
+ }
98
103
 
99
104
  // Return true if `that` describes a texture that is compatible with this info and can validly
100
105
  // be used to fulfill a promise image that was created with this TextureInfo.
@@ -114,6 +119,9 @@ private:
114
119
  : fBackend(BackendTextureData::kBackend)
115
120
  , fViewFormat(data.viewFormat())
116
121
  , fProtected(data.isProtected()) {
122
+ // TextureInfoPriv should not construct a TextureInfo if `data` would fail this assert.
123
+ SkASSERT(data.fSampleCount == 1 || data.fSampleCount == 2 || data.fSampleCount == 4 ||
124
+ data.fSampleCount == 8 || data.fSampleCount == 16);
117
125
  fData.emplace<BackendTextureData>(data);
118
126
  }
119
127
 
@@ -46,7 +46,7 @@ public:
46
46
 
47
47
  DawnTextureInfo() = default;
48
48
 
49
- DawnTextureInfo(WGPUTexture texture);
49
+ explicit DawnTextureInfo(WGPUTexture texture);
50
50
 
51
51
  DawnTextureInfo(uint32_t sampleCount,
52
52
  Mipmapped mipmapped,
@@ -103,9 +103,6 @@ private:
103
103
  Protected isProtected() const { return Protected::kNo; }
104
104
  TextureFormat viewFormat() const;
105
105
 
106
- bool serialize(SkWStream*) const;
107
- bool deserialize(SkStream*);
108
-
109
106
  // Virtual API when the specific backend type is not available.
110
107
  SkString toBackendString() const override;
111
108
 
@@ -34,7 +34,7 @@ public:
34
34
  bool fFramebufferOnly = false;
35
35
 
36
36
  MtlTextureInfo() = default;
37
- MtlTextureInfo(CFTypeRef mtlTexture);
37
+ explicit MtlTextureInfo(CFTypeRef mtlTexture);
38
38
  MtlTextureInfo(uint32_t sampleCount,
39
39
  skgpu::Mipmapped mipmapped,
40
40
  MTLPixelFormat format,
@@ -57,9 +57,6 @@ private:
57
57
  Protected isProtected() const { return Protected::kNo; }
58
58
  TextureFormat viewFormat() const;
59
59
 
60
- bool serialize(SkWStream*) const;
61
- bool deserialize(SkStream*);
62
-
63
60
  // Virtual API when the specific backend type is not available.
64
61
  SkString toBackendString() const override;
65
62
 
@@ -13,9 +13,6 @@
13
13
  #include "include/gpu/graphite/TextureInfo.h"
14
14
  #include "include/gpu/vk/VulkanTypes.h"
15
15
 
16
- class SkStream;
17
- class SkWStream;
18
-
19
16
  namespace skgpu::graphite {
20
17
 
21
18
  class SK_API VulkanTextureInfo final : public TextureInfo::Data {
@@ -40,7 +37,7 @@ public:
40
37
  VulkanYcbcrConversionInfo fYcbcrConversionInfo;
41
38
 
42
39
  VulkanTextureInfo() = default;
43
- VulkanTextureInfo(uint32_t sampleCount,
40
+ VulkanTextureInfo(VkSampleCountFlagBits sampleCount,
44
41
  Mipmapped mipmapped,
45
42
  VkImageCreateFlags flags,
46
43
  VkFormat format,
@@ -49,7 +46,7 @@ public:
49
46
  VkSharingMode sharingMode,
50
47
  VkImageAspectFlags aspectMask,
51
48
  VulkanYcbcrConversionInfo ycbcrConversionInfo)
52
- : Data(sampleCount, mipmapped)
49
+ : Data(static_cast<uint8_t>(sampleCount), mipmapped)
53
50
  , fFlags(flags)
54
51
  , fFormat(format)
55
52
  , fImageTiling(imageTiling)
@@ -70,9 +67,6 @@ private:
70
67
  }
71
68
  TextureFormat viewFormat() const;
72
69
 
73
- bool serialize(SkWStream*) const;
74
- bool deserialize(SkStream*);
75
-
76
70
  // Virtual API when the specific backend type is not available.
77
71
  SkString toBackendString() const override;
78
72
 
@@ -36,7 +36,7 @@ public:
36
36
 
37
37
  struct Info {
38
38
  Info() {}
39
- Info(const char* name) : fName(name), fSpecVersion(0) {}
39
+ explicit Info(const char* name) : fName(name), fSpecVersion(0) {}
40
40
 
41
41
  SkString fName;
42
42
  uint32_t fSpecVersion;