mirror of
https://github.com/servo/servo.git
synced 2025-08-04 13:10:20 +01:00
add window member to servo cef browser object to fix framebuffer size method
platforms other than macos will not need/use a get_backing_rect() method since there is no virtual pixel scaling, and this method will need to be usable even before browsers are finished setting up, so ensure we can at least pass initial window size back also check method pointer availability before calling into a null function
This commit is contained in:
parent
e5a274b467
commit
1cd850b121
2 changed files with 45 additions and 13 deletions
|
@ -18,6 +18,7 @@ use glutin_app;
|
||||||
use libc::c_int;
|
use libc::c_int;
|
||||||
use std::cell::{Cell, RefCell, BorrowState};
|
use std::cell::{Cell, RefCell, BorrowState};
|
||||||
use std::ptr;
|
use std::ptr;
|
||||||
|
use std::rc::Rc;
|
||||||
use std::sync::atomic::{AtomicIsize, Ordering};
|
use std::sync::atomic::{AtomicIsize, Ordering};
|
||||||
|
|
||||||
thread_local!(pub static ID_COUNTER: AtomicIsize = AtomicIsize::new(0));
|
thread_local!(pub static ID_COUNTER: AtomicIsize = AtomicIsize::new(0));
|
||||||
|
@ -87,6 +88,8 @@ pub struct ServoCefBrowser {
|
||||||
pub host: CefBrowserHost,
|
pub host: CefBrowserHost,
|
||||||
/// A reference to the browser client.
|
/// A reference to the browser client.
|
||||||
pub client: CefClient,
|
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.
|
/// Whether the on-created callback has fired yet.
|
||||||
pub callback_executed: Cell<bool>,
|
pub callback_executed: Cell<bool>,
|
||||||
/// the display system window handle: only to be used with host.get_window_handle()
|
/// 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 frame = ServoCefFrame::new().as_cef_interface();
|
||||||
let host = ServoCefBrowserHost::new(client.clone()).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 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 servo_browser = if window_info.windowless_rendering_enabled == 0 {
|
||||||
let glutin_window = glutin_app::create_window(window_info.parent_window as glutin_app::WindowID);
|
glutin_window = Some(glutin_app::create_window(window_info.parent_window as glutin_app::WindowID));
|
||||||
let servo_browser = Browser::new(Some(glutin_window.clone()));
|
let servo_browser = Browser::new(glutin_window.clone());
|
||||||
window_handle = glutin_window.platform_window() as cef_window_handle_t;
|
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)
|
ServoBrowser::OnScreen(servo_browser)
|
||||||
} else {
|
} else {
|
||||||
ServoBrowser::Invalid
|
ServoBrowser::Invalid
|
||||||
|
@ -120,6 +127,7 @@ impl ServoCefBrowser {
|
||||||
frame: frame,
|
frame: frame,
|
||||||
host: host,
|
host: host,
|
||||||
client: client,
|
client: client,
|
||||||
|
window: glutin_window,
|
||||||
callback_executed: Cell::new(false),
|
callback_executed: Cell::new(false),
|
||||||
servo_browser: RefCell::new(servo_browser),
|
servo_browser: RefCell::new(servo_browser),
|
||||||
message_queue: RefCell::new(vec!()),
|
message_queue: RefCell::new(vec!()),
|
||||||
|
@ -139,9 +147,9 @@ pub trait ServoCefBrowserExtensions {
|
||||||
impl ServoCefBrowserExtensions for CefBrowser {
|
impl ServoCefBrowserExtensions for CefBrowser {
|
||||||
fn init(&self, window_info: &cef_window_info_t) {
|
fn init(&self, window_info: &cef_window_info_t) {
|
||||||
if window_info.windowless_rendering_enabled != 0 {
|
if window_info.windowless_rendering_enabled != 0 {
|
||||||
let window = window::Window::new();
|
let window = window::Window::new(window_info.width, window_info.height);
|
||||||
let servo_browser = Browser::new(Some(window.clone()));
|
|
||||||
window.set_browser(self.clone());
|
window.set_browser(self.clone());
|
||||||
|
let servo_browser = Browser::new(Some(window.clone()));
|
||||||
*self.downcast().servo_browser.borrow_mut() = ServoBrowser::OffScreen(servo_browser);
|
*self.downcast().servo_browser.borrow_mut() = ServoBrowser::OffScreen(servo_browser);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -43,6 +43,7 @@ pub static mut DISPLAY: *mut c_void = 0 as *mut c_void;
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct Window {
|
pub struct Window {
|
||||||
cef_browser: RefCell<Option<CefBrowser>>,
|
cef_browser: RefCell<Option<CefBrowser>>,
|
||||||
|
size: TypedSize2D<DevicePixel,u32>
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(target_os="macos")]
|
#[cfg(target_os="macos")]
|
||||||
|
@ -77,11 +78,12 @@ fn load_gl() {
|
||||||
|
|
||||||
impl Window {
|
impl Window {
|
||||||
/// Creates a new window.
|
/// Creates a new window.
|
||||||
pub fn new() -> Rc<Window> {
|
pub fn new(width: u32, height: u32) -> Rc<Window> {
|
||||||
load_gl();
|
load_gl();
|
||||||
|
|
||||||
Rc::new(Window {
|
Rc::new(Window {
|
||||||
cef_browser: RefCell::new(None),
|
cef_browser: RefCell::new(None),
|
||||||
|
size: TypedSize2D(width, height)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -166,17 +168,39 @@ impl WindowMethods for Window {
|
||||||
fn framebuffer_size(&self) -> TypedSize2D<DevicePixel,u32> {
|
fn framebuffer_size(&self) -> TypedSize2D<DevicePixel,u32> {
|
||||||
let browser = self.cef_browser.borrow();
|
let browser = self.cef_browser.borrow();
|
||||||
match *browser {
|
match *browser {
|
||||||
None => TypedSize2D(400, 300),
|
None => self.size,
|
||||||
Some(ref browser) => {
|
Some(ref browser) => {
|
||||||
|
if browser.downcast().callback_executed.get() != true {
|
||||||
|
self.size
|
||||||
|
} else {
|
||||||
let mut rect = cef_rect_t::zero();
|
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()
|
browser.get_host()
|
||||||
.get_client()
|
.get_client()
|
||||||
.get_render_handler()
|
.get_render_handler()
|
||||||
.get_backing_rect((*browser).clone(), &mut rect);
|
.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)
|
TypedSize2D(rect.width as u32, rect.height as u32)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn size(&self) -> TypedSize2D<ScreenPx,f32> {
|
fn size(&self) -> TypedSize2D<ScreenPx,f32> {
|
||||||
let browser = self.cef_browser.borrow();
|
let browser = self.cef_browser.borrow();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue