react-native-skia 3.0.1 → 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 +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 +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/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 +5 -13
- package/react-native-skia.podspec +34 -58
- 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,383 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
|
|
3
|
+
#include <cmath>
|
|
4
|
+
#include <deque>
|
|
5
|
+
#include <functional>
|
|
6
|
+
#include <memory>
|
|
7
|
+
#include <mutex>
|
|
8
|
+
#include <stdexcept>
|
|
9
|
+
#include <unordered_map>
|
|
10
|
+
#include <utility>
|
|
11
|
+
#include <vector>
|
|
12
|
+
|
|
13
|
+
#include "RNDawnContext.h"
|
|
14
|
+
#include "RNDawnUtils.h"
|
|
15
|
+
#include "RNSkCanvasProvider.h"
|
|
16
|
+
#include "RNSkPlatformContext.h"
|
|
17
|
+
|
|
18
|
+
#pragma clang diagnostic push
|
|
19
|
+
#pragma clang diagnostic ignored "-Wdocumentation"
|
|
20
|
+
|
|
21
|
+
#include "include/core/SkCanvas.h"
|
|
22
|
+
#include "include/core/SkColorSpace.h"
|
|
23
|
+
#include "include/core/SkImageInfo.h"
|
|
24
|
+
#include "include/gpu/graphite/Recorder.h"
|
|
25
|
+
#include "include/gpu/graphite/Recording.h"
|
|
26
|
+
#include "include/gpu/graphite/TextureInfo.h"
|
|
27
|
+
#include "include/gpu/graphite/dawn/DawnGraphiteTypes.h"
|
|
28
|
+
|
|
29
|
+
#pragma clang diagnostic pop
|
|
30
|
+
|
|
31
|
+
namespace RNSkia {
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* The Graphite recorder of one view. Shared by the view's target and by every
|
|
35
|
+
* recording snapped from it, so that the recorder outlives its recordings
|
|
36
|
+
* whichever of them is released last.
|
|
37
|
+
*/
|
|
38
|
+
struct RNSkGraphiteRecorder {
|
|
39
|
+
std::unique_ptr<skgpu::graphite::Recorder> recorder;
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* A frame snapped from a view's recorder, with the description of the target
|
|
44
|
+
* it was recorded for. Immutable once snapped: it can be replayed any number
|
|
45
|
+
* of times, from any thread.
|
|
46
|
+
*/
|
|
47
|
+
class RNSkGraphiteRecording {
|
|
48
|
+
public:
|
|
49
|
+
RNSkGraphiteRecording(std::shared_ptr<RNSkGraphiteRecorder> recorder,
|
|
50
|
+
std::unique_ptr<skgpu::graphite::Recording> recording,
|
|
51
|
+
const RNSkGraphiteTargetInfo &target)
|
|
52
|
+
: _recorder(std::move(recorder)), _recording(std::move(recording)),
|
|
53
|
+
_target(target) {}
|
|
54
|
+
|
|
55
|
+
skgpu::graphite::Recording *get() const { return _recording.get(); }
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
Whether the recording was made for a texture of the given size. A deferred
|
|
59
|
+
canvas records against fixed dimensions: Graphite sizes the passes (and
|
|
60
|
+
their depth and stencil attachments) from them, so replaying it onto a
|
|
61
|
+
texture of another size is rejected by Dawn and draws nothing. A recording
|
|
62
|
+
of another size is replayed through a texture of its own size instead (see
|
|
63
|
+
RNSkView::present).
|
|
64
|
+
*/
|
|
65
|
+
bool hasSizeOf(const RNSkGraphiteTargetInfo &target) const {
|
|
66
|
+
return _target.width == target.width && _target.height == target.height;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/** The target the recording was made for. */
|
|
70
|
+
const RNSkGraphiteTargetInfo &getTarget() const { return _target; }
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
Whether the recording has the format of the given target, and the target
|
|
74
|
+
supports every usage the recording relies on.
|
|
75
|
+
*/
|
|
76
|
+
bool hasFormatOf(const RNSkGraphiteTargetInfo &target) const {
|
|
77
|
+
return _target.colorType == target.colorType &&
|
|
78
|
+
_target.textureInfo.canBeFulfilledBy(target.textureInfo);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/** Whether the recording can be replayed straight onto the given target. */
|
|
82
|
+
bool isCompatibleWith(const RNSkGraphiteTargetInfo &target) const {
|
|
83
|
+
return hasSizeOf(target) && hasFormatOf(target);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
private:
|
|
87
|
+
// Declared before the recording so that the recording is released first.
|
|
88
|
+
std::shared_ptr<RNSkGraphiteRecorder> _recorder;
|
|
89
|
+
std::unique_ptr<skgpu::graphite::Recording> _recording;
|
|
90
|
+
RNSkGraphiteTargetInfo _target;
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* What a view and the producers recording for it share: the view's recorder,
|
|
95
|
+
* the queue of recordings waiting to be presented and the description of the
|
|
96
|
+
* target texture. Created by whichever side comes first (see
|
|
97
|
+
* RNSkGraphiteTargetRegistry) and kept alive by both.
|
|
98
|
+
*
|
|
99
|
+
* Recording happens on the producer's thread (the JS thread, a worklet
|
|
100
|
+
* runtime or the render thread pool), presenting on the main thread; the
|
|
101
|
+
* queue is the hand-off. A recorder serves one thread at a time, which is
|
|
102
|
+
* enforced by allowing a single open recording.
|
|
103
|
+
*/
|
|
104
|
+
class RNSkGraphiteTarget {
|
|
105
|
+
public:
|
|
106
|
+
explicit RNSkGraphiteTarget(std::shared_ptr<RNSkPlatformContext> context)
|
|
107
|
+
: _context(std::move(context)) {}
|
|
108
|
+
|
|
109
|
+
// Producer side ------------------------------------------------------------
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
The layout size (points) and the props the format follows from, as known
|
|
113
|
+
to JS. Used until the view has a surface of its own.
|
|
114
|
+
*/
|
|
115
|
+
void setLayout(float width, float height, bool opaque, bool highBitDepth) {
|
|
116
|
+
std::lock_guard<std::mutex> lock(_stateMutex);
|
|
117
|
+
_layoutWidth = width;
|
|
118
|
+
_layoutHeight = height;
|
|
119
|
+
_opaque = opaque;
|
|
120
|
+
_highBitDepth = highBitDepth;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/** Current width of the target, in points. */
|
|
124
|
+
float getWidth() {
|
|
125
|
+
return resolveTargetInfo().width / _context->getPixelDensity();
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/** Current height of the target, in points. */
|
|
129
|
+
float getHeight() {
|
|
130
|
+
return resolveTargetInfo().height / _context->getPixelDensity();
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
Returns a canvas that records the next frame, in points. The canvas is
|
|
135
|
+
deleted by finishRecording(). Throws while a recording is already open.
|
|
136
|
+
*/
|
|
137
|
+
SkCanvas *beginRecording() {
|
|
138
|
+
auto target = resolveTargetInfo();
|
|
139
|
+
std::lock_guard<std::mutex> lock(_stateMutex);
|
|
140
|
+
if (_recording) {
|
|
141
|
+
throw std::runtime_error("SkiaGraphiteView: a recording is already open, "
|
|
142
|
+
"call finishRecording() first.");
|
|
143
|
+
}
|
|
144
|
+
if (target.width <= 0 || target.height <= 0) {
|
|
145
|
+
throw std::runtime_error("SkiaGraphiteView: the view has no size yet.");
|
|
146
|
+
}
|
|
147
|
+
if (_recorder == nullptr) {
|
|
148
|
+
auto recorder = std::make_shared<RNSkGraphiteRecorder>();
|
|
149
|
+
recorder->recorder = DawnContext::getInstance().makeRecorder();
|
|
150
|
+
if (recorder->recorder == nullptr) {
|
|
151
|
+
throw std::runtime_error(
|
|
152
|
+
"SkiaGraphiteView: could not create a Graphite recorder.");
|
|
153
|
+
}
|
|
154
|
+
_recorder = std::move(recorder);
|
|
155
|
+
}
|
|
156
|
+
auto imageInfo =
|
|
157
|
+
SkImageInfo::Make(target.width, target.height, target.colorType,
|
|
158
|
+
kPremul_SkAlphaType, SkColorSpace::MakeSRGB());
|
|
159
|
+
auto *canvas =
|
|
160
|
+
_recorder->recorder->makeDeferredCanvas(imageInfo, target.textureInfo);
|
|
161
|
+
if (canvas == nullptr) {
|
|
162
|
+
throw std::runtime_error(
|
|
163
|
+
"SkiaGraphiteView: could not create a deferred canvas.");
|
|
164
|
+
}
|
|
165
|
+
// The canvas loads whatever the target holds: the producer clears.
|
|
166
|
+
auto pd = _context->getPixelDensity();
|
|
167
|
+
canvas->scale(pd, pd);
|
|
168
|
+
_recording = true;
|
|
169
|
+
_recordingTarget = target;
|
|
170
|
+
return canvas;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
/** Snaps the open recording. Throws when no recording is open. */
|
|
174
|
+
std::shared_ptr<RNSkGraphiteRecording> finishRecording() {
|
|
175
|
+
std::lock_guard<std::mutex> lock(_stateMutex);
|
|
176
|
+
if (!_recording) {
|
|
177
|
+
throw std::runtime_error("SkiaGraphiteView: no recording is open, call "
|
|
178
|
+
"beginRecording() first.");
|
|
179
|
+
}
|
|
180
|
+
_recording = false;
|
|
181
|
+
auto recording = _recorder->recorder->snap();
|
|
182
|
+
if (recording == nullptr) {
|
|
183
|
+
throw std::runtime_error(
|
|
184
|
+
"SkiaGraphiteView: snapping the recording failed.");
|
|
185
|
+
}
|
|
186
|
+
return std::make_shared<RNSkGraphiteRecording>(
|
|
187
|
+
_recorder, std::move(recording), _recordingTarget);
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
/**
|
|
191
|
+
Queues a recording for the next frame. Recordings are never dropped: a
|
|
192
|
+
later frame may depend on resources an earlier one uploaded.
|
|
193
|
+
*/
|
|
194
|
+
void submit(std::shared_ptr<RNSkGraphiteRecording> recording) {
|
|
195
|
+
std::function<void()> requestFrame;
|
|
196
|
+
{
|
|
197
|
+
std::lock_guard<std::mutex> lock(_queueMutex);
|
|
198
|
+
_queue.push_back(std::move(recording));
|
|
199
|
+
requestFrame = _requestFrame;
|
|
200
|
+
}
|
|
201
|
+
if (requestFrame) {
|
|
202
|
+
requestFrame();
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
// View side ----------------------------------------------------------------
|
|
207
|
+
|
|
208
|
+
/**
|
|
209
|
+
Binds the target to the view's surface: the provider describes the target
|
|
210
|
+
texture, requestFrame asks the view to present the queue.
|
|
211
|
+
*/
|
|
212
|
+
void attach(std::weak_ptr<RNSkCanvasProvider> provider,
|
|
213
|
+
std::function<void()> requestFrame) {
|
|
214
|
+
{
|
|
215
|
+
std::lock_guard<std::mutex> lock(_stateMutex);
|
|
216
|
+
_provider = std::move(provider);
|
|
217
|
+
}
|
|
218
|
+
std::lock_guard<std::mutex> lock(_queueMutex);
|
|
219
|
+
_requestFrame = std::move(requestFrame);
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
/**
|
|
223
|
+
Undoes attach(), for the view owning the given provider only. Native view
|
|
224
|
+
ids are reused across reloads and an Android view is only destroyed when
|
|
225
|
+
its Java object is finalized, so a view going away may find its target
|
|
226
|
+
already bound to its successor; that binding is left alone.
|
|
227
|
+
*/
|
|
228
|
+
void detach(const std::shared_ptr<RNSkCanvasProvider> &provider) {
|
|
229
|
+
{
|
|
230
|
+
std::lock_guard<std::mutex> lock(_stateMutex);
|
|
231
|
+
if (_provider.lock() != provider) {
|
|
232
|
+
return;
|
|
233
|
+
}
|
|
234
|
+
_provider.reset();
|
|
235
|
+
}
|
|
236
|
+
std::lock_guard<std::mutex> lock(_queueMutex);
|
|
237
|
+
_requestFrame = nullptr;
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
/** Takes every recording submitted since the last call, in order. */
|
|
241
|
+
std::vector<std::shared_ptr<RNSkGraphiteRecording>> takeQueued() {
|
|
242
|
+
std::lock_guard<std::mutex> lock(_queueMutex);
|
|
243
|
+
std::vector<std::shared_ptr<RNSkGraphiteRecording>> recordings(
|
|
244
|
+
_queue.begin(), _queue.end());
|
|
245
|
+
_queue.clear();
|
|
246
|
+
return recordings;
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
/**
|
|
250
|
+
Puts recordings that could not be presented back at the front of the
|
|
251
|
+
queue, ahead of anything submitted meanwhile, so that the order holds.
|
|
252
|
+
*/
|
|
253
|
+
void requeue(
|
|
254
|
+
const std::vector<std::shared_ptr<RNSkGraphiteRecording>> &recordings) {
|
|
255
|
+
std::lock_guard<std::mutex> lock(_queueMutex);
|
|
256
|
+
_queue.insert(_queue.begin(), recordings.begin(), recordings.end());
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
/** The most recently submitted recording still waiting, if any. */
|
|
260
|
+
std::shared_ptr<RNSkGraphiteRecording> peekLatest() {
|
|
261
|
+
std::lock_guard<std::mutex> lock(_queueMutex);
|
|
262
|
+
return _queue.empty() ? nullptr : _queue.back();
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
bool hasQueued() {
|
|
266
|
+
std::lock_guard<std::mutex> lock(_queueMutex);
|
|
267
|
+
return !_queue.empty();
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
private:
|
|
271
|
+
/**
|
|
272
|
+
The target to record against: the view's surface when it has one, else
|
|
273
|
+
the pixel size the platform laid the view out with, else the layout size
|
|
274
|
+
JS measured; in the last two cases with the format the surface will be
|
|
275
|
+
created with, following the same rules (see DawnWindowContext and
|
|
276
|
+
SkiaView.java).
|
|
277
|
+
*/
|
|
278
|
+
RNSkGraphiteTargetInfo resolveTargetInfo() {
|
|
279
|
+
std::shared_ptr<RNSkCanvasProvider> provider;
|
|
280
|
+
float width;
|
|
281
|
+
float height;
|
|
282
|
+
bool opaque;
|
|
283
|
+
bool highBitDepth;
|
|
284
|
+
{
|
|
285
|
+
std::lock_guard<std::mutex> lock(_stateMutex);
|
|
286
|
+
provider = _provider.lock();
|
|
287
|
+
width = _layoutWidth;
|
|
288
|
+
height = _layoutHeight;
|
|
289
|
+
opaque = _opaque;
|
|
290
|
+
highBitDepth = _highBitDepth;
|
|
291
|
+
}
|
|
292
|
+
RNSkGraphiteTargetInfo info;
|
|
293
|
+
if (provider && provider->getTargetInfo(&info)) {
|
|
294
|
+
return info;
|
|
295
|
+
}
|
|
296
|
+
#if defined(__ANDROID__)
|
|
297
|
+
// The 10-bit buffer format only has 2 bits of alpha: translucent views
|
|
298
|
+
// stay 8-bit.
|
|
299
|
+
if (!opaque) {
|
|
300
|
+
highBitDepth = false;
|
|
301
|
+
}
|
|
302
|
+
#else
|
|
303
|
+
(void)opaque;
|
|
304
|
+
#endif
|
|
305
|
+
if (!provider || !provider->getLayoutSize(&info.width, &info.height)) {
|
|
306
|
+
// Not laid out yet (JS gets its onLayout before the platform lays the
|
|
307
|
+
// view out): the size JS measured, in points. The layout is on the
|
|
308
|
+
// pixel grid, so the product is an integer up to rounding errors.
|
|
309
|
+
double pd = _context->getPixelDensity();
|
|
310
|
+
info.width = static_cast<int>(std::lround(width * pd));
|
|
311
|
+
info.height = static_cast<int>(std::lround(height * pd));
|
|
312
|
+
} else {
|
|
313
|
+
}
|
|
314
|
+
info.colorType = highBitDepth ? DawnUtils::HighBitDepthColorType
|
|
315
|
+
: DawnUtils::PreferedColorType;
|
|
316
|
+
info.textureInfo = skgpu::graphite::TextureInfos::MakeDawn(
|
|
317
|
+
skgpu::graphite::DawnTextureInfo(
|
|
318
|
+
skgpu::graphite::SampleCount::k1, skgpu::Mipmapped::kNo,
|
|
319
|
+
highBitDepth ? DawnUtils::HighBitDepthTextureFormat
|
|
320
|
+
: DawnUtils::PreferredTextureFormat,
|
|
321
|
+
DawnUtils::DefaultTargetUsage, wgpu::TextureAspect::All));
|
|
322
|
+
return info;
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
std::shared_ptr<RNSkPlatformContext> _context;
|
|
326
|
+
|
|
327
|
+
// Recorder, open recording and target description.
|
|
328
|
+
std::mutex _stateMutex;
|
|
329
|
+
std::shared_ptr<RNSkGraphiteRecorder> _recorder;
|
|
330
|
+
bool _recording = false;
|
|
331
|
+
RNSkGraphiteTargetInfo _recordingTarget;
|
|
332
|
+
std::weak_ptr<RNSkCanvasProvider> _provider;
|
|
333
|
+
float _layoutWidth = 0;
|
|
334
|
+
float _layoutHeight = 0;
|
|
335
|
+
bool _opaque = false;
|
|
336
|
+
bool _highBitDepth = false;
|
|
337
|
+
|
|
338
|
+
// Hand-off to the main thread.
|
|
339
|
+
std::mutex _queueMutex;
|
|
340
|
+
std::deque<std::shared_ptr<RNSkGraphiteRecording>> _queue;
|
|
341
|
+
std::function<void()> _requestFrame;
|
|
342
|
+
};
|
|
343
|
+
|
|
344
|
+
/**
|
|
345
|
+
* Targets by native view id. Entries are weak: a target lives as long as the
|
|
346
|
+
* view or a JS context object holds it.
|
|
347
|
+
*/
|
|
348
|
+
class RNSkGraphiteTargetRegistry {
|
|
349
|
+
public:
|
|
350
|
+
static RNSkGraphiteTargetRegistry &getInstance() {
|
|
351
|
+
static RNSkGraphiteTargetRegistry instance;
|
|
352
|
+
return instance;
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
RNSkGraphiteTargetRegistry(const RNSkGraphiteTargetRegistry &) = delete;
|
|
356
|
+
RNSkGraphiteTargetRegistry &
|
|
357
|
+
operator=(const RNSkGraphiteTargetRegistry &) = delete;
|
|
358
|
+
|
|
359
|
+
std::shared_ptr<RNSkGraphiteTarget>
|
|
360
|
+
getOrCreate(size_t nativeId,
|
|
361
|
+
const std::shared_ptr<RNSkPlatformContext> &context) {
|
|
362
|
+
std::lock_guard<std::mutex> lock(_mutex);
|
|
363
|
+
auto it = _targets.find(nativeId);
|
|
364
|
+
if (it != _targets.end()) {
|
|
365
|
+
if (auto target = it->second.lock()) {
|
|
366
|
+
return target;
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
for (auto entry = _targets.begin(); entry != _targets.end();) {
|
|
370
|
+
entry = entry->second.expired() ? _targets.erase(entry) : ++entry;
|
|
371
|
+
}
|
|
372
|
+
auto target = std::make_shared<RNSkGraphiteTarget>(context);
|
|
373
|
+
_targets[nativeId] = target;
|
|
374
|
+
return target;
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
private:
|
|
378
|
+
RNSkGraphiteTargetRegistry() = default;
|
|
379
|
+
std::mutex _mutex;
|
|
380
|
+
std::unordered_map<size_t, std::weak_ptr<RNSkGraphiteTarget>> _targets;
|
|
381
|
+
};
|
|
382
|
+
|
|
383
|
+
} // namespace RNSkia
|
|
@@ -10,19 +10,16 @@
|
|
|
10
10
|
#include <utility>
|
|
11
11
|
#include <vector>
|
|
12
12
|
|
|
13
|
-
#include "
|
|
13
|
+
#include "RNSkGraphiteProducer.h"
|
|
14
|
+
#include "RNSkGraphiteTarget.h"
|
|
14
15
|
#include "RNSkPlatformContext.h"
|
|
15
16
|
#include "RNSkView.h"
|
|
17
|
+
#include "api/JsiSkGraphiteContext.h"
|
|
16
18
|
#include "api/JsiSkNativeObjects.h"
|
|
17
19
|
#include "jsi/JsiPromises.h"
|
|
18
20
|
#include "jsi/ViewProperty.h"
|
|
19
21
|
#include <jsi/jsi.h>
|
|
20
22
|
|
|
21
|
-
#if defined(SK_GRAPHITE)
|
|
22
|
-
#include "RNSkGraphiteView.h"
|
|
23
|
-
#include "api/JsiSkGraphiteContext.h"
|
|
24
|
-
#endif
|
|
25
|
-
|
|
26
23
|
namespace RNSkia {
|
|
27
24
|
|
|
28
25
|
namespace jsi = facebook::jsi;
|
|
@@ -223,8 +220,8 @@ public:
|
|
|
223
220
|
// the values from recording time until the next change.
|
|
224
221
|
auto it = info->props.find("recorder");
|
|
225
222
|
if (it != info->props.end() && it->second.isRecorder()) {
|
|
226
|
-
|
|
227
|
-
|
|
223
|
+
RNSkGraphiteProducer::applyUpdatesTo(it->second.getRecorder(),
|
|
224
|
+
runtime, recorderId, values);
|
|
228
225
|
}
|
|
229
226
|
});
|
|
230
227
|
if (view == nullptr) {
|
|
@@ -355,13 +352,12 @@ public:
|
|
|
355
352
|
}
|
|
356
353
|
|
|
357
354
|
/**
|
|
358
|
-
Returns the recording side of a
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
355
|
+
Returns the recording side of a view: (nativeId, width, height, opaque,
|
|
356
|
+
highBitDepth), the size in points as laid out and the props the surface
|
|
357
|
+
format follows from. The view may not exist yet; the context binds to it
|
|
358
|
+
by id when it does.
|
|
362
359
|
*/
|
|
363
360
|
JSI_HOST_FUNCTION(makeGraphiteContext) {
|
|
364
|
-
#if defined(SK_GRAPHITE)
|
|
365
361
|
if (count < 3 || !arguments[0].isNumber() || !arguments[1].isNumber() ||
|
|
366
362
|
!arguments[2].isNumber()) {
|
|
367
363
|
throw jsi::JSError(runtime, "makeGraphiteContext: expected (nativeId, "
|
|
@@ -378,11 +374,6 @@ public:
|
|
|
378
374
|
target->setLayout(width, height, opaque, highBitDepth);
|
|
379
375
|
return makeJsiObject(runtime, std::make_shared<JsiSkGraphiteContext>(
|
|
380
376
|
_platformContext, std::move(target)));
|
|
381
|
-
#else
|
|
382
|
-
throw jsi::JSError(runtime,
|
|
383
|
-
"SkiaGraphiteView requires the Graphite backend. "
|
|
384
|
-
"Rebuild with SK_GRAPHITE enabled.");
|
|
385
|
-
#endif
|
|
386
377
|
}
|
|
387
378
|
|
|
388
379
|
static void definePrototype(jsi::Runtime &runtime, jsi::Object &prototype) {
|
|
@@ -105,34 +105,28 @@ public:
|
|
|
105
105
|
*/
|
|
106
106
|
virtual sk_sp<SkImage> makeImageFromNativeBuffer(void *buffer) = 0;
|
|
107
107
|
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
int height, bool mipMapped) = 0;
|
|
112
|
-
|
|
113
|
-
virtual const TextureInfo getTexture(sk_sp<SkSurface> image) = 0;
|
|
114
|
-
|
|
115
|
-
virtual const TextureInfo getTexture(sk_sp<SkImage> image) = 0;
|
|
116
|
-
|
|
117
|
-
virtual GrDirectContext *getDirectContext() = 0;
|
|
118
|
-
#else
|
|
108
|
+
// The handle-based texture interop of the Ganesh era (Metal and OpenGL
|
|
109
|
+
// texture handles). Graphite textures cross the package boundary as
|
|
110
|
+
// WGPUTexture pointers instead (see JsiSkImageFactory).
|
|
119
111
|
sk_sp<SkImage> makeImageFromNativeTexture(const TextureInfo &textureInfo,
|
|
120
112
|
int width, int height,
|
|
121
113
|
bool mipMapped) {
|
|
122
114
|
throw std::runtime_error(
|
|
123
|
-
"makeImageFromNativeTexture not
|
|
115
|
+
"makeImageFromNativeTexture is not available on Graphite, use "
|
|
116
|
+
"Skia.Image.MakeImageFromNativeTexture(pointer)");
|
|
124
117
|
}
|
|
125
118
|
|
|
126
119
|
const TextureInfo getTexture(sk_sp<SkSurface> image) {
|
|
127
120
|
throw std::runtime_error(
|
|
128
|
-
"getTexture(surface) not
|
|
121
|
+
"getTexture(surface) is not available on Graphite, use "
|
|
122
|
+
"Skia.Surface.MakeFromNativeTexture(pointer)");
|
|
129
123
|
}
|
|
130
124
|
|
|
131
125
|
const TextureInfo getTexture(sk_sp<SkImage> image) {
|
|
132
126
|
throw std::runtime_error(
|
|
133
|
-
"getTexture(image) not
|
|
127
|
+
"getTexture(image) is not available on Graphite, use "
|
|
128
|
+
"Skia.Image.MakeNativeTextureFromImage(image)");
|
|
134
129
|
}
|
|
135
|
-
#endif
|
|
136
130
|
|
|
137
131
|
virtual void releaseNativeBuffer(uint64_t pointer) = 0;
|
|
138
132
|
|