Skip to content
Permalink
Browse files

CanvasRenderTask connected to Layout

Update rust-azure to f4a02f3f621b0a994a20d42e438371a87c62f898.
  • Loading branch information...
ebalint committed Nov 27, 2014
1 parent 43e34d6 commit 81f47344d6e121d86de368a25107415406de3c0f
@@ -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,
}

@@ -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),
@@ -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,
}
}
@@ -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());
}
}
@@ -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;
@@ -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
@@ -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) {
@@ -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,
}
}
@@ -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};
@@ -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;
@@ -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));
}
}
}

Oops, something went wrong.

13 comments on commit 81f4734

@bors-servo

This comment has been minimized.

Copy link
Contributor

bors-servo replied Jan 9, 2015

saw approval from jdm
at ebalint@81f4734

@bors-servo

This comment has been minimized.

Copy link
Contributor

bors-servo replied Jan 9, 2015

merging ebalint/servo/canvas = 81f4734 into auto

@bors-servo

This comment has been minimized.

Copy link
Contributor

bors-servo replied Jan 9, 2015

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

@bors-servo

This comment has been minimized.

Copy link
Contributor

bors-servo replied Jan 9, 2015

@bors-servo

This comment has been minimized.

Copy link
Contributor

bors-servo replied Jan 9, 2015

saw approval from jdm
at ebalint@81f4734

@bors-servo

This comment has been minimized.

Copy link
Contributor

bors-servo replied Jan 9, 2015

merging ebalint/servo/canvas = 81f4734 into auto

@bors-servo

This comment has been minimized.

Copy link
Contributor

bors-servo replied Jan 9, 2015

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

@bors-servo

This comment has been minimized.

Copy link
Contributor

bors-servo replied Jan 9, 2015

@bors-servo

This comment has been minimized.

Copy link
Contributor

bors-servo replied Jan 9, 2015

saw approval from jdm
at ebalint@81f4734

@bors-servo

This comment has been minimized.

Copy link
Contributor

bors-servo replied Jan 9, 2015

merging ebalint/servo/canvas = 81f4734 into auto

@bors-servo

This comment has been minimized.

Copy link
Contributor

bors-servo replied Jan 9, 2015

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

@bors-servo

This comment has been minimized.

Copy link
Contributor

bors-servo replied Jan 9, 2015

fast-forwarding master to auto = da400a7

Please sign in to comment.
You can’t perform that action at this time.