react-native-skia 3.0.0 → 3.0.2
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/Package.swift +14 -13
- package/android/CMakeLists.txt +13 -42
- package/android/build.gradle +55 -47
- package/android/cpp/jni/JniLoad.cpp +2 -4
- package/android/cpp/jni/include/JniSkiaView.h +123 -0
- package/android/cpp/rnskia-android/{RNSkOpenGLCanvasProvider.cpp → RNSkAndroidCanvasProvider.cpp} +45 -100
- package/android/cpp/rnskia-android/{RNSkOpenGLCanvasProvider.h → RNSkAndroidCanvasProvider.h} +24 -22
- package/android/cpp/rnskia-android/RNSkAndroidPlatformContext.h +0 -83
- package/android/cpp/rnskia-android/RNSkAndroidVideo.cpp +0 -8
- package/android/src/main/java/com/reactnative/skia/RNSkiaPackage.java +1 -2
- package/android/src/main/java/com/reactnative/skia/SkiaSurfaceView.java +1 -3
- package/android/src/main/java/com/reactnative/skia/SkiaTextureView.java +1 -17
- package/android/src/main/java/com/reactnative/skia/{SkiaBaseView.java → SkiaView.java} +78 -16
- package/android/src/main/java/com/reactnative/skia/SkiaViewManager.java +85 -0
- package/apple/MetalLayerColorSpace.mm +0 -4
- package/apple/RNSkApplePlatformContext.h +0 -14
- package/apple/RNSkApplePlatformContext.mm +2 -112
- package/apple/RNSkMetalCanvasProvider.h +14 -19
- package/apple/RNSkMetalCanvasProvider.mm +35 -68
- package/apple/SkiaView.h +20 -0
- package/apple/SkiaView.mm +210 -0
- package/cpp/api/JsiSkApi.h +2 -13
- package/cpp/api/JsiSkCanvas.h +4 -18
- package/cpp/api/JsiSkGraphiteContext.h +1 -5
- package/cpp/api/JsiSkGraphiteRecording.h +1 -5
- package/cpp/api/JsiSkImage.h +7 -41
- package/cpp/api/JsiSkImageFactory.h +0 -14
- package/cpp/api/JsiSkSurface.h +2 -16
- package/cpp/api/JsiSkSurfaceFactory.h +0 -8
- package/cpp/rnskia/RNDawnContext.h +6 -0
- package/cpp/rnskia/RNDawnInterop.cpp +0 -4
- package/cpp/rnskia/RNDawnUtils.h +0 -1
- package/cpp/rnskia/RNDawnWindowContext.cpp +10 -0
- package/cpp/rnskia/RNDawnWindowContext.h +4 -0
- package/cpp/rnskia/RNSkCanvasProvider.h +221 -0
- package/cpp/rnskia/RNSkGraphiteProducer.cpp +36 -14
- package/cpp/rnskia/RNSkGraphiteProducer.h +23 -8
- package/cpp/rnskia/RNSkGraphiteTarget.h +383 -0
- package/cpp/rnskia/RNSkJsiViewApi.h +9 -18
- package/cpp/rnskia/RNSkPlatformContext.h +9 -15
- package/cpp/rnskia/RNSkView.h +340 -245
- package/jestSetup.js +1 -3
- package/lib/commonjs/Platform/Platform.web.js +1 -1
- package/lib/commonjs/Platform/Platform.web.js.map +1 -1
- package/lib/commonjs/index.d.ts +1 -3
- package/lib/commonjs/index.js +3 -12
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/mock/index.js +0 -1
- package/lib/commonjs/mock/index.js.map +1 -1
- package/lib/commonjs/renderer/Canvas.d.ts +15 -12
- package/lib/commonjs/renderer/Canvas.js +24 -20
- package/lib/commonjs/renderer/Canvas.js.map +1 -1
- package/lib/commonjs/skia/types/Graphite.d.ts +3 -3
- package/lib/commonjs/skia/types/Graphite.js.map +1 -1
- package/lib/commonjs/skia/types/Image/ImageFactory.d.ts +2 -2
- package/lib/commonjs/skia/types/Image/ImageFactory.js.map +1 -1
- package/lib/commonjs/skia/types/Skia.d.ts +1 -2
- package/lib/commonjs/skia/types/Skia.js.map +1 -1
- package/lib/commonjs/skia/types/Surface/SurfaceFactory.d.ts +1 -1
- package/lib/commonjs/skia/types/Surface/SurfaceFactory.js.map +1 -1
- package/lib/commonjs/specs/NativeSkiaModule.web.d.ts +5 -4
- package/lib/commonjs/specs/NativeSkiaModule.web.js +5 -9
- package/lib/commonjs/specs/NativeSkiaModule.web.js.map +1 -1
- package/lib/{typescript/src/specs/SkiaPictureViewNativeComponent.d.ts → commonjs/specs/SkiaViewNativeComponent.d.ts} +0 -3
- package/lib/commonjs/specs/{SkiaPictureViewNativeComponent.js → SkiaViewNativeComponent.js} +2 -2
- package/lib/commonjs/specs/SkiaViewNativeComponent.js.map +1 -0
- package/lib/commonjs/specs/SkiaViewNativeComponent.web.d.ts +10 -0
- package/lib/commonjs/specs/SkiaViewNativeComponent.web.js +27 -0
- package/lib/commonjs/specs/SkiaViewNativeComponent.web.js.map +1 -0
- package/lib/commonjs/views/SkiaGraphiteView.d.ts +3 -4
- package/lib/commonjs/views/SkiaGraphiteView.js +23 -12
- package/lib/commonjs/views/SkiaGraphiteView.js.map +1 -1
- package/lib/commonjs/views/SkiaPictureView.d.ts +4 -1
- package/lib/commonjs/views/SkiaPictureView.js +12 -10
- package/lib/commonjs/views/SkiaPictureView.js.map +1 -1
- package/lib/commonjs/views/SkiaView.web.d.ts +12 -0
- package/lib/commonjs/views/{SkiaGraphiteView.web.js → SkiaView.web.js} +82 -38
- package/lib/commonjs/views/SkiaView.web.js.map +1 -0
- package/lib/commonjs/views/SkiaWebRenderer.js +1 -1
- package/lib/commonjs/views/SkiaWebRenderer.js.map +1 -1
- package/lib/commonjs/views/android.d.ts +6 -0
- package/lib/commonjs/views/android.js +17 -0
- package/lib/commonjs/views/android.js.map +1 -0
- package/lib/commonjs/views/types.d.ts +3 -12
- package/lib/commonjs/views/types.js.map +1 -1
- package/lib/module/Platform/Platform.web.js +1 -1
- package/lib/module/Platform/Platform.web.js.map +1 -1
- package/lib/module/index.d.ts +1 -3
- package/lib/module/index.js +1 -3
- package/lib/module/index.js.map +1 -1
- package/lib/module/mock/index.js +0 -1
- package/lib/module/mock/index.js.map +1 -1
- package/lib/module/renderer/Canvas.d.ts +15 -12
- package/lib/module/renderer/Canvas.js +24 -19
- package/lib/module/renderer/Canvas.js.map +1 -1
- package/lib/module/skia/types/Graphite.d.ts +3 -3
- package/lib/module/skia/types/Graphite.js.map +1 -1
- package/lib/module/skia/types/Image/ImageFactory.d.ts +2 -2
- package/lib/module/skia/types/Image/ImageFactory.js.map +1 -1
- package/lib/module/skia/types/Skia.d.ts +1 -2
- package/lib/module/skia/types/Skia.js.map +1 -1
- package/lib/module/skia/types/Surface/SurfaceFactory.d.ts +1 -1
- package/lib/module/skia/types/Surface/SurfaceFactory.js.map +1 -1
- package/lib/module/specs/NativeSkiaModule.web.d.ts +5 -4
- package/lib/module/specs/NativeSkiaModule.web.js +5 -9
- package/lib/module/specs/NativeSkiaModule.web.js.map +1 -1
- package/lib/{commonjs/specs/SkiaPictureViewNativeComponent.d.ts → module/specs/SkiaViewNativeComponent.d.ts} +0 -3
- package/lib/module/specs/{SkiaPictureViewNativeComponent.js → SkiaViewNativeComponent.js} +2 -2
- package/lib/module/specs/SkiaViewNativeComponent.js.map +1 -0
- package/lib/module/specs/SkiaViewNativeComponent.web.d.ts +10 -0
- package/lib/module/specs/SkiaViewNativeComponent.web.js +21 -0
- package/lib/module/specs/SkiaViewNativeComponent.web.js.map +1 -0
- package/lib/module/views/SkiaGraphiteView.d.ts +3 -4
- package/lib/module/views/SkiaGraphiteView.js +23 -12
- package/lib/module/views/SkiaGraphiteView.js.map +1 -1
- package/lib/module/views/SkiaPictureView.d.ts +4 -1
- package/lib/module/views/SkiaPictureView.js +12 -10
- package/lib/module/views/SkiaPictureView.js.map +1 -1
- package/lib/module/views/SkiaView.web.d.ts +12 -0
- package/lib/module/views/{SkiaGraphiteView.web.js → SkiaView.web.js} +80 -36
- package/lib/module/views/SkiaView.web.js.map +1 -0
- package/lib/module/views/SkiaWebRenderer.js +1 -1
- package/lib/module/views/SkiaWebRenderer.js.map +1 -1
- package/lib/module/views/android.d.ts +6 -0
- package/lib/module/views/android.js +10 -0
- package/lib/module/views/android.js.map +1 -0
- package/lib/module/views/types.d.ts +3 -12
- package/lib/module/views/types.js.map +1 -1
- package/lib/typescript/src/index.d.ts +1 -3
- package/lib/typescript/src/renderer/Canvas.d.ts +15 -12
- package/lib/typescript/src/skia/types/Graphite.d.ts +3 -3
- package/lib/typescript/src/skia/types/Image/ImageFactory.d.ts +2 -2
- package/lib/typescript/src/skia/types/Skia.d.ts +1 -2
- package/lib/typescript/src/skia/types/Surface/SurfaceFactory.d.ts +1 -1
- package/lib/typescript/src/specs/NativeSkiaModule.web.d.ts +5 -4
- package/lib/{module/specs/SkiaPictureViewNativeComponent.d.ts → typescript/src/specs/SkiaViewNativeComponent.d.ts} +0 -3
- package/lib/typescript/src/specs/SkiaViewNativeComponent.web.d.ts +10 -0
- package/lib/typescript/src/views/SkiaGraphiteView.d.ts +3 -4
- package/lib/typescript/src/views/SkiaPictureView.d.ts +4 -1
- package/lib/typescript/src/views/SkiaView.web.d.ts +12 -0
- package/lib/typescript/src/views/android.d.ts +6 -0
- package/lib/typescript/src/views/types.d.ts +3 -12
- package/package.json +8 -16
- package/react-native-skia.podspec +50 -57
- package/src/Platform/Platform.web.tsx +1 -1
- package/src/index.ts +1 -3
- package/src/mock/index.ts +0 -1
- package/src/renderer/Canvas.tsx +23 -27
- package/src/skia/types/Graphite.ts +3 -3
- package/src/skia/types/Image/ImageFactory.ts +2 -2
- package/src/skia/types/Skia.ts +1 -2
- package/src/skia/types/Surface/SurfaceFactory.ts +1 -1
- package/src/specs/NativeSkiaModule.web.ts +9 -21
- package/src/specs/{SkiaPictureViewNativeComponent.ts → SkiaViewNativeComponent.ts} +1 -4
- package/src/specs/{SkiaPictureViewNativeComponent.web.ts → SkiaViewNativeComponent.web.ts} +8 -10
- package/src/views/SkiaGraphiteView.tsx +27 -16
- package/src/views/SkiaPictureView.tsx +11 -10
- package/src/views/{SkiaGraphiteView.web.tsx → SkiaView.web.tsx} +100 -53
- package/src/views/SkiaWebRenderer.ts +1 -1
- package/src/views/android.ts +16 -0
- package/src/views/types.ts +3 -14
- package/android/cpp/jni/include/JniSkiaBaseView.h +0 -92
- package/android/cpp/jni/include/JniSkiaGraphiteView.h +0 -176
- package/android/cpp/jni/include/JniSkiaPictureView.h +0 -172
- package/android/cpp/rnskia-android/GrAHardwareBufferUtils.cpp +0 -245
- package/android/cpp/rnskia-android/GrAHardwareBufferUtils.h +0 -33
- package/android/cpp/rnskia-android/OpenGLContext.h +0 -248
- package/android/cpp/rnskia-android/OpenGLWindowContext.cpp +0 -67
- package/android/cpp/rnskia-android/OpenGLWindowContext.h +0 -75
- package/android/cpp/rnskia-android/RNSkAndroidView.h +0 -67
- package/android/cpp/rnskia-android/gl/Context.h +0 -80
- package/android/cpp/rnskia-android/gl/Display.h +0 -123
- package/android/cpp/rnskia-android/gl/Error.cpp +0 -45
- package/android/cpp/rnskia-android/gl/Error.h +0 -8
- package/android/cpp/rnskia-android/gl/Surface.h +0 -43
- package/android/src/main/java/com/reactnative/skia/SkiaBaseViewManager.java +0 -65
- package/android/src/main/java/com/reactnative/skia/SkiaGraphiteView.java +0 -78
- package/android/src/main/java/com/reactnative/skia/SkiaGraphiteViewManager.java +0 -32
- package/android/src/main/java/com/reactnative/skia/SkiaPictureView.java +0 -105
- package/android/src/main/java/com/reactnative/skia/SkiaPictureViewManager.java +0 -44
- package/apple/MetalContext.h +0 -116
- package/apple/MetalContext.mm +0 -38
- package/apple/MetalWindowContext.h +0 -42
- package/apple/MetalWindowContext.mm +0 -95
- package/apple/RNSkAppleView.h +0 -49
- package/apple/RNSkAppleView.mm +0 -35
- package/apple/SkiaCVPixelBufferUtils.h +0 -122
- package/apple/SkiaCVPixelBufferUtils.mm +0 -535
- package/apple/SkiaGraphiteView.h +0 -26
- package/apple/SkiaGraphiteView.mm +0 -180
- package/apple/SkiaPictureView.h +0 -7
- package/apple/SkiaPictureView.mm +0 -70
- package/apple/SkiaUIView.h +0 -31
- package/apple/SkiaUIView.mm +0 -164
- package/cpp/rnskia/RNSkGraphiteView.h +0 -708
- package/cpp/rnskia/RNSkPictureView.cpp +0 -69
- package/cpp/rnskia/RNSkPictureView.h +0 -211
- package/cpp/skia/src/gpu/ganesh/gl/GrGLDefines.h +0 -1162
- package/lib/commonjs/renderer/DefaultCanvas.d.ts +0 -8
- package/lib/commonjs/renderer/DefaultCanvas.js +0 -42
- package/lib/commonjs/renderer/DefaultCanvas.js.map +0 -1
- package/lib/commonjs/renderer/GraphiteCanvas.d.ts +0 -22
- package/lib/commonjs/renderer/GraphiteCanvas.js +0 -64
- package/lib/commonjs/renderer/GraphiteCanvas.js.map +0 -1
- package/lib/commonjs/renderer/GraphiteCanvas.web.d.ts +0 -1
- package/lib/commonjs/renderer/GraphiteCanvas.web.js +0 -13
- package/lib/commonjs/renderer/GraphiteCanvas.web.js.map +0 -1
- package/lib/commonjs/specs/SkiaGraphiteViewNativeComponent.d.ts +0 -10
- package/lib/commonjs/specs/SkiaGraphiteViewNativeComponent.js +0 -12
- package/lib/commonjs/specs/SkiaGraphiteViewNativeComponent.js.map +0 -1
- package/lib/commonjs/specs/SkiaGraphiteViewNativeComponent.web.d.ts +0 -9
- package/lib/commonjs/specs/SkiaGraphiteViewNativeComponent.web.js +0 -28
- package/lib/commonjs/specs/SkiaGraphiteViewNativeComponent.web.js.map +0 -1
- package/lib/commonjs/specs/SkiaPictureViewNativeComponent.js.map +0 -1
- package/lib/commonjs/specs/SkiaPictureViewNativeComponent.web.d.ts +0 -10
- package/lib/commonjs/specs/SkiaPictureViewNativeComponent.web.js +0 -29
- package/lib/commonjs/specs/SkiaPictureViewNativeComponent.web.js.map +0 -1
- package/lib/commonjs/views/SkiaGraphiteView.web.d.ts +0 -14
- package/lib/commonjs/views/SkiaGraphiteView.web.js.map +0 -1
- package/lib/commonjs/views/SkiaPictureView.web.d.ts +0 -11
- package/lib/commonjs/views/SkiaPictureView.web.js +0 -165
- package/lib/commonjs/views/SkiaPictureView.web.js.map +0 -1
- package/lib/module/renderer/DefaultCanvas.d.ts +0 -8
- package/lib/module/renderer/DefaultCanvas.js +0 -34
- package/lib/module/renderer/DefaultCanvas.js.map +0 -1
- package/lib/module/renderer/GraphiteCanvas.d.ts +0 -22
- package/lib/module/renderer/GraphiteCanvas.js +0 -57
- package/lib/module/renderer/GraphiteCanvas.js.map +0 -1
- package/lib/module/renderer/GraphiteCanvas.web.d.ts +0 -1
- package/lib/module/renderer/GraphiteCanvas.web.js +0 -4
- package/lib/module/renderer/GraphiteCanvas.web.js.map +0 -1
- package/lib/module/specs/SkiaGraphiteViewNativeComponent.d.ts +0 -10
- package/lib/module/specs/SkiaGraphiteViewNativeComponent.js +0 -8
- package/lib/module/specs/SkiaGraphiteViewNativeComponent.js.map +0 -1
- package/lib/module/specs/SkiaGraphiteViewNativeComponent.web.d.ts +0 -9
- package/lib/module/specs/SkiaGraphiteViewNativeComponent.web.js +0 -22
- package/lib/module/specs/SkiaGraphiteViewNativeComponent.web.js.map +0 -1
- package/lib/module/specs/SkiaPictureViewNativeComponent.js.map +0 -1
- package/lib/module/specs/SkiaPictureViewNativeComponent.web.d.ts +0 -10
- package/lib/module/specs/SkiaPictureViewNativeComponent.web.js +0 -23
- package/lib/module/specs/SkiaPictureViewNativeComponent.web.js.map +0 -1
- package/lib/module/views/SkiaGraphiteView.web.d.ts +0 -14
- package/lib/module/views/SkiaGraphiteView.web.js.map +0 -1
- package/lib/module/views/SkiaPictureView.web.d.ts +0 -11
- package/lib/module/views/SkiaPictureView.web.js +0 -156
- package/lib/module/views/SkiaPictureView.web.js.map +0 -1
- package/lib/typescript/src/renderer/DefaultCanvas.d.ts +0 -8
- package/lib/typescript/src/renderer/GraphiteCanvas.d.ts +0 -22
- package/lib/typescript/src/renderer/GraphiteCanvas.web.d.ts +0 -1
- package/lib/typescript/src/specs/SkiaGraphiteViewNativeComponent.d.ts +0 -10
- package/lib/typescript/src/specs/SkiaGraphiteViewNativeComponent.web.d.ts +0 -9
- package/lib/typescript/src/specs/SkiaPictureViewNativeComponent.web.d.ts +0 -10
- package/lib/typescript/src/views/SkiaGraphiteView.web.d.ts +0 -14
- package/lib/typescript/src/views/SkiaPictureView.web.d.ts +0 -11
- package/libs/.graphite +0 -1
- package/src/renderer/DefaultCanvas.tsx +0 -41
- package/src/renderer/GraphiteCanvas.tsx +0 -61
- package/src/renderer/GraphiteCanvas.web.tsx +0 -3
- package/src/specs/SkiaGraphiteViewNativeComponent.ts +0 -17
- package/src/specs/SkiaGraphiteViewNativeComponent.web.ts +0 -31
- package/src/views/SkiaPictureView.web.tsx +0 -224
package/apple/SkiaView.h
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
|
|
3
|
+
#import <CoreFoundation/CoreFoundation.h>
|
|
4
|
+
#if !TARGET_OS_OSX
|
|
5
|
+
#import <UIKit/UIKit.h>
|
|
6
|
+
#else
|
|
7
|
+
#import <React/RCTUIKit.h>
|
|
8
|
+
#endif // !TARGET_OS_OSX
|
|
9
|
+
|
|
10
|
+
#import <React/RCTViewComponentView.h>
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* The Fabric component behind <Canvas>, <SkiaPictureView> and
|
|
14
|
+
* <SkiaGraphiteView>: a CAMetalLayer presenting Graphite recordings on the
|
|
15
|
+
* display link. The frames are recorded by the native render thread pool
|
|
16
|
+
* (declarative content) or by JS (SkiaViewApi.makeGraphiteContext).
|
|
17
|
+
*/
|
|
18
|
+
@interface SkiaView : RCTViewComponentView
|
|
19
|
+
|
|
20
|
+
@end
|
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
#import "SkiaView.h"
|
|
2
|
+
|
|
3
|
+
#import <QuartzCore/CADisplayLink.h>
|
|
4
|
+
#import <QuartzCore/CATransaction.h>
|
|
5
|
+
|
|
6
|
+
#import <React/RCTConversions.h>
|
|
7
|
+
#import <React/RCTConvert.h>
|
|
8
|
+
#import <React/RCTFabricComponentsPlugins.h>
|
|
9
|
+
|
|
10
|
+
#import <react/renderer/components/rnskia/ComponentDescriptors.h>
|
|
11
|
+
#import <react/renderer/components/rnskia/EventEmitters.h>
|
|
12
|
+
#import <react/renderer/components/rnskia/Props.h>
|
|
13
|
+
#import <react/renderer/components/rnskia/RCTComponentViewHelpers.h>
|
|
14
|
+
|
|
15
|
+
#include <memory>
|
|
16
|
+
|
|
17
|
+
#import "RNSkManager.h"
|
|
18
|
+
#import "RNSkMetalCanvasProvider.h"
|
|
19
|
+
#import "RNSkView.h"
|
|
20
|
+
#import "RNSkiaModule.h"
|
|
21
|
+
|
|
22
|
+
using namespace facebook::react;
|
|
23
|
+
|
|
24
|
+
@implementation SkiaView {
|
|
25
|
+
// The native view and the layer it presents into. Both exist while the
|
|
26
|
+
// view is in the hierarchy (see willMoveToSuperview:).
|
|
27
|
+
std::shared_ptr<RNSkia::RNSkView> _view;
|
|
28
|
+
std::shared_ptr<RNSkMetalCanvasProvider> _provider;
|
|
29
|
+
// Owned by the module, which outlives its views (see finalizeUpdates:).
|
|
30
|
+
RNSkia::RNSkManager *_manager;
|
|
31
|
+
size_t _nativeId;
|
|
32
|
+
bool _highBitDepth;
|
|
33
|
+
#if !TARGET_OS_OSX
|
|
34
|
+
CADisplayLink *_displayLink;
|
|
35
|
+
#endif
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
- (instancetype)initWithFrame:(CGRect)frame {
|
|
39
|
+
if (self = [super initWithFrame:frame]) {
|
|
40
|
+
_manager = [RNSkiaModule latestActiveSkManager].get();
|
|
41
|
+
_nativeId = 0;
|
|
42
|
+
_highBitDepth = false;
|
|
43
|
+
static const auto defaultProps = std::make_shared<const SkiaViewProps>();
|
|
44
|
+
_props = defaultProps;
|
|
45
|
+
}
|
|
46
|
+
return self;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
#pragma mark - Lifecycle
|
|
50
|
+
|
|
51
|
+
// The native view lives while the view is in the hierarchy: it is created
|
|
52
|
+
// when the view gets a superview and torn down when it leaves it, so that a
|
|
53
|
+
// view kept around by a transition does not keep a surface.
|
|
54
|
+
#if !TARGET_OS_OSX
|
|
55
|
+
- (void)willMoveToSuperview:(UIView *)newSuperView {
|
|
56
|
+
[super willMoveToSuperview:newSuperView];
|
|
57
|
+
#else
|
|
58
|
+
- (void)viewWillMoveToSuperview:(NSView *)newSuperView {
|
|
59
|
+
[super viewWillMoveToSuperview:newSuperView];
|
|
60
|
+
#endif // !TARGET_OS_OSX
|
|
61
|
+
if (newSuperView == nullptr || _view != nullptr || _manager == nullptr) {
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
auto context = _manager->getPlatformContext();
|
|
65
|
+
_provider = std::make_shared<RNSkMetalCanvasProvider>(context);
|
|
66
|
+
_view = std::make_shared<RNSkia::RNSkView>(context, _provider);
|
|
67
|
+
[self.layer addSublayer:_provider->getLayer()];
|
|
68
|
+
if (_nativeId != 0) {
|
|
69
|
+
_manager->setSkiaView(_nativeId, _view);
|
|
70
|
+
}
|
|
71
|
+
_provider->setHighBitDepth(_highBitDepth);
|
|
72
|
+
__weak SkiaView *weakSelf = self;
|
|
73
|
+
_view->setFrameScheduler([weakSelf]() { [weakSelf scheduleFrame]; });
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
- (void)removeFromSuperview {
|
|
77
|
+
[self stopDisplayLink];
|
|
78
|
+
if (_view != nullptr) {
|
|
79
|
+
[_provider->getLayer() removeFromSuperlayer];
|
|
80
|
+
if (_nativeId != 0 && _manager != nullptr) {
|
|
81
|
+
_manager->setSkiaView(_nativeId, nullptr);
|
|
82
|
+
}
|
|
83
|
+
_view = nullptr;
|
|
84
|
+
_provider = nullptr;
|
|
85
|
+
}
|
|
86
|
+
[super removeFromSuperview];
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
- (void)dealloc {
|
|
90
|
+
[self stopDisplayLink];
|
|
91
|
+
[self unregisterView];
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
- (void)prepareForRecycle {
|
|
95
|
+
[super prepareForRecycle];
|
|
96
|
+
[self stopDisplayLink];
|
|
97
|
+
[self unregisterView];
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
- (void)finalizeUpdates:(RNComponentViewUpdateMask)updateMask {
|
|
101
|
+
[super finalizeUpdates:updateMask];
|
|
102
|
+
if (updateMask == RNComponentViewUpdateMaskAll) {
|
|
103
|
+
// this flag is only set when the view is inserted and we want to set the
|
|
104
|
+
// manager here since the view could be recycled or the app could be
|
|
105
|
+
// refreshed and we would have a stale manager then
|
|
106
|
+
_manager = [RNSkiaModule latestActiveSkManager].get();
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
- (void)unregisterView {
|
|
111
|
+
if (_manager != nullptr && _nativeId != 0) {
|
|
112
|
+
_manager->unregisterSkiaView(_nativeId);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
#pragma mark - Frames
|
|
117
|
+
|
|
118
|
+
// Presents on the display link: armed when a recording is submitted, paused
|
|
119
|
+
// again once the queue is empty. macOS has no CADisplayLink on the minimum
|
|
120
|
+
// deployment target, so frames are presented as soon as the main thread gets
|
|
121
|
+
// to them there.
|
|
122
|
+
- (void)scheduleFrame {
|
|
123
|
+
#if !TARGET_OS_OSX
|
|
124
|
+
if (_displayLink == nil) {
|
|
125
|
+
_displayLink = [CADisplayLink displayLinkWithTarget:self
|
|
126
|
+
selector:@selector(onFrame:)];
|
|
127
|
+
[_displayLink addToRunLoop:[NSRunLoop mainRunLoop]
|
|
128
|
+
forMode:NSRunLoopCommonModes];
|
|
129
|
+
}
|
|
130
|
+
_displayLink.paused = NO;
|
|
131
|
+
#else
|
|
132
|
+
if (_view != nullptr) {
|
|
133
|
+
_view->presentFrame();
|
|
134
|
+
}
|
|
135
|
+
#endif
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
#if !TARGET_OS_OSX
|
|
139
|
+
- (void)onFrame:(CADisplayLink *)link {
|
|
140
|
+
if (_view == nullptr || !_view->presentFrame()) {
|
|
141
|
+
link.paused = YES;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
#endif
|
|
145
|
+
|
|
146
|
+
- (void)stopDisplayLink {
|
|
147
|
+
#if !TARGET_OS_OSX
|
|
148
|
+
[_displayLink invalidate];
|
|
149
|
+
_displayLink = nil;
|
|
150
|
+
#endif
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
#pragma mark - Render
|
|
154
|
+
|
|
155
|
+
- (void)drawRect:(CGRect)rect {
|
|
156
|
+
// The OS asked for a draw: present what the view holds right away.
|
|
157
|
+
if (_view != nullptr) {
|
|
158
|
+
_view->redraw();
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
#pragma mark - Layout
|
|
163
|
+
|
|
164
|
+
- (void)layoutSubviews {
|
|
165
|
+
[super layoutSubviews];
|
|
166
|
+
if (_provider != nullptr) {
|
|
167
|
+
[CATransaction begin];
|
|
168
|
+
[CATransaction setDisableActions:YES];
|
|
169
|
+
_provider->setSize(self.bounds.size.width, self.bounds.size.height);
|
|
170
|
+
[CATransaction commit];
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
#pragma mark - Props
|
|
175
|
+
|
|
176
|
+
+ (ComponentDescriptorProvider)componentDescriptorProvider {
|
|
177
|
+
return concreteComponentDescriptorProvider<SkiaViewComponentDescriptor>();
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
- (void)updateProps:(const Props::Shared &)props
|
|
181
|
+
oldProps:(const Props::Shared &)oldProps {
|
|
182
|
+
const auto &newProps = *std::static_pointer_cast<const SkiaViewProps>(props);
|
|
183
|
+
[super updateProps:props oldProps:oldProps];
|
|
184
|
+
int nativeId =
|
|
185
|
+
[[RCTConvert NSString:RCTNSStringFromString(newProps.nativeId)] intValue];
|
|
186
|
+
[self bindNativeId:nativeId];
|
|
187
|
+
[self setHighBitDepth:newProps.highBitDepth];
|
|
188
|
+
// opaque, androidSurfaceType and androidZOrderOnTop select the backing view
|
|
189
|
+
// on Android; a CAMetalLayer composites like any other layer.
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
// Not setNativeId:, which is the setter of RCTViewComponentView's nativeId
|
|
193
|
+
// (the string Fabric assigns from the nativeID prop).
|
|
194
|
+
- (void)bindNativeId:(size_t)nativeId {
|
|
195
|
+
_nativeId = nativeId;
|
|
196
|
+
if (_view != nullptr) {
|
|
197
|
+
_manager->registerSkiaView(nativeId, _view);
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
- (void)setHighBitDepth:(bool)highBitDepth {
|
|
202
|
+
_highBitDepth = highBitDepth;
|
|
203
|
+
if (_provider != nullptr) {
|
|
204
|
+
_provider->setHighBitDepth(highBitDepth);
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
@end
|
|
209
|
+
|
|
210
|
+
Class<RCTComponentViewProtocol> SkiaViewCls(void) { return SkiaView.class; }
|
package/cpp/api/JsiSkApi.h
CHANGED
|
@@ -6,9 +6,7 @@
|
|
|
6
6
|
|
|
7
7
|
#include "JsiSkNativeObjects.h"
|
|
8
8
|
|
|
9
|
-
#ifdef SK_GRAPHITE
|
|
10
9
|
#include "rnskia/RNDawnContext.h"
|
|
11
|
-
#endif
|
|
12
10
|
|
|
13
11
|
#include "JsiNativeBuffer.h"
|
|
14
12
|
#include "JsiSkAnimatedImage.h"
|
|
@@ -167,19 +165,12 @@ public:
|
|
|
167
165
|
return JsiSkColor::createCtor()(runtime, thisValue, arguments, count);
|
|
168
166
|
}
|
|
169
167
|
JSI_HOST_FUNCTION(getNativeDevice) {
|
|
170
|
-
#ifdef SK_GRAPHITE
|
|
171
168
|
// Raw WGPUDevice pointer of the Graphite device, as a BigInt. Consumed by
|
|
172
169
|
// react-native-webgpu's importDevice(), which AddRefs it; the pointer
|
|
173
170
|
// stays owned by DawnContext and is valid for the process lifetime.
|
|
174
171
|
auto &dawnContext = DawnContext::getInstance();
|
|
175
172
|
return jsi::BigInt::fromUint64(
|
|
176
|
-
runtime,
|
|
177
|
-
reinterpret_cast<uint64_t>(dawnContext.getWGPUDevice().Get()));
|
|
178
|
-
#else
|
|
179
|
-
throw jsi::JSError(runtime,
|
|
180
|
-
"getNativeDevice() is only available with the Graphite "
|
|
181
|
-
"backend. Rebuild with SK_GRAPHITE enabled.");
|
|
182
|
-
#endif
|
|
173
|
+
runtime, reinterpret_cast<uint64_t>(dawnContext.getWGPUDevice().Get()));
|
|
183
174
|
}
|
|
184
175
|
|
|
185
176
|
JSI_HOST_FUNCTION(Recorder) {
|
|
@@ -191,9 +182,7 @@ public:
|
|
|
191
182
|
// property access returns a fresh JS wrapper around the shared factory
|
|
192
183
|
// instance.
|
|
193
184
|
std::shared_ptr<JsiSkSVGFactory> getSVGFactory() { return _svgFactory; }
|
|
194
|
-
std::shared_ptr<JsiSkImageFactory> getImageFactory() {
|
|
195
|
-
return _imageFactory;
|
|
196
|
-
}
|
|
185
|
+
std::shared_ptr<JsiSkImageFactory> getImageFactory() { return _imageFactory; }
|
|
197
186
|
std::shared_ptr<JsiSkAnimatedImageFactory> getAnimatedImageFactory() {
|
|
198
187
|
return _animatedImageFactory;
|
|
199
188
|
}
|
package/cpp/api/JsiSkCanvas.h
CHANGED
|
@@ -24,9 +24,7 @@
|
|
|
24
24
|
|
|
25
25
|
#include "utils/RNSkTypedArray.h"
|
|
26
26
|
|
|
27
|
-
#if defined(SK_GRAPHITE)
|
|
28
27
|
#include "rnskia/RNDawnContext.h"
|
|
29
|
-
#endif
|
|
30
28
|
|
|
31
29
|
#include <jsi/jsi.h>
|
|
32
30
|
|
|
@@ -42,10 +40,6 @@
|
|
|
42
40
|
#include "include/core/SkSurface.h"
|
|
43
41
|
#include "include/core/SkTypeface.h"
|
|
44
42
|
|
|
45
|
-
#if !defined(SK_GRAPHITE)
|
|
46
|
-
#include "include/gpu/ganesh/GrDirectContext.h"
|
|
47
|
-
#endif
|
|
48
|
-
|
|
49
43
|
#pragma clang diagnostic pop
|
|
50
44
|
|
|
51
45
|
namespace RNSkia {
|
|
@@ -56,9 +50,7 @@ class JsiSkCanvas : public JsiSkNativeObject<JsiSkCanvas> {
|
|
|
56
50
|
public:
|
|
57
51
|
static constexpr const char *CLASS_NAME = "Canvas";
|
|
58
52
|
|
|
59
|
-
void drawPaint(std::shared_ptr<SkPaint> paint) {
|
|
60
|
-
_canvas->drawPaint(*paint);
|
|
61
|
-
}
|
|
53
|
+
void drawPaint(std::shared_ptr<SkPaint> paint) { _canvas->drawPaint(*paint); }
|
|
62
54
|
|
|
63
55
|
void drawLine(double x1, double y1, double x2, double y2,
|
|
64
56
|
std::shared_ptr<SkPaint> paint) {
|
|
@@ -355,8 +347,7 @@ public:
|
|
|
355
347
|
|
|
356
348
|
void clipPath(std::shared_ptr<SkPathBuilder> path, double op,
|
|
357
349
|
bool doAntiAlias) {
|
|
358
|
-
_canvas->clipPath(path->snapshot(), static_cast<SkClipOp>(op),
|
|
359
|
-
doAntiAlias);
|
|
350
|
+
_canvas->clipPath(path->snapshot(), static_cast<SkClipOp>(op), doAntiAlias);
|
|
360
351
|
}
|
|
361
352
|
|
|
362
353
|
void clipRect(std::shared_ptr<SkRect> rect, double op, bool doAntiAlias) {
|
|
@@ -410,9 +401,7 @@ public:
|
|
|
410
401
|
|
|
411
402
|
void concat(std::shared_ptr<SkMatrix> matrix) { _canvas->concat(*matrix); }
|
|
412
403
|
|
|
413
|
-
void drawPicture(sk_sp<SkPicture> picture) {
|
|
414
|
-
_canvas->drawPicture(picture);
|
|
415
|
-
}
|
|
404
|
+
void drawPicture(sk_sp<SkPicture> picture) { _canvas->drawPicture(picture); }
|
|
416
405
|
|
|
417
406
|
JSI_HOST_FUNCTION(drawAtlas) {
|
|
418
407
|
auto atlas = JsiSkImage::fromValue(runtime, arguments[0]);
|
|
@@ -518,7 +507,6 @@ public:
|
|
|
518
507
|
.getArrayBuffer(runtime);
|
|
519
508
|
auto bfrPtr = reinterpret_cast<void *>(buffer.data(runtime));
|
|
520
509
|
|
|
521
|
-
#if defined(SK_GRAPHITE)
|
|
522
510
|
// Graphite records draws lazily and offers no synchronous GPU readback. If
|
|
523
511
|
// this canvas belongs to a surface, snap & submit its recording, snapshot
|
|
524
512
|
// it to a CPU raster image and read from that (mirroring
|
|
@@ -540,7 +528,6 @@ public:
|
|
|
540
528
|
}
|
|
541
529
|
return dest;
|
|
542
530
|
}
|
|
543
|
-
#endif
|
|
544
531
|
|
|
545
532
|
if (!_canvas->readPixels(*info, bfrPtr, bytesPerRow, srcX, srcY)) {
|
|
546
533
|
return jsi::Value::null();
|
|
@@ -599,8 +586,7 @@ public:
|
|
|
599
586
|
installMethod(runtime, prototype, "drawColor", &JsiSkCanvas::drawColor);
|
|
600
587
|
installMethod(runtime, prototype, "clear", &JsiSkCanvas::clear);
|
|
601
588
|
installMethod(runtime, prototype, "concat", &JsiSkCanvas::concat);
|
|
602
|
-
installMethod(runtime, prototype, "drawPicture",
|
|
603
|
-
&JsiSkCanvas::drawPicture);
|
|
589
|
+
installMethod(runtime, prototype, "drawPicture", &JsiSkCanvas::drawPicture);
|
|
604
590
|
installHostMethod(runtime, prototype, "drawAtlas", &JsiSkCanvas::drawAtlas);
|
|
605
591
|
installHostMethod(runtime, prototype, "readPixels",
|
|
606
592
|
&JsiSkCanvas::readPixels);
|
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
#pragma once
|
|
2
2
|
|
|
3
|
-
#if defined(SK_GRAPHITE)
|
|
4
|
-
|
|
5
3
|
#include <memory>
|
|
6
4
|
#include <utility>
|
|
7
5
|
|
|
@@ -10,7 +8,7 @@
|
|
|
10
8
|
#include "JsiSkCanvas.h"
|
|
11
9
|
#include "JsiSkGraphiteRecording.h"
|
|
12
10
|
#include "JsiSkNativeObjects.h"
|
|
13
|
-
#include "rnskia/
|
|
11
|
+
#include "rnskia/RNSkGraphiteTarget.h"
|
|
14
12
|
|
|
15
13
|
namespace RNSkia {
|
|
16
14
|
|
|
@@ -78,5 +76,3 @@ private:
|
|
|
78
76
|
};
|
|
79
77
|
|
|
80
78
|
} // namespace RNSkia
|
|
81
|
-
|
|
82
|
-
#endif // SK_GRAPHITE
|
|
@@ -1,14 +1,12 @@
|
|
|
1
1
|
#pragma once
|
|
2
2
|
|
|
3
|
-
#if defined(SK_GRAPHITE)
|
|
4
|
-
|
|
5
3
|
#include <memory>
|
|
6
4
|
#include <utility>
|
|
7
5
|
|
|
8
6
|
#include <jsi/jsi.h>
|
|
9
7
|
|
|
10
8
|
#include "JsiSkNativeObjects.h"
|
|
11
|
-
#include "rnskia/
|
|
9
|
+
#include "rnskia/RNSkGraphiteTarget.h"
|
|
12
10
|
|
|
13
11
|
namespace RNSkia {
|
|
14
12
|
|
|
@@ -40,5 +38,3 @@ public:
|
|
|
40
38
|
};
|
|
41
39
|
|
|
42
40
|
} // namespace RNSkia
|
|
43
|
-
|
|
44
|
-
#endif // SK_GRAPHITE
|
package/cpp/api/JsiSkImage.h
CHANGED
|
@@ -17,12 +17,8 @@
|
|
|
17
17
|
#include "JsiTextureInfo.h"
|
|
18
18
|
#include "utils/RNSkTypedArray.h"
|
|
19
19
|
|
|
20
|
-
#if defined(SK_GRAPHITE)
|
|
21
20
|
#include "include/gpu/graphite/Context.h"
|
|
22
21
|
#include "rnskia/RNDawnContext.h"
|
|
23
|
-
#else
|
|
24
|
-
#include "include/gpu/ganesh/GrDirectContext.h"
|
|
25
|
-
#endif
|
|
26
22
|
|
|
27
23
|
#pragma clang diagnostic push
|
|
28
24
|
#pragma clang diagnostic ignored "-Wdocumentation"
|
|
@@ -187,18 +183,7 @@ public:
|
|
|
187
183
|
? static_cast<SkEncodedImageFormat>(*formatParam)
|
|
188
184
|
: SkEncodedImageFormat::kPNG;
|
|
189
185
|
auto quality = qualityParam.has_value() ? *qualityParam : 100.0;
|
|
190
|
-
auto image = getObject();
|
|
191
|
-
#if defined(SK_GRAPHITE)
|
|
192
|
-
image = DawnContext::getInstance().MakeRasterImage(image);
|
|
193
|
-
#else
|
|
194
|
-
if (image->isTextureBacked()) {
|
|
195
|
-
auto grContext = getContext()->getDirectContext();
|
|
196
|
-
image = image->makeRasterImage(grContext);
|
|
197
|
-
if (!image) {
|
|
198
|
-
return nullptr;
|
|
199
|
-
}
|
|
200
|
-
}
|
|
201
|
-
#endif
|
|
186
|
+
auto image = DawnContext::getInstance().MakeRasterImage(getObject());
|
|
202
187
|
sk_sp<SkData> data;
|
|
203
188
|
|
|
204
189
|
if (format == SkEncodedImageFormat::kJPEG) {
|
|
@@ -236,10 +221,10 @@ public:
|
|
|
236
221
|
count >= 1 && !arguments[0].isUndefined() && !arguments[0].isNull()
|
|
237
222
|
? JsiOptional<double>(arguments[0].asNumber())
|
|
238
223
|
: JsiOptional<double>();
|
|
239
|
-
JsiOptional<double> quality =
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
224
|
+
JsiOptional<double> quality =
|
|
225
|
+
count >= 2 && arguments[1].isNumber()
|
|
226
|
+
? JsiOptional<double>(arguments[1].asNumber())
|
|
227
|
+
: JsiOptional<double>();
|
|
243
228
|
auto data = encodeImageData(format, quality);
|
|
244
229
|
if (!data) {
|
|
245
230
|
return jsi::Value::null();
|
|
@@ -310,38 +295,19 @@ public:
|
|
|
310
295
|
.getArrayBuffer(runtime);
|
|
311
296
|
auto bfrPtr = reinterpret_cast<void *>(buffer.data(runtime));
|
|
312
297
|
|
|
313
|
-
|
|
314
|
-
//
|
|
315
|
-
// copy of the image (a no-op when the image is already raster) and read the
|
|
316
|
-
// pixels from that. This matches the Ganesh behaviour for non-texture and
|
|
317
|
-
// texture-backed images alike.
|
|
298
|
+
// Graphite offers no synchronous GPU readback, so read from a CPU raster
|
|
299
|
+
// copy of the image (a no-op when the image is already raster).
|
|
318
300
|
auto image = DawnContext::getInstance().MakeRasterImage(getObject());
|
|
319
301
|
if (!image ||
|
|
320
302
|
!image->readPixels(nullptr, info, bfrPtr, bytesPerRow, srcX, srcY)) {
|
|
321
303
|
return jsi::Value::null();
|
|
322
304
|
}
|
|
323
|
-
#else
|
|
324
|
-
auto grContext = getContext()->getDirectContext();
|
|
325
|
-
if (!getObject()->readPixels(grContext, info, bfrPtr, bytesPerRow, srcX,
|
|
326
|
-
srcY)) {
|
|
327
|
-
return jsi::Value::null();
|
|
328
|
-
}
|
|
329
|
-
#endif
|
|
330
305
|
return dest;
|
|
331
306
|
}
|
|
332
307
|
|
|
333
308
|
std::variant<std::nullptr_t, std::shared_ptr<JsiSkImage>>
|
|
334
309
|
makeNonTextureImage() {
|
|
335
|
-
#if defined(SK_GRAPHITE)
|
|
336
310
|
auto rasterImage = DawnContext::getInstance().MakeRasterImage(getObject());
|
|
337
|
-
#else
|
|
338
|
-
auto grContext = getContext()->getDirectContext();
|
|
339
|
-
auto image = getObject();
|
|
340
|
-
if (!grContext) {
|
|
341
|
-
throw std::runtime_error("No GPU context available.");
|
|
342
|
-
}
|
|
343
|
-
auto rasterImage = image->makeRasterImage(grContext);
|
|
344
|
-
#endif
|
|
345
311
|
if (!rasterImage) {
|
|
346
312
|
return nullptr;
|
|
347
313
|
}
|
|
@@ -13,9 +13,7 @@
|
|
|
13
13
|
#include "JsiSkNativeObjects.h"
|
|
14
14
|
#include "jsi/JsiPromises.h"
|
|
15
15
|
|
|
16
|
-
#ifdef SK_GRAPHITE
|
|
17
16
|
#include "rnskia/RNDawnContext.h"
|
|
18
|
-
#endif
|
|
19
17
|
|
|
20
18
|
namespace RNSkia {
|
|
21
19
|
|
|
@@ -109,7 +107,6 @@ public:
|
|
|
109
107
|
// device: both packages link one Dawn and share one wgpu::Instance.
|
|
110
108
|
|
|
111
109
|
JSI_HOST_FUNCTION(MakeImageFromNativeTexture) {
|
|
112
|
-
#ifdef SK_GRAPHITE
|
|
113
110
|
if (count < 1 || !arguments[0].isBigInt()) {
|
|
114
111
|
throw std::runtime_error("MakeImageFromNativeTexture requires a "
|
|
115
112
|
"WGPUTexture pointer (BigInt), e.g. "
|
|
@@ -137,15 +134,9 @@ public:
|
|
|
137
134
|
}
|
|
138
135
|
return makeJsiObject(
|
|
139
136
|
runtime, std::make_shared<JsiSkImage>(getContext(), std::move(image)));
|
|
140
|
-
#else
|
|
141
|
-
throw std::runtime_error(
|
|
142
|
-
"MakeImageFromNativeTexture is only available with the Graphite "
|
|
143
|
-
"backend. Rebuild with SK_GRAPHITE enabled.");
|
|
144
|
-
#endif
|
|
145
137
|
}
|
|
146
138
|
|
|
147
139
|
JSI_HOST_FUNCTION(MakeNativeTextureFromImage) {
|
|
148
|
-
#ifdef SK_GRAPHITE
|
|
149
140
|
if (count < 1) {
|
|
150
141
|
throw std::runtime_error(
|
|
151
142
|
"MakeNativeTextureFromImage requires an SkImage argument");
|
|
@@ -165,11 +156,6 @@ public:
|
|
|
165
156
|
// releases it when the JS GPUTexture is destroyed.
|
|
166
157
|
return jsi::BigInt::fromUint64(
|
|
167
158
|
runtime, reinterpret_cast<uint64_t>(texture.MoveToCHandle()));
|
|
168
|
-
#else
|
|
169
|
-
throw std::runtime_error(
|
|
170
|
-
"MakeNativeTextureFromImage is only available with the Graphite "
|
|
171
|
-
"backend. Rebuild with SK_GRAPHITE enabled.");
|
|
172
|
-
#endif
|
|
173
159
|
}
|
|
174
160
|
|
|
175
161
|
size_t getMemoryPressure() override { return 1024; }
|
package/cpp/api/JsiSkSurface.h
CHANGED
|
@@ -15,15 +15,12 @@
|
|
|
15
15
|
#include "JsiSkCanvas.h"
|
|
16
16
|
#include "JsiSkImage.h"
|
|
17
17
|
|
|
18
|
-
#if defined(SK_GRAPHITE)
|
|
19
18
|
#include "rnskia/RNDawnContext.h"
|
|
20
|
-
#endif
|
|
21
19
|
|
|
22
20
|
#pragma clang diagnostic push
|
|
23
21
|
#pragma clang diagnostic ignored "-Wdocumentation"
|
|
24
22
|
|
|
25
23
|
#include "include/core/SkSurface.h"
|
|
26
|
-
#include "include/gpu/ganesh/GrDirectContext.h"
|
|
27
24
|
|
|
28
25
|
#pragma clang diagnostic pop
|
|
29
26
|
|
|
@@ -87,7 +84,6 @@ public:
|
|
|
87
84
|
// submitted work. Required before a native consumer on a different command
|
|
88
85
|
// queue reads this surface's texture via getNativeTextureUnstable(). #3916
|
|
89
86
|
bool sync = syncParam.has_value() && *syncParam;
|
|
90
|
-
#if defined(SK_GRAPHITE)
|
|
91
87
|
// A raster surface (e.g. Skia.Surface.Make) has no Graphite recorder;
|
|
92
88
|
// only Graphite-backed surfaces need to snap and submit a recording.
|
|
93
89
|
if (auto *recorder = surface->recorder()) {
|
|
@@ -96,11 +92,6 @@ public:
|
|
|
96
92
|
recording.get(), sync ? skgpu::graphite::SyncToCpu::kYes
|
|
97
93
|
: skgpu::graphite::SyncToCpu::kNo);
|
|
98
94
|
}
|
|
99
|
-
#else
|
|
100
|
-
if (auto dContext = GrAsDirectContext(surface->recordingContext())) {
|
|
101
|
-
dContext->flushAndSubmit(sync ? GrSyncCpu::kYes : GrSyncCpu::kNo);
|
|
102
|
-
}
|
|
103
|
-
#endif
|
|
104
95
|
}
|
|
105
96
|
|
|
106
97
|
JSI_HOST_FUNCTION(makeImageSnapshot) {
|
|
@@ -113,14 +104,12 @@ public:
|
|
|
113
104
|
} else {
|
|
114
105
|
image = surface->makeImageSnapshot();
|
|
115
106
|
}
|
|
116
|
-
#if defined(SK_GRAPHITE)
|
|
117
107
|
// A raster surface (e.g. Skia.Surface.Make) has no Graphite recorder; its
|
|
118
108
|
// snapshot is already a valid CPU image, so skip the recording submit.
|
|
119
109
|
if (auto *recorder = surface->recorder()) {
|
|
120
110
|
auto recording = recorder->snap();
|
|
121
111
|
DawnContext::getInstance().submitRecording(recording.get());
|
|
122
112
|
}
|
|
123
|
-
#endif
|
|
124
113
|
if (count > 1 && arguments[1].isObject()) {
|
|
125
114
|
auto jsiImage = getJsiObject<JsiSkImage>(runtime, arguments[1]);
|
|
126
115
|
jsiImage->setObject(image);
|
|
@@ -173,11 +162,8 @@ public:
|
|
|
173
162
|
size_t estimated = pixelBytes;
|
|
174
163
|
|
|
175
164
|
auto canvas = surface->getCanvas();
|
|
176
|
-
const bool isGpuBacked =
|
|
177
|
-
|
|
178
|
-
surface->recorder() != nullptr ||
|
|
179
|
-
(canvas && (canvas->recordingContext() != nullptr ||
|
|
180
|
-
canvas->recorder() != nullptr));
|
|
165
|
+
const bool isGpuBacked = surface->recorder() != nullptr ||
|
|
166
|
+
(canvas && canvas->recorder() != nullptr);
|
|
181
167
|
|
|
182
168
|
if (isGpuBacked) {
|
|
183
169
|
// Account for a resolved texture and depth/stencil attachments.
|
|
@@ -10,9 +10,7 @@
|
|
|
10
10
|
|
|
11
11
|
#include "JsiSkSurface.h"
|
|
12
12
|
|
|
13
|
-
#ifdef SK_GRAPHITE
|
|
14
13
|
#include "rnskia/RNDawnContext.h"
|
|
15
|
-
#endif
|
|
16
14
|
|
|
17
15
|
#pragma clang diagnostic push
|
|
18
16
|
#pragma clang diagnostic ignored "-Wdocumentation"
|
|
@@ -68,7 +66,6 @@ public:
|
|
|
68
66
|
// directly into a texture created on the shared device, so WebGPU can
|
|
69
67
|
// sample what Skia drew without any copy.
|
|
70
68
|
JSI_HOST_FUNCTION(MakeFromNativeTexture) {
|
|
71
|
-
#ifdef SK_GRAPHITE
|
|
72
69
|
if (count < 1 || !arguments[0].isBigInt()) {
|
|
73
70
|
throw std::runtime_error("MakeFromNativeTexture requires a WGPUTexture "
|
|
74
71
|
"pointer (BigInt), e.g. texture.nativePointer");
|
|
@@ -91,11 +88,6 @@ public:
|
|
|
91
88
|
}
|
|
92
89
|
return makeJsiObject(runtime, std::make_shared<JsiSkSurface>(
|
|
93
90
|
getContext(), std::move(surface)));
|
|
94
|
-
#else
|
|
95
|
-
throw std::runtime_error(
|
|
96
|
-
"MakeFromNativeTexture is only available with the Graphite backend. "
|
|
97
|
-
"Rebuild with SK_GRAPHITE enabled.");
|
|
98
|
-
#endif
|
|
99
91
|
}
|
|
100
92
|
|
|
101
93
|
size_t getMemoryPressure() override { return 2048; }
|
|
@@ -144,6 +144,11 @@ public:
|
|
|
144
144
|
}
|
|
145
145
|
|
|
146
146
|
sk_sp<SkImage> MakeImageFromBuffer(void *buffer) {
|
|
147
|
+
#if defined(__ANDROID__) && __ANDROID_API__ < 26
|
|
148
|
+
// AHardwareBuffer is only available from API 26
|
|
149
|
+
(void)buffer;
|
|
150
|
+
return nullptr;
|
|
151
|
+
#else
|
|
147
152
|
#ifdef __APPLE__
|
|
148
153
|
wgpu::SharedTextureMemoryIOSurfaceDescriptor platformDesc;
|
|
149
154
|
auto ioSurface = CVPixelBufferGetIOSurface((CVPixelBufferRef)buffer);
|
|
@@ -213,6 +218,7 @@ public:
|
|
|
213
218
|
return nullptr;
|
|
214
219
|
}
|
|
215
220
|
return nullptr;
|
|
221
|
+
#endif
|
|
216
222
|
}
|
|
217
223
|
|
|
218
224
|
// Create offscreen surface
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
#ifdef SK_GRAPHITE
|
|
2
|
-
|
|
3
1
|
#include "RNDawnContext.h"
|
|
4
2
|
|
|
5
3
|
// Runtime discovery surface for react-native-webgpu.
|
|
@@ -15,5 +13,3 @@ extern "C" __attribute__((visibility("default"))) WGPUInstance
|
|
|
15
13
|
rnskia_getWGPUInstance() {
|
|
16
14
|
return RNSkia::DawnContext::getInstance().getWGPUInstance().Get();
|
|
17
15
|
}
|
|
18
|
-
|
|
19
|
-
#endif
|
package/cpp/rnskia/RNDawnUtils.h
CHANGED
|
@@ -137,7 +137,6 @@ requestDevice(dawn::native::Adapter &nativeAdapter,
|
|
|
137
137
|
#endif
|
|
138
138
|
"disable_lazy_clear_for_mapped_at_creation_buffer",
|
|
139
139
|
"allow_unsafe_apis",
|
|
140
|
-
"use_user_defined_labels_in_backend",
|
|
141
140
|
"disable_robustness",
|
|
142
141
|
};
|
|
143
142
|
wgpu::DawnTogglesDescriptor togglesDesc;
|
|
@@ -42,4 +42,14 @@ bool DawnWindowContext::presentRecordings(
|
|
|
42
42
|
return success;
|
|
43
43
|
}
|
|
44
44
|
|
|
45
|
+
bool DawnWindowContext::presentImage(const sk_sp<SkImage> &image) {
|
|
46
|
+
auto surface = getSurface();
|
|
47
|
+
if (!surface) {
|
|
48
|
+
return false;
|
|
49
|
+
}
|
|
50
|
+
surface->getCanvas()->drawImage(image, 0, 0);
|
|
51
|
+
present();
|
|
52
|
+
return true;
|
|
53
|
+
}
|
|
54
|
+
|
|
45
55
|
} // namespace RNSkia
|
|
@@ -74,6 +74,10 @@ public:
|
|
|
74
74
|
bool presentRecordings(
|
|
75
75
|
const std::vector<skgpu::graphite::Recording *> &recordings);
|
|
76
76
|
|
|
77
|
+
// Draws an image at the origin of the current swapchain texture (on the
|
|
78
|
+
// window's own recorder) and presents it.
|
|
79
|
+
bool presentImage(const sk_sp<SkImage> &image);
|
|
80
|
+
|
|
77
81
|
SkColorType getColorType() const { return _colorType; }
|
|
78
82
|
|
|
79
83
|
// The texture description a deferred canvas must be recorded with to be
|