fix(🐘): make Skia contextes per JS runtime not thread local#3715
fix(🐘): make Skia contextes per JS runtime not thread local#3715wcandillon wants to merge 8 commits intoShopify:mainfrom
Conversation
There was a problem hiding this comment.
Pull request overview
This PR refactors the Skia rendering context management to be per JavaScript runtime instance rather than thread-local. This change ensures that each JS runtime maintains its own graphics context, improving isolation and preventing potential issues when multiple runtimes exist.
Changes:
- Removed thread-local singleton patterns from
MetalContext(Apple) andOpenGLContext(Android) in favor of per-instance contexts - Added thread-affinity checks to OpenGL contexts to catch and prevent cross-thread usage
- Updated
WindowContextownership fromunique_ptrtoshared_ptrto support the new architecture
Reviewed changes
Copilot reviewed 17 out of 18 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| packages/skia/cpp/rnskia/RNSkPlatformContext.h | Added useP3ColorSpace parameter to makeContextFromNativeSurface method |
| packages/skia/apple/SkiaCVPixelBufferUtils.mm | Reformatted macro definitions for consistency |
| packages/skia/apple/RNSkMetalCanvasProvider.mm | Removed direct MetalContext::getInstance() calls, now uses platform context |
| packages/skia/apple/RNSkMetalCanvasProvider.h | Changed _ctx from unique_ptr to shared_ptr |
| packages/skia/apple/RNSkApplePlatformContext.mm | Added instance-based metalContext() method replacing singleton pattern |
| packages/skia/apple/RNSkApplePlatformContext.h | Added private MetalContext member and initialization logic |
| packages/skia/apple/MetalContext.h | Removed singleton pattern, made constructor public |
| packages/skia/android/cpp/rnskia-android/RNSkOpenGLCanvasProvider.h | Changed _surfaceHolder from unique_ptr to shared_ptr |
| packages/skia/android/cpp/rnskia-android/RNSkOpenGLCanvasProvider.cpp | Replaced direct OpenGL context calls with platform context method |
| packages/skia/android/cpp/rnskia-android/RNSkAndroidVideo.h | Added _context member to hold platform context reference |
| packages/skia/android/cpp/rnskia-android/RNSkAndroidVideo.cpp | Updated constructor to accept and use platform context |
| packages/skia/android/cpp/rnskia-android/RNSkAndroidPlatformContext.h | Added getOpenGLContext() method and made class inherit from enable_shared_from_this |
| packages/skia/android/cpp/rnskia-android/OpenGLWindowContext.h | Added thread-affinity checking with assertThread method |
| packages/skia/android/cpp/rnskia-android/OpenGLWindowContext.cpp | Added thread assertions to public methods |
| packages/skia/android/cpp/rnskia-android/OpenGLContext.h | Removed singleton pattern, added thread-affinity checks, moved constructor implementation inline |
| packages/skia/android/cpp/jni/include/JniSkiaPictureView.h | Replaced direct context calls with platform context usage |
| externals/skia | Updated Skia submodule commit |
| apps/example/ios/Podfile.lock | Updated pod dependencies checksums and CocoaPods version |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
Hey @wcandillon - any update on this PR? I noticed that when I tried to create a demo app using VisionCamera V5 + Skia, memory exploded (3GB+) and the app was killed, making the VisionCamera Skia integration unusable on iOS for now. Android works fine, since the Threading primitives don't use pools like I'd love to help push this across the finish line wherever I can. |
No description provided.