diff --git a/ports/libsimpleservo/src/api.rs b/ports/libsimpleservo/src/api.rs index a271dda59e4..57c6d644500 100644 --- a/ports/libsimpleservo/src/api.rs +++ b/ports/libsimpleservo/src/api.rs @@ -39,6 +39,9 @@ pub trait HostTrait { /// Will be called from the thread used for the init call. /// Will be called when the GL buffer has been updated. fn flush(&self); + /// Will be called before drawing. + /// Time to make the targetted GL context current. + fn make_current(&self); /// Page starts loading. /// "Reload button" should be disabled. /// "Stop button" should be enabled. @@ -353,6 +356,7 @@ impl WindowMethods for ServoCallbacks { _height: Length, ) -> bool { debug!("WindowMethods::prepare_for_composite"); + self.host_callbacks.make_current(); true } diff --git a/ports/libsimpleservo/src/capi.rs b/ports/libsimpleservo/src/capi.rs index cbd4f36108c..89ffe408759 100644 --- a/ports/libsimpleservo/src/capi.rs +++ b/ports/libsimpleservo/src/capi.rs @@ -28,6 +28,7 @@ fn call(f: F) where F: Fn(&mut ServoGlue) -> Result<(), &'static str> { #[repr(C)] pub struct CHostCallbacks { pub flush: extern fn(), + pub make_current: extern fn(), pub on_load_started: extern fn(), pub on_load_ended: extern fn(), pub on_title_changed: extern fn(title: *const c_char), @@ -223,6 +224,11 @@ impl HostTrait for HostCallbacks { (self.0.flush)(); } + fn make_current(&self) { + debug!("make_current"); + (self.0.make_current)(); + } + fn on_load_started(&self) { debug!("on_load_ended"); (self.0.on_load_started)(); diff --git a/ports/libsimpleservo/src/jniapi.rs b/ports/libsimpleservo/src/jniapi.rs index 84649659e81..1e338eb8569 100644 --- a/ports/libsimpleservo/src/jniapi.rs +++ b/ports/libsimpleservo/src/jniapi.rs @@ -277,6 +277,13 @@ impl HostTrait for HostCallbacks { .unwrap(); } + fn make_current(&self) { + debug!("make_current"); + let env = self.jvm.get_env().unwrap(); + env.call_method(self.callbacks.as_obj(), "makeCurrent", "()V", &[]) + .unwrap(); + } + fn on_load_started(&self) { debug!("on_load_started"); let env = self.jvm.get_env().unwrap();