Repository navigation
Conversation
Canvases kept no alpha, so a frame that keeps alpha was drawn twice, on black and on white, with the opacity recovered from the difference: twice the paint, a whole unblend pass, and a white buffer as large as the frame kept between frames. Frames were drawn whole, too: every change repainted everything. Canvas pixels now carry alpha, and blending composites premultiplied pixels, so a transparent frame is drawn once. The two passes, their unblend and the white buffer are gone, and transparent windows and offscreen targets use the normal damage planning: a frame redraws only what changed, and an idle frame costs nothing. Whether a canvas keeps alpha is chosen per primitive, so opaque frames keep their exact pixels. The Windows layered presenter now reports its bitmap as one frame old, which lets transparent windows redraw only what changed. Offscreen's builders keep their target transparent, which with_buffers, with_threads and with_hinting dropped.
The new unit test only asserted that repeated blending does not lower the opacity, which a destination alpha that never grows passes, and it blended onto a clear canvas only, where the destination's alpha is skipped. The transparent partial test compared two targets without checking that either keeps alpha, so it passed with transparency disabled. Each now fails when the behavior it names is broken: the unit test pins the opacity three quarter-opaque layers reach, and how the destination's alpha and color add up; the partial test requires clear pixels in the frame it compares.
This branch has not been deployed
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.
What this changes
Fixes #174
A frame that keeps alpha was drawn twice, on black and on white, with the opacity recovered from the difference: twice the paint, a whole unblend pass, and a white buffer as large as the frame kept between frames. Every change also repainted the whole target, so the cost followed the window size rather than the change: at 1920x1080 and 2x, updating one label took 31 ms, against 0.19 ms on an opaque target.
Canvas pixels now carry alpha, and blending composites premultiplied pixels, so such a frame is drawn once. Whether a canvas keeps alpha is chosen per primitive, so opaque frames keep their exact pixels: the 28 deterministic images of
cpui-snapshotsare byte-identical before and after. Transparent windows and offscreen targets now use the normal damage planning, so only what changed is redrawn, and an idle frame costs nothing.The white buffer, about 33 MB at that size and scale, is gone.
Renderer::draw_transparentkeeps its signature and draws once too.Checks
scripts/check.shpassesCHANGELOG.mdis updated for a change users will noticedocs/anddocs/zh-CN/, if they are affectedcargo run --release -p cpui-benchstays within budget, if per-frame code changedNew tests cover premultiplied blending, tinting a capture that keeps alpha, a scaled and faded capture matching on both canvases, and partial transparent frames matching full ones through rotating buffers, scrolling and theme changes.
cargo checkpasses for the minimum Rust (1.89),aarch64-linux-androidandwasm32-unknown-unknown.