diff options
author | bors-servo <lbergstrom+bors@mozilla.com> | 2018-04-02 22:24:34 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-04-02 22:24:34 -0400 |
commit | 9cd60c8e78af7b80e7578612ae442de26d1a325b (patch) | |
tree | 95cb4a7da49820c3c023c8c0ecab9d821f0ea32d /components/script/dom/htmlcanvaselement.rs | |
parent | a208d4246cf0e02a1a22196f26692bd29fb35011 (diff) | |
parent | 8a1590efc6ab6690cd9aab5ec3d46f854b891b4f (diff) | |
download | servo-9cd60c8e78af7b80e7578612ae442de26d1a325b.tar.gz servo-9cd60c8e78af7b80e7578612ae442de26d1a325b.zip |
Auto merge of #20447 - Brody-Eastwood:master, r=jdm
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 -->
Diffstat (limited to 'components/script/dom/htmlcanvaselement.rs')
-rw-r--r-- | components/script/dom/htmlcanvaselement.rs | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/components/script/dom/htmlcanvaselement.rs b/components/script/dom/htmlcanvaselement.rs index 8cfbccd5faa..3854b29967b 100644 --- a/components/script/dom/htmlcanvaselement.rs +++ b/components/script/dom/htmlcanvaselement.rs @@ -3,7 +3,7 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ use base64; -use canvas_traits::canvas::{CanvasMsg, FromScriptMsg}; +use canvas_traits::canvas::{CanvasMsg, CanvasId, FromScriptMsg}; use canvas_traits::webgl::WebGLVersion; use dom::attr::Attr; use dom::bindings::cell::DomRefCell; @@ -105,6 +105,7 @@ pub trait LayoutHTMLCanvasElementHelpers { fn data(&self) -> HTMLCanvasData; fn get_width(&self) -> LengthOrPercentageOrAuto; fn get_height(&self) -> LengthOrPercentageOrAuto; + fn get_canvas_id_for_layout(&self) -> CanvasId; } impl LayoutHTMLCanvasElementHelpers for LayoutDom<HTMLCanvasElement> { @@ -133,6 +134,7 @@ impl LayoutHTMLCanvasElementHelpers for LayoutDom<HTMLCanvasElement> { source: source, width: width_attr.map_or(DEFAULT_WIDTH, |val| val.as_uint()), height: height_attr.map_or(DEFAULT_HEIGHT, |val| val.as_uint()), + canvas_id: self.get_canvas_id_for_layout(), } } } @@ -156,6 +158,18 @@ impl LayoutHTMLCanvasElementHelpers for LayoutDom<HTMLCanvasElement> { .unwrap_or(LengthOrPercentageOrAuto::Auto) } } + + #[allow(unsafe_code)] + fn get_canvas_id_for_layout(&self) -> CanvasId { + unsafe { + let canvas = &*self.unsafe_get(); + if let &Some(CanvasContext::Context2d(ref context)) = canvas.context.borrow_for_layout() { + context.to_layout().get_canvas_id() + } else { + CanvasId(0) + } + } + } } @@ -261,7 +275,7 @@ impl HTMLCanvasElement { let data = match self.context.borrow().as_ref() { Some(&CanvasContext::Context2d(ref context)) => { let (sender, receiver) = ipc::channel(self.global().time_profiler_chan().clone()).unwrap(); - let msg = CanvasMsg::FromScript(FromScriptMsg::SendPixels(sender)); + let msg = CanvasMsg::FromScript(FromScriptMsg::SendPixels(sender), context.get_canvas_id()); context.get_ipc_renderer().send(msg).unwrap(); receiver.recv().unwrap()?.into() |