mirror of
https://github.com/servo/servo.git
synced 2025-06-17 04:44:28 +00:00
Canvas: implement global composition and blending.
This commit is contained in:
parent
8efd70b01b
commit
a8343a0750
31 changed files with 221 additions and 127 deletions
|
@ -35,7 +35,7 @@ use dom::bindings::utils::{Reflectable, Reflector, WindowProxyHandler};
|
|||
use script_task::ScriptChan;
|
||||
|
||||
use canvas::canvas_paint_task::{CanvasGradientStop, LinearGradientStyle, RadialGradientStyle};
|
||||
use canvas::canvas_paint_task::{LineCapStyle, LineJoinStyle};
|
||||
use canvas::canvas_paint_task::{LineCapStyle, LineJoinStyle, CompositionOrBlending};
|
||||
use cssparser::RGBA;
|
||||
use encoding::types::EncodingRef;
|
||||
use geom::matrix2d::Matrix2D;
|
||||
|
@ -270,7 +270,7 @@ no_jsmanaged_fields!(RGBA);
|
|||
no_jsmanaged_fields!(Matrix2D<T>);
|
||||
no_jsmanaged_fields!(StorageType);
|
||||
no_jsmanaged_fields!(CanvasGradientStop, LinearGradientStyle, RadialGradientStyle);
|
||||
no_jsmanaged_fields!(LineCapStyle, LineJoinStyle);
|
||||
no_jsmanaged_fields!(LineCapStyle, LineJoinStyle, CompositionOrBlending);
|
||||
|
||||
impl JSTraceable for Box<ScriptChan+Send> {
|
||||
#[inline]
|
||||
|
|
|
@ -30,7 +30,7 @@ use geom::size::Size2D;
|
|||
use canvas::canvas_msg::{CanvasMsg, Canvas2dMsg, CanvasCommonMsg};
|
||||
use canvas::canvas_paint_task::{CanvasPaintTask, FillOrStrokeStyle};
|
||||
use canvas::canvas_paint_task::{LinearGradientStyle, RadialGradientStyle};
|
||||
use canvas::canvas_paint_task::{LineCapStyle, LineJoinStyle};
|
||||
use canvas::canvas_paint_task::{LineCapStyle, LineJoinStyle, CompositionOrBlending};
|
||||
|
||||
use net_traits::image::base::Image;
|
||||
use net_traits::image_cache_task::{ImageResponseMsg, Msg};
|
||||
|
@ -61,6 +61,7 @@ pub struct CanvasRenderingContext2D {
|
|||
#[jstraceable]
|
||||
struct CanvasContextState {
|
||||
global_alpha: f64,
|
||||
global_composition: CompositionOrBlending,
|
||||
image_smoothing_enabled: bool,
|
||||
stroke_color: RGBA,
|
||||
line_width: f64,
|
||||
|
@ -81,6 +82,7 @@ impl CanvasContextState {
|
|||
};
|
||||
CanvasContextState {
|
||||
global_alpha: 1.0,
|
||||
global_composition: CompositionOrBlending::default(),
|
||||
image_smoothing_enabled: true,
|
||||
stroke_color: black,
|
||||
line_width: 1.0,
|
||||
|
@ -421,6 +423,23 @@ impl<'a> CanvasRenderingContext2DMethods for JSRef<'a, CanvasRenderingContext2D>
|
|||
self.renderer.send(CanvasMsg::Canvas2d(Canvas2dMsg::SetGlobalAlpha(alpha as f32))).unwrap()
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/#dom-context-2d-globalcompositeoperation
|
||||
fn GlobalCompositeOperation(self) -> DOMString {
|
||||
let state = self.state.borrow();
|
||||
match state.global_composition {
|
||||
CompositionOrBlending::Composition(op) => op.to_str().to_owned(),
|
||||
CompositionOrBlending::Blending(op) => op.to_str().to_owned(),
|
||||
}
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/#dom-context-2d-globalcompositeoperation
|
||||
fn SetGlobalCompositeOperation(self, op_str: DOMString) {
|
||||
if let Some(op) = CompositionOrBlending::from_str(&op_str) {
|
||||
self.state.borrow_mut().global_composition = op;
|
||||
self.renderer.send(CanvasMsg::Canvas2d(Canvas2dMsg::SetGlobalComposition(op))).unwrap()
|
||||
}
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/#dom-context-2d-fillrect
|
||||
fn FillRect(self, x: f64, y: f64, width: f64, height: f64) {
|
||||
if let Some(rect) = self.create_drawable_rect(x, y, width, height) {
|
||||
|
|
|
@ -50,7 +50,7 @@ interface CanvasRenderingContext2D {
|
|||
|
||||
// compositing
|
||||
attribute unrestricted double globalAlpha; // (default 1.0)
|
||||
// attribute DOMString globalCompositeOperation; // (default source-over)
|
||||
attribute DOMString globalCompositeOperation; // (default source-over)
|
||||
|
||||
// image smoothing
|
||||
attribute boolean imageSmoothingEnabled; // (default true)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue