From 2d6626e7ef5d917f38040a2ea9766b6f5e2d2d29 Mon Sep 17 00:00:00 2001 From: Glenn Watson Date: Fri, 24 Oct 2014 13:45:42 +1000 Subject: [PATCH] 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. --- Cargo.lock | 1 + components/compositing/compositor.rs | 6 +++--- components/compositing/compositor_task.rs | 11 +++++------ components/compositing/windowing.rs | 4 ++++ ports/android/glut_app/Cargo.lock | 1 + ports/android/glut_app/Cargo.toml | 3 +++ ports/android/glut_app/lib.rs | 1 + ports/android/glut_app/window.rs | 8 ++++++++ ports/cef/Cargo.lock | 1 + ports/glfw/Cargo.toml | 3 +++ ports/glfw/lib.rs | 1 + ports/glfw/window.rs | 18 ++++++++++++++++++ 12 files changed, 49 insertions(+), 9 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index c6dafc4bfe9..7b169f1d642 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -215,6 +215,7 @@ dependencies = [ "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)", "msg 0.0.1", + "opengles 0.1.0 (git+https://github.com/servo/rust-opengles#6776e9c07feb149d34b087039ecf6b2c143e3afc)", "util 0.0.1", ] diff --git a/components/compositing/compositor.rs b/components/compositing/compositor.rs index dbae782262e..ab959f17a3f 100644 --- a/components/compositing/compositor.rs +++ b/components/compositing/compositor.rs @@ -145,13 +145,13 @@ impl IOCompositor { // display list. This is only here because we don't have that logic in the renderer yet. let window_size = window.framebuffer_size(); let hidpi_factor = window.hidpi_factor(); + let context = CompositorTask::create_graphics_context(&window.native_metadata()); let show_debug_borders = opts::get().show_debug_borders; IOCompositor { window: window, port: port, - context: rendergl::RenderContext::new(CompositorTask::create_graphics_context(), - show_debug_borders), + context: rendergl::RenderContext::new(context, show_debug_borders), root_pipeline: None, scene: Scene::new(Rect { origin: Zero::zero(), @@ -294,7 +294,7 @@ impl IOCompositor { } (Ok(GetGraphicsMetadata(chan)), NotShuttingDown) => { - chan.send(Some(azure_hl::current_graphics_metadata())); + chan.send(Some(self.window.native_metadata())); } (Ok(CreateOrUpdateRootLayer(layer_properties)), NotShuttingDown) => { diff --git a/components/compositing/compositor_task.rs b/components/compositing/compositor_task.rs index 4d5df1def91..dd215af28f7 100644 --- a/components/compositing/compositor_task.rs +++ b/components/compositing/compositor_task.rs @@ -25,9 +25,6 @@ use std::rc::Rc; use url::Url; -#[cfg(target_os="linux")] -use azure::azure_hl; - /// The implementation of the layers-based compositor. #[deriving(Clone)] pub struct CompositorChan { @@ -189,11 +186,13 @@ impl CompositorTask { /// /// FIXME(pcwalton): Probably could be less platform-specific, using the metadata abstraction. #[cfg(target_os="linux")] - pub fn create_graphics_context() -> NativeCompositingGraphicsContext { - NativeCompositingGraphicsContext::from_display(azure_hl::current_display()) + pub fn create_graphics_context(native_metadata: &NativeGraphicsMetadata) + -> NativeCompositingGraphicsContext { + NativeCompositingGraphicsContext::from_display(native_metadata.display) } #[cfg(not(target_os="linux"))] - pub fn create_graphics_context() -> NativeCompositingGraphicsContext { + pub fn create_graphics_context(_: &NativeGraphicsMetadata) + -> NativeCompositingGraphicsContext { NativeCompositingGraphicsContext::new() } diff --git a/components/compositing/windowing.rs b/components/compositing/windowing.rs index 5091ee50f15..915a15d77b8 100644 --- a/components/compositing/windowing.rs +++ b/components/compositing/windowing.rs @@ -8,6 +8,7 @@ use geom::point::TypedPoint2D; use geom::scale_factor::ScaleFactor; use geom::size::TypedSize2D; use layers::geometry::DevicePixel; +use layers::platform::surface::NativeGraphicsMetadata; use servo_msg::compositor_msg::{ReadyState, RenderState}; use servo_util::geometry::ScreenPx; @@ -71,5 +72,8 @@ pub trait WindowMethods { /// Returns the hidpi factor of the monitor. fn hidpi_factor(&self) -> ScaleFactor; + + /// Gets the OS native graphics information for this window. + fn native_metadata(&self) -> NativeGraphicsMetadata; } diff --git a/ports/android/glut_app/Cargo.lock b/ports/android/glut_app/Cargo.lock index 40c7a67d695..c3036937ad4 100644 --- a/ports/android/glut_app/Cargo.lock +++ b/ports/android/glut_app/Cargo.lock @@ -4,6 +4,7 @@ version = "0.0.1" dependencies = [ "alert 0.1.0 (git+https://github.com/servo/rust-alert#fdc24f13be8d8a2d15214ec228d166b3221b809e)", "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)", "glut 0.0.1 (git+https://github.com/servo/rust-glut#01af0162ea0322ad1a40d6adb023a39813605949)", "layers 0.1.0 (git+https://github.com/servo/rust-layers#eac91e00db9af155f3004b408a18cb6d9f462a25)", diff --git a/ports/android/glut_app/Cargo.toml b/ports/android/glut_app/Cargo.toml index a4372c4a910..ed9cc080fce 100644 --- a/ports/android/glut_app/Cargo.toml +++ b/ports/android/glut_app/Cargo.toml @@ -32,3 +32,6 @@ default-features = false [dependencies.util] path = "../../../components/util" + +[dependencies.egl] +git = "https://github.com/servo/rust-egl" diff --git a/ports/android/glut_app/lib.rs b/ports/android/glut_app/lib.rs index 232ad20c80f..07eefc7132e 100644 --- a/ports/android/glut_app/lib.rs +++ b/ports/android/glut_app/lib.rs @@ -10,6 +10,7 @@ extern crate alert; extern crate compositing; +extern crate egl; extern crate geom; extern crate glut; extern crate layers; diff --git a/ports/android/glut_app/window.rs b/ports/android/glut_app/window.rs index a9e06af2ccb..de5c7063eac 100644 --- a/ports/android/glut_app/window.rs +++ b/ports/android/glut_app/window.rs @@ -18,6 +18,7 @@ use geom::point::{Point2D, TypedPoint2D}; use geom::scale_factor::ScaleFactor; use geom::size::TypedSize2D; use layers::geometry::DevicePixel; +use layers::platform::surface::NativeGraphicsMetadata; use msg::compositor_msg::{IdleRenderState, RenderState, RenderingRenderState}; use msg::compositor_msg::{FinishedLoading, Blank, ReadyState}; use util::geometry::ScreenPx; @@ -187,6 +188,13 @@ impl WindowMethods for Window { //FIXME: Do nothing in GLUT now. ScaleFactor(1.0) } + + fn native_metadata(&self) -> NativeGraphicsMetadata { + use egl::egl::GetCurrentDisplay; + NativeGraphicsMetadata { + display: GetCurrentDisplay(), + } + } } impl Window { diff --git a/ports/cef/Cargo.lock b/ports/cef/Cargo.lock index e8a382ae607..35949fc4085 100644 --- a/ports/cef/Cargo.lock +++ b/ports/cef/Cargo.lock @@ -226,6 +226,7 @@ dependencies = [ "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)", "msg 0.0.1", + "opengles 0.1.0 (git+https://github.com/servo/rust-opengles#6776e9c07feb149d34b087039ecf6b2c143e3afc)", "util 0.0.1", ] diff --git a/ports/glfw/Cargo.toml b/ports/glfw/Cargo.toml index 3212bd428ac..044f27c727c 100644 --- a/ports/glfw/Cargo.toml +++ b/ports/glfw/Cargo.toml @@ -28,3 +28,6 @@ path = "../../components/msg" [dependencies.util] path = "../../components/util" + +[dependencies.opengles] +git = "https://github.com/servo/rust-opengles" diff --git a/ports/glfw/lib.rs b/ports/glfw/lib.rs index 9c6013a28d0..f70749a62fa 100644 --- a/ports/glfw/lib.rs +++ b/ports/glfw/lib.rs @@ -17,6 +17,7 @@ extern crate libc; extern crate msg; extern crate time; extern crate util; +extern crate opengles; use geom::scale_factor::ScaleFactor; use std::rc::Rc; diff --git a/ports/glfw/window.rs b/ports/glfw/window.rs index 597175ebfac..076dbe397e9 100644 --- a/ports/glfw/window.rs +++ b/ports/glfw/window.rs @@ -17,6 +17,7 @@ use geom::scale_factor::ScaleFactor; use geom::size::TypedSize2D; use glfw::{mod, Context}; use layers::geometry::DevicePixel; +use layers::platform::surface::NativeGraphicsMetadata; use libc::c_int; use msg::compositor_msg::{IdleRenderState, RenderState, RenderingRenderState}; use msg::compositor_msg::{FinishedLoading, Blank, Loading, PerformingLayout, ReadyState}; @@ -151,6 +152,23 @@ impl WindowMethods for Window { let window_size = self.size().width.get(); 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 {