@shopify/react-native-skia 0.1.120 → 0.1.123
Sign up to get free protection for your applications and to get access to all the features.
- package/android/CMakeLists.txt +33 -17
- package/android/build.gradle +81 -34
- package/android/cpp/jni/JniSkiaDrawView.cpp +14 -71
- package/android/cpp/jni/JniSkiaManager.cpp +1 -1
- package/android/cpp/jni/include/JniSkiaDrawView.h +18 -22
- package/android/cpp/jni/include/JniSkiaManager.h +4 -4
- package/android/cpp/rnskia-android/RNSkDrawViewImpl.cpp +68 -0
- package/android/cpp/rnskia-android/RNSkDrawViewImpl.h +48 -0
- package/android/cpp/{jni/include/JniPlatformContextWrapper.h → rnskia-android/RNSkPlatformContextImpl.h} +4 -4
- package/android/cpp/{jni → rnskia-android}/SkiaOpenGLRenderer.cpp +39 -54
- package/android/cpp/{jni/include → rnskia-android}/SkiaOpenGLRenderer.h +2 -31
- package/android/src/main/java/com/shopify/reactnative/skia/PlatformContext.java +1 -1
- package/android/src/main/java/com/shopify/reactnative/skia/RNSkiaViewManager.java +1 -1
- package/android/src/main/java/com/shopify/reactnative/skia/SkiaDrawView.java +21 -28
- package/cpp/api/JsiSkApi.h +2 -0
- package/cpp/api/JsiSkColor.h +49 -0
- package/cpp/api/JsiSkPath.h +31 -2
- package/cpp/api/JsiSkPathFactory.h +96 -1
- package/cpp/api/third_party/CSSColorParser.h +324 -0
- package/cpp/rnskia/RNSkAnimation.h +4 -7
- package/cpp/rnskia/RNSkDrawView.cpp +77 -116
- package/cpp/rnskia/RNSkDrawView.h +5 -35
- package/cpp/rnskia/RNSkJsiViewApi.h +8 -5
- package/cpp/rnskia/RNSkManager.cpp +2 -2
- package/cpp/rnskia/RNSkManager.h +2 -2
- package/cpp/rnskia/RNSkPlatformContext.h +1 -1
- package/cpp/rnskia/values/RNSkClockValue.h +19 -11
- package/cpp/rnskia/values/RNSkDerivedValue.h +1 -1
- package/cpp/rnskia/values/RNSkReadonlyValue.h +15 -15
- package/cpp/utils/RNSkTimingInfo.h +13 -1
- package/ios/RNSkia-iOS/RNSkDrawViewImpl.h +5 -7
- package/ios/RNSkia-iOS/RNSkDrawViewImpl.mm +25 -10
- package/ios/RNSkia-iOS/SkiaDrawView.mm +21 -15
- package/lib/commonjs/renderer/Canvas.js +3 -3
- package/lib/commonjs/renderer/Canvas.js.map +1 -1
- package/lib/commonjs/renderer/components/Paint.js +1 -1
- package/lib/commonjs/renderer/components/Paint.js.map +1 -1
- package/lib/commonjs/renderer/components/shapes/Path.js +10 -2
- package/lib/commonjs/renderer/components/shapes/Path.js.map +1 -1
- package/lib/commonjs/renderer/nodes/Node.js +3 -3
- package/lib/commonjs/renderer/nodes/Node.js.map +1 -1
- package/lib/commonjs/renderer/processors/Paint.js +6 -1
- package/lib/commonjs/renderer/processors/Paint.js.map +1 -1
- package/lib/commonjs/skia/Color.js +3 -25
- package/lib/commonjs/skia/Color.js.map +1 -1
- package/lib/commonjs/skia/Image/Image.js.map +1 -1
- package/lib/commonjs/skia/ImageFilter/ImageFilterFactory.js.map +1 -1
- package/lib/commonjs/skia/Paint/Paint.js +13 -1
- package/lib/commonjs/skia/Paint/Paint.js.map +1 -1
- package/lib/commonjs/skia/Paint/usePaint.js +2 -4
- package/lib/commonjs/skia/Paint/usePaint.js.map +1 -1
- package/lib/commonjs/skia/Path/Path.js +13 -1
- package/lib/commonjs/skia/Path/Path.js.map +1 -1
- package/lib/commonjs/skia/Shader/Shader.js.map +1 -1
- package/lib/commonjs/skia/Skia.js +43 -3
- package/lib/commonjs/skia/Skia.js.map +1 -1
- package/lib/module/renderer/Canvas.js +2 -2
- package/lib/module/renderer/Canvas.js.map +1 -1
- package/lib/module/renderer/components/Paint.js +2 -2
- package/lib/module/renderer/components/Paint.js.map +1 -1
- package/lib/module/renderer/components/shapes/Path.js +10 -3
- package/lib/module/renderer/components/shapes/Path.js.map +1 -1
- package/lib/module/renderer/nodes/Node.js +3 -3
- package/lib/module/renderer/nodes/Node.js.map +1 -1
- package/lib/module/renderer/processors/Paint.js +6 -1
- package/lib/module/renderer/processors/Paint.js.map +1 -1
- package/lib/module/skia/Color.js +2 -21
- package/lib/module/skia/Color.js.map +1 -1
- package/lib/module/skia/Image/Image.js.map +1 -1
- package/lib/module/skia/ImageFilter/ImageFilterFactory.js.map +1 -1
- package/lib/module/skia/Paint/Paint.js +6 -0
- package/lib/module/skia/Paint/Paint.js.map +1 -1
- package/lib/module/skia/Paint/usePaint.js +2 -3
- package/lib/module/skia/Paint/usePaint.js.map +1 -1
- package/lib/module/skia/Path/Path.js +11 -0
- package/lib/module/skia/Path/Path.js.map +1 -1
- package/lib/module/skia/Shader/Shader.js.map +1 -1
- package/lib/module/skia/Skia.js +45 -2
- package/lib/module/skia/Skia.js.map +1 -1
- package/lib/typescript/src/renderer/components/shapes/Path.d.ts +3 -1
- package/lib/typescript/src/renderer/processors/Paint.d.ts +2 -1
- package/lib/typescript/src/skia/Color.d.ts +0 -1
- package/lib/typescript/src/skia/Image/Image.d.ts +3 -3
- package/lib/typescript/src/skia/ImageFilter/ImageFilterFactory.d.ts +2 -2
- package/lib/typescript/src/skia/Paint/Paint.d.ts +3 -2
- package/lib/typescript/src/skia/Path/Path.d.ts +13 -0
- package/lib/typescript/src/skia/Path/PathFactory.d.ts +7 -1
- package/lib/typescript/src/skia/Picture/Picture.d.ts +2 -2
- package/lib/typescript/src/skia/RuntimeEffect/RuntimeEffect.d.ts +3 -3
- package/lib/typescript/src/skia/Shader/Shader.d.ts +2 -2
- package/lib/typescript/src/skia/Shader/ShaderFactory.d.ts +9 -9
- package/lib/typescript/src/skia/Skia.d.ts +5 -3
- package/package.json +1 -1
- package/scripts/install-npm.js +1 -1
- package/src/renderer/Canvas.tsx +2 -2
- package/src/renderer/components/Paint.tsx +2 -2
- package/src/renderer/components/shapes/Path.tsx +12 -4
- package/src/renderer/nodes/Node.ts +3 -3
- package/src/renderer/processors/Paint.ts +5 -0
- package/src/skia/Color.ts +3 -20
- package/src/skia/Image/Image.ts +3 -3
- package/src/skia/ImageFilter/ImageFilterFactory.ts +2 -2
- package/src/skia/Paint/Paint.ts +9 -2
- package/src/skia/Paint/usePaint.ts +2 -4
- package/src/skia/Path/Path.ts +16 -0
- package/src/skia/Path/PathFactory.ts +8 -1
- package/src/skia/Picture/Picture.ts +2 -2
- package/src/skia/RuntimeEffect/RuntimeEffect.ts +4 -4
- package/src/skia/Shader/Shader.ts +2 -2
- package/src/skia/Shader/ShaderFactory.ts +9 -9
- package/src/skia/Skia.ts +47 -3
package/android/CMakeLists.txt
CHANGED
@@ -10,12 +10,20 @@ set (SKIA_SVG_LIB "svg")
|
|
10
10
|
set (SKIA_SKSHAPER_LIB "skshaper")
|
11
11
|
|
12
12
|
set(build_DIR ${CMAKE_SOURCE_DIR}/build)
|
13
|
-
file
|
13
|
+
file(GLOB LIBRN_DIR "${PREBUILT_DIR}/${ANDROID_ABI}")
|
14
14
|
file(GLOB libfbjni_link_DIRS "${build_DIR}/fbjni*.aar/jni/${ANDROID_ABI}")
|
15
15
|
file(GLOB libfbjni_include_DIRS "${build_DIR}/fbjni-*-headers.jar/")
|
16
16
|
|
17
17
|
link_directories(../libs/android/${ANDROID_ABI}/)
|
18
18
|
|
19
|
+
if(${REACT_NATIVE_VERSION} LESS 66)
|
20
|
+
file(
|
21
|
+
TO_CMAKE_PATH
|
22
|
+
"${NODE_MODULES_DIR}/react-native/ReactCommon/jsi/jsi/jsi.cpp"
|
23
|
+
INCLUDE_JSI_CPP
|
24
|
+
)
|
25
|
+
endif()
|
26
|
+
|
19
27
|
add_library(
|
20
28
|
${PACKAGE_NAME}
|
21
29
|
SHARED
|
@@ -23,7 +31,8 @@ add_library(
|
|
23
31
|
"${PROJECT_SOURCE_DIR}/cpp/jni/JniSkiaManager.cpp"
|
24
32
|
"${PROJECT_SOURCE_DIR}/cpp/jni/JniSkiaDrawView.cpp"
|
25
33
|
"${PROJECT_SOURCE_DIR}/cpp/jni/JniPlatformContext.cpp"
|
26
|
-
"${PROJECT_SOURCE_DIR}/cpp/
|
34
|
+
"${PROJECT_SOURCE_DIR}/cpp/rnskia-android/RNSkDrawViewImpl.cpp"
|
35
|
+
"${PROJECT_SOURCE_DIR}/cpp/rnskia-android/SkiaOpenGLRenderer.cpp"
|
27
36
|
|
28
37
|
"${PROJECT_SOURCE_DIR}/cpp/jsi/JsiHostObject.cpp"
|
29
38
|
|
@@ -39,16 +48,10 @@ target_include_directories(
|
|
39
48
|
PRIVATE
|
40
49
|
|
41
50
|
# When installed in the development environment
|
42
|
-
"
|
43
|
-
"
|
44
|
-
"
|
45
|
-
"
|
46
|
-
|
47
|
-
# When installed as a package the paths are a bit different
|
48
|
-
"../../../react-native/ReactCommon/callinvoker"
|
49
|
-
"../../../react-native/ReactCommon/jsi"
|
50
|
-
"../../../react-native/ReactCommon/react/nativemodule/core"
|
51
|
-
"../../../react-native/ReactAndroid/src/main/java/com/facebook/react/turbomodule/core/jni"
|
51
|
+
"${NODE_MODULES_DIR}/react-native/ReactCommon/callinvoker"
|
52
|
+
"${NODE_MODULES_DIR}/react-native/ReactCommon/jsi"
|
53
|
+
"${NODE_MODULES_DIR}/react-native/ReactCommon/react/nativemodule/core"
|
54
|
+
"${NODE_MODULES_DIR}/react-native/ReactAndroid/src/main/java/com/facebook/react/turbomodule/core/jni"
|
52
55
|
|
53
56
|
cpp/skia/include/config/
|
54
57
|
cpp/skia/include/core/
|
@@ -62,6 +65,7 @@ target_include_directories(
|
|
62
65
|
cpp/api
|
63
66
|
cpp/jsi
|
64
67
|
cpp/jni/include
|
68
|
+
cpp/rnskia-android
|
65
69
|
cpp/rnskia
|
66
70
|
cpp/rnskia/values
|
67
71
|
cpp/utils
|
@@ -87,11 +91,23 @@ find_library(
|
|
87
91
|
)
|
88
92
|
|
89
93
|
find_library(
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
)
|
94
|
+
JSI_LIB
|
95
|
+
jsi
|
96
|
+
PATHS ${LIBRN_DIR}
|
97
|
+
NO_CMAKE_FIND_ROOT_PATH
|
98
|
+
)
|
99
|
+
if(${REACT_NATIVE_VERSION} LESS 66)
|
100
|
+
# JSI lib didn't exist on RN 0.65 and before. Simply omit it.
|
101
|
+
set (JSI_LIB "")
|
102
|
+
else()
|
103
|
+
# RN 0.66 distributes libjsi.so, can be used instead of compiling jsi.cpp manually.
|
104
|
+
find_library(
|
105
|
+
JSI_LIB
|
106
|
+
jsi
|
107
|
+
PATHS ${LIBRN_DIR}
|
108
|
+
NO_CMAKE_FIND_ROOT_PATH
|
109
|
+
)
|
110
|
+
endif()
|
95
111
|
|
96
112
|
find_library(
|
97
113
|
REACT_LIB
|
package/android/build.gradle
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
import java.nio.file.Paths
|
2
|
+
|
1
3
|
// android/build.gradle
|
2
4
|
|
3
5
|
// based on:
|
@@ -26,6 +28,60 @@ def safeExtGet(prop, fallback) {
|
|
26
28
|
|
27
29
|
apply plugin: 'com.android.library'
|
28
30
|
|
31
|
+
static def findNodeModules(baseDir) {
|
32
|
+
def basePath = baseDir.toPath().normalize()
|
33
|
+
// Node's module resolution algorithm searches up to the root directory,
|
34
|
+
// after which the base path will be null
|
35
|
+
while (basePath) {
|
36
|
+
def nodeModulesPath = Paths.get(basePath.toString(), "node_modules")
|
37
|
+
def reactNativePath = Paths.get(nodeModulesPath.toString(), "react-native")
|
38
|
+
if (nodeModulesPath.toFile().exists() && reactNativePath.toFile().exists()) {
|
39
|
+
return nodeModulesPath.toString()
|
40
|
+
}
|
41
|
+
basePath = basePath.getParent()
|
42
|
+
}
|
43
|
+
throw new GradleException("React-Native-Skia: Failed to find node_modules/ path!")
|
44
|
+
}
|
45
|
+
|
46
|
+
def nodeModules = findNodeModules(projectDir)
|
47
|
+
logger.warn("react-native-skia: node_modules/ found at: ${nodeModules}")
|
48
|
+
|
49
|
+
def sourceBuild = false
|
50
|
+
def defaultDir = null
|
51
|
+
def androidSourcesDir = null
|
52
|
+
def androidSourcesName = 'React Native sources'
|
53
|
+
|
54
|
+
if (rootProject.ext.has('reactNativeAndroidRoot')) {
|
55
|
+
defaultDir = rootProject.ext.get('reactNativeAndroidRoot')
|
56
|
+
androidSourcesDir = defaultDir.parentFile.toString()
|
57
|
+
} else if (findProject(':ReactAndroid') != null) {
|
58
|
+
sourceBuild = true
|
59
|
+
defaultDir = project(':ReactAndroid').projectDir
|
60
|
+
androidSourcesDir = defaultDir.parentFile.toString()
|
61
|
+
} else {
|
62
|
+
defaultDir = file("$nodeModules/react-native/android")
|
63
|
+
androidSourcesDir = defaultDir.parentFile.toString()
|
64
|
+
}
|
65
|
+
|
66
|
+
if (!defaultDir.exists()) {
|
67
|
+
throw new GradleException(
|
68
|
+
"${project.name}: React Native android directory (node_modules/react-native/android) does not exist! Resolved node_modules to: ${nodeModules}"
|
69
|
+
)
|
70
|
+
}
|
71
|
+
|
72
|
+
def prebuiltDir = sourceBuild
|
73
|
+
? "$nodeModules/react-native/ReactAndroid/src/main/jni/prebuilt/lib"
|
74
|
+
: "$buildDir/react-native-0*/jni"
|
75
|
+
|
76
|
+
|
77
|
+
def reactProperties = new Properties()
|
78
|
+
file("$nodeModules/react-native/ReactAndroid/gradle.properties").withInputStream { reactProperties.load(it) }
|
79
|
+
def REACT_NATIVE_VERSION = reactProperties.getProperty("VERSION_NAME").split("\\.")[1].toInteger()
|
80
|
+
|
81
|
+
logger.warn("react-native-skia: React Native version: ${REACT_NATIVE_VERSION}")
|
82
|
+
logger.warn("react-native-skia: Is Source build: ${sourceBuild}")
|
83
|
+
logger.warn("react-native-skia: Prebuilt dir: ${prebuiltDir}")
|
84
|
+
|
29
85
|
buildscript {
|
30
86
|
// The Android Gradle plugin is only required when opening the android folder stand-alone.
|
31
87
|
// This avoids unnecessary downloads and potential conflicts when the library is included as a
|
@@ -56,7 +112,10 @@ android {
|
|
56
112
|
cmake {
|
57
113
|
cppFlags "-fexceptions", "-frtti", "-std=c++1y", "-DONANDROID"
|
58
114
|
abiFilters 'x86', 'x86_64', 'armeabi-v7a', 'arm64-v8a'
|
59
|
-
arguments '-DANDROID_STL=c++_shared'
|
115
|
+
arguments '-DANDROID_STL=c++_shared',
|
116
|
+
"-DREACT_NATIVE_VERSION=${REACT_NATIVE_VERSION}",
|
117
|
+
"-DNODE_MODULES_DIR=${nodeModules}",
|
118
|
+
"-DPREBUILT_DIR=${prebuiltDir}"
|
60
119
|
}
|
61
120
|
}
|
62
121
|
}
|
@@ -72,7 +131,13 @@ android {
|
|
72
131
|
}
|
73
132
|
|
74
133
|
packagingOptions {
|
75
|
-
excludes = [
|
134
|
+
excludes = [
|
135
|
+
"**/libc++_shared.so",
|
136
|
+
"**/libfbjni.so",
|
137
|
+
"**/libjsi.so",
|
138
|
+
"**/libreact_nativemodule_core.so",
|
139
|
+
"**/libturbomodulejsijni.so"
|
140
|
+
]
|
76
141
|
}
|
77
142
|
|
78
143
|
|
@@ -114,33 +179,6 @@ dependencies {
|
|
114
179
|
extractJNI(files(rnAAR))
|
115
180
|
}
|
116
181
|
|
117
|
-
def configureReactNativePom(def pom) {
|
118
|
-
def packageJson = new groovy.json.JsonSlurper().parseText(file('../package.json').text)
|
119
|
-
|
120
|
-
pom.project {
|
121
|
-
name packageJson.title
|
122
|
-
artifactId packageJson.name
|
123
|
-
version = packageJson.version
|
124
|
-
group = "com.shopify.reactnative.skia"
|
125
|
-
description packageJson.description
|
126
|
-
url packageJson.repository.baseUrl
|
127
|
-
|
128
|
-
licenses {
|
129
|
-
license {
|
130
|
-
name packageJson.license
|
131
|
-
url packageJson.repository.baseUrl + '/blob/master/' + packageJson.licenseFilename
|
132
|
-
distribution 'repo'
|
133
|
-
}
|
134
|
-
}
|
135
|
-
|
136
|
-
developers {
|
137
|
-
developer {
|
138
|
-
name packageJson.author
|
139
|
-
}
|
140
|
-
}
|
141
|
-
}
|
142
|
-
}
|
143
|
-
|
144
182
|
afterEvaluate { project ->
|
145
183
|
task androidSourcesJar(type: Jar) {
|
146
184
|
classifier = 'sources'
|
@@ -188,9 +226,18 @@ task extractJNIFiles {
|
|
188
226
|
}
|
189
227
|
}
|
190
228
|
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
229
|
+
extractJNIFiles.mustRunAfter extractAARHeaders
|
230
|
+
|
231
|
+
def nativeBuildDependsOn(dependsOnTask, variant) {
|
232
|
+
def buildTasks = tasks.findAll({ task ->
|
233
|
+
!task.name.contains("Clean") && (task.name.contains("externalNative") || task.name.contains("CMake")) })
|
234
|
+
if (variant != null) {
|
235
|
+
buildTasks = buildTasks.findAll({ task -> task.name.contains(variant) })
|
236
|
+
}
|
237
|
+
buildTasks.forEach { task -> task.dependsOn(dependsOnTask) }
|
196
238
|
}
|
239
|
+
|
240
|
+
afterEvaluate {
|
241
|
+
nativeBuildDependsOn(extractAARHeaders, null)
|
242
|
+
nativeBuildDependsOn(extractJNIFiles, null)
|
243
|
+
}
|
@@ -31,16 +31,13 @@ namespace RNSkia
|
|
31
31
|
/**** DTOR ***/
|
32
32
|
JniSkiaDrawView::~JniSkiaDrawView()
|
33
33
|
{
|
34
|
-
#if LOG_ALL_DRAWING
|
35
|
-
RNSkLogger::logToConsole("JniSkiaDrawView::~JniSkiaDrawView %i", getNativeId());
|
36
|
-
#endif
|
37
34
|
}
|
38
35
|
|
39
36
|
/**** JNI ****/
|
40
37
|
|
41
38
|
TSelf JniSkiaDrawView::initHybrid(
|
42
|
-
|
43
|
-
|
39
|
+
alias_ref<HybridClass::jhybridobject> jThis,
|
40
|
+
JavaSkiaManager skiaManager)
|
44
41
|
{
|
45
42
|
return makeCxxInstance(jThis, skiaManager);
|
46
43
|
}
|
@@ -60,17 +57,17 @@ namespace RNSkia
|
|
60
57
|
{
|
61
58
|
if (mode.compare("continuous") == 0)
|
62
59
|
{
|
63
|
-
setDrawingMode(RNSkDrawingMode::Continuous);
|
60
|
+
_drawView->setDrawingMode(RNSkDrawingMode::Continuous);
|
64
61
|
}
|
65
62
|
else
|
66
63
|
{
|
67
|
-
setDrawingMode(RNSkDrawingMode::Default);
|
64
|
+
_drawView->setDrawingMode(RNSkDrawingMode::Default);
|
68
65
|
}
|
69
66
|
}
|
70
67
|
|
71
68
|
void JniSkiaDrawView::setDebugMode(bool show)
|
72
69
|
{
|
73
|
-
setShowDebugOverlays(show);
|
70
|
+
_drawView->setShowDebugOverlays(show);
|
74
71
|
}
|
75
72
|
|
76
73
|
void JniSkiaDrawView::updateTouchPoints(jni::JArrayDouble touches)
|
@@ -78,7 +75,7 @@ namespace RNSkia
|
|
78
75
|
// Create touch points
|
79
76
|
std::vector<RNSkia::RNSkTouchPoint> points;
|
80
77
|
auto pin = touches.pin();
|
81
|
-
auto scale =
|
78
|
+
auto scale = _drawView->getPixelDensity();
|
82
79
|
points.reserve(pin.size() / 4);
|
83
80
|
for (size_t i = 0; i < pin.size(); i += 4)
|
84
81
|
{
|
@@ -89,81 +86,27 @@ namespace RNSkia
|
|
89
86
|
point.type = (RNSkia::RNSkTouchType)pin[i + 3];
|
90
87
|
points.push_back(point);
|
91
88
|
}
|
92
|
-
updateTouchState(std::move(points));
|
89
|
+
_drawView->updateTouchState(std::move(points));
|
93
90
|
}
|
94
91
|
|
95
92
|
void JniSkiaDrawView::surfaceAvailable(jobject surface, int width, int height)
|
96
93
|
{
|
97
|
-
|
98
|
-
RNSkLogger::logToConsole("JniSkiaDrawView::surfaceAvailable %i", getNativeId());
|
99
|
-
#endif
|
100
|
-
|
101
|
-
_width = width;
|
102
|
-
_height = height;
|
103
|
-
|
104
|
-
if (_renderer == nullptr)
|
105
|
-
{
|
106
|
-
// Create renderer!
|
107
|
-
_renderer = new SkiaOpenGLRenderer(
|
108
|
-
ANativeWindow_fromSurface(Environment::current(), surface), getNativeId());
|
109
|
-
|
110
|
-
// Set the draw function
|
111
|
-
setNativeDrawFunc(std::bind(&JniSkiaDrawView::drawFrame, this, std::placeholders::_1));
|
112
|
-
|
113
|
-
// Redraw
|
114
|
-
requestRedraw();
|
115
|
-
}
|
94
|
+
_drawView->surfaceAvailable(ANativeWindow_fromSurface(Environment::current(), surface), width, height);
|
116
95
|
}
|
117
96
|
|
118
97
|
void JniSkiaDrawView::surfaceSizeChanged(int width, int height)
|
119
98
|
{
|
120
|
-
|
121
|
-
RNSkLogger::logToConsole("JniSkiaDrawView::surfaceSizeChanged %i", getNativeId());
|
122
|
-
#endif
|
123
|
-
|
124
|
-
_width = width;
|
125
|
-
_height = height;
|
126
|
-
|
127
|
-
// Redraw after size change
|
128
|
-
requestRedraw();
|
99
|
+
_drawView->surfaceSizeChanged(width, height);
|
129
100
|
}
|
130
101
|
|
131
102
|
void JniSkiaDrawView::surfaceDestroyed()
|
132
103
|
{
|
133
|
-
|
134
|
-
RNSkLogger::logToConsole("JniSkiaDrawView::surfaceDestroyed %i", getNativeId());
|
135
|
-
#endif
|
136
|
-
if (_renderer != nullptr)
|
137
|
-
{
|
138
|
-
// Turn off drawing
|
139
|
-
setNativeDrawFunc(nullptr);
|
140
|
-
|
141
|
-
// Start teardown
|
142
|
-
_renderer->teardown();
|
143
|
-
|
144
|
-
// Ask for a redraw to tear down the render pipeline. This
|
145
|
-
// needs to be done on the render thread since OpenGL demands
|
146
|
-
// same thread access for OpenGL contexts.
|
147
|
-
getPlatformContext()->runOnRenderThread([this]()
|
148
|
-
{
|
149
|
-
if(_renderer != nullptr) {
|
150
|
-
_renderer->run(nullptr, 0, 0);
|
151
|
-
} });
|
152
|
-
|
153
|
-
// Wait until the above render has finished.
|
154
|
-
_renderer->waitForTeardown();
|
155
|
-
|
156
|
-
// Delete renderer. All resources should be released during teardown.
|
157
|
-
delete _renderer;
|
158
|
-
_renderer = nullptr;
|
159
|
-
}
|
104
|
+
_drawView->surfaceDestroyed();
|
160
105
|
}
|
161
106
|
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
// No need to check if the renderer is nullptr since we only get here if it is not.
|
167
|
-
_renderer->run(picture, _width, _height);
|
107
|
+
void JniSkiaDrawView::releaseSurface() {
|
108
|
+
jni::ThreadScope ts;
|
109
|
+
static auto method = javaPart_->getClass()->getMethod<void(void)>("releaseSurface");
|
110
|
+
method(javaPart_.get());
|
168
111
|
}
|
169
112
|
} // namespace RNSkia
|
@@ -47,7 +47,7 @@ void JniSkiaManager::initializeRuntime() {
|
|
47
47
|
}
|
48
48
|
|
49
49
|
void JniSkiaManager::registerSkiaView(int viewTag, JniSkiaDrawView *skiaView) {
|
50
|
-
_skManager->registerSkiaDrawView(viewTag, skiaView);
|
50
|
+
_skManager->registerSkiaDrawView(viewTag, skiaView->getDrawViewImpl());
|
51
51
|
}
|
52
52
|
|
53
53
|
void JniSkiaManager::unregisterSkiaView(int viewTag) {
|
@@ -5,17 +5,16 @@
|
|
5
5
|
#include <thread>
|
6
6
|
#include <string>
|
7
7
|
|
8
|
-
#include <EGL/egl.h>
|
9
|
-
#include <GLES2/gl2.h>
|
10
8
|
#include <fbjni/fbjni.h>
|
11
9
|
#include <jni.h>
|
12
10
|
#include <jsi/jsi.h>
|
13
11
|
#include <thread>
|
14
12
|
|
15
13
|
#include <RNSkDrawView.h>
|
16
|
-
#include
|
17
|
-
#include
|
18
|
-
|
14
|
+
#include <JniSkiaManager.h>
|
15
|
+
#include <JniSkiaDrawView.h>
|
16
|
+
|
17
|
+
#include <RNSkDrawViewImpl.h>
|
19
18
|
|
20
19
|
#include <SkSurface.h>
|
21
20
|
#include <SkRefCnt.h>
|
@@ -31,16 +30,15 @@ namespace RNSkia
|
|
31
30
|
|
32
31
|
using JavaSkiaManager = jni::alias_ref<JniSkiaManager::javaobject>;
|
33
32
|
|
34
|
-
class JniSkiaDrawView : public jni::HybridClass<JniSkiaDrawView
|
35
|
-
public RNSkDrawView
|
33
|
+
class JniSkiaDrawView : public jni::HybridClass<JniSkiaDrawView>
|
36
34
|
{
|
37
35
|
public:
|
38
36
|
static auto constexpr kJavaDescriptor = "Lcom/shopify/reactnative/skia/SkiaDrawView;";
|
39
37
|
static auto constexpr TAG = "ReactNativeSkia";
|
40
38
|
|
41
39
|
static jni::local_ref<jhybriddata> initHybrid(
|
42
|
-
|
43
|
-
|
40
|
+
jni::alias_ref<jhybridobject>,
|
41
|
+
JavaSkiaManager);
|
44
42
|
|
45
43
|
static void registerNatives();
|
46
44
|
|
@@ -52,30 +50,28 @@ namespace RNSkia
|
|
52
50
|
|
53
51
|
~JniSkiaDrawView();
|
54
52
|
|
55
|
-
|
56
|
-
|
57
|
-
|
53
|
+
std::shared_ptr<RNSkDrawView> getDrawViewImpl() { return _drawView; }
|
54
|
+
|
55
|
+
void releaseSurface();
|
58
56
|
|
57
|
+
protected:
|
59
58
|
void setMode(std::string mode);
|
60
59
|
void setDebugMode(bool show);
|
61
60
|
|
62
61
|
private:
|
63
62
|
friend HybridBase;
|
64
63
|
|
65
|
-
|
66
|
-
|
67
|
-
int _width = 0;
|
68
|
-
int _height = 0;
|
69
|
-
|
70
|
-
SkiaOpenGLRenderer* _renderer = nullptr;
|
64
|
+
std::shared_ptr<RNSkDrawViewImpl> _drawView;
|
71
65
|
|
72
66
|
jni::global_ref<JniSkiaDrawView::javaobject> javaPart_;
|
73
67
|
|
74
68
|
explicit JniSkiaDrawView(
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
69
|
+
jni::alias_ref<JniSkiaDrawView::jhybridobject> jThis,
|
70
|
+
JavaSkiaManager skiaManager)
|
71
|
+
: javaPart_(jni::make_global(jThis)),
|
72
|
+
_drawView(std::make_shared<RNSkDrawViewImpl>(skiaManager->cthis()->getPlatformContext(), [this]() {
|
73
|
+
releaseSurface();
|
74
|
+
})) {
|
79
75
|
}
|
80
76
|
};
|
81
77
|
|
@@ -7,7 +7,7 @@
|
|
7
7
|
#include <memory>
|
8
8
|
|
9
9
|
#include <JniPlatformContext.h>
|
10
|
-
#include <
|
10
|
+
#include <RNSkPlatformContextImpl.h>
|
11
11
|
|
12
12
|
#include <RNSkLog.h>
|
13
13
|
|
@@ -48,14 +48,14 @@ class JniSkiaManager : public jni::HybridClass<JniSkiaManager> {
|
|
48
48
|
: _javaPart(jni::make_global(jThis)),
|
49
49
|
_jsRuntime(runtime),
|
50
50
|
_jsCallInvoker(jsCallInvoker),
|
51
|
-
_context(std::make_shared<
|
51
|
+
_context(std::make_shared<RNSkPlatformContextImpl>(platformContext, runtime, jsCallInvoker)) {
|
52
52
|
|
53
53
|
}
|
54
54
|
|
55
55
|
void registerSkiaView(int viewTag, JniSkiaDrawView *skiaView);
|
56
56
|
void unregisterSkiaView(int viewTag);
|
57
57
|
|
58
|
-
std::shared_ptr<
|
58
|
+
std::shared_ptr<RNSkPlatformContextImpl> getPlatformContext() { return _context; }
|
59
59
|
|
60
60
|
void invalidate() {
|
61
61
|
_context->stopDrawLoop();
|
@@ -73,7 +73,7 @@ class JniSkiaManager : public jni::HybridClass<JniSkiaManager> {
|
|
73
73
|
|
74
74
|
jsi::Runtime *_jsRuntime;
|
75
75
|
std::shared_ptr<facebook::react::CallInvoker> _jsCallInvoker;
|
76
|
-
std::shared_ptr<
|
76
|
+
std::shared_ptr<RNSkPlatformContextImpl> _context;
|
77
77
|
|
78
78
|
void initializeRuntime();
|
79
79
|
};
|
@@ -0,0 +1,68 @@
|
|
1
|
+
#include <RNSkDrawViewImpl.h>
|
2
|
+
|
3
|
+
#pragma clang diagnostic push
|
4
|
+
#pragma clang diagnostic ignored "-Wdocumentation"
|
5
|
+
|
6
|
+
#include <SkSurface.h>
|
7
|
+
#include <SkCanvas.h>
|
8
|
+
|
9
|
+
#pragma clang diagnostic pop
|
10
|
+
|
11
|
+
#include <RNSkLog.h>
|
12
|
+
|
13
|
+
namespace RNSkia {
|
14
|
+
RNSkDrawViewImpl::RNSkDrawViewImpl(std::shared_ptr <RNSkia::RNSkPlatformContext> context, std::function<void()> releaseSurfaceCallback) :
|
15
|
+
RNSkia::RNSkDrawView(context),
|
16
|
+
_releaseSurfaceCallback(std::move(releaseSurfaceCallback)) {}
|
17
|
+
|
18
|
+
void RNSkDrawViewImpl::surfaceAvailable(ANativeWindow* surface, int width, int height) {
|
19
|
+
_width = width;
|
20
|
+
_height = height;
|
21
|
+
|
22
|
+
if (_renderer == nullptr)
|
23
|
+
{
|
24
|
+
// Create renderer!
|
25
|
+
_renderer = std::make_unique<SkiaOpenGLRenderer>(surface, getNativeId());
|
26
|
+
|
27
|
+
// Redraw
|
28
|
+
requestRedraw();
|
29
|
+
}
|
30
|
+
}
|
31
|
+
|
32
|
+
void RNSkDrawViewImpl::surfaceDestroyed() {
|
33
|
+
if (_renderer != nullptr)
|
34
|
+
{
|
35
|
+
// Start teardown
|
36
|
+
_renderer->teardown();
|
37
|
+
|
38
|
+
// Teardown renderer on the render thread since OpenGL demands
|
39
|
+
// same thread access for OpenGL contexts.
|
40
|
+
getPlatformContext()->runOnRenderThread([weakSelf = weak_from_this()]() {
|
41
|
+
auto self = weakSelf.lock();
|
42
|
+
if(self) {
|
43
|
+
auto drawViewImpl = std::dynamic_pointer_cast<RNSkDrawViewImpl>(self);
|
44
|
+
if(drawViewImpl->_renderer != nullptr) {
|
45
|
+
drawViewImpl->_renderer->run(nullptr, 0, 0);
|
46
|
+
}
|
47
|
+
// Remove renderer
|
48
|
+
drawViewImpl->_renderer = nullptr;
|
49
|
+
drawViewImpl->_releaseSurfaceCallback();
|
50
|
+
}
|
51
|
+
});
|
52
|
+
}
|
53
|
+
}
|
54
|
+
|
55
|
+
void RNSkDrawViewImpl::surfaceSizeChanged(int width, int height) {
|
56
|
+
_width = width;
|
57
|
+
_height = height;
|
58
|
+
|
59
|
+
// Redraw after size change
|
60
|
+
requestRedraw();
|
61
|
+
}
|
62
|
+
|
63
|
+
void RNSkDrawViewImpl::drawPicture(const sk_sp <SkPicture> picture) {
|
64
|
+
if(_renderer != nullptr) {
|
65
|
+
_renderer->run(picture, _width, _height);
|
66
|
+
}
|
67
|
+
}
|
68
|
+
}
|
@@ -0,0 +1,48 @@
|
|
1
|
+
#pragma once
|
2
|
+
|
3
|
+
#include <RNSkDrawView.h>
|
4
|
+
|
5
|
+
#include <SkiaOpenGLRenderer.h>
|
6
|
+
#include <android/native_window.h>
|
7
|
+
|
8
|
+
#pragma clang diagnostic push
|
9
|
+
#pragma clang diagnostic ignored "-Wdocumentation"
|
10
|
+
|
11
|
+
#include <SkPicture.h>
|
12
|
+
#include <SkRefCnt.h>
|
13
|
+
|
14
|
+
#pragma clang diagnostic pop
|
15
|
+
|
16
|
+
namespace RNSkia {
|
17
|
+
class RNSkDrawViewImpl : public RNSkia::RNSkDrawView {
|
18
|
+
public:
|
19
|
+
RNSkDrawViewImpl(std::shared_ptr <RNSkia::RNSkPlatformContext> context,
|
20
|
+
std::function<void()> releaseSurfaceCallback);
|
21
|
+
|
22
|
+
void surfaceAvailable(ANativeWindow* surface, int, int);
|
23
|
+
void surfaceDestroyed();
|
24
|
+
void surfaceSizeChanged(int, int);
|
25
|
+
|
26
|
+
float getPixelDensity() {
|
27
|
+
return getPlatformContext()->getPixelDensity();
|
28
|
+
}
|
29
|
+
|
30
|
+
protected:
|
31
|
+
int getWidth() override { return _width * getPlatformContext()->getPixelDensity(); };
|
32
|
+
|
33
|
+
int getHeight() override { return _height * getPlatformContext()->getPixelDensity(); };
|
34
|
+
|
35
|
+
void drawPicture(const sk_sp <SkPicture> picture) override;
|
36
|
+
|
37
|
+
private:
|
38
|
+
bool createSkiaSurface();
|
39
|
+
|
40
|
+
std::unique_ptr<SkiaOpenGLRenderer> _renderer = nullptr;
|
41
|
+
|
42
|
+
int _nativeId;
|
43
|
+
int _width = -1;
|
44
|
+
int _height = -1;
|
45
|
+
|
46
|
+
std::function<void()> _releaseSurfaceCallback;
|
47
|
+
};
|
48
|
+
}
|
@@ -11,11 +11,11 @@
|
|
11
11
|
namespace RNSkia {
|
12
12
|
using namespace facebook;
|
13
13
|
|
14
|
-
class
|
14
|
+
class RNSkPlatformContextImpl: public RNSkPlatformContext {
|
15
15
|
public:
|
16
|
-
|
17
|
-
|
18
|
-
|
16
|
+
RNSkPlatformContextImpl(JniPlatformContext* jniPlatformContext,
|
17
|
+
jsi::Runtime *runtime,
|
18
|
+
std::shared_ptr<facebook::react::CallInvoker> jsCallInvoker) :
|
19
19
|
RNSkPlatformContext(runtime,
|
20
20
|
jsCallInvoker,
|
21
21
|
jniPlatformContext->getPixelDensity()),
|