Canvas: text metrics, multi-GUI filters, drawImage(canvas), toDataURL - #1855
Open
bkaradzic-microsoft wants to merge 5 commits into
Open
Canvas: text metrics, multi-GUI filters, drawImage(canvas), toDataURL#1855bkaradzic-microsoft wants to merge 5 commits into
bkaradzic-microsoft wants to merge 5 commits into
Conversation
bkaradzic-microsoft
force-pushed
the
pr/canvas-features
branch
from
August 27, 2026 23:51
47eff94 to
384f8f8
Compare
Independent of instance-branding (BabylonJS#1844 / type tags): - fontstash: CSS/canvas font-size as em units; MeasureText advance + ink bounds - MeasureText binds the same face FillText uses - nanovg_filterstack: refcount shared blur programs (multi-ADT lifetime) - drawImage(canvas) via Canvas InstanceOf + CPU pixel mirror (no NativeInstanceRegistry) - toDataURL("image/png") via bimg_encode; link bimg_encode Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 60c2ec68-6de1-445d-9fc9-b699db737eae
bkaradzic-microsoft
force-pushed
the
pr/canvas-features
branch
from
August 28, 2026 00:04
384f8f8 to
dd45487
Compare
GCC rejects default member initializers on a nested type used as an inline static member of the enclosing class. Match master: plain UniformHandle fields + value-init the static Uniforms instance. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 60c2ec68-6de1-445d-9fc9-b699db737eae
toDataURL and drawImage(canvas) previously read only the CPU pixel mirror (populated by putImageData/drawImage of bitmaps), so NanoVG draws such as fillRect/text/paths were missing from the result. CaptureRGBA now flushes pending NanoVG commands, blits the canvas RT to a READ_BACK texture, and blocks on DeviceContext::ReadTextureAsync. Mid-frame flushes complete readTexture requests so the wait works under an active FrameCompletionScope (RAF / unit-test open frame) without deadlocking. Also: - ForceMidFrameFlush API; process readTexture queue in PerformMidFrameViewFlush - Bilateral Canvas/Context detach on destroy (JS cycle finalizer order) - nvgCreateImageFromHandle helper for external bgfx textures (NODELETE) Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 60c2ec68-6de1-445d-9fc9-b699db737eae
The fontstash em-square scale change makes canvas2d text match CSS px sizing (glyphs were previously ~0.86x too small for Droid Sans). Native Canvas playground (#TKVFSA#8) draws large stroked/filled text over shapes, so the old golden (captured at the undersized scale) fails pixel compare at ~4.1%. Same golden update as shotgun 520be83; CI rendered result is within 0.125% of this reference (limit 2.5%). Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 60c2ec68-6de1-445d-9fc9-b699db737eae
bkaradzic-microsoft
requested review from
CedricGuillemet and
bghgary
and
a balanced review from Copilot
August 28, 2026 03:01
- CaptureRGBA: unpremultiply GPU readback so toDataURL/getImageData/drawImage expose straight alpha (NanoVG RT is ONE/INV_SRC_ALPHA premultiplied). - MeasureText: use nvgTextBoundsInk so height/actualBoundingBox* are glyph ink extents; nvgTextBounds still uses the line box for layout callers. - FreeType fontstash path: FT_Set_Pixel_Sizes from em `size` directly so raster matches em-scaled advances (stb path already did). - Unit test: semi-transparent fill + getImageData channel asserts on drawImage(canvas) destination. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 60c2ec68-6de1-445d-9fc9-b699db737eae
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.
Summary
Canvas2D feature work that does not depend on instance branding or JsRuntimeHost type tags.
measureTextuses advance + ink bounds and binds the same face asfillTextnanovg_filterstackrefcounts shared blur programs/uniforms (multiple ADTs)drawImage(canvas)InstanceOf(Canvas)then unwrap; CPU pixel mirror via bound contexttoDataURLbimg_encode+ base64Not in this PR
Unforgeable Path2D/Gradient/Image type checks → #1844 (held for type tags / optional). Accidental wrong-type args that are not
instanceof Canvasstill take the existing Image path.Test plan
drawImage(canvas)+toDataURL→data:image/png;base64,...