@shopify/react-native-skia 0.1.197 → 0.1.200

Sign up to get free protection for your applications and to get access to all the features.
Files changed (187) hide show
  1. package/android/CMakeLists.txt +32 -31
  2. package/android/cpp/rnskia-android/SkiaOpenGLRenderer.cpp +4 -2
  3. package/android/cpp/rnskia-android/SkiaOpenGLRenderer.h +3 -0
  4. package/cpp/api/JsiSkShaderFactory.h +4 -4
  5. package/cpp/api/JsiSkSurfaceFactory.h +2 -1
  6. package/cpp/rnskia/dom/nodes/JsiShaderNodes.h +2 -2
  7. package/cpp/skia/include/android/SkCanvasAndroid.h +20 -0
  8. package/cpp/skia/include/android/SkHeifDecoder.h +43 -0
  9. package/cpp/skia/include/android/SkSurfaceAndroid.h +50 -0
  10. package/cpp/skia/include/codec/SkAvifDecoder.h +43 -0
  11. package/cpp/skia/include/codec/SkBmpDecoder.h +43 -0
  12. package/cpp/skia/include/codec/SkCodec.h +25 -1
  13. package/cpp/skia/include/codec/SkGifDecoder.h +43 -0
  14. package/cpp/skia/include/codec/SkIcoDecoder.h +43 -0
  15. package/cpp/skia/include/codec/SkJpegDecoder.h +43 -0
  16. package/cpp/skia/include/codec/SkJpegxlDecoder.h +43 -0
  17. package/cpp/skia/include/codec/SkPngDecoder.h +43 -0
  18. package/cpp/skia/include/codec/SkRawDecoder.h +49 -0
  19. package/cpp/skia/include/codec/SkWbmpDecoder.h +43 -0
  20. package/cpp/skia/include/codec/SkWebpDecoder.h +43 -0
  21. package/cpp/skia/include/core/SkBBHFactory.h +5 -1
  22. package/cpp/skia/include/core/SkBlender.h +0 -2
  23. package/cpp/skia/include/core/SkCanvas.h +4 -23
  24. package/cpp/skia/include/core/SkColorFilter.h +14 -1
  25. package/cpp/skia/include/core/SkColorTable.h +59 -0
  26. package/cpp/skia/include/core/SkContourMeasure.h +3 -0
  27. package/cpp/skia/include/core/SkDeferredDisplayList.h +8 -104
  28. package/cpp/skia/include/core/SkDeferredDisplayListRecorder.h +8 -91
  29. package/cpp/skia/include/core/SkDrawable.h +5 -2
  30. package/cpp/skia/include/core/SkGraphics.h +7 -19
  31. package/cpp/skia/include/core/SkImage.h +157 -249
  32. package/cpp/skia/include/core/SkImageGenerator.h +0 -31
  33. package/cpp/skia/include/core/SkMilestone.h +1 -1
  34. package/cpp/skia/include/core/SkPathMeasure.h +3 -3
  35. package/cpp/skia/include/core/SkPictureRecorder.h +1 -1
  36. package/cpp/skia/include/core/SkPoint.h +5 -563
  37. package/cpp/skia/include/core/SkPoint3.h +1 -0
  38. package/cpp/skia/include/core/SkPromiseImageTexture.h +4 -30
  39. package/cpp/skia/include/core/SkRect.h +8 -8
  40. package/cpp/skia/include/core/SkSamplingOptions.h +4 -2
  41. package/cpp/skia/include/core/SkScalar.h +1 -1
  42. package/cpp/skia/include/core/SkSerialProcs.h +5 -1
  43. package/cpp/skia/include/core/SkShader.h +14 -21
  44. package/cpp/skia/include/core/SkString.h +2 -0
  45. package/cpp/skia/include/core/SkSurface.h +169 -701
  46. package/cpp/skia/include/core/SkSurfaceCharacterization.h +8 -256
  47. package/cpp/skia/include/core/SkTiledImageUtils.h +97 -0
  48. package/cpp/skia/include/core/SkTypes.h +4 -2
  49. package/cpp/skia/include/core/SkYUVAPixmaps.h +0 -5
  50. package/cpp/skia/include/effects/SkGradientShader.h +10 -1
  51. package/cpp/skia/include/effects/SkImageFilters.h +62 -37
  52. package/cpp/skia/include/effects/SkPerlinNoiseShader.h +28 -29
  53. package/cpp/skia/include/effects/SkRuntimeEffect.h +17 -12
  54. package/cpp/skia/include/gpu/GrBackendSurface.h +12 -39
  55. package/cpp/skia/include/gpu/GrBackendSurfaceMutableState.h +6 -0
  56. package/cpp/skia/include/gpu/GrContextThreadSafeProxy.h +3 -3
  57. package/cpp/skia/include/gpu/GrDirectContext.h +103 -3
  58. package/cpp/skia/include/gpu/GrRecordingContext.h +10 -19
  59. package/cpp/skia/include/gpu/MutableTextureState.h +4 -0
  60. package/cpp/skia/include/gpu/ganesh/GrExternalTextureGenerator.h +54 -0
  61. package/cpp/skia/include/gpu/ganesh/SkImageGanesh.h +20 -76
  62. package/cpp/skia/include/gpu/ganesh/SkSurfaceGanesh.h +217 -0
  63. package/cpp/skia/include/gpu/ganesh/mtl/SkSurfaceMetal.h +73 -0
  64. package/cpp/skia/include/gpu/gl/GrGLTypes.h +13 -2
  65. package/cpp/skia/include/gpu/graphite/BackendSemaphore.h +78 -0
  66. package/cpp/skia/include/gpu/graphite/BackendTexture.h +1 -0
  67. package/cpp/skia/include/gpu/graphite/Image.h +277 -0
  68. package/cpp/skia/include/gpu/graphite/ImageProvider.h +1 -1
  69. package/cpp/skia/include/gpu/graphite/Recording.h +1 -4
  70. package/cpp/skia/include/gpu/graphite/Surface.h +81 -0
  71. package/cpp/skia/include/gpu/graphite/TextureInfo.h +5 -7
  72. package/cpp/skia/include/gpu/graphite/YUVABackendTextures.h +2 -2
  73. package/cpp/skia/include/gpu/mock/GrMockTypes.h +23 -8
  74. package/cpp/skia/include/ports/SkTypeface_fontations.h +21 -0
  75. package/cpp/skia/include/private/SkGainmapInfo.h +2 -0
  76. package/cpp/skia/include/private/SkGainmapShader.h +1 -0
  77. package/cpp/skia/include/private/SkJpegMetadataDecoder.h +19 -1
  78. package/cpp/skia/include/private/SkPathRef.h +13 -15
  79. package/cpp/skia/include/private/SkXmp.h +53 -0
  80. package/cpp/skia/include/private/base/SkFeatures.h +0 -4
  81. package/cpp/skia/include/private/base/SkFloatingPoint.h +11 -5
  82. package/cpp/skia/include/private/base/SkPoint_impl.h +569 -0
  83. package/cpp/skia/include/private/base/SkSpan_impl.h +3 -7
  84. package/cpp/skia/include/private/base/SkTArray.h +11 -11
  85. package/cpp/skia/include/private/chromium/GrDeferredDisplayList.h +120 -0
  86. package/cpp/skia/include/private/chromium/GrDeferredDisplayListRecorder.h +98 -0
  87. package/cpp/skia/include/private/chromium/GrPromiseImageTexture.h +43 -0
  88. package/cpp/skia/include/private/chromium/GrSurfaceCharacterization.h +215 -0
  89. package/cpp/skia/include/private/chromium/GrVkSecondaryCBDrawContext.h +6 -6
  90. package/cpp/skia/include/private/chromium/SkImageChromium.h +104 -0
  91. package/cpp/skia/include/private/chromium/Slug.h +7 -3
  92. package/cpp/skia/include/private/gpu/ganesh/GrContext_Base.h +7 -3
  93. package/cpp/skia/include/private/gpu/ganesh/GrGLTypesPriv.h +2 -0
  94. package/cpp/skia/include/private/gpu/ganesh/GrImageContext.h +3 -2
  95. package/cpp/skia/include/private/gpu/ganesh/GrMtlTypesPriv.h +10 -2
  96. package/cpp/skia/include/{gpu → private/gpu}/ganesh/GrTextureGenerator.h +2 -13
  97. package/cpp/skia/include/private/gpu/ganesh/GrTypesPriv.h +1 -1
  98. package/cpp/skia/include/private/gpu/graphite/DawnTypesPriv.h +7 -0
  99. package/cpp/skia/include/private/gpu/graphite/MtlGraphiteTypesPriv.h +19 -6
  100. package/cpp/skia/include/private/gpu/graphite/VulkanGraphiteTypesPriv.h +13 -0
  101. package/cpp/skia/include/third_party/vulkan/vulkan/vulkan.h +0 -1
  102. package/cpp/skia/include/third_party/vulkan/vulkan/vulkan_android.h +14 -1
  103. package/cpp/skia/include/third_party/vulkan/vulkan/vulkan_core.h +999 -79
  104. package/cpp/skia/modules/skcms/src/Transform_inl.h +36 -236
  105. package/cpp/skia/modules/skparagraph/include/Paragraph.h +2 -0
  106. package/cpp/skia/modules/skparagraph/include/ParagraphBuilder.h +16 -0
  107. package/cpp/skia/modules/skparagraph/include/TextStyle.h +6 -2
  108. package/cpp/skia/modules/skresources/include/SkResources.h +1 -1
  109. package/cpp/skia/modules/svg/include/SkSVGCircle.h +1 -1
  110. package/cpp/skia/modules/svg/include/SkSVGClipPath.h +1 -1
  111. package/cpp/skia/modules/svg/include/SkSVGContainer.h +1 -1
  112. package/cpp/skia/modules/svg/include/SkSVGDOM.h +1 -1
  113. package/cpp/skia/modules/svg/include/SkSVGDefs.h +1 -1
  114. package/cpp/skia/modules/svg/include/SkSVGEllipse.h +1 -1
  115. package/cpp/skia/modules/svg/include/SkSVGFe.h +1 -1
  116. package/cpp/skia/modules/svg/include/SkSVGFeBlend.h +1 -1
  117. package/cpp/skia/modules/svg/include/SkSVGFeColorMatrix.h +1 -1
  118. package/cpp/skia/modules/svg/include/SkSVGFeComposite.h +1 -1
  119. package/cpp/skia/modules/svg/include/SkSVGFeDisplacementMap.h +1 -1
  120. package/cpp/skia/modules/svg/include/SkSVGFeFlood.h +1 -1
  121. package/cpp/skia/modules/svg/include/SkSVGFeGaussianBlur.h +1 -1
  122. package/cpp/skia/modules/svg/include/SkSVGFeImage.h +1 -1
  123. package/cpp/skia/modules/svg/include/SkSVGFeLightSource.h +1 -1
  124. package/cpp/skia/modules/svg/include/SkSVGFeLighting.h +1 -1
  125. package/cpp/skia/modules/svg/include/SkSVGFeOffset.h +1 -1
  126. package/cpp/skia/modules/svg/include/SkSVGFeTurbulence.h +1 -1
  127. package/cpp/skia/modules/svg/include/SkSVGFilter.h +1 -1
  128. package/cpp/skia/modules/svg/include/SkSVGG.h +1 -1
  129. package/cpp/skia/modules/svg/include/SkSVGGradient.h +1 -1
  130. package/cpp/skia/modules/svg/include/SkSVGHiddenContainer.h +1 -1
  131. package/cpp/skia/modules/svg/include/SkSVGImage.h +1 -1
  132. package/cpp/skia/modules/svg/include/SkSVGLine.h +1 -1
  133. package/cpp/skia/modules/svg/include/SkSVGLinearGradient.h +1 -1
  134. package/cpp/skia/modules/svg/include/SkSVGMask.h +1 -1
  135. package/cpp/skia/modules/svg/include/SkSVGNode.h +1 -1
  136. package/cpp/skia/modules/svg/include/SkSVGPath.h +1 -1
  137. package/cpp/skia/modules/svg/include/SkSVGPattern.h +1 -1
  138. package/cpp/skia/modules/svg/include/SkSVGPoly.h +1 -1
  139. package/cpp/skia/modules/svg/include/SkSVGRadialGradient.h +1 -1
  140. package/cpp/skia/modules/svg/include/SkSVGRect.h +1 -1
  141. package/cpp/skia/modules/svg/include/SkSVGRenderContext.h +3 -3
  142. package/cpp/skia/modules/svg/include/SkSVGSVG.h +1 -1
  143. package/cpp/skia/modules/svg/include/SkSVGShape.h +1 -1
  144. package/cpp/skia/modules/svg/include/SkSVGStop.h +1 -1
  145. package/cpp/skia/modules/svg/include/SkSVGText.h +1 -1
  146. package/cpp/skia/modules/svg/include/SkSVGTransformableNode.h +1 -1
  147. package/cpp/skia/modules/svg/include/SkSVGTypes.h +21 -21
  148. package/cpp/skia/modules/svg/include/SkSVGUse.h +1 -1
  149. package/cpp/skia/modules/svg/include/SkSVGValue.h +2 -2
  150. package/cpp/skia/{include/private → src/core}/SkChecksum.h +32 -17
  151. package/cpp/skia/src/core/SkTHash.h +1 -1
  152. package/ios/RNSkia-iOS/RNSkMetalCanvasProvider.mm +3 -1
  153. package/ios/RNSkia-iOS/SkiaMetalRenderer.mm +3 -1
  154. package/libs/android/arm64-v8a/libskia.a +0 -0
  155. package/libs/android/arm64-v8a/libskottie.a +0 -0
  156. package/libs/android/arm64-v8a/libsksg.a +0 -0
  157. package/libs/android/arm64-v8a/libsvg.a +0 -0
  158. package/libs/android/armeabi-v7a/libskia.a +0 -0
  159. package/libs/android/armeabi-v7a/libskottie.a +0 -0
  160. package/libs/android/armeabi-v7a/libsksg.a +0 -0
  161. package/libs/android/armeabi-v7a/libsvg.a +0 -0
  162. package/libs/android/x86/libskia.a +0 -0
  163. package/libs/android/x86/libskottie.a +0 -0
  164. package/libs/android/x86/libsksg.a +0 -0
  165. package/libs/android/x86/libsvg.a +0 -0
  166. package/libs/android/x86_64/libskia.a +0 -0
  167. package/libs/android/x86_64/libskottie.a +0 -0
  168. package/libs/android/x86_64/libsksg.a +0 -0
  169. package/libs/android/x86_64/libsvg.a +0 -0
  170. package/libs/ios/libskia.xcframework/ios-arm64_arm64e/libskia.a +0 -0
  171. package/libs/ios/libskia.xcframework/ios-arm64_arm64e_x86_64-simulator/libskia.a +0 -0
  172. package/libs/ios/libskottie.xcframework/ios-arm64_arm64e/libskottie.a +0 -0
  173. package/libs/ios/libskottie.xcframework/ios-arm64_arm64e_x86_64-simulator/libskottie.a +0 -0
  174. package/libs/ios/libsksg.xcframework/Info.plist +5 -5
  175. package/libs/ios/libsksg.xcframework/ios-arm64_arm64e/libsksg.a +0 -0
  176. package/libs/ios/libsksg.xcframework/ios-arm64_arm64e_x86_64-simulator/libsksg.a +0 -0
  177. package/libs/ios/libskshaper.xcframework/ios-arm64_arm64e/libskshaper.a +0 -0
  178. package/libs/ios/libskshaper.xcframework/ios-arm64_arm64e_x86_64-simulator/libskshaper.a +0 -0
  179. package/libs/ios/libsvg.xcframework/Info.plist +5 -5
  180. package/libs/ios/libsvg.xcframework/ios-arm64_arm64e/libsvg.a +0 -0
  181. package/libs/ios/libsvg.xcframework/ios-arm64_arm64e_x86_64-simulator/libsvg.a +0 -0
  182. package/package.json +1 -3
  183. package/cpp/skia/include/effects/SkTableColorFilter.h +0 -29
  184. package/cpp/skia/include/private/SkOpts_spi.h +0 -23
  185. package/cpp/skia/include/private/SkSpinlock.h +0 -57
  186. package/cpp/skia/include/private/chromium/GrSlug.h +0 -16
  187. package/scripts/install-npm.js +0 -33
@@ -17,523 +17,165 @@
17
17
  #include "include/core/SkSurfaceProps.h"
18
18
  #include "include/core/SkTypes.h"
19
19
 
20
- #if defined(SK_GANESH)
21
- #include "include/gpu/GrTypes.h"
22
- #else
23
- enum GrSurfaceOrigin: int;
24
- #endif
25
-
26
- #if defined(SK_GRAPHITE)
27
- #include "include/gpu/GpuTypes.h"
28
- namespace skgpu::graphite {
29
- class BackendTexture;
30
- }
31
- #endif
32
-
33
- #if defined(SK_BUILD_FOR_ANDROID) && __ANDROID_API__ >= 26
34
- #include <android/hardware_buffer.h>
35
- class GrDirectContext;
36
- #endif
37
-
38
- #if defined(SK_GANESH) && defined(SK_METAL)
39
- #include "include/gpu/mtl/GrMtlTypes.h"
40
- #endif
41
-
42
20
  #include <cstddef>
43
21
  #include <cstdint>
44
22
  #include <memory>
45
23
 
46
- class GrBackendRenderTarget;
47
24
  class GrBackendSemaphore;
48
25
  class GrBackendTexture;
49
26
  class GrRecordingContext;
27
+ class GrSurfaceCharacterization;
28
+ enum GrSurfaceOrigin : int;
50
29
  class SkBitmap;
51
30
  class SkCanvas;
52
31
  class SkCapabilities;
53
32
  class SkColorSpace;
54
- class SkDeferredDisplayList;
55
33
  class SkPaint;
56
- class SkSurfaceCharacterization;
57
- enum SkColorType : int;
34
+ class SkSurface;
58
35
  struct SkIRect;
59
36
  struct SkISize;
60
37
 
61
- namespace skgpu {
62
- class MutableTextureState;
63
- enum class Budgeted : bool;
64
- }
65
-
66
38
  namespace skgpu::graphite {
67
39
  class Recorder;
68
40
  }
69
41
 
70
- /** \class SkSurface
71
- SkSurface is responsible for managing the pixels that a canvas draws into. The pixels can be
72
- allocated either in CPU memory (a raster surface) or on the GPU (a GrRenderTarget surface).
73
- SkSurface takes care of allocating a SkCanvas that will draw into the surface. Call
74
- surface->getCanvas() to use that canvas (but don't delete it, it is owned by the surface).
75
- SkSurface always has non-zero dimensions. If there is a request for a new surface, and either
76
- of the requested dimensions are zero, then nullptr will be returned.
77
- */
78
- class SK_API SkSurface : public SkRefCnt {
79
- public:
80
-
81
- /** Allocates raster SkSurface. SkCanvas returned by SkSurface draws directly into pixels.
82
-
83
- SkSurface is returned if all parameters are valid.
84
- Valid parameters include:
85
- info dimensions are greater than zero;
86
- info contains SkColorType and SkAlphaType supported by raster surface;
87
- pixels is not nullptr;
88
- rowBytes is large enough to contain info width pixels of SkColorType.
89
-
90
- Pixel buffer size should be info height times computed rowBytes.
91
- Pixels are not initialized.
92
- To access pixels after drawing, peekPixels() or readPixels().
93
-
94
- @param imageInfo width, height, SkColorType, SkAlphaType, SkColorSpace,
95
- of raster surface; width and height must be greater than zero
96
- @param pixels pointer to destination pixels buffer
97
- @param rowBytes interval from one SkSurface row to the next
98
- @param surfaceProps LCD striping orientation and setting for device independent fonts;
99
- may be nullptr
100
- @return SkSurface if all parameters are valid; otherwise, nullptr
101
- */
102
- static sk_sp<SkSurface> MakeRasterDirect(const SkImageInfo& imageInfo, void* pixels,
103
- size_t rowBytes,
104
- const SkSurfaceProps* surfaceProps = nullptr);
105
-
106
- static sk_sp<SkSurface> MakeRasterDirect(const SkPixmap& pm,
107
- const SkSurfaceProps* props = nullptr) {
108
- return MakeRasterDirect(pm.info(), pm.writable_addr(), pm.rowBytes(), props);
109
- }
110
-
111
- /** Allocates raster SkSurface. SkCanvas returned by SkSurface draws directly into pixels.
112
- releaseProc is called with pixels and context when SkSurface is deleted.
113
-
114
- SkSurface is returned if all parameters are valid.
115
- Valid parameters include:
116
- info dimensions are greater than zero;
117
- info contains SkColorType and SkAlphaType supported by raster surface;
118
- pixels is not nullptr;
119
- rowBytes is large enough to contain info width pixels of SkColorType.
120
-
121
- Pixel buffer size should be info height times computed rowBytes.
122
- Pixels are not initialized.
123
- To access pixels after drawing, call flush() or peekPixels().
124
-
125
- @param imageInfo width, height, SkColorType, SkAlphaType, SkColorSpace,
126
- of raster surface; width and height must be greater than zero
127
- @param pixels pointer to destination pixels buffer
128
- @param rowBytes interval from one SkSurface row to the next
129
- @param releaseProc called when SkSurface is deleted; may be nullptr
130
- @param context passed to releaseProc; may be nullptr
131
- @param surfaceProps LCD striping orientation and setting for device independent fonts;
132
- may be nullptr
133
- @return SkSurface if all parameters are valid; otherwise, nullptr
134
- */
135
- static sk_sp<SkSurface> MakeRasterDirectReleaseProc(const SkImageInfo& imageInfo, void* pixels,
136
- size_t rowBytes,
137
- void (*releaseProc)(void* pixels, void* context),
138
- void* context, const SkSurfaceProps* surfaceProps = nullptr);
139
-
140
- /** Allocates raster SkSurface. SkCanvas returned by SkSurface draws directly into pixels.
141
- Allocates and zeroes pixel memory. Pixel memory size is imageInfo.height() times
142
- rowBytes, or times imageInfo.minRowBytes() if rowBytes is zero.
143
- Pixel memory is deleted when SkSurface is deleted.
144
-
145
- SkSurface is returned if all parameters are valid.
146
- Valid parameters include:
147
- info dimensions are greater than zero;
148
- info contains SkColorType and SkAlphaType supported by raster surface;
149
- rowBytes is large enough to contain info width pixels of SkColorType, or is zero.
150
-
151
- If rowBytes is zero, a suitable value will be chosen internally.
152
-
153
- @param imageInfo width, height, SkColorType, SkAlphaType, SkColorSpace,
154
- of raster surface; width and height must be greater than zero
155
- @param rowBytes interval from one SkSurface row to the next; may be zero
156
- @param surfaceProps LCD striping orientation and setting for device independent fonts;
157
- may be nullptr
158
- @return SkSurface if all parameters are valid; otherwise, nullptr
159
- */
160
- static sk_sp<SkSurface> MakeRaster(const SkImageInfo& imageInfo, size_t rowBytes,
161
- const SkSurfaceProps* surfaceProps);
162
-
163
- /** Allocates raster SkSurface. SkCanvas returned by SkSurface draws directly into pixels.
164
- Allocates and zeroes pixel memory. Pixel memory size is imageInfo.height() times
165
- imageInfo.minRowBytes().
166
- Pixel memory is deleted when SkSurface is deleted.
167
-
168
- SkSurface is returned if all parameters are valid.
169
- Valid parameters include:
170
- info dimensions are greater than zero;
171
- info contains SkColorType and SkAlphaType supported by raster surface.
172
-
173
- @param imageInfo width, height, SkColorType, SkAlphaType, SkColorSpace,
174
- of raster surface; width and height must be greater than zero
175
- @param props LCD striping orientation and setting for device independent fonts;
176
- may be nullptr
177
- @return SkSurface if all parameters are valid; otherwise, nullptr
178
- */
179
- static sk_sp<SkSurface> MakeRaster(const SkImageInfo& imageInfo,
180
- const SkSurfaceProps* props = nullptr) {
181
- return MakeRaster(imageInfo, 0, props);
182
- }
183
-
184
- /** Allocates raster SkSurface. SkCanvas returned by SkSurface draws directly into pixels.
185
- Allocates and zeroes pixel memory. Pixel memory size is height times width times
186
- four. Pixel memory is deleted when SkSurface is deleted.
187
-
188
- Internally, sets SkImageInfo to width, height, native color type, and
189
- kPremul_SkAlphaType.
190
-
191
- SkSurface is returned if width and height are greater than zero.
192
-
193
- Use to create SkSurface that matches SkPMColor, the native pixel arrangement on
194
- the platform. SkSurface drawn to output device skips converting its pixel format.
195
-
196
- @param width pixel column count; must be greater than zero
197
- @param height pixel row count; must be greater than zero
198
- @param surfaceProps LCD striping orientation and setting for device independent
199
- fonts; may be nullptr
200
- @return SkSurface if all parameters are valid; otherwise, nullptr
201
- */
202
- static sk_sp<SkSurface> MakeRasterN32Premul(int width, int height,
203
- const SkSurfaceProps* surfaceProps = nullptr);
204
-
205
- /** Caller data passed to RenderTarget/TextureReleaseProc; may be nullptr. */
206
- typedef void* ReleaseContext;
42
+ #if !defined(SK_DISABLE_LEGACY_SKSURFACE_FLUSH)
43
+ enum class GrSemaphoresSubmitted : bool;
44
+ struct GrFlushInfo;
45
+ namespace skgpu { class MutableTextureState; }
46
+ #endif
207
47
 
208
- /** User function called when supplied render target may be deleted. */
209
- typedef void (*RenderTargetReleaseProc)(ReleaseContext releaseContext);
48
+ namespace SkSurfaces {
210
49
 
211
- /** User function called when supplied texture may be deleted. */
212
- typedef void (*TextureReleaseProc)(ReleaseContext releaseContext);
50
+ enum class BackendSurfaceAccess {
51
+ kNoAccess, //!< back-end surface will not be used by client
52
+ kPresent, //!< back-end surface will be used for presenting to screen
53
+ };
213
54
 
214
- /** Wraps a GPU-backed texture into SkSurface. Caller must ensure the texture is
215
- valid for the lifetime of returned SkSurface. If sampleCnt greater than zero,
216
- creates an intermediate MSAA SkSurface which is used for drawing backendTexture.
55
+ /** Returns SkSurface without backing pixels. Drawing to SkCanvas returned from SkSurface
56
+ has no effect. Calling makeImageSnapshot() on returned SkSurface returns nullptr.
217
57
 
218
- SkSurface is returned if all parameters are valid. backendTexture is valid if
219
- its pixel configuration agrees with colorSpace and context; for instance, if
220
- backendTexture has an sRGB configuration, then context must support sRGB,
221
- and colorSpace must be present. Further, backendTexture width and height must
222
- not exceed context capabilities, and the context must be able to support
223
- back-end textures.
58
+ @param width one or greater
59
+ @param height one or greater
60
+ @return SkSurface if width and height are positive; otherwise, nullptr
224
61
 
225
- Upon success textureReleaseProc is called when it is safe to delete the texture in the
226
- backend API (accounting only for use of the texture by this surface). If SkSurface creation
227
- fails textureReleaseProc is called before this function returns.
62
+ example: https://fiddle.skia.org/c/@Surface_MakeNull
63
+ */
64
+ SK_API sk_sp<SkSurface> Null(int width, int height);
228
65
 
229
- If defined(SK_GANESH) is defined as zero, has no effect and returns nullptr.
230
-
231
- @param context GPU context
232
- @param backendTexture texture residing on GPU
233
- @param sampleCnt samples per pixel, or 0 to disable full scene anti-aliasing
234
- @param colorSpace range of colors; may be nullptr
235
- @param surfaceProps LCD striping orientation and setting for device independent
236
- fonts; may be nullptr
237
- @param textureReleaseProc function called when texture can be released
238
- @param releaseContext state passed to textureReleaseProc
239
- @return SkSurface if all parameters are valid; otherwise, nullptr
240
- */
241
- static sk_sp<SkSurface> MakeFromBackendTexture(GrRecordingContext* context,
242
- const GrBackendTexture& backendTexture,
243
- GrSurfaceOrigin origin, int sampleCnt,
244
- SkColorType colorType,
245
- sk_sp<SkColorSpace> colorSpace,
246
- const SkSurfaceProps* surfaceProps,
247
- TextureReleaseProc textureReleaseProc = nullptr,
248
- ReleaseContext releaseContext = nullptr);
249
-
250
- /** Wraps a GPU-backed buffer into SkSurface. Caller must ensure backendRenderTarget
251
- is valid for the lifetime of returned SkSurface.
252
-
253
- SkSurface is returned if all parameters are valid. backendRenderTarget is valid if
254
- its pixel configuration agrees with colorSpace and context; for instance, if
255
- backendRenderTarget has an sRGB configuration, then context must support sRGB,
256
- and colorSpace must be present. Further, backendRenderTarget width and height must
257
- not exceed context capabilities, and the context must be able to support
258
- back-end render targets.
259
-
260
- Upon success releaseProc is called when it is safe to delete the render target in the
261
- backend API (accounting only for use of the render target by this surface). If SkSurface
262
- creation fails releaseProc is called before this function returns.
263
-
264
- If defined(SK_GANESH) is defined as zero, has no effect and returns nullptr.
265
-
266
- @param context GPU context
267
- @param backendRenderTarget GPU intermediate memory buffer
268
- @param colorSpace range of colors
269
- @param surfaceProps LCD striping orientation and setting for device independent
270
- fonts; may be nullptr
271
- @param releaseProc function called when backendRenderTarget can be released
272
- @param releaseContext state passed to releaseProc
273
- @return SkSurface if all parameters are valid; otherwise, nullptr
274
- */
275
- static sk_sp<SkSurface> MakeFromBackendRenderTarget(GrRecordingContext* context,
276
- const GrBackendRenderTarget& backendRenderTarget,
277
- GrSurfaceOrigin origin,
278
- SkColorType colorType,
279
- sk_sp<SkColorSpace> colorSpace,
280
- const SkSurfaceProps* surfaceProps,
281
- RenderTargetReleaseProc releaseProc = nullptr,
282
- ReleaseContext releaseContext = nullptr);
283
-
284
- /** Returns SkSurface on GPU indicated by context. Allocates memory for
285
- pixels, based on the width, height, and SkColorType in SkImageInfo. budgeted
286
- selects whether allocation for pixels is tracked by context. imageInfo
287
- describes the pixel format in SkColorType, and transparency in
288
- SkAlphaType, and color matching in SkColorSpace.
289
-
290
- sampleCount requests the number of samples per pixel.
291
- Pass zero to disable multi-sample anti-aliasing. The request is rounded
292
- up to the next supported count, or rounded down if it is larger than the
293
- maximum supported count.
294
-
295
- surfaceOrigin pins either the top-left or the bottom-left corner to the origin.
296
-
297
- shouldCreateWithMips hints that SkImage returned by makeImageSnapshot() is mip map.
298
-
299
- If defined(SK_GANESH) is defined as zero, has no effect and returns nullptr.
300
-
301
- @param context GPU context
302
- @param imageInfo width, height, SkColorType, SkAlphaType, SkColorSpace;
303
- width, or height, or both, may be zero
304
- @param sampleCount samples per pixel, or 0 to disable full scene anti-aliasing
305
- @param surfaceProps LCD striping orientation and setting for device independent
306
- fonts; may be nullptr
307
- @param shouldCreateWithMips hint that SkSurface will host mip map images
308
- @return SkSurface if all parameters are valid; otherwise, nullptr
309
- */
310
- static sk_sp<SkSurface> MakeRenderTarget(GrRecordingContext* context,
311
- skgpu::Budgeted budgeted,
312
- const SkImageInfo& imageInfo,
313
- int sampleCount,
314
- GrSurfaceOrigin surfaceOrigin,
315
- const SkSurfaceProps* surfaceProps,
316
- bool shouldCreateWithMips = false);
317
-
318
- /** Returns SkSurface on GPU indicated by context. Allocates memory for
319
- pixels, based on the width, height, and SkColorType in SkImageInfo. budgeted
320
- selects whether allocation for pixels is tracked by context. imageInfo
321
- describes the pixel format in SkColorType, and transparency in
322
- SkAlphaType, and color matching in SkColorSpace.
323
-
324
- sampleCount requests the number of samples per pixel.
325
- Pass zero to disable multi-sample anti-aliasing. The request is rounded
326
- up to the next supported count, or rounded down if it is larger than the
327
- maximum supported count.
328
-
329
- SkSurface bottom-left corner is pinned to the origin.
330
-
331
- @param context GPU context
332
- @param imageInfo width, height, SkColorType, SkAlphaType, SkColorSpace,
333
- of raster surface; width, or height, or both, may be zero
334
- @param sampleCount samples per pixel, or 0 to disable multi-sample anti-aliasing
335
- @param surfaceProps LCD striping orientation and setting for device independent
336
- fonts; may be nullptr
337
- @return SkSurface if all parameters are valid; otherwise, nullptr
338
- */
339
- static sk_sp<SkSurface> MakeRenderTarget(GrRecordingContext* context,
340
- skgpu::Budgeted budgeted,
341
- const SkImageInfo& imageInfo,
342
- int sampleCount,
343
- const SkSurfaceProps* surfaceProps) {
344
- #if defined(SK_GANESH)
345
- return MakeRenderTarget(context, budgeted, imageInfo, sampleCount,
346
- kBottomLeft_GrSurfaceOrigin, surfaceProps);
347
- #else
348
- // TODO(kjlubick, scroggo) Remove this once Android is updated.
349
- return nullptr;
350
- #endif
351
- }
66
+ /** Allocates raster SkSurface. SkCanvas returned by SkSurface draws directly into those allocated
67
+ pixels, which are zeroed before use. Pixel memory size is imageInfo.height() times
68
+ imageInfo.minRowBytes() or rowBytes, if provided and non-zero.
352
69
 
353
- /** Returns SkSurface on GPU indicated by context. Allocates memory for
354
- pixels, based on the width, height, and SkColorType in SkImageInfo. budgeted
355
- selects whether allocation for pixels is tracked by context. imageInfo
356
- describes the pixel format in SkColorType, and transparency in
357
- SkAlphaType, and color matching in SkColorSpace.
70
+ Pixel memory is deleted when SkSurface is deleted.
358
71
 
359
- SkSurface bottom-left corner is pinned to the origin.
72
+ Validity constraints include:
73
+ - info dimensions are greater than zero;
74
+ - info contains SkColorType and SkAlphaType supported by raster surface.
360
75
 
361
- @param context GPU context
362
- @param imageInfo width, height, SkColorType, SkAlphaType, SkColorSpace,
363
- of raster surface; width, or height, or both, may be zero
364
- @return SkSurface if all parameters are valid; otherwise, nullptr
365
- */
366
- static sk_sp<SkSurface> MakeRenderTarget(GrRecordingContext* context,
367
- skgpu::Budgeted budgeted,
368
- const SkImageInfo& imageInfo) {
369
- #if defined(SK_GANESH)
370
- if (!imageInfo.width() || !imageInfo.height()) {
371
- return nullptr;
372
- }
373
- return MakeRenderTarget(context, budgeted, imageInfo, 0, kBottomLeft_GrSurfaceOrigin,
374
- nullptr);
375
- #else
376
- // TODO(kjlubick, scroggo) Remove this once Android is updated.
377
- return nullptr;
378
- #endif
379
- }
76
+ @param imageInfo width, height, SkColorType, SkAlphaType, SkColorSpace,
77
+ of raster surface; width and height must be greater than zero
78
+ @param rowBytes interval from one SkSurface row to the next.
79
+ @param props LCD striping orientation and setting for device independent fonts;
80
+ may be nullptr
81
+ @return SkSurface if parameters are valid and memory was allocated, else nullptr.
82
+ */
83
+ SK_API sk_sp<SkSurface> Raster(const SkImageInfo& imageInfo,
84
+ size_t rowBytes,
85
+ const SkSurfaceProps* surfaceProps);
86
+ inline sk_sp<SkSurface> Raster(const SkImageInfo& imageInfo,
87
+ const SkSurfaceProps* props = nullptr) {
88
+ return Raster(imageInfo, 0, props);
89
+ }
380
90
 
381
- /** Returns SkSurface on GPU indicated by context that is compatible with the provided
382
- characterization. budgeted selects whether allocation for pixels is tracked by context.
91
+ /** Allocates raster SkSurface. SkCanvas returned by SkSurface draws directly into the
92
+ provided pixels.
93
+
94
+ SkSurface is returned if all parameters are valid.
95
+ Valid parameters include:
96
+ info dimensions are greater than zero;
97
+ info contains SkColorType and SkAlphaType supported by raster surface;
98
+ pixels is not nullptr;
99
+ rowBytes is large enough to contain info width pixels of SkColorType.
100
+
101
+ Pixel buffer size should be info height times computed rowBytes.
102
+ Pixels are not initialized.
103
+ To access pixels after drawing, peekPixels() or readPixels().
104
+
105
+ @param imageInfo width, height, SkColorType, SkAlphaType, SkColorSpace,
106
+ of raster surface; width and height must be greater than zero
107
+ @param pixels pointer to destination pixels buffer
108
+ @param rowBytes interval from one SkSurface row to the next
109
+ @param surfaceProps LCD striping orientation and setting for device independent fonts;
110
+ may be nullptr
111
+ @return SkSurface if all parameters are valid; otherwise, nullptr
112
+ */
383
113
 
384
- @param context GPU context
385
- @param characterization description of the desired SkSurface
386
- @return SkSurface if all parameters are valid; otherwise, nullptr
387
- */
388
- static sk_sp<SkSurface> MakeRenderTarget(GrRecordingContext* context,
389
- const SkSurfaceCharacterization& characterization,
390
- skgpu::Budgeted budgeted);
391
-
392
- #if defined(SK_BUILD_FOR_ANDROID) && __ANDROID_API__ >= 26
393
- /** Private.
394
- Creates SkSurface from Android hardware buffer.
395
- Returned SkSurface takes a reference on the buffer. The ref on the buffer will be released
396
- when the SkSurface is destroyed and there is no pending work on the GPU involving the
397
- buffer.
398
-
399
- Only available on Android, when __ANDROID_API__ is defined to be 26 or greater.
400
-
401
- Currently this is only supported for buffers that can be textured as well as rendered to.
402
- In other words that must have both AHARDWAREBUFFER_USAGE_GPU_COLOR_OUTPUT and
403
- AHARDWAREBUFFER_USAGE_GPU_SAMPLED_IMAGE usage bits.
404
-
405
- @param context GPU context
406
- @param hardwareBuffer AHardwareBuffer Android hardware buffer
407
- @param colorSpace range of colors; may be nullptr
408
- @param surfaceProps LCD striping orientation and setting for device independent
409
- fonts; may be nullptr
410
- @param fromWindow Whether or not the AHardwareBuffer is part of an Android Window.
411
- Currently only used with Vulkan backend.
412
- @return created SkSurface, or nullptr
413
- */
414
- static sk_sp<SkSurface> MakeFromAHardwareBuffer(GrDirectContext* context,
415
- AHardwareBuffer* hardwareBuffer,
416
- GrSurfaceOrigin origin,
417
- sk_sp<SkColorSpace> colorSpace,
418
- const SkSurfaceProps* surfaceProps
419
- #ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK
420
- , bool fromWindow = false
421
- #endif // SK_BUILD_FOR_ANDROID_FRAMEWORK
422
- );
423
- #endif
114
+ SK_API sk_sp<SkSurface> WrapPixels(const SkImageInfo& imageInfo,
115
+ void* pixels,
116
+ size_t rowBytes,
117
+ const SkSurfaceProps* surfaceProps = nullptr);
118
+ inline sk_sp<SkSurface> WrapPixels(const SkPixmap& pm, const SkSurfaceProps* props = nullptr) {
119
+ return WrapPixels(pm.info(), pm.writable_addr(), pm.rowBytes(), props);
120
+ }
424
121
 
425
- #if defined(SK_GRAPHITE)
426
- /**
427
- * In Graphite, while clients hold a ref on an SkSurface, the backing gpu object does _not_
428
- * count against the budget. Once an SkSurface is freed, the backing gpu object may or may
429
- * not become a scratch (i.e., reusable) resource but, if it does, it will be counted against
430
- * the budget.
431
- */
432
- static sk_sp<SkSurface> MakeGraphite(
433
- skgpu::graphite::Recorder*,
434
- const SkImageInfo& imageInfo,
435
- skgpu::Mipmapped = skgpu::Mipmapped::kNo,
436
- const SkSurfaceProps* surfaceProps = nullptr);
122
+ using PixelsReleaseProc = void(void* pixels, void* context);
123
+
124
+ /** Allocates raster SkSurface. SkCanvas returned by SkSurface draws directly into the provided
125
+ pixels. releaseProc is called with pixels and context when SkSurface is deleted.
126
+
127
+ SkSurface is returned if all parameters are valid.
128
+ Valid parameters include:
129
+ info dimensions are greater than zero;
130
+ info contains SkColorType and SkAlphaType supported by raster surface;
131
+ pixels is not nullptr;
132
+ rowBytes is large enough to contain info width pixels of SkColorType.
133
+
134
+ Pixel buffer size should be info height times computed rowBytes.
135
+ Pixels are not initialized.
136
+ To access pixels after drawing, call flush() or peekPixels().
137
+
138
+ @param imageInfo width, height, SkColorType, SkAlphaType, SkColorSpace,
139
+ of raster surface; width and height must be greater than zero
140
+ @param pixels pointer to destination pixels buffer
141
+ @param rowBytes interval from one SkSurface row to the next
142
+ @param releaseProc called when SkSurface is deleted; may be nullptr
143
+ @param context passed to releaseProc; may be nullptr
144
+ @param surfaceProps LCD striping orientation and setting for device independent fonts;
145
+ may be nullptr
146
+ @return SkSurface if all parameters are valid; otherwise, nullptr
147
+ */
148
+ SK_API sk_sp<SkSurface> WrapPixels(const SkImageInfo& imageInfo,
149
+ void* pixels,
150
+ size_t rowBytes,
151
+ PixelsReleaseProc,
152
+ void* context,
153
+ const SkSurfaceProps* surfaceProps = nullptr);
154
+ } // namespace SkSurfaces
437
155
 
438
- /**
439
- * Wraps a GPU-backed texture in an SkSurface. Depending on the backend gpu API, the caller may
440
- * be required to ensure the texture is valid for the lifetime of the returned SkSurface. The
441
- * required lifetimes for the specific apis are:
442
- * Metal: Skia will call retain on the underlying MTLTexture so the caller can drop it once
443
- * this call returns.
444
- *
445
- * SkSurface is returned if all the parameters are valid. The backendTexture is valid if its
446
- * format agrees with colorSpace and recorder; for instance, if backendTexture has an sRGB
447
- * configuration, then the recorder must support sRGB, and colorSpace must be present. Further,
448
- * backendTexture's width and height must not exceed the recorder's capabilities, and the
449
- * recorder must be able to support the back-end texture.
450
- */
451
- static sk_sp<SkSurface> MakeGraphiteFromBackendTexture(skgpu::graphite::Recorder*,
452
- const skgpu::graphite::BackendTexture&,
453
- SkColorType colorType,
454
- sk_sp<SkColorSpace> colorSpace,
455
- const SkSurfaceProps* props);
456
-
457
- #endif // SK_GRAPHITE
458
-
459
- #if defined(SK_GANESH) && defined(SK_METAL)
460
- /** Creates SkSurface from CAMetalLayer.
461
- Returned SkSurface takes a reference on the CAMetalLayer. The ref on the layer will be
462
- released when the SkSurface is destroyed.
463
-
464
- Only available when Metal API is enabled.
465
-
466
- Will grab the current drawable from the layer and use its texture as a backendRT to
467
- create a renderable surface.
468
-
469
- @param context GPU context
470
- @param layer GrMTLHandle (expected to be a CAMetalLayer*)
471
- @param sampleCnt samples per pixel, or 0 to disable full scene anti-aliasing
472
- @param colorSpace range of colors; may be nullptr
473
- @param surfaceProps LCD striping orientation and setting for device independent
474
- fonts; may be nullptr
475
- @param drawable Pointer to drawable to be filled in when this surface is
476
- instantiated; may not be nullptr
477
- @return created SkSurface, or nullptr
478
- */
479
- static sk_sp<SkSurface> MakeFromCAMetalLayer(GrRecordingContext* context,
480
- GrMTLHandle layer,
481
- GrSurfaceOrigin origin,
482
- int sampleCnt,
483
- SkColorType colorType,
484
- sk_sp<SkColorSpace> colorSpace,
485
- const SkSurfaceProps* surfaceProps,
486
- GrMTLHandle* drawable)
487
- SK_API_AVAILABLE_CA_METAL_LAYER;
488
-
489
- /** Creates SkSurface from MTKView.
490
- Returned SkSurface takes a reference on the MTKView. The ref on the layer will be
491
- released when the SkSurface is destroyed.
492
-
493
- Only available when Metal API is enabled.
494
-
495
- Will grab the current drawable from the layer and use its texture as a backendRT to
496
- create a renderable surface.
497
-
498
- @param context GPU context
499
- @param layer GrMTLHandle (expected to be a MTKView*)
500
- @param sampleCnt samples per pixel, or 0 to disable full scene anti-aliasing
501
- @param colorSpace range of colors; may be nullptr
502
- @param surfaceProps LCD striping orientation and setting for device independent
503
- fonts; may be nullptr
504
- @return created SkSurface, or nullptr
505
- */
506
- static sk_sp<SkSurface> MakeFromMTKView(GrRecordingContext* context,
507
- GrMTLHandle mtkView,
508
- GrSurfaceOrigin origin,
509
- int sampleCnt,
510
- SkColorType colorType,
511
- sk_sp<SkColorSpace> colorSpace,
512
- const SkSurfaceProps* surfaceProps)
513
- SK_API_AVAILABLE(macos(10.11), ios(9.0));
514
- #endif
156
+ /** \class SkSurface
157
+ SkSurface is responsible for managing the pixels that a canvas draws into. The pixels can be
158
+ allocated either in CPU memory (a raster surface) or on the GPU (a GrRenderTarget surface).
159
+ SkSurface takes care of allocating a SkCanvas that will draw into the surface. Call
160
+ surface->getCanvas() to use that canvas (but don't delete it, it is owned by the surface).
161
+ SkSurface always has non-zero dimensions. If there is a request for a new surface, and either
162
+ of the requested dimensions are zero, then nullptr will be returned.
515
163
 
164
+ Clients should *not* subclass SkSurface as there is a lot of internal machinery that is
165
+ not publicly accessible.
166
+ */
167
+ class SK_API SkSurface : public SkRefCnt {
168
+ public:
516
169
  /** Is this surface compatible with the provided characterization?
517
170
 
518
171
  This method can be used to determine if an existing SkSurface is a viable destination
519
- for an SkDeferredDisplayList.
172
+ for an GrDeferredDisplayList.
520
173
 
521
174
  @param characterization The characterization for which a compatibility check is desired
522
175
  @return true if this surface is compatible with the characterization;
523
176
  false otherwise
524
177
  */
525
- bool isCompatible(const SkSurfaceCharacterization& characterization) const;
526
-
527
- /** Returns SkSurface without backing pixels. Drawing to SkCanvas returned from SkSurface
528
- has no effect. Calling makeImageSnapshot() on returned SkSurface returns nullptr.
529
-
530
- @param width one or greater
531
- @param height one or greater
532
- @return SkSurface if width and height are positive; otherwise, nullptr
533
-
534
- example: https://fiddle.skia.org/c/@Surface_MakeNull
535
- */
536
- static sk_sp<SkSurface> MakeNull(int width, int height);
178
+ bool isCompatible(const GrSurfaceCharacterization& characterization) const;
537
179
 
538
180
  /** Returns pixel count in each row; may be zero or greater.
539
181
 
@@ -582,56 +224,37 @@ public:
582
224
 
583
225
  @return the recording context, if available; nullptr otherwise
584
226
  */
585
- GrRecordingContext* recordingContext();
227
+ GrRecordingContext* recordingContext() const;
586
228
 
587
229
  /** Returns the recorder being used by the SkSurface.
588
230
 
589
231
  @return the recorder, if available; nullptr otherwise
590
232
  */
591
- skgpu::graphite::Recorder* recorder();
233
+ skgpu::graphite::Recorder* recorder() const;
592
234
 
593
- #if defined(SK_GANESH)
594
- enum BackendHandleAccess {
595
- kFlushRead_BackendHandleAccess, //!< back-end object is readable
596
- kFlushWrite_BackendHandleAccess, //!< back-end object is writable
597
- kDiscardWrite_BackendHandleAccess, //!< back-end object must be overwritten
598
- };
599
-
600
- /** Deprecated.
601
- */
602
- static const BackendHandleAccess kFlushRead_TextureHandleAccess =
603
- kFlushRead_BackendHandleAccess;
235
+ enum class BackendHandleAccess {
236
+ kFlushRead, //!< back-end object is readable
237
+ kFlushWrite, //!< back-end object is writable
238
+ kDiscardWrite, //!< back-end object must be overwritten
604
239
 
605
- /** Deprecated.
606
- */
607
- static const BackendHandleAccess kFlushWrite_TextureHandleAccess =
608
- kFlushWrite_BackendHandleAccess;
609
-
610
- /** Deprecated.
611
- */
612
- static const BackendHandleAccess kDiscardWrite_TextureHandleAccess =
613
- kDiscardWrite_BackendHandleAccess;
614
-
615
- /** Retrieves the back-end texture. If SkSurface has no back-end texture, an invalid
616
- object is returned. Call GrBackendTexture::isValid to determine if the result
617
- is valid.
618
-
619
- The returned GrBackendTexture should be discarded if the SkSurface is drawn to or deleted.
620
-
621
- @return GPU texture reference; invalid on failure
622
- */
623
- GrBackendTexture getBackendTexture(BackendHandleAccess backendHandleAccess);
624
-
625
- /** Retrieves the back-end render target. If SkSurface has no back-end render target, an invalid
626
- object is returned. Call GrBackendRenderTarget::isValid to determine if the result
627
- is valid.
240
+ // Legacy names, remove when clients are migrated
241
+ kFlushRead_BackendHandleAccess = kFlushRead,
242
+ kFlushWrite_BackendHandleAccess = kFlushWrite,
243
+ kDiscardWrite_BackendHandleAccess = kDiscardWrite,
244
+ };
628
245
 
629
- The returned GrBackendRenderTarget should be discarded if the SkSurface is drawn to
630
- or deleted.
246
+ // Legacy names, remove when clients are migrated
247
+ static constexpr BackendHandleAccess kFlushRead_BackendHandleAccess =
248
+ BackendHandleAccess::kFlushRead;
249
+ static constexpr BackendHandleAccess kFlushWrite_BackendHandleAccess =
250
+ BackendHandleAccess::kFlushWrite;
251
+ static constexpr BackendHandleAccess kDiscardWrite_BackendHandleAccess =
252
+ BackendHandleAccess::kDiscardWrite;
631
253
 
632
- @return GPU render target reference; invalid on failure
633
- */
634
- GrBackendRenderTarget getBackendRenderTarget(BackendHandleAccess backendHandleAccess);
254
+ /** Caller data passed to TextureReleaseProc; may be nullptr. */
255
+ using ReleaseContext = void*;
256
+ /** User function called when supplied texture may be deleted. */
257
+ using TextureReleaseProc = void (*)(ReleaseContext);
635
258
 
636
259
  /** If the surface was made via MakeFromBackendTexture then it's backing texture may be
637
260
  substituted with a different texture. The contents of the previous backing texture are
@@ -645,15 +268,14 @@ public:
645
268
 
646
269
  @param backendTexture the new backing texture for the surface
647
270
  @param mode Retain or discard current Content
648
- @param textureReleaseProc function called when texture can be released
649
- @param releaseContext state passed to textureReleaseProc
271
+ @param TextureReleaseProc function called when texture can be released
272
+ @param ReleaseContext state passed to textureReleaseProc
650
273
  */
651
- bool replaceBackendTexture(const GrBackendTexture& backendTexture,
652
- GrSurfaceOrigin origin,
653
- ContentChangeMode mode = kRetain_ContentChangeMode,
654
- TextureReleaseProc textureReleaseProc = nullptr,
655
- ReleaseContext releaseContext = nullptr);
656
- #endif
274
+ virtual bool replaceBackendTexture(const GrBackendTexture& backendTexture,
275
+ GrSurfaceOrigin origin,
276
+ ContentChangeMode mode = kRetain_ContentChangeMode,
277
+ TextureReleaseProc = nullptr,
278
+ ReleaseContext = nullptr) = 0;
657
279
 
658
280
  /** Returns SkCanvas that draws into SkSurface. Subsequent calls return the same SkCanvas.
659
281
  SkCanvas returned is managed and owned by SkSurface, and is deleted when SkSurface
@@ -714,34 +336,6 @@ public:
714
336
  */
715
337
  sk_sp<SkImage> makeImageSnapshot(const SkIRect& bounds);
716
338
 
717
- #if defined(SK_GRAPHITE)
718
- /**
719
- * The 'asImage' and 'makeImageCopy' API/entry points are currently only available for
720
- * Graphite.
721
- *
722
- * In this API, SkSurface no longer supports copy-on-write behavior. Instead, when creating
723
- * an image for a surface, the client must explicitly indicate if a copy should be made.
724
- * In both of the below calls the resource backing the surface will never change.
725
- *
726
- * The 'asImage' entry point has some major ramifications for the mutability of the
727
- * returned SkImage. Since the originating surface and the returned image share the
728
- * same backing, care must be taken by the client to ensure that the contents of the image
729
- * reflect the desired contents when it is consumed by the gpu.
730
- * Note: if the backing GPU buffer isn't textureable this method will return null. Graphite
731
- * will not attempt to make a copy.
732
- * Note: For 'asImage', the mipmapping of the image will match that of the source surface.
733
- *
734
- * The 'makeImageCopy' entry point allows subsetting and the addition of mipmaps (since
735
- * a copy is already being made).
736
- *
737
- * In Graphite, the legacy API call (i.e., makeImageSnapshot) will just always make a copy.
738
- */
739
- sk_sp<SkImage> asImage();
740
-
741
- sk_sp<SkImage> makeImageCopy(const SkIRect* subset = nullptr,
742
- skgpu::Mipmapped mipmapped = skgpu::Mipmapped::kNo);
743
- #endif
744
-
745
339
  /** Draws SkSurface contents to canvas, with its top-left corner at (x, y).
746
340
 
747
341
  If SkPaint paint is not nullptr, apply SkColorFilter, alpha, SkImageFilter, and SkBlendMode.
@@ -1001,131 +595,6 @@ public:
1001
595
  */
1002
596
  const SkSurfaceProps& props() const { return fProps; }
1003
597
 
1004
- /** Call to ensure all reads/writes of the surface have been issued to the underlying 3D API.
1005
- Skia will correctly order its own draws and pixel operations. This must to be used to ensure
1006
- correct ordering when the surface backing store is accessed outside Skia (e.g. direct use of
1007
- the 3D API or a windowing system). GrDirectContext has additional flush and submit methods
1008
- that apply to all surfaces and images created from a GrDirectContext. This is equivalent to
1009
- calling SkSurface::flush with a default GrFlushInfo followed by
1010
- GrDirectContext::submit(syncCpu).
1011
- */
1012
- void flushAndSubmit(bool syncCpu = false);
1013
-
1014
- enum class BackendSurfaceAccess {
1015
- kNoAccess, //!< back-end object will not be used by client
1016
- kPresent, //!< back-end surface will be used for presenting to screen
1017
- };
1018
-
1019
- #if defined(SK_GANESH)
1020
- /** If a surface is GPU texture backed, is being drawn with MSAA, and there is a resolve
1021
- texture, this call will insert a resolve command into the stream of gpu commands. In order
1022
- for the resolve to actually have an effect, the work still needs to be flushed and submitted
1023
- to the GPU after recording the resolve command. If a resolve is not supported or the
1024
- SkSurface has no dirty work to resolve, then this call is a no-op.
1025
-
1026
- This call is most useful when the SkSurface is created by wrapping a single sampled gpu
1027
- texture, but asking Skia to render with MSAA. If the client wants to use the wrapped texture
1028
- outside of Skia, the only way to trigger a resolve is either to call this command or use
1029
- SkSurface::flush.
1030
- */
1031
- void resolveMSAA();
1032
-
1033
- /** Issues pending SkSurface commands to the GPU-backed API objects and resolves any SkSurface
1034
- MSAA. A call to GrDirectContext::submit is always required to ensure work is actually sent
1035
- to the gpu. Some specific API details:
1036
- GL: Commands are actually sent to the driver, but glFlush is never called. Thus some
1037
- sync objects from the flush will not be valid until a submission occurs.
1038
-
1039
- Vulkan/Metal/D3D/Dawn: Commands are recorded to the backend APIs corresponding command
1040
- buffer or encoder objects. However, these objects are not sent to the gpu until a
1041
- submission occurs.
1042
-
1043
- The work that is submitted to the GPU will be dependent on the BackendSurfaceAccess that is
1044
- passed in.
1045
-
1046
- If BackendSurfaceAccess::kNoAccess is passed in all commands will be issued to the GPU.
1047
-
1048
- If BackendSurfaceAccess::kPresent is passed in and the backend API is not Vulkan, it is
1049
- treated the same as kNoAccess. If the backend API is Vulkan, the VkImage that backs the
1050
- SkSurface will be transferred back to its original queue. If the SkSurface was created by
1051
- wrapping a VkImage, the queue will be set to the queue which was originally passed in on
1052
- the GrVkImageInfo. Additionally, if the original queue was not external or foreign the
1053
- layout of the VkImage will be set to VK_IMAGE_LAYOUT_PRESENT_SRC_KHR.
1054
-
1055
- The GrFlushInfo describes additional options to flush. Please see documentation at
1056
- GrFlushInfo for more info.
1057
-
1058
- If the return is GrSemaphoresSubmitted::kYes, only initialized GrBackendSemaphores will be
1059
- submitted to the gpu during the next submit call (it is possible Skia failed to create a
1060
- subset of the semaphores). The client should not wait on these semaphores until after submit
1061
- has been called, but must keep them alive until then. If a submit flag was passed in with
1062
- the flush these valid semaphores can we waited on immediately. If this call returns
1063
- GrSemaphoresSubmitted::kNo, the GPU backend will not submit any semaphores to be signaled on
1064
- the GPU. Thus the client should not have the GPU wait on any of the semaphores passed in
1065
- with the GrFlushInfo. Regardless of whether semaphores were submitted to the GPU or not, the
1066
- client is still responsible for deleting any initialized semaphores.
1067
- Regardless of semaphore submission the context will still be flushed. It should be
1068
- emphasized that a return value of GrSemaphoresSubmitted::kNo does not mean the flush did not
1069
- happen. It simply means there were no semaphores submitted to the GPU. A caller should only
1070
- take this as a failure if they passed in semaphores to be submitted.
1071
-
1072
- Pending surface commands are flushed regardless of the return result.
1073
-
1074
- @param access type of access the call will do on the backend object after flush
1075
- @param info flush options
1076
- */
1077
- GrSemaphoresSubmitted flush(BackendSurfaceAccess access, const GrFlushInfo& info);
1078
-
1079
- /** Issues pending SkSurface commands to the GPU-backed API objects and resolves any SkSurface
1080
- MSAA. A call to GrDirectContext::submit is always required to ensure work is actually sent
1081
- to the gpu. Some specific API details:
1082
- GL: Commands are actually sent to the driver, but glFlush is never called. Thus some
1083
- sync objects from the flush will not be valid until a submission occurs.
1084
-
1085
- Vulkan/Metal/D3D/Dawn: Commands are recorded to the backend APIs corresponding command
1086
- buffer or encoder objects. However, these objects are not sent to the gpu until a
1087
- submission occurs.
1088
-
1089
- The GrFlushInfo describes additional options to flush. Please see documentation at
1090
- GrFlushInfo for more info.
1091
-
1092
- If a skgpu::MutableTextureState is passed in, at the end of the flush we will transition
1093
- the surface to be in the state requested by the skgpu::MutableTextureState. If the surface
1094
- (or SkImage or GrBackendSurface wrapping the same backend object) is used again after this
1095
- flush the state may be changed and no longer match what is requested here. This is often
1096
- used if the surface will be used for presenting or external use and the client wants backend
1097
- object to be prepped for that use. A finishedProc or semaphore on the GrFlushInfo will also
1098
- include the work for any requested state change.
1099
-
1100
- If the backend API is Vulkan, the caller can set the skgpu::MutableTextureState's
1101
- VkImageLayout to VK_IMAGE_LAYOUT_UNDEFINED or queueFamilyIndex to VK_QUEUE_FAMILY_IGNORED to
1102
- tell Skia to not change those respective states.
1103
-
1104
- If the return is GrSemaphoresSubmitted::kYes, only initialized GrBackendSemaphores will be
1105
- submitted to the gpu during the next submit call (it is possible Skia failed to create a
1106
- subset of the semaphores). The client should not wait on these semaphores until after submit
1107
- has been called, but must keep them alive until then. If a submit flag was passed in with
1108
- the flush these valid semaphores can we waited on immediately. If this call returns
1109
- GrSemaphoresSubmitted::kNo, the GPU backend will not submit any semaphores to be signaled on
1110
- the GPU. Thus the client should not have the GPU wait on any of the semaphores passed in
1111
- with the GrFlushInfo. Regardless of whether semaphores were submitted to the GPU or not, the
1112
- client is still responsible for deleting any initialized semaphores.
1113
- Regardleess of semaphore submission the context will still be flushed. It should be
1114
- emphasized that a return value of GrSemaphoresSubmitted::kNo does not mean the flush did not
1115
- happen. It simply means there were no semaphores submitted to the GPU. A caller should only
1116
- take this as a failure if they passed in semaphores to be submitted.
1117
-
1118
- Pending surface commands are flushed regardless of the return result.
1119
-
1120
- @param info flush options
1121
- @param access optional state change request after flush
1122
- */
1123
- GrSemaphoresSubmitted flush(const GrFlushInfo& info,
1124
- const skgpu::MutableTextureState* newState = nullptr);
1125
- #endif // defined(SK_GANESH)
1126
-
1127
- void flush();
1128
-
1129
598
  /** Inserts a list of GPU semaphores that the current GPU-backed API must wait on before
1130
599
  executing any more commands on the GPU for this surface. If this call returns false, then
1131
600
  the GPU back-end will not wait on any passed in semaphores, and the client will still own
@@ -1144,9 +613,9 @@ public:
1144
613
  bool wait(int numSemaphores, const GrBackendSemaphore* waitSemaphores,
1145
614
  bool deleteSemaphoresAfterWait = true);
1146
615
 
1147
- /** Initializes SkSurfaceCharacterization that can be used to perform GPU back-end
616
+ /** Initializes GrSurfaceCharacterization that can be used to perform GPU back-end
1148
617
  processing in a separate thread. Typically this is used to divide drawing
1149
- into multiple tiles. SkDeferredDisplayListRecorder records the drawing commands
618
+ into multiple tiles. GrDeferredDisplayListRecorder records the drawing commands
1150
619
  for each tile.
1151
620
 
1152
621
  Return true if SkSurface supports characterization. raster surface returns false.
@@ -1156,27 +625,7 @@ public:
1156
625
 
1157
626
  example: https://fiddle.skia.org/c/@Surface_characterize
1158
627
  */
1159
- bool characterize(SkSurfaceCharacterization* characterization) const;
1160
-
1161
- /** Draws the deferred display list created via a SkDeferredDisplayListRecorder.
1162
- If the deferred display list is not compatible with this SkSurface, the draw is skipped
1163
- and false is return.
1164
-
1165
- The xOffset and yOffset parameters are experimental and, if not both zero, will cause
1166
- the draw to be ignored.
1167
- When implemented, if xOffset or yOffset are non-zero, the DDL will be drawn offset by that
1168
- amount into the surface.
1169
-
1170
- @param deferredDisplayList drawing commands
1171
- @param xOffset x-offset at which to draw the DDL
1172
- @param yOffset y-offset at which to draw the DDL
1173
- @return false if deferredDisplayList is not compatible
1174
-
1175
- example: https://fiddle.skia.org/c/@Surface_draw_2
1176
- */
1177
- bool draw(sk_sp<const SkDeferredDisplayList> deferredDisplayList,
1178
- int xOffset = 0,
1179
- int yOffset = 0);
628
+ bool characterize(GrSurfaceCharacterization* characterization) const;
1180
629
 
1181
630
  protected:
1182
631
  SkSurface(int width, int height, const SkSurfaceProps* surfaceProps);
@@ -1194,6 +643,25 @@ private:
1194
643
  uint32_t fGenerationID;
1195
644
 
1196
645
  using INHERITED = SkRefCnt;
646
+
647
+ public:
648
+ #if !defined(SK_DISABLE_LEGACY_SKSURFACE_FLUSH) && defined(SK_GANESH)
649
+ using BackendSurfaceAccess = SkSurfaces::BackendSurfaceAccess;
650
+ GrSemaphoresSubmitted flush(BackendSurfaceAccess access, const GrFlushInfo& info);
651
+ GrSemaphoresSubmitted flush(const GrFlushInfo& info,
652
+ const skgpu::MutableTextureState* newState = nullptr);
653
+ void resolveMSAA();
654
+ #endif
655
+
656
+ #if !defined(SK_DISABLE_LEGACY_SKSURFACE_FLUSH)
657
+ void flushAndSubmit(bool syncCpu = false);
658
+ void flush();
659
+ #endif
660
+
661
+ #if !defined(SK_DISABLE_LEGACY_SKSURFACE_AS_IMAGE) && defined(SK_GRAPHITE)
662
+ sk_sp<SkImage> asImage();
663
+ #endif
664
+
1197
665
  };
1198
666
 
1199
667
  #endif