aboutsummaryrefslogtreecommitdiffstats
path: root/ports/servoshell
diff options
context:
space:
mode:
authorMartin Robinson <mrobinson@igalia.com>2025-02-20 14:52:18 +0100
committerGitHub <noreply@github.com>2025-02-20 13:52:18 +0000
commit5465bfc2af38e561df5f0a7f81250a0238520d6d (patch)
treec25e40c47ecc6743ffa1e6559c5c2ea5a06e64cd /ports/servoshell
parent9887ad369d65eb362db21c778ae5f00aad74db6c (diff)
downloadservo-5465bfc2af38e561df5f0a7f81250a0238520d6d.tar.gz
servo-5465bfc2af38e561df5f0a7f81250a0238520d6d.zip
libservo: Move GL acclerated media setup out of `RenderingContext` and simplify it (#35553)
This moves the GL accelerated media setup out of `RenderingContext` which prevents making libservo dependo on the Wayland and X11 versions of surfman explicitly. This support is experimental and (honestly) a bit broken. I've confirmed that this works as well as it did before the change. The main thing here is that the configuration, which currently needs surfman types, moves to servoshell. In addition: 1. Instead of passing the information to the Constellation, the setup is stored statically. This is necessary to avoid introducing a dependency on `media` in `webrender_traits`. It's quite likely that `media` types should move to the internal embedding API to avoid this. This is preserved for a followup change. 2. The whole system of wrapping the media channels in an abstract type is removed. They could be either mpsc channels or IPC channels. This was never going to work because mpsc channels cannot be serialized and deserialized with serde. Instead this just uses IPC channels. We also have other ways of doing this kind of abstraction in Servo so we do not need another. The `mpsc` version was hard-coded to be disabled. Signed-off-by: Martin Robinson <mrobinson@igalia.com>
Diffstat (limited to 'ports/servoshell')
-rw-r--r--ports/servoshell/desktop/accelerated_gl_media.rs73
-rw-r--r--ports/servoshell/desktop/headed_window.rs8
-rw-r--r--ports/servoshell/desktop/mod.rs1
3 files changed, 82 insertions, 0 deletions
diff --git a/ports/servoshell/desktop/accelerated_gl_media.rs b/ports/servoshell/desktop/accelerated_gl_media.rs
new file mode 100644
index 00000000000..1ee9011a48c
--- /dev/null
+++ b/ports/servoshell/desktop/accelerated_gl_media.rs
@@ -0,0 +1,73 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
+
+use std::cell::RefMut;
+
+use surfman::{Context, Device};
+
+#[cfg(not(any(
+ target_os = "windows",
+ all(target_os = "linux", not(target_env = "ohos"))
+)))]
+pub(crate) fn setup_gl_accelerated_media(_: RefMut<Device>, _: RefMut<Context>) {}
+
+#[cfg(all(target_os = "linux", not(target_env = "ohos")))]
+pub(crate) fn setup_gl_accelerated_media(device: RefMut<Device>, context: RefMut<Context>) {
+ use servo::media::{GlContext, NativeDisplay};
+ use servo::Servo;
+ use surfman::platform::generic::multi::connection::NativeConnection;
+ use surfman::platform::generic::multi::context::NativeContext;
+
+ let api = api(&device, &context);
+ let context = match device.native_context(&context) {
+ NativeContext::Default(NativeContext::Default(native_context)) => {
+ GlContext::Egl(native_context.egl_context as usize)
+ },
+ NativeContext::Default(NativeContext::Alternate(native_context)) => {
+ GlContext::Egl(native_context.egl_context as usize)
+ },
+ NativeContext::Alternate(_) => GlContext::Unknown,
+ };
+ let display = match device.connection().native_connection() {
+ surfman::NativeConnection::Default(NativeConnection::Default(connection)) => {
+ NativeDisplay::Egl(connection.0 as usize)
+ },
+ surfman::NativeConnection::Default(NativeConnection::Alternate(connection)) => {
+ NativeDisplay::X11(connection.x11_display as usize)
+ },
+ surfman::NativeConnection::Alternate(_) => NativeDisplay::Unknown,
+ };
+ Servo::initialize_gl_accelerated_media(display, api, context);
+}
+
+#[cfg(target_os = "windows")]
+pub(crate) fn setup_gl_accelerated_media(device: RefMut<Device>, context: RefMut<Context>) {
+ use servo::media::{GlContext, NativeDisplay};
+ use servo::Servo;
+
+ let api = api(&device, &context);
+ let context = GlContext::Egl(device.native_context(&context).egl_context as usize);
+ let display = NativeDisplay::Egl(device.native_device().egl_display as usize);
+ Servo::initialize_gl_accelerated_media(display, api, context);
+}
+
+#[cfg(any(
+ all(target_os = "linux", not(target_env = "ohos")),
+ target_os = "windows"
+))]
+fn api(device: &RefMut<Device>, context: &RefMut<Context>) -> servo::media::GlApi {
+ use servo::media::GlApi;
+ use surfman::GLApi;
+
+ let descriptor = device.context_descriptor(context);
+ let attributes = device.context_descriptor_attributes(&descriptor);
+ let major = attributes.version.major;
+ let minor = attributes.version.minor;
+ match device.connection().gl_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,
+ }
+}
diff --git a/ports/servoshell/desktop/headed_window.rs b/ports/servoshell/desktop/headed_window.rs
index 784aa4fa7c7..58316ad1aae 100644
--- a/ports/servoshell/desktop/headed_window.rs
+++ b/ports/servoshell/desktop/headed_window.rs
@@ -43,6 +43,7 @@ use super::app_state::RunningAppState;
use super::geometry::{winit_position_to_euclid_point, winit_size_to_euclid_size};
use super::keyutils::{keyboard_event_from_winit, CMD_OR_ALT};
use super::window_trait::{WindowPortsMethods, LINE_HEIGHT};
+use crate::desktop::accelerated_gl_media::setup_gl_accelerated_media;
use crate::desktop::keyutils::CMD_OR_CONTROL;
use crate::prefs::ServoShellPreferences;
@@ -132,6 +133,13 @@ impl Window {
.expect("Could not create RenderingContext for Window"),
);
+ // Setup for GL accelerated media handling. This is only active on certain Linux platforms
+ // and Windows.
+ {
+ let details = window_rendering_context.surfman_details();
+ setup_gl_accelerated_media(details.0, details.1);
+ }
+
// Make sure the gl context is made current.
window_rendering_context.make_current().unwrap();
diff --git a/ports/servoshell/desktop/mod.rs b/ports/servoshell/desktop/mod.rs
index c6c78f2f799..ffa1353906b 100644
--- a/ports/servoshell/desktop/mod.rs
+++ b/ports/servoshell/desktop/mod.rs
@@ -4,6 +4,7 @@
//! Contains files specific to the servoshell app for Desktop systems.
+mod accelerated_gl_media;
pub(crate) mod app;
mod app_state;
pub(crate) mod cli;