react-native-skia 3.0.0 → 3.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Package.swift +14 -13
- package/android/CMakeLists.txt +13 -42
- package/android/build.gradle +55 -47
- package/android/cpp/jni/JniLoad.cpp +2 -4
- package/android/cpp/jni/include/JniSkiaView.h +123 -0
- package/android/cpp/rnskia-android/{RNSkOpenGLCanvasProvider.cpp → RNSkAndroidCanvasProvider.cpp} +45 -100
- package/android/cpp/rnskia-android/{RNSkOpenGLCanvasProvider.h → RNSkAndroidCanvasProvider.h} +24 -22
- package/android/cpp/rnskia-android/RNSkAndroidPlatformContext.h +0 -83
- package/android/cpp/rnskia-android/RNSkAndroidVideo.cpp +0 -8
- package/android/src/main/java/com/reactnative/skia/RNSkiaPackage.java +1 -2
- package/android/src/main/java/com/reactnative/skia/SkiaSurfaceView.java +1 -3
- package/android/src/main/java/com/reactnative/skia/SkiaTextureView.java +1 -17
- package/android/src/main/java/com/reactnative/skia/{SkiaBaseView.java → SkiaView.java} +78 -16
- package/android/src/main/java/com/reactnative/skia/SkiaViewManager.java +85 -0
- package/apple/MetalLayerColorSpace.mm +0 -4
- package/apple/RNSkApplePlatformContext.h +0 -14
- package/apple/RNSkApplePlatformContext.mm +2 -112
- package/apple/RNSkMetalCanvasProvider.h +14 -19
- package/apple/RNSkMetalCanvasProvider.mm +35 -68
- package/apple/SkiaView.h +20 -0
- package/apple/SkiaView.mm +210 -0
- package/cpp/api/JsiSkApi.h +2 -13
- package/cpp/api/JsiSkCanvas.h +4 -18
- package/cpp/api/JsiSkGraphiteContext.h +1 -5
- package/cpp/api/JsiSkGraphiteRecording.h +1 -5
- package/cpp/api/JsiSkImage.h +7 -41
- package/cpp/api/JsiSkImageFactory.h +0 -14
- package/cpp/api/JsiSkSurface.h +2 -16
- package/cpp/api/JsiSkSurfaceFactory.h +0 -8
- package/cpp/rnskia/RNDawnContext.h +6 -0
- package/cpp/rnskia/RNDawnInterop.cpp +0 -4
- package/cpp/rnskia/RNDawnUtils.h +0 -1
- package/cpp/rnskia/RNDawnWindowContext.cpp +10 -0
- package/cpp/rnskia/RNDawnWindowContext.h +4 -0
- package/cpp/rnskia/RNSkCanvasProvider.h +221 -0
- package/cpp/rnskia/RNSkGraphiteProducer.cpp +36 -14
- package/cpp/rnskia/RNSkGraphiteProducer.h +23 -8
- package/cpp/rnskia/RNSkGraphiteTarget.h +383 -0
- package/cpp/rnskia/RNSkJsiViewApi.h +9 -18
- package/cpp/rnskia/RNSkPlatformContext.h +9 -15
- package/cpp/rnskia/RNSkView.h +340 -245
- package/jestSetup.js +1 -3
- package/lib/commonjs/Platform/Platform.web.js +1 -1
- package/lib/commonjs/Platform/Platform.web.js.map +1 -1
- package/lib/commonjs/index.d.ts +1 -3
- package/lib/commonjs/index.js +3 -12
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/mock/index.js +0 -1
- package/lib/commonjs/mock/index.js.map +1 -1
- package/lib/commonjs/renderer/Canvas.d.ts +15 -12
- package/lib/commonjs/renderer/Canvas.js +24 -20
- package/lib/commonjs/renderer/Canvas.js.map +1 -1
- package/lib/commonjs/skia/types/Graphite.d.ts +3 -3
- package/lib/commonjs/skia/types/Graphite.js.map +1 -1
- package/lib/commonjs/skia/types/Image/ImageFactory.d.ts +2 -2
- package/lib/commonjs/skia/types/Image/ImageFactory.js.map +1 -1
- package/lib/commonjs/skia/types/Skia.d.ts +1 -2
- package/lib/commonjs/skia/types/Skia.js.map +1 -1
- package/lib/commonjs/skia/types/Surface/SurfaceFactory.d.ts +1 -1
- package/lib/commonjs/skia/types/Surface/SurfaceFactory.js.map +1 -1
- package/lib/commonjs/specs/NativeSkiaModule.web.d.ts +5 -4
- package/lib/commonjs/specs/NativeSkiaModule.web.js +5 -9
- package/lib/commonjs/specs/NativeSkiaModule.web.js.map +1 -1
- package/lib/{typescript/src/specs/SkiaPictureViewNativeComponent.d.ts → commonjs/specs/SkiaViewNativeComponent.d.ts} +0 -3
- package/lib/commonjs/specs/{SkiaPictureViewNativeComponent.js → SkiaViewNativeComponent.js} +2 -2
- package/lib/commonjs/specs/SkiaViewNativeComponent.js.map +1 -0
- package/lib/commonjs/specs/SkiaViewNativeComponent.web.d.ts +10 -0
- package/lib/commonjs/specs/SkiaViewNativeComponent.web.js +27 -0
- package/lib/commonjs/specs/SkiaViewNativeComponent.web.js.map +1 -0
- package/lib/commonjs/views/SkiaGraphiteView.d.ts +3 -4
- package/lib/commonjs/views/SkiaGraphiteView.js +23 -12
- package/lib/commonjs/views/SkiaGraphiteView.js.map +1 -1
- package/lib/commonjs/views/SkiaPictureView.d.ts +4 -1
- package/lib/commonjs/views/SkiaPictureView.js +12 -10
- package/lib/commonjs/views/SkiaPictureView.js.map +1 -1
- package/lib/commonjs/views/SkiaView.web.d.ts +12 -0
- package/lib/commonjs/views/{SkiaGraphiteView.web.js → SkiaView.web.js} +82 -38
- package/lib/commonjs/views/SkiaView.web.js.map +1 -0
- package/lib/commonjs/views/SkiaWebRenderer.js +1 -1
- package/lib/commonjs/views/SkiaWebRenderer.js.map +1 -1
- package/lib/commonjs/views/android.d.ts +6 -0
- package/lib/commonjs/views/android.js +17 -0
- package/lib/commonjs/views/android.js.map +1 -0
- package/lib/commonjs/views/types.d.ts +3 -12
- package/lib/commonjs/views/types.js.map +1 -1
- package/lib/module/Platform/Platform.web.js +1 -1
- package/lib/module/Platform/Platform.web.js.map +1 -1
- package/lib/module/index.d.ts +1 -3
- package/lib/module/index.js +1 -3
- package/lib/module/index.js.map +1 -1
- package/lib/module/mock/index.js +0 -1
- package/lib/module/mock/index.js.map +1 -1
- package/lib/module/renderer/Canvas.d.ts +15 -12
- package/lib/module/renderer/Canvas.js +24 -19
- package/lib/module/renderer/Canvas.js.map +1 -1
- package/lib/module/skia/types/Graphite.d.ts +3 -3
- package/lib/module/skia/types/Graphite.js.map +1 -1
- package/lib/module/skia/types/Image/ImageFactory.d.ts +2 -2
- package/lib/module/skia/types/Image/ImageFactory.js.map +1 -1
- package/lib/module/skia/types/Skia.d.ts +1 -2
- package/lib/module/skia/types/Skia.js.map +1 -1
- package/lib/module/skia/types/Surface/SurfaceFactory.d.ts +1 -1
- package/lib/module/skia/types/Surface/SurfaceFactory.js.map +1 -1
- package/lib/module/specs/NativeSkiaModule.web.d.ts +5 -4
- package/lib/module/specs/NativeSkiaModule.web.js +5 -9
- package/lib/module/specs/NativeSkiaModule.web.js.map +1 -1
- package/lib/{commonjs/specs/SkiaPictureViewNativeComponent.d.ts → module/specs/SkiaViewNativeComponent.d.ts} +0 -3
- package/lib/module/specs/{SkiaPictureViewNativeComponent.js → SkiaViewNativeComponent.js} +2 -2
- package/lib/module/specs/SkiaViewNativeComponent.js.map +1 -0
- package/lib/module/specs/SkiaViewNativeComponent.web.d.ts +10 -0
- package/lib/module/specs/SkiaViewNativeComponent.web.js +21 -0
- package/lib/module/specs/SkiaViewNativeComponent.web.js.map +1 -0
- package/lib/module/views/SkiaGraphiteView.d.ts +3 -4
- package/lib/module/views/SkiaGraphiteView.js +23 -12
- package/lib/module/views/SkiaGraphiteView.js.map +1 -1
- package/lib/module/views/SkiaPictureView.d.ts +4 -1
- package/lib/module/views/SkiaPictureView.js +12 -10
- package/lib/module/views/SkiaPictureView.js.map +1 -1
- package/lib/module/views/SkiaView.web.d.ts +12 -0
- package/lib/module/views/{SkiaGraphiteView.web.js → SkiaView.web.js} +80 -36
- package/lib/module/views/SkiaView.web.js.map +1 -0
- package/lib/module/views/SkiaWebRenderer.js +1 -1
- package/lib/module/views/SkiaWebRenderer.js.map +1 -1
- package/lib/module/views/android.d.ts +6 -0
- package/lib/module/views/android.js +10 -0
- package/lib/module/views/android.js.map +1 -0
- package/lib/module/views/types.d.ts +3 -12
- package/lib/module/views/types.js.map +1 -1
- package/lib/typescript/src/index.d.ts +1 -3
- package/lib/typescript/src/renderer/Canvas.d.ts +15 -12
- package/lib/typescript/src/skia/types/Graphite.d.ts +3 -3
- package/lib/typescript/src/skia/types/Image/ImageFactory.d.ts +2 -2
- package/lib/typescript/src/skia/types/Skia.d.ts +1 -2
- package/lib/typescript/src/skia/types/Surface/SurfaceFactory.d.ts +1 -1
- package/lib/typescript/src/specs/NativeSkiaModule.web.d.ts +5 -4
- package/lib/{module/specs/SkiaPictureViewNativeComponent.d.ts → typescript/src/specs/SkiaViewNativeComponent.d.ts} +0 -3
- package/lib/typescript/src/specs/SkiaViewNativeComponent.web.d.ts +10 -0
- package/lib/typescript/src/views/SkiaGraphiteView.d.ts +3 -4
- package/lib/typescript/src/views/SkiaPictureView.d.ts +4 -1
- package/lib/typescript/src/views/SkiaView.web.d.ts +12 -0
- package/lib/typescript/src/views/android.d.ts +6 -0
- package/lib/typescript/src/views/types.d.ts +3 -12
- package/package.json +8 -16
- package/react-native-skia.podspec +50 -57
- package/src/Platform/Platform.web.tsx +1 -1
- package/src/index.ts +1 -3
- package/src/mock/index.ts +0 -1
- package/src/renderer/Canvas.tsx +23 -27
- package/src/skia/types/Graphite.ts +3 -3
- package/src/skia/types/Image/ImageFactory.ts +2 -2
- package/src/skia/types/Skia.ts +1 -2
- package/src/skia/types/Surface/SurfaceFactory.ts +1 -1
- package/src/specs/NativeSkiaModule.web.ts +9 -21
- package/src/specs/{SkiaPictureViewNativeComponent.ts → SkiaViewNativeComponent.ts} +1 -4
- package/src/specs/{SkiaPictureViewNativeComponent.web.ts → SkiaViewNativeComponent.web.ts} +8 -10
- package/src/views/SkiaGraphiteView.tsx +27 -16
- package/src/views/SkiaPictureView.tsx +11 -10
- package/src/views/{SkiaGraphiteView.web.tsx → SkiaView.web.tsx} +100 -53
- package/src/views/SkiaWebRenderer.ts +1 -1
- package/src/views/android.ts +16 -0
- package/src/views/types.ts +3 -14
- package/android/cpp/jni/include/JniSkiaBaseView.h +0 -92
- package/android/cpp/jni/include/JniSkiaGraphiteView.h +0 -176
- package/android/cpp/jni/include/JniSkiaPictureView.h +0 -172
- package/android/cpp/rnskia-android/GrAHardwareBufferUtils.cpp +0 -245
- package/android/cpp/rnskia-android/GrAHardwareBufferUtils.h +0 -33
- package/android/cpp/rnskia-android/OpenGLContext.h +0 -248
- package/android/cpp/rnskia-android/OpenGLWindowContext.cpp +0 -67
- package/android/cpp/rnskia-android/OpenGLWindowContext.h +0 -75
- package/android/cpp/rnskia-android/RNSkAndroidView.h +0 -67
- package/android/cpp/rnskia-android/gl/Context.h +0 -80
- package/android/cpp/rnskia-android/gl/Display.h +0 -123
- package/android/cpp/rnskia-android/gl/Error.cpp +0 -45
- package/android/cpp/rnskia-android/gl/Error.h +0 -8
- package/android/cpp/rnskia-android/gl/Surface.h +0 -43
- package/android/src/main/java/com/reactnative/skia/SkiaBaseViewManager.java +0 -65
- package/android/src/main/java/com/reactnative/skia/SkiaGraphiteView.java +0 -78
- package/android/src/main/java/com/reactnative/skia/SkiaGraphiteViewManager.java +0 -32
- package/android/src/main/java/com/reactnative/skia/SkiaPictureView.java +0 -105
- package/android/src/main/java/com/reactnative/skia/SkiaPictureViewManager.java +0 -44
- package/apple/MetalContext.h +0 -116
- package/apple/MetalContext.mm +0 -38
- package/apple/MetalWindowContext.h +0 -42
- package/apple/MetalWindowContext.mm +0 -95
- package/apple/RNSkAppleView.h +0 -49
- package/apple/RNSkAppleView.mm +0 -35
- package/apple/SkiaCVPixelBufferUtils.h +0 -122
- package/apple/SkiaCVPixelBufferUtils.mm +0 -535
- package/apple/SkiaGraphiteView.h +0 -26
- package/apple/SkiaGraphiteView.mm +0 -180
- package/apple/SkiaPictureView.h +0 -7
- package/apple/SkiaPictureView.mm +0 -70
- package/apple/SkiaUIView.h +0 -31
- package/apple/SkiaUIView.mm +0 -164
- package/cpp/rnskia/RNSkGraphiteView.h +0 -708
- package/cpp/rnskia/RNSkPictureView.cpp +0 -69
- package/cpp/rnskia/RNSkPictureView.h +0 -211
- package/cpp/skia/src/gpu/ganesh/gl/GrGLDefines.h +0 -1162
- package/lib/commonjs/renderer/DefaultCanvas.d.ts +0 -8
- package/lib/commonjs/renderer/DefaultCanvas.js +0 -42
- package/lib/commonjs/renderer/DefaultCanvas.js.map +0 -1
- package/lib/commonjs/renderer/GraphiteCanvas.d.ts +0 -22
- package/lib/commonjs/renderer/GraphiteCanvas.js +0 -64
- package/lib/commonjs/renderer/GraphiteCanvas.js.map +0 -1
- package/lib/commonjs/renderer/GraphiteCanvas.web.d.ts +0 -1
- package/lib/commonjs/renderer/GraphiteCanvas.web.js +0 -13
- package/lib/commonjs/renderer/GraphiteCanvas.web.js.map +0 -1
- package/lib/commonjs/specs/SkiaGraphiteViewNativeComponent.d.ts +0 -10
- package/lib/commonjs/specs/SkiaGraphiteViewNativeComponent.js +0 -12
- package/lib/commonjs/specs/SkiaGraphiteViewNativeComponent.js.map +0 -1
- package/lib/commonjs/specs/SkiaGraphiteViewNativeComponent.web.d.ts +0 -9
- package/lib/commonjs/specs/SkiaGraphiteViewNativeComponent.web.js +0 -28
- package/lib/commonjs/specs/SkiaGraphiteViewNativeComponent.web.js.map +0 -1
- package/lib/commonjs/specs/SkiaPictureViewNativeComponent.js.map +0 -1
- package/lib/commonjs/specs/SkiaPictureViewNativeComponent.web.d.ts +0 -10
- package/lib/commonjs/specs/SkiaPictureViewNativeComponent.web.js +0 -29
- package/lib/commonjs/specs/SkiaPictureViewNativeComponent.web.js.map +0 -1
- package/lib/commonjs/views/SkiaGraphiteView.web.d.ts +0 -14
- package/lib/commonjs/views/SkiaGraphiteView.web.js.map +0 -1
- package/lib/commonjs/views/SkiaPictureView.web.d.ts +0 -11
- package/lib/commonjs/views/SkiaPictureView.web.js +0 -165
- package/lib/commonjs/views/SkiaPictureView.web.js.map +0 -1
- package/lib/module/renderer/DefaultCanvas.d.ts +0 -8
- package/lib/module/renderer/DefaultCanvas.js +0 -34
- package/lib/module/renderer/DefaultCanvas.js.map +0 -1
- package/lib/module/renderer/GraphiteCanvas.d.ts +0 -22
- package/lib/module/renderer/GraphiteCanvas.js +0 -57
- package/lib/module/renderer/GraphiteCanvas.js.map +0 -1
- package/lib/module/renderer/GraphiteCanvas.web.d.ts +0 -1
- package/lib/module/renderer/GraphiteCanvas.web.js +0 -4
- package/lib/module/renderer/GraphiteCanvas.web.js.map +0 -1
- package/lib/module/specs/SkiaGraphiteViewNativeComponent.d.ts +0 -10
- package/lib/module/specs/SkiaGraphiteViewNativeComponent.js +0 -8
- package/lib/module/specs/SkiaGraphiteViewNativeComponent.js.map +0 -1
- package/lib/module/specs/SkiaGraphiteViewNativeComponent.web.d.ts +0 -9
- package/lib/module/specs/SkiaGraphiteViewNativeComponent.web.js +0 -22
- package/lib/module/specs/SkiaGraphiteViewNativeComponent.web.js.map +0 -1
- package/lib/module/specs/SkiaPictureViewNativeComponent.js.map +0 -1
- package/lib/module/specs/SkiaPictureViewNativeComponent.web.d.ts +0 -10
- package/lib/module/specs/SkiaPictureViewNativeComponent.web.js +0 -23
- package/lib/module/specs/SkiaPictureViewNativeComponent.web.js.map +0 -1
- package/lib/module/views/SkiaGraphiteView.web.d.ts +0 -14
- package/lib/module/views/SkiaGraphiteView.web.js.map +0 -1
- package/lib/module/views/SkiaPictureView.web.d.ts +0 -11
- package/lib/module/views/SkiaPictureView.web.js +0 -156
- package/lib/module/views/SkiaPictureView.web.js.map +0 -1
- package/lib/typescript/src/renderer/DefaultCanvas.d.ts +0 -8
- package/lib/typescript/src/renderer/GraphiteCanvas.d.ts +0 -22
- package/lib/typescript/src/renderer/GraphiteCanvas.web.d.ts +0 -1
- package/lib/typescript/src/specs/SkiaGraphiteViewNativeComponent.d.ts +0 -10
- package/lib/typescript/src/specs/SkiaGraphiteViewNativeComponent.web.d.ts +0 -9
- package/lib/typescript/src/specs/SkiaPictureViewNativeComponent.web.d.ts +0 -10
- package/lib/typescript/src/views/SkiaGraphiteView.web.d.ts +0 -14
- package/lib/typescript/src/views/SkiaPictureView.web.d.ts +0 -11
- package/libs/.graphite +0 -1
- package/src/renderer/DefaultCanvas.tsx +0 -41
- package/src/renderer/GraphiteCanvas.tsx +0 -61
- package/src/renderer/GraphiteCanvas.web.tsx +0 -3
- package/src/specs/SkiaGraphiteViewNativeComponent.ts +0 -17
- package/src/specs/SkiaGraphiteViewNativeComponent.web.ts +0 -31
- package/src/views/SkiaPictureView.web.tsx +0 -224
package/cpp/rnskia/RNSkView.h
CHANGED
|
@@ -1,31 +1,29 @@
|
|
|
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
|
-
#if defined(SK_GRAPHITE)
|
|
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/SkImage.h"
|
|
26
|
+
#include "include/core/SkRect.h"
|
|
29
27
|
|
|
30
28
|
#pragma clang diagnostic pop
|
|
31
29
|
|
|
@@ -33,211 +31,108 @@ namespace RNSkia {
|
|
|
33
31
|
|
|
34
32
|
namespace jsi = facebook::jsi;
|
|
35
33
|
|
|
36
|
-
#if defined(SK_GRAPHITE)
|
|
37
34
|
/**
|
|
38
|
-
*
|
|
39
|
-
*
|
|
40
|
-
*
|
|
41
|
-
*
|
|
35
|
+
* The native side of a Skia view. Frames come from one of two producers: JS
|
|
36
|
+
* records them itself through the view's target
|
|
37
|
+
* (SkiaViewApi.makeGraphiteContext), or <Canvas> hands over a recorder (or a
|
|
38
|
+
* picture) that the render thread pool records for the view. Either way the
|
|
39
|
+
* recordings are queued on the target; the view presents them onto its canvas
|
|
40
|
+
* provider on the main thread, aligned with the platform's display link.
|
|
41
|
+
*
|
|
42
|
+
* Threading: the registry side (RNSkJsiViewApi) runs on the JS thread, except
|
|
43
|
+
* applyUpdates() which a Reanimated mapper calls on the UI runtime; snapshots
|
|
44
|
+
* replay on the calling thread. Presenting runs on the main thread.
|
|
42
45
|
*/
|
|
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 {
|
|
46
|
+
class RNSkView : public std::enable_shared_from_this<RNSkView> {
|
|
115
47
|
public:
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
std::
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
48
|
+
RNSkView(std::shared_ptr<RNSkPlatformContext> context,
|
|
49
|
+
std::shared_ptr<RNSkCanvasProvider> canvasProvider)
|
|
50
|
+
: _platformContext(std::move(context)),
|
|
51
|
+
_canvasProvider(std::move(canvasProvider)),
|
|
52
|
+
_producer(std::make_shared<RNSkGraphiteProducer>()) {
|
|
53
|
+
// A new surface or a new size: present again. The platform view owns
|
|
54
|
+
// the provider together with this view, and the destructor clears the
|
|
55
|
+
// callback, so a raw capture is safe.
|
|
56
|
+
_canvasProvider->setRequestRedraw([this]() { requestRedraw(); });
|
|
123
57
|
}
|
|
124
58
|
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
if (_surface == nullptr) {
|
|
132
|
-
return nullptr;
|
|
59
|
+
~RNSkView() {
|
|
60
|
+
_canvasProvider->setRequestRedraw(nullptr);
|
|
61
|
+
std::shared_ptr<RNSkGraphiteTarget> target;
|
|
62
|
+
{
|
|
63
|
+
std::lock_guard<std::mutex> lock(_mutex);
|
|
64
|
+
target = std::move(_target);
|
|
133
65
|
}
|
|
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();
|
|
66
|
+
if (target) {
|
|
67
|
+
target->detach(_canvasProvider);
|
|
142
68
|
}
|
|
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
69
|
}
|
|
155
70
|
|
|
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; };
|
|
71
|
+
// Registry side ------------------------------------------------------------
|
|
165
72
|
|
|
166
73
|
/**
|
|
167
|
-
|
|
74
|
+
Binds the view to its id. The target recording for this id (created by
|
|
75
|
+
whichever side came first, see RNSkGraphiteTargetRegistry) is attached to
|
|
76
|
+
the view's surface, and frames recorded before the view existed are
|
|
77
|
+
presented now.
|
|
168
78
|
*/
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
79
|
+
void setNativeId(size_t nativeId) {
|
|
80
|
+
_nativeId = nativeId;
|
|
81
|
+
std::shared_ptr<RNSkGraphiteTarget> previous;
|
|
82
|
+
{
|
|
83
|
+
std::lock_guard<std::mutex> lock(_mutex);
|
|
84
|
+
if (_target && _targetId == nativeId) {
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
previous = std::move(_target);
|
|
88
|
+
_targetId = nativeId;
|
|
89
|
+
_target = RNSkGraphiteTargetRegistry::getInstance().getOrCreate(
|
|
90
|
+
nativeId, _platformContext);
|
|
172
91
|
}
|
|
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;
|
|
92
|
+
if (previous) {
|
|
93
|
+
previous->detach(_canvasProvider);
|
|
181
94
|
}
|
|
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;
|
|
95
|
+
std::weak_ptr<RNSkView> weakThis = weak_from_this();
|
|
96
|
+
auto context = _platformContext;
|
|
97
|
+
auto scheduleOnMainThread = [weakThis, context]() {
|
|
98
|
+
context->runOnMainThread([weakThis]() {
|
|
99
|
+
if (auto view = weakThis.lock()) {
|
|
100
|
+
view->scheduleFrame();
|
|
101
|
+
}
|
|
102
|
+
});
|
|
103
|
+
};
|
|
104
|
+
auto target = getTarget();
|
|
105
|
+
target->attach(_canvasProvider, scheduleOnMainThread);
|
|
106
|
+
_producer->setTarget(target);
|
|
107
|
+
if (target->hasQueued()) {
|
|
108
|
+
scheduleOnMainThread();
|
|
200
109
|
}
|
|
201
|
-
return DawnContext::getInstance().insertRecordings(recordings,
|
|
202
|
-
_surface.get());
|
|
203
110
|
}
|
|
204
|
-
#endif
|
|
205
|
-
|
|
206
|
-
private:
|
|
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
111
|
|
|
225
|
-
|
|
226
|
-
Destructor
|
|
227
|
-
*/
|
|
228
|
-
virtual ~RNSkView() {}
|
|
112
|
+
size_t getNativeId() { return _nativeId; }
|
|
229
113
|
|
|
230
|
-
|
|
231
|
-
|
|
114
|
+
/** Declarative content: the recorder of <Canvas>, or a picture. */
|
|
115
|
+
void setJsiProperties(
|
|
116
|
+
std::unordered_map<std::string, RNJsi::ViewProperty> &props) {
|
|
117
|
+
for (auto &prop : props) {
|
|
118
|
+
if (prop.first == "recorder") {
|
|
119
|
+
_producer->setRecorder(
|
|
120
|
+
prop.second.isRecorder() ? prop.second.getRecorder() : nullptr);
|
|
121
|
+
} else if (prop.first == "picture") {
|
|
122
|
+
_producer->setPicture(prop.second.isPicture() ? prop.second.getPicture()
|
|
123
|
+
: nullptr);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
}
|
|
232
127
|
|
|
233
128
|
/**
|
|
234
129
|
Reads the shared values on the calling runtime into the recording the
|
|
235
130
|
view owns and schedules a frame. Returns false when there is nothing to
|
|
236
131
|
update: no recording, or one other than recorderId (a stale mapper).
|
|
237
132
|
*/
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
return
|
|
133
|
+
bool applyUpdates(jsi::Runtime &runtime, double recorderId,
|
|
134
|
+
const jsi::Array &values) {
|
|
135
|
+
return _producer->applyUpdates(runtime, recorderId, values);
|
|
241
136
|
}
|
|
242
137
|
|
|
243
138
|
/**
|
|
@@ -246,91 +141,291 @@ public:
|
|
|
246
141
|
until it is finalized, so the resources go away here rather than with the
|
|
247
142
|
garbage collector.
|
|
248
143
|
*/
|
|
249
|
-
|
|
144
|
+
void releaseContent() { _producer->clear(); }
|
|
250
145
|
|
|
146
|
+
/** Schedules redraw() on the main thread, once. */
|
|
251
147
|
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
|
-
});
|
|
148
|
+
if (_redrawRequested.exchange(true)) {
|
|
149
|
+
return;
|
|
267
150
|
}
|
|
151
|
+
std::weak_ptr<RNSkView> weakThis = weak_from_this();
|
|
152
|
+
_platformContext->runOnMainThread([weakThis]() {
|
|
153
|
+
if (auto view = weakThis.lock()) {
|
|
154
|
+
if (view->_redrawRequested) {
|
|
155
|
+
view->redraw();
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
});
|
|
268
159
|
}
|
|
269
160
|
|
|
161
|
+
/**
|
|
162
|
+
Main thread. Presents everything submitted since the last frame; with
|
|
163
|
+
nothing queued, presents the last frame again (a redraw after a resize or
|
|
164
|
+
on a new surface). Without a surface the queue is left alone: the surface
|
|
165
|
+
presents it when it appears.
|
|
166
|
+
*/
|
|
270
167
|
void redraw() {
|
|
271
|
-
_renderer->renderImmediate(_canvasProvider);
|
|
272
168
|
_redrawRequested = false;
|
|
169
|
+
RNSkGraphiteTargetInfo targetInfo;
|
|
170
|
+
if (!_canvasProvider->getTargetInfo(&targetInfo)) {
|
|
171
|
+
return;
|
|
172
|
+
}
|
|
173
|
+
// Declarative content is recorded again for the surface as it is now.
|
|
174
|
+
const bool frameComing = _producer->requestFrame();
|
|
175
|
+
auto target = getTarget();
|
|
176
|
+
std::shared_ptr<RNSkGraphiteRecording> lastPresented;
|
|
177
|
+
{
|
|
178
|
+
std::lock_guard<std::mutex> lock(_mutex);
|
|
179
|
+
lastPresented = _lastPresented;
|
|
180
|
+
}
|
|
181
|
+
std::vector<std::shared_ptr<RNSkGraphiteRecording>> recordings;
|
|
182
|
+
if (target) {
|
|
183
|
+
recordings = target->takeQueued();
|
|
184
|
+
}
|
|
185
|
+
if (recordings.empty()) {
|
|
186
|
+
// With a frame on its way, the layer keeps showing the last one until
|
|
187
|
+
// it lands: presenting it again would only cost a second present.
|
|
188
|
+
// Otherwise the last frame is presented again, also onto a surface of
|
|
189
|
+
// another size (the view was resized and nothing records for it): the
|
|
190
|
+
// frame then shows at its own size rather than nothing at all.
|
|
191
|
+
if (frameComing || lastPresented == nullptr) {
|
|
192
|
+
return;
|
|
193
|
+
}
|
|
194
|
+
if (present(_canvasProvider, targetInfo, {lastPresented},
|
|
195
|
+
/* remember= */ true)) {
|
|
196
|
+
_producer->onFramePresented();
|
|
197
|
+
}
|
|
198
|
+
return;
|
|
199
|
+
}
|
|
200
|
+
if (present(_canvasProvider, targetInfo, recordings,
|
|
201
|
+
/* remember= */ true)) {
|
|
202
|
+
_producer->onFramePresented();
|
|
203
|
+
} else if (target) {
|
|
204
|
+
target->requeue(recordings);
|
|
205
|
+
}
|
|
273
206
|
}
|
|
274
207
|
|
|
275
208
|
/**
|
|
276
|
-
|
|
209
|
+
Renders the view into an offscreen surface: declarative content is
|
|
210
|
+
replayed on the calling thread with the latest values, so the snapshot
|
|
211
|
+
does not wait for a frame; otherwise the current frame is replayed.
|
|
277
212
|
*/
|
|
278
|
-
|
|
213
|
+
sk_sp<SkImage> makeImageSnapshot(SkRect *bounds) {
|
|
214
|
+
auto provider = std::make_shared<RNSkOffscreenCanvasProvider>(
|
|
215
|
+
_platformContext, getScaledWidth(), getScaledHeight());
|
|
216
|
+
if (_producer->hasContent()) {
|
|
217
|
+
if (auto *canvas = provider->getCanvas()) {
|
|
218
|
+
_producer->renderInto(canvas, _platformContext->getPixelDensity());
|
|
219
|
+
}
|
|
220
|
+
} else {
|
|
221
|
+
renderLastFrame(provider);
|
|
222
|
+
}
|
|
223
|
+
return provider->makeSnapshot(bounds);
|
|
224
|
+
}
|
|
279
225
|
|
|
280
|
-
/**
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
226
|
+
/** Width of the surface, in pixels. */
|
|
227
|
+
int getScaledWidth() { return _canvasProvider->getWidth(); }
|
|
228
|
+
|
|
229
|
+
/** Height of the surface, in pixels. */
|
|
230
|
+
int getScaledHeight() { return _canvasProvider->getHeight(); }
|
|
231
|
+
|
|
232
|
+
// Platform view side -------------------------------------------------------
|
|
284
233
|
|
|
285
234
|
/**
|
|
286
|
-
|
|
235
|
+
Installed by the platform view: arms its display link. Main thread. Without
|
|
236
|
+
one, frames are presented as soon as the main thread gets to them.
|
|
287
237
|
*/
|
|
288
|
-
void
|
|
289
|
-
|
|
290
|
-
|
|
238
|
+
void setFrameScheduler(std::function<void()> scheduler) {
|
|
239
|
+
_frameScheduler = std::move(scheduler);
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
/** Main thread: a recording is waiting. */
|
|
243
|
+
void scheduleFrame() {
|
|
244
|
+
if (_frameScheduler) {
|
|
245
|
+
_frameScheduler();
|
|
246
|
+
} else {
|
|
247
|
+
redraw();
|
|
248
|
+
}
|
|
291
249
|
}
|
|
292
250
|
|
|
293
251
|
/**
|
|
294
|
-
|
|
252
|
+
Display link tick: presents the queued recordings. Returns whether more
|
|
253
|
+
are waiting, so that the caller keeps its display link armed: also when the
|
|
254
|
+
present failed (the app is in the background), so that the recordings are
|
|
255
|
+
tried again on the next frame rather than left waiting for a redraw.
|
|
256
|
+
Without a surface the queue is left alone: the surface presents it when
|
|
257
|
+
it appears.
|
|
295
258
|
*/
|
|
296
|
-
|
|
259
|
+
bool presentFrame() {
|
|
260
|
+
auto target = getTarget();
|
|
261
|
+
if (target == nullptr) {
|
|
262
|
+
return false;
|
|
263
|
+
}
|
|
264
|
+
RNSkGraphiteTargetInfo targetInfo;
|
|
265
|
+
if (!_canvasProvider->getTargetInfo(&targetInfo)) {
|
|
266
|
+
return false;
|
|
267
|
+
}
|
|
268
|
+
auto recordings = target->takeQueued();
|
|
269
|
+
if (recordings.empty()) {
|
|
270
|
+
return false;
|
|
271
|
+
}
|
|
272
|
+
if (!present(_canvasProvider, targetInfo, recordings,
|
|
273
|
+
/* remember= */ true)) {
|
|
274
|
+
target->requeue(recordings);
|
|
275
|
+
return true;
|
|
276
|
+
}
|
|
277
|
+
_producer->onFramePresented();
|
|
278
|
+
return target->hasQueued();
|
|
279
|
+
}
|
|
297
280
|
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
281
|
+
bool hasQueuedRecordings() {
|
|
282
|
+
auto target = getTarget();
|
|
283
|
+
return target && target->hasQueued();
|
|
284
|
+
}
|
|
301
285
|
|
|
302
|
-
|
|
303
|
-
return
|
|
286
|
+
std::shared_ptr<RNSkCanvasProvider> getCanvasProvider() {
|
|
287
|
+
return _canvasProvider;
|
|
304
288
|
}
|
|
305
289
|
|
|
306
|
-
std::shared_ptr<
|
|
290
|
+
std::shared_ptr<RNSkPlatformContext> getPlatformContext() {
|
|
291
|
+
return _platformContext;
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
private:
|
|
295
|
+
std::shared_ptr<RNSkGraphiteTarget> getTarget() {
|
|
296
|
+
std::lock_guard<std::mutex> lock(_mutex);
|
|
297
|
+
return _target;
|
|
298
|
+
}
|
|
307
299
|
|
|
308
300
|
/**
|
|
309
|
-
|
|
301
|
+
Replays the frame on screen, or the one about to be, onto another
|
|
302
|
+
provider (a snapshot surface). Any thread.
|
|
310
303
|
*/
|
|
311
|
-
|
|
304
|
+
bool renderLastFrame(const std::shared_ptr<RNSkCanvasProvider> &provider) {
|
|
305
|
+
std::shared_ptr<RNSkGraphiteTarget> target;
|
|
306
|
+
std::shared_ptr<RNSkGraphiteRecording> recording;
|
|
307
|
+
{
|
|
308
|
+
std::lock_guard<std::mutex> lock(_mutex);
|
|
309
|
+
target = _target;
|
|
310
|
+
recording = _lastPresented;
|
|
311
|
+
}
|
|
312
|
+
if (target) {
|
|
313
|
+
if (auto latest = target->peekLatest()) {
|
|
314
|
+
recording = latest;
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
if (recording == nullptr) {
|
|
318
|
+
return false;
|
|
319
|
+
}
|
|
320
|
+
RNSkGraphiteTargetInfo targetInfo;
|
|
321
|
+
if (!provider->getTargetInfo(&targetInfo)) {
|
|
322
|
+
return false;
|
|
323
|
+
}
|
|
324
|
+
return present(provider, targetInfo, {recording}, /* remember= */ false);
|
|
325
|
+
}
|
|
312
326
|
|
|
313
327
|
/**
|
|
314
|
-
|
|
328
|
+
Replays the recordings onto the provider's target, in order, and remembers
|
|
329
|
+
the last one for the next redraw when asked to (not for a snapshot).
|
|
330
|
+
Returns false when the provider could not present (no surface, app in the
|
|
331
|
+
background), in which case the caller keeps the recordings.
|
|
315
332
|
*/
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
333
|
+
bool
|
|
334
|
+
present(const std::shared_ptr<RNSkCanvasProvider> &provider,
|
|
335
|
+
const RNSkGraphiteTargetInfo &targetInfo,
|
|
336
|
+
const std::vector<std::shared_ptr<RNSkGraphiteRecording>> &recordings,
|
|
337
|
+
bool remember) {
|
|
338
|
+
// Recordings of the target's size are replayed straight onto it, as one
|
|
339
|
+
// batch; one of another size goes through a texture of its own size.
|
|
340
|
+
std::vector<skgpu::graphite::Recording *> batch;
|
|
341
|
+
std::shared_ptr<RNSkGraphiteRecording> last;
|
|
342
|
+
bool success = true;
|
|
343
|
+
auto flush = [&]() {
|
|
344
|
+
if (!batch.empty()) {
|
|
345
|
+
success = provider->presentRecordings(batch) && success;
|
|
346
|
+
batch.clear();
|
|
347
|
+
}
|
|
348
|
+
};
|
|
349
|
+
for (const auto &recording : recordings) {
|
|
350
|
+
// A recording made for another format (recorded before the surface
|
|
351
|
+
// existed, with a bit depth the surface did not get) cannot be
|
|
352
|
+
// replayed onto this one.
|
|
353
|
+
if (!recording->hasFormatOf(targetInfo)) {
|
|
354
|
+
RNSkLogger::logToConsole("SkiaView: skipping a recording made for a "
|
|
355
|
+
"different surface format");
|
|
356
|
+
continue;
|
|
357
|
+
}
|
|
358
|
+
if (recording->hasSizeOf(targetInfo)) {
|
|
359
|
+
batch.push_back(recording->get());
|
|
360
|
+
last = recording;
|
|
361
|
+
continue;
|
|
362
|
+
}
|
|
363
|
+
flush();
|
|
364
|
+
if (presentResized(provider, recording)) {
|
|
365
|
+
last = recording;
|
|
366
|
+
} else {
|
|
367
|
+
success = false;
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
flush();
|
|
371
|
+
if (last == nullptr) {
|
|
372
|
+
// Nothing presentable: the recordings are consumed, not kept.
|
|
373
|
+
return true;
|
|
374
|
+
}
|
|
375
|
+
if (success && remember) {
|
|
376
|
+
std::lock_guard<std::mutex> lock(_mutex);
|
|
377
|
+
_lastPresented = last;
|
|
378
|
+
}
|
|
379
|
+
return success;
|
|
321
380
|
}
|
|
322
|
-
|
|
323
|
-
|
|
381
|
+
|
|
382
|
+
/**
|
|
383
|
+
Presents a recording made for another size than the target's: the size
|
|
384
|
+
JS measured before the surface existed can be a pixel off (the platform
|
|
385
|
+
rounds the layout to pixels on its own terms), and the view may have been
|
|
386
|
+
resized since. The recording is replayed into a texture of its own size
|
|
387
|
+
and that texture is drawn onto the target, so the frame shows rather than
|
|
388
|
+
being dropped; the copy only happens while the sizes differ.
|
|
389
|
+
*/
|
|
390
|
+
bool presentResized(const std::shared_ptr<RNSkCanvasProvider> &provider,
|
|
391
|
+
const std::shared_ptr<RNSkGraphiteRecording> &recording) {
|
|
392
|
+
const auto &size = recording->getTarget();
|
|
393
|
+
auto intermediate = std::make_shared<RNSkOffscreenCanvasProvider>(
|
|
394
|
+
_platformContext, size.width, size.height);
|
|
395
|
+
RNSkGraphiteTargetInfo info;
|
|
396
|
+
if (!intermediate->getTargetInfo(&info) ||
|
|
397
|
+
!recording->isCompatibleWith(info)) {
|
|
398
|
+
// No texture of that size and format: the frame is consumed.
|
|
399
|
+
RNSkLogger::logToConsole("SkiaView: skipping a %dx%d recording, the "
|
|
400
|
+
"surface is %dx%d",
|
|
401
|
+
size.width, size.height, provider->getWidth(),
|
|
402
|
+
provider->getHeight());
|
|
403
|
+
return true;
|
|
404
|
+
}
|
|
405
|
+
if (!intermediate->presentRecordings({recording->get()})) {
|
|
406
|
+
return false;
|
|
407
|
+
}
|
|
408
|
+
auto image = intermediate->makeImage();
|
|
409
|
+
if (image == nullptr) {
|
|
410
|
+
return false;
|
|
411
|
+
}
|
|
412
|
+
return provider->presentImage(image);
|
|
324
413
|
}
|
|
325
414
|
|
|
326
|
-
private:
|
|
327
415
|
std::shared_ptr<RNSkPlatformContext> _platformContext;
|
|
328
416
|
std::shared_ptr<RNSkCanvasProvider> _canvasProvider;
|
|
329
|
-
std::shared_ptr<
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
417
|
+
std::shared_ptr<RNSkGraphiteProducer> _producer;
|
|
418
|
+
size_t _nativeId = 0;
|
|
419
|
+
std::function<void()> _frameScheduler;
|
|
333
420
|
std::atomic<bool> _redrawRequested = {false};
|
|
421
|
+
|
|
422
|
+
// The target is bound on the JS thread and read on the main thread and by
|
|
423
|
+
// snapshots; the last presented frame is written by the main thread and
|
|
424
|
+
// read by snapshots.
|
|
425
|
+
std::mutex _mutex;
|
|
426
|
+
std::shared_ptr<RNSkGraphiteTarget> _target;
|
|
427
|
+
size_t _targetId = 0;
|
|
428
|
+
std::shared_ptr<RNSkGraphiteRecording> _lastPresented;
|
|
334
429
|
};
|
|
335
430
|
|
|
336
431
|
} // namespace RNSkia
|
package/jestSetup.js
CHANGED