Auto merge of #6125 - zmike:renderrenderrenderrender, r=larsbergstrom

A collection of commits which improves embedding integration and rendering.

@larsbergstrom

<!-- Reviewable:start -->
[<img src="https://reviewable.io/review_button.png" height=40 alt="Review on Reviewable"/>](https://reviewable.io/reviews/servo/servo/6125)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2015-05-24 19:26:00 -05:00
commit 4a95bce9f2
18 changed files with 264 additions and 111 deletions

View file

@ -1288,8 +1288,13 @@ impl<Window: WindowMethods> IOCompositor<Window> {
self.composite_specific_target(target);
}
fn composite_specific_target(&mut self, target: CompositeTarget) -> Option<png::Image> {
if !self.window.prepare_for_composite() {
pub fn composite_specific_target(&mut self, target: CompositeTarget) -> Option<png::Image> {
if !self.context.is_some() {
return None
}
let (width, height) =
(self.window_size.width.get() as usize, self.window_size.height.get() as usize);
if !self.window.prepare_for_composite(width, height) {
return None
}
@ -1302,9 +1307,6 @@ impl<Window: WindowMethods> IOCompositor<Window> {
_ => {}
}
let (width, height) =
(self.window_size.width.get() as usize, self.window_size.height.get() as usize);
let (framebuffer_ids, texture_ids) = match target {
CompositeTarget::Window => (vec!(), vec!()),
_ => initialize_png(width, height)

View file

@ -123,7 +123,7 @@ pub trait WindowMethods {
/// Requests that the window system prepare a composite. Typically this will involve making
/// some type of platform-specific graphics context current. Returns true if the composite may
/// proceed and false if it should not.
fn prepare_for_composite(&self) -> bool;
fn prepare_for_composite(&self, width: usize, height: usize) -> bool;
/// Sets the cursor to be used in the window.
fn set_cursor(&self, cursor: Cursor);

View file

@ -443,7 +443,7 @@ dependencies = [
[[package]]
name = "glutin"
version = "0.0.26"
source = "git+https://github.com/servo/glutin?branch=servo#ec7a5e40c1cc7b8176eb1e1f7bf70c8a19559400"
source = "git+https://github.com/servo/glutin?branch=servo#e888dc79471f062ae0b5fae0ba9e0f01ac96048e"
dependencies = [
"android_glue 0.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
"gdi32-sys 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
@ -460,7 +460,7 @@ dependencies = [
"osmesa-sys 0.0.5 (registry+https://github.com/rust-lang/crates.io-index)",
"user32-sys 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
"winapi 0.1.17 (registry+https://github.com/rust-lang/crates.io-index)",
"x11 0.0.33 (registry+https://github.com/rust-lang/crates.io-index)",
"x11 1.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
@ -481,6 +481,7 @@ dependencies = [
"time 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)",
"url 0.2.33 (registry+https://github.com/rust-lang/crates.io-index)",
"util 0.0.1",
"x11 1.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
@ -616,7 +617,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "layers"
version = "0.1.0"
source = "git+https://github.com/servo/rust-layers#ff65707d621498949ed428077da7e42a9f9d2745"
source = "git+https://github.com/servo/rust-layers#cfc29e48a11f0c1e5390a049850c3ba10f23e0ad"
dependencies = [
"azure 0.1.0 (git+https://github.com/servo/rust-azure)",
"cgl 0.0.1 (git+https://github.com/servo/rust-cgl)",
@ -630,7 +631,7 @@ dependencies = [
"log 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
"rustc-serialize 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)",
"skia 0.0.20130412 (git+https://github.com/servo/skia)",
"xlib 0.1.0 (git+https://github.com/servo/rust-xlib)",
"x11 1.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
@ -843,7 +844,7 @@ dependencies = [
[[package]]
name = "offscreen_gl_context"
version = "0.0.1"
source = "git+https://github.com/ecoal95/rust-offscreen-rendering-context#97eacf34b72f69b10130a0de016529e98ee32f04"
source = "git+https://github.com/ecoal95/rust-offscreen-rendering-context#99cee719a811f28e70fe33fa71137663ac210487"
dependencies = [
"cgl 0.0.1 (git+https://github.com/servo/rust-cgl)",
"core_foundation 0.1.0 (git+https://github.com/servo/rust-core-foundation)",
@ -853,7 +854,7 @@ dependencies = [
"layers 0.1.0 (git+https://github.com/servo/rust-layers)",
"libc 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
"xlib 0.1.0 (git+https://github.com/servo/rust-xlib)",
"x11 1.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
@ -1329,10 +1330,11 @@ dependencies = [
[[package]]
name = "x11"
version = "0.0.33"
version = "1.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"libc 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)",
"pkg-config 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]

25
ports/cef/Cargo.lock generated
View file

@ -29,7 +29,7 @@ dependencies = [
"style 0.0.1",
"url 0.2.33 (registry+https://github.com/rust-lang/crates.io-index)",
"util 0.0.1",
"x11 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
"x11 1.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
@ -445,7 +445,7 @@ dependencies = [
[[package]]
name = "glutin"
version = "0.0.26"
source = "git+https://github.com/servo/glutin?branch=servo#ec7a5e40c1cc7b8176eb1e1f7bf70c8a19559400"
source = "git+https://github.com/servo/glutin?branch=servo#e888dc79471f062ae0b5fae0ba9e0f01ac96048e"
dependencies = [
"android_glue 0.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
"gdi32-sys 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
@ -462,7 +462,7 @@ dependencies = [
"osmesa-sys 0.0.5 (registry+https://github.com/rust-lang/crates.io-index)",
"user32-sys 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
"winapi 0.1.17 (registry+https://github.com/rust-lang/crates.io-index)",
"x11 0.0.33 (registry+https://github.com/rust-lang/crates.io-index)",
"x11 1.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
@ -483,6 +483,7 @@ dependencies = [
"time 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)",
"url 0.2.33 (registry+https://github.com/rust-lang/crates.io-index)",
"util 0.0.1",
"x11 1.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
@ -618,7 +619,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "layers"
version = "0.1.0"
source = "git+https://github.com/servo/rust-layers#ff65707d621498949ed428077da7e42a9f9d2745"
source = "git+https://github.com/servo/rust-layers#cfc29e48a11f0c1e5390a049850c3ba10f23e0ad"
dependencies = [
"azure 0.1.0 (git+https://github.com/servo/rust-azure)",
"cgl 0.0.1 (git+https://github.com/servo/rust-cgl)",
@ -632,7 +633,7 @@ dependencies = [
"log 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
"rustc-serialize 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)",
"skia 0.0.20130412 (git+https://github.com/servo/skia)",
"xlib 0.1.0 (git+https://github.com/servo/rust-xlib)",
"x11 1.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
@ -833,7 +834,7 @@ dependencies = [
[[package]]
name = "offscreen_gl_context"
version = "0.0.1"
source = "git+https://github.com/ecoal95/rust-offscreen-rendering-context#97eacf34b72f69b10130a0de016529e98ee32f04"
source = "git+https://github.com/ecoal95/rust-offscreen-rendering-context#99cee719a811f28e70fe33fa71137663ac210487"
dependencies = [
"cgl 0.0.1 (git+https://github.com/servo/rust-cgl)",
"core_foundation 0.1.0 (git+https://github.com/servo/rust-core-foundation)",
@ -843,7 +844,7 @@ dependencies = [
"layers 0.1.0 (git+https://github.com/servo/rust-layers)",
"libc 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
"xlib 0.1.0 (git+https://github.com/servo/rust-xlib)",
"x11 1.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
@ -1314,15 +1315,7 @@ dependencies = [
[[package]]
name = "x11"
version = "0.0.33"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"libc 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "x11"
version = "1.0.0"
version = "1.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"libc 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)",

View file

@ -18,6 +18,7 @@ use glutin_app;
use libc::c_int;
use std::cell::{Cell, RefCell, BorrowState};
use std::ptr;
use std::rc::Rc;
use std::sync::atomic::{AtomicIsize, Ordering};
thread_local!(pub static ID_COUNTER: AtomicIsize = AtomicIsize::new(0));
@ -87,6 +88,8 @@ pub struct ServoCefBrowser {
pub host: CefBrowserHost,
/// A reference to the browser client.
pub client: CefClient,
/// the glutin window when using windowed rendering
pub window: Option<Rc<glutin_app::window::Window>>,
/// Whether the on-created callback has fired yet.
pub callback_executed: Cell<bool>,
/// the display system window handle: only to be used with host.get_window_handle()
@ -102,11 +105,15 @@ impl ServoCefBrowser {
let frame = ServoCefFrame::new().as_cef_interface();
let host = ServoCefBrowserHost::new(client.clone()).as_cef_interface();
let mut window_handle: cef_window_handle_t = get_null_window_handle();
let mut glutin_window: Option<Rc<glutin_app::window::Window>> = None;
let servo_browser = if window_info.windowless_rendering_enabled == 0 {
let glutin_window = glutin_app::create_window(window_info.parent_window as glutin_app::WindowID);
let servo_browser = Browser::new(Some(glutin_window.clone()));
window_handle = glutin_window.platform_window() as cef_window_handle_t;
glutin_window = Some(glutin_app::create_window(window_info.parent_window as glutin_app::WindowID));
let servo_browser = Browser::new(glutin_window.clone());
window_handle = match glutin_window {
Some(ref win) => win.platform_window() as cef_window_handle_t,
None => get_null_window_handle()
};
ServoBrowser::OnScreen(servo_browser)
} else {
ServoBrowser::Invalid
@ -120,6 +127,7 @@ impl ServoCefBrowser {
frame: frame,
host: host,
client: client,
window: glutin_window,
callback_executed: Cell::new(false),
servo_browser: RefCell::new(servo_browser),
message_queue: RefCell::new(vec!()),
@ -139,9 +147,9 @@ pub trait ServoCefBrowserExtensions {
impl ServoCefBrowserExtensions for CefBrowser {
fn init(&self, window_info: &cef_window_info_t) {
if window_info.windowless_rendering_enabled != 0 {
let window = window::Window::new();
let servo_browser = Browser::new(Some(window.clone()));
let window = window::Window::new(window_info.width, window_info.height);
window.set_browser(self.clone());
let servo_browser = Browser::new(Some(window.clone()));
*self.downcast().servo_browser.borrow_mut() = ServoBrowser::OffScreen(servo_browser);
}
@ -198,7 +206,16 @@ pub fn update() {
if browser.downcast().callback_executed.get() == false {
browser_callback_after_created(browser.clone());
}
browser.send_window_event(WindowEvent::Idle);
let mut events = match browser.downcast().window {
Some(ref win) => win.wait_events(),
None => vec![WindowEvent::Idle]
};
loop {
match events.pop() {
Some(event) => browser.send_window_event(event),
None => break
}
}
}
});
}
@ -238,9 +255,9 @@ fn browser_host_create(window_info: &cef_window_info_t,
if callback_executed {
browser_callback_after_created(browser.clone());
}
if url != ptr::null() {
unsafe { browser.downcast().frame.load_url(CefWrap::to_rust(url)); }
}
//if url != ptr::null() {
//unsafe { browser.downcast().frame.load_url(CefWrap::to_rust(url)); }
//}
BROWSERS.with(|browsers| {
browsers.borrow_mut().push(browser.clone());
});

View file

@ -7,6 +7,7 @@ use interfaces::{CefBrowser, CefBrowserHost, CefClient, cef_browser_t, cef_brows
use types::{cef_mouse_button_type_t, cef_mouse_event, cef_rect_t, cef_key_event, cef_window_handle_t};
use types::cef_key_event_type_t::{KEYEVENT_CHAR, KEYEVENT_KEYDOWN, KEYEVENT_KEYUP, KEYEVENT_RAWKEYDOWN};
use browser::{self, ServoCefBrowserExtensions};
use wrappers::CefWrap;
use compositing::windowing::{WindowEvent, MouseWindowEvent};
use geom::point::TypedPoint2D;
@ -14,13 +15,15 @@ use geom::size::TypedSize2D;
use libc::{c_double, c_int};
use msg::constellation_msg::{self, KeyModifiers, KeyState};
use script_traits::MouseButton;
use std::cell::RefCell;
use std::cell::{Cell, RefCell};
pub struct ServoCefBrowserHost {
/// A reference to the browser.
pub browser: RefCell<Option<CefBrowser>>,
/// A reference to the client.
pub client: CefClient,
/// flag for return value of prepare_for_composite
pub composite_ok: Cell<bool>,
}
full_cef_class_impl! {
@ -35,9 +38,19 @@ full_cef_class_impl! {
fn was_resized(&this,) -> () {{
let mut rect = cef_rect_t::zero();
if cfg!(target_os="macos") {
if check_ptr_exist!(this.get_client(), get_render_handler) &&
check_ptr_exist!(this.get_client().get_render_handler(), get_backing_rect) {
this.get_client()
.get_render_handler()
.get_backing_rect(this.downcast().browser.borrow().clone().unwrap(), &mut rect);
}
} else if check_ptr_exist!(this.get_client(), get_render_handler) &&
check_ptr_exist!(this.get_client().get_render_handler(), get_view_rect) {
this.get_client()
.get_render_handler()
.get_view_rect(this.downcast().browser.borrow().clone().unwrap(), &mut rect);
}
let size = TypedSize2D(rect.width as u32, rect.height as u32);
this.downcast().send_window_event(WindowEvent::Resize(size));
}}
@ -165,6 +178,12 @@ full_cef_class_impl! {
this.downcast().send_window_event(WindowEvent::InitializeCompositing);
}}
fn composite(&this,) -> () {{
this.downcast().composite_ok.set(true);
this.downcast().send_window_event(WindowEvent::Refresh);
this.downcast().composite_ok.set(false);
}}
fn get_window_handle(&this,) -> cef_window_handle_t {{
let t = this.downcast();
let browser = t.browser.borrow();
@ -178,6 +197,7 @@ impl ServoCefBrowserHost {
ServoCefBrowserHost {
browser: RefCell::new(None),
client: client,
composite_ok: Cell::new(false),
}
}

View file

@ -5,16 +5,18 @@
use command_line::command_line_init;
use interfaces::cef_app_t;
use types::{cef_main_args_t, cef_settings_t};
use window::init_window;
use libc::{c_char, c_int, c_void};
use util::opts;
use std::ffi;
use std::str;
use browser;
use std_url::Url;
const MAX_RENDERING_THREADS: usize = 128;
//static HOME_URL: &'static str = "http://s27.postimg.org/vqbtrolyr/servo.jpg";
static HOME_URL: &'static str = "http://s27.postimg.org/vqbtrolyr/servo.jpg";
static CEF_API_HASH_UNIVERSAL: &'static [u8] = b"8efd129f4afc344bd04b2feb7f73a149b6c4e27f\0";
#[cfg(target_os="windows")]
@ -65,8 +67,13 @@ pub extern "C" fn cef_initialize(args: *const cef_main_args_t,
temp_opts.hard_fail = false;
temp_opts.enable_text_antialiasing = true;
temp_opts.resources_path = None;
temp_opts.url = Url::parse(HOME_URL).unwrap();
opts::set(temp_opts);
if unsafe { (*settings).windowless_rendering_enabled != 0 } {
init_window();
}
return 1
}

View file

@ -1320,6 +1320,13 @@ pub struct _cef_browser_host_t {
pub drag_source_system_drag_ended: Option<extern "C" fn(
this: *mut cef_browser_host_t) -> ()>,
//
// Instructs the browser to perform an accelerated composite. The appropriate
// Direct3D or OpenGL state must have been set up before calling this
// function.
//
pub composite: Option<extern "C" fn(this: *mut cef_browser_host_t) -> ()>,
//
// Instructs the browser to initialize accelerated compositing. The
// appropriate Direct3D or OpenGL state must have been set up before calling
@ -2214,6 +2221,23 @@ impl CefBrowserHost {
}
}
//
// Instructs the browser to perform an accelerated composite. The appropriate
// Direct3D or OpenGL state must have been set up before calling this
// function.
//
pub fn composite(&self) -> () {
if self.c_object.is_null() ||
self.c_object as usize == mem::POST_DROP_USIZE {
panic!("called a CEF method on a null object")
}
unsafe {
CefWrap::to_rust(
((*self.c_object).composite.unwrap())(
self.c_object))
}
}
//
// Instructs the browser to initialize accelerated compositing. The
// appropriate Direct3D or OpenGL state must have been set up before calling

View file

@ -175,7 +175,7 @@ pub struct _cef_render_handler_t {
// Called to retrieve the backing size of the view rectangle which is relative
// to screen coordinates. On HiDPI displays, the backing size can differ from
// the view size as returned by |GetViewRect|. Return true (1) if the
// rectangle was provided.
// rectangle was provided. Only used on Mac OS.
//
pub get_backing_rect: Option<extern "C" fn(this: *mut cef_render_handler_t,
browser: *mut interfaces::cef_browser_t,
@ -527,7 +527,7 @@ impl CefRenderHandler {
// Called to retrieve the backing size of the view rectangle which is relative
// to screen coordinates. On HiDPI displays, the backing size can differ from
// the view size as returned by |GetViewRect|. Return true (1) if the
// rectangle was provided.
// rectangle was provided. Only used on Mac OS.
//
pub fn get_backing_rect(&self, browser: interfaces::CefBrowser,
rect: &mut types::cef_rect_t) -> libc::c_int {

View file

@ -58,6 +58,7 @@ extern crate core_text;
#[cfg(target_os="macos")]
#[macro_use]
extern crate objc;
#[cfg(target_os="linux")] extern crate x11;
// Must come first.
pub mod macros;

View file

@ -4,6 +4,13 @@
#![macro_use]
macro_rules! check_ptr_exist {
($var:expr, $member:ident) => (
unsafe { (*CefWrap::to_c($var)).$member.is_some() }
);
}
// Provides the implementation of a CEF class. An example follows:
//
// struct ServoCefThing {

View file

@ -8,12 +8,12 @@ use types::cef_paint_element_type_t::PET_VIEW;
use std::ptr;
pub trait CefRenderHandlerExtensions {
fn paint(&self, browser: CefBrowser);
fn paint(&self, browser: CefBrowser, width: usize, height: usize);
}
impl CefRenderHandlerExtensions for CefRenderHandler {
fn paint(&self, browser: CefBrowser) {
self.on_paint(browser, PET_VIEW, 0, ptr::null(), &mut (), 0, 0)
fn paint(&self, browser: CefBrowser, width: usize, height: usize) {
self.on_paint(browser, PET_VIEW, 0, ptr::null(), &mut (), width as i32, height as i32)
}
}

View file

@ -12,6 +12,7 @@ use interfaces::CefBrowser;
use render_handler::CefRenderHandlerExtensions;
use rustc_unicode::str::Utf16Encoder;
use types::{cef_cursor_handle_t, cef_cursor_type_t, cef_rect_t};
use wrappers::CefWrap;
use compositing::compositor_task::{self, CompositorProxy, CompositorReceiver};
use compositing::windowing::{WindowEvent, WindowMethods};
@ -20,7 +21,7 @@ use geom::size::TypedSize2D;
use gleam::gl;
use layers::geometry::DevicePixel;
use layers::platform::surface::NativeGraphicsMetadata;
use libc::{c_char, c_void};
use libc::{c_char, c_int, c_void};
use msg::constellation_msg::{Key, KeyModifiers};
use std::ptr;
use std_url::Url;
@ -33,15 +34,17 @@ use std::sync::mpsc::{Sender, channel};
#[cfg(target_os="linux")]
extern crate x11;
#[cfg(target_os="linux")]
use self::x11::xlib::XOpenDisplay;
use self::x11::xlib::{XInitThreads,XOpenDisplay};
#[cfg(target_os="linux")]
pub static mut DISPLAY: *mut c_void = 0 as *mut c_void;
/// The type of an off-screen window.
#[allow(raw_pointer_derive)]
#[derive(Clone)]
pub struct Window {
cef_browser: RefCell<Option<CefBrowser>>,
#[cfg(target_os="linux")]
display: *mut c_void,
size: TypedSize2D<DevicePixel,u32>
}
#[cfg(target_os="macos")]
@ -76,21 +79,12 @@ fn load_gl() {
impl Window {
/// Creates a new window.
#[cfg(target_os="linux")]
pub fn new() -> Rc<Window> {
load_gl();
Rc::new(Window {
cef_browser: RefCell::new(None),
display: unsafe { XOpenDisplay(ptr::null()) as *mut c_void },
})
}
#[cfg(not(target_os="linux"))]
pub fn new() -> Rc<Window> {
pub fn new(width: u32, height: u32) -> Rc<Window> {
load_gl();
Rc::new(Window {
cef_browser: RefCell::new(None),
size: TypedSize2D(width, height)
})
}
@ -175,17 +169,39 @@ impl WindowMethods for Window {
fn framebuffer_size(&self) -> TypedSize2D<DevicePixel,u32> {
let browser = self.cef_browser.borrow();
match *browser {
None => TypedSize2D(400, 300),
None => self.size,
Some(ref browser) => {
if browser.downcast().callback_executed.get() != true {
self.size
} else {
let mut rect = cef_rect_t::zero();
rect.width = self.size.width.get() as i32;
rect.height = self.size.height.get() as i32;
if cfg!(target_os="macos") {
// osx relies on virtual pixel scaling to provide sizes different from actual
// pixel size on screen. other platforms are just 1.0 unless the desktop/toolkit says otherwise
if check_ptr_exist!(browser.get_host().get_client(), get_render_handler) &&
check_ptr_exist!(browser.get_host().get_client().get_render_handler(), get_backing_rect) {
browser.get_host()
.get_client()
.get_render_handler()
.get_backing_rect((*browser).clone(), &mut rect);
}
} else {
if check_ptr_exist!(browser.get_host().get_client(), get_render_handler) &&
check_ptr_exist!(browser.get_host().get_client().get_render_handler(), get_view_rect) {
browser.get_host()
.get_client()
.get_render_handler()
.get_view_rect((*browser).clone(), &mut rect);
}
}
TypedSize2D(rect.width as u32, rect.height as u32)
}
}
}
}
fn size(&self) -> TypedSize2D<ScreenPx,f32> {
let browser = self.cef_browser.borrow();
@ -207,29 +223,44 @@ impl WindowMethods for Window {
match *browser {
None => {}
Some(ref browser) => {
if check_ptr_exist!(browser.get_host().get_client(), get_render_handler) &&
check_ptr_exist!(browser.get_host().get_client().get_render_handler(), on_present) {
browser.get_host().get_client().get_render_handler().on_present(browser.clone());
}
}
}
}
fn hidpi_factor(&self) -> ScaleFactor<ScreenPx,DevicePixel,f32> {
if cfg!(target_os="macos") {
let browser = self.cef_browser.borrow();
match *browser {
None => ScaleFactor::new(1.0),
Some(ref browser) => {
let mut view_rect = cef_rect_t::zero();
if check_ptr_exist!(browser.get_host().get_client(), get_render_handler) &&
check_ptr_exist!(browser.get_host().get_client().get_render_handler(), get_view_rect) {
browser.get_host()
.get_client()
.get_render_handler()
.get_view_rect((*browser).clone(), &mut view_rect);
}
let mut backing_rect = cef_rect_t::zero();
if check_ptr_exist!(browser.get_host().get_client(), get_render_handler) &&
check_ptr_exist!(browser.get_host().get_client().get_render_handler(), get_backing_rect) {
browser.get_host()
.get_client()
.get_render_handler()
.get_backing_rect((*browser).clone(), &mut backing_rect);
}
ScaleFactor::new(backing_rect.width as f32 / view_rect.width as f32)
}
}
} else {
// FIXME(zmike)
// need to figure out a method for actually getting the scale factor instead of this nonsense
ScaleFactor::new(1.0 as f32)
}
}
#[cfg(target_os="macos")]
@ -246,8 +277,11 @@ impl WindowMethods for Window {
#[cfg(target_os="linux")]
fn native_metadata(&self) -> NativeGraphicsMetadata {
use x11::xlib;
unsafe {
NativeGraphicsMetadata {
display: self.display,
display: DISPLAY as *mut xlib::Display,
}
}
}
@ -260,15 +294,24 @@ impl WindowMethods for Window {
box receiver as Box<CompositorReceiver>)
}
fn prepare_for_composite(&self) -> bool {
fn prepare_for_composite(&self, width: usize, height: usize) -> bool {
let browser = self.cef_browser.borrow();
match *browser {
None => {}
None => {
panic!("No browser?!?");
}
Some(ref browser) => {
browser.get_host().get_client().get_render_handler().paint(browser.clone());
}
}
if browser.downcast().host.downcast().composite_ok.get() == true {
true
} else {
if check_ptr_exist!(browser.get_host().get_client(), get_render_handler) &&
check_ptr_exist!(browser.get_host().get_client().get_render_handler(), on_paint) {
browser.get_host().get_client().get_render_handler().paint(browser.clone(), width, height);
}
false
}
}
}
}
fn load_end(&self) {
@ -278,11 +321,14 @@ impl WindowMethods for Window {
None => return,
Some(ref browser) => browser,
};
if check_ptr_exist!(browser.get_host().get_client(), get_load_handler) &&
check_ptr_exist!(browser.get_host().get_client().get_load_handler(), on_load_end) {
browser.get_host()
.get_client()
.get_load_handler()
.on_load_end((*browser).clone(), browser.get_main_frame(), 200);
}
}
fn set_page_title(&self, string: Option<String>) {
let browser = self.cef_browser.borrow();
@ -332,6 +378,8 @@ impl WindowMethods for Window {
Some(ref browser) => {
let cursor_handle = self.cursor_handle_for_cursor(cursor);
let info = CefCursorInfo { hotspot: cef_point_t {x: 0, y: 0}, image_scale_factor: 0.0, buffer: 0 as *mut isize, size: cef_size_t { width: 0, height: 0 } };
if check_ptr_exist!(browser.get_host().get_client(), get_render_handler) &&
check_ptr_exist!(browser.get_host().get_client().get_render_handler(), on_cursor_change) {
browser.get_host()
.get_client()
.get_render_handler()
@ -341,6 +389,7 @@ impl WindowMethods for Window {
}
}
}
}
struct CefCompositorProxy {
sender: Sender<compositor_task::Msg>,
@ -378,7 +427,6 @@ impl CompositorProxy for CefCompositorProxy {
#[cfg(target_os="linux")]
fn send(&mut self, msg: compositor_task::Msg) {
// FIXME(pcwalton): Kick the GTK event loop awake?
self.sender.send(msg).unwrap();
}
@ -389,3 +437,23 @@ impl CompositorProxy for CefCompositorProxy {
}
}
#[cfg(target_os="linux")]
pub fn init_window() {
unsafe {
assert!(XInitThreads() != 0);
DISPLAY = XOpenDisplay(ptr::null()) as *mut c_void;
}
}
#[cfg(not(target_os="linux"))]
pub fn init_window() {}
#[cfg(target_os="linux")]
#[no_mangle]
pub extern "C" fn cef_get_xdisplay() -> *mut c_void {
unsafe { DISPLAY }
}
#[cfg(not(target_os="linux"))]
#[no_mangle]
pub extern "C" fn cef_get_xdisplay() -> *mut c_void {
ptr::null_mut()
}

View file

@ -47,3 +47,4 @@ time = "0.1.12"
bitflags = "*"
libc = "*"
url = "*"
x11 = "*"

View file

@ -21,6 +21,7 @@ extern crate time;
extern crate util;
extern crate egl;
extern crate url;
#[cfg(target_os="linux")] extern crate x11;
use compositing::windowing::WindowEvent;
use geom::scale_factor::ScaleFactor;

View file

@ -552,14 +552,15 @@ impl WindowMethods for Window {
self.window.set_cursor(glutin_cursor);
}
fn prepare_for_composite(&self) -> bool {
fn prepare_for_composite(&self, _width: usize, _height: usize) -> bool {
true
}
#[cfg(target_os="linux")]
fn native_metadata(&self) -> NativeGraphicsMetadata {
use x11::xlib;
NativeGraphicsMetadata {
display: unsafe { self.window.platform_display() }
display: unsafe { self.window.platform_display() as *mut xlib::Display }
}
}
@ -691,7 +692,7 @@ impl WindowMethods for Window {
fn set_cursor(&self, _: Cursor) {
}
fn prepare_for_composite(&self) -> bool {
fn prepare_for_composite(&self, _width: usize, _height: usize) -> bool {
true
}

17
ports/gonk/Cargo.lock generated
View file

@ -527,7 +527,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "layers"
version = "0.1.0"
source = "git+https://github.com/servo/rust-layers#ff65707d621498949ed428077da7e42a9f9d2745"
source = "git+https://github.com/servo/rust-layers#cfc29e48a11f0c1e5390a049850c3ba10f23e0ad"
dependencies = [
"azure 0.1.0 (git+https://github.com/servo/rust-azure)",
"cgl 0.0.1 (git+https://github.com/servo/rust-cgl)",
@ -541,7 +541,7 @@ dependencies = [
"log 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
"rustc-serialize 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)",
"skia 0.0.20130412 (git+https://github.com/servo/skia)",
"xlib 0.1.0 (git+https://github.com/servo/rust-xlib)",
"x11 1.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
@ -725,7 +725,7 @@ dependencies = [
[[package]]
name = "offscreen_gl_context"
version = "0.0.1"
source = "git+https://github.com/ecoal95/rust-offscreen-rendering-context#97eacf34b72f69b10130a0de016529e98ee32f04"
source = "git+https://github.com/ecoal95/rust-offscreen-rendering-context#99cee719a811f28e70fe33fa71137663ac210487"
dependencies = [
"cgl 0.0.1 (git+https://github.com/servo/rust-cgl)",
"core_foundation 0.1.0 (git+https://github.com/servo/rust-core-foundation)",
@ -735,7 +735,7 @@ dependencies = [
"layers 0.1.0 (git+https://github.com/servo/rust-layers)",
"libc 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
"xlib 0.1.0 (git+https://github.com/servo/rust-xlib)",
"x11 1.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
@ -1177,6 +1177,15 @@ dependencies = [
"libc 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "x11"
version = "1.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"libc 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)",
"pkg-config 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "xlib"
version = "0.1.0"

View file

@ -831,7 +831,7 @@ impl WindowMethods for Window {
fn set_cursor(&self, _: Cursor) {
}
fn prepare_for_composite(&self) -> bool {
fn prepare_for_composite(&self, _width: usize, _height: usize) -> bool {
true
}
}