-
Notifications
You must be signed in to change notification settings - Fork 49
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(web): optimize and fix present_with_damage #150
Conversation
I addressed the clippy lint. |
b600089
to
1ccd3eb
Compare
52abefe
to
d4a6f5e
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @CBenoit!
Apart from the fix this is also a great performance improvement!
This patch fixes the present_with_damage implementation for the web backend. `CanvasRenderingContext2D`’s `putImageDate` was used incorrectly. As per Mozilla documentation: > imageData > > An ImageData object containing the array of pixel values. > > dx > > Horizontal position (x coordinate) at which to place the image data > in the destination canvas. > > dy > > Vertical position (y coordinate) at which to place the image data > in the destination canvas. > > dirtyX > > Horizontal position (x coordinate) of the top-left corner from which > the image data will be extracted. Defaults to 0. > > dirtyY > > Vertical position (y coordinate) of the top-left corner from which > the image data will be extracted. Defaults to 0. As such, `dx` is different from `dirtyX` and `dy` is different from `dirtyY`. When the actual `ImageData` is as big as the canvas itself, `dx` and `dy` should always be `0.0` and `0.0`, and only `dirtyX` and `dirtyY` are actually representing the top-left coordinates for the dirty region. The dirty region is relative to the image data. This patch also optimizes the BGRX to RGBA conversion by only creating a bitmap for the smallest region enclosing all the damaged regions. This does not affect the behavior of `present`.
4aa4563
to
94f2984
Compare
Just waiting for somebody to take a look at #150 (comment) before I merge this. @notgull, would be appreciated. |
Thank you for the prompt review! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me!
This patch fixes the
present_with_damage
implementation for the web backend.CanvasRenderingContext2D
’sputImageData
was used incorrectly.As per Mozilla documentation:
As such,
dx
is different fromdirtyX
anddy
is different fromdirtyY
.When the actual
ImageData
is as big as the canvas itself,dx
anddy
should always be0.0
and0.0
, and onlydirtyX
anddirtyY
are actually representing the top-left coordinates for the dirty region. The dirty region is relative to the image data.This patch also optimizes the BGRX to RGBA conversion by only creating a bitmap for the smallest region enclosing all the damaged regions. This does not affect the behavior of
present
.