mirror of
https://github.com/servo/servo.git
synced 2025-08-03 04:30:10 +01:00
Make canvas send their data themselves to other canvas
This commit is contained in:
parent
2086d216dd
commit
f8c3fe1076
7 changed files with 43 additions and 26 deletions
|
@ -148,6 +148,12 @@ impl<'a> CanvasPaintThread<'a> {
|
||||||
Canvas2dMsg::DrawImageSelf(image_size, dest_rect, source_rect, smoothing_enabled) => {
|
Canvas2dMsg::DrawImageSelf(image_size, dest_rect, source_rect, smoothing_enabled) => {
|
||||||
painter.draw_image_self(image_size, dest_rect, source_rect, smoothing_enabled)
|
painter.draw_image_self(image_size, dest_rect, source_rect, smoothing_enabled)
|
||||||
}
|
}
|
||||||
|
Canvas2dMsg::DrawImageInOther(
|
||||||
|
renderer, image_size, dest_rect, source_rect, smoothing, sender
|
||||||
|
) => {
|
||||||
|
painter.draw_image_in_other(
|
||||||
|
renderer, image_size, dest_rect, source_rect, smoothing, sender)
|
||||||
|
}
|
||||||
Canvas2dMsg::MoveTo(ref point) => painter.move_to(point),
|
Canvas2dMsg::MoveTo(ref point) => painter.move_to(point),
|
||||||
Canvas2dMsg::LineTo(ref point) => painter.line_to(point),
|
Canvas2dMsg::LineTo(ref point) => painter.line_to(point),
|
||||||
Canvas2dMsg::Rect(ref rect) => painter.rect(rect),
|
Canvas2dMsg::Rect(ref rect) => painter.rect(rect),
|
||||||
|
@ -371,6 +377,26 @@ impl<'a> CanvasPaintThread<'a> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn draw_image_in_other(&self,
|
||||||
|
renderer: IpcSender<CanvasMsg>,
|
||||||
|
image_size: Size2D<f64>,
|
||||||
|
dest_rect: Rect<f64>,
|
||||||
|
source_rect: Rect<f64>,
|
||||||
|
smoothing_enabled: bool,
|
||||||
|
sender: IpcSender<()>) {
|
||||||
|
let mut image_data = self.read_pixels(source_rect.to_i32(), image_size);
|
||||||
|
// TODO: avoid double byte_swap.
|
||||||
|
byte_swap(&mut image_data);
|
||||||
|
|
||||||
|
let msg = CanvasMsg::Canvas2d(Canvas2dMsg::DrawImage(
|
||||||
|
image_data, source_rect.size, dest_rect, source_rect, smoothing_enabled));
|
||||||
|
renderer.send(msg).unwrap();
|
||||||
|
// We acknowledge to the caller here that the data was sent to the
|
||||||
|
// other canvas so that if JS immediately afterwards try to get the
|
||||||
|
// pixels of the other one, it won't retrieve the other values.
|
||||||
|
sender.send(()).unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
fn move_to(&self, point: &Point2D<AzFloat>) {
|
fn move_to(&self, point: &Point2D<AzFloat>) {
|
||||||
self.path_builder.move_to(*point)
|
self.path_builder.move_to(*point)
|
||||||
}
|
}
|
||||||
|
|
|
@ -79,6 +79,8 @@ pub enum Canvas2dMsg {
|
||||||
ArcTo(Point2D<f32>, Point2D<f32>, f32),
|
ArcTo(Point2D<f32>, Point2D<f32>, f32),
|
||||||
DrawImage(Vec<u8>, Size2D<f64>, Rect<f64>, Rect<f64>, bool),
|
DrawImage(Vec<u8>, Size2D<f64>, Rect<f64>, Rect<f64>, bool),
|
||||||
DrawImageSelf(Size2D<f64>, Rect<f64>, Rect<f64>, bool),
|
DrawImageSelf(Size2D<f64>, Rect<f64>, Rect<f64>, bool),
|
||||||
|
DrawImageInOther(
|
||||||
|
IpcSender<CanvasMsg>, Size2D<f64>, Rect<f64>, Rect<f64>, bool, IpcSender<()>),
|
||||||
BeginPath,
|
BeginPath,
|
||||||
BezierCurveTo(Point2D<f32>, Point2D<f32>, Point2D<f32>),
|
BezierCurveTo(Point2D<f32>, Point2D<f32>, Point2D<f32>),
|
||||||
ClearRect(Rect<f32>),
|
ClearRect(Rect<f32>),
|
||||||
|
|
|
@ -20,7 +20,6 @@ tinyfiledialogs = {git = "https://github.com/jdm/tinyfiledialogs"}
|
||||||
angle = {git = "https://github.com/servo/angle", branch = "servo"}
|
angle = {git = "https://github.com/servo/angle", branch = "servo"}
|
||||||
app_units = {version = "0.2.3", features = ["plugins"]}
|
app_units = {version = "0.2.3", features = ["plugins"]}
|
||||||
bitflags = "0.7"
|
bitflags = "0.7"
|
||||||
canvas = {path = "../canvas"}
|
|
||||||
canvas_traits = {path = "../canvas_traits"}
|
canvas_traits = {path = "../canvas_traits"}
|
||||||
caseless = "0.1.0"
|
caseless = "0.1.0"
|
||||||
cssparser = {version = "0.5.4", features = ["heap_size", "serde-serialization"]}
|
cssparser = {version = "0.5.4", features = ["heap_size", "serde-serialization"]}
|
||||||
|
|
|
@ -2,7 +2,6 @@
|
||||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
use canvas::canvas_paint_thread::RectToi32;
|
|
||||||
use canvas_traits::{Canvas2dMsg, CanvasCommonMsg, CanvasMsg};
|
use canvas_traits::{Canvas2dMsg, CanvasCommonMsg, CanvasMsg};
|
||||||
use canvas_traits::{CompositionOrBlending, LineCapStyle, LineJoinStyle};
|
use canvas_traits::{CompositionOrBlending, LineCapStyle, LineJoinStyle};
|
||||||
use canvas_traits::{FillOrStrokeStyle, FillRule, LinearGradientStyle, RadialGradientStyle, RepetitionStyle};
|
use canvas_traits::{FillOrStrokeStyle, FillRule, LinearGradientStyle, RadialGradientStyle, RepetitionStyle};
|
||||||
|
@ -363,36 +362,30 @@ impl CanvasRenderingContext2D {
|
||||||
|
|
||||||
let smoothing_enabled = self.state.borrow().image_smoothing_enabled;
|
let smoothing_enabled = self.state.borrow().image_smoothing_enabled;
|
||||||
|
|
||||||
// If the source and target canvas are the same
|
if &*self.canvas == canvas {
|
||||||
let msg = if &*self.canvas == canvas {
|
let msg = CanvasMsg::Canvas2d(Canvas2dMsg::DrawImageSelf(
|
||||||
CanvasMsg::Canvas2d(Canvas2dMsg::DrawImageSelf(image_size,
|
image_size, dest_rect, source_rect, smoothing_enabled));
|
||||||
dest_rect,
|
self.ipc_renderer.send(msg).unwrap();
|
||||||
source_rect,
|
|
||||||
smoothing_enabled))
|
|
||||||
} else {
|
} else {
|
||||||
// Source and target canvases are different
|
|
||||||
let context = match canvas.get_or_init_2d_context() {
|
let context = match canvas.get_or_init_2d_context() {
|
||||||
Some(context) => context,
|
Some(context) => context,
|
||||||
None => return Err(Error::InvalidState),
|
None => return Err(Error::InvalidState),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let (sender, receiver) = ipc::channel().unwrap();
|
||||||
|
let msg = CanvasMsg::Canvas2d(Canvas2dMsg::DrawImageInOther(
|
||||||
|
self.ipc_renderer.clone(),
|
||||||
|
image_size,
|
||||||
|
dest_rect,
|
||||||
|
source_rect,
|
||||||
|
smoothing_enabled,
|
||||||
|
sender));
|
||||||
|
|
||||||
let renderer = context.get_ipc_renderer();
|
let renderer = context.get_ipc_renderer();
|
||||||
let (sender, receiver) = ipc::channel::<Vec<u8>>().unwrap();
|
renderer.send(msg).unwrap();
|
||||||
// Reads pixels from source image
|
receiver.recv().unwrap();
|
||||||
renderer.send(CanvasMsg::Canvas2d(Canvas2dMsg::GetImageData(source_rect.to_i32(),
|
|
||||||
image_size,
|
|
||||||
sender)))
|
|
||||||
.unwrap();
|
|
||||||
let imagedata = receiver.recv().unwrap();
|
|
||||||
// Writes pixels to destination canvas
|
|
||||||
CanvasMsg::Canvas2d(Canvas2dMsg::DrawImage(imagedata,
|
|
||||||
source_rect.size,
|
|
||||||
dest_rect,
|
|
||||||
source_rect,
|
|
||||||
smoothing_enabled))
|
|
||||||
};
|
};
|
||||||
|
|
||||||
self.ipc_renderer.send(msg).unwrap();
|
|
||||||
self.mark_as_dirty();
|
self.mark_as_dirty();
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,7 +34,6 @@ extern crate app_units;
|
||||||
#[allow(unused_extern_crates)]
|
#[allow(unused_extern_crates)]
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate bitflags;
|
extern crate bitflags;
|
||||||
extern crate canvas;
|
|
||||||
extern crate canvas_traits;
|
extern crate canvas_traits;
|
||||||
extern crate caseless;
|
extern crate caseless;
|
||||||
extern crate core;
|
extern crate core;
|
||||||
|
|
1
components/servo/Cargo.lock
generated
1
components/servo/Cargo.lock
generated
|
@ -1874,7 +1874,6 @@ dependencies = [
|
||||||
"angle 0.1.0 (git+https://github.com/servo/angle?branch=servo)",
|
"angle 0.1.0 (git+https://github.com/servo/angle?branch=servo)",
|
||||||
"app_units 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)",
|
"app_units 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"bitflags 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
"bitflags 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"canvas 0.0.1",
|
|
||||||
"canvas_traits 0.0.1",
|
"canvas_traits 0.0.1",
|
||||||
"caseless 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
"caseless 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"cssparser 0.5.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
"cssparser 0.5.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
|
1
ports/cef/Cargo.lock
generated
1
ports/cef/Cargo.lock
generated
|
@ -1732,7 +1732,6 @@ dependencies = [
|
||||||
"angle 0.1.0 (git+https://github.com/servo/angle?branch=servo)",
|
"angle 0.1.0 (git+https://github.com/servo/angle?branch=servo)",
|
||||||
"app_units 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)",
|
"app_units 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"bitflags 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
"bitflags 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"canvas 0.0.1",
|
|
||||||
"canvas_traits 0.0.1",
|
"canvas_traits 0.0.1",
|
||||||
"caseless 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
"caseless 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"cssparser 0.5.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
"cssparser 0.5.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue