mirror of
https://github.com/servo/servo.git
synced 2025-08-07 06:25:32 +01:00
Implement Window's GL context for Glutin
This commit is contained in:
parent
9f4f9dc750
commit
e0a5abf7df
2 changed files with 119 additions and 9 deletions
|
@ -2,7 +2,10 @@
|
||||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
* 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/. */
|
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
use glutin::{WindowedContext, NotCurrent, PossiblyCurrent};
|
use glutin::os::ContextTraitExt;
|
||||||
|
use glutin::{NotCurrent, PossiblyCurrent, WindowedContext};
|
||||||
|
use servo_media::player::context::GlContext as RawContext;
|
||||||
|
use std::os::raw;
|
||||||
|
|
||||||
pub enum GlContext {
|
pub enum GlContext {
|
||||||
Current(WindowedContext<PossiblyCurrent>),
|
Current(WindowedContext<PossiblyCurrent>),
|
||||||
|
@ -71,4 +74,59 @@ impl GlContext {
|
||||||
GlContext::None => unreachable!(),
|
GlContext::None => unreachable!(),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
pub fn raw_context(&self) -> RawContext {
|
||||||
|
match self {
|
||||||
|
GlContext::Current(c) => {
|
||||||
|
let raw_handle = unsafe { c.raw_handle() };
|
||||||
|
|
||||||
|
#[cfg(any(
|
||||||
|
target_os = "linux",
|
||||||
|
target_os = "dragonfly",
|
||||||
|
target_os = "freebsd",
|
||||||
|
target_os = "netbsd",
|
||||||
|
target_os = "openbsd"
|
||||||
|
))]
|
||||||
|
{
|
||||||
|
use glutin::os::unix::RawHandle;
|
||||||
|
|
||||||
|
return match raw_handle {
|
||||||
|
RawHandle::Egl(handle) => RawContext::Egl(handle as usize),
|
||||||
|
RawHandle::Glx(handle) => RawContext::Glx(handle as usize),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(not(any(
|
||||||
|
target_os = "linux",
|
||||||
|
target_os = "dragonfly",
|
||||||
|
target_os = "freebsd",
|
||||||
|
target_os = "netbsd",
|
||||||
|
target_os = "openbsd"
|
||||||
|
)))]
|
||||||
|
unimplemented!()
|
||||||
|
}
|
||||||
|
GlContext::NotCurrent(_) => {
|
||||||
|
error!("Context is not current.");
|
||||||
|
RawContext::Unknown
|
||||||
|
}
|
||||||
|
GlContext::None => unreachable!(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
pub fn egl_display(&self) -> Option<*const raw::c_void> {
|
||||||
|
match self {
|
||||||
|
GlContext::Current(c) => unsafe { c.get_egl_display() },
|
||||||
|
GlContext::NotCurrent(_) => {
|
||||||
|
error!("Context is not current.");
|
||||||
|
None
|
||||||
|
},
|
||||||
|
GlContext::None => unreachable!(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn get_api(&self) -> glutin::Api {
|
||||||
|
match self {
|
||||||
|
GlContext::Current(c) => c.get_api(),
|
||||||
|
GlContext::NotCurrent(c) => c.get_api(),
|
||||||
|
GlContext::None => unreachable!(),
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,9 +13,9 @@ use gleam::gl;
|
||||||
use glutin::dpi::{LogicalPosition, LogicalSize, PhysicalSize};
|
use glutin::dpi::{LogicalPosition, LogicalSize, PhysicalSize};
|
||||||
#[cfg(target_os = "macos")]
|
#[cfg(target_os = "macos")]
|
||||||
use glutin::os::macos::{ActivationPolicy, WindowBuilderExt};
|
use glutin::os::macos::{ActivationPolicy, WindowBuilderExt};
|
||||||
|
use glutin::Api;
|
||||||
#[cfg(any(target_os = "linux", target_os = "windows"))]
|
#[cfg(any(target_os = "linux", target_os = "windows"))]
|
||||||
use glutin::Icon;
|
use glutin::Icon;
|
||||||
use glutin::Api;
|
|
||||||
use glutin::{ElementState, KeyboardInput, MouseButton, MouseScrollDelta, TouchPhase};
|
use glutin::{ElementState, KeyboardInput, MouseButton, MouseScrollDelta, TouchPhase};
|
||||||
#[cfg(any(target_os = "linux", target_os = "windows"))]
|
#[cfg(any(target_os = "linux", target_os = "windows"))]
|
||||||
use image;
|
use image;
|
||||||
|
@ -30,7 +30,7 @@ use servo::style_traits::DevicePixel;
|
||||||
use servo::webrender_api::{
|
use servo::webrender_api::{
|
||||||
DeviceIntPoint, DeviceIntRect, DeviceIntSize, FramebufferIntSize, ScrollLocation,
|
DeviceIntPoint, DeviceIntRect, DeviceIntSize, FramebufferIntSize, ScrollLocation,
|
||||||
};
|
};
|
||||||
use servo_media::player::context as MediaPlayerCtxt;
|
use servo_media::player::context::{GlApi, GlContext as PlayerGLContext, NativeDisplay};
|
||||||
use std::cell::{Cell, RefCell};
|
use std::cell::{Cell, RefCell};
|
||||||
use std::mem;
|
use std::mem;
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
|
@ -526,16 +526,68 @@ impl WindowMethods for Window {
|
||||||
self.gl_context.borrow_mut().make_current();
|
self.gl_context.borrow_mut().make_current();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_gl_context(&self) -> MediaPlayerCtxt::GlContext {
|
fn get_gl_context(&self) -> PlayerGLContext {
|
||||||
MediaPlayerCtxt::GlContext::Unknown
|
self.gl_context.borrow().raw_context()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_native_display(&self) -> MediaPlayerCtxt::NativeDisplay {
|
fn get_native_display(&self) -> NativeDisplay {
|
||||||
MediaPlayerCtxt::NativeDisplay::Unknown
|
#[cfg(any(
|
||||||
|
target_os = "linux",
|
||||||
|
target_os = "dragonfly",
|
||||||
|
target_os = "freebsd",
|
||||||
|
target_os = "netbsd",
|
||||||
|
target_os = "openbsd"
|
||||||
|
))]
|
||||||
|
let native_display = {
|
||||||
|
if let Some(display) = self.gl_context.borrow().egl_display() {
|
||||||
|
NativeDisplay::Egl(display as usize)
|
||||||
|
} else {
|
||||||
|
use glutin::os::unix::WindowExt;
|
||||||
|
|
||||||
|
if let Some(display) = self.gl_context.borrow().window().get_wayland_display() {
|
||||||
|
NativeDisplay::Wayland(display as usize)
|
||||||
|
} else if let Some(display) = self.gl_context.borrow().window().get_xlib_display() {
|
||||||
|
NativeDisplay::X11(display as usize)
|
||||||
|
} else {
|
||||||
|
NativeDisplay::Unknown
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
#[cfg(not(any(
|
||||||
|
target_os = "linux",
|
||||||
|
target_os = "dragonfly",
|
||||||
|
target_os = "freebsd",
|
||||||
|
target_os = "netbsd",
|
||||||
|
target_os = "openbsd"
|
||||||
|
)))]
|
||||||
|
let native_display = NativeDisplay::Unknown;
|
||||||
|
|
||||||
|
native_display
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_gl_api(&self) -> MediaPlayerCtxt::GlApi {
|
fn get_gl_api(&self) -> GlApi {
|
||||||
MediaPlayerCtxt::GlApi::None
|
let api = self.gl_context.borrow().get_api();
|
||||||
|
|
||||||
|
let version = self.gl.get_string(gl::VERSION);
|
||||||
|
let version = version.trim_start_matches("OpenGL ES ");
|
||||||
|
let mut values = version.split(&['.', ' '][..]);
|
||||||
|
let major = values
|
||||||
|
.next()
|
||||||
|
.and_then(|v| v.parse::<u32>().ok())
|
||||||
|
.unwrap_or(1);
|
||||||
|
let minor = values
|
||||||
|
.next()
|
||||||
|
.and_then(|v| v.parse::<u32>().ok())
|
||||||
|
.unwrap_or(20);
|
||||||
|
|
||||||
|
match api {
|
||||||
|
glutin::Api::OpenGl if major >= 3 && minor >= 2 => GlApi::OpenGL3,
|
||||||
|
glutin::Api::OpenGl => GlApi::OpenGL,
|
||||||
|
glutin::Api::OpenGlEs if major > 1 => GlApi::Gles2,
|
||||||
|
glutin::Api::OpenGlEs => GlApi::Gles1,
|
||||||
|
_ => GlApi::None,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue