Repository navigation
fix(ios): take the Metal drawable on first draw; threaded WebGL layer changes off main - #190
Merged
Merged
Conversation
… changes off main Metal 2D presented and then immediately took the next drawable, holding one of the layer's drawables between frames. It now takes it on the frame's first draw, as tvOS already did (#146). Offscreen Metal contexts are unchanged. Threaded WebGL called renderbufferStorage:fromDrawable: (and, for Worker transfers, setDrawableProperties:) on the WebGL thread, which modifies the CanvasGLView's backing layer and made UIKit log "Modifying properties of a view's layer off the main thread". Both now run inside an explicit CATransaction with actions disabled when off main. Adds a lifecycle spec checking 2D contents survive presents and idle frames.
Includes the Metal drawable and threaded WebGL layer fixes, and #187's CanvasJSIModule change in libcanvasnativev8.so.
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Metal 2D: take the drawable on first draw
Context::presentpresented and then immediately took the next drawable from theCAMetalLayer, so every canvas held one of the layer's drawables between frames. With several canvases this starves the pool andnextDrawableblocks sooner. The drawable is now taken on the frame's first draw (bind_surface), the path tvOS has used since #146. Contents carry over throughreplace_backend_texture, as before. Offscreen Metal contexts are unchanged.Threaded WebGL: layer changes off the main thread
Since threaded WebGL (#176),
renderbufferStorage:fromDrawable:runs on the WebGL thread. It sets thecontentsofCanvasGLView's backing layer, so UIKit logged "Modifying properties of a view's layer off the main thread" once per context. The Worker transfer path did the same withsetDrawableProperties:. Both now go throughcanvas_core::gpu::gl::change_view_layer, which wraps the change in aCATransactionwith actions disabled when off main. That skips UIKit's action lookup, and the explicit commit applies the change. The main-thread path is untouched.Libraries
Rebuilt the xcframework (all 6 slices) and the Android AAR. The AAR's
libcanvasnativev8.sopicks up #187'sCanvasJSIModule.cppchange. Both fixes are Apple-only; Android was rebuilt for #187 and tested on the emulator below.Testing
New spec:
lifecycle"a 2d context keeps earlier frames' drawing (threaded|direct)" draws across several presents and idle frames and checks every earlier draw is still there.iOS 26.4 simulator, rebuilt xcframework: lifecycle 12/12, 2d 180/180, imagebitmap 18/18, bitmaprenderer 15/15, canvassource 9/9, offscreen 64/64, webgl 83/83, webgpu 19/19, scaling 6/6. UIKit warnings: 16 before, 0 after. The busy-screen trail scene keeps its whole trail.
Android emulator (Pixel 9 Pro), rebuilt AAR: 2d 180/180, webgl 83/83, imagebitmap 18/18, bitmaprenderer 15/15, scaling 6/6, offscreen 63/64, canvassource 7/9, lifecycle 9 to 11 of 15. All remaining failures are either WebGPU, which the emulator has no adapter for, or "webgl/webgl2 frame drawn before the surface exists". That second pair also fails in 4 of 5 runs with the previous AAR, so it is an existing flake.
Not tested on a physical iOS device. The simulator runs at its 60 fps cap with headroom, so the frame-pacing gain from the drawable change was not measurable there; it should show with several canvases on a device.