aboutsummaryrefslogtreecommitdiffstats
path: root/ports/servoshell/egl/ohos.rs
diff options
context:
space:
mode:
Diffstat (limited to 'ports/servoshell/egl/ohos.rs')
-rw-r--r--ports/servoshell/egl/ohos.rs66
1 files changed, 58 insertions, 8 deletions
diff --git a/ports/servoshell/egl/ohos.rs b/ports/servoshell/egl/ohos.rs
index 66e568972b0..908a4c75240 100644
--- a/ports/servoshell/egl/ohos.rs
+++ b/ports/servoshell/egl/ohos.rs
@@ -26,14 +26,14 @@ use simpleservo::EventLoopWaker;
use xcomponent_sys::{
OH_NativeXComponent, OH_NativeXComponent_Callback, OH_NativeXComponent_GetKeyEvent,
OH_NativeXComponent_GetKeyEventAction, OH_NativeXComponent_GetKeyEventCode,
- OH_NativeXComponent_GetTouchEvent, OH_NativeXComponent_KeyAction, OH_NativeXComponent_KeyCode,
- OH_NativeXComponent_KeyEvent, OH_NativeXComponent_RegisterCallback,
- OH_NativeXComponent_RegisterKeyEventCallback, OH_NativeXComponent_TouchEvent,
- OH_NativeXComponent_TouchEventType,
+ OH_NativeXComponent_GetTouchEvent, OH_NativeXComponent_GetXComponentSize,
+ OH_NativeXComponent_KeyAction, OH_NativeXComponent_KeyCode, OH_NativeXComponent_KeyEvent,
+ OH_NativeXComponent_RegisterCallback, OH_NativeXComponent_RegisterKeyEventCallback,
+ OH_NativeXComponent_TouchEvent, OH_NativeXComponent_TouchEventType,
};
use super::host_trait::HostTrait;
-use super::servo_glue::ServoGlue;
+use super::servo_glue::{Coordinates, ServoGlue};
mod resources;
mod simpleservo;
@@ -104,6 +104,10 @@ pub(super) enum ServoAction {
ImeSendEnter,
Initialize(Box<InitOpts>),
Vsync,
+ Resize {
+ width: i32,
+ height: i32,
+ },
}
/// Queue length for the thread-safe function to submit URL updates to ArkTS
@@ -180,6 +184,9 @@ impl ServoAction {
servo.notify_vsync();
servo.present_if_needed();
},
+ Resize { width, height } => {
+ servo.resize(Coordinates::new(0, 0, *width, *height, *width, *height))
+ },
};
}
}
@@ -263,9 +270,52 @@ extern "C" fn on_surface_created_cb(xcomponent: *mut OH_NativeXComponent, window
info!("Returning from on_surface_created_cb");
}
-// Todo: Probably we need to block here, until the main thread has processed the change.
-extern "C" fn on_surface_changed_cb(_component: *mut OH_NativeXComponent, _window: *mut c_void) {
- error!("on_surface_changed_cb is currently not implemented!");
+/// Returns the size of the surface
+///
+/// # Safety
+///
+/// `xcomponent` and `native_window` must be valid, non-null and aligned pointers to a
+/// live xcomponent and associated native window surface.
+unsafe fn get_xcomponent_size(
+ xcomponent: *mut OH_NativeXComponent,
+ native_window: *mut c_void,
+) -> Result<euclid::default::Size2D<i32>, i32> {
+ let mut width: u64 = 0;
+ let mut height: u64 = 0;
+ let result = unsafe {
+ OH_NativeXComponent_GetXComponentSize(
+ xcomponent,
+ native_window,
+ &raw mut width,
+ &raw mut height,
+ )
+ };
+ if result != 0 {
+ debug!("OH_NativeXComponent_GetXComponentSize failed with {result}");
+ return Err(result);
+ }
+
+ let width: i32 = width.try_into().expect("Width too large");
+ let height: i32 = height.try_into().expect("Height too large");
+ Ok(euclid::Size2D::new(width, height))
+}
+
+extern "C" fn on_surface_changed_cb(
+ xcomponent: *mut OH_NativeXComponent,
+ native_window: *mut c_void,
+) {
+ debug!("on_surface_changed_cb: xc: {xcomponent:?}, window: {native_window:?}");
+ // SAFETY: We just obtained these pointers from the callback, so we can assume them to be valid.
+ if let Ok(size) = unsafe { get_xcomponent_size(xcomponent, native_window) } {
+ info!("on_surface_changed_cb: Resizing to {size:?}");
+ call(ServoAction::Resize {
+ width: size.width,
+ height: size.height,
+ })
+ .unwrap();
+ } else {
+ error!("on_surface_changed_cb: Surface changed, but failed to obtain new size")
+ }
}
extern "C" fn on_surface_destroyed_cb(_component: *mut OH_NativeXComponent, _window: *mut c_void) {