Skip to content
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

Merged
merged 6 commits into from
Sep 9, 2023

Conversation

CBenoit
Copy link
Contributor

@CBenoit CBenoit commented Sep 8, 2023

This patch fixes the present_with_damage implementation for the web backend. CanvasRenderingContext2D’s putImageData 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.

src/web.rs Outdated Show resolved Hide resolved
@CBenoit
Copy link
Contributor Author

CBenoit commented Sep 8, 2023

I addressed the clippy lint.

src/web.rs Outdated Show resolved Hide resolved
src/web.rs Outdated Show resolved Hide resolved
src/util.rs Show resolved Hide resolved
@daxpedda daxpedda force-pushed the web-fix-put-image branch 2 times, most recently from 52abefe to d4a6f5e Compare September 9, 2023 09:17
Copy link
Member

@daxpedda daxpedda left a 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!

CBenoit and others added 6 commits September 9, 2023 11:20
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`.
@daxpedda
Copy link
Member

daxpedda commented Sep 9, 2023

Just waiting for somebody to take a look at #150 (comment) before I merge this.

@notgull, would be appreciated.

@CBenoit
Copy link
Contributor Author

CBenoit commented Sep 9, 2023

Thank you for the prompt review!

Copy link
Member

@notgull notgull left a 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!

@daxpedda daxpedda merged commit 908408b into rust-windowing:master Sep 9, 2023
41 of 45 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

Successfully merging this pull request may close these issues.

3 participants