servoshell/desktop/
accelerated_gl_media.rs1use std::cell::RefMut;
6
7use surfman::{Context, Device};
8
9#[cfg(not(any(
10 target_os = "windows",
11 all(target_os = "linux", not(target_env = "ohos"))
12)))]
13pub(crate) fn setup_gl_accelerated_media(_: RefMut<'_, Device>, _: RefMut<'_, Context>) {}
14
15#[cfg(all(target_os = "linux", not(target_env = "ohos")))]
16pub(crate) fn setup_gl_accelerated_media(device: RefMut<'_, Device>, context: RefMut<'_, Context>) {
17 use servo::{MediaGlContext, MediaNativeDisplay, Servo};
18 use surfman::platform::generic::multi::connection::NativeConnection;
19 use surfman::platform::generic::multi::context::NativeContext;
20
21 let api = api(&device, &context);
22 let context = match device.native_context(&context) {
23 NativeContext::Default(NativeContext::Default(native_context)) => {
24 MediaGlContext::Egl(native_context.egl_context as usize)
25 },
26 NativeContext::Default(NativeContext::Alternate(native_context)) => {
27 MediaGlContext::Egl(native_context.egl_context as usize)
28 },
29 NativeContext::Alternate(_) => MediaGlContext::Unknown,
30 };
31 let display = match device.connection().native_connection() {
32 surfman::NativeConnection::Default(NativeConnection::Default(connection)) => {
33 MediaNativeDisplay::Egl(connection.0 as usize)
34 },
35 surfman::NativeConnection::Default(NativeConnection::Alternate(connection)) => {
36 MediaNativeDisplay::X11(connection.x11_display as usize)
37 },
38 surfman::NativeConnection::Alternate(_) => MediaNativeDisplay::Unknown,
39 };
40 Servo::initialize_gl_accelerated_media(display, api, context);
41}
42
43#[cfg(target_os = "windows")]
44pub(crate) fn setup_gl_accelerated_media(device: RefMut<'_, Device>, context: RefMut<'_, Context>) {
45 use servo::{MediaGlContext, MediaNativeDisplay, Servo};
46
47 let api = api(&device, &context);
48 let context = MediaGlContext::Egl(device.native_context(&context).egl_context as usize);
49 let display = MediaNativeDisplay::Egl(device.native_device().egl_display as usize);
50 Servo::initialize_gl_accelerated_media(display, api, context);
51}
52
53#[cfg(any(
54 all(target_os = "linux", not(target_env = "ohos")),
55 target_os = "windows"
56))]
57fn api(device: &RefMut<Device>, context: &RefMut<Context>) -> servo::MediaGlApi {
58 use servo::MediaGlApi;
59 use surfman::GLApi;
60
61 let descriptor = device.context_descriptor(context);
62 let attributes = device.context_descriptor_attributes(&descriptor);
63 let major = attributes.version.major;
64 let minor = attributes.version.minor;
65 match device.connection().gl_api() {
66 GLApi::GL if major >= 3 && minor >= 2 => MediaGlApi::OpenGL3,
67 GLApi::GL => MediaGlApi::OpenGL,
68 GLApi::GLES if major > 1 => MediaGlApi::Gles2,
69 GLApi::GLES => MediaGlApi::Gles1,
70 }
71}