@shopify/react-native-skia 1.5.3 → 1.5.5
Sign up to get free protection for your applications and to get access to all the features.
- package/android/CMakeLists.txt +53 -13
- package/android/build.gradle +3 -0
- package/android/cpp/rnskia-android/OpenGLContext.h +122 -11
- package/android/cpp/rnskia-android/OpenGLWindowContext.cpp +73 -0
- package/android/cpp/rnskia-android/OpenGLWindowContext.h +74 -0
- package/android/cpp/rnskia-android/RNSkAndroidPlatformContext.h +18 -1
- package/android/cpp/rnskia-android/RNSkAndroidVideo.cpp +12 -1
- package/android/cpp/rnskia-android/RNSkOpenGLCanvasProvider.cpp +13 -1
- package/android/cpp/rnskia-android/opengl/Context.h +77 -0
- package/android/cpp/rnskia-android/opengl/Display.h +117 -0
- package/android/cpp/rnskia-android/opengl/Error.cpp +9 -0
- package/android/cpp/rnskia-android/opengl/Error.h +44 -0
- package/android/cpp/rnskia-android/opengl/Surface.h +43 -0
- package/android/src/main/java/com/shopify/reactnative/skia/SkiaBaseView.java +0 -1
- package/cpp/api/JsiSkImage.h +15 -2
- package/cpp/api/JsiSkSurface.h +18 -3
- package/cpp/rnskia/DawnContext.h +241 -0
- package/cpp/rnskia/DawnUtils.h +127 -0
- package/cpp/rnskia/DawnWindowContext.cpp +19 -0
- package/cpp/rnskia/DawnWindowContext.h +77 -0
- package/cpp/rnskia/ImageProvider.h +100 -0
- package/cpp/rnskia/RNSkView.h +6 -0
- package/cpp/skia/include/android/SkAnimatedImage.h +14 -0
- package/cpp/skia/include/codec/SkAvifDecoder.h +39 -3
- package/cpp/skia/include/codec/SkCodec.h +16 -0
- package/cpp/skia/include/config/SkUserConfig.h +3 -2
- package/cpp/skia/include/core/SkCanvas.h +55 -10
- package/cpp/skia/include/core/SkContourMeasure.h +76 -0
- package/cpp/skia/include/core/SkFontScanner.h +48 -0
- package/cpp/skia/include/core/SkMilestone.h +1 -1
- package/cpp/skia/include/core/SkPath.h +11 -0
- package/cpp/skia/include/core/SkPathEffect.h +0 -23
- package/cpp/skia/include/core/SkRect.h +2 -0
- package/cpp/skia/include/core/SkString.h +4 -0
- package/cpp/skia/include/core/SkTypeface.h +5 -0
- package/cpp/skia/include/core/SkTypes.h +8 -3
- package/cpp/skia/include/docs/SkPDFDocument.h +3 -3
- package/cpp/skia/include/effects/SkOverdrawColorFilter.h +1 -0
- package/cpp/skia/include/effects/SkRuntimeEffect.h +2 -1
- package/cpp/skia/include/encode/SkJpegEncoder.h +4 -0
- package/cpp/skia/include/gpu/ganesh/GrContextOptions.h +8 -1
- package/cpp/skia/include/gpu/ganesh/GrDirectContext.h +18 -3
- package/cpp/skia/include/gpu/ganesh/GrTypes.h +11 -0
- package/cpp/skia/include/gpu/ganesh/gl/GrGLFunctions.h +5 -1
- package/cpp/skia/include/gpu/ganesh/gl/GrGLInterface.h +0 -1
- package/cpp/skia/include/gpu/graphite/GraphiteTypes.h +8 -0
- package/cpp/skia/include/gpu/graphite/Recorder.h +0 -2
- package/cpp/skia/include/gpu/graphite/precompile/PaintOptions.h +7 -4
- package/cpp/skia/include/gpu/graphite/precompile/PrecompileImageFilter.h +2 -0
- package/cpp/skia/include/gpu/graphite/precompile/PrecompileMaskFilter.h +2 -0
- package/cpp/skia/include/ports/SkFontMgr_android_ndk.h +25 -0
- package/cpp/skia/include/ports/SkFontMgr_fontconfig.h +4 -2
- package/cpp/skia/include/ports/SkFontScanner_Fontations.h +15 -0
- package/cpp/skia/include/ports/SkFontScanner_FreeType.h +15 -0
- package/cpp/skia/include/private/SkExif.h +14 -0
- package/cpp/skia/include/private/SkPathRef.h +36 -0
- package/cpp/skia/include/private/base/SkFeatures.h +4 -0
- package/cpp/skia/include/private/base/SkSpan_impl.h +1 -3
- package/cpp/skia/modules/skcms/src/skcms_internals.h +3 -0
- package/cpp/skia/src/base/SkMathPriv.h +1 -8
- package/ios/RNSkia-iOS/RNSkMetalCanvasProvider.h +1 -2
- package/ios/RNSkia-iOS/RNSkMetalCanvasProvider.mm +25 -19
- package/ios/RNSkia-iOS/RNSkiOSPlatformContext.mm +23 -0
- package/ios/RNSkia-iOS/SkiaCVPixelBufferUtils.mm +4 -8
- package/ios/RNSkia-iOS/SkiaMetalSurfaceFactory.h +26 -8
- package/ios/RNSkia-iOS/SkiaMetalSurfaceFactory.mm +0 -20
- package/libs/android/arm64-v8a/libskia.a +0 -0
- package/libs/android/arm64-v8a/libskottie.a +0 -0
- package/libs/android/armeabi-v7a/libskia.a +0 -0
- package/libs/android/armeabi-v7a/libskottie.a +0 -0
- package/libs/android/x86/libskia.a +0 -0
- package/libs/android/x86/libskottie.a +0 -0
- package/libs/android/x86_64/libskia.a +0 -0
- package/libs/android/x86_64/libskottie.a +0 -0
- package/libs/ios/libskia.xcframework/ios-arm64_arm64e/libskia.a +0 -0
- package/libs/ios/libskia.xcframework/ios-arm64_arm64e_x86_64-simulator/libskia.a +0 -0
- package/libs/ios/libskottie.xcframework/ios-arm64_arm64e/libskottie.a +0 -0
- package/libs/ios/libskottie.xcframework/ios-arm64_arm64e_x86_64-simulator/libskottie.a +0 -0
- package/libs/ios/libskparagraph.xcframework/ios-arm64_arm64e/libskparagraph.a +0 -0
- package/libs/ios/libskparagraph.xcframework/ios-arm64_arm64e_x86_64-simulator/libskparagraph.a +0 -0
- package/libs/ios/libsksg.xcframework/ios-arm64_arm64e/libsksg.a +0 -0
- package/libs/ios/libsksg.xcframework/ios-arm64_arm64e_x86_64-simulator/libsksg.a +0 -0
- package/libs/ios/libskshaper.xcframework/Info.plist +5 -5
- package/libs/ios/libskshaper.xcframework/ios-arm64_arm64e/libskshaper.a +0 -0
- package/libs/ios/libskshaper.xcframework/ios-arm64_arm64e_x86_64-simulator/libskshaper.a +0 -0
- package/libs/ios/libskunicode_core.xcframework/Info.plist +5 -5
- package/libs/ios/libskunicode_core.xcframework/ios-arm64_arm64e/libskunicode_core.a +0 -0
- package/libs/ios/libskunicode_core.xcframework/ios-arm64_arm64e_x86_64-simulator/libskunicode_core.a +0 -0
- package/libs/ios/libskunicode_libgrapheme.xcframework/Info.plist +5 -5
- package/libs/ios/libskunicode_libgrapheme.xcframework/ios-arm64_arm64e/libskunicode_libgrapheme.a +0 -0
- package/libs/ios/libskunicode_libgrapheme.xcframework/ios-arm64_arm64e_x86_64-simulator/libskunicode_libgrapheme.a +0 -0
- package/libs/ios/libsvg.xcframework/ios-arm64_arm64e/libsvg.a +0 -0
- package/libs/ios/libsvg.xcframework/ios-arm64_arm64e_x86_64-simulator/libsvg.a +0 -0
- package/package.json +1 -1
- package/react-native-skia.podspec +35 -9
- package/src/renderer/__tests__/e2e/SVG.spec.tsx +2 -1
- package/android/cpp/rnskia-android/SkiaOpenGLHelper.h +0 -310
- package/android/cpp/rnskia-android/SkiaOpenGLSurfaceFactory.cpp +0 -188
- package/android/cpp/rnskia-android/SkiaOpenGLSurfaceFactory.h +0 -100
package/android/CMakeLists.txt
CHANGED
@@ -3,8 +3,8 @@ cmake_minimum_required(VERSION 3.4.1)
|
|
3
3
|
|
4
4
|
set (CMAKE_VERBOSE_MAKEFILE ON)
|
5
5
|
set (CMAKE_CXX_STANDARD 17)
|
6
|
-
set
|
7
|
-
|
6
|
+
set(SK_GRAPHITE OFF)
|
7
|
+
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DSK_BUILD_FOR_ANDROID -DFOLLY_NO_CONFIG=1 -DFOLLY_HAVE_CLOCK_GETTIME=1 -DFOLLY_HAVE_MEMRCHR=1 -DFOLLY_USE_LIBCPP=1 -DFOLLY_MOBILE=1 -DON_ANDROID -DONANDROID")
|
8
8
|
set (PACKAGE_NAME "rnskia")
|
9
9
|
set (SKIA_LIB "skia")
|
10
10
|
set (SKIA_SVG_LIB "svg")
|
@@ -13,6 +13,7 @@ set (SKIA_SKPARAGRAPH_LIB "skparagraph")
|
|
13
13
|
set (SKIA_SKUNICODE_CORE_LIB "skunicode_core")
|
14
14
|
set (SKIA_SKUNICODE_ICU_LIB "skunicode_icu")
|
15
15
|
|
16
|
+
|
16
17
|
# Clear some variables
|
17
18
|
unset(LIBRN_DIR CACHE)
|
18
19
|
unset(libfbjni_link_DIRS CACHE)
|
@@ -30,6 +31,34 @@ message("-- LIBRN : " ${LIBRN_DIR})
|
|
30
31
|
|
31
32
|
link_directories(../libs/android/${ANDROID_ABI}/)
|
32
33
|
|
34
|
+
# Import prebuilt SKIA libraries
|
35
|
+
set (SKIA_LIBS_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../libs/android/${ANDROID_ABI}")
|
36
|
+
|
37
|
+
if(SK_GRAPHITE)
|
38
|
+
add_definitions(-DSK_GRAPHITE)
|
39
|
+
set(DAWN_NATIVE_LIB "libdawn_native_static")
|
40
|
+
set(DAWN_PLATFORM_LIB "libdawn_platform_static")
|
41
|
+
set(DAWN_PROC_LIB "libdawn_proc_static")
|
42
|
+
set(BACKEND_SOURCES
|
43
|
+
#TODO: is this source needed to be added?
|
44
|
+
"${PROJECT_SOURCE_DIR}/../cpp/rnskia/DawnWindowContext.cpp"
|
45
|
+
)
|
46
|
+
add_library(libdawn_native_static STATIC IMPORTED)
|
47
|
+
set_property(TARGET libdawn_native_static PROPERTY IMPORTED_LOCATION "${SKIA_LIBS_PATH}/libdawn_native_static.a")
|
48
|
+
|
49
|
+
add_library(libdawn_platform_static STATIC IMPORTED)
|
50
|
+
set_property(TARGET libdawn_platform_static PROPERTY IMPORTED_LOCATION "${SKIA_LIBS_PATH}/libdawn_platform_static.a")
|
51
|
+
|
52
|
+
add_library(libdawn_proc_static STATIC IMPORTED)
|
53
|
+
set_property(TARGET libdawn_proc_static PROPERTY IMPORTED_LOCATION "${SKIA_LIBS_PATH}/libdawn_proc_static.a")
|
54
|
+
else()
|
55
|
+
add_definitions(-DSK_GL -DSK_GANESH)
|
56
|
+
set(BACKEND_SOURCES
|
57
|
+
"${PROJECT_SOURCE_DIR}/cpp/rnskia-android/OpenGLWindowContext.cpp"
|
58
|
+
"${PROJECT_SOURCE_DIR}/cpp/rnskia-android/GrAHardwareBufferUtils.cpp"
|
59
|
+
)
|
60
|
+
endif()
|
61
|
+
|
33
62
|
if(${REACT_NATIVE_VERSION} LESS 66)
|
34
63
|
file(
|
35
64
|
TO_CMAKE_PATH
|
@@ -45,9 +74,8 @@ add_library(
|
|
45
74
|
"${PROJECT_SOURCE_DIR}/cpp/jni/JniSkiaManager.cpp"
|
46
75
|
|
47
76
|
"${PROJECT_SOURCE_DIR}/cpp/jni/JniPlatformContext.cpp"
|
77
|
+
"${PROJECT_SOURCE_DIR}/cpp/rnskia-android/opengl/Error.cpp"
|
48
78
|
"${PROJECT_SOURCE_DIR}/cpp/rnskia-android/RNSkOpenGLCanvasProvider.cpp"
|
49
|
-
"${PROJECT_SOURCE_DIR}/cpp/rnskia-android/SkiaOpenGLSurfaceFactory.cpp"
|
50
|
-
"${PROJECT_SOURCE_DIR}/cpp/rnskia-android/GrAHardwareBufferUtils.cpp"
|
51
79
|
"${PROJECT_SOURCE_DIR}/cpp/rnskia-android/AHardwareBufferUtils.cpp"
|
52
80
|
"${PROJECT_SOURCE_DIR}/cpp/rnskia-android/RNSkAndroidVideo.cpp"
|
53
81
|
|
@@ -66,9 +94,10 @@ add_library(
|
|
66
94
|
|
67
95
|
"${PROJECT_SOURCE_DIR}/../cpp/api/third_party/CSSColorParser.cpp"
|
68
96
|
"${PROJECT_SOURCE_DIR}/../cpp/api/third_party/base64.cpp"
|
69
|
-
|
97
|
+
${BACKEND_SOURCES}
|
70
98
|
)
|
71
99
|
|
100
|
+
|
72
101
|
target_include_directories(
|
73
102
|
${PACKAGE_NAME}
|
74
103
|
PRIVATE
|
@@ -88,6 +117,7 @@ target_include_directories(
|
|
88
117
|
# so "include/core/SkRef.h" instead of "SkRef.h", as otherwise
|
89
118
|
# the prefab cannot be shipped.
|
90
119
|
../cpp/skia
|
120
|
+
../cpp/dawn/include
|
91
121
|
|
92
122
|
../cpp/api
|
93
123
|
../cpp/jsi
|
@@ -102,9 +132,6 @@ target_include_directories(
|
|
102
132
|
${libfbjni_include_DIRS}
|
103
133
|
)
|
104
134
|
|
105
|
-
# Import prebuilt SKIA libraries
|
106
|
-
set (SKIA_LIBS_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../libs/android/${ANDROID_ABI}")
|
107
|
-
|
108
135
|
add_library(skia STATIC IMPORTED)
|
109
136
|
set_property(TARGET skia PROPERTY IMPORTED_LOCATION "${SKIA_LIBS_PATH}/libskia.a")
|
110
137
|
|
@@ -240,8 +267,7 @@ add_definitions(-DREACT_NATIVE_VERSION=${REACT_NATIVE_VERSION})
|
|
240
267
|
|
241
268
|
# Link
|
242
269
|
if(${REACT_NATIVE_VERSION} GREATER_EQUAL 76)
|
243
|
-
|
244
|
-
${PACKAGE_NAME}
|
270
|
+
set(COMMON_LIBS
|
245
271
|
${LOG_LIB}
|
246
272
|
${REACT_LIB}
|
247
273
|
${FBJNI_LIBRARY}
|
@@ -258,8 +284,7 @@ if(${REACT_NATIVE_VERSION} GREATER_EQUAL 76)
|
|
258
284
|
-landroid
|
259
285
|
)
|
260
286
|
else()
|
261
|
-
|
262
|
-
${PACKAGE_NAME}
|
287
|
+
set(COMMON_LIBS
|
263
288
|
${LOG_LIB}
|
264
289
|
${FBJNI_LIBRARY}
|
265
290
|
${REACT_LIB}
|
@@ -278,4 +303,19 @@ else()
|
|
278
303
|
-lEGL
|
279
304
|
-landroid
|
280
305
|
)
|
281
|
-
endif()
|
306
|
+
endif()
|
307
|
+
|
308
|
+
if(SK_GRAPHITE)
|
309
|
+
target_link_libraries(${PACKAGE_NAME}
|
310
|
+
${COMMON_LIBS}
|
311
|
+
${DAWN_NATIVE_LIB}
|
312
|
+
${DAWN_PLATFORM_LIB}
|
313
|
+
${DAWN_PROC_LIB}
|
314
|
+
)
|
315
|
+
else()
|
316
|
+
target_link_libraries(${PACKAGE_NAME}
|
317
|
+
${COMMON_LIBS}
|
318
|
+
-lGLESv2
|
319
|
+
-lEGL
|
320
|
+
)
|
321
|
+
endif()
|
package/android/build.gradle
CHANGED
@@ -330,6 +330,9 @@ if (ENABLE_PREFAB) {
|
|
330
330
|
} else if (path.contains("skia/include") || path.contains("skia/modules") || path.contains("skia/src")) {
|
331
331
|
// Skip flattening Skia dir
|
332
332
|
path = path.substring("skia/".length())
|
333
|
+
} else if (path.startsWith("dawn/include/")) {
|
334
|
+
// Flatten dawn/include/dawn and dawn/include/webgpu
|
335
|
+
path = path.substring("dawn/include/".length())
|
333
336
|
} else {
|
334
337
|
// flatten anything else
|
335
338
|
path = path.substring(path.lastIndexOf("/") + 1)
|
@@ -1,9 +1,18 @@
|
|
1
1
|
#pragma once
|
2
2
|
|
3
|
-
#include "
|
4
|
-
#include "
|
3
|
+
#include "GrAHardwareBufferUtils.h"
|
4
|
+
#include "OpenGLWindowContext.h"
|
5
|
+
#include "opengl/Display.h"
|
5
6
|
|
7
|
+
#include "include/core/SkCanvas.h"
|
8
|
+
#include "include/core/SkColorSpace.h"
|
6
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"
|
7
16
|
|
8
17
|
class OpenGLContext {
|
9
18
|
public:
|
@@ -16,25 +25,127 @@ public:
|
|
16
25
|
}
|
17
26
|
|
18
27
|
sk_sp<SkSurface> MakeOffscreen(int width, int height) {
|
19
|
-
|
20
|
-
|
28
|
+
auto colorType = kRGBA_8888_SkColorType;
|
29
|
+
|
30
|
+
SkSurfaceProps props(0, kUnknown_SkPixelGeometry);
|
31
|
+
|
32
|
+
auto result = _ctx->makeCurrent(*_surface);
|
33
|
+
if (!result) {
|
34
|
+
return nullptr;
|
35
|
+
}
|
36
|
+
|
37
|
+
// Create texture
|
38
|
+
auto texture = _directContext->createBackendTexture(
|
39
|
+
width, height, colorType, skgpu::Mipmapped::kNo, GrRenderable::kYes);
|
40
|
+
|
41
|
+
if (!texture.isValid()) {
|
42
|
+
RNSkia::RNSkLogger::logToConsole(
|
43
|
+
"couldn't create offscreen texture %dx%d", width, height);
|
44
|
+
}
|
45
|
+
|
46
|
+
struct ReleaseContext {
|
47
|
+
GrDirectContext *directContext;
|
48
|
+
GrBackendTexture texture;
|
49
|
+
};
|
50
|
+
|
51
|
+
auto releaseCtx = new ReleaseContext{.directContext = _directContext.get(),
|
52
|
+
.texture = texture};
|
53
|
+
|
54
|
+
// Create a SkSurface from the GrBackendTexture
|
55
|
+
return SkSurfaces::WrapBackendTexture(
|
56
|
+
_directContext.get(), texture, kTopLeft_GrSurfaceOrigin, 0, colorType,
|
57
|
+
nullptr, &props,
|
58
|
+
[](void *addr) {
|
59
|
+
auto releaseCtx = reinterpret_cast<ReleaseContext *>(addr);
|
60
|
+
releaseCtx->directContext->deleteBackendTexture(releaseCtx->texture);
|
61
|
+
delete releaseCtx;
|
62
|
+
},
|
63
|
+
releaseCtx);
|
21
64
|
}
|
22
65
|
|
23
|
-
sk_sp<SkImage> MakeImageFromBuffer(void *buffer
|
24
|
-
|
25
|
-
|
66
|
+
sk_sp<SkImage> MakeImageFromBuffer(void *buffer,
|
67
|
+
bool requireKnownFormat = false) {
|
68
|
+
#if __ANDROID_API__ >= 26
|
69
|
+
const AHardwareBuffer *hardwareBuffer =
|
70
|
+
static_cast<AHardwareBuffer *>(buffer);
|
71
|
+
RNSkia::DeleteImageProc deleteImageProc = nullptr;
|
72
|
+
RNSkia::UpdateImageProc updateImageProc = nullptr;
|
73
|
+
RNSkia::TexImageCtx deleteImageCtx = nullptr;
|
74
|
+
|
75
|
+
AHardwareBuffer_Desc description;
|
76
|
+
AHardwareBuffer_describe(hardwareBuffer, &description);
|
77
|
+
GrBackendFormat format;
|
78
|
+
switch (description.format) {
|
79
|
+
// TODO: find out if we can detect, which graphic buffers support
|
80
|
+
// GR_GL_TEXTURE_2D
|
81
|
+
case AHARDWAREBUFFER_FORMAT_R8G8B8A8_UNORM:
|
82
|
+
format = GrBackendFormats::MakeGL(GR_GL_RGBA8, GR_GL_TEXTURE_EXTERNAL);
|
83
|
+
case AHARDWAREBUFFER_FORMAT_R16G16B16A16_FLOAT:
|
84
|
+
format = GrBackendFormats::MakeGL(GR_GL_RGBA16F, GR_GL_TEXTURE_EXTERNAL);
|
85
|
+
case AHARDWAREBUFFER_FORMAT_R5G6B5_UNORM:
|
86
|
+
format = GrBackendFormats::MakeGL(GR_GL_RGB565, GR_GL_TEXTURE_EXTERNAL);
|
87
|
+
case AHARDWAREBUFFER_FORMAT_R10G10B10A2_UNORM:
|
88
|
+
format = GrBackendFormats::MakeGL(GR_GL_RGB10_A2, GR_GL_TEXTURE_EXTERNAL);
|
89
|
+
case AHARDWAREBUFFER_FORMAT_R8G8B8_UNORM:
|
90
|
+
format = GrBackendFormats::MakeGL(GR_GL_RGB8, GR_GL_TEXTURE_EXTERNAL);
|
91
|
+
#if __ANDROID_API__ >= 33
|
92
|
+
case AHARDWAREBUFFER_FORMAT_R8_UNORM:
|
93
|
+
format = GrBackendFormats::MakeGL(GR_GL_R8, GR_GL_TEXTURE_EXTERNAL);
|
94
|
+
#endif
|
95
|
+
default:
|
96
|
+
if (requireKnownFormat) {
|
97
|
+
format = GrBackendFormat();
|
98
|
+
} else {
|
99
|
+
format = GrBackendFormats::MakeGL(GR_GL_RGBA8, GR_GL_TEXTURE_EXTERNAL);
|
100
|
+
}
|
101
|
+
}
|
102
|
+
|
103
|
+
auto backendTex = RNSkia::MakeGLBackendTexture(
|
104
|
+
_directContext.get(), const_cast<AHardwareBuffer *>(hardwareBuffer),
|
105
|
+
description.width, description.height, &deleteImageProc,
|
106
|
+
&updateImageProc, &deleteImageCtx, false, format, false);
|
107
|
+
if (!backendTex.isValid()) {
|
108
|
+
RNSkia::RNSkLogger::logToConsole(
|
109
|
+
"Failed to convert HardwareBuffer to OpenGL Texture!");
|
110
|
+
return nullptr;
|
111
|
+
}
|
112
|
+
sk_sp<SkImage> image = SkImages::BorrowTextureFrom(
|
113
|
+
_directContext.get(), backendTex, kTopLeft_GrSurfaceOrigin,
|
114
|
+
kRGBA_8888_SkColorType, kOpaque_SkAlphaType, nullptr, deleteImageProc,
|
115
|
+
deleteImageCtx);
|
116
|
+
return image;
|
117
|
+
#else
|
118
|
+
throw std::runtime_error(
|
119
|
+
"HardwareBuffers are only supported on Android API 26 or higher! Set "
|
120
|
+
"your minSdk to 26 (or higher) and try again.");
|
121
|
+
#endif
|
26
122
|
}
|
27
123
|
|
28
124
|
std::unique_ptr<RNSkia::WindowContext> MakeWindow(ANativeWindow *window,
|
29
125
|
int width, int height) {
|
30
|
-
return RNSkia::
|
31
|
-
|
126
|
+
return std::make_unique<RNSkia::OpenGLWindowContext>(
|
127
|
+
_config, _display.get(), _ctx.get(), _directContext.get(), window,
|
128
|
+
width, height);
|
32
129
|
}
|
33
130
|
|
34
131
|
private:
|
35
|
-
|
132
|
+
EGLConfig _config;
|
133
|
+
std::unique_ptr<RNSkia::Display> _display;
|
134
|
+
std::unique_ptr<RNSkia::Context> _ctx;
|
135
|
+
std::unique_ptr<RNSkia::Surface> _surface;
|
136
|
+
sk_sp<GrDirectContext> _directContext;
|
36
137
|
|
37
138
|
OpenGLContext() {
|
38
|
-
RNSkia::
|
139
|
+
_display = std::make_unique<RNSkia::Display>();
|
140
|
+
_config = _display->chooseConfig();
|
141
|
+
_ctx = _display->makeContext(_config, nullptr);
|
142
|
+
_surface = _display->makePixelBufferSurface(_config, 1, 1);
|
143
|
+
_ctx->makeCurrent(*_surface);
|
144
|
+
auto backendInterface = GrGLMakeNativeInterface();
|
145
|
+
_directContext = GrDirectContexts::MakeGL(backendInterface);
|
146
|
+
|
147
|
+
if (_directContext == nullptr) {
|
148
|
+
throw std::runtime_error("GrDirectContexts::MakeGL failed");
|
149
|
+
}
|
39
150
|
}
|
40
151
|
};
|
@@ -0,0 +1,73 @@
|
|
1
|
+
#include "OpenGLWindowContext.h"
|
2
|
+
#include "GrAHardwareBufferUtils.h"
|
3
|
+
|
4
|
+
#pragma clang diagnostic push
|
5
|
+
#pragma clang diagnostic ignored "-Wdocumentation"
|
6
|
+
|
7
|
+
#include "include/gpu/ganesh/SkImageGanesh.h"
|
8
|
+
#include "include/gpu/ganesh/gl/GrGLBackendSurface.h"
|
9
|
+
#include "src/gpu/ganesh/gl/GrGLDefines.h"
|
10
|
+
|
11
|
+
#pragma clang diagnostic pop
|
12
|
+
|
13
|
+
namespace RNSkia {
|
14
|
+
|
15
|
+
sk_sp<SkSurface> OpenGLWindowContext::getSurface() {
|
16
|
+
if (_skSurface == nullptr) {
|
17
|
+
|
18
|
+
struct ReleaseContext {
|
19
|
+
std::unique_ptr<Surface> surface = nullptr;
|
20
|
+
};
|
21
|
+
|
22
|
+
auto releaseCtx = new ReleaseContext();
|
23
|
+
releaseCtx->surface = _display->makeWindowSurface(_config, _window);
|
24
|
+
_surface = releaseCtx->surface.get();
|
25
|
+
|
26
|
+
// Now make this one current
|
27
|
+
_context->makeCurrent(*releaseCtx->surface);
|
28
|
+
|
29
|
+
// Set up parameters for the render target so that it
|
30
|
+
// matches the underlying OpenGL context.
|
31
|
+
GrGLFramebufferInfo fboInfo;
|
32
|
+
|
33
|
+
// We pass 0 as the framebuffer id, since the
|
34
|
+
// underlying Skia GrGlGpu will read this when wrapping the context in the
|
35
|
+
// render target and the GrGlGpu object.
|
36
|
+
fboInfo.fFBOID = 0;
|
37
|
+
fboInfo.fFormat = 0x8058; // GL_RGBA8
|
38
|
+
|
39
|
+
GLint stencil;
|
40
|
+
glGetIntegerv(GL_STENCIL_BITS, &stencil);
|
41
|
+
|
42
|
+
GLint samples;
|
43
|
+
glGetIntegerv(GL_SAMPLES, &samples);
|
44
|
+
|
45
|
+
auto colorType = kN32_SkColorType;
|
46
|
+
|
47
|
+
auto maxSamples =
|
48
|
+
_directContext->maxSurfaceSampleCountForColorType(colorType);
|
49
|
+
|
50
|
+
if (samples > maxSamples) {
|
51
|
+
samples = maxSamples;
|
52
|
+
}
|
53
|
+
|
54
|
+
auto renderTarget = GrBackendRenderTargets::MakeGL(_width, _height, samples,
|
55
|
+
stencil, fboInfo);
|
56
|
+
|
57
|
+
SkSurfaceProps props(0, kUnknown_SkPixelGeometry);
|
58
|
+
|
59
|
+
|
60
|
+
// Create surface object
|
61
|
+
_skSurface = SkSurfaces::WrapBackendRenderTarget(
|
62
|
+
_directContext, renderTarget, kBottomLeft_GrSurfaceOrigin, colorType,
|
63
|
+
nullptr, &props,
|
64
|
+
[](void *addr) {
|
65
|
+
auto releaseCtx = reinterpret_cast<ReleaseContext *>(addr);
|
66
|
+
delete releaseCtx;
|
67
|
+
},
|
68
|
+
reinterpret_cast<void *>(releaseCtx));
|
69
|
+
}
|
70
|
+
return _skSurface;
|
71
|
+
}
|
72
|
+
|
73
|
+
} // namespace RNSkia
|
@@ -0,0 +1,74 @@
|
|
1
|
+
#pragma once
|
2
|
+
|
3
|
+
#include "RNSkLog.h"
|
4
|
+
|
5
|
+
#include <fbjni/fbjni.h>
|
6
|
+
#include <jni.h>
|
7
|
+
|
8
|
+
#include <android/native_window_jni.h>
|
9
|
+
#include <android/surface_texture.h>
|
10
|
+
#include <android/surface_texture_jni.h>
|
11
|
+
#include <condition_variable>
|
12
|
+
#include <memory>
|
13
|
+
#include <thread>
|
14
|
+
#include <unordered_map>
|
15
|
+
|
16
|
+
#include "WindowContext.h"
|
17
|
+
#include "opengl/Display.h"
|
18
|
+
|
19
|
+
#pragma clang diagnostic push
|
20
|
+
#pragma clang diagnostic ignored "-Wdocumentation"
|
21
|
+
|
22
|
+
#include "include/core/SkCanvas.h"
|
23
|
+
#include "include/core/SkColorSpace.h"
|
24
|
+
#include "include/core/SkSurface.h"
|
25
|
+
#include "include/gpu/ganesh/GrBackendSurface.h"
|
26
|
+
#include "include/gpu/ganesh/GrDirectContext.h"
|
27
|
+
#include "include/gpu/ganesh/SkSurfaceGanesh.h"
|
28
|
+
#include "include/gpu/ganesh/gl/GrGLInterface.h"
|
29
|
+
|
30
|
+
#pragma clang diagnostic pop
|
31
|
+
|
32
|
+
namespace RNSkia {
|
33
|
+
|
34
|
+
class OpenGLWindowContext : public WindowContext {
|
35
|
+
public:
|
36
|
+
OpenGLWindowContext(EGLConfig &config, Display *display, Context *context,
|
37
|
+
GrDirectContext *directContext, ANativeWindow *window,
|
38
|
+
int width, int height)
|
39
|
+
: _config(config), _display(display), _directContext(directContext),
|
40
|
+
_context(context), _window(window), _width(width), _height(height) {}
|
41
|
+
|
42
|
+
~OpenGLWindowContext() { ANativeWindow_release(_window); }
|
43
|
+
|
44
|
+
sk_sp<SkSurface> getSurface() override;
|
45
|
+
|
46
|
+
void present() override {
|
47
|
+
_context->makeCurrent(*_surface);
|
48
|
+
_directContext->flushAndSubmit();
|
49
|
+
_surface->Present();
|
50
|
+
}
|
51
|
+
|
52
|
+
void resize(int width, int height) override {
|
53
|
+
_skSurface = nullptr;
|
54
|
+
_width = width;
|
55
|
+
_height = height;
|
56
|
+
}
|
57
|
+
|
58
|
+
int getWidth() override { return _width; };
|
59
|
+
|
60
|
+
int getHeight() override { return _height; };
|
61
|
+
|
62
|
+
private:
|
63
|
+
ANativeWindow *_window;
|
64
|
+
sk_sp<SkSurface> _skSurface = nullptr;
|
65
|
+
EGLConfig _config;
|
66
|
+
Context *_context;
|
67
|
+
Surface* _surface;
|
68
|
+
Display *_display;
|
69
|
+
GrDirectContext *_directContext;
|
70
|
+
int _width = 0;
|
71
|
+
int _height = 0;
|
72
|
+
};
|
73
|
+
|
74
|
+
} // namespace RNSkia
|
@@ -9,9 +9,14 @@
|
|
9
9
|
#include <memory>
|
10
10
|
#include <string>
|
11
11
|
|
12
|
+
#if defined(SK_GRAPHITE)
|
13
|
+
#include "DawnContext.h"
|
14
|
+
#else
|
15
|
+
#include "OpenGLContext.h"
|
16
|
+
#endif
|
17
|
+
|
12
18
|
#include "AHardwareBufferUtils.h"
|
13
19
|
#include "JniPlatformContext.h"
|
14
|
-
#include "OpenGLContext.h"
|
15
20
|
#include "RNSkAndroidVideo.h"
|
16
21
|
#include "RNSkPlatformContext.h"
|
17
22
|
|
@@ -51,17 +56,29 @@ public:
|
|
51
56
|
}
|
52
57
|
|
53
58
|
sk_sp<SkSurface> makeOffscreenSurface(int width, int height) override {
|
59
|
+
#if defined(SK_GRAPHITE)
|
60
|
+
return DawnContext::getInstance().MakeOffscreen(width, height);
|
61
|
+
#else
|
54
62
|
return OpenGLContext::getInstance().MakeOffscreen(width, height);
|
63
|
+
#endif
|
55
64
|
}
|
56
65
|
|
57
66
|
std::shared_ptr<WindowContext>
|
58
67
|
makeContextFromNativeSurface(void *surface, int width, int height) override {
|
68
|
+
#if defined(SK_GRAPHITE)
|
69
|
+
return DawnContext::getInstance().MakeWindow(surface, width, height);
|
70
|
+
#else
|
59
71
|
return OpenGLContext::getInstance().MakeWindow(
|
60
72
|
reinterpret_cast<ANativeWindow *>(surface), width, height);
|
73
|
+
#endif
|
61
74
|
}
|
62
75
|
|
63
76
|
sk_sp<SkImage> makeImageFromNativeBuffer(void *buffer) override {
|
77
|
+
#if defined(SK_GRAPHITE)
|
78
|
+
return DawnContext::getInstance().MakeImageFromBuffer(buffer);
|
79
|
+
#else
|
64
80
|
return OpenGLContext::getInstance().MakeImageFromBuffer(buffer);
|
81
|
+
#endif
|
65
82
|
}
|
66
83
|
|
67
84
|
std::shared_ptr<RNSkVideo> createVideo(const std::string &url) override {
|
@@ -5,6 +5,14 @@
|
|
5
5
|
#include <android/hardware_buffer_jni.h>
|
6
6
|
#endif
|
7
7
|
|
8
|
+
#include "RNSkLog.h"
|
9
|
+
|
10
|
+
#if defined(SK_GRAPHITE)
|
11
|
+
#include "DawnContext.h"
|
12
|
+
#else
|
13
|
+
#include "OpenGLContext.h"
|
14
|
+
#endif
|
15
|
+
|
8
16
|
#pragma clang diagnostic push
|
9
17
|
#pragma clang diagnostic ignored "-Wdocumentation"
|
10
18
|
|
@@ -13,7 +21,6 @@
|
|
13
21
|
|
14
22
|
#pragma clang diagnostic pop
|
15
23
|
|
16
|
-
#include "OpenGLContext.h"
|
17
24
|
#include "RNSkAndroidVideo.h"
|
18
25
|
|
19
26
|
namespace RNSkia {
|
@@ -52,7 +59,11 @@ sk_sp<SkImage> RNSkAndroidVideo::nextImage(double *timeStamp) {
|
|
52
59
|
// Convert jobject to AHardwareBuffer
|
53
60
|
AHardwareBuffer *buffer =
|
54
61
|
AHardwareBuffer_fromHardwareBuffer(env, jHardwareBuffer);
|
62
|
+
#if defined(SK_GRAPHITE)
|
63
|
+
return DawnContext::getInstance().MakeImageFromBuffer(buffer);
|
64
|
+
#else
|
55
65
|
return OpenGLContext::getInstance().MakeImageFromBuffer(buffer);
|
66
|
+
#endif
|
56
67
|
#else
|
57
68
|
return nullptr;
|
58
69
|
#endif
|
@@ -1,8 +1,17 @@
|
|
1
1
|
#include "RNSkOpenGLCanvasProvider.h"
|
2
2
|
|
3
|
+
#include <android/native_window_jni.h>
|
4
|
+
#include <fbjni/fbjni.h>
|
5
|
+
#include <jni.h>
|
3
6
|
#include <memory>
|
4
7
|
|
8
|
+
#include "RNSkLog.h"
|
9
|
+
|
10
|
+
#if defined(SK_GRAPHITE)
|
11
|
+
#include "DawnContext.h"
|
12
|
+
#else
|
5
13
|
#include "OpenGLContext.h"
|
14
|
+
#endif
|
6
15
|
|
7
16
|
#pragma clang diagnostic push
|
8
17
|
#pragma clang diagnostic ignored "-Wdocumentation"
|
@@ -62,7 +71,6 @@ bool RNSkOpenGLCanvasProvider::renderToCanvas(
|
|
62
71
|
return false;
|
63
72
|
}
|
64
73
|
}
|
65
|
-
|
66
74
|
return false;
|
67
75
|
}
|
68
76
|
|
@@ -89,8 +97,12 @@ void RNSkOpenGLCanvasProvider::surfaceAvailable(jobject jSurfaceTexture,
|
|
89
97
|
env->DeleteLocalRef(jSurface);
|
90
98
|
env->DeleteLocalRef(surfaceClass);
|
91
99
|
env->DeleteLocalRef(surfaceTextureClass);
|
100
|
+
#if defined(SK_GRAPHITE)
|
101
|
+
_surfaceHolder = DawnContext::getInstance().MakeWindow(window, width, height);
|
102
|
+
#else
|
92
103
|
_surfaceHolder =
|
93
104
|
OpenGLContext::getInstance().MakeWindow(window, width, height);
|
105
|
+
#endif
|
94
106
|
|
95
107
|
// Post redraw request to ensure we paint in the next draw cycle.
|
96
108
|
_requestRedraw();
|
@@ -0,0 +1,77 @@
|
|
1
|
+
#pragma once
|
2
|
+
|
3
|
+
#include "opengl/Error.h"
|
4
|
+
#include "opengl/Surface.h"
|
5
|
+
|
6
|
+
namespace RNSkia {
|
7
|
+
|
8
|
+
class Surface;
|
9
|
+
class Display;
|
10
|
+
|
11
|
+
class Context {
|
12
|
+
public:
|
13
|
+
~Context() {
|
14
|
+
if (_context != EGL_NO_CONTEXT) {
|
15
|
+
if (eglDestroyContext(_display, _context) != EGL_TRUE) {
|
16
|
+
LOG_EGL_ERROR;
|
17
|
+
}
|
18
|
+
}
|
19
|
+
}
|
20
|
+
|
21
|
+
bool isValid() const { return _context != EGL_NO_CONTEXT; }
|
22
|
+
|
23
|
+
const EGLContext &getHandle() const { return _context; }
|
24
|
+
|
25
|
+
bool makeCurrent(const Surface &surface) const {
|
26
|
+
if (_context == EGL_NO_CONTEXT) {
|
27
|
+
return false;
|
28
|
+
}
|
29
|
+
const auto result =
|
30
|
+
eglMakeCurrentIfNecessary(_display, surface.getHandle(),
|
31
|
+
surface.getHandle(), _context) == EGL_TRUE;
|
32
|
+
if (!result) {
|
33
|
+
LOG_EGL_ERROR;
|
34
|
+
}
|
35
|
+
return result;
|
36
|
+
}
|
37
|
+
|
38
|
+
bool clearCurrent() const {
|
39
|
+
const auto result =
|
40
|
+
eglMakeCurrentIfNecessary(_display, EGL_NO_SURFACE, EGL_NO_SURFACE,
|
41
|
+
EGL_NO_CONTEXT) == EGL_TRUE;
|
42
|
+
if (!result) {
|
43
|
+
LOG_EGL_ERROR;
|
44
|
+
}
|
45
|
+
return result;
|
46
|
+
}
|
47
|
+
|
48
|
+
bool isCurrent() const { return eglGetCurrentContext() == _context; }
|
49
|
+
|
50
|
+
private:
|
51
|
+
friend class Display;
|
52
|
+
|
53
|
+
EGLDisplay _display = EGL_NO_DISPLAY;
|
54
|
+
EGLContext _context = EGL_NO_CONTEXT;
|
55
|
+
|
56
|
+
static EGLBoolean eglMakeCurrentIfNecessary(EGLDisplay display,
|
57
|
+
EGLSurface draw, EGLSurface read,
|
58
|
+
EGLContext context) {
|
59
|
+
if (display != eglGetCurrentDisplay() ||
|
60
|
+
draw != eglGetCurrentSurface(EGL_DRAW) ||
|
61
|
+
read != eglGetCurrentSurface(EGL_READ) ||
|
62
|
+
context != eglGetCurrentContext()) {
|
63
|
+
return eglMakeCurrent(display, draw, read, context);
|
64
|
+
}
|
65
|
+
|
66
|
+
return EGL_TRUE;
|
67
|
+
}
|
68
|
+
|
69
|
+
Context(EGLDisplay display, EGLContext context)
|
70
|
+
: _display(display), _context(context) {}
|
71
|
+
|
72
|
+
Context(const Context &) = delete;
|
73
|
+
|
74
|
+
Context &operator=(const Context &) = delete;
|
75
|
+
};
|
76
|
+
|
77
|
+
} // namespace RNSkia
|