Skip to content

Commit d875dfc

Browse files
committed
Refactoring as of 2019/06/22.
Signed-off-by: Hal Gentz <zegentzy@protonmail.com>
1 parent 6220e4b commit d875dfc

File tree

7 files changed

+155
-45
lines changed

7 files changed

+155
-45
lines changed

.circleci/config.yml.old

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
version: 2
2+
3+
jobs:
4+
5+
android-test:
6+
working_directory: ~/glutin
7+
docker:
8+
- image: gentz/android-rs-glue
9+
steps:
10+
- run: apt-get -qq update && apt-get install -y git
11+
- checkout
12+
- restore_cache:
13+
key: android-test-cache-{{ checksum "Cargo.toml" }}
14+
- run: cd glutin_examples && cargo apk build --example window
15+
- save_cache:
16+
key: android-test-cache-{{ checksum "Cargo.toml" }}
17+
paths:
18+
- target
19+
20+
asmjs-test:
21+
working_directory: ~/glutin
22+
docker:
23+
- image: tomaka/rustc-emscripten
24+
steps:
25+
- run: apt-get -qq update && apt-get install -y git
26+
- checkout
27+
- restore_cache:
28+
key: asmjs-test-cache-{{ checksum "Cargo.toml" }}
29+
- run: cargo build --example window --target asmjs-unknown-emscripten
30+
- save_cache:
31+
key: asmjs-test-cache-{{ checksum "Cargo.toml" }}
32+
paths:
33+
- target
34+
35+
wasm-test:
36+
working_directory: ~/glutin
37+
docker:
38+
- image: tomaka/rustc-emscripten
39+
steps:
40+
- run: apt-get -qq update && apt-get install -y git
41+
- checkout
42+
- restore_cache:
43+
key: wasm-test-cache-{{ checksum "Cargo.toml" }}
44+
- run: cargo build --example window --target wasm32-unknown-emscripten
45+
- save_cache:
46+
key: wasm-test-cache-{{ checksum "Cargo.toml" }}
47+
paths:
48+
- target
49+
50+
workflows:
51+
version: 2
52+
test-all:
53+
jobs:
54+
- android-test
55+
- asmjs-test
56+
- wasm-test

.gitattributes

+2
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,5 @@
2020
*.PDF diff=astextplain
2121
*.rtf diff=astextplain
2222
*.RTF diff=astextplain
23+
24+
/CHANGELOG.md merge=union

glutin/Cargo.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ serde = ["winit/serde"]
1919
[dependencies]
2020
lazy_static = "1.3"
2121
#winit = "^0.19.1"
22-
winit = { git = "https://github.com/rust-windowing/winit.git", rev = "0eefa3b" }
22+
winit = { git = "https://github.com/rust-windowing/winit.git", rev = "db794b9" }
23+
log = "0.4"
2324

2425
[target.'cfg(target_os = "android")'.dependencies]
2526
android_glue = "0.2"
@@ -62,4 +63,3 @@ glutin_egl_sys = { version = "0.1.3", path = "../glutin_egl_sys" }
6263
glutin_glx_sys = { version = "0.1.5", path = "../glutin_glx_sys" }
6364
derivative = "1.0"
6465
parking_lot = "0.8"
65-
log = "0.4"

glutin/src/lib.rs

-7
Original file line numberDiff line numberDiff line change
@@ -99,13 +99,6 @@ extern crate lazy_static;
9999
#[cfg(any(target_os = "macos", target_os = "ios"))]
100100
#[macro_use]
101101
extern crate objc;
102-
#[cfg(any(
103-
target_os = "linux",
104-
target_os = "dragonfly",
105-
target_os = "freebsd",
106-
target_os = "netbsd",
107-
target_os = "openbsd",
108-
))]
109102
#[macro_use]
110103
extern crate log;
111104
#[cfg(any(

glutin/src/platform_impl/unix/mod.rs

+52-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ mod x11;
1212
use self::x11::X11Context;
1313
use crate::{
1414
Api, ContextCurrentState, ContextError, CreationError, GlAttributes,
15-
NotCurrent, PixelFormat, PixelFormatRequirements,
15+
NotCurrent, PixelFormat, PixelFormatRequirements, ContextBuilderWrapper,
1616
};
1717
pub use x11::utils as x11_utils;
1818

@@ -78,6 +78,36 @@ impl Context {
7878
}
7979
}
8080

81+
#[inline]
82+
pub fn new<T>(
83+
el: &EventLoop<T>,
84+
cb: ContextBuilderWrapper<&'_ Context>,
85+
pbuffer_support: bool,
86+
window_surface_support: bool,
87+
surfaceless_support: bool,
88+
) -> Result<Self, CreationError> {
89+
if el.is_wayland() {
90+
unimplemented!()
91+
/*Context::is_compatible(&gl_attr.sharing, ContextType::Wayland)?;
92+
93+
let gl_attr = gl_attr.clone().map_sharing(|ctx| match *ctx {
94+
Context::Wayland(ref ctx) => ctx,
95+
_ => unreachable!(),
96+
});
97+
wayland::Context::new(wb, el, pf_reqs, &gl_attr, plat_attr)
98+
.map(|(win, context)| (win, Context::Wayland(context)))*/
99+
} else {
100+
Context::is_compatible(&cb.gl_attr.sharing, ContextType::X11)?;
101+
let cb = cb.map_sharing(|ctx| match *ctx {
102+
Context::X11(ref ctx) => ctx,
103+
_ => unreachable!(),
104+
});
105+
x11::Context::new(el, cb, pbuffer_support, window_surface_support, surfaceless_support)
106+
.map(|context| Context::X11(context))
107+
}
108+
}
109+
110+
/*
81111
#[inline]
82112
pub fn new_windowed<T>(
83113
wb: WindowBuilder,
@@ -141,7 +171,7 @@ impl Context {
141171
x11::Context::new_headless(&el, pf_reqs, &gl_attr, plat_attr, size)
142172
.map(|ctx| Context::X11(ctx))
143173
}
144-
}
174+
}*/
145175

146176
#[inline]
147177
pub unsafe fn make_current(&self) -> Result<(), ContextError> {
@@ -231,9 +261,29 @@ impl Context {
231261
}
232262
}
233263

264+
#[derive(Debug, Clone)]
265+
pub enum BackingApi {
266+
GlxThenEgl,
267+
EglThenGlx,
268+
Egl,
269+
Glx,
270+
}
271+
272+
impl Default for BackingApi {
273+
fn default() -> Self {
274+
BackingApi::GlxThenEgl
275+
}
276+
}
277+
234278
#[derive(Default, Debug, Clone)]
235279
pub struct PlatformAttributes {
236280
/// X11 only: set internally to insure a certain visual xid is used when
237281
/// choosing the fbconfig.
238282
pub(crate) x11_visual_xid: Option<std::os::raw::c_ulong>,
283+
284+
/// GLX only: Whether the context will have transparency support.
285+
pub glx_transparency: Option<bool>,
286+
287+
/// Ignored by surfaceless.
288+
pub backing_api: BackingApi,
239289
}

glutin/src/platform_impl/unix/x11.rs

+27-34
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use crate::platform::unix::{
1010
use crate::platform_impl::{x11_utils, PlatformAttributes};
1111
use crate::{
1212
Api, ContextError, CreationError, GlAttributes, GlRequest, PixelFormat,
13-
PixelFormatRequirements,
13+
PixelFormatRequirements, ContextBuilderWrapper
1414
};
1515

1616
use glutin_glx_sys as ffi;
@@ -98,7 +98,7 @@ unsafe impl Sync for Context {}
9898
pub fn select_config<T, F>(
9999
xconn: &Arc<XConnection>,
100100
transparent: Option<bool>,
101-
plat_attr: &PlatformAttributes,
101+
cb: &ContextBuilderWrapper<&'_ Context>,
102102
config_ids: Vec<T>,
103103
mut convert_to_xvisualinfo: F,
104104
) -> Result<(T, ffi::XVisualInfo), ()>
@@ -119,7 +119,7 @@ where
119119
&xconn,
120120
visual_infos,
121121
transparent == Some(true),
122-
plat_attr.x11_visual_xid,
122+
cb.plat_attr.x11_visual_xid,
123123
);
124124

125125
let pict_format = unsafe {
@@ -184,6 +184,7 @@ impl Context {
184184
}
185185
}
186186

187+
/*
187188
#[inline]
188189
pub fn new_headless<T>(
189190
el: &EventLoop<T>,
@@ -310,24 +311,22 @@ impl Context {
310311
311312
Ok(context)
312313
}
313-
}
314+
}*/
314315

315316
#[inline]
316317
fn new_first_stage<'a>(
317318
xconn: &Arc<XConnection>,
318-
pf_reqs: &PixelFormatRequirements,
319-
gl_attr: &'a GlAttributes<&'a Context>,
320-
plat_attr: &'a PlatformAttributes,
319+
cb: &ContextBuilderWrapper<&'_ Context>,
321320
screen_id: raw::c_int,
322-
builder_glx_u: &'a mut Option<GlAttributes<&'a GlxContext>>,
323-
builder_egl_u: &'a mut Option<GlAttributes<&'a EglContext>>,
321+
builder_glx_u: &'_ mut Option<ContextBuilderWrapper<&'_ GlxContext>>,
322+
builder_egl_u: &'_ mut Option<ContextBuilderWrapper<&'_ EglContext>>,
324323
surface_type: EglSurfaceType,
325324
prefer_egl: bool,
326325
force_prefer_unless_only: bool,
327326
transparent: Option<bool>,
328327
) -> Result<Prototype<'a>, CreationError> {
329328
let select_config = |cs, display| {
330-
select_config(&xconn, transparent, plat_attr, cs, |config_id| {
329+
select_config(&xconn, transparent, cb, cs, |config_id| {
331330
let xid = egl::get_native_visual_id(display, *config_id)
332331
as ffi::VisualID;
333332
if xid == 0 {
@@ -337,7 +336,7 @@ impl Context {
337336
})
338337
.map(|(c, _)| c)
339338
};
340-
Ok(match gl_attr.version {
339+
Ok(match cb.gl_attr.version {
341340
GlRequest::Latest
342341
| GlRequest::Specific(Api::OpenGl, _)
343342
| GlRequest::GlThenGles { .. } => {
@@ -347,25 +346,23 @@ impl Context {
347346
// However, with surfaceless, GLX isn't really there, so we
348347
// should prefer EGL.
349348
let glx = |builder_u: &'a mut Option<_>| {
350-
let builder = gl_attr.clone();
349+
let builder = cb.clone();
351350
*builder_u =
352351
Some(builder.map_sharing(|c| match c.context {
353352
X11Context::Glx(ref c) => c,
354353
_ => panic!(),
355354
}));
356355
Ok(Prototype::Glx(GlxContext::new(
357356
Arc::clone(&xconn),
358-
pf_reqs,
359357
builder_u.as_ref().unwrap(),
360-
plat_attr,
361358
screen_id,
362359
surface_type,
363360
transparent,
364361
)?))
365362
};
366363

367364
let egl = |builder_u: &'a mut Option<_>| {
368-
let builder = gl_attr.clone();
365+
let builder = cb.clone();
369366
*builder_u =
370367
Some(builder.map_sharing(|c| match c.context {
371368
X11Context::Egl(ref c) => c,
@@ -374,9 +371,7 @@ impl Context {
374371
let native_display =
375372
NativeDisplay::X11(Some(xconn.display as *const _));
376373
Ok(Prototype::Egl(EglContext::new(
377-
pf_reqs,
378374
builder_u.as_ref().unwrap(),
379-
plat_attr,
380375
native_display,
381376
surface_type,
382377
select_config,
@@ -428,16 +423,14 @@ impl Context {
428423
}
429424
GlRequest::Specific(Api::OpenGlEs, _) => {
430425
if let Some(_) = *EGL {
431-
let builder = gl_attr.clone();
426+
let builder = cb.clone();
432427
*builder_egl_u =
433428
Some(builder.map_sharing(|c| match c.context {
434429
X11Context::Egl(ref c) => c,
435430
_ => panic!(),
436431
}));
437432
Prototype::Egl(EglContext::new(
438-
pf_reqs,
439433
builder_egl_u.as_ref().unwrap(),
440-
plat_attr,
441434
NativeDisplay::X11(Some(xconn.display as *const _)),
442435
surface_type,
443436
select_config,
@@ -458,25 +451,25 @@ impl Context {
458451

459452
#[inline]
460453
pub fn new<T>(
461-
wb: WindowBuilder,
462454
el: &EventLoop<T>,
463-
pf_reqs: &PixelFormatRequirements,
464-
gl_attr: &GlAttributes<&Context>,
465-
plat_attr: &PlatformAttributes,
466-
) -> Result<(Window, Self), CreationError> {
455+
cb: ContextBuilderWrapper<&'_ Context>,
456+
pbuffer_support: bool,
457+
window_surface_support: bool,
458+
surfaceless_support: bool,
459+
) -> Result<Self, CreationError> {
467460
Self::try_then_fallback(|fallback| {
468-
Self::new_impl(wb.clone(), el, pf_reqs, gl_attr, plat_attr, fallback)
461+
Self::new_impl(el, &cb, pbuffer_support, window_surface_support, surfaceless_support, fallback)
469462
})
470463
}
471464

472465
fn new_impl<T>(
473-
wb: WindowBuilder,
474466
el: &EventLoop<T>,
475-
pf_reqs: &PixelFormatRequirements,
476-
gl_attr: &GlAttributes<&Context>,
477-
plat_attr: &PlatformAttributes,
467+
cb: &ContextBuilderWrapper<&'_ Context>,
468+
pbuffer_support: bool,
469+
window_surface_support: bool,
470+
surfaceless_support: bool,
478471
fallback: bool,
479-
) -> Result<(Window, Self), CreationError> {
472+
) -> Result<Self, CreationError> {
480473
let xconn = match el.xlib_xconnection() {
481474
Some(xconn) => xconn,
482475
None => {
@@ -495,9 +488,7 @@ impl Context {
495488
// start the context building process
496489
let context = Self::new_first_stage(
497490
&xconn,
498-
pf_reqs,
499-
gl_attr,
500-
plat_attr,
491+
cb,
501492
screen_id,
502493
&mut builder_glx_u,
503494
&mut builder_egl_u,
@@ -537,6 +528,7 @@ impl Context {
537528
Ok((win, context))
538529
}
539530

531+
/*
540532
#[inline]
541533
pub fn new_raw_context(
542534
xconn: Arc<XConnection>,
@@ -624,6 +616,7 @@ impl Context {
624616
625617
Ok(context)
626618
}
619+
*/
627620

628621
#[inline]
629622
pub unsafe fn make_current(&self) -> Result<(), ContextError> {

glutin/src/surface.rs

+16
Original file line numberDiff line numberDiff line change
@@ -87,3 +87,19 @@ impl PBuffer {
8787
}
8888

8989
impl IsPBuffer for PBuffer {}
90+
91+
impl Drop for PBuffer {
92+
fn drop(&mut self) {
93+
if self.is_current() {
94+
warn!("User dropped PBuffer that is still current. Future operations that modify and/or depend on the pbuffer will cause UB.");
95+
}
96+
}
97+
}
98+
99+
impl<T> Drop for WindowSurfaceWrapper<T> {
100+
fn drop(&mut self) {
101+
if self.is_current() {
102+
warn!("User dropped WindowSurfaceWrapper that is still current. Future operations that modify and/or depend on the surface will cause UB.");
103+
}
104+
}
105+
}

0 commit comments

Comments
 (0)