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
Make offscreen canvas rendering context use offscreen canvas' size #24465
Comments
Cool! I'll start looking into it |
Should I also remove the |
Also, given that it's not yet merged, is it possible for me to check out the code from #24464 to make changes, or is it easier to just wait for the merge to occur? |
That will set your current git head to the head of that branch, using your own local branch with the name |
There are a lot of mismatches between |
Either updating them to use u64 or creating new Size2D values with the inner width and height values cast to the appropriate type. |
Okay cool. If I create the new |
If it requires casting u64 to u32, we should probably update the CanvasState code to use u64 internally. |
So, converting everything to u64 seems to be quite an extensive undertaking that makes OffscreenCanvas' size implementation inconsistent with that of HTMLCanvasElement's size (which uses u32). While attempting to switch OffscreenCanvasRenderingContext2D to use u64 sizes, it required changing several methods that other objects (like HTMLCanvasElement) relied upon (for example, some in macros.rs and lib.rs). I propose that we instead change OffscreenCanvas.rs to use u32 sizes to bring it in-line with the implementation of HTMLCanvasElement and CanvasRenderingContext2D. This requires changing the OffscreenCanvasBinding. If we use u64 on OffscreenCanvasRenderingContext2D, we'd need to change HTMLCanvasElement's bindings (because of shared methods). Questions:
Here's a link to a branch with the build failing because of the OffscreenCanvas's u64 sizes and OffscreenCanvasRenderingContext2D's u32 sizes: |
We face a limitation, because OffscreenCanvasBinding is generated automatically from https://github.com/servo/servo/blob/master/components/script/dom/webidls/OffscreenCanvas.webidl, which comes from https://html.spec.whatwg.org/multipage/canvas.html#the-offscreencanvas-interface and explicitly requires Let's take a step back - what are the actual problems that you were running into in #24465 (comment)? I checked and CanvasState already already accepts a u64 size in its constructor, so what sort of mismatches are you talking about? The code in CanvasRenderingContext2D and OffscreenCanvasRenderingContext2D should be distinct, they just share the common use of CanvasState. |
Right! The issue is specifically in GetImageData(), PutImageData(), and PutImageData_() in OffscreenCanvasRenderingContext2D. Those all call corresponding methods in CanvasRenderingContext2D, and in those calls, I'm passing in the associated canvas' size (u64) (GetImageData in OffscreenCanvasRenderingContext2D). The issue is that in CanvasRenderingContext2D, there are calls to actually write/read ImageData, and this has height/width properties that are u32 and are constrained by bindings (GetImageData in CanvasRenderingContext2D) (ImageData). |
So, to be pedantic, those methods actually call CanvasState::GetImageData/PutImageData/PutImageData_, which are hand-written and not generated. Is there a problem updating those to accept u64 values, and casting the u32 values used in CanvasRenderingContext2D::GetImageData/PutImageData/PutImageData_? Similarly, ImageData could store u64 values internally and still accept u32 values in the public generated APIs. |
Ah okay–my bad. That seems reasonable. I'll try and modify ImageData! I may need to modify a few more methods as well to accept u64 (associated with rectangle manipulation) but that shouldn't be a problem |
Alright; on the final stretch here. I have the types switched over successfully and am now working on the final task: "when OffscreenCanvas's SetWidth or SetHeight methods are called, send a CanvasMsg::Recreate message to the canvas paint thread (see CanvasRenderingContext2D::set_bitmap_dimensions for a model, called from HTMLCanvasElement::recreate_contexts)" I'm working on adding the necessary methods, and it seems pretty straightforward, but I have a question. In canvasrenderingcontext2d.rs, CanvasRenderingContext2D is able to access the members of CanvasState (stored in its own canvas_state member). This allows it to provide functions like CanvasRenderingContext2D::set_bitmap_dimensions. OffscreenCanvasRenderingContext2D is not able to access the internal members of CanvasState. For example, I get the compiler output:
I did some searching to figure out why this is the case, but everything I've read seems to point to the idea that structs' members are private unless explicitly marked |
We either need to make the members public or add a method that encapsulates the operation on the private members. I think adding a |
Oh, and the 2d canvas code can access them because it is currently in the same module as CanvasState (because they're in the same file), and privacy exists at the module boundary. |
Make offscreen canvas rendering context use offscreen canvas' size Updated the offscreen canvas rendering context to use the offscreen canvas' size. This involved upgrading several methods to accept u64 sizes. Additionally, the code in OffscreenCanvas::SetWidth() and OffscreenCanvas::SetHeight() was updated to send CanvasMsg::Recreate to the canvas paint thread. --- - [X] `./mach build -d` does not report any errors - [X] `./mach test-tidy` does not report any errors - [X] These changes fix #24465 - [X] These changes do not require tests because the purpose of this was to tidy up code
Make offscreen canvas rendering context use offscreen canvas' size; Consolidate size helpers <!-- Please describe your changes on the following line: --> Addresses issues raised in the review of PR #24518 and includes changes to 17 tests' metadata for those that now PASS. Contains fixes in PR #24518: Updated the offscreen canvas rendering context to use the offscreen canvas' size. This involved upgrading several methods to accept u64 sizes. Additionally, the code in OffscreenCanvas::SetWidth() and OffscreenCanvas::SetHeight() was updated to send CanvasMsg::Recreate to the canvas paint thread. --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `___` with appropriate data: --> - [X] `./mach build -d` does not report any errors - [X] `./mach test-tidy` does not report any errors - [X] These changes fix #24465 <!-- Either: --> - [X] There are tests for these changes – 17 were updated to PASS
…map_dimensions Removed passing test .ini files and moved euclid extensions to euclidext.rs to factor out redundant code Removed passing tests Moved Euclid extensions to euclidext.rs and replaced imports where necessary Tidied up set bitmap dimensions so that it resides in canvas state Add set_bitmap_dimensions to ContextState. Without borrow. Tests passing successfully
…map_dimensions Removed passing test .ini files and moved euclid extensions to euclidext.rs to factor out redundant code Removed passing tests Moved Euclid extensions to euclidext.rs and replaced imports where necessary Tidied up set bitmap dimensions so that it resides in canvas state Add set_bitmap_dimensions to ContextState. Without borrow. Tests passing successfully Removed width and height from offscreenrenderingcontext2d; switched to using canvas size where needed; made canvas definite instead of optional. still need to change sizing in associated classes to use u64 instead of u32 removed size from offscreencanvasrenderingcontext2d.rs; now getting canvas size through referenced canvas Updated pixels::clip to use u64 data types and added trait to canvasrenderingcontext2d.rs to convert u32 sizes to u64 added Size2D<u32> to Size2D<u64> conversion to webglrenderingcontext and converted u32 sizes to u64 where relevant updated get_rect to use u64. beginning to make type changes to canvas.rs Updated canvas, canvas_data, and canvas_paint_thread to use u64 when relevant Added ability to Recreate canvas when OffscreenCanvas::SetWidth() or OffscreenCanvas::SetHeight() are called Fixed formatting; passes ./mach test-tidy 🎉 consolidated sizing helpers and updated 17 tests with 'PASS' Removed passing tests Moved Euclid extensions to euclidext.rs and replaced imports where necessary Tidied up set bitmap dimensions so that it resides in canvas state Add set_bitmap_dimensions to ContextState. Without borrow. merged
…map_dimensions Removed passing test .ini files and moved euclid extensions to euclidext.rs to factor out redundant code
…map_dimensions Removed passing test .ini files and moved euclid extensions to euclidext.rs to factor out redundant code
Make offscreen canvas rendering context use offscreen canvas' size; Consolidate size helpers <!-- Please describe your changes on the following line: --> Addresses issues raised in the review of PR #24518 and includes changes to 17 tests' metadata for those that now PASS. Contains fixes in PR #24518: Updated the offscreen canvas rendering context to use the offscreen canvas' size. This involved upgrading several methods to accept u64 sizes. Additionally, the code in OffscreenCanvas::SetWidth() and OffscreenCanvas::SetHeight() was updated to send CanvasMsg::Recreate to the canvas paint thread. --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `___` with appropriate data: --> - [X] `./mach build -d` does not report any errors - [X] `./mach test-tidy` does not report any errors - [X] These changes fix #24465 and fix #24536 <!-- Either: --> - [X] There are tests for these changes – 17 were updated to PASS
Make offscreen canvas rendering context use offscreen canvas' size; Consolidate size helpers <!-- Please describe your changes on the following line: --> Addresses issues raised in the review of PR #24518 and includes changes to 17 tests' metadata for those that now PASS. Contains fixes in PR #24518: Updated the offscreen canvas rendering context to use the offscreen canvas' size. This involved upgrading several methods to accept u64 sizes. Additionally, the code in OffscreenCanvas::SetWidth() and OffscreenCanvas::SetHeight() was updated to send CanvasMsg::Recreate to the canvas paint thread. --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `___` with appropriate data: --> - [X] `./mach build -d` does not report any errors - [X] `./mach test-tidy` does not report any errors - [X] These changes fix #24465 and fix #24536 <!-- Either: --> - [X] There are tests for these changes – 17 were updated to PASS
Spec: https://html.spec.whatwg.org/multipage/canvas.html#dom-offscreencanvas-width
#24464 adds
width
andheight
members, but these are duplicated from the ones stored in the associated OffscreenCanvas. We should do the following:@bblanke This would be a good task for your group to work on. It should allow some more tests to pass, too.
The text was updated successfully, but these errors were encountered: