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
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
|
|
3
|
+
#include <functional>
|
|
4
|
+
#include <memory>
|
|
5
|
+
#include <utility>
|
|
6
|
+
#include <vector>
|
|
7
|
+
|
|
8
|
+
#include "RNDawnContext.h"
|
|
9
|
+
#include "RNDawnUtils.h"
|
|
10
|
+
#include "RNSkPlatformContext.h"
|
|
11
|
+
|
|
12
|
+
#pragma clang diagnostic push
|
|
13
|
+
#pragma clang diagnostic ignored "-Wdocumentation"
|
|
14
|
+
|
|
15
|
+
#include "include/core/SkCanvas.h"
|
|
16
|
+
#include "include/core/SkImage.h"
|
|
17
|
+
#include "include/core/SkSurface.h"
|
|
18
|
+
#include "include/gpu/graphite/Recording.h"
|
|
19
|
+
#include "include/gpu/graphite/TextureInfo.h"
|
|
20
|
+
#include "include/gpu/graphite/dawn/DawnGraphiteTypes.h"
|
|
21
|
+
|
|
22
|
+
#pragma clang diagnostic pop
|
|
23
|
+
|
|
24
|
+
namespace RNSkia {
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Describes the texture a recording is replayed onto: the pixel size and the
|
|
28
|
+
* format of a window (or offscreen) surface. A deferred canvas is recorded
|
|
29
|
+
* against this description, so it can be created before the surface itself
|
|
30
|
+
* exists.
|
|
31
|
+
*/
|
|
32
|
+
struct RNSkGraphiteTargetInfo {
|
|
33
|
+
int width = 0;
|
|
34
|
+
int height = 0;
|
|
35
|
+
SkColorType colorType = kUnknown_SkColorType;
|
|
36
|
+
skgpu::graphite::TextureInfo textureInfo;
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* The surface a view presents into: a platform window (a CAMetalLayer, an
|
|
41
|
+
* ANativeWindow) or an offscreen surface. It describes its target texture to
|
|
42
|
+
* whoever records for the view and replays their recordings onto it.
|
|
43
|
+
*/
|
|
44
|
+
class RNSkCanvasProvider {
|
|
45
|
+
public:
|
|
46
|
+
virtual ~RNSkCanvasProvider() = default;
|
|
47
|
+
|
|
48
|
+
/** Width of the surface, in pixels. */
|
|
49
|
+
virtual int getWidth() = 0;
|
|
50
|
+
|
|
51
|
+
/** Height of the surface, in pixels. */
|
|
52
|
+
virtual int getHeight() = 0;
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
Describes the current target texture. Safe to call from any thread;
|
|
56
|
+
returns false while there is no surface to describe.
|
|
57
|
+
*/
|
|
58
|
+
virtual bool getTargetInfo(RNSkGraphiteTargetInfo *info) = 0;
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
The size in pixels the surface will have, known from the platform layout
|
|
62
|
+
before the surface itself exists (on Android the surface only appears a
|
|
63
|
+
frame after the view is laid out). Safe to call from any thread; returns
|
|
64
|
+
false until the view is laid out. A frame recorded against this size is
|
|
65
|
+
presented as is once the surface appears, where one recorded against a
|
|
66
|
+
size derived from the layout in points could be off by a pixel and would
|
|
67
|
+
not cover the surface.
|
|
68
|
+
*/
|
|
69
|
+
virtual bool getLayoutSize(int *width, int *height) { return false; }
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
Replays the recordings, in order, onto the target texture and presents
|
|
73
|
+
it. Called on the thread that owns the surface. Returns false when the
|
|
74
|
+
surface cannot present right now (there is none, or the app is in the
|
|
75
|
+
background): nothing was consumed.
|
|
76
|
+
*/
|
|
77
|
+
virtual bool presentRecordings(
|
|
78
|
+
const std::vector<skgpu::graphite::Recording *> &recordings) = 0;
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
Draws an image at the origin of the target texture and presents it. Same
|
|
82
|
+
thread and return value as presentRecordings(). Used for a recording whose
|
|
83
|
+
size differs from the target's: it is replayed into a texture of its own
|
|
84
|
+
size first (see RNSkView::present).
|
|
85
|
+
*/
|
|
86
|
+
virtual bool presentImage(const sk_sp<SkImage> &image) = 0;
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
Installed by the view owning the provider: asks it for a frame when the
|
|
90
|
+
surface appears or changes size.
|
|
91
|
+
*/
|
|
92
|
+
void setRequestRedraw(std::function<void()> requestRedraw) {
|
|
93
|
+
_requestRedraw = std::move(requestRedraw);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
protected:
|
|
97
|
+
void requestRedraw() {
|
|
98
|
+
if (_requestRedraw) {
|
|
99
|
+
_requestRedraw();
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
private:
|
|
104
|
+
std::function<void()> _requestRedraw;
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* An offscreen surface the content of a view is replayed into for a snapshot.
|
|
109
|
+
*/
|
|
110
|
+
class RNSkOffscreenCanvasProvider : public RNSkCanvasProvider {
|
|
111
|
+
public:
|
|
112
|
+
RNSkOffscreenCanvasProvider(
|
|
113
|
+
const std::shared_ptr<RNSkPlatformContext> &context, int width,
|
|
114
|
+
int height)
|
|
115
|
+
: _width(width), _height(height), _pd(context->getPixelDensity()),
|
|
116
|
+
_surface(context->makeOffscreenSurface(width, height)) {}
|
|
117
|
+
|
|
118
|
+
virtual ~RNSkOffscreenCanvasProvider() = default;
|
|
119
|
+
|
|
120
|
+
/** The canvas of the surface, in pixels; nullptr without a surface. */
|
|
121
|
+
SkCanvas *getCanvas() { return _surface ? _surface->getCanvas() : nullptr; }
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
A GPU image of the surface, usable by any recorder of the context once
|
|
125
|
+
this returns; nullptr without a surface.
|
|
126
|
+
*/
|
|
127
|
+
sk_sp<SkImage> makeImage() {
|
|
128
|
+
if (_surface == nullptr) {
|
|
129
|
+
return nullptr;
|
|
130
|
+
}
|
|
131
|
+
auto image = _surface->makeImageSnapshot();
|
|
132
|
+
// The snapshot is a copy task on the surface's recorder: submitted here,
|
|
133
|
+
// so that the image is complete for whoever draws it next.
|
|
134
|
+
if (auto *recorder = _surface->recorder()) {
|
|
135
|
+
DawnContext::getInstance().submitRecording(recorder->snap().get());
|
|
136
|
+
}
|
|
137
|
+
return image;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
Returns a snapshot of the current surface/canvas
|
|
142
|
+
*/
|
|
143
|
+
sk_sp<SkImage> makeSnapshot(SkRect *bounds) {
|
|
144
|
+
if (_surface == nullptr) {
|
|
145
|
+
return nullptr;
|
|
146
|
+
}
|
|
147
|
+
sk_sp<SkImage> image;
|
|
148
|
+
if (bounds != nullptr) {
|
|
149
|
+
SkIRect b =
|
|
150
|
+
SkIRect::MakeXYWH(bounds->x() * _pd, bounds->y() * _pd,
|
|
151
|
+
bounds->width() * _pd, bounds->height() * _pd);
|
|
152
|
+
image = _surface->makeImageSnapshot(b);
|
|
153
|
+
} else {
|
|
154
|
+
image = _surface->makeImageSnapshot();
|
|
155
|
+
}
|
|
156
|
+
// Only Graphite-backed surfaces have a recorder to snap/submit; a raster
|
|
157
|
+
// surface's snapshot is already a valid CPU image.
|
|
158
|
+
if (auto *recorder = _surface->recorder()) {
|
|
159
|
+
DawnContext::getInstance().submitRecording(recorder->snap().get());
|
|
160
|
+
}
|
|
161
|
+
return DawnContext::getInstance().MakeRasterImage(image);
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
int getWidth() override { return _width; }
|
|
165
|
+
|
|
166
|
+
int getHeight() override { return _height; }
|
|
167
|
+
|
|
168
|
+
bool getTargetInfo(RNSkGraphiteTargetInfo *info) override {
|
|
169
|
+
if (_surface == nullptr || _surface->recorder() == nullptr) {
|
|
170
|
+
return false;
|
|
171
|
+
}
|
|
172
|
+
// Graphite gives its render targets the sampled+renderable usage, a
|
|
173
|
+
// superset of what a deferred canvas asks for.
|
|
174
|
+
auto colorType = _surface->imageInfo().colorType();
|
|
175
|
+
info->width = _width;
|
|
176
|
+
info->height = _height;
|
|
177
|
+
info->colorType = colorType;
|
|
178
|
+
info->textureInfo = skgpu::graphite::TextureInfos::MakeDawn(
|
|
179
|
+
skgpu::graphite::DawnTextureInfo(
|
|
180
|
+
skgpu::graphite::SampleCount::k1, skgpu::Mipmapped::kNo,
|
|
181
|
+
DawnUtils::textureFormatForColorType(colorType),
|
|
182
|
+
DawnUtils::DefaultTargetUsage, wgpu::TextureAspect::All));
|
|
183
|
+
return true;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
bool presentRecordings(
|
|
187
|
+
const std::vector<skgpu::graphite::Recording *> &recordings) override {
|
|
188
|
+
auto *recorder = _surface ? _surface->recorder() : nullptr;
|
|
189
|
+
if (recorder == nullptr) {
|
|
190
|
+
return false;
|
|
191
|
+
}
|
|
192
|
+
// A new surface clears itself in its first pass, which its own recorder
|
|
193
|
+
// only records when it next snaps. The recordings go straight to the
|
|
194
|
+
// context, so that clear would run after them and wipe them: record and
|
|
195
|
+
// submit it first (the explicit clear makes sure the pass is emitted).
|
|
196
|
+
if (!_cleared) {
|
|
197
|
+
_surface->getCanvas()->clear(SK_ColorTRANSPARENT);
|
|
198
|
+
DawnContext::getInstance().submitRecording(recorder->snap().get());
|
|
199
|
+
_cleared = true;
|
|
200
|
+
}
|
|
201
|
+
return DawnContext::getInstance().insertRecordings(recordings,
|
|
202
|
+
_surface.get());
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
bool presentImage(const sk_sp<SkImage> &image) override {
|
|
206
|
+
if (_surface == nullptr) {
|
|
207
|
+
return false;
|
|
208
|
+
}
|
|
209
|
+
_surface->getCanvas()->drawImage(image, 0, 0);
|
|
210
|
+
return true;
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
private:
|
|
214
|
+
int _width;
|
|
215
|
+
int _height;
|
|
216
|
+
float _pd;
|
|
217
|
+
sk_sp<SkSurface> _surface;
|
|
218
|
+
bool _cleared = false;
|
|
219
|
+
};
|
|
220
|
+
|
|
221
|
+
} // namespace RNSkia
|
|
@@ -1,15 +1,13 @@
|
|
|
1
1
|
// Everything that needs a complete Recorder lives here rather than in
|
|
2
2
|
// RNSkGraphiteProducer.h (which the view headers include on their own).
|
|
3
|
-
#if defined(SK_GRAPHITE)
|
|
4
|
-
|
|
5
3
|
#include "RNSkGraphiteProducer.h"
|
|
6
4
|
|
|
7
5
|
#include <memory>
|
|
8
6
|
#include <utility>
|
|
9
7
|
|
|
10
|
-
#include "
|
|
11
|
-
#include "RNSkPictureView.h"
|
|
8
|
+
#include "RNSkGraphiteTarget.h"
|
|
12
9
|
#include "RNSkThreadPool.h"
|
|
10
|
+
#include "api/recorder/DrawingCtx.h"
|
|
13
11
|
#include "api/recorder/RNRecorder.h"
|
|
14
12
|
#include "utils/RNSkLog.h"
|
|
15
13
|
|
|
@@ -20,6 +18,21 @@ namespace RNSkia {
|
|
|
20
18
|
|
|
21
19
|
RNSkGraphiteProducer::~RNSkGraphiteProducer() = default;
|
|
22
20
|
|
|
21
|
+
void RNSkGraphiteProducer::drawContent(SkCanvas *canvas, Recorder *recorder,
|
|
22
|
+
const sk_sp<SkPicture> &picture,
|
|
23
|
+
float pixelDensity) {
|
|
24
|
+
canvas->clear(SK_ColorTRANSPARENT);
|
|
25
|
+
canvas->save();
|
|
26
|
+
canvas->scale(pixelDensity, pixelDensity);
|
|
27
|
+
if (recorder != nullptr) {
|
|
28
|
+
DrawingCtx ctx(canvas);
|
|
29
|
+
recorder->play(&ctx);
|
|
30
|
+
} else if (picture != nullptr) {
|
|
31
|
+
canvas->drawPicture(picture);
|
|
32
|
+
}
|
|
33
|
+
canvas->restore();
|
|
34
|
+
}
|
|
35
|
+
|
|
23
36
|
void RNSkGraphiteProducer::setTarget(
|
|
24
37
|
std::shared_ptr<RNSkGraphiteTarget> target) {
|
|
25
38
|
std::lock_guard<std::mutex> lock(_mutex);
|
|
@@ -67,6 +80,18 @@ bool RNSkGraphiteProducer::hasContent() {
|
|
|
67
80
|
return _recorder != nullptr || _picture != nullptr;
|
|
68
81
|
}
|
|
69
82
|
|
|
83
|
+
bool RNSkGraphiteProducer::applyUpdatesTo(
|
|
84
|
+
const std::shared_ptr<Recorder> &recorder, jsi::Runtime &runtime,
|
|
85
|
+
double recorderId, const jsi::Array &values) {
|
|
86
|
+
if (recorder == nullptr || recorder->id != recorderId) {
|
|
87
|
+
return false;
|
|
88
|
+
}
|
|
89
|
+
// The values are written into the commands by the next replay, which the
|
|
90
|
+
// caller schedules: the mapper never waits for a draw.
|
|
91
|
+
recorder->readUpdates(runtime, values);
|
|
92
|
+
return true;
|
|
93
|
+
}
|
|
94
|
+
|
|
70
95
|
bool RNSkGraphiteProducer::applyUpdates(jsi::Runtime &runtime,
|
|
71
96
|
double recorderId,
|
|
72
97
|
const jsi::Array &values) {
|
|
@@ -75,13 +100,12 @@ bool RNSkGraphiteProducer::applyUpdates(jsi::Runtime &runtime,
|
|
|
75
100
|
std::lock_guard<std::mutex> lock(_mutex);
|
|
76
101
|
recorder = _recorder;
|
|
77
102
|
}
|
|
78
|
-
if (recorder == nullptr || recorder->id != recorderId) {
|
|
79
|
-
return false;
|
|
80
|
-
}
|
|
81
103
|
// Outside the lock: a commit replacing the recorder must not wait for the
|
|
82
104
|
// read. Should it land while this runs, the values go into the retired
|
|
83
105
|
// recorder and the commit's own frame draws the new one.
|
|
84
|
-
recorder
|
|
106
|
+
if (!applyUpdatesTo(recorder, runtime, recorderId, values)) {
|
|
107
|
+
return false;
|
|
108
|
+
}
|
|
85
109
|
std::lock_guard<std::mutex> lock(_mutex);
|
|
86
110
|
_dirty = true;
|
|
87
111
|
kickLocked();
|
|
@@ -142,14 +166,14 @@ void RNSkGraphiteProducer::produce() {
|
|
|
142
166
|
// The deferred canvas already draws in points.
|
|
143
167
|
drawContent(canvas, recorder.get(), picture, /* pixelDensity= */ 1.0f);
|
|
144
168
|
} catch (const std::exception &e) {
|
|
145
|
-
RNSkLogger::logToConsole(
|
|
146
|
-
|
|
169
|
+
RNSkLogger::logToConsole("Canvas: replaying the scene failed: %s",
|
|
170
|
+
e.what());
|
|
147
171
|
}
|
|
148
172
|
try {
|
|
149
173
|
recording = target->finishRecording();
|
|
150
174
|
} catch (const std::exception &e) {
|
|
151
|
-
RNSkLogger::logToConsole(
|
|
152
|
-
|
|
175
|
+
RNSkLogger::logToConsole("Canvas: recording the frame failed: %s",
|
|
176
|
+
e.what());
|
|
153
177
|
}
|
|
154
178
|
}
|
|
155
179
|
}
|
|
@@ -185,5 +209,3 @@ void RNSkGraphiteProducer::renderInto(SkCanvas *canvas, float pixelDensity) {
|
|
|
185
209
|
}
|
|
186
210
|
|
|
187
211
|
} // namespace RNSkia
|
|
188
|
-
|
|
189
|
-
#endif // SK_GRAPHITE
|
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
#pragma once
|
|
2
2
|
|
|
3
|
-
#if defined(SK_GRAPHITE)
|
|
4
|
-
|
|
5
3
|
#include <memory>
|
|
6
4
|
#include <mutex>
|
|
7
5
|
|
|
@@ -20,9 +18,9 @@ class Recorder;
|
|
|
20
18
|
class RNSkGraphiteTarget;
|
|
21
19
|
|
|
22
20
|
/**
|
|
23
|
-
* Records the declarative content of a
|
|
24
|
-
*
|
|
25
|
-
*
|
|
21
|
+
* Records the declarative content of a view (a Recorder handed over by
|
|
22
|
+
* <Canvas>, or a picture) into Graphite recordings, on the render thread
|
|
23
|
+
* pool.
|
|
26
24
|
*
|
|
27
25
|
* Three threads meet here. The JS thread hands over the content. A Reanimated
|
|
28
26
|
* mapper, on the UI runtime, reads the shared values into the recorder's
|
|
@@ -50,7 +48,11 @@ public:
|
|
|
50
48
|
/**
|
|
51
49
|
Takes ownership of the recorder (or releases it with nullptr). A recording
|
|
52
50
|
without shared values is played once into a picture: nothing will ever
|
|
53
|
-
update it, and drawing a picture is cheaper than replaying commands.
|
|
51
|
+
update it, and drawing a picture is cheaper than replaying commands. The
|
|
52
|
+
recorder is owned here rather than by a JS wrapper: its commands hold
|
|
53
|
+
every native resource the canvas draws (images, pictures, paths), and
|
|
54
|
+
tying their lifetime to the garbage collector of a runtime that rarely
|
|
55
|
+
allocates (the UI runtime) kept them resident long after unmount.
|
|
54
56
|
*/
|
|
55
57
|
void setRecorder(std::shared_ptr<Recorder> recorder);
|
|
56
58
|
|
|
@@ -73,6 +75,14 @@ public:
|
|
|
73
75
|
bool applyUpdates(jsi::Runtime &runtime, double recorderId,
|
|
74
76
|
const jsi::Array &values);
|
|
75
77
|
|
|
78
|
+
/**
|
|
79
|
+
Same as applyUpdates(), for a recording that no view owns yet (one queued
|
|
80
|
+
in the view registry until its view registers).
|
|
81
|
+
*/
|
|
82
|
+
static bool applyUpdatesTo(const std::shared_ptr<Recorder> &recorder,
|
|
83
|
+
jsi::Runtime &runtime, double recorderId,
|
|
84
|
+
const jsi::Array &values);
|
|
85
|
+
|
|
76
86
|
/**
|
|
77
87
|
Marks the content dirty and schedules a frame if one can start. Returns
|
|
78
88
|
whether a frame is coming at all: there is content and a target to record
|
|
@@ -90,6 +100,13 @@ public:
|
|
|
90
100
|
void renderInto(SkCanvas *canvas, float pixelDensity);
|
|
91
101
|
|
|
92
102
|
private:
|
|
103
|
+
/**
|
|
104
|
+
Replays declarative content, a recorder if there is one, else a picture,
|
|
105
|
+
into a canvas: clears it and applies the density.
|
|
106
|
+
*/
|
|
107
|
+
static void drawContent(SkCanvas *canvas, Recorder *recorder,
|
|
108
|
+
const sk_sp<SkPicture> &picture, float pixelDensity);
|
|
109
|
+
|
|
93
110
|
/**
|
|
94
111
|
Swaps the content under the lock and releases the previous one outside of
|
|
95
112
|
it: the recorder's destructor hands the commands to the main thread, and a
|
|
@@ -112,5 +129,3 @@ private:
|
|
|
112
129
|
};
|
|
113
130
|
|
|
114
131
|
} // namespace RNSkia
|
|
115
|
-
|
|
116
|
-
#endif // SK_GRAPHITE
|