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

Separate out windowing from compositing

  • Loading branch information
pcwalton committed May 9, 2013
commit 7e933b74641f48b6fd531e58f36519821406cd54
@@ -0,0 +1,92 @@
/* 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/. */

//! A windowing implementation using GLUT.
///
/// 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 geom::size::Size2D;
use glut::glut::{DOUBLE, WindowHeight, WindowWidth};
use glut::glut;

/// A structure responsible for setting up and tearing down the entire windowing system.
pub struct Application;

impl Application {
pub fn new() -> Application {
glut::init();
glut::init_display_mode(DOUBLE);
Application
}
}

/// The type of a window.
pub struct Window {
glut_window: glut::Window,
composite_callback: Option<CompositeCallback>,
resize_callback: Option<ResizeCallback>,
}

impl Window {
/// Creates a new window.
pub fn new(_: &Application) -> @mut Window {
// Create the GLUT window.
let glut_window = glut::create_window(~"Servo");
glut::reshape_window(glut_window, 800, 600);

// Create our window object.
let window = @mut Window {
glut_window: glut_window,
composite_callback: None,
resize_callback: None,
};

// Register event handlers.
do glut::reshape_func(window.glut_window) |width, height| {
match window.resize_callback {
None => {}
Some(callback) => callback(width as uint, height as uint),
}
};
do glut::display_func {
// FIXME(pcwalton): This will not work with multiple windows.
match window.composite_callback {
None => {}
Some(callback) => callback(),
}
};

window
}

/// Returns the size of the window.
pub fn size(&mut self) -> Size2D<f32> {

This comment has been minimized.

Copy link
@metajack

metajack May 9, 2013

Contributor

Why does this take &mut self?

Size2D(glut::get(WindowWidth) as f32, glut::get(WindowHeight) as f32)
}

/// Presents the window to the screen (perhaps by page flipping).
pub fn present(&mut self) {
glut::swap_buffers();
glut::post_redisplay();
}

/// Registers a callback to run when a composite event occurs.
pub fn set_composite_callback(&mut self, new_composite_callback: CompositeCallback) {
self.composite_callback = Some(new_composite_callback)
}

/// Registers a callback to run when a resize event occurs.
pub fn set_resize_callback(&mut self, new_resize_callback: ResizeCallback) {
self.resize_callback = Some(new_resize_callback)
}

/// Spins the event loop.
pub fn check_loop(@mut self) {
glut::check_loop()
}
}

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

//! A windowing implementation using shared OpenGL textures.
///
/// In this setup, Servo renders to an OpenGL texture and uses IPC to share that texture with
/// another application. It also uses IPC to handle events.
///
/// This is designed for sandboxing scenarios which the OpenGL graphics driver is either sandboxed
/// 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 geom::size::Size2D;
use sharegl::base::ShareContext;
use sharegl::platform::Context;

/// A structure responsible for setting up and tearing down the entire windowing system.
pub struct Application;

impl Application {
pub fn new() -> Application {
Application
}
}

/// The type of a window.
pub struct Window(Context);

impl Window {
/// Creates a new window.
pub fn new(_: &Application) -> @mut Window {
let share_context: Context = ShareContext::new(Size2D(800, 600));
println(fmt!("Sharing ID is %d", share_context.id()));
@mut Window(share_context)
}

/// Returns the size of the window.
pub fn size(&mut self) -> Size2D<f32> {
Size2D(800.0, 600.0)
}

/// Presents the window to the screen (perhaps by page flipping).
pub fn present(&mut self) {
(*self).flush();
}

/// Registers a callback to run when a composite event occurs.
pub fn set_composite_callback(&mut self, _: CompositeCallback) {}

/// Registers a callback to run when a resize event occurs.
pub fn set_resize_callback(&mut self, _: ResizeCallback) {}

/// Returns the next event.
pub fn check_loop(@mut self) {}
}

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

//! Platform-specific functionality for Servo.

#[cfg(not(shared_gl_windowing))]
pub use platform::common::glut_windowing::{Application, Window};
#[cfg(shared_gl_windowing)]
pub use platform::common::shared_gl_windowing::{Application, Window};

pub mod common {
#[cfg(not(shared_gl_windowing))]
pub mod glut_windowing;
#[cfg(shared_gl_windowing)]
pub mod shared_gl_windowing;
}

@@ -115,6 +115,9 @@ pub mod html {
pub mod hubbub_html_parser;
}

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

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

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