Layerize canvas

Note that this keeps using readback right now, `NativeSurface` painting
will be implemented soon.

Also see https://github.com/servo/servo/issues/6142
This commit is contained in:
ecoal95 2015-05-20 10:29:08 +02:00
parent 6481058309
commit 3350522306
35 changed files with 769 additions and 500 deletions

View file

@ -11,9 +11,15 @@ path = "lib.rs"
[dependencies.plugins]
path = "../plugins"
[dependencies.gfx_traits]
path = "../gfx_traits"
[dependencies.net_traits]
path = "../net_traits"
[dependencies.canvas_traits]
path = "../canvas_traits"
[dependencies.util]
path = "../util"

View file

@ -1,41 +0,0 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* 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/. */
use azure::AzFloat;
use azure::azure::AzColor;
#[inline]
pub fn new(r: AzFloat, g: AzFloat, b: AzFloat, a: AzFloat) -> AzColor {
AzColor { r: r, g: g, b: b, a: a }
}
#[inline]
pub fn rgb(r: u8, g: u8, b: u8) -> AzColor {
AzColor {
r: (r as AzFloat) / (255.0 as AzFloat),
g: (g as AzFloat) / (255.0 as AzFloat),
b: (b as AzFloat) / (255.0 as AzFloat),
a: 1.0 as AzFloat
}
}
#[inline]
pub fn rgba(r: AzFloat, g: AzFloat, b: AzFloat, a: AzFloat) -> AzColor {
AzColor { r: r, g: g, b: b, a: a }
}
#[inline]
pub fn black() -> AzColor {
AzColor { r: 0.0, g: 0.0, b: 0.0, a: 1.0 }
}
#[inline]
pub fn transparent() -> AzColor {
AzColor { r: 0.0, g: 0.0, b: 0.0, a: 0.0 }
}
#[inline]
pub fn white() -> AzColor {
AzColor { r: 1.0, g: 1.0, b: 1.0, a: 1.0 }
}

View file

@ -38,6 +38,9 @@ extern crate skia;
extern crate time;
extern crate url;
extern crate gfx_traits;
extern crate canvas_traits;
// Eventually we would like the shaper to be pluggable, as many operating systems have their own
// shapers. For now, however, this is a hard dependency.
extern crate harfbuzz;
@ -59,8 +62,6 @@ pub use paint_context::PaintContext;
// Private painting modules
mod paint_context;
// Painting
pub mod color;
#[path="display_list/mod.rs"]
pub mod display_list;
pub mod paint_task;

View file

@ -4,7 +4,7 @@
//! Painting of display lists using Moz2D/Azure.
use color;
use gfx_traits::color;
use display_list::TextOrientation::{SidewaysLeft, SidewaysRight, Upright};
use display_list::{BLUR_INFLATION_FACTOR, BorderRadii, BoxShadowClipMode, ClippingRegion};
use display_list::{TextDisplayItem};

View file

@ -20,6 +20,7 @@ use layers::platform::surface::{NativeGraphicsMetadata, NativePaintingGraphicsCo
use layers::platform::surface::NativeSurface;
use layers::layers::{BufferRequest, LayerBuffer, LayerBufferSet};
use layers;
use canvas_traits::CanvasMsg;
use msg::compositor_msg::{Epoch, FrameTreeId, LayerId};
use msg::compositor_msg::{LayerProperties, PaintListener, ScrollPolicy};
use msg::constellation_msg::Msg as ConstellationMsg;
@ -30,8 +31,9 @@ use rand::{self, Rng};
use skia::SkiaGrGLNativeContextRef;
use std::borrow::ToOwned;
use std::mem;
use std::sync::Arc;
use std::sync::{Arc, Mutex};
use std::sync::mpsc::{Receiver, Sender, channel};
use std::collections::HashMap;
use util::geometry::{Au, ZERO_POINT};
use util::opts;
use util::task::spawn_named_with_send_on_failure;
@ -69,6 +71,7 @@ pub struct PaintRequest {
pub enum Msg {
PaintInit(Epoch, Arc<StackingContext>),
CanvasLayer(LayerId, Arc<Mutex<Sender<CanvasMsg>>>),
Paint(Vec<PaintRequest>, FrameTreeId),
UnusedBuffer(Vec<Box<LayerBuffer>>),
PaintPermissionGranted,
@ -125,6 +128,9 @@ pub struct PaintTask<C> {
/// Tracks the number of buffers that the compositor currently owns. The
/// PaintTask waits to exit until all buffers are returned.
used_buffer_count: usize,
/// A map to track the canvas specific layers
canvas_map: HashMap<LayerId, Arc<Mutex<Sender<CanvasMsg>>>>,
}
// If we implement this as a function, we get borrowck errors from borrowing
@ -170,6 +176,7 @@ impl<C> PaintTask<C> where C: PaintListener + Send + 'static {
buffer_map: BufferMap::new(10000000),
worker_threads: worker_threads,
used_buffer_count: 0,
canvas_map: HashMap::new()
};
paint_task.start();
@ -216,6 +223,11 @@ impl<C> PaintTask<C> where C: PaintListener + Send + 'static {
self.initialize_layers();
}
// Inserts a new canvas renderer to the layer map
Msg::CanvasLayer(layer_id, canvas_renderer) => {
debug!("Renderer received for canvas with layer {:?}", layer_id);
self.canvas_map.insert(layer_id, canvas_renderer);
}
Msg::Paint(requests, frame_tree_id) => {
if !self.paint_permission {
debug!("PaintTask: paint ready msg");