expo-gl 12.1.0 → 12.3.0
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/CHANGELOG.md +16 -0
- package/android/CMakeLists.txt +6 -15
- package/android/build.gradle +26 -88
- package/android/legacy/CMakeLists.txt +62 -0
- package/android/src/main/java/expo/modules/gl/GLPackage.java +0 -6
- package/android/src/main/java/expo/modules/gl/GLView.kt +85 -0
- package/android/src/main/java/expo/modules/gl/GLViewModule.kt +14 -0
- package/build/GLView.d.ts +1 -1
- package/build/GLView.d.ts.map +1 -1
- package/build/GLView.types.d.ts +5 -5
- package/build/GLView.types.d.ts.map +1 -1
- package/build/GLView.web.d.ts +1 -1
- package/build/GLView.web.d.ts.map +1 -1
- package/build/GLView.web.js +1 -1
- package/build/GLView.web.js.map +1 -1
- package/expo-module.config.json +3 -0
- package/package.json +3 -3
- package/src/GLView.web.tsx +2 -2
- package/android/src/main/java/expo/modules/gl/GLView.java +0 -117
- package/android/src/main/java/expo/modules/gl/GLViewManager.java +0 -38
package/CHANGELOG.md
CHANGED
|
@@ -10,6 +10,22 @@
|
|
|
10
10
|
|
|
11
11
|
### 💡 Others
|
|
12
12
|
|
|
13
|
+
## 12.3.0 — 2023-02-03
|
|
14
|
+
|
|
15
|
+
### 🎉 New features
|
|
16
|
+
|
|
17
|
+
- Migrated the view manager to the new Expo modules API and thus added support for Fabric on Android. ([#20749](https://github.com/expo/expo/pull/20749) by [@lukmccall](https://github.com/lukmccall))
|
|
18
|
+
|
|
19
|
+
### 💡 Others
|
|
20
|
+
|
|
21
|
+
- On Android bump `compileSdkVersion` and `targetSdkVersion` to `33`. ([#20721](https://github.com/expo/expo/pull/20721) by [@lukmccall](https://github.com/lukmccall))
|
|
22
|
+
|
|
23
|
+
## 12.2.0 — 2022-12-30
|
|
24
|
+
|
|
25
|
+
### 🐛 Bug fixes
|
|
26
|
+
|
|
27
|
+
- Added React Native 0.71 support. ([#20470](https://github.com/expo/expo/pull/20470) by [@kudo](https://github.com/kudo))
|
|
28
|
+
|
|
13
29
|
## 12.1.0 — 2022-12-05
|
|
14
30
|
|
|
15
31
|
### 🎉 New features
|
package/android/CMakeLists.txt
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
cmake_minimum_required(VERSION 3.4.1)
|
|
2
2
|
|
|
3
|
+
project(expo-gl)
|
|
4
|
+
|
|
3
5
|
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
|
4
6
|
set(CMAKE_VERBOSE_MAKEFILE ON)
|
|
5
7
|
set(CMAKE_CXX_STANDARD 17)
|
|
@@ -7,6 +9,7 @@ set(CMAKE_CXX_STANDARD 17)
|
|
|
7
9
|
set(PACKAGE_NAME "expo-gl")
|
|
8
10
|
set(BUILD_DIR ${CMAKE_SOURCE_DIR}/build)
|
|
9
11
|
set(COMMON_DIR ${CMAKE_SOURCE_DIR}/../common)
|
|
12
|
+
set(ignoreMe "${REACT_NATIVE_DIR} ${RN_SO_DIR}")
|
|
10
13
|
|
|
11
14
|
add_library(
|
|
12
15
|
${PACKAGE_NAME} SHARED
|
|
@@ -26,22 +29,10 @@ add_library(
|
|
|
26
29
|
${COMMON_DIR}/EXTypedArrayApi.h
|
|
27
30
|
./src/main/cpp/EXGLJniApi.cpp)
|
|
28
31
|
|
|
29
|
-
# Extracted AAR: ${BUILD_DIR}/react-native-0*/jni/${ANDROID_ABI}
|
|
30
|
-
file(GLOB LIBRN_DIR "${RN_SO_DIR}/${ANDROID_ABI}")
|
|
31
|
-
if(NOT LIBRN_DIR)
|
|
32
|
-
# If /${ANDROID_ABI} dir not found, then ${RN_SO_DIR} is probably:
|
|
33
|
-
# ReactAndroid/build/react-ndk/exported
|
|
34
|
-
file(GLOB LIBRN_DIR "${RN_SO_DIR}")
|
|
35
|
-
endif()
|
|
36
|
-
|
|
37
32
|
target_include_directories(
|
|
38
|
-
${PACKAGE_NAME} PRIVATE "${
|
|
39
|
-
"${COMMON_DIR}")
|
|
33
|
+
${PACKAGE_NAME} PRIVATE "${COMMON_DIR}")
|
|
40
34
|
|
|
41
|
-
|
|
42
|
-
JSI_LIB jsi
|
|
43
|
-
PATHS ${LIBRN_DIR}
|
|
44
|
-
NO_CMAKE_FIND_ROOT_PATH)
|
|
35
|
+
find_package(ReactAndroid REQUIRED CONFIG)
|
|
45
36
|
|
|
46
37
|
find_library(LOG_LIB log)
|
|
47
38
|
find_library(GLES_LIB GLESv3)
|
|
@@ -56,4 +47,4 @@ target_compile_options(
|
|
|
56
47
|
-Wno-unused-parameter
|
|
57
48
|
-Wshorten-64-to-32
|
|
58
49
|
-Wstrict-prototypes)
|
|
59
|
-
target_link_libraries(${PACKAGE_NAME}
|
|
50
|
+
target_link_libraries(${PACKAGE_NAME} ReactAndroid::jsi ${LOG_LIB} ${GLES_LIB} android)
|
package/android/build.gradle
CHANGED
|
@@ -6,10 +6,7 @@ apply plugin: 'maven-publish'
|
|
|
6
6
|
apply plugin: "de.undercouch.download"
|
|
7
7
|
|
|
8
8
|
group = 'host.exp.exponent'
|
|
9
|
-
version = '12.
|
|
10
|
-
|
|
11
|
-
def customDownloadsDir = System.getenv("REACT_NATIVE_DOWNLOADS_DIR")
|
|
12
|
-
def downloadsDir = customDownloadsDir ? new File(customDownloadsDir) : new File("$buildDir/downloads")
|
|
9
|
+
version = '12.3.0'
|
|
13
10
|
|
|
14
11
|
def REACT_NATIVE_BUILD_FROM_SOURCE = findProject(":ReactAndroid") != null
|
|
15
12
|
def REACT_NATIVE_DIR = REACT_NATIVE_BUILD_FROM_SOURCE
|
|
@@ -17,11 +14,12 @@ def REACT_NATIVE_DIR = REACT_NATIVE_BUILD_FROM_SOURCE
|
|
|
17
14
|
: new File(["node", "--print", "require.resolve('react-native/package.json')"].execute(null, rootDir).text.trim()).parent
|
|
18
15
|
def RN_SO_DIR = REACT_NATIVE_BUILD_FROM_SOURCE
|
|
19
16
|
? Paths.get(findProject(":ReactAndroid").getProjectDir().toString(), "build", "intermediates", "library_*", "*", "jni")
|
|
20
|
-
: "${buildDir}/react
|
|
17
|
+
: "${buildDir}/react/jni"
|
|
21
18
|
|
|
22
19
|
def reactProperties = new Properties()
|
|
23
20
|
file("$REACT_NATIVE_DIR/ReactAndroid/gradle.properties").withInputStream { reactProperties.load(it) }
|
|
24
|
-
def
|
|
21
|
+
def REACT_NATIVE_VERSION = System.getenv("REACT_NATIVE_OVERRIDE_VERSION") ?: reactProperties.getProperty("VERSION_NAME")
|
|
22
|
+
def REACT_NATIVE_TARGET_VERSION = REACT_NATIVE_VERSION.split("\\.")[1].toInteger()
|
|
25
23
|
|
|
26
24
|
def reactNativeArchitectures() {
|
|
27
25
|
def value = project.getProperties().get("reactNativeArchitectures")
|
|
@@ -83,7 +81,7 @@ afterEvaluate {
|
|
|
83
81
|
}
|
|
84
82
|
|
|
85
83
|
android {
|
|
86
|
-
compileSdkVersion safeExtGet("compileSdkVersion",
|
|
84
|
+
compileSdkVersion safeExtGet("compileSdkVersion", 33)
|
|
87
85
|
|
|
88
86
|
if (rootProject.hasProperty("ndkPath")) {
|
|
89
87
|
ndkPath rootProject.ext.ndkPath
|
|
@@ -103,9 +101,9 @@ android {
|
|
|
103
101
|
|
|
104
102
|
defaultConfig {
|
|
105
103
|
minSdkVersion safeExtGet("minSdkVersion", 21)
|
|
106
|
-
targetSdkVersion safeExtGet("targetSdkVersion",
|
|
104
|
+
targetSdkVersion safeExtGet("targetSdkVersion", 33)
|
|
107
105
|
versionCode 31
|
|
108
|
-
versionName "12.
|
|
106
|
+
versionName "12.3.0"
|
|
109
107
|
|
|
110
108
|
externalNativeBuild {
|
|
111
109
|
cmake {
|
|
@@ -119,10 +117,18 @@ android {
|
|
|
119
117
|
|
|
120
118
|
externalNativeBuild {
|
|
121
119
|
cmake {
|
|
122
|
-
|
|
120
|
+
if (REACT_NATIVE_TARGET_VERSION >= 71) {
|
|
121
|
+
path "CMakeLists.txt"
|
|
122
|
+
} else {
|
|
123
|
+
path "legacy/CMakeLists.txt"
|
|
124
|
+
}
|
|
123
125
|
}
|
|
124
126
|
}
|
|
125
127
|
|
|
128
|
+
buildFeatures {
|
|
129
|
+
prefab true
|
|
130
|
+
}
|
|
131
|
+
|
|
126
132
|
packagingOptions {
|
|
127
133
|
// Gradle will add cmake target dependencies into packaging.
|
|
128
134
|
excludes += [
|
|
@@ -150,86 +156,18 @@ dependencies {
|
|
|
150
156
|
implementation project(':expo-modules-core')
|
|
151
157
|
|
|
152
158
|
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:${getKotlinVersion()}"
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
def downloadReactNativeNightlyAAR = { buildType, version, downloadFile ->
|
|
156
|
-
def classifier = buildType == 'Debug' ? 'debug' : 'release'
|
|
157
|
-
download.run {
|
|
158
|
-
src("https://oss.sonatype.org/service/local/artifact/maven/redirect?r=snapshots&g=com.facebook.react&a=react-native&c=${classifier}&e=aar&v=${version}-SNAPSHOT")
|
|
159
|
-
onlyIfNewer(true)
|
|
160
|
-
overwrite(false)
|
|
161
|
-
dest(downloadFile)
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
def extractReactNativeAAR = { buildType ->
|
|
166
|
-
def suffix = buildType == 'Debug' ? '-debug' : '-release'
|
|
167
|
-
def rnAAR
|
|
168
|
-
if (reactNativeIsNightly) {
|
|
169
|
-
def downloadFile = file("${downloadsDir}/react-native-nightly.aar")
|
|
170
|
-
downloadReactNativeNightlyAAR(buildType, reactProperties.getProperty("VERSION_NAME"), downloadFile)
|
|
171
|
-
rnAAR = downloadFile
|
|
172
|
-
} else {
|
|
173
|
-
def rnAARs = fileTree(REACT_NATIVE_DIR).matching { include "**/react-native/**/*${suffix}.aar" }
|
|
174
|
-
if (rnAARs.isEmpty()) {
|
|
175
|
-
rnAARs = fileTree(REACT_NATIVE_DIR).matching { include "**/react-native/**/*.aar" }
|
|
176
|
-
}
|
|
177
|
-
if (rnAARs.any()) {
|
|
178
|
-
// node_modules/react-native has a .aar, extract headers
|
|
179
|
-
if (rnAARs.size() > 1) {
|
|
180
|
-
logger.error("More than one React Native AAR file has been found:")
|
|
181
|
-
rnAARs.each {println(it) }
|
|
182
|
-
throw new GradleException("Multiple React Native AARs found:\n${rnAARs.join("\n")}" +
|
|
183
|
-
"\nRemove the old ones and try again")
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
rnAAR = rnAARs.singleFile
|
|
187
|
-
}
|
|
188
|
-
def file = rnAAR.absoluteFile
|
|
189
|
-
def packageName = file.name.tokenize('-')[0]
|
|
190
|
-
copy {
|
|
191
|
-
from zipTree(file)
|
|
192
|
-
into "$buildDir/react-native.aar"
|
|
193
|
-
include "jni/**/*"
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
159
|
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
160
|
+
// Remove this when we drop SDK 47
|
|
161
|
+
if (REACT_NATIVE_TARGET_VERSION >= 71) {
|
|
162
|
+
compileOnly 'com.facebook.react:react-android'
|
|
200
163
|
}
|
|
201
164
|
}
|
|
202
165
|
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
doLast {
|
|
211
|
-
configurations.extractJNI.files.each {
|
|
212
|
-
def file = it.absoluteFile
|
|
213
|
-
copy {
|
|
214
|
-
from zipTree(file)
|
|
215
|
-
into "$buildDir/$file.name"
|
|
216
|
-
include "jni/**/*"
|
|
217
|
-
}
|
|
218
|
-
}
|
|
219
|
-
}
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
tasks.whenTaskAdded { task ->
|
|
223
|
-
if (!task.name.contains("Clean") && (task.name.contains('externalNativeBuild') || task.name.startsWith('configureCMake'))) {
|
|
224
|
-
def buildType = task.name.endsWith('Debug') ? 'Debug' : 'Release'
|
|
225
|
-
task.dependsOn(extractJNIFiles)
|
|
226
|
-
if (REACT_NATIVE_BUILD_FROM_SOURCE) {
|
|
227
|
-
task.dependsOn(":ReactAndroid:copy${buildType}JniLibsProjectOnly")
|
|
228
|
-
} else {
|
|
229
|
-
task.dependsOn("extractReactNativeAAR${buildType}")
|
|
230
|
-
}
|
|
231
|
-
} else if (task.name.startsWith('generateJsonModel') && REACT_NATIVE_BUILD_FROM_SOURCE) {
|
|
232
|
-
def buildType = task.name.endsWith('Debug') ? 'Debug' : 'Release'
|
|
233
|
-
task.dependsOn(":ReactAndroid:copy${buildType}JniLibsProjectOnly")
|
|
234
|
-
}
|
|
166
|
+
// Remove this when we drop SDK 47
|
|
167
|
+
if (REACT_NATIVE_TARGET_VERSION < 71) {
|
|
168
|
+
project.ext.extraLegacyReactNativeLibs = [
|
|
169
|
+
'prepareDoubleConversion',
|
|
170
|
+
'prepareFolly',
|
|
171
|
+
]
|
|
172
|
+
applyLegacyReactNativeLibsExtractionPlugin()
|
|
235
173
|
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
# Remove this legacy folder when we drop SDK 47
|
|
2
|
+
cmake_minimum_required(VERSION 3.4.1)
|
|
3
|
+
|
|
4
|
+
project(expo-gl)
|
|
5
|
+
|
|
6
|
+
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
|
7
|
+
set(CMAKE_VERBOSE_MAKEFILE ON)
|
|
8
|
+
set(CMAKE_CXX_STANDARD 17)
|
|
9
|
+
|
|
10
|
+
set(PACKAGE_NAME "expo-gl")
|
|
11
|
+
set(BUILD_DIR ${CMAKE_SOURCE_DIR}/../build)
|
|
12
|
+
set(COMMON_DIR ${CMAKE_SOURCE_DIR}/../../common)
|
|
13
|
+
|
|
14
|
+
add_library(
|
|
15
|
+
${PACKAGE_NAME} SHARED
|
|
16
|
+
${COMMON_DIR}/EXGLNativeApi.cpp
|
|
17
|
+
${COMMON_DIR}/EXGLNativeApi.h
|
|
18
|
+
${COMMON_DIR}/EXGLImageUtils.cpp
|
|
19
|
+
${COMMON_DIR}/EXGLImageUtils.h
|
|
20
|
+
${COMMON_DIR}/EXGLNativeContext.cpp
|
|
21
|
+
${COMMON_DIR}/EXGLNativeContext.h
|
|
22
|
+
${COMMON_DIR}/EXGLContextManager.cpp
|
|
23
|
+
${COMMON_DIR}/EXGLContextManager.h
|
|
24
|
+
${COMMON_DIR}/EXWebGLMethods.cpp
|
|
25
|
+
${COMMON_DIR}/EXWebGLMethods.h
|
|
26
|
+
${COMMON_DIR}/EXWebGLRenderer.cpp
|
|
27
|
+
${COMMON_DIR}/EXWebGLRenderer.h
|
|
28
|
+
${COMMON_DIR}/EXTypedArrayApi.cpp
|
|
29
|
+
${COMMON_DIR}/EXTypedArrayApi.h
|
|
30
|
+
../src/main/cpp/EXGLJniApi.cpp)
|
|
31
|
+
|
|
32
|
+
# Extracted AAR: ${BUILD_DIR}/react-native-0*/jni/${ANDROID_ABI}
|
|
33
|
+
file(GLOB LIBRN_DIR "${RN_SO_DIR}/${ANDROID_ABI}")
|
|
34
|
+
if(NOT LIBRN_DIR)
|
|
35
|
+
# If /${ANDROID_ABI} dir not found, then ${RN_SO_DIR} is probably:
|
|
36
|
+
# ReactAndroid/build/react-ndk/exported
|
|
37
|
+
file(GLOB LIBRN_DIR "${RN_SO_DIR}")
|
|
38
|
+
endif()
|
|
39
|
+
|
|
40
|
+
target_include_directories(
|
|
41
|
+
${PACKAGE_NAME} PRIVATE "${REACT_NATIVE_DIR}/ReactCommon/jsi"
|
|
42
|
+
"${COMMON_DIR}")
|
|
43
|
+
|
|
44
|
+
find_library(
|
|
45
|
+
JSI_LIB jsi
|
|
46
|
+
PATHS ${LIBRN_DIR}
|
|
47
|
+
NO_CMAKE_FIND_ROOT_PATH)
|
|
48
|
+
|
|
49
|
+
find_library(LOG_LIB log)
|
|
50
|
+
find_library(GLES_LIB GLESv3)
|
|
51
|
+
|
|
52
|
+
target_compile_options(
|
|
53
|
+
${PACKAGE_NAME}
|
|
54
|
+
PRIVATE -O2
|
|
55
|
+
-fexceptions
|
|
56
|
+
-frtti
|
|
57
|
+
-Wall
|
|
58
|
+
-Wextra
|
|
59
|
+
-Wno-unused-parameter
|
|
60
|
+
-Wshorten-64-to-32
|
|
61
|
+
-Wstrict-prototypes)
|
|
62
|
+
target_link_libraries(${PACKAGE_NAME} ${JSI_LIB} ${LOG_LIB} ${GLES_LIB} android)
|
|
@@ -7,16 +7,10 @@ import java.util.List;
|
|
|
7
7
|
|
|
8
8
|
import expo.modules.core.ExportedModule;
|
|
9
9
|
import expo.modules.core.BasePackage;
|
|
10
|
-
import expo.modules.core.ViewManager;
|
|
11
10
|
|
|
12
11
|
public class GLPackage extends BasePackage {
|
|
13
12
|
@Override
|
|
14
13
|
public List<ExportedModule> createExportedModules(Context context) {
|
|
15
14
|
return Collections.singletonList((ExportedModule) new GLObjectManagerModule(context));
|
|
16
15
|
}
|
|
17
|
-
|
|
18
|
-
@Override
|
|
19
|
-
public List<ViewManager> createViewManagers(Context context) {
|
|
20
|
-
return Collections.singletonList((ViewManager) new GLViewManager());
|
|
21
|
-
}
|
|
22
16
|
}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
package expo.modules.gl
|
|
2
|
+
|
|
3
|
+
import android.annotation.SuppressLint
|
|
4
|
+
import android.content.Context
|
|
5
|
+
import android.graphics.SurfaceTexture
|
|
6
|
+
import android.view.TextureView
|
|
7
|
+
import android.view.TextureView.SurfaceTextureListener
|
|
8
|
+
import expo.modules.kotlin.AppContext
|
|
9
|
+
import expo.modules.kotlin.records.Field
|
|
10
|
+
import expo.modules.kotlin.records.Record
|
|
11
|
+
import expo.modules.kotlin.viewevent.EventDispatcher
|
|
12
|
+
|
|
13
|
+
data class OnSurfaceCreateRecord(
|
|
14
|
+
@Field val exglCtxId: Int
|
|
15
|
+
) : Record
|
|
16
|
+
|
|
17
|
+
@SuppressLint("ViewConstructor")
|
|
18
|
+
class GLView(context: Context, appContext: AppContext) : TextureView(context), SurfaceTextureListener {
|
|
19
|
+
private var onSurfaceCreateWasCalled = false
|
|
20
|
+
private var onSurfaceTextureWasCalledWithZeroSize = false
|
|
21
|
+
private var glContext = GLContext(
|
|
22
|
+
appContext
|
|
23
|
+
.legacyModuleRegistry
|
|
24
|
+
.getExportedModuleOfClass(GLObjectManagerModule::class.java) as GLObjectManagerModule
|
|
25
|
+
)
|
|
26
|
+
|
|
27
|
+
private val exglContextId: Int
|
|
28
|
+
get() = glContext.contextId
|
|
29
|
+
|
|
30
|
+
val onSurfaceCreate by EventDispatcher<OnSurfaceCreateRecord>()
|
|
31
|
+
|
|
32
|
+
init {
|
|
33
|
+
surfaceTextureListener = this
|
|
34
|
+
isOpaque = false
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// Public interface to allow running events on GL thread
|
|
38
|
+
fun runOnGLThread(r: Runnable?) {
|
|
39
|
+
glContext.runAsync(r)
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// `TextureView.SurfaceTextureListener` events
|
|
43
|
+
@Synchronized
|
|
44
|
+
override fun onSurfaceTextureAvailable(surfaceTexture: SurfaceTexture, width: Int, height: Int) {
|
|
45
|
+
if (!onSurfaceCreateWasCalled) {
|
|
46
|
+
// onSurfaceTextureAvailable is sometimes called with 0 size texture
|
|
47
|
+
// and immediately followed by onSurfaceTextureSizeChanged with actual size
|
|
48
|
+
if (width == 0 || height == 0) {
|
|
49
|
+
onSurfaceTextureWasCalledWithZeroSize = true
|
|
50
|
+
}
|
|
51
|
+
if (!onSurfaceTextureWasCalledWithZeroSize) {
|
|
52
|
+
initializeSurfaceInGLContext(surfaceTexture)
|
|
53
|
+
}
|
|
54
|
+
onSurfaceCreateWasCalled = true
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
override fun onSurfaceTextureDestroyed(surface: SurfaceTexture): Boolean {
|
|
59
|
+
glContext.destroy()
|
|
60
|
+
|
|
61
|
+
// reset flag, so the context will be recreated when the new surface is available
|
|
62
|
+
onSurfaceCreateWasCalled = false
|
|
63
|
+
return true
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
@Synchronized
|
|
67
|
+
override fun onSurfaceTextureSizeChanged(surfaceTexture: SurfaceTexture, width: Int, height: Int) {
|
|
68
|
+
if (onSurfaceTextureWasCalledWithZeroSize && (width != 0 || height != 0)) {
|
|
69
|
+
initializeSurfaceInGLContext(surfaceTexture)
|
|
70
|
+
onSurfaceTextureWasCalledWithZeroSize = false
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
override fun onSurfaceTextureUpdated(surface: SurfaceTexture) = Unit
|
|
75
|
+
|
|
76
|
+
fun flush() {
|
|
77
|
+
glContext.flush()
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
private fun initializeSurfaceInGLContext(surfaceTexture: SurfaceTexture) {
|
|
81
|
+
glContext.initialize(surfaceTexture) {
|
|
82
|
+
onSurfaceCreate(OnSurfaceCreateRecord(exglContextId))
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
package expo.modules.gl
|
|
2
|
+
|
|
3
|
+
import expo.modules.kotlin.modules.Module
|
|
4
|
+
import expo.modules.kotlin.modules.ModuleDefinition
|
|
5
|
+
|
|
6
|
+
class GLViewModule : Module() {
|
|
7
|
+
override fun definition() = ModuleDefinition {
|
|
8
|
+
Name("ExponentGLView")
|
|
9
|
+
|
|
10
|
+
View(GLView::class) {
|
|
11
|
+
Events("onSurfaceCreate")
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
}
|
package/build/GLView.d.ts
CHANGED
package/build/GLView.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"GLView.d.ts","sourceRoot":"","sources":["../src/GLView.tsx"],"names":[],"mappings":"AAMA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAI/B,OAAO,EACL,iBAAiB,EACjB,kBAAkB,EAClB,UAAU,EACV,yBAAyB,EACzB,eAAe,EACf,WAAW,EACZ,MAAM,gBAAgB,CAAC;AAIxB,
|
|
1
|
+
{"version":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iBAAiB,CAAC,OAAO,GAAE,eAAoB,GAAG,OAAO,CAAC,UAAU,CAAC;CAO5E"}
|
package/build/GLView.types.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { Component, ComponentClass } from 'react';
|
|
2
2
|
import { ViewProps } from 'react-native';
|
|
3
|
-
export
|
|
3
|
+
export type SurfaceCreateEvent = {
|
|
4
4
|
nativeEvent: {
|
|
5
5
|
exglCtxId: number;
|
|
6
6
|
};
|
|
7
7
|
};
|
|
8
|
-
export
|
|
8
|
+
export type SnapshotOptions = {
|
|
9
9
|
/**
|
|
10
10
|
* Whether to flip the snapshot vertically.
|
|
11
11
|
* @default false
|
|
@@ -40,7 +40,7 @@ export declare type SnapshotOptions = {
|
|
|
40
40
|
*/
|
|
41
41
|
compress?: number;
|
|
42
42
|
};
|
|
43
|
-
export
|
|
43
|
+
export type GLSnapshot = {
|
|
44
44
|
/**
|
|
45
45
|
* URI to the snapshot.
|
|
46
46
|
*/
|
|
@@ -64,8 +64,8 @@ export interface ExpoWebGLRenderingContext extends WebGL2RenderingContext {
|
|
|
64
64
|
flushEXP(): void;
|
|
65
65
|
__expoSetLogging(option: GLLoggingOption): void;
|
|
66
66
|
}
|
|
67
|
-
export
|
|
68
|
-
export
|
|
67
|
+
export type ComponentOrHandle = null | number | Component<any, any> | ComponentClass<any>;
|
|
68
|
+
export type GLViewProps = {
|
|
69
69
|
/**
|
|
70
70
|
* A function that will be called when the OpenGL ES context is created.
|
|
71
71
|
* The function is passed a single argument `gl` that extends a [WebGLRenderingContext](https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14) interface.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"GLView.types.d.ts","sourceRoot":"","sources":["../src/GLView.types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,cAAc,EAAE,MAAM,OAAO,CAAC;AAClD,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAGzC,
|
|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,EAAE,GAAG,CAAC,GAAG,cAAc,CAAC,GAAG,CAAC,CAAC;AAG1F,MAAM,MAAM,WAAW,GAAG;IACxB;;;OAGG;IACH,eAAe,CAAC,EAAE,EAAE,yBAAyB,GAAG,IAAI,CAAC;IACrD;;;;;OAKG;IACH,WAAW,EAAE,MAAM,CAAC;IACpB;;;OAGG;IACH,sBAAsB,CAAC,CAAC,QAAQ,EAAE,iBAAiB,GAAG,IAAI,OAAE;CAC7D,GAAG,SAAS,CAAC;AAGd,oBAAY,eAAe;IACzB;;OAEG;IACH,QAAQ,IAAI;IACZ;;OAEG;IACH,YAAY,IAAI;IAChB;;;OAGG;IACH,UAAU,IAAI;IACd;;OAEG;IACH,iBAAiB,IAAI;IACrB;;;OAGG;IACH,gBAAgB,IAAI;IACpB;;OAEG;IACH,GAAG,KAAmE;CACvE"}
|
package/build/GLView.web.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import { WebGLObject } from './GLView';
|
|
3
3
|
import { GLViewProps, GLSnapshot, SnapshotOptions, ComponentOrHandle } from './GLView.types';
|
|
4
|
-
export
|
|
4
|
+
export type GLViewWebProps = GLViewProps & {
|
|
5
5
|
onContextCreate: (gl: WebGLRenderingContext) => void;
|
|
6
6
|
onContextRestored?: (gl?: WebGLRenderingContext) => void;
|
|
7
7
|
onContextLost?: () => void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"GLView.web.d.ts","sourceRoot":"","sources":["../src/GLView.web.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAI/B,OAAO,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AACvC,OAAO,EACL,WAAW,EAEX,UAAU,EACV,eAAe,EACf,iBAAiB,EAClB,MAAM,gBAAgB,CAAC;AAoExB,
|
|
1
|
+
{"version":3,"file":"GLView.web.d.ts","sourceRoot":"","sources":["../src/GLView.web.tsx"],"names":[],"mapp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OAAO,CAAC,IAAI,CAAC;IAIpC,wBAAwB,IAAI,OAAO,CAAC,IAAI,CAAC;IAIzC,kBAAkB,CAAC,QAAQ,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC;CAGtE"}
|
package/build/GLView.web.js
CHANGED
|
@@ -4,7 +4,7 @@ import * as React from 'react';
|
|
|
4
4
|
import { Dimensions } from 'react-native';
|
|
5
5
|
import Canvas from './Canvas';
|
|
6
6
|
function getImageForAsset(asset) {
|
|
7
|
-
if (asset != null && typeof asset === 'object' && asset
|
|
7
|
+
if (asset != null && typeof asset === 'object' && asset.downloadAsync) {
|
|
8
8
|
const dataURI = asset.localUri || asset.uri || '';
|
|
9
9
|
const image = new Image();
|
|
10
10
|
image.src = dataURI;
|
package/build/GLView.web.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"GLView.web.js","sourceRoot":"","sources":["../src/GLView.web.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AAC9E,OAAO,SAAS,MAAM,WAAW,CAAC;AAClC,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAE1C,OAAO,MAAM,MAAM,UAAU,CAAC;AAU9B,SAAS,gBAAgB,CAAC,KAIzB;IACC,IAAI,KAAK,IAAI,IAAI,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,KAAK,CAAC,aAAa,EAAE;QACvF,MAAM,OAAO,GAAG,KAAK,CAAC,QAAQ,IAAI,KAAK,CAAC,GAAG,IAAI,EAAE,CAAC;QAClD,MAAM,KAAK,GAAG,IAAI,KAAK,EAAE,CAAC;QAC1B,KAAK,CAAC,GAAG,GAAG,OAAO,CAAC;QACpB,OAAO,KAAK,CAAC;KACd;IACD,OAAO,KAAK,CAAC;AACf,CAAC;AAED,S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B,EAAE,IAAI,CAAC,aAAa,CAAC,CAAC;YACrE,IAAI,CAAC,MAAM,CAAC,gBAAgB,CAAC,sBAAsB,EAAE,IAAI,CAAC,iBAAiB,CAAC,CAAC;YAE7E,IAAI,CAAC,YAAY,EAAE,CAAC;SACrB;IACH,CAAC,CAAC;IAEK,KAAK,CAAC,iBAAiB,CAAC,UAA2B,EAAE;QAC1D,IAAI,CAAC,MAAM,CAAC,iBAAiB,EAAE;YAC7B,MAAM,IAAI,mBAAmB,CAAC,SAAS,EAAE,mBAAmB,CAAC,CAAC;SAC/D;QAED,MAAM,EAAE,GAAG,IAAI,CAAC,oBAAoB,EAAE,CAAC;QACvC,OAAO,MAAM,MAAM,CAAC,iBAAiB,CAAC,EAAE,EAAE,OAAO,CAAC,CAAC;IACrD,CAAC;IAEM,KAAK,CAAC,mBAAmB;QAC9B,MAAM,IAAI,mBAAmB,CAAC,QAAQ,EAAE,qBAAqB,CAAC,CAAC;IACjE,CAAC;IAEM,KAAK,CAAC,wBAAwB;QACnC,MAAM,IAAI,mBAAmB,CAAC,QAAQ,EAAE,0BAA0B,CAAC,CAAC;IACtE,CAAC;IAEM,KAAK,CAAC,kBAAkB,CAAC,QAAqB;QACnD,MAAM,IAAI,mBAAmB,CAAC,QAAQ,EAAE,oBAAoB,CAAC,CAAC;IAChE,CAAC;CACF","sourcesContent":["import { CodedError, Platform, UnavailabilityError } from 'expo-modules-core';\nimport invariant from 'invariant';\nimport * as React from 'react';\nimport { Dimensions } from 'react-native';\n\nimport Canvas from './Canvas';\nimport { WebGLObject } from './GLView';\nimport {\n GLViewProps,\n ExpoWebGLRenderingContext,\n GLSnapshot,\n SnapshotOptions,\n ComponentOrHandle,\n} from './GLView.types';\n\nfunction getImageForAsset(asset: {\n downloadAsync: () => Promise<any>;\n uri?: string;\n localUri?: string;\n}): HTMLImageElement | any {\n if (asset != null && typeof asset === 'object' && asset !== null && asset.downloadAsync) {\n const dataURI = asset.localUri || asset.uri || '';\n const image = new Image();\n image.src = dataURI;\n return image;\n }\n return asset;\n}\n\nfunction isOffscreenCanvas(element: any): element is OffscreenCanvas {\n return element && typeof element.convertToBlob === 'function';\n}\n\nfunction asExpoContext(gl: ExpoWebGLRenderingContext): WebGLRenderingContext {\n gl.endFrameEXP = function glEndFrameEXP(): void {};\n\n if (!gl['_expo_texImage2D']) {\n gl['_expo_texImage2D'] = gl.texImage2D;\n gl.texImage2D = (...props: any[]): any => {\n const nextProps = [...props];\n nextProps.push(getImageForAsset(nextProps.pop()));\n return gl['_expo_texImage2D'](...nextProps);\n };\n }\n\n if (!gl['_expo_texSubImage2D']) {\n gl['_expo_texSubImage2D'] = gl.texSubImage2D;\n gl.texSubImage2D = (...props: any[]): any => {\n const nextProps = [...props];\n nextProps.push(getImageForAsset(nextProps.pop()));\n return gl['_expo_texSubImage2D'](...nextProps);\n };\n }\n\n return gl;\n}\n\nfunction ensureContext(\n canvas?: HTMLCanvasElement,\n contextAttributes?: WebGLContextAttributes\n): WebGLRenderingContext {\n if (!canvas) {\n throw new CodedError(\n 'ERR_GL_INVALID',\n 'Attempting to use the GL context before it has been created.'\n );\n }\n\n // Apple disables WebGL 2.0 and doesn't provide any way to detect if it's disabled.\n const isIOS = !!navigator.platform && /iPad|iPhone|iPod/.test(navigator.platform);\n\n const context =\n (!isIOS && canvas.getContext('webgl2', contextAttributes)) ||\n canvas.getContext('webgl', contextAttributes) ||\n canvas.getContext('webgl-experimental', contextAttributes) ||\n canvas.getContext('experimental-webgl', contextAttributes);\n invariant(context, 'Browser does not support WebGL');\n return asExpoContext(context as ExpoWebGLRenderingContext);\n}\n\n// @needsAudit @docsMissing\nexport type GLViewWebProps = GLViewProps & {\n onContextCreate: (gl: WebGLRenderingContext) => void;\n onContextRestored?: (gl?: WebGLRenderingContext) => void;\n onContextLost?: () => void;\n webglContextAttributes?: WebGLContextAttributes;\n // type overwrite\n nativeRef_EXPERIMENTAL?(callback: ComponentOrHandle | HTMLCanvasElement | null);\n};\n\nasync function getBlobFromWebGLRenderingContext(\n gl: WebGLRenderingContext,\n options: SnapshotOptions = {}\n): Promise<{ width: number; height: number; blob: Blob | null }> {\n invariant(gl, 'getBlobFromWebGLRenderingContext(): WebGL Rendering Context is not defined');\n\n const { canvas } = gl;\n\n let blob: Blob | null = null;\n\n if (typeof (canvas as any).msToBlob === 'function') {\n // @ts-ignore: polyfill: https://stackoverflow.com/a/29815058/4047926\n blob = await canvas.msToBlob();\n } else if (isOffscreenCanvas(canvas)) {\n blob = await canvas.convertToBlob({ quality: options.compress, type: options.format });\n } else {\n blob = await new Promise((resolve) => {\n canvas.toBlob((blob: Blob | null) => resolve(blob), options.format, options.compress);\n });\n }\n\n return {\n blob,\n width: canvas.width,\n height: canvas.height,\n };\n}\n\nexport class GLView extends React.Component<GLViewWebProps> {\n canvas?: HTMLCanvasElement;\n\n gl?: WebGLRenderingContext;\n\n static async createContextAsync(): Promise<WebGLRenderingContext | null> {\n if (!Platform.isDOMAvailable) {\n return null;\n }\n const canvas = document.createElement('canvas');\n const { width, height, scale } = Dimensions.get('window');\n canvas.width = width * scale;\n canvas.height = height * scale;\n return ensureContext(canvas);\n }\n\n static async destroyContextAsync(exgl?: WebGLRenderingContext | number): Promise<boolean> {\n // Do nothing\n return true;\n }\n\n static async takeSnapshotAsync(\n gl: WebGLRenderingContext,\n options: SnapshotOptions = {}\n ): Promise<GLSnapshot> {\n const { blob, width, height } = await getBlobFromWebGLRenderingContext(gl, options);\n\n if (!blob) {\n throw new CodedError('ERR_GL_SNAPSHOT', 'Failed to save the GL context');\n }\n\n return {\n uri: blob,\n localUri: '',\n width,\n height,\n };\n }\n\n componentWillUnmount() {\n if (this.gl) {\n const loseContextExt = this.gl.getExtension('WEBGL_lose_context');\n if (loseContextExt) {\n loseContextExt.loseContext();\n }\n this.gl = undefined;\n }\n if (this.canvas) {\n this.canvas.removeEventListener('webglcontextlost', this.onContextLost);\n this.canvas.removeEventListener('webglcontextrestored', this.onContextRestored);\n }\n }\n\n render() {\n const {\n onContextCreate,\n onContextRestored,\n onContextLost,\n webglContextAttributes,\n msaaSamples,\n nativeRef_EXPERIMENTAL,\n // @ts-ignore: ref does not exist\n ref,\n ...domProps\n } = this.props;\n\n return <Canvas {...domProps} canvasRef={this.setCanvasRef} />;\n }\n\n componentDidUpdate(prevProps) {\n const { webglContextAttributes } = this.props;\n if (this.canvas && webglContextAttributes !== prevProps.webglContextAttributes) {\n this.onContextLost(null);\n this.onContextRestored();\n }\n }\n\n private getGLContextOrReject(): WebGLRenderingContext {\n const gl = this.getGLContext();\n if (!gl) {\n throw new CodedError(\n 'ERR_GL_INVALID',\n 'Attempting to use the GL context before it has been created.'\n );\n }\n return gl;\n }\n\n private onContextLost = (event: Event | null): void => {\n if (event && event.preventDefault) {\n event.preventDefault();\n }\n this.gl = undefined;\n\n if (typeof this.props.onContextLost === 'function') {\n this.props.onContextLost();\n }\n };\n\n private onContextRestored = (): void => {\n this.gl = undefined;\n if (this.getGLContext() == null) {\n throw new CodedError('ERR_GL_INVALID', 'Failed to restore GL context.');\n }\n };\n\n private getGLContext(): WebGLRenderingContext | null {\n if (this.gl) return this.gl;\n\n if (this.canvas) {\n this.gl = ensureContext(this.canvas, this.props.webglContextAttributes);\n if (typeof this.props.onContextCreate === 'function') {\n this.props.onContextCreate(this.gl);\n }\n return this.gl;\n }\n return null;\n }\n\n private setCanvasRef = (canvas: HTMLCanvasElement): void => {\n this.canvas = canvas;\n\n if (typeof this.props.nativeRef_EXPERIMENTAL === 'function') {\n this.props.nativeRef_EXPERIMENTAL(canvas);\n }\n\n if (this.canvas) {\n this.canvas.addEventListener('webglcontextlost', this.onContextLost);\n this.canvas.addEventListener('webglcontextrestored', this.onContextRestored);\n\n this.getGLContext();\n }\n };\n\n public async takeSnapshotAsync(options: SnapshotOptions = {}): Promise<GLSnapshot> {\n if (!GLView.takeSnapshotAsync) {\n throw new UnavailabilityError('expo-gl', 'takeSnapshotAsync');\n }\n\n const gl = this.getGLContextOrReject();\n return await GLView.takeSnapshotAsync(gl, options);\n }\n\n public async startARSessionAsync(): Promise<void> {\n throw new UnavailabilityError('GLView', 'startARSessionAsync');\n }\n\n public async createCameraTextureAsync(): Promise<void> {\n throw new UnavailabilityError('GLView', 'createCameraTextureAsync');\n }\n\n public async destroyObjectAsync(glObject: WebGLObject): Promise<void> {\n throw new UnavailabilityError('GLView', 'destroyObjectAsync');\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"GLView.web.js","sourceRoot":"","sources":["../src/GLView.web.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AAC9E,OAAO,SAAS,MAAM,WAAW,CAAC;AAClC,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAE1C,OAAO,MAAM,MAAM,UAAU,CAAC;AAU9B,SAAS,gBAAgB,CAAC,KAIzB;IACC,IAAI,KAAK,IAAI,IAAI,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,CAAC,aAAa,EAAE;QACrE,MAAM,OAAO,GAAG,KAAK,CAAC,QAAQ,IAAI,KAAK,CAAC,GAAG,IAAI,EAAE,CAAC;QAClD,MAAM,KAAK,GAAG,IAAI,KAAK,EAAE,CAAC;QAC1B,KAAK,CAAC,GAAG,GAAG,OAAO,CAAC;QACpB,OAAO,KAAK,CAAC;KACd;IACD,OAAO,KAAK,CAAC;AACf,CAAC;AAED,SAAS,iBAAiB,CAAC,OAAY;IACrC,OAAO,OAAO,IAAI,OAAO,OAAO,CAAC,aAAa,KAAK,UAAU,CAAC;AAChE,CAAC;AAED,SAAS,aAAa,CAAC,EAA6B;IAClD,EAAE,CAAC,WAAW,GAAG,SAAS,aAAa,KAAU,CAAC,CAAC;IAEnD,IAAI,CAAC,EAAE,CAAC,kBAAkB,CAAC,EAAE;QAC3B,EAAE,CAAC,kBAAkB,CAAC,GAAG,EAAE,CAAC,UA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,mBAAmB,CAAC,SAAS,EAAE,mBAAmB,CAAC,CAAC;SAC/D;QAED,MAAM,EAAE,GAAG,IAAI,CAAC,oBAAoB,EAAE,CAAC;QACvC,OAAO,MAAM,MAAM,CAAC,iBAAiB,CAAC,EAAE,EAAE,OAAO,CAAC,CAAC;IACrD,CAAC;IAEM,KAAK,CAAC,mBAAmB;QAC9B,MAAM,IAAI,mBAAmB,CAAC,QAAQ,EAAE,qBAAqB,CAAC,CAAC;IACjE,CAAC;IAEM,KAAK,CAAC,wBAAwB;QACnC,MAAM,IAAI,mBAAmB,CAAC,QAAQ,EAAE,0BAA0B,CAAC,CAAC;IACtE,CAAC;IAEM,KAAK,CAAC,kBAAkB,CAAC,QAAqB;QACnD,MAAM,IAAI,mBAAmB,CAAC,QAAQ,EAAE,oBAAoB,CAAC,CAAC;IAChE,CAAC;CACF","sourcesContent":["import { CodedError, Platform, UnavailabilityError } from 'expo-modules-core';\nimport invariant from 'invariant';\nimport * as React from 'react';\nimport { Dimensions } from 'react-native';\n\nimport Canvas from './Canvas';\nimport { WebGLObject } from './GLView';\nimport {\n GLViewProps,\n ExpoWebGLRenderingContext,\n GLSnapshot,\n SnapshotOptions,\n ComponentOrHandle,\n} from './GLView.types';\n\nfunction getImageForAsset(asset: {\n downloadAsync?: () => Promise<any>;\n uri?: string;\n localUri?: string;\n}): HTMLImageElement | any {\n if (asset != null && typeof asset === 'object' && asset.downloadAsync) {\n const dataURI = asset.localUri || asset.uri || '';\n const image = new Image();\n image.src = dataURI;\n return image;\n }\n return asset;\n}\n\nfunction isOffscreenCanvas(element: any): element is OffscreenCanvas {\n return element && typeof element.convertToBlob === 'function';\n}\n\nfunction asExpoContext(gl: ExpoWebGLRenderingContext): WebGLRenderingContext {\n gl.endFrameEXP = function glEndFrameEXP(): void {};\n\n if (!gl['_expo_texImage2D']) {\n gl['_expo_texImage2D'] = gl.texImage2D;\n gl.texImage2D = (...props: any[]): any => {\n const nextProps = [...props];\n nextProps.push(getImageForAsset(nextProps.pop()));\n return gl['_expo_texImage2D'](...nextProps);\n };\n }\n\n if (!gl['_expo_texSubImage2D']) {\n gl['_expo_texSubImage2D'] = gl.texSubImage2D;\n gl.texSubImage2D = (...props: any[]): any => {\n const nextProps = [...props];\n nextProps.push(getImageForAsset(nextProps.pop()));\n return gl['_expo_texSubImage2D'](...nextProps);\n };\n }\n\n return gl;\n}\n\nfunction ensureContext(\n canvas?: HTMLCanvasElement,\n contextAttributes?: WebGLContextAttributes\n): WebGLRenderingContext {\n if (!canvas) {\n throw new CodedError(\n 'ERR_GL_INVALID',\n 'Attempting to use the GL context before it has been created.'\n );\n }\n\n // Apple disables WebGL 2.0 and doesn't provide any way to detect if it's disabled.\n const isIOS = !!navigator.platform && /iPad|iPhone|iPod/.test(navigator.platform);\n\n const context =\n (!isIOS && canvas.getContext('webgl2', contextAttributes)) ||\n canvas.getContext('webgl', contextAttributes) ||\n canvas.getContext('webgl-experimental', contextAttributes) ||\n canvas.getContext('experimental-webgl', contextAttributes);\n invariant(context, 'Browser does not support WebGL');\n return asExpoContext(context as ExpoWebGLRenderingContext);\n}\n\n// @needsAudit @docsMissing\nexport type GLViewWebProps = GLViewProps & {\n onContextCreate: (gl: WebGLRenderingContext) => void;\n onContextRestored?: (gl?: WebGLRenderingContext) => void;\n onContextLost?: () => void;\n webglContextAttributes?: WebGLContextAttributes;\n // type overwrite\n nativeRef_EXPERIMENTAL?(callback: ComponentOrHandle | HTMLCanvasElement | null);\n};\n\nasync function getBlobFromWebGLRenderingContext(\n gl: WebGLRenderingContext,\n options: SnapshotOptions = {}\n): Promise<{ width: number; height: number; blob: Blob | null }> {\n invariant(gl, 'getBlobFromWebGLRenderingContext(): WebGL Rendering Context is not defined');\n\n const { canvas } = gl;\n\n let blob: Blob | null = null;\n\n if (typeof (canvas as any).msToBlob === 'function') {\n // @ts-ignore: polyfill: https://stackoverflow.com/a/29815058/4047926\n blob = await canvas.msToBlob();\n } else if (isOffscreenCanvas(canvas)) {\n blob = await canvas.convertToBlob({ quality: options.compress, type: options.format });\n } else {\n blob = await new Promise((resolve) => {\n canvas.toBlob((blob: Blob | null) => resolve(blob), options.format, options.compress);\n });\n }\n\n return {\n blob,\n width: canvas.width,\n height: canvas.height,\n };\n}\n\nexport class GLView extends React.Component<GLViewWebProps> {\n canvas?: HTMLCanvasElement;\n\n gl?: WebGLRenderingContext;\n\n static async createContextAsync(): Promise<WebGLRenderingContext | null> {\n if (!Platform.isDOMAvailable) {\n return null;\n }\n const canvas = document.createElement('canvas');\n const { width, height, scale } = Dimensions.get('window');\n canvas.width = width * scale;\n canvas.height = height * scale;\n return ensureContext(canvas);\n }\n\n static async destroyContextAsync(exgl?: WebGLRenderingContext | number): Promise<boolean> {\n // Do nothing\n return true;\n }\n\n static async takeSnapshotAsync(\n gl: WebGLRenderingContext,\n options: SnapshotOptions = {}\n ): Promise<GLSnapshot> {\n const { blob, width, height } = await getBlobFromWebGLRenderingContext(gl, options);\n\n if (!blob) {\n throw new CodedError('ERR_GL_SNAPSHOT', 'Failed to save the GL context');\n }\n\n return {\n uri: blob,\n localUri: '',\n width,\n height,\n };\n }\n\n componentWillUnmount() {\n if (this.gl) {\n const loseContextExt = this.gl.getExtension('WEBGL_lose_context');\n if (loseContextExt) {\n loseContextExt.loseContext();\n }\n this.gl = undefined;\n }\n if (this.canvas) {\n this.canvas.removeEventListener('webglcontextlost', this.onContextLost);\n this.canvas.removeEventListener('webglcontextrestored', this.onContextRestored);\n }\n }\n\n render() {\n const {\n onContextCreate,\n onContextRestored,\n onContextLost,\n webglContextAttributes,\n msaaSamples,\n nativeRef_EXPERIMENTAL,\n // @ts-ignore: ref does not exist\n ref,\n ...domProps\n } = this.props;\n\n return <Canvas {...domProps} canvasRef={this.setCanvasRef} />;\n }\n\n componentDidUpdate(prevProps) {\n const { webglContextAttributes } = this.props;\n if (this.canvas && webglContextAttributes !== prevProps.webglContextAttributes) {\n this.onContextLost(null);\n this.onContextRestored();\n }\n }\n\n private getGLContextOrReject(): WebGLRenderingContext {\n const gl = this.getGLContext();\n if (!gl) {\n throw new CodedError(\n 'ERR_GL_INVALID',\n 'Attempting to use the GL context before it has been created.'\n );\n }\n return gl;\n }\n\n private onContextLost = (event: Event | null): void => {\n if (event && event.preventDefault) {\n event.preventDefault();\n }\n this.gl = undefined;\n\n if (typeof this.props.onContextLost === 'function') {\n this.props.onContextLost();\n }\n };\n\n private onContextRestored = (): void => {\n this.gl = undefined;\n if (this.getGLContext() == null) {\n throw new CodedError('ERR_GL_INVALID', 'Failed to restore GL context.');\n }\n };\n\n private getGLContext(): WebGLRenderingContext | null {\n if (this.gl) return this.gl;\n\n if (this.canvas) {\n this.gl = ensureContext(this.canvas, this.props.webglContextAttributes);\n if (typeof this.props.onContextCreate === 'function') {\n this.props.onContextCreate(this.gl);\n }\n return this.gl;\n }\n return null;\n }\n\n private setCanvasRef = (canvas: HTMLCanvasElement): void => {\n this.canvas = canvas;\n\n if (typeof this.props.nativeRef_EXPERIMENTAL === 'function') {\n this.props.nativeRef_EXPERIMENTAL(canvas);\n }\n\n if (this.canvas) {\n this.canvas.addEventListener('webglcontextlost', this.onContextLost);\n this.canvas.addEventListener('webglcontextrestored', this.onContextRestored);\n\n this.getGLContext();\n }\n };\n\n public async takeSnapshotAsync(options: SnapshotOptions = {}): Promise<GLSnapshot> {\n if (!GLView.takeSnapshotAsync) {\n throw new UnavailabilityError('expo-gl', 'takeSnapshotAsync');\n }\n\n const gl = this.getGLContextOrReject();\n return await GLView.takeSnapshotAsync(gl, options);\n }\n\n public async startARSessionAsync(): Promise<void> {\n throw new UnavailabilityError('GLView', 'startARSessionAsync');\n }\n\n public async createCameraTextureAsync(): Promise<void> {\n throw new UnavailabilityError('GLView', 'createCameraTextureAsync');\n }\n\n public async destroyObjectAsync(glObject: WebGLObject): Promise<void> {\n throw new UnavailabilityError('GLView', 'destroyObjectAsync');\n }\n}\n"]}
|
package/expo-module.config.json
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "expo-gl",
|
|
3
|
-
"version": "12.
|
|
3
|
+
"version": "12.3.0",
|
|
4
4
|
"description": "Provides GLView that acts as OpenGL ES render target and gives GL context object implementing WebGL 2.0 specification.",
|
|
5
5
|
"main": "build/index.js",
|
|
6
6
|
"types": "build/index.d.ts",
|
|
@@ -44,10 +44,10 @@
|
|
|
44
44
|
"@types/offscreencanvas": "2019.6.4",
|
|
45
45
|
"@types/webgl2": "^0.0.6",
|
|
46
46
|
"expo-module-scripts": "^3.0.0",
|
|
47
|
-
"react-test-renderer": "
|
|
47
|
+
"react-test-renderer": "18.2.0"
|
|
48
48
|
},
|
|
49
49
|
"peerDependencies": {
|
|
50
50
|
"expo": "*"
|
|
51
51
|
},
|
|
52
|
-
"gitHead": "
|
|
52
|
+
"gitHead": "1815e2eaad8c753588c7b1eb74420174a28e01f4"
|
|
53
53
|
}
|
package/src/GLView.web.tsx
CHANGED
|
@@ -14,11 +14,11 @@ import {
|
|
|
14
14
|
} from './GLView.types';
|
|
15
15
|
|
|
16
16
|
function getImageForAsset(asset: {
|
|
17
|
-
downloadAsync
|
|
17
|
+
downloadAsync?: () => Promise<any>;
|
|
18
18
|
uri?: string;
|
|
19
19
|
localUri?: string;
|
|
20
20
|
}): HTMLImageElement | any {
|
|
21
|
-
if (asset != null && typeof asset === 'object' && asset
|
|
21
|
+
if (asset != null && typeof asset === 'object' && asset.downloadAsync) {
|
|
22
22
|
const dataURI = asset.localUri || asset.uri || '';
|
|
23
23
|
const image = new Image();
|
|
24
24
|
image.src = dataURI;
|
|
@@ -1,117 +0,0 @@
|
|
|
1
|
-
package expo.modules.gl;
|
|
2
|
-
|
|
3
|
-
import android.content.Context;
|
|
4
|
-
import android.graphics.SurfaceTexture;
|
|
5
|
-
import android.os.Bundle;
|
|
6
|
-
import android.view.TextureView;
|
|
7
|
-
|
|
8
|
-
import expo.modules.core.ModuleRegistry;
|
|
9
|
-
import expo.modules.core.interfaces.services.EventEmitter;
|
|
10
|
-
|
|
11
|
-
public class GLView extends TextureView implements TextureView.SurfaceTextureListener {
|
|
12
|
-
private boolean mOnSurfaceCreateCalled = false;
|
|
13
|
-
private boolean mOnSurfaceTextureCreatedWithZeroSize = false;
|
|
14
|
-
|
|
15
|
-
private GLContext mGLContext;
|
|
16
|
-
private ModuleRegistry mModuleRegistry;
|
|
17
|
-
|
|
18
|
-
// Suppresses ViewConstructor warnings
|
|
19
|
-
public GLView(Context context) {
|
|
20
|
-
super(context);
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
public GLView(Context context, ModuleRegistry moduleRegistry) {
|
|
24
|
-
super(context);
|
|
25
|
-
setSurfaceTextureListener(this);
|
|
26
|
-
setOpaque(false);
|
|
27
|
-
|
|
28
|
-
GLObjectManagerModule objectManager = (GLObjectManagerModule)moduleRegistry.getExportedModuleOfClass(GLObjectManagerModule.class);
|
|
29
|
-
mGLContext = new GLContext(objectManager);
|
|
30
|
-
mModuleRegistry = moduleRegistry;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
// Public interface to allow running events on GL thread
|
|
34
|
-
|
|
35
|
-
public void runOnGLThread(Runnable r) {
|
|
36
|
-
mGLContext.runAsync(r);
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
public GLContext getGLContext() {
|
|
40
|
-
return mGLContext;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
// `TextureView.SurfaceTextureListener` events
|
|
45
|
-
|
|
46
|
-
@Override
|
|
47
|
-
synchronized public void onSurfaceTextureAvailable(SurfaceTexture surfaceTexture, int width, int height) {
|
|
48
|
-
if (!mOnSurfaceCreateCalled) {
|
|
49
|
-
// onSurfaceTextureAvailable is sometimes called with 0 size texture
|
|
50
|
-
// and immediately followed by onSurfaceTextureSizeChanged with actual size
|
|
51
|
-
if (width == 0 || height == 0) {
|
|
52
|
-
mOnSurfaceTextureCreatedWithZeroSize = true;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
if (!mOnSurfaceTextureCreatedWithZeroSize) {
|
|
56
|
-
initializeSurfaceInGLContext(surfaceTexture);
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
mOnSurfaceCreateCalled = true;
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
@Override
|
|
64
|
-
public boolean onSurfaceTextureDestroyed(SurfaceTexture surface) {
|
|
65
|
-
mGLContext.destroy();
|
|
66
|
-
|
|
67
|
-
// reset flag, so the context will be recreated when the new surface is available
|
|
68
|
-
mOnSurfaceCreateCalled = false;
|
|
69
|
-
|
|
70
|
-
return true;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
@Override
|
|
74
|
-
synchronized public void onSurfaceTextureSizeChanged(SurfaceTexture surfaceTexture, int width, int height) {
|
|
75
|
-
if (mOnSurfaceTextureCreatedWithZeroSize && (width != 0 || height != 0)) {
|
|
76
|
-
initializeSurfaceInGLContext(surfaceTexture);
|
|
77
|
-
mOnSurfaceTextureCreatedWithZeroSize = false;
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
@Override
|
|
82
|
-
public void onSurfaceTextureUpdated(SurfaceTexture surface) {
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
public void flush() {
|
|
86
|
-
mGLContext.flush();
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
public int getEXGLCtxId() {
|
|
90
|
-
return mGLContext.getContextId();
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
private void initializeSurfaceInGLContext(SurfaceTexture surfaceTexture) {
|
|
94
|
-
mGLContext.initialize(surfaceTexture, new Runnable() {
|
|
95
|
-
@Override
|
|
96
|
-
public void run() {
|
|
97
|
-
final Bundle event = new Bundle();
|
|
98
|
-
final EventEmitter eventEmitter = mModuleRegistry.getModule(EventEmitter.class);
|
|
99
|
-
|
|
100
|
-
event.putInt("exglCtxId", mGLContext.getContextId());
|
|
101
|
-
|
|
102
|
-
eventEmitter.emit(getId(), new EventEmitter.BaseEvent() {
|
|
103
|
-
@Override
|
|
104
|
-
public String getEventName() {
|
|
105
|
-
return "onSurfaceCreate";
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
@Override
|
|
109
|
-
public Bundle getEventBody() {
|
|
110
|
-
return event;
|
|
111
|
-
}
|
|
112
|
-
});
|
|
113
|
-
}
|
|
114
|
-
});
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
package expo.modules.gl;
|
|
2
|
-
|
|
3
|
-
import android.content.Context;
|
|
4
|
-
|
|
5
|
-
import java.util.Arrays;
|
|
6
|
-
import java.util.List;
|
|
7
|
-
|
|
8
|
-
import expo.modules.core.ModuleRegistry;
|
|
9
|
-
import expo.modules.core.ViewManager;
|
|
10
|
-
|
|
11
|
-
public class GLViewManager extends ViewManager<GLView> {
|
|
12
|
-
private ModuleRegistry mModuleRegistry;
|
|
13
|
-
|
|
14
|
-
@Override
|
|
15
|
-
public String getName() {
|
|
16
|
-
return "ExponentGLView";
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
@Override
|
|
20
|
-
public GLView createViewInstance(Context context) {
|
|
21
|
-
return new GLView(context, mModuleRegistry);
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
@Override
|
|
25
|
-
public ViewManagerType getViewManagerType() {
|
|
26
|
-
return ViewManagerType.SIMPLE;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
@Override
|
|
30
|
-
public List<String> getExportedEventNames() {
|
|
31
|
-
return Arrays.asList("onSurfaceCreate");
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
@Override
|
|
35
|
-
public void onCreate(ModuleRegistry moduleRegistry) {
|
|
36
|
-
mModuleRegistry = moduleRegistry;
|
|
37
|
-
}
|
|
38
|
-
}
|