From 5697d9ff2c1cfc831e1bc5c9c7c77502a87e2c68 Mon Sep 17 00:00:00 2001 From: Mike Blumenkrantz Date: Tue, 19 May 2015 13:10:23 -0400 Subject: [PATCH] add back browser_host::composite() method for embedding this changes the way that applications will use servo. whereas previously it was only necessary to call initialize() -> makecurrent, it's now necessary to explicitly call the composite() method in order to trigger the gl rendering. any other composite attempts (by servo) will trigger the on_paint() method, informing the app that a frame is ready. it's then up to the app to schedule the composite() such that the frame is rendered in a timely manner --- ports/cef/browser_host.rs | 11 ++++++++++- ports/cef/window.rs | 15 ++++++++++++--- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/ports/cef/browser_host.rs b/ports/cef/browser_host.rs index b9112db85c9..680f7e8b99b 100644 --- a/ports/cef/browser_host.rs +++ b/ports/cef/browser_host.rs @@ -15,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>, /// A reference to the client. pub client: CefClient, + /// flag for return value of prepare_for_composite + pub composite_ok: Cell, } full_cef_class_impl! { @@ -176,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(); @@ -189,6 +197,7 @@ impl ServoCefBrowserHost { ServoCefBrowserHost { browser: RefCell::new(None), client: client, + composite_ok: Cell::new(false), } } diff --git a/ports/cef/window.rs b/ports/cef/window.rs index 827e067c7fa..a73f2253fe8 100644 --- a/ports/cef/window.rs +++ b/ports/cef/window.rs @@ -296,12 +296,21 @@ impl WindowMethods for Window { 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(), width, height); + 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 + } } } - true } fn load_end(&self) {