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
|
@@ -3,18 +3,33 @@ package com.reactnative.skia;
|
|
|
3
3
|
import android.content.Context;
|
|
4
4
|
import android.graphics.SurfaceTexture;
|
|
5
5
|
import android.util.Log;
|
|
6
|
+
import android.view.Choreographer;
|
|
6
7
|
import android.view.MotionEvent;
|
|
7
8
|
import android.view.Surface;
|
|
8
9
|
import android.view.View;
|
|
9
10
|
|
|
11
|
+
import com.facebook.jni.HybridData;
|
|
12
|
+
import com.facebook.jni.annotations.DoNotStrip;
|
|
13
|
+
import com.facebook.react.bridge.ReactContext;
|
|
10
14
|
import com.facebook.react.uimanager.PointerEvents;
|
|
11
15
|
import com.facebook.react.views.view.ReactViewGroup;
|
|
12
16
|
|
|
13
|
-
|
|
17
|
+
/**
|
|
18
|
+
* The Android view behind <Canvas>, <SkiaPictureView> and <SkiaGraphiteView>.
|
|
19
|
+
* It is backed by a SurfaceView or a TextureView (see updateView()) that the
|
|
20
|
+
* native side draws into with Graphite, presenting the queued recordings on
|
|
21
|
+
* the Choreographer.
|
|
22
|
+
*/
|
|
23
|
+
public class SkiaView extends ReactViewGroup implements SkiaViewAPI, Choreographer.FrameCallback {
|
|
14
24
|
// Backing view kinds, see updateView().
|
|
15
25
|
private static final int KIND_SURFACE_VIEW = 0;
|
|
16
26
|
private static final int KIND_TEXTURE_VIEW = 1;
|
|
17
27
|
|
|
28
|
+
private static final String TAG = "SkiaView";
|
|
29
|
+
|
|
30
|
+
@DoNotStrip
|
|
31
|
+
private HybridData mHybridData;
|
|
32
|
+
|
|
18
33
|
private View mView;
|
|
19
34
|
|
|
20
35
|
// Props, applied together in updateView().
|
|
@@ -28,11 +43,12 @@ public abstract class SkiaBaseView extends ReactViewGroup implements SkiaViewAPI
|
|
|
28
43
|
private boolean mAppliedZOrderOnTop;
|
|
29
44
|
private boolean mAppliedHighBitDepth;
|
|
30
45
|
|
|
31
|
-
private
|
|
32
|
-
private final String tag = "SkiaView";
|
|
46
|
+
private boolean mFramePending = false;
|
|
33
47
|
|
|
34
|
-
public
|
|
48
|
+
public SkiaView(Context context) {
|
|
35
49
|
super(context);
|
|
50
|
+
RNSkiaModule skiaModule = ((ReactContext) context).getNativeModule(RNSkiaModule.class);
|
|
51
|
+
mHybridData = initHybrid(skiaModule.getSkiaManager());
|
|
36
52
|
}
|
|
37
53
|
|
|
38
54
|
@Override
|
|
@@ -82,7 +98,7 @@ public abstract class SkiaBaseView extends ReactViewGroup implements SkiaViewAPI
|
|
|
82
98
|
return false;
|
|
83
99
|
}
|
|
84
100
|
if (kind != KIND_SURFACE_VIEW || !mOpaque) {
|
|
85
|
-
Log.w(
|
|
101
|
+
Log.w(TAG, "highBitDepth requires an opaque SurfaceView on Android, falling back to the 8-bit format");
|
|
86
102
|
return false;
|
|
87
103
|
}
|
|
88
104
|
return true;
|
|
@@ -107,8 +123,8 @@ public abstract class SkiaBaseView extends ReactViewGroup implements SkiaViewAPI
|
|
|
107
123
|
mAppliedZOrderOnTop = zOrderOnTop;
|
|
108
124
|
mAppliedHighBitDepth = highBitDepth;
|
|
109
125
|
mView = kind == KIND_SURFACE_VIEW
|
|
110
|
-
? new SkiaSurfaceView(getContext(), this,
|
|
111
|
-
: new SkiaTextureView(getContext(), this,
|
|
126
|
+
? new SkiaSurfaceView(getContext(), this, zOrderOnTop, mOpaque)
|
|
127
|
+
: new SkiaTextureView(getContext(), this, mOpaque);
|
|
112
128
|
addView(mView);
|
|
113
129
|
// React Native sizes native children explicitly through onLayout, so
|
|
114
130
|
// the requestLayout triggered by addView is ignored; size the new
|
|
@@ -130,11 +146,52 @@ public abstract class SkiaBaseView extends ReactViewGroup implements SkiaViewAPI
|
|
|
130
146
|
@Override
|
|
131
147
|
protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
|
|
132
148
|
super.onLayout(changed, left, top, right, bottom);
|
|
149
|
+
// The backing view gets this exact size, and so does its surface: tell
|
|
150
|
+
// the native side now, so that a frame recorded before the surface
|
|
151
|
+
// exists (the first one usually is) already has the right size.
|
|
152
|
+
setLayoutSize(right - left, bottom - top);
|
|
133
153
|
if (mView != null) {
|
|
134
154
|
mView.layout(0, 0, right - left, bottom - top);
|
|
135
155
|
}
|
|
136
156
|
}
|
|
137
157
|
|
|
158
|
+
// Frames --------------------------------------------------------------
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* Presents the queued recordings on the next vsync. Main thread; called
|
|
162
|
+
* from native when a recording is submitted.
|
|
163
|
+
*/
|
|
164
|
+
@DoNotStrip
|
|
165
|
+
public void scheduleFrame() {
|
|
166
|
+
if (!mFramePending) {
|
|
167
|
+
mFramePending = true;
|
|
168
|
+
Choreographer.getInstance().postFrameCallback(this);
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
@Override
|
|
173
|
+
public void doFrame(long frameTimeNanos) {
|
|
174
|
+
mFramePending = false;
|
|
175
|
+
if (presentFrame()) {
|
|
176
|
+
scheduleFrame();
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
@Override
|
|
181
|
+
protected void onDetachedFromWindow() {
|
|
182
|
+
super.onDetachedFromWindow();
|
|
183
|
+
Choreographer.getInstance().removeFrameCallback(this);
|
|
184
|
+
mFramePending = false;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
@Override
|
|
188
|
+
protected void finalize() throws Throwable {
|
|
189
|
+
super.finalize();
|
|
190
|
+
mHybridData.resetNative();
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
// Surfaces ------------------------------------------------------------
|
|
194
|
+
|
|
138
195
|
// SurfaceView callbacks: the native side receives an android.view.Surface.
|
|
139
196
|
|
|
140
197
|
@Override
|
|
@@ -144,7 +201,7 @@ public abstract class SkiaBaseView extends ReactViewGroup implements SkiaViewAPI
|
|
|
144
201
|
|
|
145
202
|
@Override
|
|
146
203
|
public void onSurfaceChanged(Surface surface, int width, int height) {
|
|
147
|
-
Log.i(
|
|
204
|
+
Log.i(TAG, "onSurfaceChanged " + width + "/" + height);
|
|
148
205
|
surfaceSizeChanged(surface, width, height, true, mAppliedHighBitDepth);
|
|
149
206
|
}
|
|
150
207
|
|
|
@@ -158,7 +215,7 @@ public abstract class SkiaBaseView extends ReactViewGroup implements SkiaViewAPI
|
|
|
158
215
|
|
|
159
216
|
@Override
|
|
160
217
|
public void onSurfaceTextureChanged(SurfaceTexture surface, int width, int height) {
|
|
161
|
-
Log.i(
|
|
218
|
+
Log.i(TAG, "onSurfaceTextureSizeChanged " + width + "/" + height);
|
|
162
219
|
surfaceSizeChanged(surface, width, height, false, false);
|
|
163
220
|
}
|
|
164
221
|
|
|
@@ -167,19 +224,24 @@ public abstract class SkiaBaseView extends ReactViewGroup implements SkiaViewAPI
|
|
|
167
224
|
surfaceDestroyed();
|
|
168
225
|
}
|
|
169
226
|
|
|
227
|
+
// Native ---------------------------------------------------------------
|
|
228
|
+
|
|
229
|
+
private native HybridData initHybrid(SkiaManager skiaManager);
|
|
230
|
+
|
|
170
231
|
// isSurface tells the native side whether `surface` is an
|
|
171
232
|
// android.view.Surface (SurfaceView) or a SurfaceTexture (TextureView).
|
|
172
|
-
|
|
233
|
+
private native void surfaceAvailable(Object surface, int width, int height, boolean isSurface, boolean highBitDepth);
|
|
173
234
|
|
|
174
|
-
|
|
235
|
+
private native void surfaceSizeChanged(Object surface, int width, int height, boolean isSurface, boolean highBitDepth);
|
|
175
236
|
|
|
176
|
-
|
|
237
|
+
private native void surfaceDestroyed();
|
|
177
238
|
|
|
178
|
-
|
|
239
|
+
private native void setLayoutSize(int width, int height);
|
|
179
240
|
|
|
180
|
-
|
|
241
|
+
native void registerView(int nativeId);
|
|
181
242
|
|
|
182
|
-
|
|
243
|
+
private native void unregisterView();
|
|
183
244
|
|
|
184
|
-
|
|
245
|
+
/** Choreographer tick: returns whether more recordings are waiting. */
|
|
246
|
+
private native boolean presentFrame();
|
|
185
247
|
}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
package com.reactnative.skia;
|
|
2
|
+
|
|
3
|
+
import com.facebook.react.uimanager.PointerEvents;
|
|
4
|
+
import com.facebook.react.uimanager.ThemedReactContext;
|
|
5
|
+
import com.facebook.react.uimanager.ViewProps;
|
|
6
|
+
import com.facebook.react.uimanager.annotations.ReactProp;
|
|
7
|
+
import com.facebook.react.viewmanagers.SkiaViewManagerDelegate;
|
|
8
|
+
import com.facebook.react.viewmanagers.SkiaViewManagerInterface;
|
|
9
|
+
import com.facebook.react.views.view.ReactViewGroup;
|
|
10
|
+
import com.facebook.react.views.view.ReactViewManager;
|
|
11
|
+
|
|
12
|
+
import androidx.annotation.NonNull;
|
|
13
|
+
import androidx.annotation.Nullable;
|
|
14
|
+
|
|
15
|
+
public class SkiaViewManager extends ReactViewManager implements SkiaViewManagerInterface<SkiaView> {
|
|
16
|
+
|
|
17
|
+
protected SkiaViewManagerDelegate mDelegate;
|
|
18
|
+
|
|
19
|
+
SkiaViewManager() {
|
|
20
|
+
mDelegate = new SkiaViewManagerDelegate(this);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
protected SkiaViewManagerDelegate getDelegate() {
|
|
24
|
+
return mDelegate;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
@NonNull
|
|
28
|
+
@Override
|
|
29
|
+
public String getName() {
|
|
30
|
+
return "SkiaView";
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
@NonNull
|
|
34
|
+
@Override
|
|
35
|
+
public SkiaView createViewInstance(@NonNull ThemedReactContext reactContext) {
|
|
36
|
+
return new SkiaView(reactContext);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
@Override
|
|
40
|
+
public void setNativeId(@NonNull ReactViewGroup view, @Nullable String nativeId) {
|
|
41
|
+
super.setNativeId(view, nativeId);
|
|
42
|
+
int nativeIdResolved = Integer.parseInt(nativeId);
|
|
43
|
+
((SkiaView) view).registerView(nativeIdResolved);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
@ReactProp(name = "opaque")
|
|
47
|
+
public void setOpaque(SkiaView view, boolean value) {
|
|
48
|
+
view.setOpaque(value);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
@ReactProp(name = "highBitDepth")
|
|
52
|
+
public void setHighBitDepth(SkiaView view, boolean value) {
|
|
53
|
+
view.setHighBitDepth(value);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
@ReactProp(name = "androidSurfaceType")
|
|
57
|
+
public void setAndroidSurfaceType(SkiaView view, @Nullable String value) {
|
|
58
|
+
view.setSurfaceType(value);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
@ReactProp(name = "androidZOrderOnTop")
|
|
62
|
+
public void setAndroidZOrderOnTop(SkiaView view, boolean value) {
|
|
63
|
+
view.setZOrderOnTop(value);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
@ReactProp(name = ViewProps.POINTER_EVENTS)
|
|
67
|
+
public void setPointerEvents(SkiaView view, @Nullable String pointerEventsStr) {
|
|
68
|
+
view.setPointerEvents(PointerEvents.parsePointerEvents(pointerEventsStr));
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
// The backing view depends on several props (opaque, androidSurfaceType,
|
|
72
|
+
// androidZOrderOnTop, highBitDepth), so it is resolved once per transaction
|
|
73
|
+
// rather than in each setter.
|
|
74
|
+
@Override
|
|
75
|
+
protected void onAfterUpdateTransaction(@NonNull ReactViewGroup view) {
|
|
76
|
+
super.onAfterUpdateTransaction(view);
|
|
77
|
+
((SkiaView) view).updateView();
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
@Override
|
|
81
|
+
public void onDropViewInstance(@NonNull ReactViewGroup view) {
|
|
82
|
+
super.onDropViewInstance(view);
|
|
83
|
+
((SkiaView) view).dropInstance();
|
|
84
|
+
}
|
|
85
|
+
}
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
#ifdef SK_GRAPHITE
|
|
2
|
-
|
|
3
1
|
#import <CoreGraphics/CoreGraphics.h>
|
|
4
2
|
#import <Foundation/Foundation.h>
|
|
5
3
|
#import <QuartzCore/CAMetalLayer.h>
|
|
@@ -35,5 +33,3 @@ void applyCAMetalLayerColorSpace(void *nativeSurface,
|
|
|
35
33
|
}
|
|
36
34
|
|
|
37
35
|
} // namespace RNSkia
|
|
38
|
-
|
|
39
|
-
#endif // SK_GRAPHITE
|
|
@@ -42,18 +42,6 @@ public:
|
|
|
42
42
|
|
|
43
43
|
sk_sp<SkImage> makeImageFromNativeBuffer(void *buffer) override;
|
|
44
44
|
|
|
45
|
-
#if !defined(SK_GRAPHITE)
|
|
46
|
-
GrDirectContext *getDirectContext() override;
|
|
47
|
-
|
|
48
|
-
sk_sp<SkImage> makeImageFromNativeTexture(const TextureInfo &textureInfo,
|
|
49
|
-
int width, int height,
|
|
50
|
-
bool mipMapped) override;
|
|
51
|
-
|
|
52
|
-
const TextureInfo getTexture(sk_sp<SkSurface> image) override;
|
|
53
|
-
|
|
54
|
-
const TextureInfo getTexture(sk_sp<SkImage> image) override;
|
|
55
|
-
#endif
|
|
56
|
-
|
|
57
45
|
uint64_t makeNativeBuffer(sk_sp<SkImage> image) override;
|
|
58
46
|
|
|
59
47
|
uint64_t makeTestNativeBuffer(int width, int height) override;
|
|
@@ -78,8 +66,6 @@ public:
|
|
|
78
66
|
|
|
79
67
|
private:
|
|
80
68
|
ViewScreenshotService *_screenshotService;
|
|
81
|
-
|
|
82
|
-
SkColorType mtlPixelFormatToSkColorType(MTLPixelFormat pixelFormat);
|
|
83
69
|
};
|
|
84
70
|
|
|
85
71
|
} // namespace RNSkia
|
|
@@ -1,18 +1,13 @@
|
|
|
1
1
|
#import "RNSkApplePlatformContext.h"
|
|
2
2
|
|
|
3
3
|
#import <CoreMedia/CMSampleBuffer.h>
|
|
4
|
-
#include <Metal/Metal.h>
|
|
5
4
|
#import <React/RCTUtils.h>
|
|
6
5
|
#include <algorithm>
|
|
7
6
|
#include <set>
|
|
8
7
|
#include <thread>
|
|
9
8
|
#include <utility>
|
|
10
9
|
|
|
11
|
-
#if defined(SK_GRAPHITE)
|
|
12
10
|
#include "RNDawnContext.h"
|
|
13
|
-
#else
|
|
14
|
-
#include "MetalContext.h"
|
|
15
|
-
#endif
|
|
16
11
|
#include "RNSkAppleVideo.h"
|
|
17
12
|
|
|
18
13
|
#pragma clang diagnostic push
|
|
@@ -83,15 +78,12 @@ void RNSkApplePlatformContext::releaseNativeBuffer(uint64_t pointer) {
|
|
|
83
78
|
}
|
|
84
79
|
|
|
85
80
|
uint64_t RNSkApplePlatformContext::makeNativeBuffer(sk_sp<SkImage> image) {
|
|
86
|
-
#if defined(SK_GRAPHITE)
|
|
87
81
|
// A Graphite GPU texture can't be read with readPixels(nullptr) (and can't be
|
|
88
|
-
// drawn onto a raster surface)
|
|
89
|
-
// it back to a raster image first.
|
|
90
|
-
// SkImage::makeNonTextureImage(), which is a no-op on Graphite.)
|
|
82
|
+
// drawn onto a raster surface): both yield uninitialized/black pixels. Read
|
|
83
|
+
// it back to a raster image first.
|
|
91
84
|
if (image && image->isTextureBacked()) {
|
|
92
85
|
image = DawnContext::getInstance().MakeRasterImage(image);
|
|
93
86
|
}
|
|
94
|
-
#endif
|
|
95
87
|
// 0. If Image is not in BGRA, convert to BGRA as only BGRA is supported.
|
|
96
88
|
if (image->colorType() != kBGRA_8888_SkColorType) {
|
|
97
89
|
const SkImageInfo bgraInfo =
|
|
@@ -241,67 +233,6 @@ uint64_t RNSkApplePlatformContext::makeTestNativeBuffer(int width, int height) {
|
|
|
241
233
|
return reinterpret_cast<uint64_t>(pixelBuffer);
|
|
242
234
|
}
|
|
243
235
|
|
|
244
|
-
#if !defined(SK_GRAPHITE)
|
|
245
|
-
GrDirectContext *RNSkApplePlatformContext::getDirectContext() {
|
|
246
|
-
return MetalContext::getInstance().getDirectContext();
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
const TextureInfo RNSkApplePlatformContext::getTexture(sk_sp<SkImage> image) {
|
|
250
|
-
TextureInfo result;
|
|
251
|
-
GrBackendTexture texture;
|
|
252
|
-
if (!SkImages::GetBackendTextureFromImage(image, &texture, true)) {
|
|
253
|
-
throw std::runtime_error("Couldn't get backend texture");
|
|
254
|
-
}
|
|
255
|
-
if (!texture.isValid()) {
|
|
256
|
-
throw std::runtime_error("Invalid backend texture");
|
|
257
|
-
}
|
|
258
|
-
GrMtlTextureInfo textureInfo;
|
|
259
|
-
if (!GrBackendTextures::GetMtlTextureInfo(texture, &textureInfo)) {
|
|
260
|
-
throw std::runtime_error("Couldn't get Metal texture info");
|
|
261
|
-
}
|
|
262
|
-
result.mtlTexture = textureInfo.fTexture.get();
|
|
263
|
-
return result;
|
|
264
|
-
}
|
|
265
|
-
|
|
266
|
-
const TextureInfo
|
|
267
|
-
RNSkApplePlatformContext::getTexture(sk_sp<SkSurface> surface) {
|
|
268
|
-
TextureInfo result;
|
|
269
|
-
GrBackendTexture texture = SkSurfaces::GetBackendTexture(
|
|
270
|
-
surface.get(), SkSurfaces::BackendHandleAccess::kFlushRead);
|
|
271
|
-
if (!texture.isValid()) {
|
|
272
|
-
throw std::runtime_error("Invalid backend texture");
|
|
273
|
-
}
|
|
274
|
-
GrMtlTextureInfo textureInfo;
|
|
275
|
-
if (!GrBackendTextures::GetMtlTextureInfo(texture, &textureInfo)) {
|
|
276
|
-
throw std::runtime_error("Couldn't get Metal texture info");
|
|
277
|
-
}
|
|
278
|
-
result.mtlTexture = textureInfo.fTexture.get();
|
|
279
|
-
return result;
|
|
280
|
-
}
|
|
281
|
-
|
|
282
|
-
sk_sp<SkImage> RNSkApplePlatformContext::makeImageFromNativeTexture(
|
|
283
|
-
const TextureInfo &texInfo, int width, int height, bool mipMapped) {
|
|
284
|
-
id<MTLTexture> mtlTexture = (__bridge id<MTLTexture>)(texInfo.mtlTexture);
|
|
285
|
-
|
|
286
|
-
SkColorType colorType = mtlPixelFormatToSkColorType(mtlTexture.pixelFormat);
|
|
287
|
-
if (colorType == SkColorType::kUnknown_SkColorType) {
|
|
288
|
-
throw std::runtime_error("Unsupported pixelFormat");
|
|
289
|
-
}
|
|
290
|
-
|
|
291
|
-
GrMtlTextureInfo textureInfo;
|
|
292
|
-
textureInfo.fTexture.retain((__bridge const void *)mtlTexture);
|
|
293
|
-
|
|
294
|
-
GrBackendTexture texture = GrBackendTextures::MakeMtl(
|
|
295
|
-
width, height, mipMapped ? skgpu::Mipmapped::kYes : skgpu::Mipmapped::kNo,
|
|
296
|
-
textureInfo);
|
|
297
|
-
|
|
298
|
-
return SkImages::BorrowTextureFrom(getDirectContext(), texture,
|
|
299
|
-
kTopLeft_GrSurfaceOrigin, colorType,
|
|
300
|
-
kPremul_SkAlphaType, nullptr);
|
|
301
|
-
return nullptr;
|
|
302
|
-
}
|
|
303
|
-
#endif
|
|
304
|
-
|
|
305
236
|
std::shared_ptr<RNSkVideo>
|
|
306
237
|
RNSkApplePlatformContext::createVideo(const std::string &url) {
|
|
307
238
|
return std::make_shared<RNSkAppleVideo>(url, this);
|
|
@@ -314,54 +245,13 @@ void RNSkApplePlatformContext::raiseError(const std::exception &err) {
|
|
|
314
245
|
sk_sp<SkSurface>
|
|
315
246
|
RNSkApplePlatformContext::makeOffscreenSurface(int width, int height,
|
|
316
247
|
bool useP3ColorSpace) {
|
|
317
|
-
#if defined(SK_GRAPHITE)
|
|
318
248
|
return DawnContext::getInstance().MakeOffscreen(width, height,
|
|
319
249
|
useP3ColorSpace);
|
|
320
|
-
#else
|
|
321
|
-
return MetalContext::getInstance().MakeOffscreen(width, height,
|
|
322
|
-
useP3ColorSpace);
|
|
323
|
-
#endif
|
|
324
250
|
}
|
|
325
251
|
|
|
326
252
|
sk_sp<SkImage>
|
|
327
253
|
RNSkApplePlatformContext::makeImageFromNativeBuffer(void *buffer) {
|
|
328
|
-
#if defined(SK_GRAPHITE)
|
|
329
254
|
return DawnContext::getInstance().MakeImageFromBuffer(buffer);
|
|
330
|
-
#else
|
|
331
|
-
return MetalContext::getInstance().MakeImageFromBuffer(buffer);
|
|
332
|
-
#endif
|
|
333
|
-
}
|
|
334
|
-
|
|
335
|
-
SkColorType RNSkApplePlatformContext::mtlPixelFormatToSkColorType(
|
|
336
|
-
MTLPixelFormat pixelFormat) {
|
|
337
|
-
switch (pixelFormat) {
|
|
338
|
-
case MTLPixelFormatRGBA8Unorm:
|
|
339
|
-
return kRGBA_8888_SkColorType;
|
|
340
|
-
case MTLPixelFormatBGRA8Unorm:
|
|
341
|
-
return kBGRA_8888_SkColorType;
|
|
342
|
-
case MTLPixelFormatRGB10A2Unorm:
|
|
343
|
-
return kRGBA_1010102_SkColorType;
|
|
344
|
-
case MTLPixelFormatR8Unorm:
|
|
345
|
-
return kGray_8_SkColorType;
|
|
346
|
-
case MTLPixelFormatRGBA16Float:
|
|
347
|
-
return kRGBA_F16_SkColorType;
|
|
348
|
-
case MTLPixelFormatRG8Unorm:
|
|
349
|
-
return kR8G8_unorm_SkColorType;
|
|
350
|
-
case MTLPixelFormatR16Float:
|
|
351
|
-
return kA16_float_SkColorType;
|
|
352
|
-
case MTLPixelFormatRG16Float:
|
|
353
|
-
return kR16G16_float_SkColorType;
|
|
354
|
-
case MTLPixelFormatR16Unorm:
|
|
355
|
-
return kA16_unorm_SkColorType;
|
|
356
|
-
case MTLPixelFormatRG16Unorm:
|
|
357
|
-
return kR16G16_unorm_SkColorType;
|
|
358
|
-
case MTLPixelFormatRGBA16Unorm:
|
|
359
|
-
return kR16G16B16A16_unorm_SkColorType;
|
|
360
|
-
case MTLPixelFormatRGBA8Unorm_sRGB:
|
|
361
|
-
return kSRGBA_8888_SkColorType;
|
|
362
|
-
default:
|
|
363
|
-
return kUnknown_SkColorType;
|
|
364
|
-
}
|
|
365
255
|
}
|
|
366
256
|
|
|
367
257
|
sk_sp<SkFontMgr> RNSkApplePlatformContext::createFontMgr() {
|
|
@@ -1,43 +1,39 @@
|
|
|
1
1
|
#pragma once
|
|
2
2
|
|
|
3
|
+
#import "RNSkCanvasProvider.h"
|
|
3
4
|
#import "RNSkPlatformContext.h"
|
|
4
|
-
#import "RNSkView.h"
|
|
5
5
|
|
|
6
6
|
#import <MetalKit/MetalKit.h>
|
|
7
7
|
#import <QuartzCore/CAMetalLayer.h>
|
|
8
8
|
|
|
9
|
+
#include <memory>
|
|
9
10
|
#include <mutex>
|
|
10
11
|
#include <vector>
|
|
11
12
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
#pragma clang diagnostic pop
|
|
18
|
-
|
|
13
|
+
/**
|
|
14
|
+
* The CAMetalLayer a SkiaView presents into. The layer is configured as a
|
|
15
|
+
* Dawn surface (see DawnWindowContext) when the view gets a size.
|
|
16
|
+
*/
|
|
19
17
|
class RNSkMetalCanvasProvider : public RNSkia::RNSkCanvasProvider {
|
|
20
18
|
public:
|
|
21
|
-
RNSkMetalCanvasProvider(
|
|
22
|
-
|
|
23
|
-
bool useP3ColorSpace = true);
|
|
19
|
+
explicit RNSkMetalCanvasProvider(
|
|
20
|
+
std::shared_ptr<RNSkia::RNSkPlatformContext> context);
|
|
24
21
|
|
|
25
22
|
~RNSkMetalCanvasProvider();
|
|
26
23
|
|
|
27
24
|
int getWidth() override;
|
|
28
25
|
int getHeight() override;
|
|
29
26
|
|
|
30
|
-
bool
|
|
27
|
+
bool getTargetInfo(RNSkia::RNSkGraphiteTargetInfo *info) override;
|
|
31
28
|
|
|
32
|
-
|
|
33
|
-
bool getGraphiteTargetInfo(RNSkia::RNSkGraphiteTargetInfo *info) override;
|
|
29
|
+
bool getLayoutSize(int *width, int *height) override;
|
|
34
30
|
|
|
35
31
|
bool presentRecordings(
|
|
36
32
|
const std::vector<skgpu::graphite::Recording *> &recordings) override;
|
|
37
|
-
|
|
33
|
+
|
|
34
|
+
bool presentImage(const sk_sp<SkImage> &image) override;
|
|
38
35
|
|
|
39
36
|
void setSize(int width, int height);
|
|
40
|
-
void setUseP3ColorSpace(bool useP3ColorSpace);
|
|
41
37
|
void setHighBitDepth(bool highBitDepth);
|
|
42
38
|
CALayer *getLayer();
|
|
43
39
|
|
|
@@ -48,13 +44,12 @@ private:
|
|
|
48
44
|
#pragma clang diagnostic ignored "-Wunguarded-availability-new"
|
|
49
45
|
CAMetalLayer *_layer;
|
|
50
46
|
#pragma clang diagnostic pop
|
|
51
|
-
bool _useP3ColorSpace = true;
|
|
52
47
|
bool _highBitDepth = false;
|
|
53
|
-
#if defined(SK_GRAPHITE)
|
|
54
48
|
// A copy of the window's target description, readable from any thread
|
|
55
49
|
// while the window itself belongs to the main thread.
|
|
56
50
|
std::mutex _targetInfoMutex;
|
|
57
51
|
RNSkia::RNSkGraphiteTargetInfo _targetInfo;
|
|
58
52
|
bool _hasTargetInfo = false;
|
|
59
|
-
|
|
53
|
+
int _layoutWidth = 0;
|
|
54
|
+
int _layoutHeight = 0;
|
|
60
55
|
};
|
|
@@ -1,31 +1,13 @@
|
|
|
1
1
|
#import "RNSkMetalCanvasProvider.h"
|
|
2
2
|
|
|
3
|
-
#import "RNSkLog.h"
|
|
4
|
-
|
|
5
|
-
#if defined(SK_GRAPHITE)
|
|
6
3
|
#import "RNDawnContext.h"
|
|
7
|
-
#
|
|
8
|
-
#import "MetalContext.h"
|
|
9
|
-
#endif
|
|
10
|
-
|
|
11
|
-
#pragma clang diagnostic push
|
|
12
|
-
#pragma clang diagnostic ignored "-Wdocumentation"
|
|
13
|
-
|
|
14
|
-
#import "include/core/SkCanvas.h"
|
|
15
|
-
#import "include/core/SkColorSpace.h"
|
|
16
|
-
#import "include/core/SkSurface.h"
|
|
17
|
-
|
|
18
|
-
#import <include/gpu/ganesh/GrBackendSurface.h>
|
|
19
|
-
#import <include/gpu/ganesh/GrDirectContext.h>
|
|
20
|
-
#import <include/gpu/ganesh/SkSurfaceGanesh.h>
|
|
4
|
+
#import "RNSkLog.h"
|
|
21
5
|
|
|
22
|
-
#
|
|
6
|
+
#include <cmath>
|
|
23
7
|
|
|
24
8
|
RNSkMetalCanvasProvider::RNSkMetalCanvasProvider(
|
|
25
|
-
std::
|
|
26
|
-
std::
|
|
27
|
-
: RNSkCanvasProvider(requestRedraw), _context(context),
|
|
28
|
-
_useP3ColorSpace(useP3ColorSpace) {
|
|
9
|
+
std::shared_ptr<RNSkia::RNSkPlatformContext> context)
|
|
10
|
+
: _context(std::move(context)) {
|
|
29
11
|
#pragma clang diagnostic push
|
|
30
12
|
#pragma clang diagnostic ignored "-Wunguarded-availability-new"
|
|
31
13
|
_layer = [CAMetalLayer layer];
|
|
@@ -61,38 +43,7 @@ static bool appIsBackgrounded() {
|
|
|
61
43
|
#endif // !TARGET_OS_OSX
|
|
62
44
|
}
|
|
63
45
|
|
|
64
|
-
|
|
65
|
-
Render to a canvas
|
|
66
|
-
*/
|
|
67
|
-
bool RNSkMetalCanvasProvider::renderToCanvas(
|
|
68
|
-
const std::function<void(SkCanvas *)> &cb) {
|
|
69
|
-
if (!_ctx) {
|
|
70
|
-
return false;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
if ([[NSThread currentThread] isMainThread]) {
|
|
74
|
-
if (appIsBackgrounded()) {
|
|
75
|
-
// Request a redraw in the next run loop callback
|
|
76
|
-
_requestRedraw();
|
|
77
|
-
// and don't draw now since it might cause errors in the metal renderer if
|
|
78
|
-
// we try to render while in the background. (see above issue)
|
|
79
|
-
return false;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
auto surface = _ctx->getSurface();
|
|
83
|
-
if (!surface) {
|
|
84
|
-
return false;
|
|
85
|
-
}
|
|
86
|
-
auto canvas = surface->getCanvas();
|
|
87
|
-
cb(canvas);
|
|
88
|
-
_ctx->present();
|
|
89
|
-
return true;
|
|
90
|
-
}
|
|
91
|
-
return false;
|
|
92
|
-
};
|
|
93
|
-
|
|
94
|
-
#if defined(SK_GRAPHITE)
|
|
95
|
-
bool RNSkMetalCanvasProvider::getGraphiteTargetInfo(
|
|
46
|
+
bool RNSkMetalCanvasProvider::getTargetInfo(
|
|
96
47
|
RNSkia::RNSkGraphiteTargetInfo *info) {
|
|
97
48
|
std::lock_guard<std::mutex> lock(_targetInfoMutex);
|
|
98
49
|
if (!_hasTargetInfo) {
|
|
@@ -102,49 +53,65 @@ bool RNSkMetalCanvasProvider::getGraphiteTargetInfo(
|
|
|
102
53
|
return true;
|
|
103
54
|
}
|
|
104
55
|
|
|
56
|
+
bool RNSkMetalCanvasProvider::getLayoutSize(int *width, int *height) {
|
|
57
|
+
std::lock_guard<std::mutex> lock(_targetInfoMutex);
|
|
58
|
+
if (_layoutWidth <= 0 || _layoutHeight <= 0) {
|
|
59
|
+
return false;
|
|
60
|
+
}
|
|
61
|
+
*width = _layoutWidth;
|
|
62
|
+
*height = _layoutHeight;
|
|
63
|
+
return true;
|
|
64
|
+
}
|
|
65
|
+
|
|
105
66
|
bool RNSkMetalCanvasProvider::presentRecordings(
|
|
106
67
|
const std::vector<skgpu::graphite::Recording *> &recordings) {
|
|
107
68
|
if (!_ctx || ![[NSThread currentThread] isMainThread]) {
|
|
108
69
|
return false;
|
|
109
70
|
}
|
|
110
71
|
if (appIsBackgrounded()) {
|
|
111
|
-
|
|
72
|
+
requestRedraw();
|
|
112
73
|
return false;
|
|
113
74
|
}
|
|
114
75
|
return static_cast<RNSkia::DawnWindowContext *>(_ctx.get())
|
|
115
76
|
->presentRecordings(recordings);
|
|
116
77
|
}
|
|
117
|
-
|
|
78
|
+
|
|
79
|
+
bool RNSkMetalCanvasProvider::presentImage(const sk_sp<SkImage> &image) {
|
|
80
|
+
if (!_ctx || ![[NSThread currentThread] isMainThread]) {
|
|
81
|
+
return false;
|
|
82
|
+
}
|
|
83
|
+
if (appIsBackgrounded()) {
|
|
84
|
+
requestRedraw();
|
|
85
|
+
return false;
|
|
86
|
+
}
|
|
87
|
+
return static_cast<RNSkia::DawnWindowContext *>(_ctx.get())
|
|
88
|
+
->presentImage(image);
|
|
89
|
+
}
|
|
118
90
|
|
|
119
91
|
void RNSkMetalCanvasProvider::setSize(int width, int height) {
|
|
120
92
|
_layer.frame = CGRectMake(0, 0, width, height);
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
93
|
+
// The layout is on the pixel grid: round rather than truncate, so that a
|
|
94
|
+
// product like 1169.9999 gives the pixel size the layout means.
|
|
95
|
+
int w = static_cast<int>(std::lround(width * _context->getPixelDensity()));
|
|
96
|
+
int h = static_cast<int>(std::lround(height * _context->getPixelDensity()));
|
|
124
97
|
_ctx = RNSkia::DawnContext::getInstance().MakeWindow((__bridge void *)_layer,
|
|
125
98
|
w, h, _highBitDepth);
|
|
126
99
|
{
|
|
127
100
|
auto *window = static_cast<RNSkia::DawnWindowContext *>(_ctx.get());
|
|
128
101
|
std::lock_guard<std::mutex> lock(_targetInfoMutex);
|
|
102
|
+
_layoutWidth = w;
|
|
103
|
+
_layoutHeight = h;
|
|
129
104
|
_targetInfo.width = window->getWidth();
|
|
130
105
|
_targetInfo.height = window->getHeight();
|
|
131
106
|
_targetInfo.colorType = window->getColorType();
|
|
132
107
|
_targetInfo.textureInfo = window->getTextureInfo();
|
|
133
108
|
_hasTargetInfo = true;
|
|
134
109
|
}
|
|
135
|
-
|
|
136
|
-
_ctx = MetalContext::getInstance().MakeWindow(_layer, w, h, _useP3ColorSpace,
|
|
137
|
-
_highBitDepth);
|
|
138
|
-
#endif
|
|
139
|
-
_requestRedraw();
|
|
110
|
+
requestRedraw();
|
|
140
111
|
}
|
|
141
112
|
|
|
142
113
|
CALayer *RNSkMetalCanvasProvider::getLayer() { return _layer; }
|
|
143
114
|
|
|
144
|
-
void RNSkMetalCanvasProvider::setUseP3ColorSpace(bool useP3ColorSpace) {
|
|
145
|
-
_useP3ColorSpace = useP3ColorSpace;
|
|
146
|
-
}
|
|
147
|
-
|
|
148
115
|
void RNSkMetalCanvasProvider::setHighBitDepth(bool highBitDepth) {
|
|
149
116
|
if (_highBitDepth == highBitDepth) {
|
|
150
117
|
return;
|