Use WindowMethods to get native graphics metadata instead of

relying on azure. This is a prerequisite for the switch to glutin.

Tested on Linux, mac. Tested that android + cef build.
This commit is contained in:
Glenn Watson 2014-10-24 13:45:42 +10:00
parent 44eec48c57
commit 2d6626e7ef
12 changed files with 49 additions and 9 deletions

1
Cargo.lock generated
View file

@ -215,6 +215,7 @@ dependencies = [
"glfw 0.0.1 (git+https://github.com/servo/glfw-rs?ref=servo#a15c2d04b8969aea653841d1d79e5fdf68de664b)", "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#eac91e00db9af155f3004b408a18cb6d9f462a25)", "layers 0.1.0 (git+https://github.com/servo/rust-layers#eac91e00db9af155f3004b408a18cb6d9f462a25)",
"msg 0.0.1", "msg 0.0.1",
"opengles 0.1.0 (git+https://github.com/servo/rust-opengles#6776e9c07feb149d34b087039ecf6b2c143e3afc)",
"util 0.0.1", "util 0.0.1",
] ]

View file

@ -145,13 +145,13 @@ impl<Window: WindowMethods> IOCompositor<Window> {
// display list. This is only here because we don't have that logic in the renderer yet. // display list. This is only here because we don't have that logic in the renderer yet.
let window_size = window.framebuffer_size(); let window_size = window.framebuffer_size();
let hidpi_factor = window.hidpi_factor(); let hidpi_factor = window.hidpi_factor();
let context = CompositorTask::create_graphics_context(&window.native_metadata());
let show_debug_borders = opts::get().show_debug_borders; let show_debug_borders = opts::get().show_debug_borders;
IOCompositor { IOCompositor {
window: window, window: window,
port: port, port: port,
context: rendergl::RenderContext::new(CompositorTask::create_graphics_context(), context: rendergl::RenderContext::new(context, show_debug_borders),
show_debug_borders),
root_pipeline: None, root_pipeline: None,
scene: Scene::new(Rect { scene: Scene::new(Rect {
origin: Zero::zero(), origin: Zero::zero(),
@ -294,7 +294,7 @@ impl<Window: WindowMethods> IOCompositor<Window> {
} }
(Ok(GetGraphicsMetadata(chan)), NotShuttingDown) => { (Ok(GetGraphicsMetadata(chan)), NotShuttingDown) => {
chan.send(Some(azure_hl::current_graphics_metadata())); chan.send(Some(self.window.native_metadata()));
} }
(Ok(CreateOrUpdateRootLayer(layer_properties)), NotShuttingDown) => { (Ok(CreateOrUpdateRootLayer(layer_properties)), NotShuttingDown) => {

View file

@ -25,9 +25,6 @@ use std::rc::Rc;
use url::Url; use url::Url;
#[cfg(target_os="linux")]
use azure::azure_hl;
/// The implementation of the layers-based compositor. /// The implementation of the layers-based compositor.
#[deriving(Clone)] #[deriving(Clone)]
pub struct CompositorChan { pub struct CompositorChan {
@ -189,11 +186,13 @@ impl CompositorTask {
/// ///
/// FIXME(pcwalton): Probably could be less platform-specific, using the metadata abstraction. /// FIXME(pcwalton): Probably could be less platform-specific, using the metadata abstraction.
#[cfg(target_os="linux")] #[cfg(target_os="linux")]
pub fn create_graphics_context() -> NativeCompositingGraphicsContext { pub fn create_graphics_context(native_metadata: &NativeGraphicsMetadata)
NativeCompositingGraphicsContext::from_display(azure_hl::current_display()) -> NativeCompositingGraphicsContext {
NativeCompositingGraphicsContext::from_display(native_metadata.display)
} }
#[cfg(not(target_os="linux"))] #[cfg(not(target_os="linux"))]
pub fn create_graphics_context() -> NativeCompositingGraphicsContext { pub fn create_graphics_context(_: &NativeGraphicsMetadata)
-> NativeCompositingGraphicsContext {
NativeCompositingGraphicsContext::new() NativeCompositingGraphicsContext::new()
} }

View file

@ -8,6 +8,7 @@ use geom::point::TypedPoint2D;
use geom::scale_factor::ScaleFactor; use geom::scale_factor::ScaleFactor;
use geom::size::TypedSize2D; use geom::size::TypedSize2D;
use layers::geometry::DevicePixel; use layers::geometry::DevicePixel;
use layers::platform::surface::NativeGraphicsMetadata;
use servo_msg::compositor_msg::{ReadyState, RenderState}; use servo_msg::compositor_msg::{ReadyState, RenderState};
use servo_util::geometry::ScreenPx; use servo_util::geometry::ScreenPx;
@ -71,5 +72,8 @@ pub trait WindowMethods {
/// Returns the hidpi factor of the monitor. /// Returns the hidpi factor of the monitor.
fn hidpi_factor(&self) -> ScaleFactor<ScreenPx, DevicePixel, f32>; fn hidpi_factor(&self) -> ScaleFactor<ScreenPx, DevicePixel, f32>;
/// Gets the OS native graphics information for this window.
fn native_metadata(&self) -> NativeGraphicsMetadata;
} }

View file

@ -4,6 +4,7 @@ version = "0.0.1"
dependencies = [ dependencies = [
"alert 0.1.0 (git+https://github.com/servo/rust-alert#fdc24f13be8d8a2d15214ec228d166b3221b809e)", "alert 0.1.0 (git+https://github.com/servo/rust-alert#fdc24f13be8d8a2d15214ec228d166b3221b809e)",
"compositing 0.0.1", "compositing 0.0.1",
"egl 0.1.0 (git+https://github.com/servo/rust-egl#88f2a13812ddbce2bf2317221663a61c31b3e220)",
"geom 0.1.0 (git+https://github.com/servo/rust-geom#b001a76e907befaae1d0d6dd259418a22092da86)", "geom 0.1.0 (git+https://github.com/servo/rust-geom#b001a76e907befaae1d0d6dd259418a22092da86)",
"glut 0.0.1 (git+https://github.com/servo/rust-glut#01af0162ea0322ad1a40d6adb023a39813605949)", "glut 0.0.1 (git+https://github.com/servo/rust-glut#01af0162ea0322ad1a40d6adb023a39813605949)",
"layers 0.1.0 (git+https://github.com/servo/rust-layers#eac91e00db9af155f3004b408a18cb6d9f462a25)", "layers 0.1.0 (git+https://github.com/servo/rust-layers#eac91e00db9af155f3004b408a18cb6d9f462a25)",

View file

@ -32,3 +32,6 @@ default-features = false
[dependencies.util] [dependencies.util]
path = "../../../components/util" path = "../../../components/util"
[dependencies.egl]
git = "https://github.com/servo/rust-egl"

View file

@ -10,6 +10,7 @@
extern crate alert; extern crate alert;
extern crate compositing; extern crate compositing;
extern crate egl;
extern crate geom; extern crate geom;
extern crate glut; extern crate glut;
extern crate layers; extern crate layers;

View file

@ -18,6 +18,7 @@ use geom::point::{Point2D, TypedPoint2D};
use geom::scale_factor::ScaleFactor; use geom::scale_factor::ScaleFactor;
use geom::size::TypedSize2D; use geom::size::TypedSize2D;
use layers::geometry::DevicePixel; use layers::geometry::DevicePixel;
use layers::platform::surface::NativeGraphicsMetadata;
use msg::compositor_msg::{IdleRenderState, RenderState, RenderingRenderState}; use msg::compositor_msg::{IdleRenderState, RenderState, RenderingRenderState};
use msg::compositor_msg::{FinishedLoading, Blank, ReadyState}; use msg::compositor_msg::{FinishedLoading, Blank, ReadyState};
use util::geometry::ScreenPx; use util::geometry::ScreenPx;
@ -187,6 +188,13 @@ impl WindowMethods for Window {
//FIXME: Do nothing in GLUT now. //FIXME: Do nothing in GLUT now.
ScaleFactor(1.0) ScaleFactor(1.0)
} }
fn native_metadata(&self) -> NativeGraphicsMetadata {
use egl::egl::GetCurrentDisplay;
NativeGraphicsMetadata {
display: GetCurrentDisplay(),
}
}
} }
impl Window { impl Window {

1
ports/cef/Cargo.lock generated
View file

@ -226,6 +226,7 @@ dependencies = [
"glfw 0.0.1 (git+https://github.com/servo/glfw-rs?ref=servo#a15c2d04b8969aea653841d1d79e5fdf68de664b)", "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#eac91e00db9af155f3004b408a18cb6d9f462a25)", "layers 0.1.0 (git+https://github.com/servo/rust-layers#eac91e00db9af155f3004b408a18cb6d9f462a25)",
"msg 0.0.1", "msg 0.0.1",
"opengles 0.1.0 (git+https://github.com/servo/rust-opengles#6776e9c07feb149d34b087039ecf6b2c143e3afc)",
"util 0.0.1", "util 0.0.1",
] ]

View file

@ -28,3 +28,6 @@ path = "../../components/msg"
[dependencies.util] [dependencies.util]
path = "../../components/util" path = "../../components/util"
[dependencies.opengles]
git = "https://github.com/servo/rust-opengles"

View file

@ -17,6 +17,7 @@ extern crate libc;
extern crate msg; extern crate msg;
extern crate time; extern crate time;
extern crate util; extern crate util;
extern crate opengles;
use geom::scale_factor::ScaleFactor; use geom::scale_factor::ScaleFactor;
use std::rc::Rc; use std::rc::Rc;

View file

@ -17,6 +17,7 @@ use geom::scale_factor::ScaleFactor;
use geom::size::TypedSize2D; use geom::size::TypedSize2D;
use glfw::{mod, Context}; use glfw::{mod, Context};
use layers::geometry::DevicePixel; use layers::geometry::DevicePixel;
use layers::platform::surface::NativeGraphicsMetadata;
use libc::c_int; use libc::c_int;
use msg::compositor_msg::{IdleRenderState, RenderState, RenderingRenderState}; use msg::compositor_msg::{IdleRenderState, RenderState, RenderingRenderState};
use msg::compositor_msg::{FinishedLoading, Blank, Loading, PerformingLayout, ReadyState}; use msg::compositor_msg::{FinishedLoading, Blank, Loading, PerformingLayout, ReadyState};
@ -151,6 +152,23 @@ impl WindowMethods for Window {
let window_size = self.size().width.get(); let window_size = self.size().width.get();
ScaleFactor((backing_size as f32) / window_size) ScaleFactor((backing_size as f32) / window_size)
} }
#[cfg(target_os="linux")]
fn native_metadata(&self) -> NativeGraphicsMetadata {
NativeGraphicsMetadata {
display: unsafe { glfw::ffi::glfwGetX11Display() },
}
}
#[cfg(target_os="macos")]
fn native_metadata(&self) -> NativeGraphicsMetadata {
use opengles::cgl::{CGLGetCurrentContext, CGLGetPixelFormat};
unsafe {
NativeGraphicsMetadata {
pixel_format: CGLGetPixelFormat(CGLGetCurrentContext()),
}
}
}
} }
impl Window { impl Window {