Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upRemove Cell/DomRefCell member wrappers from CanvasState struct #23436
Comments
|
Hi! If you have any questions regarding this issue, feel free to make a comment here, or ask it in the If you intend to work on this issue, then add |
|
@highfive: assign me |
|
Hey @chansuke! Thanks for your interest in working on this issue. It's now assigned to you! |
|
#23381 has not actually been able to merge yet, so this will have to wait. |
|
#23381 has merged, so this can be worked on now. |
|
@jdm Thanks! I will be going to start wokring on this:) |
|
@jdm Hi, I've removed the wrapper in CanvasState struct(to |
|
|
Remove redundant RefCell from CanvasState struct <!-- Please describe your changes on the following line: --> Removed DomRefCell member wrappers from CanvasState. --- <!-- 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 #23436 (GitHub issue number if applicable) <!-- Either: --> - [ ] There are tests for these changes OR - [x] These changes do not require tests because it only fixed redundancy. <!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.--> <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. --> <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/23730) <!-- Reviewable:end -->
Remove redundant RefCell from CanvasState struct <!-- Please describe your changes on the following line: --> Removed DomRefCell member wrappers from CanvasState. --- <!-- 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 #23436 (GitHub issue number if applicable) <!-- Either: --> - [ ] There are tests for these changes OR - [x] These changes do not require tests because it only fixed redundancy. <!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.--> <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. --> <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/23730) <!-- Reviewable:end -->
|
Hey @jdm, I see that code concerning the issue has changed quite a bit since this both the issue and its PR (#23730) was created. Based on the current implementation of |
|
@utsavoza In general I find methods that are &self or &mut self as needed on a struct are easier to read than those same methods performing lots of borrow/borrow_mut calls on their members. If we keep the DomRefCell wrapper around CanvasState and remove the per-member wrappers, that will yield easier to read code in my opinion. |
|
I agree. I did actually try to remove the Cell/DomRefCell member wrappers from CanvasState struct. The issue I saw with that is there will be some public methods in For example:
From the stacktrace, I am assuming that while mutably borrowing
which then causes the wpt to fail. There are few other similar scenarios that are resulting in failing wpt tests, which is why I considered removing DomRefCell wrapper for |
|
From reading the code (since draw_image_internal does not directly invoke send_canvas_2d_msg), it looks like that either comes from CanvasState::draw_html_canvas_element or CanvasState::draw_offscreen_canvas. I think we should only end up with a borrow problem in the case where we try to draw an html canvas inside of itself. One option to avoid that would be to pass the source canvas's CanvasId as an argument to draw_html_canvas_element and call this code with the source canvasid instead. That would avoid having to go through CanvasRenderingContext2D::send_canvas_2d_message. |
|
That being said, if the resulting code is just working around a couple edge cases, you might be right that it will be easier to read and write if we keep the member wrappers instead of the overall CanvasState wrapper. Use your best judgement! |
Remove DomRefCell wrapper for CanvasState <!-- Please describe your changes on the following line: --> --- <!-- 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 #23436 - [x] There are tests for these changes The PR removes the DomRefCell wrapper for CanvasState from `CanvasRenderingContext2D` and `OffscreenCanvasRenderingContext2D`. The reason for keeping member wrappers in CanvasState instead of overall CanvasState wrapper itself is because I believe that removing member wrappers would make it rather difficult to refactor the internal CanvasState methods in order to cover certain edge cases. [For example](#23436 (comment)): Drawing a canvas inside of itself would require getting and providing certain parameters for source canvas such as `canvas_id` and `is_origin_clean` that are currently accessed through source canvas context. Also, we might run into similar issue when creating patterns using canvas. <!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.--> <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->
CanvasState was introduced as part of a big refactor in #23381 that extracted common aspects of the offscreen canvas rendering context and the 2d canvas rendering context. Since the CanvasState struct is stored inside of a DomRefCell itself, that means that we can modify the methods for CanvasState to accept
&selfor&mut selfdirectly, so the Cell and DomRefCell members inside of CanvasState are redundant and can be removed.Code:
components/script/dom/canvasrenderingcontext2d.rsTo verify that everything behaves the same after changing the code, run
./mach test-wpt tests/wpt/web-platform-tests/2dcontext/ tests/wpt/web-platform-tests/offscreen-canvas.