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
package/cpp/rnskia/RNSkView.h
CHANGED
|
@@ -1,31 +1,30 @@
|
|
|
1
|
-
|
|
2
1
|
#pragma once
|
|
3
2
|
|
|
3
|
+
#include <atomic>
|
|
4
|
+
#include <functional>
|
|
4
5
|
#include <memory>
|
|
6
|
+
#include <mutex>
|
|
5
7
|
#include <string>
|
|
6
8
|
#include <unordered_map>
|
|
9
|
+
#include <utility>
|
|
7
10
|
#include <vector>
|
|
8
11
|
|
|
12
|
+
#include <jsi/jsi.h>
|
|
13
|
+
|
|
14
|
+
#include "RNSkCanvasProvider.h"
|
|
15
|
+
#include "RNSkGraphiteProducer.h"
|
|
16
|
+
#include "RNSkGraphiteTarget.h"
|
|
9
17
|
#include "RNSkPlatformContext.h"
|
|
10
18
|
#include "jsi/ViewProperty.h"
|
|
11
|
-
|
|
12
|
-
#include "api/JsiSkImage.h"
|
|
13
|
-
#include "api/JsiSkPoint.h"
|
|
14
|
-
#include "api/JsiSkRect.h"
|
|
19
|
+
#include "utils/RNSkLog.h"
|
|
15
20
|
|
|
16
21
|
#pragma clang diagnostic push
|
|
17
22
|
#pragma clang diagnostic ignored "-Wdocumentation"
|
|
18
23
|
|
|
19
24
|
#include "include/core/SkCanvas.h"
|
|
20
|
-
#include "include/core/
|
|
21
|
-
|
|
22
|
-
#
|
|
23
|
-
#include "RNDawnContext.h"
|
|
24
|
-
#include "RNDawnUtils.h"
|
|
25
|
-
#include "include/gpu/graphite/Recording.h"
|
|
26
|
-
#include "include/gpu/graphite/TextureInfo.h"
|
|
27
|
-
#include "include/gpu/graphite/dawn/DawnGraphiteTypes.h"
|
|
28
|
-
#endif
|
|
25
|
+
#include "include/core/SkColorSpace.h"
|
|
26
|
+
#include "include/core/SkImage.h"
|
|
27
|
+
#include "include/core/SkRect.h"
|
|
29
28
|
|
|
30
29
|
#pragma clang diagnostic pop
|
|
31
30
|
|
|
@@ -33,211 +32,108 @@ namespace RNSkia {
|
|
|
33
32
|
|
|
34
33
|
namespace jsi = facebook::jsi;
|
|
35
34
|
|
|
36
|
-
#if defined(SK_GRAPHITE)
|
|
37
35
|
/**
|
|
38
|
-
*
|
|
39
|
-
*
|
|
40
|
-
*
|
|
41
|
-
*
|
|
36
|
+
* The native side of a Skia view. Frames come from one of two producers: JS
|
|
37
|
+
* records them itself through the view's target
|
|
38
|
+
* (SkiaViewApi.makeGraphiteContext), or <Canvas> hands over a recorder (or a
|
|
39
|
+
* picture) that the render thread pool records for the view. Either way the
|
|
40
|
+
* recordings are queued on the target; the view presents them onto its canvas
|
|
41
|
+
* provider on the main thread, aligned with the platform's display link.
|
|
42
|
+
*
|
|
43
|
+
* Threading: the registry side (RNSkJsiViewApi) runs on the JS thread, except
|
|
44
|
+
* applyUpdates() which a Reanimated mapper calls on the UI runtime; snapshots
|
|
45
|
+
* replay on the calling thread. Presenting runs on the main thread.
|
|
42
46
|
*/
|
|
43
|
-
|
|
44
|
-
int width = 0;
|
|
45
|
-
int height = 0;
|
|
46
|
-
SkColorType colorType = kUnknown_SkColorType;
|
|
47
|
-
skgpu::graphite::TextureInfo textureInfo;
|
|
48
|
-
};
|
|
49
|
-
#endif
|
|
50
|
-
|
|
51
|
-
class RNSkCanvasProvider {
|
|
52
|
-
public:
|
|
53
|
-
explicit RNSkCanvasProvider(std::function<void()> requestRedraw)
|
|
54
|
-
: _requestRedraw(requestRedraw) {}
|
|
55
|
-
|
|
56
|
-
virtual ~RNSkCanvasProvider() = default;
|
|
57
|
-
|
|
58
|
-
#if defined(SK_GRAPHITE)
|
|
59
|
-
/**
|
|
60
|
-
Describes the current target texture. Safe to call from any thread;
|
|
61
|
-
returns false while there is no surface to describe.
|
|
62
|
-
*/
|
|
63
|
-
virtual bool getGraphiteTargetInfo(RNSkGraphiteTargetInfo *info) {
|
|
64
|
-
return false;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
/**
|
|
68
|
-
Replays the recordings, in order, onto the target texture and presents
|
|
69
|
-
it. Called on the thread that owns the surface.
|
|
70
|
-
*/
|
|
71
|
-
virtual bool presentRecordings(
|
|
72
|
-
const std::vector<skgpu::graphite::Recording *> &recordings) {
|
|
73
|
-
return false;
|
|
74
|
-
}
|
|
75
|
-
#endif
|
|
76
|
-
|
|
77
|
-
/**
|
|
78
|
-
Returns the scaled width of the view
|
|
79
|
-
*/
|
|
80
|
-
virtual int getWidth() = 0;
|
|
81
|
-
|
|
82
|
-
/**
|
|
83
|
-
Returns the scaled height of the view
|
|
84
|
-
*/
|
|
85
|
-
virtual int getHeight() = 0;
|
|
86
|
-
|
|
87
|
-
/**
|
|
88
|
-
Render to a canvas
|
|
89
|
-
*/
|
|
90
|
-
virtual bool renderToCanvas(const std::function<void(SkCanvas *)> &) = 0;
|
|
91
|
-
|
|
92
|
-
protected:
|
|
93
|
-
std::function<void()> _requestRedraw;
|
|
94
|
-
};
|
|
95
|
-
|
|
96
|
-
class RNSkRenderer {
|
|
97
|
-
public:
|
|
98
|
-
explicit RNSkRenderer(std::function<void()> requestRedraw)
|
|
99
|
-
: _requestRedraw(std::move(requestRedraw)), _showDebugOverlays(false) {}
|
|
100
|
-
|
|
101
|
-
virtual void
|
|
102
|
-
renderImmediate(std::shared_ptr<RNSkCanvasProvider> canvasProvider) = 0;
|
|
103
|
-
|
|
104
|
-
void setShowDebugOverlays(bool showDebugOverlays) {
|
|
105
|
-
_showDebugOverlays = showDebugOverlays;
|
|
106
|
-
}
|
|
107
|
-
bool getShowDebugOverlays() const { return _showDebugOverlays; }
|
|
108
|
-
|
|
109
|
-
protected:
|
|
110
|
-
std::function<void()> _requestRedraw;
|
|
111
|
-
bool _showDebugOverlays;
|
|
112
|
-
};
|
|
113
|
-
|
|
114
|
-
class RNSkOffscreenCanvasProvider : public RNSkCanvasProvider {
|
|
47
|
+
class RNSkView : public std::enable_shared_from_this<RNSkView> {
|
|
115
48
|
public:
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
std::
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
49
|
+
RNSkView(std::shared_ptr<RNSkPlatformContext> context,
|
|
50
|
+
std::shared_ptr<RNSkCanvasProvider> canvasProvider)
|
|
51
|
+
: _platformContext(std::move(context)),
|
|
52
|
+
_canvasProvider(std::move(canvasProvider)),
|
|
53
|
+
_producer(std::make_shared<RNSkGraphiteProducer>()) {
|
|
54
|
+
// A new surface or a new size: present again. The platform view owns
|
|
55
|
+
// the provider together with this view, and the destructor clears the
|
|
56
|
+
// callback, so a raw capture is safe.
|
|
57
|
+
_canvasProvider->setRequestRedraw([this]() { requestRedraw(); });
|
|
123
58
|
}
|
|
124
59
|
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
if (_surface == nullptr) {
|
|
132
|
-
return nullptr;
|
|
60
|
+
~RNSkView() {
|
|
61
|
+
_canvasProvider->setRequestRedraw(nullptr);
|
|
62
|
+
std::shared_ptr<RNSkGraphiteTarget> target;
|
|
63
|
+
{
|
|
64
|
+
std::lock_guard<std::mutex> lock(_mutex);
|
|
65
|
+
target = std::move(_target);
|
|
133
66
|
}
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
SkIRect b =
|
|
137
|
-
SkIRect::MakeXYWH(bounds->x() * _pd, bounds->y() * _pd,
|
|
138
|
-
bounds->width() * _pd, bounds->height() * _pd);
|
|
139
|
-
image = _surface->makeImageSnapshot(b);
|
|
140
|
-
} else {
|
|
141
|
-
image = _surface->makeImageSnapshot();
|
|
67
|
+
if (target) {
|
|
68
|
+
target->detach(_canvasProvider);
|
|
142
69
|
}
|
|
143
|
-
#if defined(SK_GRAPHITE)
|
|
144
|
-
// Only Graphite-backed surfaces have a recorder to snap/submit; a raster
|
|
145
|
-
// surface's snapshot is already a valid CPU image.
|
|
146
|
-
if (auto *recorder = _surface->recorder()) {
|
|
147
|
-
DawnContext::getInstance().submitRecording(recorder->snap().get());
|
|
148
|
-
}
|
|
149
|
-
return DawnContext::getInstance().MakeRasterImage(image);
|
|
150
|
-
#else
|
|
151
|
-
auto grContext = _context->getDirectContext();
|
|
152
|
-
return image->makeRasterImage(grContext);
|
|
153
|
-
#endif
|
|
154
70
|
}
|
|
155
71
|
|
|
156
|
-
|
|
157
|
-
Returns the scaled width of the view
|
|
158
|
-
*/
|
|
159
|
-
int getWidth() override { return _width; };
|
|
160
|
-
|
|
161
|
-
/**
|
|
162
|
-
Returns the scaled height of the view
|
|
163
|
-
*/
|
|
164
|
-
int getHeight() override { return _height; };
|
|
72
|
+
// Registry side ------------------------------------------------------------
|
|
165
73
|
|
|
166
74
|
/**
|
|
167
|
-
|
|
75
|
+
Binds the view to its id. The target recording for this id (created by
|
|
76
|
+
whichever side came first, see RNSkGraphiteTargetRegistry) is attached to
|
|
77
|
+
the view's surface, and frames recorded before the view existed are
|
|
78
|
+
presented now.
|
|
168
79
|
*/
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
80
|
+
void setNativeId(size_t nativeId) {
|
|
81
|
+
_nativeId = nativeId;
|
|
82
|
+
std::shared_ptr<RNSkGraphiteTarget> previous;
|
|
83
|
+
{
|
|
84
|
+
std::lock_guard<std::mutex> lock(_mutex);
|
|
85
|
+
if (_target && _targetId == nativeId) {
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
previous = std::move(_target);
|
|
89
|
+
_targetId = nativeId;
|
|
90
|
+
_target = RNSkGraphiteTargetRegistry::getInstance().getOrCreate(
|
|
91
|
+
nativeId, _platformContext);
|
|
172
92
|
}
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
};
|
|
176
|
-
|
|
177
|
-
#if defined(SK_GRAPHITE)
|
|
178
|
-
bool getGraphiteTargetInfo(RNSkGraphiteTargetInfo *info) override {
|
|
179
|
-
if (_surface == nullptr || _surface->recorder() == nullptr) {
|
|
180
|
-
return false;
|
|
93
|
+
if (previous) {
|
|
94
|
+
previous->detach(_canvasProvider);
|
|
181
95
|
}
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
auto
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
bool presentRecordings(
|
|
197
|
-
const std::vector<skgpu::graphite::Recording *> &recordings) override {
|
|
198
|
-
if (_surface == nullptr || _surface->recorder() == nullptr) {
|
|
199
|
-
return false;
|
|
96
|
+
std::weak_ptr<RNSkView> weakThis = weak_from_this();
|
|
97
|
+
auto context = _platformContext;
|
|
98
|
+
auto scheduleOnMainThread = [weakThis, context]() {
|
|
99
|
+
context->runOnMainThread([weakThis]() {
|
|
100
|
+
if (auto view = weakThis.lock()) {
|
|
101
|
+
view->scheduleFrame();
|
|
102
|
+
}
|
|
103
|
+
});
|
|
104
|
+
};
|
|
105
|
+
auto target = getTarget();
|
|
106
|
+
target->attach(_canvasProvider, scheduleOnMainThread);
|
|
107
|
+
_producer->setTarget(target);
|
|
108
|
+
if (target->hasQueued()) {
|
|
109
|
+
scheduleOnMainThread();
|
|
200
110
|
}
|
|
201
|
-
return DawnContext::getInstance().insertRecordings(recordings,
|
|
202
|
-
_surface.get());
|
|
203
111
|
}
|
|
204
|
-
#endif
|
|
205
112
|
|
|
206
|
-
|
|
207
|
-
int _width;
|
|
208
|
-
int _height;
|
|
209
|
-
float _pd = 1.0f;
|
|
210
|
-
sk_sp<SkSurface> _surface;
|
|
211
|
-
std::shared_ptr<RNSkPlatformContext> _context;
|
|
212
|
-
};
|
|
213
|
-
|
|
214
|
-
class RNSkView : public std::enable_shared_from_this<RNSkView> {
|
|
215
|
-
public:
|
|
216
|
-
/**
|
|
217
|
-
* Constructor
|
|
218
|
-
*/
|
|
219
|
-
RNSkView(std::shared_ptr<RNSkPlatformContext> context,
|
|
220
|
-
std::shared_ptr<RNSkCanvasProvider> canvasProvider,
|
|
221
|
-
std::shared_ptr<RNSkRenderer> renderer)
|
|
222
|
-
: _platformContext(context), _canvasProvider(canvasProvider),
|
|
223
|
-
_renderer(renderer) {}
|
|
224
|
-
|
|
225
|
-
/**
|
|
226
|
-
Destructor
|
|
227
|
-
*/
|
|
228
|
-
virtual ~RNSkView() {}
|
|
113
|
+
size_t getNativeId() { return _nativeId; }
|
|
229
114
|
|
|
230
|
-
|
|
231
|
-
|
|
115
|
+
/** Declarative content: the recorder of <Canvas>, or a picture. */
|
|
116
|
+
void setJsiProperties(
|
|
117
|
+
std::unordered_map<std::string, RNJsi::ViewProperty> &props) {
|
|
118
|
+
for (auto &prop : props) {
|
|
119
|
+
if (prop.first == "recorder") {
|
|
120
|
+
_producer->setRecorder(
|
|
121
|
+
prop.second.isRecorder() ? prop.second.getRecorder() : nullptr);
|
|
122
|
+
} else if (prop.first == "picture") {
|
|
123
|
+
_producer->setPicture(prop.second.isPicture() ? prop.second.getPicture()
|
|
124
|
+
: nullptr);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
}
|
|
232
128
|
|
|
233
129
|
/**
|
|
234
130
|
Reads the shared values on the calling runtime into the recording the
|
|
235
131
|
view owns and schedules a frame. Returns false when there is nothing to
|
|
236
132
|
update: no recording, or one other than recorderId (a stale mapper).
|
|
237
133
|
*/
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
return
|
|
134
|
+
bool applyUpdates(jsi::Runtime &runtime, double recorderId,
|
|
135
|
+
const jsi::Array &values) {
|
|
136
|
+
return _producer->applyUpdates(runtime, recorderId, values);
|
|
241
137
|
}
|
|
242
138
|
|
|
243
139
|
/**
|
|
@@ -246,91 +142,311 @@ public:
|
|
|
246
142
|
until it is finalized, so the resources go away here rather than with the
|
|
247
143
|
garbage collector.
|
|
248
144
|
*/
|
|
249
|
-
|
|
145
|
+
void releaseContent() { _producer->clear(); }
|
|
250
146
|
|
|
147
|
+
/** Schedules redraw() on the main thread, once. */
|
|
251
148
|
void requestRedraw() {
|
|
252
|
-
if (
|
|
253
|
-
|
|
254
|
-
// Capture a weak pointer to this
|
|
255
|
-
auto weakThis = std::weak_ptr<RNSkView>(shared_from_this());
|
|
256
|
-
|
|
257
|
-
_platformContext->runOnMainThread([weakThis]() {
|
|
258
|
-
// Try to lock the weak pointer
|
|
259
|
-
if (auto strongThis = weakThis.lock()) {
|
|
260
|
-
// Only proceed if the object still exists
|
|
261
|
-
if (strongThis->_renderer && strongThis->_redrawRequested) {
|
|
262
|
-
strongThis->_renderer->renderImmediate(strongThis->_canvasProvider);
|
|
263
|
-
strongThis->_redrawRequested = false;
|
|
264
|
-
}
|
|
265
|
-
}
|
|
266
|
-
});
|
|
149
|
+
if (_redrawRequested.exchange(true)) {
|
|
150
|
+
return;
|
|
267
151
|
}
|
|
152
|
+
std::weak_ptr<RNSkView> weakThis = weak_from_this();
|
|
153
|
+
_platformContext->runOnMainThread([weakThis]() {
|
|
154
|
+
if (auto view = weakThis.lock()) {
|
|
155
|
+
if (view->_redrawRequested) {
|
|
156
|
+
view->redraw();
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
});
|
|
268
160
|
}
|
|
269
161
|
|
|
162
|
+
/**
|
|
163
|
+
Main thread. Presents everything submitted since the last frame; with
|
|
164
|
+
nothing queued, presents the last frame again (a redraw after a resize or
|
|
165
|
+
on a new surface). Without a surface the queue is left alone: the surface
|
|
166
|
+
presents it when it appears.
|
|
167
|
+
*/
|
|
270
168
|
void redraw() {
|
|
271
|
-
_renderer->renderImmediate(_canvasProvider);
|
|
272
169
|
_redrawRequested = false;
|
|
170
|
+
RNSkGraphiteTargetInfo targetInfo;
|
|
171
|
+
if (!_canvasProvider->getTargetInfo(&targetInfo)) {
|
|
172
|
+
return;
|
|
173
|
+
}
|
|
174
|
+
// Declarative content is recorded again for the surface as it is now.
|
|
175
|
+
const bool frameComing = _producer->requestFrame();
|
|
176
|
+
auto target = getTarget();
|
|
177
|
+
std::shared_ptr<RNSkGraphiteRecording> lastPresented;
|
|
178
|
+
{
|
|
179
|
+
std::lock_guard<std::mutex> lock(_mutex);
|
|
180
|
+
lastPresented = _lastPresented;
|
|
181
|
+
}
|
|
182
|
+
std::vector<std::shared_ptr<RNSkGraphiteRecording>> recordings;
|
|
183
|
+
if (target) {
|
|
184
|
+
recordings = target->takeQueued();
|
|
185
|
+
}
|
|
186
|
+
if (recordings.empty()) {
|
|
187
|
+
// With a frame on its way, the layer keeps showing the last one until
|
|
188
|
+
// it lands: presenting it again would only cost a second present.
|
|
189
|
+
// Otherwise the last frame is presented again, also onto a surface of
|
|
190
|
+
// another size (the view was resized and nothing records for it): the
|
|
191
|
+
// frame then shows at its own size rather than nothing at all.
|
|
192
|
+
if (frameComing || lastPresented == nullptr) {
|
|
193
|
+
return;
|
|
194
|
+
}
|
|
195
|
+
if (present(_canvasProvider, targetInfo, {lastPresented},
|
|
196
|
+
/* remember= */ true)) {
|
|
197
|
+
_producer->onFramePresented();
|
|
198
|
+
}
|
|
199
|
+
return;
|
|
200
|
+
}
|
|
201
|
+
if (present(_canvasProvider, targetInfo, recordings,
|
|
202
|
+
/* remember= */ true)) {
|
|
203
|
+
_producer->onFramePresented();
|
|
204
|
+
} else if (target) {
|
|
205
|
+
target->requeue(recordings);
|
|
206
|
+
}
|
|
273
207
|
}
|
|
274
208
|
|
|
275
209
|
/**
|
|
276
|
-
|
|
210
|
+
Renders the view into an offscreen surface: declarative content is
|
|
211
|
+
replayed on the calling thread with the latest values, so the snapshot
|
|
212
|
+
does not wait for a frame; otherwise the current frame is replayed. A
|
|
213
|
+
snapshot is in sRGB whichever color space the view renders in: a frame
|
|
214
|
+
recorded in Display P3 is replayed into a surface in that color space and
|
|
215
|
+
the image is converted.
|
|
277
216
|
*/
|
|
278
|
-
|
|
217
|
+
sk_sp<SkImage> makeImageSnapshot(SkRect *bounds) {
|
|
218
|
+
if (_producer->hasContent()) {
|
|
219
|
+
auto provider = std::make_shared<RNSkOffscreenCanvasProvider>(
|
|
220
|
+
_platformContext, getScaledWidth(), getScaledHeight());
|
|
221
|
+
if (auto *canvas = provider->getCanvas()) {
|
|
222
|
+
_producer->renderInto(canvas, _platformContext->getPixelDensity());
|
|
223
|
+
}
|
|
224
|
+
return provider->makeSnapshot(bounds);
|
|
225
|
+
}
|
|
226
|
+
auto frame = getLastFrame();
|
|
227
|
+
const bool useP3ColorSpace =
|
|
228
|
+
frame != nullptr && frame->getTarget().useP3ColorSpace;
|
|
229
|
+
auto provider = std::make_shared<RNSkOffscreenCanvasProvider>(
|
|
230
|
+
_platformContext, getScaledWidth(), getScaledHeight(), useP3ColorSpace);
|
|
231
|
+
if (frame != nullptr) {
|
|
232
|
+
renderFrame(provider, frame);
|
|
233
|
+
}
|
|
234
|
+
auto image = provider->makeSnapshot(bounds);
|
|
235
|
+
if (image != nullptr && useP3ColorSpace) {
|
|
236
|
+
// A raster image: converted on the CPU, no recorder involved.
|
|
237
|
+
image = image->makeColorSpace(nullptr, SkColorSpace::MakeSRGB(), {});
|
|
238
|
+
}
|
|
239
|
+
return image;
|
|
240
|
+
}
|
|
279
241
|
|
|
280
|
-
/**
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
242
|
+
/** Width of the surface, in pixels. */
|
|
243
|
+
int getScaledWidth() { return _canvasProvider->getWidth(); }
|
|
244
|
+
|
|
245
|
+
/** Height of the surface, in pixels. */
|
|
246
|
+
int getScaledHeight() { return _canvasProvider->getHeight(); }
|
|
247
|
+
|
|
248
|
+
// Platform view side -------------------------------------------------------
|
|
284
249
|
|
|
285
250
|
/**
|
|
286
|
-
|
|
251
|
+
Installed by the platform view: arms its display link. Main thread. Without
|
|
252
|
+
one, frames are presented as soon as the main thread gets to them.
|
|
287
253
|
*/
|
|
288
|
-
void
|
|
289
|
-
|
|
290
|
-
|
|
254
|
+
void setFrameScheduler(std::function<void()> scheduler) {
|
|
255
|
+
_frameScheduler = std::move(scheduler);
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
/** Main thread: a recording is waiting. */
|
|
259
|
+
void scheduleFrame() {
|
|
260
|
+
if (_frameScheduler) {
|
|
261
|
+
_frameScheduler();
|
|
262
|
+
} else {
|
|
263
|
+
redraw();
|
|
264
|
+
}
|
|
291
265
|
}
|
|
292
266
|
|
|
293
267
|
/**
|
|
294
|
-
|
|
268
|
+
Display link tick: presents the queued recordings. Returns whether more
|
|
269
|
+
are waiting, so that the caller keeps its display link armed: also when the
|
|
270
|
+
present failed (the app is in the background), so that the recordings are
|
|
271
|
+
tried again on the next frame rather than left waiting for a redraw.
|
|
272
|
+
Without a surface the queue is left alone: the surface presents it when
|
|
273
|
+
it appears.
|
|
295
274
|
*/
|
|
296
|
-
|
|
275
|
+
bool presentFrame() {
|
|
276
|
+
auto target = getTarget();
|
|
277
|
+
if (target == nullptr) {
|
|
278
|
+
return false;
|
|
279
|
+
}
|
|
280
|
+
RNSkGraphiteTargetInfo targetInfo;
|
|
281
|
+
if (!_canvasProvider->getTargetInfo(&targetInfo)) {
|
|
282
|
+
return false;
|
|
283
|
+
}
|
|
284
|
+
auto recordings = target->takeQueued();
|
|
285
|
+
if (recordings.empty()) {
|
|
286
|
+
return false;
|
|
287
|
+
}
|
|
288
|
+
if (!present(_canvasProvider, targetInfo, recordings,
|
|
289
|
+
/* remember= */ true)) {
|
|
290
|
+
target->requeue(recordings);
|
|
291
|
+
return true;
|
|
292
|
+
}
|
|
293
|
+
_producer->onFramePresented();
|
|
294
|
+
return target->hasQueued();
|
|
295
|
+
}
|
|
297
296
|
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
297
|
+
bool hasQueuedRecordings() {
|
|
298
|
+
auto target = getTarget();
|
|
299
|
+
return target && target->hasQueued();
|
|
300
|
+
}
|
|
301
301
|
|
|
302
|
-
|
|
303
|
-
return
|
|
302
|
+
std::shared_ptr<RNSkCanvasProvider> getCanvasProvider() {
|
|
303
|
+
return _canvasProvider;
|
|
304
304
|
}
|
|
305
305
|
|
|
306
|
-
std::shared_ptr<
|
|
306
|
+
std::shared_ptr<RNSkPlatformContext> getPlatformContext() {
|
|
307
|
+
return _platformContext;
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
private:
|
|
311
|
+
std::shared_ptr<RNSkGraphiteTarget> getTarget() {
|
|
312
|
+
std::lock_guard<std::mutex> lock(_mutex);
|
|
313
|
+
return _target;
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
/** The frame on screen, or the one about to be, if any. Any thread. */
|
|
317
|
+
std::shared_ptr<RNSkGraphiteRecording> getLastFrame() {
|
|
318
|
+
std::shared_ptr<RNSkGraphiteTarget> target;
|
|
319
|
+
std::shared_ptr<RNSkGraphiteRecording> recording;
|
|
320
|
+
{
|
|
321
|
+
std::lock_guard<std::mutex> lock(_mutex);
|
|
322
|
+
target = _target;
|
|
323
|
+
recording = _lastPresented;
|
|
324
|
+
}
|
|
325
|
+
if (target) {
|
|
326
|
+
if (auto latest = target->peekLatest()) {
|
|
327
|
+
recording = latest;
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
return recording;
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
/** Replays a frame onto another provider (a snapshot surface). Any thread. */
|
|
334
|
+
bool renderFrame(const std::shared_ptr<RNSkCanvasProvider> &provider,
|
|
335
|
+
const std::shared_ptr<RNSkGraphiteRecording> &recording) {
|
|
336
|
+
RNSkGraphiteTargetInfo targetInfo;
|
|
337
|
+
if (!provider->getTargetInfo(&targetInfo)) {
|
|
338
|
+
return false;
|
|
339
|
+
}
|
|
340
|
+
return present(provider, targetInfo, {recording}, /* remember= */ false);
|
|
341
|
+
}
|
|
307
342
|
|
|
308
343
|
/**
|
|
309
|
-
|
|
344
|
+
Replays the recordings onto the provider's target, in order, and remembers
|
|
345
|
+
the last one for the next redraw when asked to (not for a snapshot).
|
|
346
|
+
Returns false when the provider could not present (no surface, app in the
|
|
347
|
+
background), in which case the caller keeps the recordings.
|
|
310
348
|
*/
|
|
311
|
-
|
|
349
|
+
bool
|
|
350
|
+
present(const std::shared_ptr<RNSkCanvasProvider> &provider,
|
|
351
|
+
const RNSkGraphiteTargetInfo &targetInfo,
|
|
352
|
+
const std::vector<std::shared_ptr<RNSkGraphiteRecording>> &recordings,
|
|
353
|
+
bool remember) {
|
|
354
|
+
// Recordings of the target's size and color space are replayed straight
|
|
355
|
+
// onto it, as one batch; any other goes through a texture of its own.
|
|
356
|
+
std::vector<skgpu::graphite::Recording *> batch;
|
|
357
|
+
std::shared_ptr<RNSkGraphiteRecording> last;
|
|
358
|
+
bool success = true;
|
|
359
|
+
auto flush = [&]() {
|
|
360
|
+
if (!batch.empty()) {
|
|
361
|
+
success = provider->presentRecordings(batch) && success;
|
|
362
|
+
batch.clear();
|
|
363
|
+
}
|
|
364
|
+
};
|
|
365
|
+
for (const auto &recording : recordings) {
|
|
366
|
+
// A recording made for another format (recorded before the surface
|
|
367
|
+
// existed, with a bit depth the surface did not get) cannot be
|
|
368
|
+
// replayed onto this one.
|
|
369
|
+
if (!recording->hasFormatOf(targetInfo)) {
|
|
370
|
+
RNSkLogger::logToConsole("SkiaView: skipping a recording made for a "
|
|
371
|
+
"different surface format");
|
|
372
|
+
continue;
|
|
373
|
+
}
|
|
374
|
+
if (recording->hasSizeOf(targetInfo) &&
|
|
375
|
+
recording->hasColorSpaceOf(targetInfo)) {
|
|
376
|
+
batch.push_back(recording->get());
|
|
377
|
+
last = recording;
|
|
378
|
+
continue;
|
|
379
|
+
}
|
|
380
|
+
flush();
|
|
381
|
+
if (presentThroughTexture(provider, recording)) {
|
|
382
|
+
last = recording;
|
|
383
|
+
} else {
|
|
384
|
+
success = false;
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
flush();
|
|
388
|
+
if (last == nullptr) {
|
|
389
|
+
// Nothing presentable: the recordings are consumed, not kept.
|
|
390
|
+
return true;
|
|
391
|
+
}
|
|
392
|
+
if (success && remember) {
|
|
393
|
+
std::lock_guard<std::mutex> lock(_mutex);
|
|
394
|
+
_lastPresented = last;
|
|
395
|
+
}
|
|
396
|
+
return success;
|
|
397
|
+
}
|
|
312
398
|
|
|
313
399
|
/**
|
|
314
|
-
|
|
400
|
+
Presents a recording made for another size than the target's: the size
|
|
401
|
+
JS measured before the surface existed can be a pixel off (the platform
|
|
402
|
+
rounds the layout to pixels on its own terms), and the view may have been
|
|
403
|
+
resized since. The recording is replayed into a texture of its own size
|
|
404
|
+
and that texture is drawn onto the target, so the frame shows rather than
|
|
405
|
+
being dropped; the copy only happens while the sizes differ. The same goes
|
|
406
|
+
for a recording made in another color space than the target's: the
|
|
407
|
+
texture is in the color space of the recording, and drawing it converts
|
|
408
|
+
the colors.
|
|
315
409
|
*/
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
410
|
+
bool presentThroughTexture(
|
|
411
|
+
const std::shared_ptr<RNSkCanvasProvider> &provider,
|
|
412
|
+
const std::shared_ptr<RNSkGraphiteRecording> &recording) {
|
|
413
|
+
const auto &size = recording->getTarget();
|
|
414
|
+
auto intermediate = std::make_shared<RNSkOffscreenCanvasProvider>(
|
|
415
|
+
_platformContext, size.width, size.height, size.useP3ColorSpace);
|
|
416
|
+
RNSkGraphiteTargetInfo info;
|
|
417
|
+
if (!intermediate->getTargetInfo(&info) ||
|
|
418
|
+
!recording->isCompatibleWith(info)) {
|
|
419
|
+
// No texture of that size and format: the frame is consumed.
|
|
420
|
+
RNSkLogger::logToConsole("SkiaView: skipping a %dx%d recording, the "
|
|
421
|
+
"surface is %dx%d",
|
|
422
|
+
size.width, size.height, provider->getWidth(),
|
|
423
|
+
provider->getHeight());
|
|
424
|
+
return true;
|
|
425
|
+
}
|
|
426
|
+
if (!intermediate->presentRecordings({recording->get()})) {
|
|
427
|
+
return false;
|
|
428
|
+
}
|
|
429
|
+
auto image = intermediate->makeImage();
|
|
430
|
+
if (image == nullptr) {
|
|
431
|
+
return false;
|
|
432
|
+
}
|
|
433
|
+
return provider->presentImage(image);
|
|
324
434
|
}
|
|
325
435
|
|
|
326
|
-
private:
|
|
327
436
|
std::shared_ptr<RNSkPlatformContext> _platformContext;
|
|
328
437
|
std::shared_ptr<RNSkCanvasProvider> _canvasProvider;
|
|
329
|
-
std::shared_ptr<
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
438
|
+
std::shared_ptr<RNSkGraphiteProducer> _producer;
|
|
439
|
+
size_t _nativeId = 0;
|
|
440
|
+
std::function<void()> _frameScheduler;
|
|
333
441
|
std::atomic<bool> _redrawRequested = {false};
|
|
442
|
+
|
|
443
|
+
// The target is bound on the JS thread and read on the main thread and by
|
|
444
|
+
// snapshots; the last presented frame is written by the main thread and
|
|
445
|
+
// read by snapshots.
|
|
446
|
+
std::mutex _mutex;
|
|
447
|
+
std::shared_ptr<RNSkGraphiteTarget> _target;
|
|
448
|
+
size_t _targetId = 0;
|
|
449
|
+
std::shared_ptr<RNSkGraphiteRecording> _lastPresented;
|
|
334
450
|
};
|
|
335
451
|
|
|
336
452
|
} // namespace RNSkia
|