feat(canvas): getContext works without waiting for ready - #158
Merged
Merged
Conversation
A context made before the Android view had a surface stayed offscreen: the first surface only fired contextReady, and a recreated TextureView surface was ignored. Every new surface now attaches the context (resize()), carrying 2D pixels over when the size is unchanged. WebGPU contexts can be created before there is a window: the context's wgpu surface is optional, None until the view has one and again once it lets go of it, with frames rendering offscreen meanwhile.
getContext works as soon as the canvas exists, as on the web. The event still fires; listening for it warns once.
…existed A frame drawn before the view had a surface went to the pbuffer (WebGL) or the offscreen texture (WebGPU) and was dropped when the window surface attached, so a canvas drawn once in `loaded` stayed blank. The attach now carries that frame over and presents it: WebGL blits it through a renderbuffer across the EGL surface switch, WebGPU copies it into the first swapchain texture.
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Advanced Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
nativeDetach2DSurface passed 12 of ContextAttributes::new's 13 arguments, so canvas-android did not compile.
Layout resized the pbuffer to the size it already had before the surface appeared, which recreated it blank and lost the frame the surface was meant to show.
GrDirectContext deletes its GL names on whichever context is current. When another canvas was current, collecting a 2d context deleted that canvas's objects and its later draws did nothing.
NAPI_HOST cannot be folded at build time, so its __non_webpack_require__ survived into the iOS bundle and imported node:module, which the iOS runtime does not have. The app failed to start.
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.
On the web a
<canvas>can be used as soon as it exists. Here, apps had to wait for the Canvasreadyevent before callinggetContext. On Android, a context created before the view had a surface was never attached to it. This PR makes the canvas usable immediately and deprecatesready.Android
getContext. Previously the first surface only firedcontextReady, and a recreated TextureView surface was ignored.GLViewalso drops its reference to a releasedSurface.loadedworks:CanvasGPUCanvasContext.surfaceis now optional:Nonemeans frames render offscreen, both before the view has a window and after it lets go of one. This replaces thesurface_lostflag from fix(canvas): keep JS contexts safe after their canvas releases the native context #156, and a detach now drops the wgpu surface instead of keeping a dead one.JS
readystill fires, but is@deprecated. Listening for it, includingready="…"in XML, warns once.Domno longer waits forready.loaded. The canvas-svg demo waits for its first layout, since it readsclientWidth.Windows
canvasnative.nodeare rebuilt from this branch.Testing
lifecyclespec tests, which callgetContextthe instant a canvas is added to the page:canvas-spec347/349. The two failures arewebgpu.videoand also fail onv3-v8.lifecyclepasses 10/10.canvas-specwith--suite lifecycleand a demo such as canvas-three.glBlitFramebuffer). Android drivers return one for WebGL 1's 2.0 request; on a true ES 2-only context the carry-over is skipped.