Skip to content

Commit

Permalink
Attach pointer to worklet runtime in main runtime (software-mansion#2253
Browse files Browse the repository at this point in the history
)

## Description

We want to add support for expo-gl in worklets,

## Changes

- Added pointer to the worklet js runtime as a field in the main js runtime. We need that pointer to inject gl renderer object from expo-gl-cpp
- Added typed array constructors to globals list in plugin.js, It allows creating typed arrays on worklet thread when using hermes, but it still does not work with JSC. WebGL standard requires typed arrays for a lot of stuff, so we can't just change it to regular arrays even if performance would be good enough.

## Test code and steps to reproduce

I prepared 2 examples here wkozyra95@b3618a8
- one that just renders gl in a loop
- one that draws  based on the input from gesture handler

I tested this example yarn linking modified `expo-gl-cpp`, so it does not work in the form with latest version of that package.

## Checklist

- [ ] Included code example that can be used to test this change
- [ ] Updated TS types
- [ ] Added TS types tests
- [ ] Added unit / integration tests
- [ ] Updated documentation
- [ ] Ensured that CI passes
  • Loading branch information
wkozyra95 authored Aug 4, 2021
1 parent a04a0e3 commit c84229a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
1 change: 1 addition & 0 deletions android/src/main/cpp/NativeProxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ void NativeProxy::installJSIBindings()
#else
std::shared_ptr<jsi::Runtime> animatedRuntime = facebook::jsc::makeJSCRuntime();
#endif
runtime_->global().setProperty(*runtime_, "_WORKLET_RUNTIME", static_cast<double>(reinterpret_cast<std::uintptr_t>(animatedRuntime.get())));

std::shared_ptr<ErrorHandler> errorHandler = std::make_shared<AndroidErrorHandler>(scheduler_);

Expand Down
9 changes: 9 additions & 0 deletions plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,15 @@ const globals = new Set([
'Date',
'Array',
'ArrayBuffer',
'Int8Array',
'Int16Array',
'Int32Array',
'Uint8Array',
'Uint8ClampedArray',
'Uint16Array',
'Uint32Array',
'Float32Array',
'Float64Array',
'Date',
'HermesInternal',
'JSON',
Expand Down

0 comments on commit c84229a

Please sign in to comment.