@shopify/react-native-skia 1.11.18 → 1.12.1

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 (211) hide show
  1. package/android/cpp/jni/JniPlatformContext.cpp +1 -0
  2. package/cpp/api/JsiSkContourMeasure.h +1 -1
  3. package/cpp/api/JsiSkHostObjects.h +21 -10
  4. package/cpp/api/JsiSkParagraph.h +17 -27
  5. package/cpp/api/JsiSkPathEffect.h +1 -1
  6. package/cpp/api/JsiSkPictureFactory.h +1 -1
  7. package/cpp/api/recorder/Drawings.h +4 -3
  8. package/cpp/rnskia/DawnContext.h +1 -1
  9. package/cpp/skia/include/codec/SkCodec.h +7 -2
  10. package/cpp/skia/include/config/SkUserConfig.h +11 -0
  11. package/cpp/skia/include/core/SkCanvas.h +11 -7
  12. package/cpp/skia/include/core/SkColor.h +10 -0
  13. package/cpp/skia/include/core/SkColorSpace.h +184 -2
  14. package/cpp/skia/include/core/SkColorType.h +114 -32
  15. package/cpp/skia/include/core/SkFontScanner.h +5 -8
  16. package/cpp/skia/include/core/SkFontStyle.h +1 -1
  17. package/cpp/skia/include/core/SkMaskFilter.h +0 -8
  18. package/cpp/skia/include/core/SkMilestone.h +1 -1
  19. package/cpp/skia/include/core/SkPath.h +1 -1
  20. package/cpp/skia/include/core/SkRRect.h +3 -1
  21. package/cpp/skia/include/core/SkShader.h +3 -3
  22. package/cpp/skia/include/core/SkString.h +8 -8
  23. package/cpp/skia/include/core/SkSurface.h +14 -0
  24. package/cpp/skia/include/core/SkTypeface.h +24 -7
  25. package/cpp/skia/include/effects/SkGradientShader.h +6 -1
  26. package/cpp/skia/include/effects/SkRuntimeEffect.h +1 -0
  27. package/cpp/skia/include/encode/SkPngEncoder.h +14 -0
  28. package/cpp/skia/include/gpu/GpuTypes.h +9 -0
  29. package/cpp/skia/include/gpu/ganesh/GrContextOptions.h +135 -133
  30. package/cpp/skia/include/gpu/ganesh/GrDirectContext.h +5 -0
  31. package/cpp/skia/include/gpu/ganesh/GrDriverBugWorkarounds.h +3 -3
  32. package/cpp/skia/include/gpu/ganesh/GrTypes.h +14 -9
  33. package/cpp/skia/include/gpu/graphite/Context.h +25 -2
  34. package/cpp/skia/include/gpu/graphite/ContextOptions.h +23 -5
  35. package/cpp/skia/include/gpu/graphite/GraphiteTypes.h +20 -1
  36. package/cpp/skia/include/gpu/graphite/Image.h +1 -0
  37. package/cpp/skia/include/gpu/graphite/LogPriority.h +36 -0
  38. package/cpp/skia/include/gpu/graphite/PrecompileContext.h +52 -0
  39. package/cpp/skia/include/gpu/graphite/Recorder.h +6 -0
  40. package/cpp/skia/include/gpu/graphite/Recording.h +3 -1
  41. package/cpp/skia/include/gpu/graphite/mtl/MtlGraphiteTypes.h +4 -36
  42. package/cpp/skia/include/gpu/graphite/mtl/MtlGraphiteTypesUtils.h +48 -0
  43. package/cpp/skia/include/gpu/graphite/precompile/Precompile.h +3 -2
  44. package/cpp/skia/include/pathops/SkPathOps.h +9 -1
  45. package/cpp/skia/include/ports/SkFontMgr_FontConfigInterface.h +3 -0
  46. package/cpp/skia/include/private/SkPathRef.h +15 -21
  47. package/cpp/skia/include/private/base/SkAttributes.h +16 -10
  48. package/cpp/skia/include/private/base/SkMutex.h +8 -0
  49. package/cpp/skia/include/private/base/SkTArray.h +1 -1
  50. package/cpp/skia/include/private/base/SkTDArray.h +1 -1
  51. package/cpp/skia/include/private/base/SkTemplates.h +24 -11
  52. package/cpp/skia/include/private/gpu/ganesh/GrTypesPriv.h +1 -1
  53. package/cpp/skia/include/sksl/SkSLDebugTrace.h +0 -3
  54. package/cpp/skia/modules/skcms/src/Transform_inl.h +20 -20
  55. package/cpp/skia/modules/skcms/src/skcms_Transform.h +4 -3
  56. package/cpp/skia/modules/skcms/src/skcms_public.h +19 -15
  57. package/cpp/skia/modules/skresources/include/SkResources.h +3 -1
  58. package/cpp/skia/modules/svg/include/SkSVGCircle.h +1 -1
  59. package/cpp/skia/modules/svg/include/SkSVGContainer.h +1 -1
  60. package/cpp/skia/modules/svg/include/SkSVGFeLightSource.h +1 -1
  61. package/cpp/skia/modules/svg/include/SkSVGImage.h +2 -2
  62. package/cpp/skia/modules/svg/include/SkSVGPath.h +1 -1
  63. package/cpp/skia/modules/svg/include/SkSVGPoly.h +1 -1
  64. package/cpp/skia/modules/svg/include/SkSVGRect.h +1 -1
  65. package/cpp/skia/modules/svg/include/SkSVGRenderContext.h +2 -0
  66. package/cpp/skia/modules/svg/include/SkSVGShape.h +1 -0
  67. package/cpp/skia/modules/svg/include/SkSVGText.h +1 -1
  68. package/cpp/skia/modules/svg/include/SkSVGTransformableNode.h +4 -0
  69. package/cpp/skia/modules/svg/include/SkSVGUse.h +1 -1
  70. package/cpp/skia/src/core/SkLRUCache.h +19 -13
  71. package/cpp/skia/src/core/SkTHash.h +50 -4
  72. package/cpp/skia/src/gpu/ganesh/gl/GrGLDefines.h +1 -0
  73. package/lib/commonjs/external/reanimated/useAnimatedImageValue.js +4 -3
  74. package/lib/commonjs/external/reanimated/useAnimatedImageValue.js.map +1 -1
  75. package/lib/commonjs/mock/index.js +1 -2
  76. package/lib/commonjs/mock/index.js.map +1 -1
  77. package/lib/commonjs/skia/web/Host.d.ts +1 -3
  78. package/lib/commonjs/skia/web/Host.js +7 -6
  79. package/lib/commonjs/skia/web/Host.js.map +1 -1
  80. package/lib/commonjs/skia/web/JsiSkFont.js +1 -1
  81. package/lib/commonjs/skia/web/JsiSkFont.js.map +1 -1
  82. package/lib/commonjs/skia/web/JsiSkFontMgr.js +1 -1
  83. package/lib/commonjs/skia/web/JsiSkFontMgr.js.map +1 -1
  84. package/lib/commonjs/skia/web/JsiSkImageFactory.js +1 -1
  85. package/lib/commonjs/skia/web/JsiSkImageFactory.js.map +1 -1
  86. package/lib/commonjs/skia/web/JsiSkImageFilterFactory.js +6 -6
  87. package/lib/commonjs/skia/web/JsiSkImageFilterFactory.js.map +1 -1
  88. package/lib/commonjs/skia/web/JsiSkPathEffectFactory.js +2 -2
  89. package/lib/commonjs/skia/web/JsiSkPathEffectFactory.js.map +1 -1
  90. package/lib/commonjs/skia/web/JsiSkPathFactory.d.ts +1 -1
  91. package/lib/commonjs/skia/web/JsiSkPathFactory.js +1 -1
  92. package/lib/commonjs/skia/web/JsiSkPathFactory.js.map +1 -1
  93. package/lib/commonjs/skia/web/JsiSkTypefaceFontProvider.js +1 -1
  94. package/lib/commonjs/skia/web/JsiSkTypefaceFontProvider.js.map +1 -1
  95. package/lib/commonjs/skia/web/JsiSkia.js +4 -3
  96. package/lib/commonjs/skia/web/JsiSkia.js.map +1 -1
  97. package/lib/commonjs/skia/web/JsiVideo.js +2 -1
  98. package/lib/commonjs/skia/web/JsiVideo.js.map +1 -1
  99. package/lib/commonjs/sksg/Recorder/Core.d.ts +1 -5
  100. package/lib/commonjs/sksg/Recorder/Core.js +12 -4
  101. package/lib/commonjs/sksg/Recorder/Core.js.map +1 -1
  102. package/lib/commonjs/sksg/Recorder/Player.js +4 -5
  103. package/lib/commonjs/sksg/Recorder/Player.js.map +1 -1
  104. package/lib/commonjs/sksg/Recorder/commands/Box.js +2 -4
  105. package/lib/commonjs/sksg/Recorder/commands/Box.js.map +1 -1
  106. package/lib/module/external/reanimated/useAnimatedImageValue.js +4 -3
  107. package/lib/module/external/reanimated/useAnimatedImageValue.js.map +1 -1
  108. package/lib/module/mock/index.js +1 -2
  109. package/lib/module/mock/index.js.map +1 -1
  110. package/lib/module/skia/web/Host.d.ts +1 -3
  111. package/lib/module/skia/web/Host.js +5 -4
  112. package/lib/module/skia/web/Host.js.map +1 -1
  113. package/lib/module/skia/web/JsiSkFont.js +2 -2
  114. package/lib/module/skia/web/JsiSkFont.js.map +1 -1
  115. package/lib/module/skia/web/JsiSkFontMgr.js +2 -2
  116. package/lib/module/skia/web/JsiSkFontMgr.js.map +1 -1
  117. package/lib/module/skia/web/JsiSkImageFactory.js +2 -2
  118. package/lib/module/skia/web/JsiSkImageFactory.js.map +1 -1
  119. package/lib/module/skia/web/JsiSkImageFilterFactory.js +7 -7
  120. package/lib/module/skia/web/JsiSkImageFilterFactory.js.map +1 -1
  121. package/lib/module/skia/web/JsiSkPathEffectFactory.js +3 -3
  122. package/lib/module/skia/web/JsiSkPathEffectFactory.js.map +1 -1
  123. package/lib/module/skia/web/JsiSkPathFactory.d.ts +1 -1
  124. package/lib/module/skia/web/JsiSkPathFactory.js +2 -2
  125. package/lib/module/skia/web/JsiSkPathFactory.js.map +1 -1
  126. package/lib/module/skia/web/JsiSkTypefaceFontProvider.js +2 -2
  127. package/lib/module/skia/web/JsiSkTypefaceFontProvider.js.map +1 -1
  128. package/lib/module/skia/web/JsiSkia.js +4 -3
  129. package/lib/module/skia/web/JsiSkia.js.map +1 -1
  130. package/lib/module/skia/web/JsiVideo.js +2 -1
  131. package/lib/module/skia/web/JsiVideo.js.map +1 -1
  132. package/lib/module/sksg/Recorder/Core.d.ts +1 -5
  133. package/lib/module/sksg/Recorder/Core.js +10 -2
  134. package/lib/module/sksg/Recorder/Core.js.map +1 -1
  135. package/lib/module/sksg/Recorder/Player.js +5 -6
  136. package/lib/module/sksg/Recorder/Player.js.map +1 -1
  137. package/lib/module/sksg/Recorder/commands/Box.js +3 -5
  138. package/lib/module/sksg/Recorder/commands/Box.js.map +1 -1
  139. package/lib/typescript/lib/commonjs/mock/index.d.ts +1 -1
  140. package/lib/typescript/lib/commonjs/skia/web/Host.d.ts +1 -3
  141. package/lib/typescript/lib/commonjs/skia/web/JsiSkFont.d.ts +1 -1
  142. package/lib/typescript/lib/commonjs/skia/web/JsiSkFontMgr.d.ts +1 -1
  143. package/lib/typescript/lib/commonjs/skia/web/JsiSkImageFactory.d.ts +1 -1
  144. package/lib/typescript/lib/commonjs/skia/web/JsiSkImageFilterFactory.d.ts +1 -1
  145. package/lib/typescript/lib/commonjs/skia/web/JsiSkPathEffectFactory.d.ts +2 -2
  146. package/lib/typescript/lib/commonjs/skia/web/JsiSkPathFactory.d.ts +1 -1
  147. package/lib/typescript/lib/commonjs/skia/web/JsiSkTypefaceFontProvider.d.ts +1 -1
  148. package/lib/typescript/lib/commonjs/skia/web/JsiSkia.d.ts +3 -3
  149. package/lib/typescript/lib/commonjs/skia/web/JsiVideo.d.ts +1 -1
  150. package/lib/typescript/lib/commonjs/sksg/Recorder/Core.d.ts +1 -1
  151. package/lib/typescript/lib/module/mock/index.d.ts +1 -1
  152. package/lib/typescript/lib/module/skia/Skia.web.d.ts +3 -3
  153. package/lib/typescript/lib/module/skia/web/Host.d.ts +1 -3
  154. package/lib/typescript/lib/module/skia/web/JsiSkFont.d.ts +1 -1
  155. package/lib/typescript/lib/module/skia/web/JsiSkFontMgr.d.ts +1 -1
  156. package/lib/typescript/lib/module/skia/web/JsiSkImageFactory.d.ts +1 -1
  157. package/lib/typescript/lib/module/skia/web/JsiSkImageFilterFactory.d.ts +1 -1
  158. package/lib/typescript/lib/module/skia/web/JsiSkPathEffectFactory.d.ts +2 -2
  159. package/lib/typescript/lib/module/skia/web/JsiSkPathFactory.d.ts +1 -1
  160. package/lib/typescript/lib/module/skia/web/JsiSkTypefaceFontProvider.d.ts +1 -1
  161. package/lib/typescript/lib/module/skia/web/JsiSkia.d.ts +3 -3
  162. package/lib/typescript/lib/module/skia/web/JsiVideo.d.ts +1 -1
  163. package/lib/typescript/lib/module/sksg/Recorder/Core.d.ts +1 -1
  164. package/lib/typescript/src/skia/web/Host.d.ts +1 -3
  165. package/lib/typescript/src/skia/web/JsiSkPathFactory.d.ts +1 -1
  166. package/lib/typescript/src/sksg/Recorder/Core.d.ts +1 -5
  167. package/package.json +1 -1
  168. package/react-native-skia.podspec +3 -3
  169. package/src/external/reanimated/useAnimatedImageValue.ts +4 -3
  170. package/src/mock/index.ts +1 -2
  171. package/src/skia/web/Host.ts +5 -4
  172. package/src/skia/web/JsiSkFont.ts +3 -3
  173. package/src/skia/web/JsiSkFontMgr.ts +3 -3
  174. package/src/skia/web/JsiSkImageFactory.ts +3 -3
  175. package/src/skia/web/JsiSkImageFilterFactory.ts +8 -18
  176. package/src/skia/web/JsiSkPathEffectFactory.ts +5 -5
  177. package/src/skia/web/JsiSkPathFactory.ts +3 -8
  178. package/src/skia/web/JsiSkTypefaceFontProvider.ts +3 -3
  179. package/src/skia/web/JsiSkia.ts +7 -4
  180. package/src/skia/web/JsiVideo.ts +2 -1
  181. package/src/sksg/Recorder/Core.ts +5 -7
  182. package/src/sksg/Recorder/Player.ts +5 -6
  183. package/src/sksg/Recorder/commands/Box.ts +3 -5
  184. package/ios/RNSkia-iOS/MetalContext.h +0 -134
  185. package/ios/RNSkia-iOS/MetalContext.mm +0 -34
  186. package/ios/RNSkia-iOS/MetalWindowContext.h +0 -39
  187. package/ios/RNSkia-iOS/MetalWindowContext.mm +0 -60
  188. package/ios/RNSkia-iOS/RNSkMetalCanvasProvider.h +0 -38
  189. package/ios/RNSkia-iOS/RNSkMetalCanvasProvider.mm +0 -103
  190. package/ios/RNSkia-iOS/RNSkiOSPlatformContext.h +0 -75
  191. package/ios/RNSkia-iOS/RNSkiOSPlatformContext.mm +0 -303
  192. package/ios/RNSkia-iOS/RNSkiOSVideo.h +0 -51
  193. package/ios/RNSkia-iOS/RNSkiOSVideo.mm +0 -137
  194. package/ios/RNSkia-iOS/RNSkiOSView.h +0 -37
  195. package/ios/RNSkia-iOS/RNSkiOSView.mm +0 -35
  196. package/ios/RNSkia-iOS/SkiaCVPixelBufferUtils.h +0 -119
  197. package/ios/RNSkia-iOS/SkiaCVPixelBufferUtils.mm +0 -344
  198. package/ios/RNSkia-iOS/SkiaManager.h +0 -25
  199. package/ios/RNSkia-iOS/SkiaManager.mm +0 -62
  200. package/ios/RNSkia-iOS/SkiaPictureView.h +0 -7
  201. package/ios/RNSkia-iOS/SkiaPictureView.mm +0 -66
  202. package/ios/RNSkia-iOS/SkiaPictureViewManager.h +0 -8
  203. package/ios/RNSkia-iOS/SkiaPictureViewManager.mm +0 -51
  204. package/ios/RNSkia-iOS/SkiaUIView.h +0 -37
  205. package/ios/RNSkia-iOS/SkiaUIView.mm +0 -168
  206. package/ios/RNSkia-iOS/ViewScreenshotService.h +0 -21
  207. package/ios/RNSkia-iOS/ViewScreenshotService.mm +0 -85
  208. package/ios/RNSkiaModule.h +0 -20
  209. package/ios/RNSkiaModule.mm +0 -55
  210. package/ios/Rnskia.xcodeproj/project.pbxproj +0 -281
  211. package/ios/Rnskia.xcworkspace/contents.xcworkspacedata +0 -7
@@ -1,134 +0,0 @@
1
- #pragma once
2
-
3
- #include "MetalWindowContext.h"
4
- #include "SkiaCVPixelBufferUtils.h"
5
-
6
- #include "include/core/SkSurface.h"
7
-
8
- #import <include/gpu/ganesh/GrBackendSurface.h>
9
- #import <include/gpu/ganesh/GrDirectContext.h>
10
- #import <include/gpu/ganesh/SkImageGanesh.h>
11
- #import <include/gpu/ganesh/SkSurfaceGanesh.h>
12
- #import <include/gpu/ganesh/mtl/GrMtlBackendContext.h>
13
- #import <include/gpu/ganesh/mtl/GrMtlBackendSurface.h>
14
- #import <include/gpu/ganesh/mtl/GrMtlDirectContext.h>
15
- #import <include/gpu/ganesh/mtl/SkSurfaceMetal.h>
16
-
17
- // namespace RNSkia {
18
- // class RNSkiOSPlatformContext;
19
- // }
20
-
21
- class MetalSharedContext {
22
- public:
23
- static MetalSharedContext &getInstance() {
24
- static MetalSharedContext instance;
25
- return instance;
26
- }
27
-
28
- id<MTLDevice> getDevice() { return _device; }
29
-
30
- private:
31
- MetalSharedContext() {
32
- _device = MTLCreateSystemDefaultDevice();
33
- if (!_device) {
34
- throw std::runtime_error("Failed to create Metal device");
35
- }
36
- }
37
-
38
- MetalSharedContext(const MetalSharedContext &) = delete;
39
- MetalSharedContext &operator=(const MetalSharedContext &) = delete;
40
-
41
- id<MTLDevice> _device;
42
- };
43
-
44
- struct OffscreenRenderContext {
45
- id<MTLTexture> texture;
46
-
47
- OffscreenRenderContext(id<MTLDevice> device,
48
- sk_sp<GrDirectContext> skiaContext,
49
- id<MTLCommandQueue> commandQueue, int width,
50
- int height) {
51
- // Create a Metal texture descriptor
52
- MTLTextureDescriptor *textureDescriptor = [MTLTextureDescriptor
53
- texture2DDescriptorWithPixelFormat:MTLPixelFormatBGRA8Unorm
54
- width:width
55
- height:height
56
- mipmapped:NO];
57
- textureDescriptor.usage =
58
- MTLTextureUsageRenderTarget | MTLTextureUsageShaderRead;
59
- texture = [device newTextureWithDescriptor:textureDescriptor];
60
- }
61
- };
62
-
63
- class MetalContext {
64
-
65
- public:
66
- MetalContext(const MetalContext &) = delete;
67
- MetalContext &operator=(const MetalContext &) = delete;
68
-
69
- static MetalContext &getInstance() {
70
- static thread_local MetalContext instance;
71
- return instance;
72
- }
73
-
74
- sk_sp<SkSurface> MakeOffscreen(int width, int height) {
75
- auto device = MetalSharedContext::getInstance().getDevice();
76
- auto ctx = new OffscreenRenderContext(device, _directContext, _commandQueue,
77
- width, height);
78
-
79
- // Create a GrBackendTexture from the Metal texture
80
- GrMtlTextureInfo info;
81
- info.fTexture.retain((__bridge void *)ctx->texture);
82
- GrBackendTexture backendTexture =
83
- GrBackendTextures::MakeMtl(width, height, skgpu::Mipmapped::kNo, info);
84
-
85
- // Create a SkSurface from the GrBackendTexture
86
- auto surface = SkSurfaces::WrapBackendTexture(
87
- _directContext.get(), backendTexture, kTopLeft_GrSurfaceOrigin, 0,
88
- kBGRA_8888_SkColorType, nullptr, nullptr,
89
- [](void *addr) { delete (OffscreenRenderContext *)addr; }, ctx);
90
-
91
- return surface;
92
- }
93
-
94
- sk_sp<SkImage> MakeImageFromBuffer(void *buffer) {
95
-
96
- CVPixelBufferRef sampleBuffer = (CVPixelBufferRef)buffer;
97
- SkiaCVPixelBufferUtils::CVPixelBufferBaseFormat format =
98
- SkiaCVPixelBufferUtils::getCVPixelBufferBaseFormat(sampleBuffer);
99
- switch (format) {
100
- case SkiaCVPixelBufferUtils::CVPixelBufferBaseFormat::rgb: {
101
- // CVPixelBuffer is in any RGB format, single-plane
102
- return SkiaCVPixelBufferUtils::RGB::makeSkImageFromCVPixelBuffer(
103
- _directContext.get(), sampleBuffer);
104
- }
105
- case SkiaCVPixelBufferUtils::CVPixelBufferBaseFormat::yuv: {
106
- // CVPixelBuffer is in any YUV format, multi-plane
107
- return SkiaCVPixelBufferUtils::YUV::makeSkImageFromCVPixelBuffer(
108
- _directContext.get(), sampleBuffer);
109
- }
110
- default:
111
- [[unlikely]] {
112
- throw std::runtime_error("Failed to convert NativeBuffer to SkImage - "
113
- "NativeBuffer has unsupported PixelFormat! " +
114
- std::to_string(static_cast<int>(format)));
115
- }
116
- }
117
- }
118
-
119
- std::unique_ptr<RNSkia::WindowContext> MakeWindow(CALayer *window, int width,
120
- int height) {
121
- auto device = MetalSharedContext::getInstance().getDevice();
122
- return std::make_unique<MetalWindowContext>(
123
- _directContext.get(), device, _commandQueue, window, width, height);
124
- }
125
-
126
- GrDirectContext *getDirectContext() { return _directContext.get(); }
127
-
128
- private:
129
- // friend class RNSkia::RNSkiOSPlatformContext;
130
- id<MTLCommandQueue> _commandQueue = nullptr;
131
- sk_sp<GrDirectContext> _directContext = nullptr;
132
-
133
- MetalContext();
134
- };
@@ -1,34 +0,0 @@
1
- #include "MetalContext.h"
2
-
3
- #include "RNSkLog.h"
4
-
5
- #import <MetalKit/MetalKit.h>
6
-
7
- #pragma clang diagnostic push
8
- #pragma clang diagnostic ignored "-Wdocumentation"
9
-
10
- #import <include/gpu/ganesh/GrBackendSurface.h>
11
- #import <include/gpu/ganesh/SkImageGanesh.h>
12
- #import <include/gpu/ganesh/mtl/GrMtlBackendContext.h>
13
- #import <include/gpu/ganesh/mtl/GrMtlBackendSurface.h>
14
- #import <include/gpu/ganesh/mtl/GrMtlDirectContext.h>
15
- #import <include/gpu/ganesh/mtl/GrMtlTypes.h>
16
- #import <include/gpu/ganesh/mtl/SkSurfaceMetal.h>
17
-
18
- #pragma clang diagnostic pop
19
-
20
- MetalContext::MetalContext() {
21
- auto device = MetalSharedContext::getInstance().getDevice();
22
- _commandQueue =
23
- id<MTLCommandQueue>(CFRetain((GrMTLHandle)[device newCommandQueue]));
24
- GrMtlBackendContext backendContext = {};
25
- backendContext.fDevice.reset((__bridge void *)device);
26
- backendContext.fQueue.reset((__bridge void *)_commandQueue);
27
- GrContextOptions grContextOptions; // set different options here.
28
-
29
- // Create the Skia Direct Context
30
- _directContext = GrDirectContexts::MakeMetal(backendContext);
31
- if (_directContext == nullptr) {
32
- RNSkia::RNSkLogger::logToConsole("Couldn't create a Skia Metal Context");
33
- }
34
- }
@@ -1,39 +0,0 @@
1
- #pragma once
2
-
3
- #import <MetalKit/MetalKit.h>
4
-
5
- #include "WindowContext.h"
6
-
7
- class SkiaMetalContext;
8
-
9
- class MetalWindowContext : public RNSkia::WindowContext {
10
- public:
11
- MetalWindowContext(GrDirectContext *directContext, id<MTLDevice> device,
12
- id<MTLCommandQueue> commandQueue, CALayer *layer,
13
- int width, int height);
14
- ~MetalWindowContext() = default;
15
-
16
- sk_sp<SkSurface> getSurface() override;
17
-
18
- void present() override;
19
-
20
- int getWidth() override {
21
- return _layer.frame.size.width * _layer.contentsScale;
22
- };
23
-
24
- int getHeight() override {
25
- return _layer.frame.size.height * _layer.contentsScale;
26
- };
27
-
28
- void resize(int width, int height) override { _skSurface = nullptr; }
29
-
30
- private:
31
- GrDirectContext *_directContext;
32
- id<MTLCommandQueue> _commandQueue;
33
- sk_sp<SkSurface> _skSurface = nullptr;
34
- #pragma clang diagnostic push
35
- #pragma clang diagnostic ignored "-Wunguarded-availability-new"
36
- CAMetalLayer *_layer;
37
- #pragma clang diagnostic pop
38
- id<CAMetalDrawable> _currentDrawable = nil;
39
- };
@@ -1,60 +0,0 @@
1
- #include "MetalWindowContext.h"
2
-
3
- #include "MetalContext.h"
4
- #include "RNSkLog.h"
5
-
6
- MetalWindowContext::MetalWindowContext(GrDirectContext *directContext,
7
- id<MTLDevice> device,
8
- id<MTLCommandQueue> commandQueue,
9
- CALayer *layer, int width, int height)
10
- : _directContext(directContext), _commandQueue(commandQueue) {
11
- #pragma clang diagnostic push
12
- #pragma clang diagnostic ignored "-Wunguarded-availability-new"
13
- _layer = (CAMetalLayer *)layer;
14
- #pragma clang diagnostic pop
15
- _layer.framebufferOnly = NO;
16
- _layer.device = device;
17
- _layer.opaque = false;
18
- _layer.contentsScale = [UIScreen mainScreen].scale;
19
- _layer.pixelFormat = MTLPixelFormatBGRA8Unorm;
20
- _layer.contentsGravity = kCAGravityBottomLeft;
21
- _layer.drawableSize = CGSizeMake(width, height);
22
- }
23
-
24
- sk_sp<SkSurface> MetalWindowContext::getSurface() {
25
- if (_skSurface) {
26
- return _skSurface;
27
- }
28
-
29
- // Get the next drawable from the CAMetalLayer
30
- _currentDrawable = [_layer nextDrawable];
31
- if (!_currentDrawable) {
32
- RNSkia::RNSkLogger::logToConsole(
33
- "Could not retrieve drawable from CAMetalLayer");
34
- return nullptr;
35
- }
36
-
37
- // Get the texture from the drawable
38
- GrMtlTextureInfo fbInfo;
39
- fbInfo.fTexture.retain((__bridge void *)_currentDrawable.texture);
40
-
41
- GrBackendRenderTarget backendRT = GrBackendRenderTargets::MakeMtl(
42
- _layer.drawableSize.width, _layer.drawableSize.height, fbInfo);
43
-
44
- _skSurface = SkSurfaces::WrapBackendRenderTarget(
45
- _directContext, backendRT, kTopLeft_GrSurfaceOrigin,
46
- kBGRA_8888_SkColorType, nullptr, nullptr);
47
-
48
- return _skSurface;
49
- }
50
-
51
- void MetalWindowContext::present() {
52
- if (auto dContext = GrAsDirectContext(_skSurface->recordingContext())) {
53
- dContext->flushAndSubmit();
54
- }
55
-
56
- id<MTLCommandBuffer> commandBuffer([_commandQueue commandBuffer]);
57
- [commandBuffer presentDrawable:_currentDrawable];
58
- [commandBuffer commit];
59
- _skSurface = nullptr;
60
- }
@@ -1,38 +0,0 @@
1
- #pragma once
2
-
3
- #import "RNSkPlatformContext.h"
4
- #import "RNSkView.h"
5
-
6
- #import <MetalKit/MetalKit.h>
7
- #import <QuartzCore/CAMetalLayer.h>
8
-
9
- #pragma clang diagnostic push
10
- #pragma clang diagnostic ignored "-Wdocumentation"
11
-
12
- #import <include/gpu/ganesh/GrDirectContext.h>
13
-
14
- #pragma clang diagnostic pop
15
-
16
- class RNSkMetalCanvasProvider : public RNSkia::RNSkCanvasProvider {
17
- public:
18
- RNSkMetalCanvasProvider(std::function<void()> requestRedraw,
19
- std::shared_ptr<RNSkia::RNSkPlatformContext> context);
20
-
21
- ~RNSkMetalCanvasProvider();
22
-
23
- int getScaledWidth() override;
24
- int getScaledHeight() override;
25
-
26
- bool renderToCanvas(const std::function<void(SkCanvas *)> &cb) override;
27
-
28
- void setSize(int width, int height);
29
- CALayer *getLayer();
30
-
31
- private:
32
- std::shared_ptr<RNSkia::RNSkPlatformContext> _context;
33
- std::unique_ptr<RNSkia::WindowContext> _ctx = nullptr;
34
- #pragma clang diagnostic push
35
- #pragma clang diagnostic ignored "-Wunguarded-availability-new"
36
- CAMetalLayer *_layer;
37
- #pragma clang diagnostic pop
38
- };
@@ -1,103 +0,0 @@
1
- #import "RNSkMetalCanvasProvider.h"
2
-
3
- #import "RNSkLog.h"
4
-
5
- #if defined(SK_GRAPHITE)
6
- #import "DawnContext.h"
7
- #else
8
- #import "MetalContext.h"
9
- #endif
10
-
11
- #pragma clang diagnostic push
12
- #pragma clang diagnostic ignored "-Wdocumentation"
13
-
14
- #import "include/core/SkCanvas.h"
15
- #import "include/core/SkColorSpace.h"
16
- #import "include/core/SkSurface.h"
17
-
18
- #import <include/gpu/ganesh/GrBackendSurface.h>
19
- #import <include/gpu/ganesh/GrDirectContext.h>
20
- #import <include/gpu/ganesh/SkSurfaceGanesh.h>
21
-
22
- #pragma clang diagnostic pop
23
-
24
- RNSkMetalCanvasProvider::RNSkMetalCanvasProvider(
25
- std::function<void()> requestRedraw,
26
- std::shared_ptr<RNSkia::RNSkPlatformContext> context)
27
- : RNSkCanvasProvider(requestRedraw), _context(context) {
28
- #pragma clang diagnostic push
29
- #pragma clang diagnostic ignored "-Wunguarded-availability-new"
30
- _layer = [CAMetalLayer layer];
31
- #pragma clang diagnostic pop
32
- }
33
-
34
- RNSkMetalCanvasProvider::~RNSkMetalCanvasProvider() {}
35
-
36
- /**
37
- Returns the scaled width of the view
38
- */
39
- int RNSkMetalCanvasProvider::getScaledWidth() {
40
- return _ctx ? _ctx->getWidth() : -1;
41
- };
42
-
43
- /**
44
- Returns the scaled height of the view
45
- */
46
- int RNSkMetalCanvasProvider::getScaledHeight() {
47
- return _ctx ? _ctx->getHeight() : -1;
48
- };
49
-
50
- /**
51
- Render to a canvas
52
- */
53
- bool RNSkMetalCanvasProvider::renderToCanvas(
54
- const std::function<void(SkCanvas *)> &cb) {
55
- if (!_ctx) {
56
- return false;
57
- }
58
-
59
- // Make sure to NOT render or try any render operations while we're in the
60
- // background or inactive. This will cause an error that might clear the
61
- // CAMetalLayer so that the canvas is empty when the app receives focus again.
62
- // Reference: https://github.com/Shopify/react-native-skia/issues/1257
63
- // NOTE: UIApplication.sharedApplication.applicationState can only be
64
- // accessed from the main thread so we need to check here.
65
- if ([[NSThread currentThread] isMainThread]) {
66
- auto state = UIApplication.sharedApplication.applicationState;
67
- if (state == UIApplicationStateBackground) {
68
- // Request a redraw in the next run loop callback
69
- _requestRedraw();
70
- // and don't draw now since it might cause errors in the metal renderer if
71
- // we try to render while in the background. (see above issue)
72
- return false;
73
- }
74
- }
75
- // Wrap in auto release pool since we want the system to clean up after
76
- // rendering and not wait until later - we've seen some example of memory
77
- // usage growing very fast in the simulator without this.
78
- @autoreleasepool {
79
- auto surface = _ctx->getSurface();
80
- if (!surface) {
81
- return false;
82
- }
83
- auto canvas = surface->getCanvas();
84
- cb(canvas);
85
- _ctx->present();
86
- }
87
- return true;
88
- };
89
-
90
- void RNSkMetalCanvasProvider::setSize(int width, int height) {
91
- _layer.frame = CGRectMake(0, 0, width, height);
92
- auto w = width * _context->getPixelDensity();
93
- auto h = height * _context->getPixelDensity();
94
- #if defined(SK_GRAPHITE)
95
- _ctx = RNSkia::DawnContext::getInstance().MakeWindow((__bridge void *)_layer,
96
- w, h);
97
- #else
98
- _ctx = MetalContext::getInstance().MakeWindow(_layer, w, h);
99
- #endif
100
- _requestRedraw();
101
- }
102
-
103
- CALayer *RNSkMetalCanvasProvider::getLayer() { return _layer; }
@@ -1,75 +0,0 @@
1
- #pragma once
2
-
3
- #import <React/RCTBridge+Private.h>
4
- #import <React/RCTBridge.h>
5
-
6
- #include <functional>
7
- #include <memory>
8
- #include <string>
9
-
10
- #include "RNSkPlatformContext.h"
11
- #include "ViewScreenshotService.h"
12
-
13
- namespace facebook {
14
- namespace react {
15
- class CallInvoker;
16
- }
17
- } // namespace facebook
18
-
19
- namespace RNSkia {
20
-
21
- class RNSkiOSPlatformContext : public RNSkPlatformContext {
22
- public:
23
- RNSkiOSPlatformContext(
24
- RCTBridge *bridge,
25
- std::shared_ptr<facebook::react::CallInvoker> jsCallInvoker)
26
- : RNSkPlatformContext(jsCallInvoker, [[UIScreen mainScreen] scale]) {
27
-
28
- // Create screenshot manager
29
- _screenshotService =
30
- [[ViewScreenshotService alloc] initWithUiManager:bridge.uiManager];
31
- }
32
-
33
- ~RNSkiOSPlatformContext() = default;
34
-
35
- void runOnMainThread(std::function<void()>) override;
36
-
37
- sk_sp<SkImage> takeScreenshotFromViewTag(size_t tag) override;
38
-
39
- sk_sp<SkImage> makeImageFromNativeBuffer(void *buffer) override;
40
-
41
- sk_sp<SkImage> makeImageFromNativeTexture(const TextureInfo &textureInfo,
42
- int width, int height,
43
- bool mipMapped) override;
44
-
45
- uint64_t makeNativeBuffer(sk_sp<SkImage> image) override;
46
-
47
- const TextureInfo getTexture(sk_sp<SkSurface> image) override;
48
-
49
- const TextureInfo getTexture(sk_sp<SkImage> image) override;
50
-
51
- void releaseNativeBuffer(uint64_t pointer) override;
52
-
53
- std::shared_ptr<RNSkVideo> createVideo(const std::string &url) override;
54
-
55
- std::shared_ptr<WindowContext>
56
- makeContextFromNativeSurface(void *surface, int width, int height) override;
57
-
58
- virtual void performStreamOperation(
59
- const std::string &sourceUri,
60
- const std::function<void(std::unique_ptr<SkStreamAsset>)> &op) override;
61
-
62
- void raiseError(const std::exception &err) override;
63
- sk_sp<SkSurface> makeOffscreenSurface(int width, int height) override;
64
- #if !defined(SK_GRAPHITE)
65
- GrDirectContext *getDirectContext() override;
66
- #endif
67
- sk_sp<SkFontMgr> createFontMgr() override;
68
-
69
- private:
70
- ViewScreenshotService *_screenshotService;
71
-
72
- SkColorType mtlPixelFormatToSkColorType(MTLPixelFormat pixelFormat);
73
- };
74
-
75
- } // namespace RNSkia