mirror of
https://github.com/servo/servo.git
synced 2025-09-27 23:30:08 +01:00
Servoshell: Refactor save_output_image and implement into OHOS (#37237)
Split out `save_output_image_if_necessary` into its own file so the code can be shared by servoshell on the desktop and ohos. Additionally, hook it up to the loop in OHOS and have OHOS allow exiting. Testing: Manual testing on ohos and desktop. --------- Signed-off-by: Narfinger <Narfinger@users.noreply.github.com>
This commit is contained in:
parent
f60c857fcf
commit
5114e24db1
6 changed files with 75 additions and 31 deletions
|
@ -25,6 +25,7 @@ use servo::{
|
|||
use url::Url;
|
||||
|
||||
use crate::egl::host_trait::HostTrait;
|
||||
use crate::output_image::save_output_image_if_necessary;
|
||||
use crate::prefs::ServoShellPreferences;
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
|
@ -718,8 +719,14 @@ impl RunningAppState {
|
|||
pub fn present_if_needed(&self) {
|
||||
if self.inner().need_present {
|
||||
self.inner_mut().need_present = false;
|
||||
self.active_webview().paint();
|
||||
if !self.active_webview().paint() {
|
||||
return;
|
||||
}
|
||||
save_output_image_if_necessary(&self.servoshell_preferences, &self.rendering_context);
|
||||
self.rendering_context.present();
|
||||
if self.servoshell_preferences.exit_after_stable_image {
|
||||
self.request_shutdown();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -123,6 +123,8 @@ const PROMPT_QUEUE_SIZE: usize = 4;
|
|||
static SET_URL_BAR_CB: OnceLock<
|
||||
ThreadsafeFunction<String, (), String, false, false, UPDATE_URL_QUEUE_SIZE>,
|
||||
> = OnceLock::new();
|
||||
static TERMINATE_CALLBACK: OnceLock<ThreadsafeFunction<(), (), (), false, false, 1>> =
|
||||
OnceLock::new();
|
||||
static PROMPT_TOAST: OnceLock<
|
||||
ThreadsafeFunction<String, (), String, false, false, PROMPT_QUEUE_SIZE>,
|
||||
> = OnceLock::new();
|
||||
|
@ -601,6 +603,15 @@ pub fn register_url_callback(callback: Function<String, ()>) -> napi_ohos::Resul
|
|||
})
|
||||
}
|
||||
|
||||
#[napi(js_name = "registerTerminateCallback")]
|
||||
pub fn register_terminate_callback(callback: Function<(), ()>) -> napi_ohos::Result<()> {
|
||||
let tsfn_builder = callback.build_threadsafe_function();
|
||||
let function = tsfn_builder.max_queue_size::<1>().build()?;
|
||||
TERMINATE_CALLBACK
|
||||
.set(function)
|
||||
.map_err(|_| napi_ohos::Error::from_reason("Failed to set terminate function"))
|
||||
}
|
||||
|
||||
#[napi]
|
||||
pub fn register_prompt_toast_callback(callback: Function<String, ()>) -> napi_ohos::Result<()> {
|
||||
debug!("register_prompt_toast_callback called!");
|
||||
|
@ -850,7 +861,13 @@ impl HostTrait for HostCallbacks {
|
|||
// todo: should we tell the vsync thread that it should perform updates?
|
||||
}
|
||||
|
||||
fn on_shutdown_complete(&self) {}
|
||||
fn on_shutdown_complete(&self) {
|
||||
if let Some(terminate_fn) = TERMINATE_CALLBACK.get() {
|
||||
terminate_fn.call((), ThreadsafeFunctionCallMode::Blocking);
|
||||
} else {
|
||||
error!("Could not shut down despite servo shutting down");
|
||||
}
|
||||
}
|
||||
|
||||
/// Shows the Inputmethod
|
||||
///
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue