From 53fcc98585807b43e049718b1d04d89733cc846a Mon Sep 17 00:00:00 2001 From: Jonathan Schwender <55576758+jschwe@users.noreply.github.com> Date: Wed, 29 Jan 2025 16:45:17 +0100 Subject: ohos: Support resizing the surface (#35158) A window resize requires to also resize the webview, otherwise it will stay at the original size. Signed-off-by: Jonathan Schwender --- ports/servoshell/egl/ohos/simpleservo.rs | 33 ++++++++++++++------------------ 1 file changed, 14 insertions(+), 19 deletions(-) (limited to 'ports/servoshell/egl/ohos') diff --git a/ports/servoshell/egl/ohos/simpleservo.rs b/ports/servoshell/egl/ohos/simpleservo.rs index 3498531a949..ff0a37c6105 100644 --- a/ports/servoshell/egl/ohos/simpleservo.rs +++ b/ports/servoshell/egl/ohos/simpleservo.rs @@ -9,7 +9,6 @@ use std::rc::Rc; use log::{debug, info}; use servo::compositing::CompositeTarget; -use servo::euclid::Size2D; use servo::webrender_traits::SurfmanRenderingContext; /// The EventLoopWaker::wake function will be called from any thread. /// It will be called to notify embedder that some events are available, @@ -17,7 +16,7 @@ use servo::webrender_traits::SurfmanRenderingContext; pub use servo::EventLoopWaker; use servo::{self, resources, Servo}; use surfman::{Connection, SurfaceType}; -use xcomponent_sys::{OH_NativeXComponent, OH_NativeXComponent_GetXComponentSize}; +use xcomponent_sys::OH_NativeXComponent; use crate::egl::host_trait::HostTrait; use crate::egl::ohos::resources::ResourceReaderInstance; @@ -68,24 +67,13 @@ pub fn init( .create_adapter() .or(Err("Failed to create adapter"))?; - let mut width: u64 = 0; - let mut height: u64 = 0; - let res = unsafe { - OH_NativeXComponent_GetXComponentSize( - xcomponent, - native_window, - &mut width as *mut _, - &mut height as *mut _, - ) + let Ok(window_size) = (unsafe { super::get_xcomponent_size(xcomponent, native_window) }) else { + return Err("Failed to get xcomponent size"); }; - assert_eq!(res, 0, "OH_NativeXComponent_GetXComponentSize failed"); - let width: i32 = width.try_into().expect("Width too large"); - let height: i32 = height.try_into().expect("Height too large"); - debug!("Creating surfman widget with width {width} and height {height}"); - let native_widget = unsafe { - connection.create_native_widget_from_ptr(native_window, Size2D::new(width, height)) - }; + debug!("Creating surfman widget with {window_size:?}"); + let native_widget = + unsafe { connection.create_native_widget_from_ptr(native_window, window_size) }; let surface_type = SurfaceType::Widget { native_widget }; info!("Creating rendering context"); @@ -102,7 +90,14 @@ pub fn init( let window_callbacks = Rc::new(ServoWindowCallbacks::new( callbacks, - RefCell::new(Coordinates::new(0, 0, width, height, width, height)), + RefCell::new(Coordinates::new( + 0, + 0, + window_size.width, + window_size.height, + window_size.width, + window_size.height, + )), options.display_density as f32, )); -- cgit v1.2.3