Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor compositor #431

Merged
merged 7 commits into from May 9, 2013
Prev

servo: Address review comments

  • Loading branch information
pcwalton committed May 9, 2013
commit 4eb305e56815a4277c30b8910f3ef31b96294715
@@ -5,6 +5,7 @@
use compositing::resize_rate_limiter::ResizeRateLimiter;
use dom::event::Event;
use platform::{Application, Window};
use windowing::{ApplicationMethods, WindowMethods};

use azure::azure_hl::{BackendType, B8G8R8A8, DataSourceSurface, DrawTarget, SourceSurfaceMethods};
use core::cell::Cell;
@@ -21,12 +22,6 @@ use servo_util::time;

mod resize_rate_limiter;

/// Type of the function that is called when the screen is to be redisplayed.
pub type CompositeCallback = @fn();

/// Type of the function that is called when the window is resized.
pub type ResizeCallback = @fn(uint, uint);

/// The implementation of the layers-based compositor.
#[deriving(Clone)]
pub struct CompositorImpl {
@@ -84,8 +79,8 @@ impl layers::layers::ImageData for AzureDrawTargetImageData {
fn mainloop(po: Port<Msg>, dom_event_chan: SharedChan<Event>, opts: &Opts) {
let key_handlers: @mut ~[Chan<()>] = @mut ~[];

let app = Application::new();
let window = Window::new(&app);
let app: Application = ApplicationMethods::new();
let window: @mut Window = WindowMethods::new(&app);

let surfaces = @mut SurfaceSet(opts.render_backend);

@@ -7,7 +7,7 @@
/// GLUT is a very old and bare-bones toolkit. However, it has good cross-platform support, at
/// least on desktops. It is designed for testing Servo without the need of a UI.

use compositing::{CompositeCallback, ResizeCallback};
use windowing::{ApplicationMethods, CompositeCallback, ResizeCallback, WindowMethods};

use geom::size::Size2D;
use glut::glut::{DOUBLE, WindowHeight, WindowWidth};
@@ -16,7 +16,7 @@ use glut::glut;
/// A structure responsible for setting up and tearing down the entire windowing system.
pub struct Application;

impl Application {
impl ApplicationMethods for Application {
pub fn new() -> Application {
glut::init();
glut::init_display_mode(DOUBLE);
@@ -31,7 +31,7 @@ pub struct Window {
resize_callback: Option<ResizeCallback>,
}

impl Window {
impl WindowMethods<Application> for Window {
/// Creates a new window.
pub fn new(_: &Application) -> @mut Window {
// Create the GLUT window.
@@ -64,7 +64,7 @@ impl Window {
}

/// Returns the size of the window.
pub fn size(&mut self) -> Size2D<f32> {
pub fn size(&self) -> Size2D<f32> {
Size2D(glut::get(WindowWidth) as f32, glut::get(WindowHeight) as f32)
}

@@ -11,7 +11,7 @@
/// along with the Servo process or trusted. If the OpenGL driver itself is untrusted, then this
/// windowing implementation is not appropriate.

use compositing::{CompositeCallback, ResizeCallback};
use windowing::{CompositeCallback, ResizeCallback};

use geom::size::Size2D;
use sharegl::base::ShareContext;
@@ -20,7 +20,7 @@ use sharegl::platform::Context;
/// A structure responsible for setting up and tearing down the entire windowing system.
pub struct Application;

impl Application {
impl ApplicationMethods for Application {
pub fn new() -> Application {
Application
}
@@ -29,7 +29,7 @@ impl Application {
/// The type of a window.
pub struct Window(Context);

impl Window {
impl WindowingMethods<Application> for Window {
/// Creates a new window.
pub fn new(_: &Application) -> @mut Window {
let share_context: Context = ShareContext::new(Size2D(800, 600));
@@ -116,6 +116,8 @@ pub mod html {
pub mod hubbub_html_parser;
}

pub mod windowing;

#[path="platform/mod.rs"]
pub mod platform;

@@ -0,0 +1,34 @@
/* 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/. */

//! Abstract windowing methods. The concrete implementations of these can be found in `platform/`.

use geom::size::Size2D;

/// Type of the function that is called when the screen is to be redisplayed.
pub type CompositeCallback = @fn();

/// Type of the function that is called when the window is resized.
pub type ResizeCallback = @fn(uint, uint);

/// Methods for an abstract Application.
pub trait ApplicationMethods {
fn new() -> Self;
}

pub trait WindowMethods<A> {
/// Creates a new window.
pub fn new(app: &A) -> @mut Self;
/// Returns the size of the window.
pub fn size(&self) -> Size2D<f32>;
/// Presents the window to the screen (perhaps by page flipping).
pub fn present(&mut self);
/// Registers a callback to run when a composite event occurs.
pub fn set_composite_callback(&mut self, new_composite_callback: CompositeCallback);
/// Registers a callback to run when a resize event occurs.
pub fn set_resize_callback(&mut self, new_resize_callback: ResizeCallback);
/// Spins the event loop.
pub fn check_loop(@mut self);
}

ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.