mirror of
https://github.com/servo/servo.git
synced 2025-08-12 00:45:33 +01:00
servo: Address review comments
This commit is contained in:
parent
7c40535dd8
commit
4eb305e568
5 changed files with 46 additions and 15 deletions
|
@ -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;
|
||||
|
||||
|
|
34
src/servo/windowing.rs
Normal file
34
src/servo/windowing.rs
Normal file
|
@ -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);
|
||||
}
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue