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
+515
−489
Merged
Refactor compositor #431
Changes from 1 commit
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
fdde75e
Rename "osmain" to "compositing"
pcwalton 7e933b7
Separate out windowing from compositing
pcwalton 0a6b537
servo: Remove the type parameter from the compositor, rename OSMain, …
pcwalton 7267f80
servo: Warning police.
pcwalton 932070b
Split the network stuff out of servo-gfx into servo-net
pcwalton 7c40535
Add missing compositing/mod.rs
pcwalton 4eb305e
servo: Address review comments
pcwalton File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.
Separate out windowing from compositing
- Loading branch information
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> { | ||
|
||
| 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; | ||
| } | ||
|
|
ProTip!
Use n and p to navigate between commits in a pull request.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Why does this take
&mut self?