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