react-native-skia 3.0.1 → 3.0.3
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/README.md +19 -2
- package/android/CMakeLists.txt +13 -42
- package/android/build.gradle +54 -63
- 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 +10 -12
- package/apple/RNSkApplePlatformContext.h +12 -14
- package/apple/RNSkApplePlatformContext.mm +19 -112
- package/apple/RNSkMetalCanvasProvider.h +14 -19
- package/apple/RNSkMetalCanvasProvider.mm +39 -70
- package/apple/RNSkiaModule.mm +10 -0
- 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 +3 -2
- package/cpp/rnskia/RNDawnInterop.cpp +0 -4
- package/cpp/rnskia/RNDawnUtils.h +12 -1
- package/cpp/rnskia/RNDawnWindowContext.cpp +12 -1
- package/cpp/rnskia/RNDawnWindowContext.h +19 -7
- package/cpp/rnskia/RNMetalLayerColorSpace.h +4 -2
- package/cpp/rnskia/RNSkCanvasProvider.h +231 -0
- package/cpp/rnskia/RNSkGraphiteProducer.cpp +36 -14
- package/cpp/rnskia/RNSkGraphiteProducer.h +23 -8
- package/cpp/rnskia/RNSkGraphiteTarget.h +396 -0
- package/cpp/rnskia/RNSkJsiViewApi.h +9 -18
- package/cpp/rnskia/RNSkPlatformContext.h +17 -15
- package/cpp/rnskia/RNSkView.h +362 -246
- 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/external/reanimated/interpolators.js +1 -1
- package/lib/commonjs/external/reanimated/interpolators.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 +25 -21
- 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/external/reanimated/interpolators.js +1 -1
- package/lib/module/external/reanimated/interpolators.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 +25 -20
- 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 +5 -13
- package/react-native-skia.podspec +34 -58
- package/src/Platform/Platform.web.tsx +1 -1
- package/src/external/reanimated/interpolators.ts +1 -1
- package/src/index.ts +1 -3
- package/src/mock/index.ts +0 -1
- package/src/renderer/Canvas.tsx +24 -28
- 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
|
@@ -1,31 +1,13 @@
|
|
|
1
1
|
#import "RNSkMetalCanvasProvider.h"
|
|
2
2
|
|
|
3
|
-
#import "RNSkLog.h"
|
|
4
|
-
|
|
5
|
-
#if defined(SK_GRAPHITE)
|
|
6
3
|
#import "RNDawnContext.h"
|
|
7
|
-
#
|
|
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>
|
|
4
|
+
#import "RNSkLog.h"
|
|
21
5
|
|
|
22
|
-
#
|
|
6
|
+
#include <cmath>
|
|
23
7
|
|
|
24
8
|
RNSkMetalCanvasProvider::RNSkMetalCanvasProvider(
|
|
25
|
-
std::
|
|
26
|
-
std::
|
|
27
|
-
: RNSkCanvasProvider(requestRedraw), _context(context),
|
|
28
|
-
_useP3ColorSpace(useP3ColorSpace) {
|
|
9
|
+
std::shared_ptr<RNSkia::RNSkPlatformContext> context)
|
|
10
|
+
: _context(std::move(context)) {
|
|
29
11
|
#pragma clang diagnostic push
|
|
30
12
|
#pragma clang diagnostic ignored "-Wunguarded-availability-new"
|
|
31
13
|
_layer = [CAMetalLayer layer];
|
|
@@ -61,38 +43,7 @@ static bool appIsBackgrounded() {
|
|
|
61
43
|
#endif // !TARGET_OS_OSX
|
|
62
44
|
}
|
|
63
45
|
|
|
64
|
-
|
|
65
|
-
Render to a canvas
|
|
66
|
-
*/
|
|
67
|
-
bool RNSkMetalCanvasProvider::renderToCanvas(
|
|
68
|
-
const std::function<void(SkCanvas *)> &cb) {
|
|
69
|
-
if (!_ctx) {
|
|
70
|
-
return false;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
if ([[NSThread currentThread] isMainThread]) {
|
|
74
|
-
if (appIsBackgrounded()) {
|
|
75
|
-
// Request a redraw in the next run loop callback
|
|
76
|
-
_requestRedraw();
|
|
77
|
-
// and don't draw now since it might cause errors in the metal renderer if
|
|
78
|
-
// we try to render while in the background. (see above issue)
|
|
79
|
-
return false;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
auto surface = _ctx->getSurface();
|
|
83
|
-
if (!surface) {
|
|
84
|
-
return false;
|
|
85
|
-
}
|
|
86
|
-
auto canvas = surface->getCanvas();
|
|
87
|
-
cb(canvas);
|
|
88
|
-
_ctx->present();
|
|
89
|
-
return true;
|
|
90
|
-
}
|
|
91
|
-
return false;
|
|
92
|
-
};
|
|
93
|
-
|
|
94
|
-
#if defined(SK_GRAPHITE)
|
|
95
|
-
bool RNSkMetalCanvasProvider::getGraphiteTargetInfo(
|
|
46
|
+
bool RNSkMetalCanvasProvider::getTargetInfo(
|
|
96
47
|
RNSkia::RNSkGraphiteTargetInfo *info) {
|
|
97
48
|
std::lock_guard<std::mutex> lock(_targetInfoMutex);
|
|
98
49
|
if (!_hasTargetInfo) {
|
|
@@ -102,49 +53,67 @@ bool RNSkMetalCanvasProvider::getGraphiteTargetInfo(
|
|
|
102
53
|
return true;
|
|
103
54
|
}
|
|
104
55
|
|
|
56
|
+
bool RNSkMetalCanvasProvider::getLayoutSize(int *width, int *height) {
|
|
57
|
+
std::lock_guard<std::mutex> lock(_targetInfoMutex);
|
|
58
|
+
if (_layoutWidth <= 0 || _layoutHeight <= 0) {
|
|
59
|
+
return false;
|
|
60
|
+
}
|
|
61
|
+
*width = _layoutWidth;
|
|
62
|
+
*height = _layoutHeight;
|
|
63
|
+
return true;
|
|
64
|
+
}
|
|
65
|
+
|
|
105
66
|
bool RNSkMetalCanvasProvider::presentRecordings(
|
|
106
67
|
const std::vector<skgpu::graphite::Recording *> &recordings) {
|
|
107
68
|
if (!_ctx || ![[NSThread currentThread] isMainThread]) {
|
|
108
69
|
return false;
|
|
109
70
|
}
|
|
110
71
|
if (appIsBackgrounded()) {
|
|
111
|
-
|
|
72
|
+
requestRedraw();
|
|
112
73
|
return false;
|
|
113
74
|
}
|
|
114
75
|
return static_cast<RNSkia::DawnWindowContext *>(_ctx.get())
|
|
115
76
|
->presentRecordings(recordings);
|
|
116
77
|
}
|
|
117
|
-
|
|
78
|
+
|
|
79
|
+
bool RNSkMetalCanvasProvider::presentImage(const sk_sp<SkImage> &image) {
|
|
80
|
+
if (!_ctx || ![[NSThread currentThread] isMainThread]) {
|
|
81
|
+
return false;
|
|
82
|
+
}
|
|
83
|
+
if (appIsBackgrounded()) {
|
|
84
|
+
requestRedraw();
|
|
85
|
+
return false;
|
|
86
|
+
}
|
|
87
|
+
return static_cast<RNSkia::DawnWindowContext *>(_ctx.get())
|
|
88
|
+
->presentImage(image);
|
|
89
|
+
}
|
|
118
90
|
|
|
119
91
|
void RNSkMetalCanvasProvider::setSize(int width, int height) {
|
|
120
92
|
_layer.frame = CGRectMake(0, 0, width, height);
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
93
|
+
// The layout is on the pixel grid: round rather than truncate, so that a
|
|
94
|
+
// product like 1169.9999 gives the pixel size the layout means.
|
|
95
|
+
int w = static_cast<int>(std::lround(width * _context->getPixelDensity()));
|
|
96
|
+
int h = static_cast<int>(std::lround(height * _context->getPixelDensity()));
|
|
97
|
+
_ctx = RNSkia::DawnContext::getInstance().MakeWindow(
|
|
98
|
+
(__bridge void *)_layer, w, h, _highBitDepth,
|
|
99
|
+
_context->prefersP3ColorSpace());
|
|
126
100
|
{
|
|
127
101
|
auto *window = static_cast<RNSkia::DawnWindowContext *>(_ctx.get());
|
|
128
102
|
std::lock_guard<std::mutex> lock(_targetInfoMutex);
|
|
103
|
+
_layoutWidth = w;
|
|
104
|
+
_layoutHeight = h;
|
|
129
105
|
_targetInfo.width = window->getWidth();
|
|
130
106
|
_targetInfo.height = window->getHeight();
|
|
131
107
|
_targetInfo.colorType = window->getColorType();
|
|
108
|
+
_targetInfo.useP3ColorSpace = window->usesP3ColorSpace();
|
|
132
109
|
_targetInfo.textureInfo = window->getTextureInfo();
|
|
133
110
|
_hasTargetInfo = true;
|
|
134
111
|
}
|
|
135
|
-
|
|
136
|
-
_ctx = MetalContext::getInstance().MakeWindow(_layer, w, h, _useP3ColorSpace,
|
|
137
|
-
_highBitDepth);
|
|
138
|
-
#endif
|
|
139
|
-
_requestRedraw();
|
|
112
|
+
requestRedraw();
|
|
140
113
|
}
|
|
141
114
|
|
|
142
115
|
CALayer *RNSkMetalCanvasProvider::getLayer() { return _layer; }
|
|
143
116
|
|
|
144
|
-
void RNSkMetalCanvasProvider::setUseP3ColorSpace(bool useP3ColorSpace) {
|
|
145
|
-
_useP3ColorSpace = useP3ColorSpace;
|
|
146
|
-
}
|
|
147
|
-
|
|
148
117
|
void RNSkMetalCanvasProvider::setHighBitDepth(bool highBitDepth) {
|
|
149
118
|
if (_highBitDepth == highBitDepth) {
|
|
150
119
|
return;
|
package/apple/RNSkiaModule.mm
CHANGED
|
@@ -39,6 +39,16 @@ RCT_EXPORT_MODULE()
|
|
|
39
39
|
return YES;
|
|
40
40
|
}
|
|
41
41
|
|
|
42
|
+
- (instancetype)init {
|
|
43
|
+
if (self = [super init]) {
|
|
44
|
+
// Created on the main queue (see requiresMainQueueSetup): the screen is
|
|
45
|
+
// asked for its color gamut here, where UIKit may be used. The platform
|
|
46
|
+
// context is created on the JS thread and only reads the answer.
|
|
47
|
+
RNSkia::RNSkApplePlatformContext::mainScreenSupportsP3();
|
|
48
|
+
}
|
|
49
|
+
return self;
|
|
50
|
+
}
|
|
51
|
+
|
|
42
52
|
- (void)
|
|
43
53
|
installJSIBindingsWithRuntime:(facebook::jsi::Runtime &)runtime
|
|
44
54
|
callInvoker:
|
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
|
}
|