Skip to content

Commit

Permalink
Move windowing code out of the compositor
Browse files Browse the repository at this point in the history
This is mainly just moving code around, in preparation for further changes to
the "windowing" API.
  • Loading branch information
mbrubeck committed Oct 10, 2014
1 parent bfb81a5 commit 77d32ee
Show file tree
Hide file tree
Showing 23 changed files with 828 additions and 206 deletions.
18 changes: 11 additions & 7 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 7 additions & 1 deletion Cargo.toml
Expand Up @@ -6,7 +6,7 @@ authors = ["The Servo Project Developers"]

[lib]
name = "servo"
crate-type = ["rlib", "dylib"]
crate-type = ["rlib"]

[[bin]]
name = "servo"
Expand All @@ -24,6 +24,8 @@ name = "contenttest"
path = "tests/contenttest.rs"
harness = false

[features]
default = ["glfw_app"]

[dependencies.compositing]
path = "components/compositing"
Expand All @@ -46,5 +48,9 @@ path = "components/layout"
[dependencies.gfx]
path = "components/gfx"

[dependencies.glfw_app]
path = "ports/glfw"
optional = true

[dependencies.url]
git = "https://github.com/servo/rust-url"
1 change: 0 additions & 1 deletion README.md
Expand Up @@ -89,7 +89,6 @@ git clone https://github.com/servo/servo
cd servo
ANDROID_TOOLCHAIN=/path/to/toolchain ANDROID_NDK=/path/to/ndk PATH=$PATH:/path/to/toolchain/bin ./mach build --android
cd ports/android
ANDROID_NDK=/path/to/ndk ANDROID_SDK=/path/to/sdk make
ANDROID_SDK=/path/to/sdk make install
```

Expand Down
8 changes: 0 additions & 8 deletions components/compositing/Cargo.toml
Expand Up @@ -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"

Expand All @@ -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"

30 changes: 10 additions & 20 deletions components/compositing/compositor.rs
Expand Up @@ -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};
Expand Down Expand Up @@ -54,7 +53,7 @@ use time::precise_time_s;
use url::Url;


pub struct IOCompositor {
pub struct IOCompositor<Window: WindowMethods> {
/// The application window.
window: Rc<Window>,

Expand Down Expand Up @@ -136,22 +135,13 @@ enum ShutdownState {
FinishedShuttingDown,
}

impl IOCompositor {
fn new(app: &Application,
opts: Opts,
port: Receiver<Msg>,
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<Window> = WindowMethods::new(app, opts.output_file.is_none(),
framebuffer_size.as_uint());
impl<Window: WindowMethods> IOCompositor<Window> {
fn new(window: Rc<Window>,
opts: Opts,
port: Receiver<Msg>,
constellation_chan: ConstellationChan,
time_profiler_chan: TimeProfilerChan,
memory_profiler_chan: MemoryProfilerChan) -> IOCompositor<Window> {

// Create an initial layer tree.
//
Expand Down Expand Up @@ -192,13 +182,13 @@ impl IOCompositor {
}
}

pub fn create(app: &Application,
pub fn create(window: Rc<Window>,
opts: Opts,
port: Receiver<Msg>,
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,
Expand Down
39 changes: 10 additions & 29 deletions components/compositing/compositor_task.rs
Expand Up @@ -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;
Expand All @@ -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;

Expand Down Expand Up @@ -183,28 +183,9 @@ pub enum Msg {
LoadComplete(PipelineId, Url),
}

pub enum CompositorMode {
Windowed(Application),
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(ApplicationMethods::new())
};

CompositorTask {
mode: mode
}
}

/// Creates a graphics context. Platform-specific.
///
/// FIXME(pcwalton): Probably could be less platform-specific, using the metadata abstraction.
Expand All @@ -217,24 +198,24 @@ impl CompositorTask {
NativeCompositingGraphicsContext::new()
}

pub fn create(opts: Opts,
pub fn create<Window: WindowMethods>(
window: Option<Rc<Window>>,
opts: Opts,
port: Receiver<Msg>,
constellation_chan: ConstellationChan,
time_profiler_chan: TimeProfilerChan,
memory_profiler_chan: MemoryProfilerChan) {

let compositor = CompositorTask::new(opts.headless);

match compositor.mode {
Windowed(ref app) => {
compositor::IOCompositor::create(app,
match window {
Some(window) => {
compositor::IOCompositor::create(window,
opts,
port,
constellation_chan.clone(),
time_profiler_chan,
memory_profiler_chan)
}
Headless => {
None => {
headless::NullCompositor::create(port,
constellation_chan.clone(),
time_profiler_chan,
Expand Down
9 changes: 1 addition & 8 deletions components/compositing/lib.rs
Expand Up @@ -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;
Expand Down Expand Up @@ -56,7 +52,4 @@ mod headless;
pub mod pipeline;
pub mod constellation;

mod windowing;

#[path="platform/mod.rs"]
pub mod platform;
pub mod windowing;
10 changes: 1 addition & 9 deletions components/compositing/windowing.rs
Expand Up @@ -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<DevicePixel, f32>),
Expand Down Expand Up @@ -54,14 +53,7 @@ pub enum WindowEvent {
QuitWindowEvent,
}

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

pub trait WindowMethods<A> {
/// Creates a new window.
fn new(app: &A, is_foreground: bool, size: TypedSize2D<DevicePixel, uint>) -> Rc<Self>;
pub trait WindowMethods {
/// Returns the size of the window in hardware pixels.
fn framebuffer_size(&self) -> TypedSize2D<DevicePixel, uint>;
/// Returns the size of the window in density-independent "px" units.
Expand Down
13 changes: 10 additions & 3 deletions ports/android/Makefile
@@ -1,9 +1,11 @@
CARGO_OPTS ?=

.PHONY: all
all:
all: glut_app
NDK_DEBUG=1 $(ANDROID_NDK)/ndk-build -B
find ../../target ! \( -type d -name dist -prune \) -name libmozjs.so | \
find glut_app/target ! \( -type d -name dist -prune \) -name libmozjs.so | \
xargs -I {} cp -f {} libs/armeabi
find ../../target ! \( -type d -name dist -prune \) -name 'libservo-*.so' | \
find glut_app/target ! \( -type d -name dist -prune \) -name 'libglut_app-*.so' | \
xargs -I {} cp -f {} libs/armeabi/libservo.so
find ../../rust/lib/rustlib/arm-linux-androideabi/lib \
-name '*.so' -type f -size +1c | \
Expand All @@ -14,6 +16,11 @@ all:
--path .
ant debug

.PHONY: glut_app
glut_app:
cd glut_app; \
../../../mach cargo build --target=arm-linux-androideabi $(CARGO_OPTS)

.PHONY: install
install:
$(ANDROID_SDK)/platform-tools/adb install -r bin/ServoAndroid-debug.apk

4 comments on commit 77d32ee

@bors-servo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

saw approval from larsbergstrom
at mbrubeck@77d32ee

@bors-servo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging mbrubeck/servo/app2 = 77d32ee into auto

@bors-servo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mbrubeck/servo/app2 = 77d32ee merged ok, testing candidate = 528ad45

@bors-servo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.