From f61c802a6a82a3462522c9e707412d5b17fab8f5 Mon Sep 17 00:00:00 2001 From: Matt Brubeck Date: Mon, 29 Sep 2014 14:22:02 -0700 Subject: [PATCH 01/11] Move windowing code out of the compositor This is mainly just moving code around, in preparation for further changes to the "windowing" API. --- Cargo.lock | 24 ++++---- Cargo.toml | 10 ++++ components/compositing/Cargo.toml | 8 --- components/compositing/compositor.rs | 30 ++++------ components/compositing/compositor_task.rs | 16 ++--- components/compositing/lib.rs | 9 +-- components/compositing/windowing.rs | 10 +--- ports/glfw/Cargo.toml | 30 ++++++++++ ports/glfw/lib.rs | 43 ++++++++++++++ .../glfw_windowing.rs => ports/glfw/window.rs | 58 +++++++------------ ports/glut/Cargo.toml | 29 ++++++++++ ports/glut/lib.rs | 41 +++++++++++++ .../glut_windowing.rs => ports/glut/window.rs | 47 ++++++--------- src/lib.rs | 25 ++++---- src/main.rs | 11 +++- support/glfw-rs | 2 +- 16 files changed, 250 insertions(+), 143 deletions(-) create mode 100644 ports/glfw/Cargo.toml create mode 100644 ports/glfw/lib.rs rename components/compositing/platform/common/glfw_windowing.rs => ports/glfw/window.rs (87%) create mode 100644 ports/glut/Cargo.toml create mode 100644 ports/glut/lib.rs rename components/compositing/platform/common/glut_windowing.rs => ports/glut/window.rs (90%) diff --git a/Cargo.lock b/Cargo.lock index 6e05b1e2a253..5c1fa0073427 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4,6 +4,7 @@ version = "0.0.1" dependencies = [ "compositing 0.0.1", "gfx 0.0.1", + "glfw-app 0.0.1", "layout 0.0.1", "msg 0.0.1", "net 0.0.1", @@ -64,8 +65,6 @@ dependencies = [ "devtools_traits 0.0.1", "geom 0.1.0 (git+https://github.com/servo/rust-geom#90add8d65273c8a46aa16d73959e29a51d0c282d)", "gfx 0.0.1", - "glfw 0.0.1 (git+https://github.com/servo/glfw-rs?ref=servo#7ccfaca315a43d97914e1601c90ad348ef190edf)", - "glut 0.0.1 (git+https://github.com/servo/rust-glut#01af0162ea0322ad1a40d6adb023a39813605949)", "layers 0.1.0 (git+https://github.com/servo/rust-layers#180d3ff2f28d239e32d01982c76be5c97d5763a8)", "layout_traits 0.0.1", "msg 0.0.1", @@ -202,18 +201,23 @@ dependencies = [ ] [[package]] -name = "glfw-sys" -version = "3.0.4" -source = "git+https://github.com/servo/glfw?ref=cargo-3.0.4#65a2b4721276589d9de24f6a9999a2db37286cae" - -[[package]] -name = "glut" +name = "glfw-app" version = "0.0.1" -source = "git+https://github.com/servo/rust-glut#01af0162ea0322ad1a40d6adb023a39813605949" dependencies = [ - "opengles 0.1.0 (git+https://github.com/servo/rust-opengles#6776e9c07feb149d34b087039ecf6b2c143e3afc)", + "alert 0.1.0 (git+https://github.com/servo/rust-alert#fdc24f13be8d8a2d15214ec228d166b3221b809e)", + "compositing 0.0.1", + "geom 0.1.0 (git+https://github.com/servo/rust-geom#90add8d65273c8a46aa16d73959e29a51d0c282d)", + "glfw 0.0.1 (git+https://github.com/servo/glfw-rs?ref=servo#7ccfaca315a43d97914e1601c90ad348ef190edf)", + "layers 0.1.0 (git+https://github.com/servo/rust-layers#9c2848823e24af586899947743704b1238f374c8)", + "msg 0.0.1", + "util 0.0.1", ] +[[package]] +name = "glfw-sys" +version = "3.0.4" +source = "git+https://github.com/servo/glfw?ref=cargo-3.0.4#65a2b4721276589d9de24f6a9999a2db37286cae" + [[package]] name = "harfbuzz" version = "0.1.0" diff --git a/Cargo.toml b/Cargo.toml index 2472f99be991..91a090c33959 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -24,6 +24,8 @@ name = "contenttest" path = "tests/contenttest.rs" harness = false +[features] +default = ["glfw-app"] [dependencies.compositing] path = "components/compositing" @@ -46,5 +48,13 @@ path = "components/layout" [dependencies.gfx] path = "components/gfx" +[dependencies.glfw-app] +path = "ports/glfw" +optional = true + +[dependencies.glut-app] +path = "ports/glut" +optional = true + [dependencies.url] git = "https://github.com/servo/rust-url" diff --git a/components/compositing/Cargo.toml b/components/compositing/Cargo.toml index e306ae8fd944..83a4bbee5cc5 100644 --- a/components/compositing/Cargo.toml +++ b/components/compositing/Cargo.toml @@ -40,10 +40,6 @@ git = "https://github.com/servo/rust-azure" [dependencies.geom] git = "https://github.com/servo/rust-geom" -[dependencies.glfw] -git = "https://github.com/servo/glfw-rs" -branch = "servo" - [dependencies.layers] git = "https://github.com/servo/rust-layers" @@ -61,7 +57,3 @@ git = "https://github.com/servo/rust-core-graphics" [dependencies.core_text] git = "https://github.com/servo/rust-core-text" - -[dependencies.glut] -git = "https://github.com/servo/rust-glut" - diff --git a/components/compositing/compositor.rs b/components/compositing/compositor.rs index b751ef1d2c66..5bf1afd39a17 100644 --- a/components/compositing/compositor.rs +++ b/components/compositing/compositor.rs @@ -11,7 +11,6 @@ use constellation::SendableFrameTree; use events; use events::ScrollPositionChanged; use pipeline::CompositionPipeline; -use platform::{Application, Window}; use windowing; use windowing::{FinishedWindowEvent, IdleWindowEvent, LoadUrlWindowEvent, MouseWindowClickEvent}; use windowing::{MouseWindowEvent, MouseWindowEventClass, MouseWindowMouseDownEvent}; @@ -54,7 +53,7 @@ use time::precise_time_s; use url::Url; -pub struct IOCompositor { +pub struct IOCompositor { /// The application window. window: Rc, @@ -136,22 +135,13 @@ enum ShutdownState { FinishedShuttingDown, } -impl IOCompositor { - fn new(app: &Application, - opts: Opts, - port: Receiver, - constellation_chan: ConstellationChan, - time_profiler_chan: TimeProfilerChan, - memory_profiler_chan: MemoryProfilerChan) -> IOCompositor { - - let scale_factor = match opts.device_pixels_per_px { - Some(device_pixels_per_px) => device_pixels_per_px, - None => ScaleFactor(1.0), - }; - let framebuffer_size = opts.initial_window_size.as_f32() * scale_factor; - - let window: Rc = WindowMethods::new(app, opts.output_file.is_none(), - framebuffer_size.as_uint()); +impl IOCompositor { + fn new(window: Rc, + opts: Opts, + port: Receiver, + constellation_chan: ConstellationChan, + time_profiler_chan: TimeProfilerChan, + memory_profiler_chan: MemoryProfilerChan) -> IOCompositor { // Create an initial layer tree. // @@ -192,13 +182,13 @@ impl IOCompositor { } } - pub fn create(app: &Application, + pub fn create(window: Rc, opts: Opts, port: Receiver, constellation_chan: ConstellationChan, time_profiler_chan: TimeProfilerChan, memory_profiler_chan: MemoryProfilerChan) { - let mut compositor = IOCompositor::new(app, + let mut compositor = IOCompositor::new(window, opts, port, constellation_chan, diff --git a/components/compositing/compositor_task.rs b/components/compositing/compositor_task.rs index 786c05f27da0..d0e16fc1b9fb 100644 --- a/components/compositing/compositor_task.rs +++ b/components/compositing/compositor_task.rs @@ -7,8 +7,7 @@ pub use windowing; use compositor; use headless; pub use constellation::SendableFrameTree; -use windowing::{ApplicationMethods, WindowMethods}; -use platform::Application; +use windowing::WindowMethods; use azure::azure_hl::{SourceSurfaceMethods, Color}; use geom::point::Point2D; @@ -23,6 +22,7 @@ use servo_util::memory::MemoryProfilerChan; use servo_util::opts::Opts; use servo_util::time::TimeProfilerChan; use std::comm::{channel, Sender, Receiver}; +use std::rc::Rc; use url::Url; @@ -184,7 +184,7 @@ pub enum Msg { } pub enum CompositorMode { - Windowed(Application), + Windowed, Headless } @@ -197,7 +197,7 @@ impl CompositorTask { let mode: CompositorMode = if is_headless { Headless } else { - Windowed(ApplicationMethods::new()) + Windowed }; CompositorTask { @@ -217,7 +217,9 @@ impl CompositorTask { NativeCompositingGraphicsContext::new() } - pub fn create(opts: Opts, + pub fn create( + window: Rc, + opts: Opts, port: Receiver, constellation_chan: ConstellationChan, time_profiler_chan: TimeProfilerChan, @@ -226,8 +228,8 @@ impl CompositorTask { let compositor = CompositorTask::new(opts.headless); match compositor.mode { - Windowed(ref app) => { - compositor::IOCompositor::create(app, + Windowed => { + compositor::IOCompositor::create(window, opts, port, constellation_chan.clone(), diff --git a/components/compositing/lib.rs b/components/compositing/lib.rs index 1b8131ec299c..44592caa61c9 100644 --- a/components/compositing/lib.rs +++ b/components/compositing/lib.rs @@ -19,10 +19,6 @@ extern crate azure; extern crate devtools_traits; extern crate geom; extern crate gfx; -#[cfg(not(target_os="android"))] -extern crate glfw; -#[cfg(target_os="android")] -extern crate glut; extern crate layers; extern crate layout_traits; extern crate opengles; @@ -56,7 +52,4 @@ mod headless; pub mod pipeline; pub mod constellation; -mod windowing; - -#[path="platform/mod.rs"] -pub mod platform; +pub mod windowing; diff --git a/components/compositing/windowing.rs b/components/compositing/windowing.rs index 6a90167628a1..5091ee50f152 100644 --- a/components/compositing/windowing.rs +++ b/components/compositing/windowing.rs @@ -10,7 +10,6 @@ use geom::size::TypedSize2D; use layers::geometry::DevicePixel; use servo_msg::compositor_msg::{ReadyState, RenderState}; use servo_util::geometry::ScreenPx; -use std::rc::Rc; pub enum MouseWindowEvent { MouseWindowClickEvent(uint, TypedPoint2D), @@ -54,14 +53,7 @@ pub enum WindowEvent { QuitWindowEvent, } -/// Methods for an abstract Application. -pub trait ApplicationMethods { - fn new() -> Self; -} - -pub trait WindowMethods { - /// Creates a new window. - fn new(app: &A, is_foreground: bool, size: TypedSize2D) -> Rc; +pub trait WindowMethods { /// Returns the size of the window in hardware pixels. fn framebuffer_size(&self) -> TypedSize2D; /// Returns the size of the window in density-independent "px" units. diff --git a/ports/glfw/Cargo.toml b/ports/glfw/Cargo.toml new file mode 100644 index 000000000000..253cf460d92c --- /dev/null +++ b/ports/glfw/Cargo.toml @@ -0,0 +1,30 @@ +[package] +name = "glfw-app" +version = "0.0.1" +authors = ["The Servo Project Developers"] + +[lib] +name = "glfwapp" +path = "lib.rs" + +[dependencies.alert] +git = "https://github.com/servo/rust-alert" + +[dependencies.compositing] +path = "../../components/compositing" + +[dependencies.geom] +git = "https://github.com/servo/rust-geom" + +[dependencies.glfw] +git = "https://github.com/servo/glfw-rs" +branch = "servo" + +[dependencies.layers] +git = "https://github.com/servo/rust-layers" + +[dependencies.msg] +path = "../../components/msg" + +[dependencies.util] +path = "../../components/util" diff --git a/ports/glfw/lib.rs b/ports/glfw/lib.rs new file mode 100644 index 000000000000..de3cecf24f6d --- /dev/null +++ b/ports/glfw/lib.rs @@ -0,0 +1,43 @@ +/* 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 simple application that uses GLFW to open a window for Servo to display in. + +#![license = "MPL"] +#![feature(macro_rules)] +#![deny(unused_imports, unused_variable)] + +extern crate alert; +extern crate compositing; +extern crate geom; +extern crate glfw; +extern crate layers; +extern crate libc; +extern crate msg; +extern crate time; +extern crate util; + +use geom::scale_factor::ScaleFactor; +use std::rc::Rc; +use window::Window; + +mod window; + +pub fn create_window(opts: &util::opts::Opts) -> Rc { + // Initialize GLFW. + let glfw = glfw::init(glfw::FAIL_ON_ERRORS).unwrap_or_else(|_| { + // handles things like inability to connect to X + // cannot simply fail, since the runtime isn't up yet (causes a nasty abort) + println!("GLFW initialization failed"); + unsafe { libc::exit(1); } + }); + + // Read command-line options. + let foreground = opts.output_file.is_none(); + let scale_factor = opts.device_pixels_per_px.unwrap_or(ScaleFactor(1.0)); + let size = opts.initial_window_size.as_f32() * scale_factor; + + // Open a window. + Window::new(glfw, foreground, size.as_uint()) +} diff --git a/components/compositing/platform/common/glfw_windowing.rs b/ports/glfw/window.rs similarity index 87% rename from components/compositing/platform/common/glfw_windowing.rs rename to ports/glfw/window.rs index dfe200bf8d88..50be31f05db8 100644 --- a/components/compositing/platform/common/glfw_windowing.rs +++ b/ports/glfw/window.rs @@ -4,15 +4,15 @@ //! A windowing implementation using GLFW. -use windowing::{ApplicationMethods, WindowEvent, WindowMethods}; -use windowing::{IdleWindowEvent, ResizeWindowEvent, LoadUrlWindowEvent, MouseWindowEventClass, MouseWindowMoveEventClass}; -use windowing::{ScrollWindowEvent, ZoomWindowEvent, PinchZoomWindowEvent, NavigationWindowEvent, FinishedWindowEvent}; -use windowing::{QuitWindowEvent, MouseWindowClickEvent, MouseWindowMouseDownEvent, MouseWindowMouseUpEvent}; -use windowing::RefreshWindowEvent; -use windowing::{Forward, Back}; +use compositing::windowing::{WindowEvent, WindowMethods}; +use compositing::windowing::{IdleWindowEvent, ResizeWindowEvent, LoadUrlWindowEvent, MouseWindowEventClass, MouseWindowMoveEventClass}; +use compositing::windowing::{ScrollWindowEvent, ZoomWindowEvent, PinchZoomWindowEvent, NavigationWindowEvent, FinishedWindowEvent}; +use compositing::windowing::{QuitWindowEvent, MouseWindowClickEvent, MouseWindowMouseDownEvent, MouseWindowMouseUpEvent}; +use compositing::windowing::RefreshWindowEvent; +use compositing::windowing::{Forward, Back}; use alert::{Alert, AlertMethods}; -use libc::{exit, c_int}; +use libc::c_int; use time; use time::Timespec; use std::cell::{Cell, RefCell}; @@ -23,35 +23,14 @@ use geom::point::{Point2D, TypedPoint2D}; use geom::scale_factor::ScaleFactor; use geom::size::TypedSize2D; use layers::geometry::DevicePixel; -use servo_msg::compositor_msg::{IdleRenderState, RenderState, RenderingRenderState}; -use servo_msg::compositor_msg::{FinishedLoading, Blank, Loading, PerformingLayout, ReadyState}; -use servo_util::geometry::ScreenPx; +use msg::compositor_msg::{IdleRenderState, RenderState, RenderingRenderState}; +use msg::compositor_msg::{FinishedLoading, Blank, Loading, PerformingLayout, ReadyState}; +use util::geometry::ScreenPx; use glfw; use glfw::Context; /// A structure responsible for setting up and tearing down the entire windowing system. -pub struct Application { - pub glfw: glfw::Glfw, -} - -impl ApplicationMethods for Application { - fn new() -> Application { - let app = glfw::init(glfw::LOG_ERRORS); - match app { - Err(_) => { - // handles things like inability to connect to X - // cannot simply fail, since the runtime isn't up yet (causes a nasty abort) - println!("GLFW initialization failed"); - unsafe { exit(1); } - } - Ok(app) => { - Application { glfw: app } - } - } - } -} - macro_rules! glfw_callback( ( $callback:path ($($arg:ident: $arg_ty:ty),*) $block:expr @@ -102,21 +81,22 @@ pub struct Window { last_title_set_time: Cell, } -impl WindowMethods for Window { +impl Window { /// Creates a new window. - fn new(app: &Application, is_foreground: bool, size: TypedSize2D) -> Rc { + pub fn new(glfw: glfw::Glfw, is_foreground: bool, size: TypedSize2D) + -> Rc { // Create the GLFW window. let window_size = size.to_untyped(); - app.glfw.window_hint(glfw::Visible(is_foreground)); - let (glfw_window, events) = app.glfw.create_window(window_size.width as u32, - window_size.height as u32, - "Servo", glfw::Windowed) + glfw.window_hint(glfw::Visible(is_foreground)); + let (glfw_window, events) = glfw.create_window(window_size.width as u32, + window_size.height as u32, + "Servo", glfw::Windowed) .expect("Failed to create GLFW window"); glfw_window.make_current(); // Create our window object. let window = Window { - glfw: app.glfw, + glfw: glfw, glfw_window: glfw_window, events: events, @@ -144,7 +124,9 @@ impl WindowMethods for Window { wrapped_window } +} +impl WindowMethods for Window { /// Returns the size of the window in hardware pixels. fn framebuffer_size(&self) -> TypedSize2D { let (width, height) = self.glfw_window.get_framebuffer_size(); diff --git a/ports/glut/Cargo.toml b/ports/glut/Cargo.toml new file mode 100644 index 000000000000..44adac331020 --- /dev/null +++ b/ports/glut/Cargo.toml @@ -0,0 +1,29 @@ +[package] +name = "glut-app" +version = "0.0.1" +authors = ["The Servo Project Developers"] + +[lib] +name = "glutapp" +path = "lib.rs" + +[dependencies.alert] +git = "https://github.com/servo/rust-alert" + +[dependencies.compositing] +path = "../../components/compositing" + +[dependencies.geom] +git = "https://github.com/servo/rust-geom" + +[dependencies.glut] +git = "https://github.com/servo/rust-glut" + +[dependencies.layers] +git = "https://github.com/servo/rust-layers" + +[dependencies.msg] +path = "../../components/msg" + +[dependencies.util] +path = "../../components/util" diff --git a/ports/glut/lib.rs b/ports/glut/lib.rs new file mode 100644 index 000000000000..67e8300185f4 --- /dev/null +++ b/ports/glut/lib.rs @@ -0,0 +1,41 @@ +/* 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 simple application that uses GLUT to open a window for Servo to display in. + +#![license = "MPL"] +#![feature(macro_rules, phase)] +#![deny(unused_imports, unused_variable)] + +extern crate alert; +extern crate compositing; +extern crate geom; +extern crate glut; +extern crate layers; +extern crate libc; +#[phase(plugin,link)] +extern crate log; +extern crate msg; +extern crate util; + +use geom::scale_factor::ScaleFactor; +use std::rc::Rc; +use window::Window; + +use glut::glut::{init, init_display_mode, DOUBLE}; + +mod window; + +pub fn create_window(opts: &util::opts::Opts) -> Rc { + // Initialize GLUT. + init(); + init_display_mode(DOUBLE); + + // Read command-line options. + let scale_factor = opts.device_pixels_per_px.unwrap_or(ScaleFactor(1.0)); + let size = opts.initial_window_size.as_f32() * scale_factor; + + // Open a window. + Window::new(size.as_uint()) +} diff --git a/components/compositing/platform/common/glut_windowing.rs b/ports/glut/window.rs similarity index 90% rename from components/compositing/platform/common/glut_windowing.rs rename to ports/glut/window.rs index 00d5cc889e8d..a9e06af2ccb3 100644 --- a/components/compositing/platform/common/glut_windowing.rs +++ b/ports/glut/window.rs @@ -4,11 +4,11 @@ //! A windowing implementation using GLUT. -use windowing::{ApplicationMethods, WindowEvent, WindowMethods}; -use windowing::{IdleWindowEvent, ResizeWindowEvent, LoadUrlWindowEvent, MouseWindowEventClass}; -use windowing::{ScrollWindowEvent, ZoomWindowEvent, NavigationWindowEvent, FinishedWindowEvent}; -use windowing::{MouseWindowClickEvent, MouseWindowMouseDownEvent, MouseWindowMouseUpEvent}; -use windowing::{Forward, Back}; +use compositing::windowing::{WindowEvent, WindowMethods}; +use compositing::windowing::{IdleWindowEvent, ResizeWindowEvent, LoadUrlWindowEvent, MouseWindowEventClass}; +use compositing::windowing::{ScrollWindowEvent, ZoomWindowEvent, NavigationWindowEvent, FinishedWindowEvent}; +use compositing::windowing::{MouseWindowClickEvent, MouseWindowMouseDownEvent, MouseWindowMouseUpEvent}; +use compositing::windowing::{Forward, Back}; use alert::{Alert, AlertMethods}; use libc::{c_int, c_uchar}; @@ -18,33 +18,16 @@ use geom::point::{Point2D, TypedPoint2D}; use geom::scale_factor::ScaleFactor; use geom::size::TypedSize2D; use layers::geometry::DevicePixel; -use servo_msg::compositor_msg::{IdleRenderState, RenderState, RenderingRenderState}; -use servo_msg::compositor_msg::{FinishedLoading, Blank, ReadyState}; -use servo_util::geometry::ScreenPx; +use msg::compositor_msg::{IdleRenderState, RenderState, RenderingRenderState}; +use msg::compositor_msg::{FinishedLoading, Blank, ReadyState}; +use util::geometry::ScreenPx; -use glut::glut::{ACTIVE_SHIFT, DOUBLE, WindowHeight}; +use glut::glut::{ACTIVE_SHIFT, WindowHeight}; use glut::glut::WindowWidth; use glut::glut; // static THROBBER: [char, ..8] = [ '⣾', '⣽', '⣻', '⢿', '⡿', '⣟', '⣯', '⣷' ]; -/// A structure responsible for setting up and tearing down the entire windowing system. -pub struct Application; - -impl ApplicationMethods for Application { - fn new() -> Application { - glut::init(); - glut::init_display_mode(DOUBLE); - Application - } -} - -impl Drop for Application { - fn drop(&mut self) { - drop_local_window(); - } -} - /// The type of a window. pub struct Window { pub glut_window: glut::Window, @@ -61,9 +44,9 @@ pub struct Window { pub throbber_frame: Cell, } -impl WindowMethods for Window { +impl Window { /// Creates a new window. - fn new(_: &Application, _: bool, size: TypedSize2D) -> Rc { + pub fn new(size: TypedSize2D) -> Rc { // Create the GLUT window. let window_size = size.to_untyped(); glut::init_window_size(window_size.width, window_size.height); @@ -145,7 +128,15 @@ impl WindowMethods for Window { wrapped_window } +} + +impl Drop for Window { + fn drop(&mut self) { + drop_local_window(); + } +} +impl WindowMethods for Window { /// Returns the size of the window in hardware pixels. fn framebuffer_size(&self) -> TypedSize2D { TypedSize2D(glut::get(WindowWidth) as uint, glut::get(WindowHeight) as uint) diff --git a/src/lib.rs b/src/lib.rs index 6434f0c364c2..11eb90028974 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -30,9 +30,14 @@ extern crate native; extern crate rustrt; extern crate url; +#[cfg(not(test), target_os="android")] +extern crate glutapp; + #[cfg(not(test))] use compositing::{CompositorChan, CompositorTask, Constellation}; #[cfg(not(test))] +use compositing::windowing::WindowMethods; +#[cfg(not(test))] use servo_msg::constellation_msg::{ConstellationChan, InitLoadUrlMsg}; #[cfg(not(test))] use script::dom::bindings::codegen::RegisterBindings; @@ -71,20 +76,17 @@ pub extern "C" fn android_start(argc: int, argv: *const *const u8) -> int { } } - let opts = opts::from_cmdline_args(args.as_slice()); - match opts { - Some(mut o) => { - // Always use CPU rendering on android. - o.cpu_painting = true; - run(o); - }, - None => {} - } + opts::from_cmdline_args(args.as_slice()).map(|mut opts| { + // Always use CPU rendering on android. + opts.cpu_painting = true; + let window = glutapp::create_window(&opts); + run(opts, window); + }); }) } #[cfg(not(test))] -pub fn run(opts: opts::Opts) { +pub fn run(opts: opts::Opts, window: std::rc::Rc) { ::servo_util::opts::set_experimental_enabled(opts.enable_experimental); RegisterBindings::RegisterProxyHandlers(); @@ -151,7 +153,8 @@ pub fn run(opts: opts::Opts) { let constellation_chan = result_port.recv(); debug!("preparing to enter main loop"); - CompositorTask::create(opts, + CompositorTask::create(window, + opts, compositor_port, constellation_chan, time_profiler_chan, diff --git a/src/main.rs b/src/main.rs index a1ced51d823c..3d97f8740af2 100644 --- a/src/main.rs +++ b/src/main.rs @@ -11,6 +11,9 @@ extern crate servo; extern crate native; extern crate "util" as servo_util; +#[cfg(not(test),not(target_os="android"))] +extern crate glfwapp; + #[cfg(not(test),not(target_os="android"))] use servo_util::opts; @@ -20,13 +23,15 @@ use servo::run; #[cfg(not(test),not(target_os="android"))] use std::os; -#[cfg(not(test), target_os="linux")] -#[cfg(not(test), target_os="macos")] +#[cfg(not(test), not(target_os="android"))] #[start] #[allow(dead_code)] fn start(argc: int, argv: *const *const u8) -> int { native::start(argc, argv, proc() { - opts::from_cmdline_args(os::args().as_slice()).map(run); + opts::from_cmdline_args(os::args().as_slice()).map(|opts| { + let window = glfwapp::create_window(&opts); + run(opts, window); + }); }) } diff --git a/support/glfw-rs b/support/glfw-rs index 0baf7f662b8d..7098e6c29074 160000 --- a/support/glfw-rs +++ b/support/glfw-rs @@ -1 +1 @@ -Subproject commit 0baf7f662b8d78c8db9930b03832e16fede5d1ac +Subproject commit 7098e6c290749ef95aadabe505eed9040e013884 From 4fc943305b90241c764c6592d7568dd8e2007e1f Mon Sep 17 00:00:00 2001 From: Matt Brubeck Date: Tue, 30 Sep 2014 12:10:05 -0700 Subject: [PATCH 02/11] Update CEF port to use glfwapp --- ports/cef/Cargo.lock | 27 +++++++++++++++------------ ports/cef/Cargo.toml | 10 +++------- ports/cef/core.rs | 4 +++- ports/cef/lib.rs | 5 +---- 4 files changed, 22 insertions(+), 24 deletions(-) diff --git a/ports/cef/Cargo.lock b/ports/cef/Cargo.lock index fb5a1d2faaf9..c8607e82130a 100644 --- a/ports/cef/Cargo.lock +++ b/ports/cef/Cargo.lock @@ -8,8 +8,7 @@ dependencies = [ "devtools 0.0.1", "geom 0.1.0 (git+https://github.com/servo/rust-geom#90add8d65273c8a46aa16d73959e29a51d0c282d)", "gfx 0.0.1", - "glfw 0.0.1 (git+https://github.com/servo/glfw-rs?ref=servo#955dbe919870b0536f79123232d87c0efe3c552e)", - "glut 0.0.1 (git+https://github.com/servo/rust-glut#01af0162ea0322ad1a40d6adb023a39813605949)", + "glfw-app 0.0.1", "js 0.1.0 (git+https://github.com/servo/rust-mozjs#41fb0d80a5ed5614ca13a120cdb3281e599d4e04)", "layers 0.1.0 (git+https://github.com/servo/rust-layers#180d3ff2f28d239e32d01982c76be5c97d5763a8)", "msg 0.0.1", @@ -76,8 +75,6 @@ dependencies = [ "devtools_traits 0.0.1", "geom 0.1.0 (git+https://github.com/servo/rust-geom#90add8d65273c8a46aa16d73959e29a51d0c282d)", "gfx 0.0.1", - "glfw 0.0.1 (git+https://github.com/servo/glfw-rs?ref=servo#955dbe919870b0536f79123232d87c0efe3c552e)", - "glut 0.0.1 (git+https://github.com/servo/rust-glut#01af0162ea0322ad1a40d6adb023a39813605949)", "layers 0.1.0 (git+https://github.com/servo/rust-layers#180d3ff2f28d239e32d01982c76be5c97d5763a8)", "layout_traits 0.0.1", "msg 0.0.1", @@ -214,18 +211,23 @@ dependencies = [ ] [[package]] -name = "glfw-sys" -version = "3.0.4" -source = "git+https://github.com/servo/glfw?ref=cargo-3.0.4#65a2b4721276589d9de24f6a9999a2db37286cae" - -[[package]] -name = "glut" +name = "glfw-app" version = "0.0.1" -source = "git+https://github.com/servo/rust-glut#01af0162ea0322ad1a40d6adb023a39813605949" dependencies = [ - "opengles 0.1.0 (git+https://github.com/servo/rust-opengles#6776e9c07feb149d34b087039ecf6b2c143e3afc)", + "alert 0.1.0 (git+https://github.com/servo/rust-alert#fdc24f13be8d8a2d15214ec228d166b3221b809e)", + "compositing 0.0.1", + "geom 0.1.0 (git+https://github.com/servo/rust-geom#90add8d65273c8a46aa16d73959e29a51d0c282d)", + "glfw 0.0.1 (git+https://github.com/servo/glfw-rs?ref=servo#955dbe919870b0536f79123232d87c0efe3c552e)", + "layers 0.1.0 (git+https://github.com/servo/rust-layers#9c2848823e24af586899947743704b1238f374c8)", + "msg 0.0.1", + "util 0.0.1", ] +[[package]] +name = "glfw-sys" +version = "3.0.4" +source = "git+https://github.com/servo/glfw?ref=cargo-3.0.4#65a2b4721276589d9de24f6a9999a2db37286cae" + [[package]] name = "harfbuzz" version = "0.1.0" @@ -441,6 +443,7 @@ version = "0.0.1" dependencies = [ "compositing 0.0.1", "gfx 0.0.1", + "glfw-app 0.0.1", "layout 0.0.1", "msg 0.0.1", "net 0.0.1", diff --git a/ports/cef/Cargo.toml b/ports/cef/Cargo.toml index 95ffcf73cefb..d2726b0568c3 100644 --- a/ports/cef/Cargo.toml +++ b/ports/cef/Cargo.toml @@ -11,6 +11,9 @@ crate-type = ["dylib"] [dependencies.servo] path = "../.." +[dependencies.glfw-app] +path = "../glfw" + [dependencies.plugins] path = "../../components/plugins" @@ -41,13 +44,6 @@ git = "https://github.com/servo/rust-azure" [dependencies.geom] git = "https://github.com/servo/rust-geom" -[dependencies.glfw] -git = "https://github.com/servo/glfw-rs" -branch = "servo" - -[dependencies.glut] -git = "https://github.com/servo/rust-glut" - [dependencies.js] git = "https://github.com/servo/rust-mozjs" diff --git a/ports/cef/core.rs b/ports/cef/core.rs index 41f85f791104..2439b6ca07fc 100644 --- a/ports/cef/core.rs +++ b/ports/cef/core.rs @@ -7,6 +7,7 @@ use azure; use command_line::command_line_init; use eutil::fptr_is_null; use geom::size::TypedSize2D; +use glfwapp; use libc::{c_int, c_void}; use native; use servo; @@ -72,7 +73,8 @@ pub extern "C" fn cef_run_message_loop() { initial_window_size: TypedSize2D(800, 600), }; native::start(0, 0 as *const *const u8, proc() { - servo::run(opts); + let window = glfwapp::create_window(&opts); + servo::run(opts, window); }); } diff --git a/ports/cef/lib.rs b/ports/cef/lib.rs index e486644aa891..ebb6bf96b0f2 100644 --- a/ports/cef/lib.rs +++ b/ports/cef/lib.rs @@ -18,10 +18,7 @@ extern crate servo; extern crate azure; extern crate geom; extern crate gfx; -#[cfg(not(target_os="android"))] -extern crate glfw; -#[cfg(target_os="android")] -extern crate glut; +extern crate glfwapp; extern crate js; extern crate layers; extern crate opengles; From 9bed9ea44456db788282f8aa99c701440d64617e Mon Sep 17 00:00:00 2001 From: Matt Brubeck Date: Tue, 30 Sep 2014 12:23:25 -0700 Subject: [PATCH 03/11] Update to latest servo/glfw-rs Picks up servo/glfw-rs#26. --- support/glfw-rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/support/glfw-rs b/support/glfw-rs index 7098e6c29074..a15c2d04b896 160000 --- a/support/glfw-rs +++ b/support/glfw-rs @@ -1 +1 @@ -Subproject commit 7098e6c290749ef95aadabe505eed9040e013884 +Subproject commit a15c2d04b8969aea653841d1d79e5fdf68de664b From 486f3d6352b67f2efe90c63426bfa68035dae762 Mon Sep 17 00:00:00 2001 From: Matt Brubeck Date: Tue, 30 Sep 2014 13:47:23 -0700 Subject: [PATCH 04/11] Update Cargo.lock to match actual glfw-rs rev --- Cargo.lock | 4 ++-- ports/cef/Cargo.lock | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 5c1fa0073427..910ff36736f5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -194,7 +194,7 @@ dependencies = [ [[package]] name = "glfw" version = "0.0.1" -source = "git+https://github.com/servo/glfw-rs?ref=servo#7ccfaca315a43d97914e1601c90ad348ef190edf" +source = "git+https://github.com/servo/glfw-rs?ref=servo#a15c2d04b8969aea653841d1d79e5fdf68de664b" dependencies = [ "glfw-sys 3.0.4 (git+https://github.com/servo/glfw?ref=cargo-3.0.4#65a2b4721276589d9de24f6a9999a2db37286cae)", "semver 0.0.1 (git+https://github.com/rust-lang/semver#d04583a173395b76c1eaa15cc630a5f6f8f0ae10)", @@ -207,7 +207,7 @@ dependencies = [ "alert 0.1.0 (git+https://github.com/servo/rust-alert#fdc24f13be8d8a2d15214ec228d166b3221b809e)", "compositing 0.0.1", "geom 0.1.0 (git+https://github.com/servo/rust-geom#90add8d65273c8a46aa16d73959e29a51d0c282d)", - "glfw 0.0.1 (git+https://github.com/servo/glfw-rs?ref=servo#7ccfaca315a43d97914e1601c90ad348ef190edf)", + "glfw 0.0.1 (git+https://github.com/servo/glfw-rs?ref=servo#a15c2d04b8969aea653841d1d79e5fdf68de664b)", "layers 0.1.0 (git+https://github.com/servo/rust-layers#9c2848823e24af586899947743704b1238f374c8)", "msg 0.0.1", "util 0.0.1", diff --git a/ports/cef/Cargo.lock b/ports/cef/Cargo.lock index c8607e82130a..bab751347750 100644 --- a/ports/cef/Cargo.lock +++ b/ports/cef/Cargo.lock @@ -43,7 +43,7 @@ dependencies = [ "egl 0.1.0 (git+https://github.com/servo/rust-egl#88f2a13812ddbce2bf2317221663a61c31b3e220)", "freetype 0.1.0 (git+https://github.com/servo/rust-freetype#0b03da276e4bdeae2300596dabc4ccb16733ad70)", "geom 0.1.0 (git+https://github.com/servo/rust-geom#90add8d65273c8a46aa16d73959e29a51d0c282d)", - "glfw 0.0.1 (git+https://github.com/servo/glfw-rs?ref=servo#955dbe919870b0536f79123232d87c0efe3c552e)", + "glfw 0.0.1 (git+https://github.com/servo/glfw-rs?ref=servo#a15c2d04b8969aea653841d1d79e5fdf68de664b)", "layers 0.1.0 (git+https://github.com/servo/rust-layers#180d3ff2f28d239e32d01982c76be5c97d5763a8)", "opengles 0.1.0 (git+https://github.com/servo/rust-opengles#6776e9c07feb149d34b087039ecf6b2c143e3afc)", "skia-sys 0.0.20130412 (git+https://github.com/servo/skia#6d696712962fd0d41120b7a414a48417da8e6a92)", @@ -204,7 +204,7 @@ dependencies = [ [[package]] name = "glfw" version = "0.0.1" -source = "git+https://github.com/servo/glfw-rs?ref=servo#955dbe919870b0536f79123232d87c0efe3c552e" +source = "git+https://github.com/servo/glfw-rs?ref=servo#a15c2d04b8969aea653841d1d79e5fdf68de664b" dependencies = [ "glfw-sys 3.0.4 (git+https://github.com/servo/glfw?ref=cargo-3.0.4#65a2b4721276589d9de24f6a9999a2db37286cae)", "semver 0.0.1 (git+https://github.com/rust-lang/semver#d04583a173395b76c1eaa15cc630a5f6f8f0ae10)", @@ -217,7 +217,7 @@ dependencies = [ "alert 0.1.0 (git+https://github.com/servo/rust-alert#fdc24f13be8d8a2d15214ec228d166b3221b809e)", "compositing 0.0.1", "geom 0.1.0 (git+https://github.com/servo/rust-geom#90add8d65273c8a46aa16d73959e29a51d0c282d)", - "glfw 0.0.1 (git+https://github.com/servo/glfw-rs?ref=servo#955dbe919870b0536f79123232d87c0efe3c552e)", + "glfw 0.0.1 (git+https://github.com/servo/glfw-rs?ref=servo#a15c2d04b8969aea653841d1d79e5fdf68de664b)", "layers 0.1.0 (git+https://github.com/servo/rust-layers#9c2848823e24af586899947743704b1238f374c8)", "msg 0.0.1", "util 0.0.1", From cc386a76a34c259d7cac95e0bd62168d1ba91211 Mon Sep 17 00:00:00 2001 From: Matt Brubeck Date: Tue, 30 Sep 2014 13:56:52 -0700 Subject: [PATCH 05/11] Fix headless mode --- components/compositing/compositor_task.rs | 31 ++++------------------- ports/cef/core.rs | 2 +- src/lib.rs | 6 +++-- src/main.rs | 6 ++++- 4 files changed, 15 insertions(+), 30 deletions(-) diff --git a/components/compositing/compositor_task.rs b/components/compositing/compositor_task.rs index d0e16fc1b9fb..aa133741cea6 100644 --- a/components/compositing/compositor_task.rs +++ b/components/compositing/compositor_task.rs @@ -183,28 +183,9 @@ pub enum Msg { LoadComplete(PipelineId, Url), } -pub enum CompositorMode { - Windowed, - Headless -} - -pub struct CompositorTask { - pub mode: CompositorMode, -} +pub struct CompositorTask; impl CompositorTask { - fn new(is_headless: bool) -> CompositorTask { - let mode: CompositorMode = if is_headless { - Headless - } else { - Windowed - }; - - CompositorTask { - mode: mode - } - } - /// Creates a graphics context. Platform-specific. /// /// FIXME(pcwalton): Probably could be less platform-specific, using the metadata abstraction. @@ -218,17 +199,15 @@ impl CompositorTask { } pub fn create( - window: Rc, + window: Option>, opts: Opts, port: Receiver, constellation_chan: ConstellationChan, time_profiler_chan: TimeProfilerChan, memory_profiler_chan: MemoryProfilerChan) { - let compositor = CompositorTask::new(opts.headless); - - match compositor.mode { - Windowed => { + match window { + Some(window) => { compositor::IOCompositor::create(window, opts, port, @@ -236,7 +215,7 @@ impl CompositorTask { time_profiler_chan, memory_profiler_chan) } - Headless => { + None => { headless::NullCompositor::create(port, constellation_chan.clone(), time_profiler_chan, diff --git a/ports/cef/core.rs b/ports/cef/core.rs index 2439b6ca07fc..1e26b2258502 100644 --- a/ports/cef/core.rs +++ b/ports/cef/core.rs @@ -73,7 +73,7 @@ pub extern "C" fn cef_run_message_loop() { initial_window_size: TypedSize2D(800, 600), }; native::start(0, 0 as *const *const u8, proc() { - let window = glfwapp::create_window(&opts); + let window = Some(glfwapp::create_window(&opts)); servo::run(opts, window); }); } diff --git a/src/lib.rs b/src/lib.rs index 11eb90028974..9d8296dce515 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -60,6 +60,8 @@ use green::GreenTaskBuilder; #[cfg(not(test))] use std::os; #[cfg(not(test))] +use std::rc::Rc; +#[cfg(not(test))] use std::task::TaskBuilder; #[cfg(not(test), target_os="android")] use std::string; @@ -79,14 +81,14 @@ pub extern "C" fn android_start(argc: int, argv: *const *const u8) -> int { opts::from_cmdline_args(args.as_slice()).map(|mut opts| { // Always use CPU rendering on android. opts.cpu_painting = true; - let window = glutapp::create_window(&opts); + let window = Some(glutapp::create_window(&opts)); run(opts, window); }); }) } #[cfg(not(test))] -pub fn run(opts: opts::Opts, window: std::rc::Rc) { +pub fn run(opts: opts::Opts, window: Option>) { ::servo_util::opts::set_experimental_enabled(opts.enable_experimental); RegisterBindings::RegisterProxyHandlers(); diff --git a/src/main.rs b/src/main.rs index 3d97f8740af2..bd50fa148288 100644 --- a/src/main.rs +++ b/src/main.rs @@ -29,7 +29,11 @@ use std::os; fn start(argc: int, argv: *const *const u8) -> int { native::start(argc, argv, proc() { opts::from_cmdline_args(os::args().as_slice()).map(|opts| { - let window = glfwapp::create_window(&opts); + let window = if opts.headless { + None + } else { + Some(glfwapp::create_window(&opts)) + }; run(opts, window); }); }) From 64730b7023fb811f339711074bf0002ccda515ae Mon Sep 17 00:00:00 2001 From: Matt Brubeck Date: Tue, 30 Sep 2014 14:00:23 -0700 Subject: [PATCH 06/11] Revert some CEF changes (try to fix Mac build errors) --- ports/cef/Cargo.lock | 1 + ports/cef/Cargo.toml | 4 ++++ ports/cef/lib.rs | 1 + 3 files changed, 6 insertions(+) diff --git a/ports/cef/Cargo.lock b/ports/cef/Cargo.lock index bab751347750..96515d1da93d 100644 --- a/ports/cef/Cargo.lock +++ b/ports/cef/Cargo.lock @@ -8,6 +8,7 @@ dependencies = [ "devtools 0.0.1", "geom 0.1.0 (git+https://github.com/servo/rust-geom#90add8d65273c8a46aa16d73959e29a51d0c282d)", "gfx 0.0.1", + "glfw 0.0.1 (git+https://github.com/servo/glfw-rs?ref=servo#a15c2d04b8969aea653841d1d79e5fdf68de664b)", "glfw-app 0.0.1", "js 0.1.0 (git+https://github.com/servo/rust-mozjs#41fb0d80a5ed5614ca13a120cdb3281e599d4e04)", "layers 0.1.0 (git+https://github.com/servo/rust-layers#180d3ff2f28d239e32d01982c76be5c97d5763a8)", diff --git a/ports/cef/Cargo.toml b/ports/cef/Cargo.toml index d2726b0568c3..85de1a51db69 100644 --- a/ports/cef/Cargo.toml +++ b/ports/cef/Cargo.toml @@ -44,6 +44,10 @@ git = "https://github.com/servo/rust-azure" [dependencies.geom] git = "https://github.com/servo/rust-geom" +[dependencies.glfw] +git = "https://github.com/servo/glfw-rs" +branch = "servo" + [dependencies.js] git = "https://github.com/servo/rust-mozjs" diff --git a/ports/cef/lib.rs b/ports/cef/lib.rs index ebb6bf96b0f2..ec8b63112071 100644 --- a/ports/cef/lib.rs +++ b/ports/cef/lib.rs @@ -18,6 +18,7 @@ extern crate servo; extern crate azure; extern crate geom; extern crate gfx; +extern crate glfw; extern crate glfwapp; extern crate js; extern crate layers; From ce7ceca7a0706e44a5fbc8594374fd4f08ee3657 Mon Sep 17 00:00:00 2001 From: Matt Brubeck Date: Tue, 30 Sep 2014 15:06:15 -0700 Subject: [PATCH 07/11] Change glfw-app to glfw_app (try to fix Mac linker error) --- Cargo.lock | 14 +++++++------- Cargo.toml | 6 +++--- ports/cef/Cargo.lock | 16 ++++++++-------- ports/cef/Cargo.toml | 2 +- ports/glfw/Cargo.toml | 2 +- ports/glut/Cargo.toml | 2 +- 6 files changed, 21 insertions(+), 21 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 910ff36736f5..aaed628d2ae8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4,7 +4,7 @@ version = "0.0.1" dependencies = [ "compositing 0.0.1", "gfx 0.0.1", - "glfw-app 0.0.1", + "glfw_app 0.0.1", "layout 0.0.1", "msg 0.0.1", "net 0.0.1", @@ -201,7 +201,12 @@ dependencies = [ ] [[package]] -name = "glfw-app" +name = "glfw-sys" +version = "3.0.4" +source = "git+https://github.com/servo/glfw?ref=cargo-3.0.4#65a2b4721276589d9de24f6a9999a2db37286cae" + +[[package]] +name = "glfw_app" version = "0.0.1" dependencies = [ "alert 0.1.0 (git+https://github.com/servo/rust-alert#fdc24f13be8d8a2d15214ec228d166b3221b809e)", @@ -213,11 +218,6 @@ dependencies = [ "util 0.0.1", ] -[[package]] -name = "glfw-sys" -version = "3.0.4" -source = "git+https://github.com/servo/glfw?ref=cargo-3.0.4#65a2b4721276589d9de24f6a9999a2db37286cae" - [[package]] name = "harfbuzz" version = "0.1.0" diff --git a/Cargo.toml b/Cargo.toml index 91a090c33959..fe3df5a95859 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -25,7 +25,7 @@ path = "tests/contenttest.rs" harness = false [features] -default = ["glfw-app"] +default = ["glfw_app"] [dependencies.compositing] path = "components/compositing" @@ -48,11 +48,11 @@ path = "components/layout" [dependencies.gfx] path = "components/gfx" -[dependencies.glfw-app] +[dependencies.glfw_app] path = "ports/glfw" optional = true -[dependencies.glut-app] +[dependencies.glut_app] path = "ports/glut" optional = true diff --git a/ports/cef/Cargo.lock b/ports/cef/Cargo.lock index 96515d1da93d..4a168827b5df 100644 --- a/ports/cef/Cargo.lock +++ b/ports/cef/Cargo.lock @@ -9,7 +9,7 @@ dependencies = [ "geom 0.1.0 (git+https://github.com/servo/rust-geom#90add8d65273c8a46aa16d73959e29a51d0c282d)", "gfx 0.0.1", "glfw 0.0.1 (git+https://github.com/servo/glfw-rs?ref=servo#a15c2d04b8969aea653841d1d79e5fdf68de664b)", - "glfw-app 0.0.1", + "glfw_app 0.0.1", "js 0.1.0 (git+https://github.com/servo/rust-mozjs#41fb0d80a5ed5614ca13a120cdb3281e599d4e04)", "layers 0.1.0 (git+https://github.com/servo/rust-layers#180d3ff2f28d239e32d01982c76be5c97d5763a8)", "msg 0.0.1", @@ -212,7 +212,12 @@ dependencies = [ ] [[package]] -name = "glfw-app" +name = "glfw-sys" +version = "3.0.4" +source = "git+https://github.com/servo/glfw?ref=cargo-3.0.4#65a2b4721276589d9de24f6a9999a2db37286cae" + +[[package]] +name = "glfw_app" version = "0.0.1" dependencies = [ "alert 0.1.0 (git+https://github.com/servo/rust-alert#fdc24f13be8d8a2d15214ec228d166b3221b809e)", @@ -224,11 +229,6 @@ dependencies = [ "util 0.0.1", ] -[[package]] -name = "glfw-sys" -version = "3.0.4" -source = "git+https://github.com/servo/glfw?ref=cargo-3.0.4#65a2b4721276589d9de24f6a9999a2db37286cae" - [[package]] name = "harfbuzz" version = "0.1.0" @@ -444,7 +444,7 @@ version = "0.0.1" dependencies = [ "compositing 0.0.1", "gfx 0.0.1", - "glfw-app 0.0.1", + "glfw_app 0.0.1", "layout 0.0.1", "msg 0.0.1", "net 0.0.1", diff --git a/ports/cef/Cargo.toml b/ports/cef/Cargo.toml index 85de1a51db69..a0de421b9707 100644 --- a/ports/cef/Cargo.toml +++ b/ports/cef/Cargo.toml @@ -11,7 +11,7 @@ crate-type = ["dylib"] [dependencies.servo] path = "../.." -[dependencies.glfw-app] +[dependencies.glfw_app] path = "../glfw" [dependencies.plugins] diff --git a/ports/glfw/Cargo.toml b/ports/glfw/Cargo.toml index 253cf460d92c..16c78dcede33 100644 --- a/ports/glfw/Cargo.toml +++ b/ports/glfw/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "glfw-app" +name = "glfw_app" version = "0.0.1" authors = ["The Servo Project Developers"] diff --git a/ports/glut/Cargo.toml b/ports/glut/Cargo.toml index 44adac331020..aaa80f9adc3d 100644 --- a/ports/glut/Cargo.toml +++ b/ports/glut/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "glut-app" +name = "glut_app" version = "0.0.1" authors = ["The Servo Project Developers"] From 27160e72c680442dd1291b7ac644e588f881bc85 Mon Sep 17 00:00:00 2001 From: Matt Brubeck Date: Tue, 30 Sep 2014 16:11:36 -0700 Subject: [PATCH 08/11] Make crate name match package name (try to fix Mac build) --- ports/cef/core.rs | 4 ++-- ports/cef/lib.rs | 2 +- ports/glfw/Cargo.toml | 2 +- ports/glut/Cargo.toml | 2 +- src/lib.rs | 4 ++-- src/main.rs | 4 ++-- 6 files changed, 9 insertions(+), 9 deletions(-) diff --git a/ports/cef/core.rs b/ports/cef/core.rs index 1e26b2258502..1cc82d141902 100644 --- a/ports/cef/core.rs +++ b/ports/cef/core.rs @@ -7,7 +7,7 @@ use azure; use command_line::command_line_init; use eutil::fptr_is_null; use geom::size::TypedSize2D; -use glfwapp; +use glfw_app; use libc::{c_int, c_void}; use native; use servo; @@ -73,7 +73,7 @@ pub extern "C" fn cef_run_message_loop() { initial_window_size: TypedSize2D(800, 600), }; native::start(0, 0 as *const *const u8, proc() { - let window = Some(glfwapp::create_window(&opts)); + let window = Some(glfw_app::create_window(&opts)); servo::run(opts, window); }); } diff --git a/ports/cef/lib.rs b/ports/cef/lib.rs index ec8b63112071..bf7aeec80e6b 100644 --- a/ports/cef/lib.rs +++ b/ports/cef/lib.rs @@ -19,7 +19,7 @@ extern crate azure; extern crate geom; extern crate gfx; extern crate glfw; -extern crate glfwapp; +extern crate glfw_app; extern crate js; extern crate layers; extern crate opengles; diff --git a/ports/glfw/Cargo.toml b/ports/glfw/Cargo.toml index 16c78dcede33..3212bd428ac2 100644 --- a/ports/glfw/Cargo.toml +++ b/ports/glfw/Cargo.toml @@ -4,7 +4,7 @@ version = "0.0.1" authors = ["The Servo Project Developers"] [lib] -name = "glfwapp" +name = "glfw_app" path = "lib.rs" [dependencies.alert] diff --git a/ports/glut/Cargo.toml b/ports/glut/Cargo.toml index aaa80f9adc3d..7a3cdae18d42 100644 --- a/ports/glut/Cargo.toml +++ b/ports/glut/Cargo.toml @@ -4,7 +4,7 @@ version = "0.0.1" authors = ["The Servo Project Developers"] [lib] -name = "glutapp" +name = "glut_app" path = "lib.rs" [dependencies.alert] diff --git a/src/lib.rs b/src/lib.rs index 9d8296dce515..adfdb011f4bd 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -31,7 +31,7 @@ extern crate rustrt; extern crate url; #[cfg(not(test), target_os="android")] -extern crate glutapp; +extern crate glut_app; #[cfg(not(test))] use compositing::{CompositorChan, CompositorTask, Constellation}; @@ -81,7 +81,7 @@ pub extern "C" fn android_start(argc: int, argv: *const *const u8) -> int { opts::from_cmdline_args(args.as_slice()).map(|mut opts| { // Always use CPU rendering on android. opts.cpu_painting = true; - let window = Some(glutapp::create_window(&opts)); + let window = Some(glut_app::create_window(&opts)); run(opts, window); }); }) diff --git a/src/main.rs b/src/main.rs index bd50fa148288..9d78c0967c74 100644 --- a/src/main.rs +++ b/src/main.rs @@ -12,7 +12,7 @@ extern crate native; extern crate "util" as servo_util; #[cfg(not(test),not(target_os="android"))] -extern crate glfwapp; +extern crate glfw_app; #[cfg(not(test),not(target_os="android"))] use servo_util::opts; @@ -32,7 +32,7 @@ fn start(argc: int, argv: *const *const u8) -> int { let window = if opts.headless { None } else { - Some(glfwapp::create_window(&opts)) + Some(glfw_app::create_window(&opts)) }; run(opts, window); }); From aad63b9e861e0b6b73f587f05380c1b3b399a3a2 Mon Sep 17 00:00:00 2001 From: Matt Brubeck Date: Tue, 30 Sep 2014 16:26:55 -0700 Subject: [PATCH 09/11] Explicitly link glfw_app into libservo --- src/lib.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index adfdb011f4bd..9f97d16aa407 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -30,6 +30,8 @@ extern crate native; extern crate rustrt; extern crate url; +#[cfg(not(test), not(target_os="android"))] +extern crate glfw_app; #[cfg(not(test), target_os="android")] extern crate glut_app; From 485d49538f6cd83d60e5c91100274a25fcc4371a Mon Sep 17 00:00:00 2001 From: Matt Brubeck Date: Wed, 1 Oct 2014 13:54:41 -0700 Subject: [PATCH 10/11] Init GLFW with LOG_ERRORS --- ports/glfw/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ports/glfw/lib.rs b/ports/glfw/lib.rs index de3cecf24f6d..d0f96f950eb3 100644 --- a/ports/glfw/lib.rs +++ b/ports/glfw/lib.rs @@ -26,7 +26,7 @@ mod window; pub fn create_window(opts: &util::opts::Opts) -> Rc { // Initialize GLFW. - let glfw = glfw::init(glfw::FAIL_ON_ERRORS).unwrap_or_else(|_| { + let glfw = glfw::init(glfw::LOG_ERRORS).unwrap_or_else(|_| { // handles things like inability to connect to X // cannot simply fail, since the runtime isn't up yet (causes a nasty abort) println!("GLFW initialization failed"); From fa6d493f5f4c70d1fb9686d651986f780d007a4d Mon Sep 17 00:00:00 2001 From: Matt Brubeck Date: Thu, 2 Oct 2014 10:57:07 -0700 Subject: [PATCH 11/11] Move glut_app into ports/android --- Cargo.toml | 6 +--- ports/{glut => android/glut_app}/Cargo.toml | 11 ++++++-- ports/{glut => android/glut_app}/lib.rs | 31 ++++++++++++++++++--- ports/{glut => android/glut_app}/window.rs | 0 src/lib.rs | 28 ------------------- 5 files changed, 36 insertions(+), 40 deletions(-) rename ports/{glut => android/glut_app}/Cargo.toml (70%) rename ports/{glut => android/glut_app}/lib.rs (53%) rename ports/{glut => android/glut_app}/window.rs (100%) diff --git a/Cargo.toml b/Cargo.toml index fe3df5a95859..a48a9b7ecd5c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,7 +6,7 @@ authors = ["The Servo Project Developers"] [lib] name = "servo" -crate-type = ["rlib", "dylib"] +crate-type = ["rlib"] [[bin]] name = "servo" @@ -52,9 +52,5 @@ path = "components/gfx" path = "ports/glfw" optional = true -[dependencies.glut_app] -path = "ports/glut" -optional = true - [dependencies.url] git = "https://github.com/servo/rust-url" diff --git a/ports/glut/Cargo.toml b/ports/android/glut_app/Cargo.toml similarity index 70% rename from ports/glut/Cargo.toml rename to ports/android/glut_app/Cargo.toml index 7a3cdae18d42..a4372c4a9108 100644 --- a/ports/glut/Cargo.toml +++ b/ports/android/glut_app/Cargo.toml @@ -6,12 +6,13 @@ authors = ["The Servo Project Developers"] [lib] name = "glut_app" path = "lib.rs" +crate-type = ["dylib"] [dependencies.alert] git = "https://github.com/servo/rust-alert" [dependencies.compositing] -path = "../../components/compositing" +path = "../../../components/compositing" [dependencies.geom] git = "https://github.com/servo/rust-geom" @@ -23,7 +24,11 @@ git = "https://github.com/servo/rust-glut" git = "https://github.com/servo/rust-layers" [dependencies.msg] -path = "../../components/msg" +path = "../../../components/msg" + +[dependencies.servo] +path = "../../.." +default-features = false [dependencies.util] -path = "../../components/util" +path = "../../../components/util" diff --git a/ports/glut/lib.rs b/ports/android/glut_app/lib.rs similarity index 53% rename from ports/glut/lib.rs rename to ports/android/glut_app/lib.rs index 67e8300185f4..90269e91c5b4 100644 --- a/ports/glut/lib.rs +++ b/ports/android/glut_app/lib.rs @@ -14,20 +14,23 @@ extern crate geom; extern crate glut; extern crate layers; extern crate libc; -#[phase(plugin,link)] -extern crate log; +#[phase(plugin, link)] extern crate log; extern crate msg; -extern crate util; +extern crate native; +extern crate servo; +#[phase(plugin, link)] extern crate util; use geom::scale_factor::ScaleFactor; use std::rc::Rc; +use std::string; +use util::opts; use window::Window; use glut::glut::{init, init_display_mode, DOUBLE}; mod window; -pub fn create_window(opts: &util::opts::Opts) -> Rc { +pub fn create_window(opts: &opts::Opts) -> Rc { // Initialize GLUT. init(); init_display_mode(DOUBLE); @@ -39,3 +42,23 @@ pub fn create_window(opts: &util::opts::Opts) -> Rc { // Open a window. Window::new(size.as_uint()) } + +#[no_mangle] +#[allow(dead_code)] +pub extern "C" fn android_start(argc: int, argv: *const *const u8) -> int { + native::start(argc, argv, proc() { + let mut args: Vec = vec!(); + for i in range(0u, argc as uint) { + unsafe { + args.push(string::raw::from_buf(*argv.offset(i as int) as *const u8)); + } + } + + opts::from_cmdline_args(args.as_slice()).map(|mut opts| { + // Always use CPU rendering on android. + opts.cpu_painting = true; + let window = Some(create_window(&opts)); + servo::run(opts, window); + }); + }) +} diff --git a/ports/glut/window.rs b/ports/android/glut_app/window.rs similarity index 100% rename from ports/glut/window.rs rename to ports/android/glut_app/window.rs diff --git a/src/lib.rs b/src/lib.rs index 9f97d16aa407..a7b6bc1ca53b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -30,11 +30,6 @@ extern crate native; extern crate rustrt; extern crate url; -#[cfg(not(test), not(target_os="android"))] -extern crate glfw_app; -#[cfg(not(test), target_os="android")] -extern crate glut_app; - #[cfg(not(test))] use compositing::{CompositorChan, CompositorTask, Constellation}; #[cfg(not(test))] @@ -65,29 +60,6 @@ use std::os; use std::rc::Rc; #[cfg(not(test))] use std::task::TaskBuilder; -#[cfg(not(test), target_os="android")] -use std::string; - -#[cfg(not(test), target_os="android")] -#[no_mangle] -#[allow(dead_code)] -pub extern "C" fn android_start(argc: int, argv: *const *const u8) -> int { - native::start(argc, argv, proc() { - let mut args: Vec = vec!(); - for i in range(0u, argc as uint) { - unsafe { - args.push(string::raw::from_buf(*argv.offset(i as int) as *const u8)); - } - } - - opts::from_cmdline_args(args.as_slice()).map(|mut opts| { - // Always use CPU rendering on android. - opts.cpu_painting = true; - let window = Some(glut_app::create_window(&opts)); - run(opts, window); - }); - }) -} #[cfg(not(test))] pub fn run(opts: opts::Opts, window: Option>) {