@shopify/react-native-skia 1.5.10 → 1.7.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (171) hide show
  1. package/android/cpp/jni/include/JniSkiaBaseView.h +6 -5
  2. package/android/cpp/jni/include/JniSkiaDomView.h +6 -4
  3. package/android/cpp/jni/include/JniSkiaManager.h +2 -2
  4. package/android/cpp/jni/include/JniSkiaPictureView.h +6 -4
  5. package/android/cpp/rnskia-android/MainThreadDispatcher.h +3 -0
  6. package/android/cpp/rnskia-android/OpenGLContext.h +44 -9
  7. package/android/cpp/rnskia-android/OpenGLWindowContext.cpp +0 -1
  8. package/android/cpp/rnskia-android/OpenGLWindowContext.h +2 -2
  9. package/android/cpp/rnskia-android/RNSkAndroidPlatformContext.h +61 -3
  10. package/android/cpp/rnskia-android/RNSkAndroidView.h +10 -13
  11. package/android/cpp/rnskia-android/RNSkOpenGLCanvasProvider.cpp +42 -36
  12. package/android/cpp/rnskia-android/RNSkOpenGLCanvasProvider.h +2 -2
  13. package/android/cpp/rnskia-android/gl/Display.h +2 -0
  14. package/android/src/main/java/com/shopify/reactnative/skia/SkiaAHBView.java +113 -0
  15. package/android/src/main/java/com/shopify/reactnative/skia/SkiaBaseView.java +45 -54
  16. package/android/src/main/java/com/shopify/reactnative/skia/SkiaBaseViewManager.java +5 -0
  17. package/android/src/main/java/com/shopify/reactnative/skia/SkiaDomView.java +2 -2
  18. package/android/src/main/java/com/shopify/reactnative/skia/SkiaPictureView.java +2 -2
  19. package/android/src/main/java/com/shopify/reactnative/skia/SkiaSurfaceView.java +42 -0
  20. package/android/src/main/java/com/shopify/reactnative/skia/SkiaTextureView.java +90 -0
  21. package/android/src/main/java/com/shopify/reactnative/skia/SkiaViewAPI.java +16 -0
  22. package/android/src/paper/java/com/facebook/react/viewmanagers/SkiaDomViewManagerDelegate.java +3 -0
  23. package/android/src/paper/java/com/facebook/react/viewmanagers/SkiaDomViewManagerInterface.java +1 -0
  24. package/android/src/paper/java/com/facebook/react/viewmanagers/SkiaPictureViewManagerDelegate.java +3 -1
  25. package/android/src/paper/java/com/facebook/react/viewmanagers/SkiaPictureViewManagerInterface.java +1 -0
  26. package/cpp/api/JsiSkContourMeasure.h +1 -5
  27. package/cpp/api/JsiSkImage.h +11 -0
  28. package/cpp/api/JsiSkImageFactory.h +14 -0
  29. package/cpp/api/JsiSkPicture.h +2 -0
  30. package/cpp/api/JsiSkSurface.h +7 -0
  31. package/cpp/api/JsiTextureInfo.h +53 -0
  32. package/cpp/jsi/ViewProperty.h +48 -0
  33. package/cpp/rnskia/RNSkDomView.cpp +0 -20
  34. package/cpp/rnskia/RNSkDomView.h +4 -9
  35. package/cpp/rnskia/RNSkJsiViewApi.h +3 -3
  36. package/cpp/rnskia/RNSkPictureView.h +11 -28
  37. package/cpp/rnskia/RNSkPlatformContext.h +18 -12
  38. package/cpp/rnskia/RNSkView.h +5 -29
  39. package/ios/RNSkia-iOS/MetalContext.h +101 -15
  40. package/ios/RNSkia-iOS/MetalContext.mm +9 -8
  41. package/ios/RNSkia-iOS/MetalWindowContext.h +39 -0
  42. package/ios/RNSkia-iOS/MetalWindowContext.mm +60 -0
  43. package/ios/RNSkia-iOS/RNSkiOSPlatformContext.h +13 -25
  44. package/ios/RNSkia-iOS/RNSkiOSPlatformContext.mm +88 -2
  45. package/ios/RNSkia-iOS/SkiaCVPixelBufferUtils.mm +9 -2
  46. package/ios/RNSkia-iOS/SkiaDomViewManager.mm +5 -0
  47. package/ios/RNSkia-iOS/SkiaManager.mm +1 -2
  48. package/ios/RNSkia-iOS/SkiaPictureView.mm +1 -0
  49. package/ios/RNSkia-iOS/SkiaPictureViewManager.mm +5 -0
  50. package/ios/RNSkia-iOS/SkiaUIView.h +1 -0
  51. package/ios/RNSkia-iOS/SkiaUIView.mm +21 -14
  52. package/lib/commonjs/skia/types/Image/ColorType.d.ts +21 -0
  53. package/lib/commonjs/skia/types/Image/ColorType.js +29 -0
  54. package/lib/commonjs/skia/types/Image/ColorType.js.map +1 -0
  55. package/lib/commonjs/skia/types/Image/ColorType.web.d.ts +19 -0
  56. package/lib/commonjs/skia/types/Image/ColorType.web.js +27 -0
  57. package/lib/commonjs/skia/types/Image/ColorType.web.js.map +1 -0
  58. package/lib/commonjs/skia/types/Image/Image.d.ts +10 -0
  59. package/lib/commonjs/skia/types/Image/Image.js.map +1 -1
  60. package/lib/commonjs/skia/types/Image/ImageFactory.d.ts +19 -19
  61. package/lib/commonjs/skia/types/Image/ImageFactory.js +1 -21
  62. package/lib/commonjs/skia/types/Image/ImageFactory.js.map +1 -1
  63. package/lib/commonjs/skia/types/Image/index.d.ts +1 -0
  64. package/lib/commonjs/skia/types/Image/index.js +11 -0
  65. package/lib/commonjs/skia/types/Image/index.js.map +1 -1
  66. package/lib/commonjs/skia/types/Matrix4.d.ts +6 -0
  67. package/lib/commonjs/skia/types/Matrix4.js +69 -1
  68. package/lib/commonjs/skia/types/Matrix4.js.map +1 -1
  69. package/lib/commonjs/skia/types/Surface/Surface.d.ts +11 -0
  70. package/lib/commonjs/skia/types/Surface/Surface.js.map +1 -1
  71. package/lib/commonjs/skia/web/JsiSkImage.d.ts +1 -0
  72. package/lib/commonjs/skia/web/JsiSkImage.js +4 -0
  73. package/lib/commonjs/skia/web/JsiSkImage.js.map +1 -1
  74. package/lib/commonjs/skia/web/JsiSkImageFactory.d.ts +1 -0
  75. package/lib/commonjs/skia/web/JsiSkImageFactory.js +3 -0
  76. package/lib/commonjs/skia/web/JsiSkImageFactory.js.map +1 -1
  77. package/lib/commonjs/skia/web/JsiSkSurface.d.ts +1 -0
  78. package/lib/commonjs/skia/web/JsiSkSurface.js +4 -0
  79. package/lib/commonjs/skia/web/JsiSkSurface.js.map +1 -1
  80. package/lib/commonjs/specs/SkiaPictureViewNativeComponent.d.ts +1 -0
  81. package/lib/commonjs/specs/SkiaPictureViewNativeComponent.js.map +1 -1
  82. package/lib/commonjs/views/SkiaDomView.js +3 -1
  83. package/lib/commonjs/views/SkiaDomView.js.map +1 -1
  84. package/lib/commonjs/views/SkiaPictureView.js +5 -1
  85. package/lib/commonjs/views/SkiaPictureView.js.map +1 -1
  86. package/lib/commonjs/views/types.d.ts +2 -0
  87. package/lib/commonjs/views/types.js.map +1 -1
  88. package/lib/module/skia/types/Image/ColorType.d.ts +21 -0
  89. package/lib/module/skia/types/Image/ColorType.js +23 -0
  90. package/lib/module/skia/types/Image/ColorType.js.map +1 -0
  91. package/lib/module/skia/types/Image/ColorType.web.d.ts +19 -0
  92. package/lib/module/skia/types/Image/ColorType.web.js +21 -0
  93. package/lib/module/skia/types/Image/ColorType.web.js.map +1 -0
  94. package/lib/module/skia/types/Image/Image.d.ts +10 -0
  95. package/lib/module/skia/types/Image/Image.js.map +1 -1
  96. package/lib/module/skia/types/Image/ImageFactory.d.ts +19 -19
  97. package/lib/module/skia/types/Image/ImageFactory.js +0 -20
  98. package/lib/module/skia/types/Image/ImageFactory.js.map +1 -1
  99. package/lib/module/skia/types/Image/index.d.ts +1 -0
  100. package/lib/module/skia/types/Image/index.js +1 -0
  101. package/lib/module/skia/types/Image/index.js.map +1 -1
  102. package/lib/module/skia/types/Matrix4.d.ts +6 -0
  103. package/lib/module/skia/types/Matrix4.js +67 -0
  104. package/lib/module/skia/types/Matrix4.js.map +1 -1
  105. package/lib/module/skia/types/Surface/Surface.d.ts +11 -0
  106. package/lib/module/skia/types/Surface/Surface.js.map +1 -1
  107. package/lib/module/skia/web/JsiSkImage.d.ts +1 -0
  108. package/lib/module/skia/web/JsiSkImage.js +4 -0
  109. package/lib/module/skia/web/JsiSkImage.js.map +1 -1
  110. package/lib/module/skia/web/JsiSkImageFactory.d.ts +1 -0
  111. package/lib/module/skia/web/JsiSkImageFactory.js +3 -0
  112. package/lib/module/skia/web/JsiSkImageFactory.js.map +1 -1
  113. package/lib/module/skia/web/JsiSkSurface.d.ts +1 -0
  114. package/lib/module/skia/web/JsiSkSurface.js +4 -0
  115. package/lib/module/skia/web/JsiSkSurface.js.map +1 -1
  116. package/lib/module/specs/SkiaPictureViewNativeComponent.d.ts +1 -0
  117. package/lib/module/specs/SkiaPictureViewNativeComponent.js.map +1 -1
  118. package/lib/module/views/SkiaDomView.js +3 -1
  119. package/lib/module/views/SkiaDomView.js.map +1 -1
  120. package/lib/module/views/SkiaPictureView.js +5 -1
  121. package/lib/module/views/SkiaPictureView.js.map +1 -1
  122. package/lib/module/views/types.d.ts +2 -0
  123. package/lib/module/views/types.js.map +1 -1
  124. package/lib/typescript/lib/commonjs/skia/types/Image/ColorType.d.ts +2 -0
  125. package/lib/typescript/lib/commonjs/skia/types/Image/ColorType.web.d.ts +2 -0
  126. package/lib/typescript/lib/commonjs/skia/types/Image/ImageFactory.d.ts +0 -1
  127. package/lib/typescript/lib/commonjs/skia/types/Matrix4.d.ts +6 -0
  128. package/lib/typescript/lib/commonjs/skia/web/JsiSkImage.d.ts +1 -0
  129. package/lib/typescript/lib/commonjs/skia/web/JsiSkImageFactory.d.ts +1 -0
  130. package/lib/typescript/lib/commonjs/skia/web/JsiSkSurface.d.ts +1 -0
  131. package/lib/typescript/lib/module/mock/index.d.ts +1 -0
  132. package/lib/typescript/lib/module/skia/types/Image/ColorType.d.ts +1 -0
  133. package/lib/typescript/lib/module/skia/types/Image/ColorType.web.d.ts +1 -0
  134. package/lib/typescript/lib/module/skia/types/Image/ImageFactory.d.ts +0 -1
  135. package/lib/typescript/lib/module/skia/types/Image/index.d.ts +1 -0
  136. package/lib/typescript/lib/module/skia/types/Matrix4.d.ts +1 -0
  137. package/lib/typescript/lib/module/skia/web/JsiSkImage.d.ts +1 -0
  138. package/lib/typescript/lib/module/skia/web/JsiSkImageFactory.d.ts +1 -0
  139. package/lib/typescript/lib/module/skia/web/JsiSkSurface.d.ts +1 -0
  140. package/lib/typescript/src/skia/types/Image/ColorType.d.ts +21 -0
  141. package/lib/typescript/src/skia/types/Image/ColorType.web.d.ts +19 -0
  142. package/lib/typescript/src/skia/types/Image/Image.d.ts +10 -0
  143. package/lib/typescript/src/skia/types/Image/ImageFactory.d.ts +19 -19
  144. package/lib/typescript/src/skia/types/Image/index.d.ts +1 -0
  145. package/lib/typescript/src/skia/types/Matrix4.d.ts +6 -0
  146. package/lib/typescript/src/skia/types/Surface/Surface.d.ts +11 -0
  147. package/lib/typescript/src/skia/web/JsiSkImage.d.ts +1 -0
  148. package/lib/typescript/src/skia/web/JsiSkImageFactory.d.ts +1 -0
  149. package/lib/typescript/src/skia/web/JsiSkSurface.d.ts +1 -0
  150. package/lib/typescript/src/specs/SkiaPictureViewNativeComponent.d.ts +1 -0
  151. package/lib/typescript/src/views/types.d.ts +2 -0
  152. package/package.json +1 -1
  153. package/src/renderer/__tests__/e2e/Matrix4.spec.tsx +93 -0
  154. package/src/skia/__tests__/Enums.spec.ts +2 -2
  155. package/src/skia/types/Image/ColorType.ts +21 -0
  156. package/src/skia/types/Image/ColorType.web.ts +19 -0
  157. package/src/skia/types/Image/Image.ts +11 -0
  158. package/src/skia/types/Image/ImageFactory.ts +25 -20
  159. package/src/skia/types/Image/index.ts +1 -0
  160. package/src/skia/types/Matrix4.ts +101 -0
  161. package/src/skia/types/Surface/Surface.ts +12 -0
  162. package/src/skia/web/JsiSkImage.ts +5 -0
  163. package/src/skia/web/JsiSkImageFactory.ts +4 -0
  164. package/src/skia/web/JsiSkSurface.ts +5 -0
  165. package/src/specs/SkiaPictureViewNativeComponent.ts +1 -0
  166. package/src/views/SkiaDomView.tsx +2 -1
  167. package/src/views/SkiaPictureView.tsx +4 -1
  168. package/src/views/types.ts +3 -0
  169. package/cpp/jsi/JsiValueWrapper.h +0 -164
  170. package/ios/RNSkia-iOS/SkiaMetalSurfaceFactory.h +0 -128
  171. package/ios/RNSkia-iOS/SkiaMetalSurfaceFactory.mm +0 -92
@@ -1,128 +0,0 @@
1
- #pragma once
2
-
3
- #import <MetalKit/MetalKit.h>
4
-
5
- #include <memory>
6
-
7
- #include "RNSkLog.h"
8
- #include "WindowContext.h"
9
-
10
- #pragma clang diagnostic push
11
- #pragma clang diagnostic ignored "-Wdocumentation"
12
-
13
- #import "include/core/SkCanvas.h"
14
- #import "include/core/SkColorSpace.h"
15
-
16
- #import <CoreMedia/CMSampleBuffer.h>
17
- #import <CoreVideo/CVMetalTextureCache.h>
18
-
19
- #import <include/gpu/ganesh/GrBackendSurface.h>
20
- #import <include/gpu/ganesh/GrDirectContext.h>
21
- #import <include/gpu/ganesh/SkImageGanesh.h>
22
- #import <include/gpu/ganesh/SkSurfaceGanesh.h>
23
- #import <include/gpu/ganesh/mtl/GrMtlBackendContext.h>
24
- #import <include/gpu/ganesh/mtl/GrMtlBackendSurface.h>
25
- #import <include/gpu/ganesh/mtl/GrMtlDirectContext.h>
26
- #import <include/gpu/ganesh/mtl/SkSurfaceMetal.h>
27
-
28
- #pragma clang diagnostic pop
29
-
30
- using SkiaMetalContext = struct SkiaMetalContext {
31
- id<MTLCommandQueue> commandQueue = nullptr;
32
- sk_sp<GrDirectContext> skContext = nullptr;
33
- };
34
-
35
- class SkiaMetalSurfaceFactory {
36
- friend class IOSSkiaContext;
37
-
38
- public:
39
- static sk_sp<SkSurface> makeOffscreenSurface(id<MTLDevice> device,
40
- SkiaMetalContext *context,
41
- int width, int height);
42
-
43
- static sk_sp<SkImage>
44
- makeTextureFromCVPixelBuffer(SkiaMetalContext *context,
45
- CVPixelBufferRef pixelBuffer);
46
-
47
- static std::unique_ptr<RNSkia::WindowContext>
48
- makeContext(SkiaMetalContext *context, CALayer *texture, int width,
49
- int height);
50
- };
51
-
52
- class IOSSkiaContext : public RNSkia::WindowContext {
53
- public:
54
- IOSSkiaContext(SkiaMetalContext *context, CALayer *layer, int width,
55
- int height)
56
- : _context(context) {
57
- #pragma clang diagnostic push
58
- #pragma clang diagnostic ignored "-Wunguarded-availability-new"
59
- _layer = (CAMetalLayer *)layer;
60
- #pragma clang diagnostic pop
61
- _layer.framebufferOnly = NO;
62
- _layer.device = MTLCreateSystemDefaultDevice();
63
- _layer.opaque = false;
64
- _layer.contentsScale = [UIScreen mainScreen].scale;
65
- _layer.pixelFormat = MTLPixelFormatBGRA8Unorm;
66
- _layer.contentsGravity = kCAGravityBottomLeft;
67
- _layer.drawableSize = CGSizeMake(width, height);
68
- }
69
-
70
- ~IOSSkiaContext() {}
71
-
72
- sk_sp<SkSurface> getSurface() override {
73
- if (_skSurface) {
74
- return _skSurface;
75
- }
76
-
77
- // Get the next drawable from the CAMetalLayer
78
- _currentDrawable = [_layer nextDrawable];
79
- if (!_currentDrawable) {
80
- RNSkia::RNSkLogger::logToConsole(
81
- "Could not retrieve drawable from CAMetalLayer");
82
- return nullptr;
83
- }
84
-
85
- // Get the texture from the drawable
86
- GrMtlTextureInfo fbInfo;
87
- fbInfo.fTexture.retain((__bridge void *)_currentDrawable.texture);
88
-
89
- GrBackendRenderTarget backendRT = GrBackendRenderTargets::MakeMtl(
90
- _layer.drawableSize.width, _layer.drawableSize.height, fbInfo);
91
-
92
- _skSurface = SkSurfaces::WrapBackendRenderTarget(
93
- _context->skContext.get(), backendRT, kTopLeft_GrSurfaceOrigin,
94
- kBGRA_8888_SkColorType, nullptr, nullptr);
95
-
96
- return _skSurface;
97
- }
98
-
99
- void present() override {
100
- if (auto dContext = GrAsDirectContext(_skSurface->recordingContext())) {
101
- dContext->flushAndSubmit();
102
- }
103
-
104
- id<MTLCommandBuffer> commandBuffer([_context->commandQueue commandBuffer]);
105
- [commandBuffer presentDrawable:_currentDrawable];
106
- [commandBuffer commit];
107
- _skSurface = nullptr;
108
- }
109
-
110
- int getWidth() override {
111
- return _layer.frame.size.width * _layer.contentsScale;
112
- };
113
-
114
- int getHeight() override {
115
- return _layer.frame.size.height * _layer.contentsScale;
116
- };
117
-
118
- void resize(int width, int height) override { _skSurface = nullptr; }
119
-
120
- private:
121
- SkiaMetalContext *_context;
122
- sk_sp<SkSurface> _skSurface = nullptr;
123
- #pragma clang diagnostic push
124
- #pragma clang diagnostic ignored "-Wunguarded-availability-new"
125
- CAMetalLayer *_layer;
126
- #pragma clang diagnostic pop
127
- id<CAMetalDrawable> _currentDrawable = nil;
128
- };
@@ -1,92 +0,0 @@
1
- #import "RNSkLog.h"
2
-
3
- #import "SkiaCVPixelBufferUtils.h"
4
- #import "SkiaMetalSurfaceFactory.h"
5
-
6
- #pragma clang diagnostic push
7
- #pragma clang diagnostic ignored "-Wdocumentation"
8
-
9
- #import "include/core/SkCanvas.h"
10
- #import "include/core/SkColorSpace.h"
11
- #import "include/core/SkSurface.h"
12
-
13
- #import <include/gpu/ganesh/GrBackendSurface.h>
14
- #import <include/gpu/ganesh/GrDirectContext.h>
15
- #import <include/gpu/ganesh/SkImageGanesh.h>
16
- #import <include/gpu/ganesh/SkSurfaceGanesh.h>
17
- #import <include/gpu/ganesh/mtl/GrMtlBackendContext.h>
18
- #import <include/gpu/ganesh/mtl/GrMtlBackendSurface.h>
19
- #import <include/gpu/ganesh/mtl/GrMtlDirectContext.h>
20
- #import <include/gpu/ganesh/mtl/SkSurfaceMetal.h>
21
-
22
- #pragma clang diagnostic pop
23
-
24
- struct OffscreenRenderContext {
25
- id<MTLTexture> texture;
26
-
27
- OffscreenRenderContext(id<MTLDevice> device,
28
- sk_sp<GrDirectContext> skiaContext,
29
- id<MTLCommandQueue> commandQueue, int width,
30
- int height) {
31
- // Create a Metal texture descriptor
32
- MTLTextureDescriptor *textureDescriptor = [MTLTextureDescriptor
33
- texture2DDescriptorWithPixelFormat:MTLPixelFormatBGRA8Unorm
34
- width:width
35
- height:height
36
- mipmapped:NO];
37
- textureDescriptor.usage =
38
- MTLTextureUsageRenderTarget | MTLTextureUsageShaderRead;
39
- texture = [device newTextureWithDescriptor:textureDescriptor];
40
- }
41
- };
42
-
43
- std::unique_ptr<RNSkia::WindowContext>
44
- SkiaMetalSurfaceFactory::makeContext(SkiaMetalContext *context,
45
- CALayer *texture, int width, int height) {
46
- return std::make_unique<IOSSkiaContext>(context, texture, width, height);
47
- }
48
-
49
- sk_sp<SkSurface> SkiaMetalSurfaceFactory::makeOffscreenSurface(
50
- id<MTLDevice> device, SkiaMetalContext *context, int width, int height) {
51
-
52
- auto ctx = new OffscreenRenderContext(device, context->skContext,
53
- context->commandQueue, width, height);
54
-
55
- // Create a GrBackendTexture from the Metal texture
56
- GrMtlTextureInfo info;
57
- info.fTexture.retain((__bridge void *)ctx->texture);
58
- GrBackendTexture backendTexture =
59
- GrBackendTextures::MakeMtl(width, height, skgpu::Mipmapped::kNo, info);
60
-
61
- // Create a SkSurface from the GrBackendTexture
62
- auto surface = SkSurfaces::WrapBackendTexture(
63
- context->skContext.get(), backendTexture, kTopLeft_GrSurfaceOrigin, 0,
64
- kBGRA_8888_SkColorType, nullptr, nullptr,
65
- [](void *addr) { delete (OffscreenRenderContext *)addr; }, ctx);
66
-
67
- return surface;
68
- }
69
-
70
- sk_sp<SkImage> SkiaMetalSurfaceFactory::makeTextureFromCVPixelBuffer(
71
- SkiaMetalContext *context, CVPixelBufferRef pixelBuffer) {
72
- SkiaCVPixelBufferUtils::CVPixelBufferBaseFormat format =
73
- SkiaCVPixelBufferUtils::getCVPixelBufferBaseFormat(pixelBuffer);
74
- switch (format) {
75
- case SkiaCVPixelBufferUtils::CVPixelBufferBaseFormat::rgb: {
76
- // CVPixelBuffer is in any RGB format, single-plane
77
- return SkiaCVPixelBufferUtils::RGB::makeSkImageFromCVPixelBuffer(
78
- context->skContext.get(), pixelBuffer);
79
- }
80
- case SkiaCVPixelBufferUtils::CVPixelBufferBaseFormat::yuv: {
81
- // CVPixelBuffer is in any YUV format, multi-plane
82
- return SkiaCVPixelBufferUtils::YUV::makeSkImageFromCVPixelBuffer(
83
- context->skContext.get(), pixelBuffer);
84
- }
85
- default:
86
- [[unlikely]] {
87
- throw std::runtime_error("Failed to convert NativeBuffer to SkImage - "
88
- "NativeBuffer has unsupported PixelFormat! " +
89
- std::to_string(static_cast<int>(format)));
90
- }
91
- }
92
- }