@shopify/react-native-skia 1.11.11 → 1.12.0
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.
- package/android/build.gradle +10 -0
- package/cpp/rnskia/DawnContext.h +1 -1
- package/lib/commonjs/sksg/Recorder/Core.d.ts +1 -5
- package/lib/commonjs/sksg/Recorder/Core.js +12 -4
- package/lib/commonjs/sksg/Recorder/Core.js.map +1 -1
- package/lib/commonjs/sksg/Recorder/Player.js +4 -5
- package/lib/commonjs/sksg/Recorder/Player.js.map +1 -1
- package/lib/commonjs/sksg/Recorder/commands/Box.js +2 -4
- package/lib/commonjs/sksg/Recorder/commands/Box.js.map +1 -1
- package/lib/commonjs/specs/NativeSkiaModule.web.d.ts +2 -0
- package/lib/commonjs/specs/NativeSkiaModule.web.js +10 -1
- package/lib/commonjs/specs/NativeSkiaModule.web.js.map +1 -1
- package/lib/module/sksg/Recorder/Core.d.ts +1 -5
- package/lib/module/sksg/Recorder/Core.js +10 -2
- package/lib/module/sksg/Recorder/Core.js.map +1 -1
- package/lib/module/sksg/Recorder/Player.js +5 -6
- package/lib/module/sksg/Recorder/Player.js.map +1 -1
- package/lib/module/sksg/Recorder/commands/Box.js +3 -5
- package/lib/module/sksg/Recorder/commands/Box.js.map +1 -1
- package/lib/module/specs/NativeSkiaModule.web.d.ts +2 -0
- package/lib/module/specs/NativeSkiaModule.web.js +10 -1
- package/lib/module/specs/NativeSkiaModule.web.js.map +1 -1
- package/lib/typescript/lib/commonjs/sksg/Recorder/Core.d.ts +1 -1
- package/lib/typescript/lib/module/sksg/Recorder/Core.d.ts +1 -1
- package/lib/typescript/src/sksg/Recorder/Core.d.ts +1 -5
- package/lib/typescript/src/specs/NativeSkiaModule.web.d.ts +2 -0
- package/package.json +5 -4
- package/react-native-skia.podspec +3 -3
- package/src/sksg/Recorder/Core.ts +5 -7
- package/src/sksg/Recorder/Player.ts +5 -6
- package/src/sksg/Recorder/commands/Box.ts +3 -5
- package/src/specs/NativeSkiaModule.web.ts +12 -2
- package/ios/RNSkia-iOS/MetalContext.h +0 -134
- package/ios/RNSkia-iOS/MetalContext.mm +0 -34
- package/ios/RNSkia-iOS/MetalWindowContext.h +0 -39
- package/ios/RNSkia-iOS/MetalWindowContext.mm +0 -60
- package/ios/RNSkia-iOS/RNSkMetalCanvasProvider.h +0 -38
- package/ios/RNSkia-iOS/RNSkMetalCanvasProvider.mm +0 -103
- package/ios/RNSkia-iOS/RNSkiOSPlatformContext.h +0 -75
- package/ios/RNSkia-iOS/RNSkiOSPlatformContext.mm +0 -303
- package/ios/RNSkia-iOS/RNSkiOSVideo.h +0 -51
- package/ios/RNSkia-iOS/RNSkiOSVideo.mm +0 -137
- package/ios/RNSkia-iOS/RNSkiOSView.h +0 -37
- package/ios/RNSkia-iOS/RNSkiOSView.mm +0 -35
- package/ios/RNSkia-iOS/SkiaCVPixelBufferUtils.h +0 -119
- package/ios/RNSkia-iOS/SkiaCVPixelBufferUtils.mm +0 -344
- package/ios/RNSkia-iOS/SkiaManager.h +0 -25
- package/ios/RNSkia-iOS/SkiaManager.mm +0 -62
- package/ios/RNSkia-iOS/SkiaPictureView.h +0 -7
- package/ios/RNSkia-iOS/SkiaPictureView.mm +0 -66
- package/ios/RNSkia-iOS/SkiaPictureViewManager.h +0 -8
- package/ios/RNSkia-iOS/SkiaPictureViewManager.mm +0 -51
- package/ios/RNSkia-iOS/SkiaUIView.h +0 -37
- package/ios/RNSkia-iOS/SkiaUIView.mm +0 -168
- package/ios/RNSkia-iOS/ViewScreenshotService.h +0 -21
- package/ios/RNSkia-iOS/ViewScreenshotService.mm +0 -85
- package/ios/RNSkiaModule.h +0 -20
- package/ios/RNSkiaModule.mm +0 -55
- package/ios/Rnskia.xcodeproj/project.pbxproj +0 -281
- package/ios/Rnskia.xcworkspace/contents.xcworkspacedata +0 -7
@@ -1,119 +0,0 @@
|
|
1
|
-
//
|
2
|
-
// SkiaCVPixelBufferUtils.h
|
3
|
-
// react-native-skia
|
4
|
-
//
|
5
|
-
// Created by Marc Rousavy on 10.04.24.
|
6
|
-
//
|
7
|
-
|
8
|
-
#pragma once
|
9
|
-
|
10
|
-
#import <vector>
|
11
|
-
|
12
|
-
#import <CoreMedia/CMSampleBuffer.h>
|
13
|
-
#import <CoreVideo/CVMetalTextureCache.h>
|
14
|
-
#import <MetalKit/MetalKit.h>
|
15
|
-
|
16
|
-
#pragma clang diagnostic push
|
17
|
-
#pragma clang diagnostic ignored "-Wdocumentation"
|
18
|
-
#import "include/core/SkColorSpace.h"
|
19
|
-
#import "include/core/SkImage.h"
|
20
|
-
#import "include/gpu/ganesh/GrBackendSurface.h"
|
21
|
-
#import "include/gpu/ganesh/GrYUVABackendTextures.h"
|
22
|
-
#pragma clang diagnostic pop
|
23
|
-
|
24
|
-
/**
|
25
|
-
Holds a Metal Texture.
|
26
|
-
When the `TextureHolder` is destroyed, the underlying Metal Texture
|
27
|
-
is marked as invalid and might be overwritten by the Texture Cache,
|
28
|
-
so make sure to delete the `TextureHolder` only when the `SkImage`
|
29
|
-
has been deleted.
|
30
|
-
|
31
|
-
For example, use the `releaseProc` parameter in `BorrowImageFromTexture`
|
32
|
-
to delete the `TextureHolder`.
|
33
|
-
*/
|
34
|
-
class TextureHolder {
|
35
|
-
public:
|
36
|
-
/**
|
37
|
-
Create a new instance of TextureHolder which holds
|
38
|
-
the given `CVMetalTextureRef`.
|
39
|
-
|
40
|
-
The given `CVMetalTextureRef` is assumed to already be
|
41
|
-
retained with `CFRetain`, and will later be manually
|
42
|
-
released with `CFRelease`.
|
43
|
-
*/
|
44
|
-
TextureHolder(CVMetalTextureRef texture);
|
45
|
-
~TextureHolder();
|
46
|
-
|
47
|
-
/**
|
48
|
-
Converts this Texture to a Skia GrBackendTexture.
|
49
|
-
*/
|
50
|
-
GrBackendTexture toGrBackendTexture();
|
51
|
-
|
52
|
-
private:
|
53
|
-
CVMetalTextureRef _texture;
|
54
|
-
};
|
55
|
-
|
56
|
-
/**
|
57
|
-
Same as `TextureHolder`, but for multiple planar textures (e.g. YUVA)
|
58
|
-
*/
|
59
|
-
class MultiTexturesHolder {
|
60
|
-
public:
|
61
|
-
~MultiTexturesHolder();
|
62
|
-
void addTexture(TextureHolder *texture);
|
63
|
-
|
64
|
-
private:
|
65
|
-
std::vector<TextureHolder *> _textures;
|
66
|
-
};
|
67
|
-
|
68
|
-
class SkiaCVPixelBufferUtils {
|
69
|
-
public:
|
70
|
-
enum class CVPixelBufferBaseFormat { rgb, yuv };
|
71
|
-
|
72
|
-
/**
|
73
|
-
Get the base format (currently only RGB) of the PixelBuffer.
|
74
|
-
Depending on the base-format, different methods have to be used to create
|
75
|
-
Skia buffers.
|
76
|
-
*/
|
77
|
-
static CVPixelBufferBaseFormat
|
78
|
-
getCVPixelBufferBaseFormat(CVPixelBufferRef pixelBuffer);
|
79
|
-
|
80
|
-
class RGB {
|
81
|
-
public:
|
82
|
-
/**
|
83
|
-
Creates a GPU-backed Skia Texture (SkImage) with the given RGB
|
84
|
-
CVPixelBuffer.
|
85
|
-
*/
|
86
|
-
static sk_sp<SkImage>
|
87
|
-
makeSkImageFromCVPixelBuffer(GrDirectContext *context,
|
88
|
-
CVPixelBufferRef pixelBuffer);
|
89
|
-
|
90
|
-
private:
|
91
|
-
static SkColorType getCVPixelBufferColorType(CVPixelBufferRef pixelBuffer);
|
92
|
-
};
|
93
|
-
|
94
|
-
class YUV {
|
95
|
-
public:
|
96
|
-
/**
|
97
|
-
Creates a GPU-backed Skia Texture (SkImage) with the given YUV
|
98
|
-
CVPixelBuffer.
|
99
|
-
*/
|
100
|
-
static sk_sp<SkImage>
|
101
|
-
makeSkImageFromCVPixelBuffer(GrDirectContext *context,
|
102
|
-
CVPixelBufferRef pixelBuffer);
|
103
|
-
|
104
|
-
private:
|
105
|
-
static SkYUVAInfo::PlaneConfig getPlaneConfig(OSType pixelFormat);
|
106
|
-
static SkYUVAInfo::Subsampling getSubsampling(OSType pixelFormat);
|
107
|
-
static SkYUVColorSpace getColorspace(OSType pixelFormat);
|
108
|
-
static SkYUVAInfo getYUVAInfoForCVPixelBuffer(CVPixelBufferRef pixelBuffer);
|
109
|
-
};
|
110
|
-
|
111
|
-
private:
|
112
|
-
static CVMetalTextureCacheRef getTextureCache();
|
113
|
-
static TextureHolder *
|
114
|
-
getSkiaTextureForCVPixelBufferPlane(CVPixelBufferRef pixelBuffer,
|
115
|
-
size_t planeIndex);
|
116
|
-
static MTLPixelFormat
|
117
|
-
getMTLPixelFormatForCVPixelBufferPlane(CVPixelBufferRef pixelBuffer,
|
118
|
-
size_t planeIndex);
|
119
|
-
};
|
@@ -1,344 +0,0 @@
|
|
1
|
-
//
|
2
|
-
// SkiaCVPixelBufferUtils.mm
|
3
|
-
// react-native-skia
|
4
|
-
//
|
5
|
-
// Created by Marc Rousavy on 10.04.24.
|
6
|
-
//
|
7
|
-
|
8
|
-
#import "SkiaCVPixelBufferUtils.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
|
-
#include <TargetConditionals.h>
|
31
|
-
#if TARGET_RT_BIG_ENDIAN
|
32
|
-
#define FourCC2Str(fourcc) \
|
33
|
-
(const char[]) { \
|
34
|
-
*((char *)&fourcc), *(((char *)&fourcc) + 1), *(((char *)&fourcc) + 2), \
|
35
|
-
*(((char *)&fourcc) + 3), 0 \
|
36
|
-
}
|
37
|
-
#else
|
38
|
-
#define FourCC2Str(fourcc) \
|
39
|
-
(const char[]) { \
|
40
|
-
*(((char *)&fourcc) + 3), *(((char *)&fourcc) + 2), \
|
41
|
-
*(((char *)&fourcc) + 1), *(((char *)&fourcc) + 0), 0 \
|
42
|
-
}
|
43
|
-
#endif
|
44
|
-
|
45
|
-
// pragma MARK: TextureHolder
|
46
|
-
|
47
|
-
TextureHolder::TextureHolder(CVMetalTextureRef texture) : _texture(texture) {}
|
48
|
-
TextureHolder::~TextureHolder() {
|
49
|
-
// ARC will now automatically release _texture.
|
50
|
-
CFRelease(_texture);
|
51
|
-
}
|
52
|
-
|
53
|
-
GrBackendTexture TextureHolder::toGrBackendTexture() {
|
54
|
-
// Unwrap the underlying MTLTexture
|
55
|
-
id<MTLTexture> mtlTexture = CVMetalTextureGetTexture(_texture);
|
56
|
-
if (mtlTexture == nil) [[unlikely]] {
|
57
|
-
throw std::runtime_error(
|
58
|
-
"Failed to get MTLTexture from CVMetalTextureRef!");
|
59
|
-
}
|
60
|
-
|
61
|
-
// Wrap MTLTexture in Skia's GrBackendTexture
|
62
|
-
GrMtlTextureInfo textureInfo;
|
63
|
-
textureInfo.fTexture.retain((__bridge void *)mtlTexture);
|
64
|
-
GrBackendTexture texture =
|
65
|
-
GrBackendTextures::MakeMtl((int)mtlTexture.width, (int)mtlTexture.height,
|
66
|
-
skgpu::Mipmapped::kNo, textureInfo);
|
67
|
-
return texture;
|
68
|
-
}
|
69
|
-
|
70
|
-
MultiTexturesHolder::~MultiTexturesHolder() {
|
71
|
-
for (TextureHolder *texture : _textures) {
|
72
|
-
delete texture;
|
73
|
-
}
|
74
|
-
}
|
75
|
-
|
76
|
-
void MultiTexturesHolder::addTexture(TextureHolder *texture) {
|
77
|
-
_textures.push_back(texture);
|
78
|
-
}
|
79
|
-
|
80
|
-
// pragma MARK: Base
|
81
|
-
|
82
|
-
SkiaCVPixelBufferUtils::CVPixelBufferBaseFormat
|
83
|
-
SkiaCVPixelBufferUtils::getCVPixelBufferBaseFormat(
|
84
|
-
CVPixelBufferRef pixelBuffer) {
|
85
|
-
OSType format = CVPixelBufferGetPixelFormatType(pixelBuffer);
|
86
|
-
|
87
|
-
switch (format) {
|
88
|
-
// 8-bit YUV formats
|
89
|
-
case kCVPixelFormatType_420YpCbCr8Planar:
|
90
|
-
case kCVPixelFormatType_420YpCbCr8PlanarFullRange:
|
91
|
-
case kCVPixelFormatType_420YpCbCr8BiPlanarVideoRange:
|
92
|
-
case kCVPixelFormatType_420YpCbCr8BiPlanarFullRange:
|
93
|
-
// 10-bit YUV formats
|
94
|
-
case kCVPixelFormatType_420YpCbCr10BiPlanarVideoRange:
|
95
|
-
case kCVPixelFormatType_420YpCbCr10BiPlanarFullRange:
|
96
|
-
case kCVPixelFormatType_422YpCbCr10BiPlanarVideoRange:
|
97
|
-
case kCVPixelFormatType_422YpCbCr10BiPlanarFullRange:
|
98
|
-
case kCVPixelFormatType_444YpCbCr10BiPlanarVideoRange:
|
99
|
-
case kCVPixelFormatType_444YpCbCr10BiPlanarFullRange:
|
100
|
-
return CVPixelBufferBaseFormat::yuv;
|
101
|
-
case kCVPixelFormatType_24RGB:
|
102
|
-
case kCVPixelFormatType_24BGR:
|
103
|
-
case kCVPixelFormatType_32ARGB:
|
104
|
-
case kCVPixelFormatType_32BGRA:
|
105
|
-
case kCVPixelFormatType_32ABGR:
|
106
|
-
case kCVPixelFormatType_32RGBA:
|
107
|
-
return CVPixelBufferBaseFormat::rgb;
|
108
|
-
default:
|
109
|
-
[[unlikely]] throw std::runtime_error(
|
110
|
-
"CVPixelBuffer has unknown pixel format! " +
|
111
|
-
std::string("Expected: any RGB or YUV format, Received: ") +
|
112
|
-
std::string(FourCC2Str(format)));
|
113
|
-
}
|
114
|
-
}
|
115
|
-
|
116
|
-
// pragma MARK: RGB
|
117
|
-
|
118
|
-
SkColorType SkiaCVPixelBufferUtils::RGB::getCVPixelBufferColorType(
|
119
|
-
CVPixelBufferRef pixelBuffer) {
|
120
|
-
OSType format = CVPixelBufferGetPixelFormatType(pixelBuffer);
|
121
|
-
|
122
|
-
switch (format) {
|
123
|
-
case kCVPixelFormatType_32BGRA:
|
124
|
-
[[likely]] return kBGRA_8888_SkColorType;
|
125
|
-
case kCVPixelFormatType_32RGBA:
|
126
|
-
return kRGBA_8888_SkColorType;
|
127
|
-
// This can be extended with branches for specific RGB formats if Apple
|
128
|
-
// uses new formats.
|
129
|
-
default:
|
130
|
-
[[unlikely]] throw std::runtime_error(
|
131
|
-
"CVPixelBuffer has unknown RGB format! " +
|
132
|
-
std::string(FourCC2Str(format)));
|
133
|
-
}
|
134
|
-
}
|
135
|
-
|
136
|
-
sk_sp<SkImage> SkiaCVPixelBufferUtils::RGB::makeSkImageFromCVPixelBuffer(
|
137
|
-
GrDirectContext *context, CVPixelBufferRef pixelBuffer) {
|
138
|
-
// 1. Get Skia color type for RGB buffer
|
139
|
-
SkColorType colorType = getCVPixelBufferColorType(pixelBuffer);
|
140
|
-
|
141
|
-
// 2. Get texture, RGB buffers only have one plane
|
142
|
-
TextureHolder *texture =
|
143
|
-
getSkiaTextureForCVPixelBufferPlane(pixelBuffer, /* planeIndex */ 0);
|
144
|
-
|
145
|
-
// 3. Convert to image with manual memory cleanup
|
146
|
-
return SkImages::BorrowTextureFrom(
|
147
|
-
context, texture->toGrBackendTexture(), kTopLeft_GrSurfaceOrigin,
|
148
|
-
colorType, kOpaque_SkAlphaType, nullptr,
|
149
|
-
[](void *texture) { delete (TextureHolder *)texture; }, (void *)texture);
|
150
|
-
}
|
151
|
-
|
152
|
-
// pragma MARK: YUV
|
153
|
-
|
154
|
-
sk_sp<SkImage> SkiaCVPixelBufferUtils::YUV::makeSkImageFromCVPixelBuffer(
|
155
|
-
GrDirectContext *context, CVPixelBufferRef pixelBuffer) {
|
156
|
-
// 1. Get all planes (YUV, Y_UV, Y_U_V or Y_U_V_A)
|
157
|
-
size_t planesCount = CVPixelBufferGetPlaneCount(pixelBuffer);
|
158
|
-
MultiTexturesHolder *texturesHolder = new MultiTexturesHolder();
|
159
|
-
GrBackendTexture textures[planesCount];
|
160
|
-
|
161
|
-
for (size_t planeIndex = 0; planeIndex < planesCount; planeIndex++) {
|
162
|
-
TextureHolder *textureHolder =
|
163
|
-
getSkiaTextureForCVPixelBufferPlane(pixelBuffer, planeIndex);
|
164
|
-
textures[planeIndex] = textureHolder->toGrBackendTexture();
|
165
|
-
texturesHolder->addTexture(textureHolder);
|
166
|
-
}
|
167
|
-
|
168
|
-
// 2. Wrap info about buffer
|
169
|
-
SkYUVAInfo info = getYUVAInfoForCVPixelBuffer(pixelBuffer);
|
170
|
-
|
171
|
-
// 3. Wrap as YUVA textures type
|
172
|
-
GrYUVABackendTextures yuvaTextures(info, textures, kTopLeft_GrSurfaceOrigin);
|
173
|
-
|
174
|
-
// 4. Wrap into SkImage type with manualy memory cleanup
|
175
|
-
return SkImages::TextureFromYUVATextures(
|
176
|
-
context, yuvaTextures, nullptr,
|
177
|
-
[](void *textureHolders) {
|
178
|
-
delete (MultiTexturesHolder *)textureHolders;
|
179
|
-
},
|
180
|
-
(void *)texturesHolder);
|
181
|
-
}
|
182
|
-
|
183
|
-
SkYUVAInfo SkiaCVPixelBufferUtils::YUV::getYUVAInfoForCVPixelBuffer(
|
184
|
-
CVPixelBufferRef pixelBuffer) {
|
185
|
-
size_t width = CVPixelBufferGetWidth(pixelBuffer);
|
186
|
-
size_t height = CVPixelBufferGetHeight(pixelBuffer);
|
187
|
-
SkISize size =
|
188
|
-
SkISize::Make(static_cast<int>(width), static_cast<int>(height));
|
189
|
-
|
190
|
-
OSType format = CVPixelBufferGetPixelFormatType(pixelBuffer);
|
191
|
-
SkYUVAInfo::PlaneConfig planeConfig = getPlaneConfig(format);
|
192
|
-
SkYUVAInfo::Subsampling subsampling = getSubsampling(format);
|
193
|
-
SkYUVColorSpace colorspace = getColorspace(format);
|
194
|
-
|
195
|
-
return SkYUVAInfo(size, planeConfig, subsampling, colorspace);
|
196
|
-
}
|
197
|
-
|
198
|
-
// pragma MARK: YUV getPlaneConfig()
|
199
|
-
|
200
|
-
SkYUVAInfo::PlaneConfig
|
201
|
-
SkiaCVPixelBufferUtils::YUV::getPlaneConfig(OSType pixelFormat) {
|
202
|
-
switch (pixelFormat) {
|
203
|
-
case kCVPixelFormatType_420YpCbCr8Planar:
|
204
|
-
case kCVPixelFormatType_420YpCbCr8PlanarFullRange:
|
205
|
-
return SkYUVAInfo::PlaneConfig::kYUV;
|
206
|
-
case kCVPixelFormatType_420YpCbCr8BiPlanarVideoRange:
|
207
|
-
case kCVPixelFormatType_420YpCbCr8BiPlanarFullRange:
|
208
|
-
case kCVPixelFormatType_420YpCbCr10BiPlanarVideoRange:
|
209
|
-
case kCVPixelFormatType_420YpCbCr10BiPlanarFullRange:
|
210
|
-
case kCVPixelFormatType_422YpCbCr10BiPlanarVideoRange:
|
211
|
-
case kCVPixelFormatType_422YpCbCr10BiPlanarFullRange:
|
212
|
-
case kCVPixelFormatType_444YpCbCr10BiPlanarVideoRange:
|
213
|
-
case kCVPixelFormatType_444YpCbCr10BiPlanarFullRange:
|
214
|
-
[[likely]] return SkYUVAInfo::PlaneConfig::kY_UV;
|
215
|
-
|
216
|
-
// This can be extended with branches for specific YUV formats if Apple
|
217
|
-
// uses new formats.
|
218
|
-
default:
|
219
|
-
[[unlikely]] throw std::runtime_error("Invalid pixel format! " +
|
220
|
-
std::string(FourCC2Str(pixelFormat)));
|
221
|
-
}
|
222
|
-
}
|
223
|
-
|
224
|
-
// pragma MARK: YUV getSubsampling()
|
225
|
-
|
226
|
-
SkYUVAInfo::Subsampling
|
227
|
-
SkiaCVPixelBufferUtils::YUV::getSubsampling(OSType pixelFormat) {
|
228
|
-
switch (pixelFormat) {
|
229
|
-
case kCVPixelFormatType_420YpCbCr8Planar:
|
230
|
-
case kCVPixelFormatType_420YpCbCr8PlanarFullRange:
|
231
|
-
case kCVPixelFormatType_420YpCbCr8BiPlanarVideoRange:
|
232
|
-
case kCVPixelFormatType_420YpCbCr8BiPlanarFullRange:
|
233
|
-
case kCVPixelFormatType_420YpCbCr10BiPlanarVideoRange:
|
234
|
-
case kCVPixelFormatType_420YpCbCr10BiPlanarFullRange:
|
235
|
-
[[likely]] return SkYUVAInfo::Subsampling::k420;
|
236
|
-
case kCVPixelFormatType_422YpCbCr10BiPlanarVideoRange:
|
237
|
-
case kCVPixelFormatType_422YpCbCr10BiPlanarFullRange:
|
238
|
-
return SkYUVAInfo::Subsampling::k422;
|
239
|
-
case kCVPixelFormatType_444YpCbCr10BiPlanarVideoRange:
|
240
|
-
case kCVPixelFormatType_444YpCbCr10BiPlanarFullRange:
|
241
|
-
return SkYUVAInfo::Subsampling::k444;
|
242
|
-
// This can be extended with branches for specific YUV formats if Apple
|
243
|
-
// uses new formats.
|
244
|
-
default:
|
245
|
-
[[unlikely]] throw std::runtime_error("Invalid pixel format! " +
|
246
|
-
std::string(FourCC2Str(pixelFormat)));
|
247
|
-
}
|
248
|
-
}
|
249
|
-
|
250
|
-
// pragma MARK: YUV getColorspace()
|
251
|
-
|
252
|
-
SkYUVColorSpace SkiaCVPixelBufferUtils::YUV::getColorspace(OSType pixelFormat) {
|
253
|
-
switch (pixelFormat) {
|
254
|
-
case kCVPixelFormatType_420YpCbCr8BiPlanarVideoRange:
|
255
|
-
[[likely]]
|
256
|
-
// 8-bit limited
|
257
|
-
return SkYUVColorSpace::kRec709_Limited_SkYUVColorSpace;
|
258
|
-
case kCVPixelFormatType_420YpCbCr8Planar:
|
259
|
-
case kCVPixelFormatType_420YpCbCr8PlanarFullRange:
|
260
|
-
case kCVPixelFormatType_420YpCbCr8BiPlanarFullRange:
|
261
|
-
[[likely]]
|
262
|
-
// 8-bit full
|
263
|
-
return SkYUVColorSpace::kRec709_Full_SkYUVColorSpace;
|
264
|
-
case kCVPixelFormatType_420YpCbCr10BiPlanarVideoRange:
|
265
|
-
case kCVPixelFormatType_422YpCbCr10BiPlanarVideoRange:
|
266
|
-
case kCVPixelFormatType_444YpCbCr10BiPlanarVideoRange:
|
267
|
-
// 10-bit limited
|
268
|
-
return SkYUVColorSpace::kBT2020_10bit_Limited_SkYUVColorSpace;
|
269
|
-
case kCVPixelFormatType_420YpCbCr10BiPlanarFullRange:
|
270
|
-
case kCVPixelFormatType_422YpCbCr10BiPlanarFullRange:
|
271
|
-
case kCVPixelFormatType_444YpCbCr10BiPlanarFullRange:
|
272
|
-
// 10-bit full
|
273
|
-
return SkYUVColorSpace::kBT2020_10bit_Full_SkYUVColorSpace;
|
274
|
-
// This can be extended with branches for specific YUV formats if Apple
|
275
|
-
// uses new formats.
|
276
|
-
default:
|
277
|
-
[[unlikely]] throw std::runtime_error("Invalid pixel format! " +
|
278
|
-
std::string(FourCC2Str(pixelFormat)));
|
279
|
-
}
|
280
|
-
}
|
281
|
-
|
282
|
-
// pragma MARK: CVPixelBuffer -> Skia Texture
|
283
|
-
|
284
|
-
TextureHolder *SkiaCVPixelBufferUtils::getSkiaTextureForCVPixelBufferPlane(
|
285
|
-
CVPixelBufferRef pixelBuffer, size_t planeIndex) {
|
286
|
-
// 1. Get cache
|
287
|
-
CVMetalTextureCacheRef textureCache = getTextureCache();
|
288
|
-
|
289
|
-
// 2. Get MetalTexture from CMSampleBuffer
|
290
|
-
size_t width = CVPixelBufferGetWidthOfPlane(pixelBuffer, planeIndex);
|
291
|
-
size_t height = CVPixelBufferGetHeightOfPlane(pixelBuffer, planeIndex);
|
292
|
-
MTLPixelFormat pixelFormat =
|
293
|
-
getMTLPixelFormatForCVPixelBufferPlane(pixelBuffer, planeIndex);
|
294
|
-
|
295
|
-
CVMetalTextureRef textureHolder;
|
296
|
-
CVReturn result = CVMetalTextureCacheCreateTextureFromImage(
|
297
|
-
kCFAllocatorDefault, textureCache, pixelBuffer, nil, pixelFormat, width,
|
298
|
-
height, planeIndex, &textureHolder);
|
299
|
-
|
300
|
-
if (result != kCVReturnSuccess) [[unlikely]] {
|
301
|
-
throw std::runtime_error(
|
302
|
-
"Failed to create Metal Texture from CMSampleBuffer! Result: " +
|
303
|
-
std::to_string(result));
|
304
|
-
}
|
305
|
-
|
306
|
-
return new TextureHolder(textureHolder);
|
307
|
-
}
|
308
|
-
|
309
|
-
// pragma MARK: getTextureCache()
|
310
|
-
|
311
|
-
CVMetalTextureCacheRef SkiaCVPixelBufferUtils::getTextureCache() {
|
312
|
-
static CVMetalTextureCacheRef textureCache = nil;
|
313
|
-
if (textureCache == nil) {
|
314
|
-
// Create a new Texture Cache
|
315
|
-
auto result = CVMetalTextureCacheCreate(kCFAllocatorDefault, nil,
|
316
|
-
MTLCreateSystemDefaultDevice(), nil,
|
317
|
-
&textureCache);
|
318
|
-
if (result != kCVReturnSuccess || textureCache == nil) {
|
319
|
-
throw std::runtime_error("Failed to create Metal Texture Cache!");
|
320
|
-
}
|
321
|
-
}
|
322
|
-
return textureCache;
|
323
|
-
}
|
324
|
-
|
325
|
-
// pragma MARK: Get CVPixelBuffer MTLPixelFormat
|
326
|
-
|
327
|
-
MTLPixelFormat SkiaCVPixelBufferUtils::getMTLPixelFormatForCVPixelBufferPlane(
|
328
|
-
CVPixelBufferRef pixelBuffer, size_t planeIndex) {
|
329
|
-
size_t width = CVPixelBufferGetWidthOfPlane(pixelBuffer, planeIndex);
|
330
|
-
size_t bytesPerRow =
|
331
|
-
CVPixelBufferGetBytesPerRowOfPlane(pixelBuffer, planeIndex);
|
332
|
-
double bytesPerPixel = round(static_cast<double>(bytesPerRow) / width);
|
333
|
-
if (bytesPerPixel == 1) {
|
334
|
-
return MTLPixelFormatR8Unorm;
|
335
|
-
} else if (bytesPerPixel == 2) {
|
336
|
-
return MTLPixelFormatRG8Unorm;
|
337
|
-
} else if (bytesPerPixel == 4) {
|
338
|
-
return MTLPixelFormatBGRA8Unorm;
|
339
|
-
} else [[unlikely]] {
|
340
|
-
throw std::runtime_error("Invalid bytes per row! Expected 1 (R), 2 (RG) or "
|
341
|
-
"4 (RGBA), but received " +
|
342
|
-
std::to_string(bytesPerPixel));
|
343
|
-
}
|
344
|
-
}
|
@@ -1,25 +0,0 @@
|
|
1
|
-
#pragma once
|
2
|
-
|
3
|
-
#import <React/RCTBridge.h>
|
4
|
-
|
5
|
-
#import "RNSkManager.h"
|
6
|
-
|
7
|
-
@interface SkiaManager : NSObject
|
8
|
-
|
9
|
-
- (std::shared_ptr<RNSkia::RNSkManager>)skManager;
|
10
|
-
|
11
|
-
- (instancetype)init NS_UNAVAILABLE;
|
12
|
-
|
13
|
-
- (void)invalidate;
|
14
|
-
|
15
|
-
- (instancetype)initWithBridge:(RCTBridge *)bridge
|
16
|
-
jsInvoker:(std::shared_ptr<facebook::react::CallInvoker>)
|
17
|
-
jsInvoker;
|
18
|
-
|
19
|
-
#ifdef RCT_NEW_ARCH_ENABLED
|
20
|
-
// Fabric components do not have a better way to interact with TurboModules.
|
21
|
-
// Workaround to get the SkManager instance from singleton.
|
22
|
-
+ (std::shared_ptr<RNSkia::RNSkManager>)latestActiveSkManager;
|
23
|
-
#endif // RCT_NEW_ARCH_ENABLED
|
24
|
-
|
25
|
-
@end
|
@@ -1,62 +0,0 @@
|
|
1
|
-
#import "SkiaManager.h"
|
2
|
-
|
3
|
-
#import <Foundation/Foundation.h>
|
4
|
-
|
5
|
-
#import <React/RCTBridge+Private.h>
|
6
|
-
#import <React/RCTBridge.h>
|
7
|
-
#import <React/RCTUIManager.h>
|
8
|
-
|
9
|
-
#import "RNSkiOSPlatformContext.h"
|
10
|
-
|
11
|
-
static __weak SkiaManager *sharedInstance = nil;
|
12
|
-
|
13
|
-
@implementation SkiaManager {
|
14
|
-
std::shared_ptr<RNSkia::RNSkManager> _skManager;
|
15
|
-
__weak RCTBridge *weakBridge;
|
16
|
-
}
|
17
|
-
|
18
|
-
- (std::shared_ptr<RNSkia::RNSkManager>)skManager {
|
19
|
-
return _skManager;
|
20
|
-
}
|
21
|
-
|
22
|
-
- (void)invalidate {
|
23
|
-
if (_skManager != nullptr) {
|
24
|
-
_skManager->invalidate();
|
25
|
-
}
|
26
|
-
_skManager = nullptr;
|
27
|
-
}
|
28
|
-
|
29
|
-
- (instancetype)initWithBridge:(RCTBridge *)bridge
|
30
|
-
jsInvoker:(std::shared_ptr<facebook::react::CallInvoker>)
|
31
|
-
jsInvoker {
|
32
|
-
self = [super init];
|
33
|
-
if (self) {
|
34
|
-
sharedInstance = self;
|
35
|
-
RCTCxxBridge *cxxBridge = (RCTCxxBridge *)bridge;
|
36
|
-
if (cxxBridge.runtime) {
|
37
|
-
|
38
|
-
facebook::jsi::Runtime *jsRuntime =
|
39
|
-
(facebook::jsi::Runtime *)cxxBridge.runtime;
|
40
|
-
|
41
|
-
// Create the RNSkiaManager (cross platform)
|
42
|
-
_skManager = std::make_shared<RNSkia::RNSkManager>(
|
43
|
-
jsRuntime, jsInvoker,
|
44
|
-
std::make_shared<RNSkia::RNSkiOSPlatformContext>(bridge, jsInvoker));
|
45
|
-
}
|
46
|
-
}
|
47
|
-
return self;
|
48
|
-
}
|
49
|
-
|
50
|
-
- (void)dealloc {
|
51
|
-
sharedInstance = nil;
|
52
|
-
}
|
53
|
-
|
54
|
-
#ifdef RCT_NEW_ARCH_ENABLED
|
55
|
-
+ (std::shared_ptr<RNSkia::RNSkManager>)latestActiveSkManager {
|
56
|
-
if (sharedInstance != nil) {
|
57
|
-
return [sharedInstance skManager];
|
58
|
-
}
|
59
|
-
return nullptr;
|
60
|
-
}
|
61
|
-
#endif // RCT_NEW_ARCH_ENABLED
|
62
|
-
@end
|
@@ -1,66 +0,0 @@
|
|
1
|
-
#ifdef RCT_NEW_ARCH_ENABLED
|
2
|
-
#import "SkiaPictureView.h"
|
3
|
-
|
4
|
-
#import "RNSkIOSView.h"
|
5
|
-
#import "RNSkPictureView.h"
|
6
|
-
#import "RNSkPlatformContext.h"
|
7
|
-
|
8
|
-
#import "RNSkiaModule.h"
|
9
|
-
#import "SkiaManager.h"
|
10
|
-
#import "SkiaUIView.h"
|
11
|
-
|
12
|
-
#import <React/RCTBridge+Private.h>
|
13
|
-
#import <React/RCTConversions.h>
|
14
|
-
#import <React/RCTFabricComponentsPlugins.h>
|
15
|
-
|
16
|
-
#import <react/renderer/components/rnskia/ComponentDescriptors.h>
|
17
|
-
#import <react/renderer/components/rnskia/EventEmitters.h>
|
18
|
-
#import <react/renderer/components/rnskia/Props.h>
|
19
|
-
#import <react/renderer/components/rnskia/RCTComponentViewHelpers.h>
|
20
|
-
|
21
|
-
using namespace facebook::react;
|
22
|
-
|
23
|
-
@implementation SkiaPictureView
|
24
|
-
|
25
|
-
- (instancetype)initWithFrame:(CGRect)frame {
|
26
|
-
if (self = [super initWithFrame:frame]) {
|
27
|
-
// Pass SkManager as a raw pointer to avoid circular dependencies
|
28
|
-
auto skManager = [SkiaManager latestActiveSkManager].get();
|
29
|
-
[self initCommon:skManager
|
30
|
-
factory:[](std::shared_ptr<RNSkia::RNSkPlatformContext> context) {
|
31
|
-
return std::make_shared<RNSkiOSView<RNSkia::RNSkPictureView>>(
|
32
|
-
context);
|
33
|
-
}];
|
34
|
-
static const auto defaultProps =
|
35
|
-
std::make_shared<const SkiaPictureViewProps>();
|
36
|
-
_props = defaultProps;
|
37
|
-
}
|
38
|
-
return self;
|
39
|
-
}
|
40
|
-
|
41
|
-
#pragma mark - RCTComponentViewProtocol
|
42
|
-
|
43
|
-
+ (ComponentDescriptorProvider)componentDescriptorProvider {
|
44
|
-
return concreteComponentDescriptorProvider<
|
45
|
-
SkiaPictureViewComponentDescriptor>();
|
46
|
-
}
|
47
|
-
|
48
|
-
- (void)updateProps:(const Props::Shared &)props
|
49
|
-
oldProps:(const Props::Shared &)oldProps {
|
50
|
-
const auto &newProps =
|
51
|
-
*std::static_pointer_cast<const SkiaPictureViewProps>(props);
|
52
|
-
[super updateProps:props oldProps:oldProps];
|
53
|
-
int nativeId =
|
54
|
-
[[RCTConvert NSString:RCTNSStringFromString(newProps.nativeId)] intValue];
|
55
|
-
[self setNativeId:nativeId];
|
56
|
-
[self setDebugMode:newProps.debug];
|
57
|
-
[self setOpaque:newProps.opaque];
|
58
|
-
}
|
59
|
-
|
60
|
-
@end
|
61
|
-
|
62
|
-
Class<RCTComponentViewProtocol> SkiaPictureViewCls(void) {
|
63
|
-
return SkiaPictureView.class;
|
64
|
-
}
|
65
|
-
|
66
|
-
#endif // RCT_NEW_ARCH_ENABLED
|
@@ -1,51 +0,0 @@
|
|
1
|
-
|
2
|
-
#include "SkiaPictureViewManager.h"
|
3
|
-
#include <React/RCTBridge+Private.h>
|
4
|
-
|
5
|
-
#include "RNSkIOSView.h"
|
6
|
-
#include "RNSkPictureView.h"
|
7
|
-
#include "RNSkPlatformContext.h"
|
8
|
-
|
9
|
-
#include "RNSkiaModule.h"
|
10
|
-
#include "SkiaManager.h"
|
11
|
-
#include "SkiaUIView.h"
|
12
|
-
|
13
|
-
@implementation SkiaPictureViewManager
|
14
|
-
|
15
|
-
RCT_EXPORT_MODULE(SkiaPictureView)
|
16
|
-
|
17
|
-
- (SkiaManager *)skiaManager {
|
18
|
-
auto bridge = self.bridge;
|
19
|
-
RCTAssert(bridge, @"Bridge must not be nil.");
|
20
|
-
auto skiaModule = (RNSkiaModule *)[bridge moduleForName:@"RNSkiaModule"];
|
21
|
-
return [skiaModule manager];
|
22
|
-
}
|
23
|
-
|
24
|
-
RCT_CUSTOM_VIEW_PROPERTY(nativeID, NSNumber, SkiaUIView) {
|
25
|
-
// Get parameter
|
26
|
-
int nativeId = [[RCTConvert NSString:json] intValue];
|
27
|
-
[(SkiaUIView *)view setNativeId:nativeId];
|
28
|
-
}
|
29
|
-
|
30
|
-
RCT_CUSTOM_VIEW_PROPERTY(debug, BOOL, SkiaUIView) {
|
31
|
-
bool debug = json != NULL ? [RCTConvert BOOL:json] : false;
|
32
|
-
[(SkiaUIView *)view setDebugMode:debug];
|
33
|
-
}
|
34
|
-
|
35
|
-
RCT_CUSTOM_VIEW_PROPERTY(opaque, BOOL, SkiaUIView) {
|
36
|
-
bool opaque = json != NULL ? [RCTConvert BOOL:json] : false;
|
37
|
-
[(SkiaUIView *)view setOpaque:opaque];
|
38
|
-
}
|
39
|
-
|
40
|
-
- (UIView *)view {
|
41
|
-
auto skManager = [[self skiaManager] skManager];
|
42
|
-
// Pass SkManager as a raw pointer to avoid circular dependenciesr
|
43
|
-
return [[SkiaUIView alloc]
|
44
|
-
initWithManager:skManager.get()
|
45
|
-
factory:[](std::shared_ptr<RNSkia::RNSkPlatformContext> context) {
|
46
|
-
return std::make_shared<RNSkiOSView<RNSkia::RNSkPictureView>>(
|
47
|
-
context);
|
48
|
-
}];
|
49
|
-
}
|
50
|
-
|
51
|
-
@end
|