Skip to content

Commit

Permalink
Use DrawTarget::new instead of DrawTarget::new_with_data in CanvasPai…
Browse files Browse the repository at this point in the history
…ntTask
  • Loading branch information
ebalint committed Jan 15, 2015
1 parent ddf77a1 commit 1d91e90
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 15 deletions.
22 changes: 9 additions & 13 deletions components/canvas/canvas_paint_task.rs
Expand Up @@ -9,15 +9,14 @@ use geom::size::Size2D;
use servo_util::task::spawn_named;

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

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

Expand All @@ -31,7 +30,7 @@ pub struct CanvasPaintTask {
impl CanvasPaintTask {
fn new(size: Size2D<i32>) -> CanvasPaintTask {
CanvasPaintTask {
drawtarget: CanvasPaintTask::create_with_data(size),
drawtarget: CanvasPaintTask::create(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 Down Expand Up @@ -71,20 +70,17 @@ impl CanvasPaintTask {
self.drawtarget.stroke_rect(rect, &self.stroke_color, &self.stroke_opts, &drawopts);
}

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 create(size: Size2D<i32>) -> DrawTarget {
DrawTarget::new(BackendType::Skia, size, SurfaceFormat::B8G8R8A8)
}

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

fn send_pixel_contents(&mut self, chan: Sender<Arc<Vec<u8>>>) {
chan.send(self.drawtarget.data.clone().unwrap());
fn send_pixel_contents(&mut self, chan: Sender<Vec<u8>>) {
self.drawtarget.snapshot().get_data_surface().with_data(|element| {
chan.send(element.to_vec());
})
}
}
4 changes: 2 additions & 2 deletions components/layout/display_list_builder.rs
Expand Up @@ -875,11 +875,11 @@ impl FragmentDisplayListBuilding for Fragment {
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 (sender, receiver) = channel::<Vec<u8>>();
let canvas_data = match canvas_fragment_info.renderer {
Some(ref renderer) => {
renderer.deref().lock().send(SendPixelContents(sender));
(*receiver.recv()).clone()
receiver.recv()
},
None => Vec::from_elem(width * height * 4, 0xFFu8)
};
Expand Down

13 comments on commit 1d91e90

@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@1d91e90

@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 = 1d91e90 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 = 1d91e90 merged ok, testing candidate = 2abff8a

@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@1d91e90

@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 = 1d91e90 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 = 1d91e90 merged ok, testing candidate = 6fb45ba

@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@1d91e90

@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 = 1d91e90 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 = 1d91e90 merged ok, testing candidate = d9d7fdf

@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 = d9d7fdf

Please sign in to comment.