Skip to content

Commit

Permalink
WIP: Decouple glutin from winit
Browse files Browse the repository at this point in the history
Thit commit removes direct dependency on the winit and
using raw_window_handle crate instead
  • Loading branch information
kchibisov committed Aug 18, 2022
1 parent 38f7344 commit 525062b
Show file tree
Hide file tree
Showing 73 changed files with 5,543 additions and 9,002 deletions.
68 changes: 23 additions & 45 deletions glutin/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,63 +3,41 @@ name = "glutin"
version = "0.28.0"
authors = ["The glutin contributors", "Pierre Krieger <[email protected]>"]
description = "Cross-platform OpenGL context provider."
keywords = ["windowing", "opengl"]
keywords = ["windowing", "opengl", "egl", "glx", "wgl", "cgl"]
license = "Apache-2.0"
readme = "../README.md"
repository = "https://github.com/rust-windowing/glutin"
documentation = "https://docs.rs/glutin"
edition = "2018"

[package.metadata.docs.rs]
features = ["serde"]
edition = "2021"

[features]
serde = ["winit/serde"]
x11 = ["winit/x11", "glutin_glx_sys"]
wayland = ["winit/wayland", "winit/wayland-dlopen", "wayland-client", "wayland-egl"]
wayland-dlopen = ["winit/wayland-dlopen"]
default = ["x11", "wayland", "wayland-dlopen"]
default = ["egl", "glx", "x11", "wayland", "wgl"]
egl = ["glutin_egl_sys", "glutin_gles2_sys"]
glx = ["x11", "x11-dl", "glutin_glx_sys"]
wgl = []
x11 = ["x11-dl"]
wayland = ["wayland-sys"]

[dependencies]
lazy_static = "1.3"
winit = { version = "0.26", default-features = false }
libloading = "0.7.3"
once_cell = "1.12"
raw-window-handle = "0.5.0"
bitflags = "1.3.2"

[target.'cfg(target_os = "windows")'.dependencies]
glutin_egl_sys = { version = "0.1.5", path = "../glutin_egl_sys", optional = true }
glutin_gles2_sys = { version = "0.1.5", path = "../glutin_gles2_sys", optional = true }

[target.'cfg(target_os = "android")'.dependencies]
glutin_egl_sys = { version = "0.1.5", path = "../glutin_egl_sys" }
libloading = "0.7"
parking_lot = "0.11"
raw-window-handle = "0.4"

[target.'cfg(any(target_os = "ios", target_os = "macos"))'.dependencies]
objc = "0.2.6"
glutin_gles2_sys = { version = "0.1.5", path = "../glutin_gles2_sys" }

[target.'cfg(target_os = "macos")'.dependencies]
cgl = "0.3"
cocoa = "0.24"
core-foundation = "0.9"

[target.'cfg(target_os = "windows")'.dependencies.winapi]
version = "0.3"
features = [
"winnt",
"winuser",
"wingdi",
"libloaderapi",
]

[target.'cfg(target_os = "windows")'.dependencies]
libloading = "0.7"
glutin_wgl_sys = { version = "0.1.5", path = "../glutin_wgl_sys" }
glutin_egl_sys = { version = "0.1.5", path = "../glutin_egl_sys" }
parking_lot = "0.11"

[target.'cfg(any(target_os = "linux", target_os = "freebsd", target_os = "dragonfly", target_os = "netbsd", target_os = "openbsd"))'.dependencies]
osmesa-sys = "0.1"
wayland-client = { version = "0.29", features = ["dlopen"], optional = true }
wayland-egl = { version = "0.29", optional = true }
libloading = "0.7"
glutin_egl_sys = { version = "0.1.5", path = "../glutin_egl_sys" }
wayland-sys = { version = "0.30.0-beta.8", default-features = false, features = ["egl", "client"], optional = true }
x11-dl = { version = "2.19.1", optional = true }
glutin_glx_sys = { version = "0.1.7", path = "../glutin_glx_sys", optional = true }
parking_lot = "0.11"
log = "0.4"
glutin_egl_sys = { version = "0.1.5", path = "../glutin_egl_sys", optional = true }
glutin_gles2_sys = { version = "0.1.5", path = "../glutin_gles2_sys", optional = true }

[build-dependencies]
cfg_aliases = "0.1.1"
97 changes: 97 additions & 0 deletions glutin/src/api/cgl/config.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
use std::os::raw::c_int;
use std::sync::Arc;

use crate::config::{
Api, AsRawConfig, ColorBufferType, ConfigSurfaceTypes, ConfigTemplate, GlConfig, RawConfig,
};
use crate::display::GetGlDisplay;
use crate::private::Sealed;

#[cfg(x11_platform)]
use crate::platform::x11::X11VisualInfo;

use super::display::Display;

impl Display {
pub(crate) fn find_configs(
&self,
template: ConfigTemplate,
) -> Option<Box<dyn Iterator<Item = Config> + '_>> {
todo!()
}
}

#[derive(Clone)]
pub struct Config {
pub(crate) inner: Arc<ConfigInner>,
}

pub(crate) struct ConfigInner {}

impl Sealed for Config {}

impl GlConfig for Config {
fn color_buffer_type(&self) -> ColorBufferType {
todo!()
}

fn float_pixels(&self) -> bool {
todo!()
}

#[cfg(x11_platform)]
fn x11_visual(&self) -> Option<X11VisualInfo> {
todo!()
}

fn native_visual(&self) -> u32 {
todo!()
}

fn alpha_size(&self) -> u8 {
todo!()
}

fn srgb_capable(&self) -> bool {
todo!()
}

fn depth_size(&self) -> u8 {
todo!()
}

fn stencil_size(&self) -> u8 {
todo!()
}

fn sample_buffers(&self) -> u8 {
todo!()
}

fn config_surface_types(&self) -> ConfigSurfaceTypes {
todo!()
}

fn api(&self) -> Api {
todo!()
}
}

impl GetGlDisplay for Config {
type Target = Display;
fn display(&self) -> Self::Target {
todo!()
}
}

impl Config {
fn raw_attribute(&self, attr: c_int) -> c_int {
todo!()
}
}

impl AsRawConfig for Config {
fn raw_config(&self) -> RawConfig {
todo!()
}
}
183 changes: 183 additions & 0 deletions glutin/src/api/cgl/context.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,183 @@
use std::cell::Cell;
use std::ffi::{self, CStr};
use std::marker::PhantomData;
use std::rc::Rc;

use crate::context::{AsRawContext, ContextAttributes, RawContext};

use crate::config::GetGlConfig;
use crate::display::GetGlDisplay;
use crate::error::Result;
use crate::prelude::*;
use crate::private::Sealed;
use crate::surface::SurfaceTypeTrait;

use super::config::Config;
use super::display::Display;
use super::surface::Surface;

impl Display {
pub(crate) fn create_context(
&self,
config: &Config,
context_attributes: &ContextAttributes,
) -> Result<NotCurrentContext> {
todo!()
}
}

pub struct PossiblyCurrentContext {
inner: ContextInner,
// The context could be current only on the one thread.
_nosendsync: PhantomData<Rc<()>>,
}

pub struct NotCurrentContext {
inner: ContextInner,
// Only non-current context could be send between threads safely.
_nosync: PhantomData<Cell<()>>,
}

impl Sealed for PossiblyCurrentContext {}
impl Sealed for NotCurrentContext {}

impl NotCurrentContext {
fn new(inner: ContextInner) -> Self {
Self { inner, _nosync: PhantomData }
}
}

impl GetGlDisplay for NotCurrentContext {
type Target = Display;
fn display(&self) -> Self::Target {
self.inner.display.clone()
}
}

impl GetGlDisplay for PossiblyCurrentContext {
type Target = Display;
fn display(&self) -> Self::Target {
self.inner.display.clone()
}
}

impl GetGlConfig for NotCurrentContext {
type Target = Config;
fn config(&self) -> Self::Target {
self.inner.config.clone()
}
}

impl GetGlConfig for PossiblyCurrentContext {
type Target = Config;
fn config(&self) -> Self::Target {
self.inner.config.clone()
}
}

impl<T: SurfaceTypeTrait> PossiblyCurrentContextGlSurfaceAccessor<T> for PossiblyCurrentContext {
type Surface = Surface<T>;

fn make_current(&self, surface: &Self::Surface) -> Result<()> {
self.inner.make_current_draw_read(surface, surface)
}

fn make_current_draw_read(
&self,
surface_draw: &Self::Surface,
surface_read: &Self::Surface,
) -> Result<()> {
self.inner.make_current_draw_read(surface_draw, surface_read)
}
}

impl PossiblyCurrentGlContext for PossiblyCurrentContext {
type NotCurrentContext = NotCurrentContext;

fn make_not_current(self) -> Result<Self::NotCurrentContext> {
self.inner.make_not_current()?;
Ok(NotCurrentContext::new(self.inner))
}

fn update_after_resize(&self) {
self.inner.update_after_resize()
}

fn set_swap_interval(&self, interval: u16) {}

fn is_current(&self) -> bool {
todo!()
}

fn get_proc_address(&self, addr: &CStr) -> *const ffi::c_void {
todo!()
}
}

impl NotCurrentGlContext for NotCurrentContext {
type PossiblyCurrentContext = PossiblyCurrentContext;

fn treat_as_current(self) -> PossiblyCurrentContext {
PossiblyCurrentContext { inner: self.inner, _nosendsync: PhantomData }
}
}

impl<T: SurfaceTypeTrait> NotCurrentGlContextSurfaceAccessor<T> for NotCurrentContext {
type Surface = Surface<T>;
type PossiblyCurrentContext = PossiblyCurrentContext;

fn make_current(self, surface: &Self::Surface) -> Result<Self::PossiblyCurrentContext> {
self.inner.make_current_draw_read(surface, surface)?;
Ok(PossiblyCurrentContext { inner: self.inner, _nosendsync: PhantomData })
}

fn make_current_draw_read(
self,
surface_draw: &Self::Surface,
surface_read: &Self::Surface,
) -> Result<Self::PossiblyCurrentContext> {
self.inner.make_current_draw_read(surface_draw, surface_read)?;
Ok(PossiblyCurrentContext { inner: self.inner, _nosendsync: PhantomData })
}
}

impl AsRawContext for PossiblyCurrentContext {
fn raw_context(&self) -> RawContext {
todo!()
}
}

impl AsRawContext for NotCurrentContext {
fn raw_context(&self) -> RawContext {
todo!()
}
}

struct ContextInner {
display: Display,
config: Config,
}

impl ContextInner {
fn make_current_draw_read<T: SurfaceTypeTrait>(
&self,
surface_draw: &Surface<T>,
surface_read: &Surface<T>,
) -> Result<()> {
todo!()
}

fn make_not_current(&self) -> Result<()> {
todo!()
}

fn update_after_resize(&self) {
// This line is intentionally left blank.
}
}

impl Drop for ContextInner {
fn drop(&mut self) {
todo!()
}
}
Loading

0 comments on commit 525062b

Please sign in to comment.