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
|
@@ -1,172 +0,0 @@
|
|
|
1
|
-
#pragma once
|
|
2
|
-
|
|
3
|
-
#include <cstdint>
|
|
4
|
-
#include <memory>
|
|
5
|
-
#include <string>
|
|
6
|
-
#include <vector>
|
|
7
|
-
|
|
8
|
-
#include <fbjni/fbjni.h>
|
|
9
|
-
#include <jni.h>
|
|
10
|
-
#include <jsi/jsi.h>
|
|
11
|
-
|
|
12
|
-
#include "JniSkiaBaseView.h"
|
|
13
|
-
#include "JniSkiaManager.h"
|
|
14
|
-
#include "RNSkAndroidView.h"
|
|
15
|
-
#include "RNSkPictureView.h"
|
|
16
|
-
|
|
17
|
-
#include <android/native_window.h>
|
|
18
|
-
#include <android/native_window_jni.h>
|
|
19
|
-
#include <fbjni/detail/Hybrid.h>
|
|
20
|
-
|
|
21
|
-
#if defined(SK_GRAPHITE)
|
|
22
|
-
#include "RNDawnContext.h"
|
|
23
|
-
#else
|
|
24
|
-
#include "OpenGLContext.h"
|
|
25
|
-
#endif
|
|
26
|
-
#include "include/core/SkBitmap.h"
|
|
27
|
-
#include "include/core/SkCanvas.h"
|
|
28
|
-
#include "include/core/SkImage.h"
|
|
29
|
-
#include "include/core/SkPaint.h"
|
|
30
|
-
#include "include/core/SkPicture.h"
|
|
31
|
-
#include "include/core/SkPictureRecorder.h"
|
|
32
|
-
#include "include/core/SkSurface.h"
|
|
33
|
-
|
|
34
|
-
namespace RNSkia {
|
|
35
|
-
namespace jsi = facebook::jsi;
|
|
36
|
-
namespace jni = facebook::jni;
|
|
37
|
-
|
|
38
|
-
class JniSkiaPictureView : public jni::HybridClass<JniSkiaPictureView>,
|
|
39
|
-
public JniSkiaBaseView {
|
|
40
|
-
public:
|
|
41
|
-
static auto constexpr kJavaDescriptor =
|
|
42
|
-
"Lcom/reactnative/skia/SkiaPictureView;";
|
|
43
|
-
|
|
44
|
-
static jni::local_ref<jhybriddata>
|
|
45
|
-
initHybrid(jni::alias_ref<jhybridobject> jThis,
|
|
46
|
-
jni::alias_ref<JniSkiaManager::javaobject> skiaManager) {
|
|
47
|
-
return makeCxxInstance(jThis, skiaManager);
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
static void registerNatives() {
|
|
51
|
-
registerHybrid(
|
|
52
|
-
{makeNativeMethod("initHybrid", JniSkiaPictureView::initHybrid),
|
|
53
|
-
makeNativeMethod("surfaceAvailable",
|
|
54
|
-
JniSkiaPictureView::surfaceAvailable),
|
|
55
|
-
makeNativeMethod("surfaceDestroyed",
|
|
56
|
-
JniSkiaPictureView::surfaceDestroyed),
|
|
57
|
-
makeNativeMethod("surfaceSizeChanged",
|
|
58
|
-
JniSkiaPictureView::surfaceSizeChanged),
|
|
59
|
-
makeNativeMethod("setDebugMode", JniSkiaPictureView::setDebugMode),
|
|
60
|
-
makeNativeMethod("registerView", JniSkiaPictureView::registerView),
|
|
61
|
-
makeNativeMethod("unregisterView", JniSkiaPictureView::unregisterView),
|
|
62
|
-
makeNativeMethod("getBitmap", JniSkiaPictureView::getBitmap)});
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
protected:
|
|
66
|
-
void surfaceAvailable(jobject surface, int width, int height, bool isSurface,
|
|
67
|
-
bool highBitDepth) override {
|
|
68
|
-
JniSkiaBaseView::surfaceAvailable(surface, width, height, isSurface,
|
|
69
|
-
highBitDepth);
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
void surfaceSizeChanged(jobject surface, int width, int height,
|
|
73
|
-
bool isSurface, bool highBitDepth) override {
|
|
74
|
-
JniSkiaBaseView::surfaceSizeChanged(surface, width, height, isSurface,
|
|
75
|
-
highBitDepth);
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
void surfaceDestroyed() override { JniSkiaBaseView::surfaceDestroyed(); }
|
|
79
|
-
|
|
80
|
-
void setDebugMode(bool show) override { JniSkiaBaseView::setDebugMode(show); }
|
|
81
|
-
|
|
82
|
-
void registerView(int nativeId) override {
|
|
83
|
-
JniSkiaBaseView::registerView(nativeId);
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
void unregisterView() override { JniSkiaBaseView::unregisterView(); }
|
|
87
|
-
|
|
88
|
-
jni::local_ref<jni::JArrayInt> getBitmap(int width, int height) override {
|
|
89
|
-
// Get the RNSkPictureView from the android view
|
|
90
|
-
auto pictureView =
|
|
91
|
-
std::static_pointer_cast<RNSkAndroidView<RNSkia::RNSkPictureView>>(
|
|
92
|
-
_skiaAndroidView);
|
|
93
|
-
if (!pictureView) {
|
|
94
|
-
return JniSkiaBaseView::getBitmap(width, height);
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
// Get the renderer and cast it to RNSkPictureRenderer
|
|
98
|
-
auto renderer = std::static_pointer_cast<RNSkia::RNSkPictureRenderer>(
|
|
99
|
-
pictureView->getRenderer());
|
|
100
|
-
if (!renderer) {
|
|
101
|
-
return jni::JArrayInt::newArray(0);
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
const size_t pixelCount =
|
|
105
|
-
static_cast<size_t>(width) * static_cast<size_t>(height);
|
|
106
|
-
if (pixelCount == 0) {
|
|
107
|
-
return jni::JArrayInt::newArray(0);
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
sk_sp<SkSurface> surface;
|
|
111
|
-
#if defined(SK_GRAPHITE)
|
|
112
|
-
surface = DawnContext::getInstance().MakeOffscreen(width, height);
|
|
113
|
-
#else
|
|
114
|
-
surface = OpenGLContext::getInstance().MakeOffscreen(width, height);
|
|
115
|
-
#endif
|
|
116
|
-
|
|
117
|
-
if (!surface) {
|
|
118
|
-
return jni::JArrayInt::newArray(0);
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
SkCanvas *canvas = surface->getCanvas();
|
|
122
|
-
if (canvas == nullptr) {
|
|
123
|
-
return jni::JArrayInt::newArray(0);
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
// Draws whatever the view currently shows: a picture or a recorder.
|
|
127
|
-
renderer->drawInto(canvas, pictureView->getPixelDensity());
|
|
128
|
-
|
|
129
|
-
sk_sp<SkImage> snapshot = surface->makeImageSnapshot();
|
|
130
|
-
if (!snapshot) {
|
|
131
|
-
return jni::JArrayInt::newArray(0);
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
sk_sp<SkImage> image = snapshot->makeNonTextureImage();
|
|
135
|
-
if (!image) {
|
|
136
|
-
return jni::JArrayInt::newArray(0);
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
if (!image) {
|
|
140
|
-
return jni::JArrayInt::newArray(0);
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
std::vector<int32_t> pixels(pixelCount);
|
|
144
|
-
SkImageInfo readInfo = SkImageInfo::Make(
|
|
145
|
-
width, height, kBGRA_8888_SkColorType, kPremul_SkAlphaType);
|
|
146
|
-
size_t rowBytes = static_cast<size_t>(width) * sizeof(int32_t);
|
|
147
|
-
if (!image->readPixels(nullptr, readInfo, pixels.data(), rowBytes, 0, 0)) {
|
|
148
|
-
return jni::JArrayInt::newArray(0);
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
auto intArray = jni::JArrayInt::newArray(pixelCount);
|
|
152
|
-
intArray->setRegion(0, pixelCount,
|
|
153
|
-
reinterpret_cast<const jint *>(pixels.data()));
|
|
154
|
-
|
|
155
|
-
return intArray;
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
private:
|
|
159
|
-
friend HybridBase;
|
|
160
|
-
|
|
161
|
-
explicit JniSkiaPictureView(
|
|
162
|
-
jni::alias_ref<jhybridobject> jThis,
|
|
163
|
-
jni::alias_ref<JniSkiaManager::javaobject> skiaManager)
|
|
164
|
-
: JniSkiaBaseView(
|
|
165
|
-
skiaManager,
|
|
166
|
-
std::make_shared<RNSkAndroidView<RNSkia::RNSkPictureView>>(
|
|
167
|
-
skiaManager->cthis()->getPlatformContext())) {}
|
|
168
|
-
|
|
169
|
-
jni::global_ref<javaobject> javaPart_;
|
|
170
|
-
};
|
|
171
|
-
|
|
172
|
-
} // namespace RNSkia
|
|
@@ -1,245 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright 2023 Google LLC
|
|
3
|
-
*
|
|
4
|
-
* Use of this source code is governed by a BSD-style license that can be
|
|
5
|
-
* found in the LICENSE file.
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
#include "GrAHardwareBufferUtils.h"
|
|
9
|
-
#if __ANDROID_API__ >= 26
|
|
10
|
-
|
|
11
|
-
#define GL_GLEXT_PROTOTYPES
|
|
12
|
-
#define EGL_EGLEXT_PROTOTYPES
|
|
13
|
-
|
|
14
|
-
#include "include/gpu/ganesh/GrBackendSurface.h"
|
|
15
|
-
#include "include/gpu/ganesh/GrDirectContext.h"
|
|
16
|
-
#include "include/gpu/ganesh/gl/GrGLBackendSurface.h"
|
|
17
|
-
#include "include/gpu/ganesh/gl/GrGLTypes.h"
|
|
18
|
-
#include "src/gpu/ganesh/gl/GrGLDefines.h"
|
|
19
|
-
// #include "src/gpu/ganesh/GrDirectContextPriv.h"
|
|
20
|
-
// #include "src/gpu/ganesh/gl/GrGLUtil.h"
|
|
21
|
-
|
|
22
|
-
#include <EGL/egl.h>
|
|
23
|
-
#include <EGL/eglext.h>
|
|
24
|
-
#include <GLES/gl.h>
|
|
25
|
-
#include <GLES/glext.h>
|
|
26
|
-
#include <android/hardware_buffer.h>
|
|
27
|
-
|
|
28
|
-
#define PROT_CONTENT_EXT_STR "EGL_EXT_protected_content"
|
|
29
|
-
#define EGL_PROTECTED_CONTENT_EXT 0x32C0
|
|
30
|
-
|
|
31
|
-
namespace RNSkia {
|
|
32
|
-
|
|
33
|
-
typedef EGLClientBuffer (*EGLGetNativeClientBufferANDROIDProc)(
|
|
34
|
-
const struct AHardwareBuffer *);
|
|
35
|
-
typedef EGLImageKHR (*EGLCreateImageKHRProc)(EGLDisplay, EGLContext, EGLenum,
|
|
36
|
-
EGLClientBuffer, const EGLint *);
|
|
37
|
-
typedef void (*EGLImageTargetTexture2DOESProc)(EGLenum, void *);
|
|
38
|
-
|
|
39
|
-
GrBackendFormat GetGLBackendFormat(GrDirectContext *dContext,
|
|
40
|
-
uint32_t bufferFormat,
|
|
41
|
-
bool requireKnownFormat) {
|
|
42
|
-
GrBackendApi backend = dContext->backend();
|
|
43
|
-
if (backend != GrBackendApi::kOpenGL) {
|
|
44
|
-
return {};
|
|
45
|
-
}
|
|
46
|
-
switch (bufferFormat) {
|
|
47
|
-
// TODO: find out if we can detect, which graphic buffers support
|
|
48
|
-
// GR_GL_TEXTURE_2D
|
|
49
|
-
case AHARDWAREBUFFER_FORMAT_R8G8B8A8_UNORM:
|
|
50
|
-
case AHARDWAREBUFFER_FORMAT_R8G8B8X8_UNORM:
|
|
51
|
-
return GrBackendFormats::MakeGL(GR_GL_RGBA8, GR_GL_TEXTURE_EXTERNAL);
|
|
52
|
-
case AHARDWAREBUFFER_FORMAT_R16G16B16A16_FLOAT:
|
|
53
|
-
return GrBackendFormats::MakeGL(GR_GL_RGBA16F, GR_GL_TEXTURE_EXTERNAL);
|
|
54
|
-
case AHARDWAREBUFFER_FORMAT_R5G6B5_UNORM:
|
|
55
|
-
return GrBackendFormats::MakeGL(GR_GL_RGB565, GR_GL_TEXTURE_EXTERNAL);
|
|
56
|
-
case AHARDWAREBUFFER_FORMAT_R10G10B10A2_UNORM:
|
|
57
|
-
return GrBackendFormats::MakeGL(GR_GL_RGB10_A2, GR_GL_TEXTURE_EXTERNAL);
|
|
58
|
-
case AHARDWAREBUFFER_FORMAT_R8G8B8_UNORM:
|
|
59
|
-
return GrBackendFormats::MakeGL(GR_GL_RGB8, GR_GL_TEXTURE_EXTERNAL);
|
|
60
|
-
#if __ANDROID_API__ >= 33
|
|
61
|
-
case AHARDWAREBUFFER_FORMAT_R8_UNORM:
|
|
62
|
-
return GrBackendFormats::MakeGL(GR_GL_R8, GR_GL_TEXTURE_EXTERNAL);
|
|
63
|
-
#endif
|
|
64
|
-
default:
|
|
65
|
-
if (requireKnownFormat) {
|
|
66
|
-
return {};
|
|
67
|
-
} else {
|
|
68
|
-
return GrBackendFormats::MakeGL(GR_GL_RGBA8, GR_GL_TEXTURE_EXTERNAL);
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
SkUNREACHABLE;
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
class GLTextureHelper {
|
|
75
|
-
public:
|
|
76
|
-
GLTextureHelper(GrGLuint texID, EGLImageKHR image, EGLDisplay display,
|
|
77
|
-
GrGLuint texTarget)
|
|
78
|
-
: fTexID(texID), fImage(image), fDisplay(display), fTexTarget(texTarget) {
|
|
79
|
-
}
|
|
80
|
-
~GLTextureHelper() {
|
|
81
|
-
glDeleteTextures(1, &fTexID);
|
|
82
|
-
// eglDestroyImageKHR will remove a ref from the AHardwareBuffer
|
|
83
|
-
eglDestroyImageKHR(fDisplay, fImage);
|
|
84
|
-
}
|
|
85
|
-
void rebind(GrDirectContext *);
|
|
86
|
-
|
|
87
|
-
private:
|
|
88
|
-
GrGLuint fTexID;
|
|
89
|
-
EGLImageKHR fImage;
|
|
90
|
-
EGLDisplay fDisplay;
|
|
91
|
-
GrGLuint fTexTarget;
|
|
92
|
-
};
|
|
93
|
-
|
|
94
|
-
void GLTextureHelper::rebind(GrDirectContext *dContext) {
|
|
95
|
-
glBindTexture(fTexTarget, fTexID);
|
|
96
|
-
GLenum status = GL_NO_ERROR;
|
|
97
|
-
if ((status = glGetError()) != GL_NO_ERROR) {
|
|
98
|
-
SkDebugf("glBindTexture(%#x, %d) failed (%#x)",
|
|
99
|
-
static_cast<int>(fTexTarget), static_cast<int>(fTexID),
|
|
100
|
-
static_cast<int>(status));
|
|
101
|
-
return;
|
|
102
|
-
}
|
|
103
|
-
glEGLImageTargetTexture2DOES(fTexTarget, fImage);
|
|
104
|
-
if ((status = glGetError()) != GL_NO_ERROR) {
|
|
105
|
-
SkDebugf("glEGLImageTargetTexture2DOES failed (%#x)",
|
|
106
|
-
static_cast<int>(status));
|
|
107
|
-
return;
|
|
108
|
-
}
|
|
109
|
-
dContext->resetContext(kTextureBinding_GrGLBackendState);
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
void delete_gl_texture(void *context) {
|
|
113
|
-
auto cleanupHelper = static_cast<GLTextureHelper *>(context);
|
|
114
|
-
delete cleanupHelper;
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
void update_gl_texture(void *context, GrDirectContext *dContext) {
|
|
118
|
-
auto cleanupHelper = static_cast<GLTextureHelper *>(context);
|
|
119
|
-
cleanupHelper->rebind(dContext);
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
static GrBackendTexture make_gl_backend_texture(
|
|
123
|
-
GrDirectContext *dContext, AHardwareBuffer *hardwareBuffer, int width,
|
|
124
|
-
int height, DeleteImageProc *deleteProc, UpdateImageProc *updateProc,
|
|
125
|
-
TexImageCtx *imageCtx, bool isProtectedContent,
|
|
126
|
-
const GrBackendFormat &backendFormat, bool isRenderable) {
|
|
127
|
-
while (GL_NO_ERROR != glGetError()) {
|
|
128
|
-
} // clear GL errors
|
|
129
|
-
|
|
130
|
-
auto eglGetNativeClientBufferANDROID =
|
|
131
|
-
(EGLGetNativeClientBufferANDROIDProc)eglGetProcAddress(
|
|
132
|
-
"eglGetNativeClientBufferANDROID");
|
|
133
|
-
if (!eglGetNativeClientBufferANDROID) {
|
|
134
|
-
RNSkLogger::logToConsole(
|
|
135
|
-
"Failed to get the eglGetNativeClientBufferAndroid proc");
|
|
136
|
-
return {};
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
EGLClientBuffer clientBuffer =
|
|
140
|
-
eglGetNativeClientBufferANDROID(hardwareBuffer);
|
|
141
|
-
EGLint attribs[] = {EGL_IMAGE_PRESERVED_KHR, EGL_TRUE,
|
|
142
|
-
isProtectedContent ? EGL_PROTECTED_CONTENT_EXT : EGL_NONE,
|
|
143
|
-
isProtectedContent ? EGL_TRUE : EGL_NONE, EGL_NONE};
|
|
144
|
-
EGLDisplay display = eglGetCurrentDisplay();
|
|
145
|
-
// eglCreateImageKHR will add a ref to the AHardwareBuffer
|
|
146
|
-
EGLImageKHR image =
|
|
147
|
-
eglCreateImageKHR(display, EGL_NO_CONTEXT, EGL_NATIVE_BUFFER_ANDROID,
|
|
148
|
-
clientBuffer, attribs);
|
|
149
|
-
if (EGL_NO_IMAGE_KHR == image) {
|
|
150
|
-
SkDebugf("Could not create EGL image, err = (%#x)",
|
|
151
|
-
static_cast<int>(eglGetError()));
|
|
152
|
-
return {};
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
GrGLuint texID;
|
|
156
|
-
glGenTextures(1, &texID);
|
|
157
|
-
if (!texID) {
|
|
158
|
-
eglDestroyImageKHR(display, image);
|
|
159
|
-
return {};
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
GrGLuint target = isRenderable ? GR_GL_TEXTURE_2D : GR_GL_TEXTURE_EXTERNAL;
|
|
163
|
-
|
|
164
|
-
glBindTexture(target, texID);
|
|
165
|
-
GLenum status = GL_NO_ERROR;
|
|
166
|
-
if ((status = glGetError()) != GL_NO_ERROR) {
|
|
167
|
-
SkDebugf("glBindTexture failed (%#x)", static_cast<int>(status));
|
|
168
|
-
glDeleteTextures(1, &texID);
|
|
169
|
-
eglDestroyImageKHR(display, image);
|
|
170
|
-
return {};
|
|
171
|
-
}
|
|
172
|
-
glEGLImageTargetTexture2DOES(target, image);
|
|
173
|
-
if ((status = glGetError()) != GL_NO_ERROR) {
|
|
174
|
-
SkDebugf("glEGLImageTargetTexture2DOES failed (%#x)",
|
|
175
|
-
static_cast<int>(status));
|
|
176
|
-
glDeleteTextures(1, &texID);
|
|
177
|
-
eglDestroyImageKHR(display, image);
|
|
178
|
-
return {};
|
|
179
|
-
}
|
|
180
|
-
dContext->resetContext(kTextureBinding_GrGLBackendState);
|
|
181
|
-
|
|
182
|
-
GrGLTextureInfo textureInfo;
|
|
183
|
-
textureInfo.fID = texID;
|
|
184
|
-
SkASSERT(backendFormat.isValid());
|
|
185
|
-
textureInfo.fTarget = target;
|
|
186
|
-
textureInfo.fFormat = GrBackendFormats::AsGLFormatEnum(backendFormat);
|
|
187
|
-
textureInfo.fProtected = skgpu::Protected(isProtectedContent);
|
|
188
|
-
|
|
189
|
-
*deleteProc = delete_gl_texture;
|
|
190
|
-
*updateProc = update_gl_texture;
|
|
191
|
-
*imageCtx = new GLTextureHelper(texID, image, display, target);
|
|
192
|
-
|
|
193
|
-
return GrBackendTextures::MakeGL(width, height, skgpu::Mipmapped::kNo,
|
|
194
|
-
textureInfo);
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
static bool can_import_protected_content_eglimpl() {
|
|
198
|
-
EGLDisplay dpy = eglGetDisplay(EGL_DEFAULT_DISPLAY);
|
|
199
|
-
const char *exts = eglQueryString(dpy, EGL_EXTENSIONS);
|
|
200
|
-
size_t cropExtLen = strlen(PROT_CONTENT_EXT_STR);
|
|
201
|
-
size_t extsLen = strlen(exts);
|
|
202
|
-
bool equal = !strcmp(PROT_CONTENT_EXT_STR, exts);
|
|
203
|
-
bool atStart = !strncmp(PROT_CONTENT_EXT_STR " ", exts, cropExtLen + 1);
|
|
204
|
-
bool atEnd =
|
|
205
|
-
(cropExtLen + 1) < extsLen &&
|
|
206
|
-
!strcmp(" " PROT_CONTENT_EXT_STR, exts + extsLen - (cropExtLen + 1));
|
|
207
|
-
bool inMiddle = strstr(exts, " " PROT_CONTENT_EXT_STR " ");
|
|
208
|
-
return equal || atStart || atEnd || inMiddle;
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
static bool can_import_protected_content(GrDirectContext *dContext) {
|
|
212
|
-
SkASSERT(GrBackendApi::kOpenGL == dContext->backend());
|
|
213
|
-
// Only compute whether the extension is present once the first time this
|
|
214
|
-
// function is called.
|
|
215
|
-
static bool hasIt = can_import_protected_content_eglimpl();
|
|
216
|
-
return hasIt;
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
GrBackendTexture
|
|
220
|
-
MakeGLBackendTexture(GrDirectContext *dContext, AHardwareBuffer *hardwareBuffer,
|
|
221
|
-
int width, int height, DeleteImageProc *deleteProc,
|
|
222
|
-
UpdateImageProc *updateProc, TexImageCtx *imageCtx,
|
|
223
|
-
bool isProtectedContent,
|
|
224
|
-
const GrBackendFormat &backendFormat, bool isRenderable) {
|
|
225
|
-
SkASSERT(dContext);
|
|
226
|
-
if (dContext->abandoned()) {
|
|
227
|
-
return {};
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
if (GrBackendApi::kOpenGL != dContext->backend()) {
|
|
231
|
-
return {};
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
if (isProtectedContent && !can_import_protected_content(dContext)) {
|
|
235
|
-
return {};
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
return make_gl_backend_texture(
|
|
239
|
-
dContext, hardwareBuffer, width, height, deleteProc, updateProc, imageCtx,
|
|
240
|
-
isProtectedContent, backendFormat, isRenderable);
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
} // namespace RNSkia
|
|
244
|
-
|
|
245
|
-
#endif
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
#pragma once
|
|
2
|
-
|
|
3
|
-
#include "include/core/SkTypes.h"
|
|
4
|
-
|
|
5
|
-
#include "RNSkLog.h"
|
|
6
|
-
|
|
7
|
-
#if __ANDROID_API__ >= 26
|
|
8
|
-
|
|
9
|
-
#include "include/gpu/ganesh/GrBackendSurface.h"
|
|
10
|
-
#include "include/gpu/ganesh/GrTypes.h"
|
|
11
|
-
|
|
12
|
-
class GrDirectContext;
|
|
13
|
-
|
|
14
|
-
extern "C" {
|
|
15
|
-
typedef struct AHardwareBuffer AHardwareBuffer;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
namespace RNSkia {
|
|
19
|
-
|
|
20
|
-
typedef void *TexImageCtx;
|
|
21
|
-
typedef void (*DeleteImageProc)(TexImageCtx);
|
|
22
|
-
typedef void (*UpdateImageProc)(TexImageCtx, GrDirectContext *);
|
|
23
|
-
|
|
24
|
-
GrBackendTexture
|
|
25
|
-
MakeGLBackendTexture(GrDirectContext *dContext, AHardwareBuffer *hardwareBuffer,
|
|
26
|
-
int width, int height, DeleteImageProc *deleteProc,
|
|
27
|
-
UpdateImageProc *updateProc, TexImageCtx *imageCtx,
|
|
28
|
-
bool isProtectedContent,
|
|
29
|
-
const GrBackendFormat &backendFormat, bool isRenderable);
|
|
30
|
-
|
|
31
|
-
} // namespace RNSkia
|
|
32
|
-
|
|
33
|
-
#endif
|
|
@@ -1,248 +0,0 @@
|
|
|
1
|
-
#pragma once
|
|
2
|
-
|
|
3
|
-
#include "GrAHardwareBufferUtils.h"
|
|
4
|
-
#include "OpenGLWindowContext.h"
|
|
5
|
-
#include "gl/Display.h"
|
|
6
|
-
|
|
7
|
-
#include "include/core/SkCanvas.h"
|
|
8
|
-
#include "include/core/SkColorSpace.h"
|
|
9
|
-
#include "include/core/SkSurface.h"
|
|
10
|
-
#include "include/gpu/ganesh/GrDirectContext.h"
|
|
11
|
-
#include "include/gpu/ganesh/SkImageGanesh.h"
|
|
12
|
-
#include "include/gpu/ganesh/gl/GrGLBackendSurface.h"
|
|
13
|
-
#include "include/gpu/ganesh/gl/GrGLDirectContext.h"
|
|
14
|
-
#include "include/gpu/ganesh/gl/GrGLInterface.h"
|
|
15
|
-
#include "src/gpu/ganesh/gl/GrGLDefines.h"
|
|
16
|
-
|
|
17
|
-
namespace RNSkia {
|
|
18
|
-
|
|
19
|
-
class OpenGLSharedContext {
|
|
20
|
-
public:
|
|
21
|
-
OpenGLSharedContext(const OpenGLSharedContext &) = delete;
|
|
22
|
-
OpenGLSharedContext &operator=(const OpenGLSharedContext &) = delete;
|
|
23
|
-
|
|
24
|
-
static OpenGLSharedContext &getInstance() {
|
|
25
|
-
static OpenGLSharedContext instance;
|
|
26
|
-
return instance;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
gl::Display *getDisplay() { return _glDisplay.get(); }
|
|
30
|
-
gl::Context *getContext() { return _glContext.get(); }
|
|
31
|
-
gl::Surface *getSurface() { return _glSurface.get(); }
|
|
32
|
-
EGLConfig getConfig() { return _glConfig; }
|
|
33
|
-
|
|
34
|
-
private:
|
|
35
|
-
std::unique_ptr<gl::Display> _glDisplay;
|
|
36
|
-
std::unique_ptr<gl::Context> _glContext;
|
|
37
|
-
std::unique_ptr<gl::Surface> _glSurface;
|
|
38
|
-
EGLConfig _glConfig;
|
|
39
|
-
|
|
40
|
-
OpenGLSharedContext() {
|
|
41
|
-
_glDisplay = std::make_unique<gl::Display>();
|
|
42
|
-
_glConfig = _glDisplay->chooseConfig();
|
|
43
|
-
_glContext = _glDisplay->makeContext(_glConfig, nullptr);
|
|
44
|
-
_glSurface = _glDisplay->makePixelBufferSurface(_glConfig, 1, 1);
|
|
45
|
-
if (_glContext == nullptr || _glSurface == nullptr) {
|
|
46
|
-
RNSkLogger::logToConsole(
|
|
47
|
-
"Couldn't create the shared OpenGL context or surface");
|
|
48
|
-
return;
|
|
49
|
-
}
|
|
50
|
-
_glContext->makeCurrent(_glSurface.get());
|
|
51
|
-
}
|
|
52
|
-
};
|
|
53
|
-
|
|
54
|
-
class OpenGLContext {
|
|
55
|
-
public:
|
|
56
|
-
friend class OpenGLWindowContext;
|
|
57
|
-
|
|
58
|
-
OpenGLContext(const OpenGLContext &) = delete;
|
|
59
|
-
OpenGLContext &operator=(const OpenGLContext &) = delete;
|
|
60
|
-
|
|
61
|
-
static OpenGLContext &getInstance() {
|
|
62
|
-
static thread_local OpenGLContext instance;
|
|
63
|
-
return instance;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
sk_sp<SkSurface> MakeOffscreen(int width, int height,
|
|
67
|
-
bool useP3ColorSpace = false) {
|
|
68
|
-
if (_directContext == nullptr) {
|
|
69
|
-
return nullptr;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
auto colorType = kRGBA_8888_SkColorType;
|
|
73
|
-
|
|
74
|
-
SkSurfaceProps props(0, kUnknown_SkPixelGeometry);
|
|
75
|
-
|
|
76
|
-
auto result = _glContext->makeCurrent(_glSurface.get());
|
|
77
|
-
if (!result) {
|
|
78
|
-
return nullptr;
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
// Create texture
|
|
82
|
-
auto GL_RGBA8 = 0x8058;
|
|
83
|
-
auto format = GrBackendFormats::MakeGL(GL_RGBA8, GL_TEXTURE_2D);
|
|
84
|
-
auto texture = _directContext->createBackendTexture(
|
|
85
|
-
width, height, format, SkColors::kTransparent, skgpu::Mipmapped::kNo,
|
|
86
|
-
GrRenderable::kYes);
|
|
87
|
-
|
|
88
|
-
if (!texture.isValid()) {
|
|
89
|
-
RNSkLogger::logToConsole("couldn't create offscreen texture %dx%d", width,
|
|
90
|
-
height);
|
|
91
|
-
return nullptr;
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
struct ReleaseContext {
|
|
95
|
-
GrDirectContext *directContext;
|
|
96
|
-
GrBackendTexture texture;
|
|
97
|
-
};
|
|
98
|
-
|
|
99
|
-
auto releaseCtx = new ReleaseContext{.directContext = _directContext.get(),
|
|
100
|
-
.texture = texture};
|
|
101
|
-
|
|
102
|
-
sk_sp<SkColorSpace> colorSpace =
|
|
103
|
-
useP3ColorSpace ? SkColorSpace::MakeRGB(SkNamedTransferFn::kSRGB,
|
|
104
|
-
SkNamedGamut::kDisplayP3)
|
|
105
|
-
: nullptr;
|
|
106
|
-
|
|
107
|
-
// Create a SkSurface from the GrBackendTexture
|
|
108
|
-
return SkSurfaces::WrapBackendTexture(
|
|
109
|
-
_directContext.get(), texture, kTopLeft_GrSurfaceOrigin, 0, colorType,
|
|
110
|
-
colorSpace, &props,
|
|
111
|
-
[](void *addr) {
|
|
112
|
-
auto releaseCtx = reinterpret_cast<ReleaseContext *>(addr);
|
|
113
|
-
releaseCtx->directContext->deleteBackendTexture(releaseCtx->texture);
|
|
114
|
-
delete releaseCtx;
|
|
115
|
-
},
|
|
116
|
-
releaseCtx);
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
sk_sp<SkImage> MakeImageFromBuffer(void *buffer,
|
|
120
|
-
bool requireKnownFormat = false) {
|
|
121
|
-
#if __ANDROID_API__ >= 26
|
|
122
|
-
if (_directContext == nullptr) {
|
|
123
|
-
return nullptr;
|
|
124
|
-
}
|
|
125
|
-
const AHardwareBuffer *hardwareBuffer =
|
|
126
|
-
static_cast<AHardwareBuffer *>(buffer);
|
|
127
|
-
DeleteImageProc deleteImageProc = nullptr;
|
|
128
|
-
UpdateImageProc updateImageProc = nullptr;
|
|
129
|
-
TexImageCtx deleteImageCtx = nullptr;
|
|
130
|
-
|
|
131
|
-
AHardwareBuffer_Desc description;
|
|
132
|
-
AHardwareBuffer_describe(hardwareBuffer, &description);
|
|
133
|
-
GrBackendFormat format;
|
|
134
|
-
auto colorType = kRGBA_8888_SkColorType;
|
|
135
|
-
switch (description.format) {
|
|
136
|
-
// TODO: find out if we can detect, which graphic buffers support
|
|
137
|
-
// GR_GL_TEXTURE_2D
|
|
138
|
-
case AHARDWAREBUFFER_FORMAT_R8G8B8A8_UNORM:
|
|
139
|
-
format = GrBackendFormats::MakeGL(GR_GL_RGBA8, GR_GL_TEXTURE_EXTERNAL);
|
|
140
|
-
colorType = kRGBA_8888_SkColorType;
|
|
141
|
-
break;
|
|
142
|
-
case AHARDWAREBUFFER_FORMAT_R16G16B16A16_FLOAT:
|
|
143
|
-
format = GrBackendFormats::MakeGL(GR_GL_RGBA16F, GR_GL_TEXTURE_EXTERNAL);
|
|
144
|
-
colorType = kRGBA_F16_SkColorType;
|
|
145
|
-
break;
|
|
146
|
-
case AHARDWAREBUFFER_FORMAT_R5G6B5_UNORM:
|
|
147
|
-
format = GrBackendFormats::MakeGL(GR_GL_RGB565, GR_GL_TEXTURE_EXTERNAL);
|
|
148
|
-
colorType = kRGB_565_SkColorType;
|
|
149
|
-
break;
|
|
150
|
-
case AHARDWAREBUFFER_FORMAT_R10G10B10A2_UNORM:
|
|
151
|
-
format = GrBackendFormats::MakeGL(GR_GL_RGB10_A2, GR_GL_TEXTURE_EXTERNAL);
|
|
152
|
-
colorType = kRGBA_1010102_SkColorType;
|
|
153
|
-
break;
|
|
154
|
-
case AHARDWAREBUFFER_FORMAT_R8G8B8_UNORM:
|
|
155
|
-
format = GrBackendFormats::MakeGL(GR_GL_RGB8, GR_GL_TEXTURE_EXTERNAL);
|
|
156
|
-
colorType = kRGB_888x_SkColorType;
|
|
157
|
-
break;
|
|
158
|
-
#if __ANDROID_API__ >= 33
|
|
159
|
-
case AHARDWAREBUFFER_FORMAT_R8_UNORM:
|
|
160
|
-
format = GrBackendFormats::MakeGL(GR_GL_R8, GR_GL_TEXTURE_EXTERNAL);
|
|
161
|
-
colorType = kAlpha_8_SkColorType;
|
|
162
|
-
break;
|
|
163
|
-
#endif
|
|
164
|
-
default:
|
|
165
|
-
if (requireKnownFormat) {
|
|
166
|
-
format = GrBackendFormat();
|
|
167
|
-
} else {
|
|
168
|
-
format = GrBackendFormats::MakeGL(GR_GL_RGBA8, GR_GL_TEXTURE_EXTERNAL);
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
auto width = static_cast<int>(description.width);
|
|
172
|
-
auto height = static_cast<int>(description.height);
|
|
173
|
-
auto backendTex = MakeGLBackendTexture(
|
|
174
|
-
_directContext.get(), const_cast<AHardwareBuffer *>(hardwareBuffer),
|
|
175
|
-
width, height, &deleteImageProc, &updateImageProc, &deleteImageCtx,
|
|
176
|
-
false, format, false);
|
|
177
|
-
if (!backendTex.isValid()) {
|
|
178
|
-
RNSkLogger::logToConsole(
|
|
179
|
-
"Failed to convert HardwareBuffer to OpenGL Texture!");
|
|
180
|
-
return nullptr;
|
|
181
|
-
}
|
|
182
|
-
sk_sp<SkImage> image = SkImages::BorrowTextureFrom(
|
|
183
|
-
_directContext.get(), backendTex, kTopLeft_GrSurfaceOrigin, colorType,
|
|
184
|
-
kOpaque_SkAlphaType, nullptr, deleteImageProc, deleteImageCtx);
|
|
185
|
-
return image;
|
|
186
|
-
#else
|
|
187
|
-
throw std::runtime_error(
|
|
188
|
-
"HardwareBuffers are only supported on Android API 26 or higher! Set "
|
|
189
|
-
"your minSdk to 26 (or higher) and try again.");
|
|
190
|
-
#endif
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
// TODO: remove width, height
|
|
194
|
-
std::unique_ptr<WindowContext> MakeWindow(ANativeWindow *window,
|
|
195
|
-
bool highBitDepth = false) {
|
|
196
|
-
if (_directContext == nullptr) {
|
|
197
|
-
RNSkLogger::logToConsole(
|
|
198
|
-
"The OpenGL context is invalid, the surface will not be rendered");
|
|
199
|
-
return nullptr;
|
|
200
|
-
}
|
|
201
|
-
auto display = OpenGLSharedContext::getInstance().getDisplay();
|
|
202
|
-
if (highBitDepth) {
|
|
203
|
-
// A 10-bit window surface would require the shared EGL context to be
|
|
204
|
-
// created without a config (EGL_KHR_no_config_context) for every app,
|
|
205
|
-
// which is too risky for existing 8-bit clients on brittle drivers.
|
|
206
|
-
RNSkLogger::logToConsole(
|
|
207
|
-
"highBitDepth is not supported on the OpenGL backend, falling back "
|
|
208
|
-
"to the 8-bit format (the Graphite backend supports it)");
|
|
209
|
-
}
|
|
210
|
-
return std::make_unique<OpenGLWindowContext>(
|
|
211
|
-
_directContext.get(), display, _glContext.get(), window,
|
|
212
|
-
OpenGLSharedContext::getInstance().getConfig());
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
GrDirectContext *getDirectContext() { return _directContext.get(); }
|
|
216
|
-
void makeCurrent() {
|
|
217
|
-
if (_glContext != nullptr) {
|
|
218
|
-
_glContext->makeCurrent(_glSurface.get());
|
|
219
|
-
}
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
private:
|
|
223
|
-
std::unique_ptr<gl::Context> _glContext;
|
|
224
|
-
std::unique_ptr<gl::Surface> _glSurface;
|
|
225
|
-
sk_sp<GrDirectContext> _directContext;
|
|
226
|
-
|
|
227
|
-
OpenGLContext() {
|
|
228
|
-
auto display = OpenGLSharedContext::getInstance().getDisplay();
|
|
229
|
-
auto sharedContext = OpenGLSharedContext::getInstance().getContext();
|
|
230
|
-
auto glConfig = OpenGLSharedContext::getInstance().getConfig();
|
|
231
|
-
_glContext = display->makeContext(glConfig, sharedContext);
|
|
232
|
-
_glSurface = display->makePixelBufferSurface(glConfig, 1, 1);
|
|
233
|
-
if (_glContext == nullptr || _glSurface == nullptr ||
|
|
234
|
-
!_glContext->makeCurrent(_glSurface.get())) {
|
|
235
|
-
RNSkLogger::logToConsole(
|
|
236
|
-
"Couldn't create the OpenGL context, Skia rendering is disabled");
|
|
237
|
-
return;
|
|
238
|
-
}
|
|
239
|
-
auto backendInterface = GrGLMakeNativeInterface();
|
|
240
|
-
_directContext = GrDirectContexts::MakeGL(backendInterface);
|
|
241
|
-
|
|
242
|
-
if (_directContext == nullptr) {
|
|
243
|
-
RNSkLogger::logToConsole("GrDirectContexts::MakeGL failed");
|
|
244
|
-
}
|
|
245
|
-
}
|
|
246
|
-
};
|
|
247
|
-
|
|
248
|
-
} // namespace RNSkia
|