Skip to content

Commit

Permalink
CanvasRenderTask connected to Layout
Browse files Browse the repository at this point in the history
Update rust-azure to f4a02f3f621b0a994a20d42e438371a87c62f898.
  • Loading branch information
ebalint committed Jan 9, 2015
1 parent 43e34d6 commit 81f4734
Show file tree
Hide file tree
Showing 11 changed files with 359 additions and 130 deletions.
22 changes: 17 additions & 5 deletions components/canvas/canvas_paint_task.rs
Expand Up @@ -9,13 +9,15 @@ use geom::size::Size2D;
use servo_util::task::spawn_named;

use std::comm;
use std::sync::Arc;

#[deriving(Copy)]
#[deriving(Clone)]
pub enum CanvasMsg {
FillRect(Rect<f32>),
ClearRect(Rect<f32>),
StrokeRect(Rect<f32>),
Recreate(Size2D<i32>),
SendPixelContents(Sender<Arc<Vec<u8>>>),
Close,
}

Expand All @@ -29,7 +31,7 @@ pub struct CanvasPaintTask {
impl CanvasPaintTask {
fn new(size: Size2D<i32>) -> CanvasPaintTask {
CanvasPaintTask {
drawtarget: CanvasPaintTask::create(size),
drawtarget: CanvasPaintTask::create_with_data(size),
fill_color: ColorPattern::new(Color::new(0., 0., 0., 1.)),
stroke_color: ColorPattern::new(Color::new(0., 0., 0., 1.)),
stroke_opts: StrokeOptions::new(1.0, 1.0),
Expand All @@ -47,6 +49,7 @@ impl CanvasPaintTask {
CanvasMsg::StrokeRect(ref rect) => painter.stroke_rect(rect),
CanvasMsg::ClearRect(ref rect) => painter.clear_rect(rect),
CanvasMsg::Recreate(size) => painter.recreate(size),
CanvasMsg::SendPixelContents(chan) => painter.send_pixel_contents(chan),
CanvasMsg::Close => break,
}
}
Expand All @@ -68,11 +71,20 @@ impl CanvasPaintTask {
self.drawtarget.stroke_rect(rect, &self.stroke_color, &self.stroke_opts, &drawopts);
}

fn create(size: Size2D<i32>) -> DrawTarget {
DrawTarget::new(BackendType::Skia, size, SurfaceFormat::B8G8R8A8)
fn create_with_data(size: Size2D<i32>) -> DrawTarget {
DrawTarget::new_with_data(BackendType::Skia,
Vec::from_elem((size.width * size.height * 4) as uint, 0u8),
0,
size,
size.width * 4,
SurfaceFormat::B8G8R8A8)
}

fn recreate(&mut self, size: Size2D<i32>) {
self.drawtarget = CanvasPaintTask::create(size);
self.drawtarget = CanvasPaintTask::create_with_data(size);
}

fn send_pixel_contents(&mut self, chan: Sender<Arc<Vec<u8>>>) {
chan.send(self.drawtarget.data.clone().unwrap());
}
}
7 changes: 6 additions & 1 deletion components/layout/construct.rs
Expand Up @@ -24,6 +24,7 @@ use flow;
use flow_ref::FlowRef;
use fragment::{Fragment, IframeFragmentInfo};
use fragment::ImageFragmentInfo;
use fragment::CanvasFragmentInfo;
use fragment::InlineAbsoluteHypotheticalFragmentInfo;
use fragment::{InlineBlockFragmentInfo, SpecificFragmentInfo};
use fragment::TableColumnFragmentInfo;
Expand Down Expand Up @@ -272,6 +273,9 @@ impl<'a> FlowConstructor<'a> {
Some(NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLTableRowElement))) |
Some(NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLTableSectionElement))) => SpecificFragmentInfo::TableRow,
Some(NodeTypeId::Text) => SpecificFragmentInfo::UnscannedText(UnscannedTextFragmentInfo::new(node)),
Some(NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLCanvasElement))) => {
SpecificFragmentInfo::Canvas(box CanvasFragmentInfo::new(node))
}
_ => {
// This includes pseudo-elements.
SpecificFragmentInfo::Generic
Expand Down Expand Up @@ -1145,7 +1149,7 @@ impl<'a> PostorderNodeMutTraversal for FlowConstructor<'a> {
}
};

debug!("building flow for node: {} {}", display, float);
debug!("building flow for node: {} {} {}", display, float, node.type_id());

// Switch on display and floatedness.
match (display, float, positioning) {
Expand Down Expand Up @@ -1288,6 +1292,7 @@ impl<'ln> NodeUtils for ThreadSafeLayoutNode<'ln> {
None |
Some(NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLImageElement))) => true,
Some(NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLObjectElement))) => self.has_object_data(),
Some(NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLCanvasElement))) => true,
Some(NodeTypeId::Element(_)) => false,
}
}
Expand Down
36 changes: 35 additions & 1 deletion components/layout/display_list_builder.rs
Expand Up @@ -11,6 +11,7 @@
#![deny(unsafe_blocks)]

use block::BlockFlow;
use canvas::canvas_paint_task::CanvasMsg::SendPixelContents;
use context::LayoutContext;
use flow::{mod, Flow, IS_ABSOLUTELY_POSITIONED, NEEDS_LAYER};
use fragment::{CoordinateSystem, Fragment, IframeFragmentInfo, ImageFragmentInfo};
Expand All @@ -32,12 +33,14 @@ use gfx::display_list::TextOrientation;
use gfx::display_list::{SolidColorDisplayItem};
use gfx::display_list::{StackingContext, TextDisplayItem};
use gfx::paint_task::PaintLayer;
use png;
use png::PixelsByColorType;
use servo_msg::compositor_msg::ScrollPolicy;
use servo_msg::constellation_msg::Msg as ConstellationMsg;
use servo_msg::constellation_msg::ConstellationChan;
use servo_net::image::holder::ImageHolder;
use servo_util::cursor::Cursor;
use servo_util::geometry::{mod, Au};
use servo_util::geometry::{mod, Au, to_px};
use servo_util::logical_geometry::{LogicalPoint, LogicalRect, LogicalSize};
use servo_util::opts;
use std::default::Default;
Expand Down Expand Up @@ -862,6 +865,37 @@ impl FragmentDisplayListBuilding for Fragment {
debug!("(building display list) no image :(");
}
}
SpecificFragmentInfo::Canvas(ref canvas_fragment_info) => {
let width = canvas_fragment_info.replaced_image_fragment_info
.computed_inline_size.map_or(0, |w| to_px(w) as uint);
let height = canvas_fragment_info.replaced_image_fragment_info
.computed_block_size.map_or(0, |h| to_px(h) as uint);

let (sender, receiver) = channel::<Arc<Vec<u8>>>();
let canvas_data = match canvas_fragment_info.renderer {
Some(ref renderer) => {
renderer.deref().lock().send(SendPixelContents(sender));
(*receiver.recv()).clone()
},
None => Vec::from_elem(width * height * 4, 0xFFu8)
};

let canvas_display_item = box ImageDisplayItem {
base: BaseDisplayItem::new(stacking_relative_content_box,
DisplayItemMetadata::new(self.node,
&*self.style,
Cursor::DefaultCursor),
(*clip).clone()),
image: Arc::new(box png::Image {
width: width as u32,
height: height as u32,
pixels: PixelsByColorType::RGBA8(canvas_data),
}),
stretch_size: stacking_relative_content_box.size,
};

display_list.content.push_back(DisplayItem::ImageClass(canvas_display_item));
}
}
}

Expand Down

13 comments on commit 81f4734

@bors-servo
Copy link
Contributor

Choose a reason for hiding this comment

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

saw approval from jdm
at ebalint@81f4734

@bors-servo
Copy link
Contributor

Choose a reason for hiding this comment

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

merging ebalint/servo/canvas = 81f4734 into auto

@bors-servo
Copy link
Contributor

Choose a reason for hiding this comment

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

ebalint/servo/canvas = 81f4734 merged ok, testing candidate = bd4aae5

@bors-servo
Copy link
Contributor

Choose a reason for hiding this comment

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

@bors-servo
Copy link
Contributor

Choose a reason for hiding this comment

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

saw approval from jdm
at ebalint@81f4734

@bors-servo
Copy link
Contributor

Choose a reason for hiding this comment

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

merging ebalint/servo/canvas = 81f4734 into auto

@bors-servo
Copy link
Contributor

Choose a reason for hiding this comment

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

ebalint/servo/canvas = 81f4734 merged ok, testing candidate = 5539745

@bors-servo
Copy link
Contributor

Choose a reason for hiding this comment

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

@bors-servo
Copy link
Contributor

Choose a reason for hiding this comment

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

saw approval from jdm
at ebalint@81f4734

@bors-servo
Copy link
Contributor

Choose a reason for hiding this comment

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

merging ebalint/servo/canvas = 81f4734 into auto

@bors-servo
Copy link
Contributor

Choose a reason for hiding this comment

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

ebalint/servo/canvas = 81f4734 merged ok, testing candidate = da400a7

@bors-servo
Copy link
Contributor

Choose a reason for hiding this comment

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

@bors-servo
Copy link
Contributor

Choose a reason for hiding this comment

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

fast-forwarding master to auto = da400a7

Please sign in to comment.