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

NCSU Canvas Rendering Project Initial Steps #20447

Merged
merged 1 commit into from Apr 3, 2018

Conversation

Brody-Eastwood
Copy link
Contributor

@Brody-Eastwood Brody-Eastwood commented Mar 27, 2018

Implements the initial steps from:

https://github.com/servo/servo/wiki/Canvas-rendering-project


  • ./mach build -d does not report any errors
  • ./mach test-tidy does not report any errors
  • These changes fix #__ (github issue number if applicable).
  • There are tests for these changes OR
  • These changes do not require tests because _____

This change is Reviewable

@highfive
Copy link

Thanks for the pull request, and welcome! The Servo team is excited to review your changes, and you should hear from @pcwalton (or someone else) soon.

@highfive
Copy link

Heads up! This PR modifies the following files:

  • @emilio: components/layout/fragment.rs, components/layout/display_list/builder.rs
  • @fitzgen: components/script/dom/paintrenderingcontext2d.rs, components/script/dom/canvasrenderingcontext2d.rs, components/script_traits/script_msg.rs, components/script/dom/bindings/trace.rs, components/script/dom/htmlcanvaselement.rs
  • @KiChjang: components/script/dom/paintrenderingcontext2d.rs, components/script/dom/canvasrenderingcontext2d.rs, components/script_traits/script_msg.rs, components/script/dom/bindings/trace.rs, components/script/dom/htmlcanvaselement.rs
  • @asajeffrey: components/script/dom/paintrenderingcontext2d.rs, components/script/dom/canvasrenderingcontext2d.rs, components/constellation/constellation.rs, components/script/dom/bindings/trace.rs, components/script/dom/htmlcanvaselement.rs
  • @cbrewster: components/constellation/constellation.rs
  • @paulrouget: components/constellation/constellation.rs

@highfive highfive added the S-awaiting-review There is new code that needs to be reviewed. label Mar 27, 2018
@highfive
Copy link

warning Warning warning

  • These commits modify layout and script code, but no tests are modified. Please consider adding a test!

Copy link
Member

@jdm jdm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work!

@@ -99,7 +100,8 @@ impl<'a> CanvasPaintState<'a> {
impl<'a> CanvasPaintThread<'a> {
fn new(size: Size2D<i32>,
webrender_api_sender: webrender_api::RenderApiSender,
antialias: AntialiasMode) -> CanvasPaintThread<'a> {
antialias: AntialiasMode,
canvas_id: CanvasId) -> CanvasPaintThread<'a> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: indentation

}
}

/// Creates a new `CanvasPaintThread` and returns an `IpcSender` to
/// communicate with it.
pub fn start(size: Size2D<i32>,
webrender_api_sender: webrender_api::RenderApiSender,
antialias: bool)
antialias: bool,
canvas_id: CanvasId)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: indentation

opts::get().enable_canvas_antialiasing);
if let Err(e) = response_sender.send(sender) {
opts::get().enable_canvas_antialiasing,self.canvas_id.clone());
if let Err(e) = response_sender.send((sender,self.canvas_id.clone())) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: add a space after , in both these lines.

@@ -1800,7 +1800,7 @@ impl FragmentDisplayListBuilding for Fragment {
let ipc_renderer = ipc_renderer.lock().unwrap();
let (sender, receiver) = ipc::channel().unwrap();
ipc_renderer
.send(CanvasMsg::FromLayout(FromLayoutMsg::SendData(sender)))
.send(CanvasMsg::FromLayout(FromLayoutMsg::SendData(sender), canvas_fragment_info.canvas_id.clone()))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: move this argument onto the next line so it's easier to read.

@@ -133,7 +134,8 @@ impl CanvasRenderingContext2D {
let script_to_constellation_chan = global.script_to_constellation_chan();
debug!("Asking constellation to create new canvas thread.");
script_to_constellation_chan.send(ScriptMsg::CreateCanvasPaintThread(size, sender)).unwrap();
let ipc_renderer = receiver.recv().unwrap();
let response = receiver.recv().unwrap();
let (ipc_renderer, canvas_id) = response;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These lines can be combined:

let (ipc_render, canvas_id) = receiver.recv().unwrap();

@@ -11,7 +11,7 @@ use LayoutControlMsg;
use LoadData;
use WorkerGlobalScopeInit;
use WorkerScriptLoadOrigin;
use canvas_traits::canvas::CanvasMsg;
use canvas_traits::canvas::{CanvasMsg,CanvasId};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: space after ,

@@ -79,7 +79,7 @@ pub enum ScriptMsg {
ChangeRunningAnimationsState(AnimationState),
/// Requests that a new 2D canvas thread be created. (This is done in the constellation because
/// 2D canvases may use the GPU and we don't want to give untrusted content access to the GPU.)
CreateCanvasPaintThread(Size2D<i32>, IpcSender<IpcSender<CanvasMsg>>),
CreateCanvasPaintThread(Size2D<i32>, IpcSender<(IpcSender<CanvasMsg>,CanvasId)>),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: space after ,

try {
ctx2.drawImage.apply(ctx2, args);
try {
ctx2.drawImage.apply(ctx2, args);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: revert the formatting changes in this file.

};

var t0 = performance.now(); //save starting time
drawImage(25, 25); // The source canvas will copied to the 0,0 position of the destination canvas
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: odd indentation on this line.


args.unshift(canvas1);
try {
ctx2.drawImage.apply(ctx2, args);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: odd indentation on these lines.

@jdm jdm added S-needs-code-changes Changes have not yet been made that were requested by a reviewer. and removed S-awaiting-review There is new code that needs to be reviewed. labels Mar 27, 2018
@jdm jdm assigned jdm and unassigned pcwalton Mar 27, 2018
@highfive highfive added S-awaiting-review There is new code that needs to be reviewed. and removed S-needs-code-changes Changes have not yet been made that were requested by a reviewer. labels Mar 28, 2018
@jdm
Copy link
Member

jdm commented Mar 28, 2018

./mach test-tidy is complaining:

./components/layout/fragment.rs:11: missing space after ,
./components/script/dom/bindings/trace.rs:34: use statement is not in alphabetical order
	expected: canvas_traits::canvas::CanvasId
	found: canvas_traits::canvas::{CanvasGradientStop, LinearGradientStyle, RadialGradientStyle}

Please squash all the commits into one as well.

@jdm jdm added S-needs-code-changes Changes have not yet been made that were requested by a reviewer. S-needs-squash Some (or all) of the commits in the PR should be combined. and removed S-awaiting-review There is new code that needs to be reviewed. labels Mar 28, 2018
@highfive highfive added S-awaiting-review There is new code that needs to be reviewed. and removed S-needs-code-changes Changes have not yet been made that were requested by a reviewer. labels Mar 30, 2018
@pmocher
Copy link

pmocher commented Mar 30, 2018

Hi! This is my first time squashing all of the commits into one. I probably did something that I wasn't supposed to.

@jdm
Copy link
Member

jdm commented Mar 30, 2018

Yeah, if the pull request still shows >1 commit after refreshing, it didn't achieve the desired effect. Be sure to run git rebase -i 5f62a1789a9bf1f4ddc736dd131d0fe4269242c3^ and mark all the commits as s instead of pick except for the topmost one.

@pmocher
Copy link

pmocher commented Mar 30, 2018

I see. I'll do that now.

@servo-wpt-sync
Copy link
Collaborator

Error syncing changes upstream. Logs saved in error-snapshot-1522386139768.

@servo-wpt-sync
Copy link
Collaborator

Error syncing changes upstream. Logs saved in error-snapshot-1522386382447.

@servo-wpt-sync
Copy link
Collaborator

Error syncing changes upstream. Logs saved in error-snapshot-1522386512547.

@pmocher
Copy link

pmocher commented Mar 30, 2018

It seems as though I've messed something up.

@jdm
Copy link
Member

jdm commented Mar 30, 2018

Indeed. I recommend running git reflog, copying the hash of the entry that corresponds to the last commit you made that appears in that list of git actions, and running git reset --hard [hash]. This should reset the state of your repository to the pre-squash state.

@jdm
Copy link
Member

jdm commented Mar 30, 2018

Ok, all of the automated tests that use a canvas are panicking with stacks like this:

  ▶ CRASH [expected PASS] /2dcontext/line-styles/canvas_linestyles_linecap_001.htm
  │ 
  │ VMware, Inc.
  │ softpipe
  │ 3.3 (Core Profile) Mesa 17.3.0-devel
  │ assertion failed: thread_state::get().is_script() (thread LayoutThread PipelineId { namespace_id: PipelineNamespaceId(0), index: PipelineIndex(NonZero(NonZero(1))) }, at components/script/dom/bindings/cell.rs:98)
  │ stack backtrace:
  │    0:     0x7f418c1b2d6c - backtrace::backtrace::trace::heb9efa3021143bc0
  │    1:     0x7f418c1b20f2 - backtrace::capture::Backtrace::new::hd20e533c9c999e36
  │    2:     0x7f41891ae90c - servo::main::{{closure}}::h96f2fd035380f7d9
  │    3:     0x7f418c1c1905 - std::panicking::rust_panic_with_hook::h489260a27605eec3
  │                         at libstd/panicking.rs:577
  │    4:     0x7f418a2c1fc3 - std::panicking::begin_panic::h88970b163c1446a9
  │    5:     0x7f4189b2a7dd - script::dom::htmlcanvaselement::HTMLCanvasElement::get_canvas_id::h8af515f893db25df
  │    6:     0x7f4189824166 - <script::dom::bindings::root::LayoutDom<script::dom::htmlcanvaselement::HTMLCanvasElement> as script::dom::htmlcanvaselement::LayoutHTMLCanvasElementHelpers>::data::hb960f9960efcb3dc
  │    7:     0x7f418982de02 - <script::dom::bindings::root::LayoutDom<script::dom::node::Node> as script::dom::node::LayoutNodeHelpers>::canvas_data::hc4d0763ec1019568
  │    8:     0x7f41895358fe - <layout::construct::FlowConstructor<'a, ConcreteThreadSafeLayoutNode>>::build_fragment_for_block::h313458c542f016e8
  │    9:     0x7f41895234bf - <layout::construct::FlowConstructor<'a, ConcreteThreadSafeLayoutNode> as layout::traversal::PostorderNodeMutTraversal<ConcreteThreadSafeLayoutNode>>::process::ha6229ff0a27676fd
  │   10:     0x7f4189630eef - style::traversal::DomTraversal::handle_postorder_traversal::h992f91b2749e6bd8
  │   11:     0x7f41895ca3dc - style::driver::traverse_dom::h9b6af5485b4e1784
  │   12:     0x7f41894da9d0 - layout_thread::LayoutThread::handle_reflow::hafe580cf2b79e1af
  │   13:     0x7f41894d447c - layout_thread::LayoutThread::handle_request_helper::hb3abd95d5d0b09c0
  │   14:     0x7f41894d2d79 - layout_thread::LayoutThread::start::h9537b41eb8b948cf
  │   15:     0x7f41895ba063 - profile_traits::mem::ProfilerChan::run_with_memory_reporting::hc7bbe6eff5174296
  │   16:     0x7f418953f62b - std::sys_common::backtrace::__rust_begin_short_backtrace::h7bf083075dc64c41
  │   17:     0x7f41894b54c7 - _ZN3std9panicking3try7do_call17hdeaf1406e5993f92E.llvm.9F59020
  │   18:     0x7f418c1eaf9e - __rust_maybe_catch_panic
  │                         at libpanic_unwind/lib.rs:102
  │   19:     0x7f418959f23a - <F as alloc::boxed::FnBox<A>>::call_box::hdb8301d823bd613e
  │   20:     0x7f418c1d98a7 - <alloc::boxed::Box<alloc::boxed::FnBox<A, Output$u3d$R$GT$$u20$$u2b$$u20$$u27$a$GT$$u20$as$u20$core..ops..function..FnOnce$LT$A$GT$$GT$::call_once::h4bbca053e9002218
  │                         at /checkout/src/liballoc/boxed.rs:798
  │                          - std::sys_common::thread::start_thread::h3301b0b4cb89e2c1
  │                         at libstd/sys_common/thread.rs:24
  │   21:     0x7f418c1c1f68 - std::sys::unix::thread::Thread::new::thread_start::h6f2358c4012c0e12
  │                         at libstd/sys/unix/thread.rs:90
  │   22:     0x7f418809f183 - start_thread
  │   23:     0x7f4186966ffc - clone
  │   24:                0x0 - <unknown>

This means that LayoutHTMLCanvasElementHelpers::data is invoking HTMLCanvasElement::get_canvas_id, which calls DomRefCell::borrow on self.context. This fails assertions we have in place about which thread is active when this borrow operation occurs, so you'll need to write a get_canvas_id_for_layout helper method that duplicates get_canvas_id but uses borrow_for_layout instead of borrow. Sorry, it's not a great system and we haven't spent time on creating something with fewer surprises.

@jdm
Copy link
Member

jdm commented Mar 30, 2018

cc @SimonSapin so you're aware of what's happening in this PR.

@highfive highfive added S-awaiting-review There is new code that needs to be reviewed. and removed S-tests-failed The changes caused existing tests to fail. labels Apr 1, 2018
@jdm
Copy link
Member

jdm commented Apr 1, 2018

@bors-servo r+

@bors-servo
Copy link
Contributor

📌 Commit 3b5cdec has been approved by jdm

@highfive highfive added S-awaiting-merge The PR is in the process of compiling and running tests on the automated CI. and removed S-awaiting-review There is new code that needs to be reviewed. labels Apr 1, 2018
@bors-servo
Copy link
Contributor

⌛ Testing commit 3b5cdec with merge 3381ade...

bors-servo pushed a commit that referenced this pull request Apr 1, 2018
NCSU Canvas Rendering Project Initial Steps

<!-- Please describe your changes on the following line: -->
Implements the initial steps from:

https://github.com/servo/servo/wiki/Canvas-rendering-project

---
<!-- 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
- [ ] These changes fix #__ (github issue number if applicable).

<!-- Either: -->
- [X] There are tests for these changes OR
- [ ] These changes do not require tests because _____

<!-- 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/20447)
<!-- Reviewable:end -->
@bors-servo
Copy link
Contributor

💔 Test failed - linux-rel-css

@highfive highfive added S-tests-failed The changes caused existing tests to fail. and removed S-awaiting-merge The PR is in the process of compiling and running tests on the automated CI. labels Apr 1, 2018
@jdm
Copy link
Member

jdm commented Apr 2, 2018

Note: to run these 2d and 3d canvas tests locally, use ./mach test-wpt tests/wpt/web-platform-tests/2dcontext/transformations/canvas_transformations_reset_001.html and ./mach test-wpt tests/wpt/mozilla/tests/webgl/conformance-2.0.0/conformance2/samplers/sampler-drawing-test.html. This will verify that any changes made actually allow the tests to run correctly.

unsafe {
let canvas = &*self.unsafe_get();
if let &Some(CanvasContext::Context2d(ref context)) = canvas.context.borrow_for_layout() {
context.get_canvas_id()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, one more change is required. There needs to be a get_canvas_id_for_layout method added to LayoutCanvasRenderingContext2DHelpers in canvasrenderingcontext2d.rs. This line should then read context.to_layout().get_canvas_id().

@highfive highfive added S-awaiting-review There is new code that needs to be reviewed. and removed S-tests-failed The changes caused existing tests to fail. labels Apr 3, 2018
@Brody-Eastwood
Copy link
Contributor Author

Those tests succeeded locally! I'm really hoping we'll see success fully this time!

@jdm
Copy link
Member

jdm commented Apr 3, 2018

@bors-servo r+

@bors-servo
Copy link
Contributor

📌 Commit 8a1590e has been approved by jdm

@highfive highfive added S-awaiting-merge The PR is in the process of compiling and running tests on the automated CI. and removed S-awaiting-review There is new code that needs to be reviewed. labels Apr 3, 2018
@bors-servo
Copy link
Contributor

⌛ Testing commit 8a1590e with merge 9cd60c8...

bors-servo pushed a commit that referenced this pull request Apr 3, 2018
NCSU Canvas Rendering Project Initial Steps

<!-- Please describe your changes on the following line: -->
Implements the initial steps from:

https://github.com/servo/servo/wiki/Canvas-rendering-project

---
<!-- 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
- [ ] These changes fix #__ (github issue number if applicable).

<!-- Either: -->
- [X] There are tests for these changes OR
- [ ] These changes do not require tests because _____

<!-- 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/20447)
<!-- Reviewable:end -->
@bors-servo
Copy link
Contributor

☀️ Test successful - android, arm32, arm64, linux-dev, linux-rel-css, linux-rel-wpt, mac-dev-unit, mac-rel-css1, mac-rel-css2, mac-rel-wpt1, mac-rel-wpt2, mac-rel-wpt3, mac-rel-wpt4, windows-msvc-dev
Approved by: jdm
Pushing 9cd60c8 to master...

@bors-servo bors-servo merged commit 8a1590e into servo:master Apr 3, 2018
@highfive highfive removed the S-awaiting-merge The PR is in the process of compiling and running tests on the automated CI. label Apr 3, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants