libservo: Handle GL video decoding setup internally (#31209)

Instead of making the client set up GL video decoding, have this done
inside libservo. The details necessary for decoding are fetched via
Surfman now. This also removes the setup for the context on Android --
which has no GStreamer support now anyway. In the future, this could be
enabled, but should likely be done using Surfman, instead of passing on
all these details manually.
This commit is contained in:
Martin Robinson 2024-02-03 15:38:48 +01:00 committed by GitHub
parent b2fe66f7e4
commit d7d0451424
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 125 additions and 156 deletions

View file

@ -126,11 +126,9 @@ pub fn Java_org_mozilla_servoview_JNIServo_init(
let wakeup = Box::new(WakeupCallback::new(callbacks_ref.clone(), &env));
let callbacks = Box::new(HostCallbacks::new(callbacks_ref, &env));
if let Err(err) = gl_glue::egl::init().and_then(|egl_init| {
opts.gl_context_pointer = Some(egl_init.gl_context);
opts.native_display_pointer = Some(egl_init.display);
simpleservo::init(opts, egl_init.gl_wrapper, wakeup, callbacks)
}) {
if let Err(err) = gl_glue::egl::init()
.and_then(|egl_init| simpleservo::init(opts, egl_init.gl_wrapper, wakeup, callbacks))
{
throw(&env, err)
};
}
@ -852,8 +850,6 @@ fn get_options(
coordinates,
density,
xr_discovery: None,
gl_context_pointer: None,
native_display_pointer: None,
surfman_integration: simpleservo::SurfmanIntegration::Widget(native_window),
prefs: None,
};

View file

@ -39,7 +39,6 @@ pub use servo::webrender_api::units::DeviceIntRect;
use servo::webrender_api::units::DevicePixel;
use servo::webrender_api::ScrollLocation;
use servo::{self, gl, Servo, TopLevelBrowsingContextId};
use servo_media::player::context as MediaPlayerContext;
use surfman::{Connection, SurfaceType};
thread_local! {
@ -56,8 +55,6 @@ pub struct InitOptions {
pub coordinates: Coordinates,
pub density: f32,
pub xr_discovery: Option<webxr::Discovery>,
pub gl_context_pointer: Option<*const c_void>,
pub native_display_pointer: Option<*const c_void>,
pub surfman_integration: SurfmanIntegration,
pub prefs: Option<HashMap<String, PrefValue>>,
}
@ -292,8 +289,6 @@ pub fn init(
host_callbacks: callbacks,
coordinates: RefCell::new(init_opts.coordinates),
density: init_opts.density,
gl_context_pointer: init_opts.gl_context_pointer,
native_display_pointer: init_opts.native_display_pointer,
rendering_context: rendering_context.clone(),
});
@ -861,8 +856,6 @@ struct ServoWindowCallbacks {
host_callbacks: Box<dyn HostTrait>,
coordinates: RefCell<Coordinates>,
density: f32,
gl_context_pointer: Option<*const c_void>,
native_display_pointer: Option<*const c_void>,
rendering_context: RenderingContext,
}
@ -906,24 +899,6 @@ impl WindowMethods for ServoWindowCallbacks {
hidpi_factor: Scale::new(self.density),
}
}
fn get_gl_context(&self) -> MediaPlayerContext::GlContext {
match self.gl_context_pointer {
Some(context) => MediaPlayerContext::GlContext::Egl(context as usize),
None => MediaPlayerContext::GlContext::Unknown,
}
}
fn get_native_display(&self) -> MediaPlayerContext::NativeDisplay {
match self.native_display_pointer {
Some(display) => MediaPlayerContext::NativeDisplay::Egl(display as usize),
None => MediaPlayerContext::NativeDisplay::Unknown,
}
}
fn get_gl_api(&self) -> MediaPlayerContext::GlApi {
MediaPlayerContext::GlApi::Gles2
}
}
struct ResourceReaderInstance;

View file

@ -14,7 +14,7 @@ use gleam::gl;
use log::{info, trace, warn};
use servo::compositing::windowing::EmbedderEvent;
use servo::compositing::CompositeTarget;
use servo::config::opts;
use servo::config::{opts, set_pref};
use servo::servo_config::pref;
use servo::Servo;
use surfman::GLApi;
@ -67,6 +67,8 @@ impl App {
// Implements window methods, used by compositor.
let window = if opts::get().headless {
// GL video rendering is not supported on headless windows.
set_pref!(media.glvideo.enabled, false);
headless_window::Window::new(
opts::get().initial_window_size,
device_pixel_ratio_override,

View file

@ -24,12 +24,7 @@ use servo::servo_geometry::DeviceIndependentPixel;
use servo::style_traits::DevicePixel;
use servo::webrender_api::units::{DeviceIntPoint, DeviceIntRect, DeviceIntSize};
use servo::webrender_api::ScrollLocation;
use servo_media::player::context::{GlApi, GlContext as PlayerGLContext, NativeDisplay};
#[cfg(target_os = "linux")]
use surfman::platform::generic::multi::connection::NativeConnection;
#[cfg(target_os = "linux")]
use surfman::platform::generic::multi::context::NativeContext;
use surfman::{Connection, Context, Device, GLApi, GLVersion, SurfaceType};
use surfman::{Connection, Context, Device, SurfaceType};
#[cfg(target_os = "windows")]
use winapi;
use winit::dpi::{LogicalPosition, PhysicalPosition, PhysicalSize};
@ -553,82 +548,6 @@ impl WindowMethods for Window {
fn rendering_context(&self) -> RenderingContext {
self.rendering_context.clone()
}
fn get_gl_context(&self) -> PlayerGLContext {
if !pref!(media.glvideo.enabled) {
return PlayerGLContext::Unknown;
}
#[allow(unused_variables)]
let native_context = self.rendering_context.native_context();
#[cfg(target_os = "windows")]
return PlayerGLContext::Egl(native_context.egl_context as usize);
#[cfg(target_os = "linux")]
return match native_context {
NativeContext::Default(NativeContext::Default(native_context)) => {
PlayerGLContext::Egl(native_context.egl_context as usize)
},
NativeContext::Default(NativeContext::Alternate(native_context)) => {
PlayerGLContext::Egl(native_context.egl_context as usize)
},
NativeContext::Alternate(_) => unimplemented!(),
};
// @TODO(victor): https://github.com/servo/media/pull/315
#[cfg(target_os = "macos")]
#[allow(unreachable_code)]
return unimplemented!();
#[cfg(not(any(target_os = "linux", target_os = "windows", target_os = "macos")))]
return unimplemented!();
}
fn get_native_display(&self) -> NativeDisplay {
if !pref!(media.glvideo.enabled) {
return NativeDisplay::Unknown;
}
#[allow(unused_variables)]
let native_connection = self.rendering_context.connection().native_connection();
#[allow(unused_variables)]
let native_device = self.rendering_context.native_device();
#[cfg(target_os = "windows")]
return NativeDisplay::Egl(native_device.egl_display as usize);
#[cfg(target_os = "linux")]
return match native_connection {
NativeConnection::Default(NativeConnection::Default(conn)) => {
NativeDisplay::Egl(conn.0 as usize)
},
NativeConnection::Default(NativeConnection::Alternate(conn)) => {
NativeDisplay::X11(conn.x11_display as usize)
},
NativeConnection::Alternate(_) => unimplemented!(),
};
// @TODO(victor): https://github.com/servo/media/pull/315
#[cfg(target_os = "macos")]
#[allow(unreachable_code)]
return unimplemented!();
#[cfg(not(any(target_os = "linux", target_os = "windows", target_os = "macos")))]
return unimplemented!();
}
fn get_gl_api(&self) -> GlApi {
let api = self.rendering_context.connection().gl_api();
let attributes = self.rendering_context.context_attributes();
let GLVersion { major, minor } = attributes.version;
match api {
GLApi::GL if major >= 3 && minor >= 2 => GlApi::OpenGL3,
GLApi::GL => GlApi::OpenGL,
GLApi::GLES if major > 1 => GlApi::Gles2,
GLApi::GLES => GlApi::Gles1,
}
}
}
fn winit_phase_to_touch_event_type(phase: TouchPhase) -> TouchEventType {

View file

@ -15,7 +15,6 @@ use servo::rendering_context::RenderingContext;
use servo::servo_geometry::DeviceIndependentPixel;
use servo::style_traits::DevicePixel;
use servo::webrender_api::units::DeviceIntRect;
use servo_media::player::context as MediaPlayerCtxt;
use surfman::{Connection, Context, Device, SurfaceType};
use crate::events_loop::WakerEvent;
@ -144,18 +143,6 @@ impl WindowMethods for Window {
self.animation_state.set(state);
}
fn get_gl_context(&self) -> MediaPlayerCtxt::GlContext {
MediaPlayerCtxt::GlContext::Unknown
}
fn get_native_display(&self) -> MediaPlayerCtxt::NativeDisplay {
MediaPlayerCtxt::NativeDisplay::Unknown
}
fn get_gl_api(&self) -> MediaPlayerCtxt::GlApi {
MediaPlayerCtxt::GlApi::None
}
fn rendering_context(&self) -> RenderingContext {
self.rendering_context.clone()
}