diff options
author | Martin Robinson <mrobinson@igalia.com> | 2025-02-18 15:50:41 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-02-18 14:50:41 +0000 |
commit | f34f2d9d0ab59dd4baa6a3a25849ece95861c461 (patch) | |
tree | e798148f24dc4b10bd4c3f90f0c82ddcddf3571f /ports/servoshell/egl/android.rs | |
parent | 73507f58e63b130d91fcf6f1da13e643b9c469d3 (diff) | |
download | servo-f34f2d9d0ab59dd4baa6a3a25849ece95861c461.tar.gz servo-f34f2d9d0ab59dd4baa6a3a25849ece95861c461.zip |
libservo: Expose `SoftwareRenderingContext` and `WindowRenderingContext` (#35501)
Expose two easy-to-use wrappers around `SurfmanRenderingContext` that
make the API simpler to use:
- `WindowRenderingContext`: This `RenderingContext` is a newtype around
`SurfmanRenderingContext` takes a `raw-window-handle` display and window
and creates a full window rendering context.
- `SoftwareRenderingContext`: is wraps `SurfmanRenderingContext` and
adds a swap chain in order to expose a software GL rendering context.
Signed-off-by: Martin Robinson <mrobinson@igalia.com>
Diffstat (limited to 'ports/servoshell/egl/android.rs')
-rw-r--r-- | ports/servoshell/egl/android.rs | 39 |
1 files changed, 29 insertions, 10 deletions
diff --git a/ports/servoshell/egl/android.rs b/ports/servoshell/egl/android.rs index 3b9721fb1f5..84b511b3146 100644 --- a/ports/servoshell/egl/android.rs +++ b/ports/servoshell/egl/android.rs @@ -8,6 +8,7 @@ mod resources; mod simpleservo; use std::os::raw::{c_char, c_int, c_void}; +use std::ptr::NonNull; use std::sync::Arc; use android_logger::{self, Config, FilterBuilder}; @@ -15,6 +16,9 @@ use jni::objects::{GlobalRef, JClass, JObject, JString, JValue, JValueOwned}; use jni::sys::{jboolean, jfloat, jint, jobject}; use jni::{JNIEnv, JavaVM}; use log::{debug, error, info, warn}; +use raw_window_handle::{ + AndroidDisplayHandle, AndroidNdkWindowHandle, RawDisplayHandle, RawWindowHandle, +}; use servo::{LoadStatus, MediaSessionActionType}; use simpleservo::{ DeviceIntRect, EventLoopWaker, InitOptions, InputMethodType, MediaSessionPlaybackState, @@ -391,12 +395,15 @@ pub extern "C" fn Java_org_servo_servoview_JNIServo_resumeCompositor<'local>( coordinates: JObject<'local>, ) { debug!("resumeCompositor"); - let widget = unsafe { ANativeWindow_fromSurface(env.get_native_interface(), surface.as_raw()) }; - let coords = jni_coords_to_rust_coords(&mut env, &coordinates); - match coords { - Ok(coords) => call(&mut env, |s| s.resume_compositor(widget, coords.clone())), - Err(error) => throw(&mut env, &error), - } + let coords = match jni_coords_to_rust_coords(&mut env, &coordinates) { + Ok(coords) => coords, + Err(error) => return throw(&mut env, &error), + }; + + let (_, window_handle) = display_and_window_handle(&mut env, &surface); + call(&mut env, |s| { + s.resume_compositor(window_handle, coords.clone()) + }); } #[no_mangle] @@ -795,17 +802,29 @@ fn get_options<'local>( None => None, }; - let native_window = - unsafe { ANativeWindow_fromSurface(env.get_native_interface(), surface.as_raw()) }; - + let (display_handle, window_handle) = display_and_window_handle(env, surface); let opts = InitOptions { args: args.unwrap_or(vec![]), url, coordinates, density, xr_discovery: None, - surfman_integration: simpleservo::SurfmanIntegration::Widget(native_window), + window_handle, + display_handle, }; Ok((opts, log, log_str, gst_debug_str)) } + +fn display_and_window_handle( + env: &mut JNIEnv<'_>, + surface: &JObject<'_>, +) -> (RawDisplayHandle, RawWindowHandle) { + let native_window = + unsafe { ANativeWindow_fromSurface(env.get_native_interface(), surface.as_raw()) }; + let native_window = NonNull::new(native_window).expect("Could not get Android window"); + ( + RawDisplayHandle::Android(AndroidDisplayHandle::new()), + RawWindowHandle::AndroidNdk(AndroidNdkWindowHandle::new(native_window)), + ) +} |