mirror of
https://github.com/servo/servo.git
synced 2025-06-19 22:59:03 +01:00
refactor compositor interfaces \--> RenderListener + ScriptListener; AttachCompositorMsg added to render_task::Msg
updated to reflect comments
This commit is contained in:
parent
496069dad4
commit
577a410f80
11 changed files with 38 additions and 31 deletions
|
@ -32,7 +32,7 @@ pub enum RenderState {
|
||||||
RenderingRenderState,
|
RenderingRenderState,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The interface used to by the renderer to acquire draw targets for each rendered frame and
|
/// The interface used by the renderer to acquire draw targets for each rendered frame and
|
||||||
/// submit them to be drawn to the display.
|
/// submit them to be drawn to the display.
|
||||||
pub trait RenderListener {
|
pub trait RenderListener {
|
||||||
fn get_gl_context(&self) -> AzGLContext;
|
fn get_gl_context(&self) -> AzGLContext;
|
||||||
|
|
|
@ -22,28 +22,36 @@ use servo_net::util::spawn_listener;
|
||||||
use servo_util::time::{ProfilerChan, profile};
|
use servo_util::time::{ProfilerChan, profile};
|
||||||
use servo_util::time;
|
use servo_util::time;
|
||||||
|
|
||||||
pub enum Msg {
|
pub enum Msg<C> {
|
||||||
|
AttachCompositorMsg(C),
|
||||||
RenderMsg(RenderLayer),
|
RenderMsg(RenderLayer),
|
||||||
ExitMsg(Chan<()>),
|
ExitMsg(Chan<()>),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[deriving(Clone)]
|
pub struct RenderChan<C> {
|
||||||
pub struct RenderChan {
|
chan: SharedChan<Msg<C>>,
|
||||||
chan: SharedChan<Msg>,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl RenderChan {
|
impl<C: RenderListener + Owned> Clone for RenderChan<C> {
|
||||||
pub fn new(chan: Chan<Msg>) -> RenderChan {
|
pub fn clone(&self) -> RenderChan<C> {
|
||||||
|
RenderChan {
|
||||||
|
chan: self.chan.clone(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<C: RenderListener + Owned> RenderChan<C> {
|
||||||
|
pub fn new(chan: Chan<Msg<C>>) -> RenderChan<C> {
|
||||||
RenderChan {
|
RenderChan {
|
||||||
chan: SharedChan::new(chan),
|
chan: SharedChan::new(chan),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pub fn send(&self, msg: Msg) {
|
pub fn send(&self, msg: Msg<C>) {
|
||||||
self.chan.send(msg);
|
self.chan.send(msg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn create_render_task<C: RenderListener + Owned>(port: Port<Msg>,
|
pub fn create_render_task<C: RenderListener + Owned>(port: Port<Msg<C>>,
|
||||||
compositor: C,
|
compositor: C,
|
||||||
opts: Opts,
|
opts: Opts,
|
||||||
profiler_chan: ProfilerChan) {
|
profiler_chan: ProfilerChan) {
|
||||||
|
@ -103,7 +111,7 @@ priv struct ThreadRenderContext {
|
||||||
}
|
}
|
||||||
|
|
||||||
priv struct Renderer<C> {
|
priv struct Renderer<C> {
|
||||||
port: Port<Msg>,
|
port: Port<Msg<C>>,
|
||||||
compositor: C,
|
compositor: C,
|
||||||
thread_pool: TaskPool<ThreadRenderContext>,
|
thread_pool: TaskPool<ThreadRenderContext>,
|
||||||
opts: Opts,
|
opts: Opts,
|
||||||
|
@ -120,6 +128,7 @@ impl<C: RenderListener + Owned> Renderer<C> {
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
match self.port.recv() {
|
match self.port.recv() {
|
||||||
|
AttachCompositorMsg(compositor) => self.compositor = compositor,
|
||||||
RenderMsg(render_layer) => self.render(render_layer),
|
RenderMsg(render_layer) => self.render(render_layer),
|
||||||
ExitMsg(response_ch) => {
|
ExitMsg(response_ch) => {
|
||||||
response_ch.send(());
|
response_ch.send(());
|
||||||
|
|
|
@ -132,7 +132,7 @@ impl CompositorTask {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Starts the compositor, which listens for messages on the specified port.
|
/// Starts the compositor, which listens for messages on the specified port.
|
||||||
pub fn create_compositor_task(port: Port<Msg>,
|
pub fn create(port: Port<Msg>,
|
||||||
profiler_chan: ProfilerChan,
|
profiler_chan: ProfilerChan,
|
||||||
shutdown_chan: Chan<()>) {
|
shutdown_chan: Chan<()>) {
|
||||||
let port = Cell(port);
|
let port = Cell(port);
|
||||||
|
|
|
@ -24,7 +24,7 @@ use servo_util::time::{ProfilerChan};
|
||||||
pub struct Engine {
|
pub struct Engine {
|
||||||
request_port: Port<Msg>,
|
request_port: Port<Msg>,
|
||||||
compositor_chan: CompositorChan,
|
compositor_chan: CompositorChan,
|
||||||
render_chan: RenderChan,
|
render_chan: RenderChan<CompositorChan>,
|
||||||
resource_task: ResourceTask,
|
resource_task: ResourceTask,
|
||||||
image_cache_task: ImageCacheTask,
|
image_cache_task: ImageCacheTask,
|
||||||
layout_chan: LayoutChan,
|
layout_chan: LayoutChan,
|
||||||
|
@ -32,12 +32,6 @@ pub struct Engine {
|
||||||
profiler_chan: ProfilerChan,
|
profiler_chan: ProfilerChan,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Drop for Engine {
|
|
||||||
fn finalize(&self) {
|
|
||||||
//self.profiler_chan.send(ForcePrintMsg);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Engine {
|
impl Engine {
|
||||||
pub fn start(compositor_chan: CompositorChan,
|
pub fn start(compositor_chan: CompositorChan,
|
||||||
opts: &Opts,
|
opts: &Opts,
|
||||||
|
@ -63,7 +57,9 @@ impl Engine {
|
||||||
// Create the layout port and channel.
|
// Create the layout port and channel.
|
||||||
let (layout_port, layout_chan) = closure_stream!(layout_interface::Msg, LayoutChan);
|
let (layout_port, layout_chan) = closure_stream!(layout_interface::Msg, LayoutChan);
|
||||||
|
|
||||||
let (render_port, render_chan) = closure_stream!(render_task::Msg, RenderChan);
|
let (render_port, render_chan) = comm::stream::<render_task::Msg<CompositorChan>>();
|
||||||
|
let (render_port, render_chan) = (Cell(render_port), RenderChan::new(render_chan));
|
||||||
|
|
||||||
|
|
||||||
compositor_chan.send(SetLayoutChan(layout_chan.clone()));
|
compositor_chan.send(SetLayoutChan(layout_chan.clone()));
|
||||||
let compositor_chan = Cell(compositor_chan);
|
let compositor_chan = Cell(compositor_chan);
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
//! The layout task. Performs layout on the DOM, builds display lists and sends them to be
|
//! The layout task. Performs layout on the DOM, builds display lists and sends them to be
|
||||||
/// rendered.
|
/// rendered.
|
||||||
|
|
||||||
|
use compositing::CompositorChan;
|
||||||
use css::matching::MatchMethods;
|
use css::matching::MatchMethods;
|
||||||
use css::select::new_css_select_ctx;
|
use css::select::new_css_select_ctx;
|
||||||
use layout::aux::{LayoutData, LayoutAuxMethods};
|
use layout::aux::{LayoutData, LayoutAuxMethods};
|
||||||
|
@ -47,7 +48,7 @@ use std::net::url::Url;
|
||||||
|
|
||||||
pub fn create_layout_task(port: Port<Msg>,
|
pub fn create_layout_task(port: Port<Msg>,
|
||||||
script_chan: ScriptChan,
|
script_chan: ScriptChan,
|
||||||
render_chan: RenderChan,
|
render_chan: RenderChan<CompositorChan>,
|
||||||
img_cache_task: ImageCacheTask,
|
img_cache_task: ImageCacheTask,
|
||||||
opts: Opts,
|
opts: Opts,
|
||||||
profiler_chan: ProfilerChan) {
|
profiler_chan: ProfilerChan) {
|
||||||
|
@ -66,7 +67,7 @@ pub fn create_layout_task(port: Port<Msg>,
|
||||||
struct Layout {
|
struct Layout {
|
||||||
port: Port<Msg>,
|
port: Port<Msg>,
|
||||||
script_chan: ScriptChan,
|
script_chan: ScriptChan,
|
||||||
render_chan: RenderChan,
|
render_chan: RenderChan<CompositorChan>,
|
||||||
image_cache_task: ImageCacheTask,
|
image_cache_task: ImageCacheTask,
|
||||||
local_image_cache: @mut LocalImageCache,
|
local_image_cache: @mut LocalImageCache,
|
||||||
font_ctx: @mut FontContext,
|
font_ctx: @mut FontContext,
|
||||||
|
@ -83,7 +84,7 @@ struct Layout {
|
||||||
impl Layout {
|
impl Layout {
|
||||||
fn new(port: Port<Msg>,
|
fn new(port: Port<Msg>,
|
||||||
script_chan: ScriptChan,
|
script_chan: ScriptChan,
|
||||||
render_chan: RenderChan,
|
render_chan: RenderChan<CompositorChan>,
|
||||||
image_cache_task: ImageCacheTask,
|
image_cache_task: ImageCacheTask,
|
||||||
opts: &Opts,
|
opts: &Opts,
|
||||||
profiler_chan: ProfilerChan)
|
profiler_chan: ProfilerChan)
|
||||||
|
|
|
@ -12,7 +12,6 @@ use windowing::{ResizeCallback, ScrollCallback, WindowMethods, WindowMouseEvent,
|
||||||
use windowing::{WindowMouseDownEvent, WindowMouseUpEvent, ZoomCallback};
|
use windowing::{WindowMouseDownEvent, WindowMouseUpEvent, ZoomCallback};
|
||||||
|
|
||||||
use alert::{Alert, AlertMethods};
|
use alert::{Alert, AlertMethods};
|
||||||
use core::cell::Cell;
|
|
||||||
use core::libc::c_int;
|
use core::libc::c_int;
|
||||||
use geom::point::Point2D;
|
use geom::point::Point2D;
|
||||||
use geom::size::Size2D;
|
use geom::size::Size2D;
|
||||||
|
|
|
@ -93,7 +93,7 @@ fn run(opts: &Opts) {
|
||||||
// Create the profiler channel.
|
// Create the profiler channel.
|
||||||
let (profiler_port, profiler_chan) = comm::stream();
|
let (profiler_port, profiler_chan) = comm::stream();
|
||||||
let profiler_chan = ProfilerChan::new(profiler_chan);
|
let profiler_chan = ProfilerChan::new(profiler_chan);
|
||||||
Profiler::create_profiler(profiler_port);
|
Profiler::create(profiler_port);
|
||||||
do opts.profiler_period.map |period| {
|
do opts.profiler_period.map |period| {
|
||||||
let profiler_chan = profiler_chan.clone();
|
let profiler_chan = profiler_chan.clone();
|
||||||
let period = *period;
|
let period = *period;
|
||||||
|
@ -109,7 +109,7 @@ fn run(opts: &Opts) {
|
||||||
// Create the compositor.
|
// Create the compositor.
|
||||||
let (compositor_port, compositor_chan) = comm::stream();
|
let (compositor_port, compositor_chan) = comm::stream();
|
||||||
let compositor_chan = CompositorChan::new(compositor_chan);
|
let compositor_chan = CompositorChan::new(compositor_chan);
|
||||||
CompositorTask::create_compositor_task(compositor_port, profiler_chan.clone(), shutdown_chan);
|
CompositorTask::create(compositor_port, profiler_chan.clone(), shutdown_chan);
|
||||||
|
|
||||||
// Create a Servo instance.
|
// Create a Servo instance.
|
||||||
|
|
||||||
|
|
|
@ -14,6 +14,8 @@ pub enum ReadyState {
|
||||||
FinishedLoading,
|
FinishedLoading,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// The interface used by the script task to tell the compositor to update its ready state,
|
||||||
|
/// which is used in displaying the appropriate message in the window's title.
|
||||||
pub trait ScriptListener : Clone {
|
pub trait ScriptListener : Clone {
|
||||||
fn set_ready_state(&self, ReadyState);
|
fn set_ready_state(&self, ReadyState);
|
||||||
}
|
}
|
||||||
|
|
|
@ -110,7 +110,7 @@ impl ProfilerCategory {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Profiler {
|
impl Profiler {
|
||||||
pub fn create_profiler(port: Port<ProfilerMsg>) {
|
pub fn create(port: Port<ProfilerMsg>) {
|
||||||
let port = Cell(port);
|
let port = Cell(port);
|
||||||
do spawn {
|
do spawn {
|
||||||
let mut profiler = Profiler::new(port.take());
|
let mut profiler = Profiler::new(port.take());
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
Subproject commit 09d2db847c11bcab7f1832d5daf5947a7c1384ee
|
Subproject commit 865f539114383a021822583801e8362faf916699
|
|
@ -1 +1 @@
|
||||||
Subproject commit 6f6b6fa95914fa6322f3277c803fd4921601cb90
|
Subproject commit 453bf81e021008f5eba29b135f07f4529e6c8b2e
|
Loading…
Add table
Add a link
Reference in a new issue