Skip to content

Commit d37c195

Browse files
committed
Refactoring as of 2019/06/23
Signed-off-by: Hal Gentz <zegentzy@protonmail.com>
1 parent aee2ac6 commit d37c195

File tree

5 files changed

+234
-205
lines changed

5 files changed

+234
-205
lines changed

glutin/src/api/osmesa/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ impl std::error::Error for LoadingError {
7474

7575
impl OsMesaContext {
7676
pub fn new(
77-
cb: ContextBuilderWrapper<&'_ OsMesaContext>,
77+
cb: ContextBuilderWrapper<&OsMesaContext>,
7878
) -> Result<Self, CreationError> {
7979
osmesa_sys::OsMesa::try_loading()
8080
.map_err(LoadingError::new)

glutin/src/context.rs

+12-14
Original file line numberDiff line numberDiff line change
@@ -374,11 +374,8 @@ impl<
374374
}
375375
}
376376

377-
impl<
378-
PBS: SupportsPBuffersTrait,
379-
WST: SupportsWindowSurfacesTrait,
380-
ST: SupportsSurfacelessTrait,
381-
> Context<PossiblyCurrentSurfaceBound, PBS, WST, ST>
377+
impl<PBS: SupportsPBuffersTrait, ST: SupportsSurfacelessTrait>
378+
Context<PossiblyCurrentSurfaceBound, PBS, SupportsWindowSurfaces::Yes, ST>
382379
{
383380
/// Swaps the buffers in case of double or triple buffering.
384381
///
@@ -393,20 +390,21 @@ impl<
393390
self.context.swap_buffers()
394391
}
395392

396-
/// Resize the context.
393+
/// Update the context after the underlying surface resizes.
397394
///
398-
/// Some platforms (macOS, Wayland) require being manually updated when
399-
/// their window or surface is resized.
395+
/// Macos requires updating the context when the underlying surface resizes.
400396
///
401397
/// The easiest way of doing this is to take every [`Resized`] window event
402-
/// that is received with a [`LogicalSize`] and convert it to a
403-
/// [`PhysicalSize`] and pass it into this function.
398+
/// that is received and call this function.
399+
///
400+
/// Note: You still have to call the [`WindowSurface`]'s
401+
/// [`update_after_resize`] function for Wayland.
404402
///
405-
/// [`LogicalSize`]: dpi/struct.LogicalSize.html
406-
/// [`PhysicalSize`]: dpi/struct.PhysicalSize.html
407403
/// [`Resized`]: event/enum.WindowEvent.html#variant.Resized
408-
pub fn resize(&self, size: dpi::PhysicalSize) {
409-
self.context.resize(size);
404+
/// FIXME: Links
405+
pub fn update_after_resize(&self) {
406+
#[cfg(target_os = "macos")]
407+
self.context.update_after_resize()
410408
}
411409
}
412410

glutin/src/platform_impl/unix/mod.rs

+107-93
Original file line numberDiff line numberDiff line change
@@ -82,97 +82,42 @@ impl Context {
8282
#[inline]
8383
pub fn new<T>(
8484
el: &EventLoop<T>,
85-
cb: ContextBuilderWrapper<&'_ Context>,
85+
cb: ContextBuilderWrapper<&Context>,
8686
pbuffer_support: bool,
8787
window_surface_support: bool,
8888
surfaceless_support: bool,
8989
) -> Result<Self, CreationError> {
9090
if el.is_wayland() {
91-
unimplemented!()
92-
/*Context::is_compatible(&gl_attr.sharing, ContextType::Wayland)?;
93-
94-
let gl_attr = gl_attr.clone().map_sharing(|ctx| match *ctx {
91+
Context::is_compatible(&cb.gl_attr.sharing, ContextType::Wayland)?;
92+
let cb = cb.clone().map_sharing(|ctx| match *ctx {
9593
Context::Wayland(ref ctx) => ctx,
9694
_ => unreachable!(),
9795
});
98-
wayland::Context::new(wb, el, pf_reqs, &gl_attr, plat_attr)
99-
.map(|(win, context)| (win, Context::Wayland(context)))*/
96+
wayland::Context::new(
97+
el,
98+
cb,
99+
pbuffer_support,
100+
window_surface_support,
101+
surfaceless_support,
102+
)
103+
.map(|context| Context::Wayland(context))
100104
} else {
101105
Context::is_compatible(&cb.gl_attr.sharing, ContextType::X11)?;
102106
let cb = cb.map_sharing(|ctx| match *ctx {
103107
Context::X11(ref ctx) => ctx,
104108
_ => unreachable!(),
105109
});
106-
x11::Context::new(el, cb, pbuffer_support, window_surface_support, surfaceless_support)
107-
.map(|context| Context::X11(context))
110+
x11::Context::new(
111+
el,
112+
cb,
113+
pbuffer_support,
114+
window_surface_support,
115+
surfaceless_support,
116+
)
117+
.map(|context| Context::X11(context))
108118
}
109119
}
110120

111-
// #[inline]
112-
// pub fn new_windowed<T>(
113-
// wb: WindowBuilder,
114-
// el: &EventLoop<T>,
115-
// pf_reqs: &PixelFormatRequirements,
116-
// gl_attr: &GlAttributes<&Context>,
117-
// plat_attr: &PlatformAttributes,
118-
// ) -> Result<(Window, Self), CreationError> {
119-
// if el.is_wayland() {
120-
// Context::is_compatible(&gl_attr.sharing, ContextType::Wayland)?;
121-
//
122-
// let gl_attr = gl_attr.clone().map_sharing(|ctx| match *ctx {
123-
// Context::Wayland(ref ctx) => ctx,
124-
// _ => unreachable!(),
125-
// });
126-
// wayland::Context::new(wb, el, pf_reqs, &gl_attr, plat_attr)
127-
// .map(|(win, context)| (win, Context::Wayland(context)))
128-
// } else {
129-
// Context::is_compatible(&gl_attr.sharing, ContextType::X11)?;
130-
// let gl_attr = gl_attr.clone().map_sharing(|ctx| match *ctx {
131-
// Context::X11(ref ctx) => ctx,
132-
// _ => unreachable!(),
133-
// });
134-
// x11::Context::new(wb, el, pf_reqs, &gl_attr, plat_attr)
135-
// .map(|(win, context)| (win, Context::X11(context)))
136-
// }
137-
// }
138-
//
139-
// #[inline]
140-
// pub fn new_headless<T>(
141-
// el: &EventLoop<T>,
142-
// pf_reqs: &PixelFormatRequirements,
143-
// gl_attr: &GlAttributes<&Context>,
144-
// plat_attr: &PlatformAttributes,
145-
// size: dpi::PhysicalSize,
146-
// ) -> Result<Self, CreationError> {
147-
// Self::new_headless_impl(el, pf_reqs, gl_attr, plat_attr, Some(size))
148-
// }
149-
//
150-
// pub fn new_headless_impl<T>(
151-
// el: &EventLoop<T>,
152-
// pf_reqs: &PixelFormatRequirements,
153-
// gl_attr: &GlAttributes<&Context>,
154-
// plat_attr: &PlatformAttributes,
155-
// size: Option<dpi::PhysicalSize>,
156-
// ) -> Result<Self, CreationError> {
157-
// if el.is_wayland() {
158-
// Context::is_compatible(&gl_attr.sharing, ContextType::Wayland)?;
159-
// let gl_attr = gl_attr.clone().map_sharing(|ctx| match *ctx {
160-
// Context::Wayland(ref ctx) => ctx,
161-
// _ => unreachable!(),
162-
// });
163-
// wayland::Context::new_headless(&el, pf_reqs, &gl_attr, plat_attr, size)
164-
// .map(|ctx| Context::Wayland(ctx))
165-
// } else {
166-
// Context::is_compatible(&gl_attr.sharing, ContextType::X11)?;
167-
// let gl_attr = gl_attr.clone().map_sharing(|ctx| match *ctx {
168-
// Context::X11(ref ctx) => ctx,
169-
// _ => unreachable!(),
170-
// });
171-
// x11::Context::new_headless(&el, pf_reqs, &gl_attr, plat_attr, size)
172-
// .map(|ctx| Context::X11(ctx))
173-
// }
174-
// }
175-
176121
#[inline]
177122
pub unsafe fn make_current(&self) -> Result<(), ContextError> {
178123
match *self {
@@ -225,15 +170,6 @@ impl Context {
225170
}
226171
}
227172

228-
#[inline]
229-
pub fn resize(&self, size: dpi::PhysicalSize) {
230-
match *self {
231-
Context::X11(_) => (),
232-
Context::Wayland(ref ctx) => ctx.resize(size),
233-
_ => unreachable!(),
234-
}
235-
}
236-
237173
#[inline]
238174
pub fn get_proc_address(&self, addr: &str) -> *const () {
239175
match *self {
@@ -250,15 +186,6 @@ impl Context {
250186
_ => unreachable!(),
251187
}
252188
}
253-
254-
#[inline]
255-
pub fn get_pixel_format(&self) -> PixelFormat {
256-
match *self {
257-
Context::X11(ref ctx) => ctx.get_pixel_format(),
258-
Context::Wayland(ref ctx) => ctx.get_pixel_format(),
259-
_ => unreachable!(),
260-
}
261-
}
262189
}
263190

264191
#[derive(Debug, Clone)]
@@ -284,6 +211,93 @@ pub struct PlatformAttributes {
284211
/// GLX only: Whether the context will have transparency support.
285212
pub glx_transparency: Option<bool>,
286213

287-
/// Ignored by surfaceless.
214+
/// Ignored by surfaceless, which is always egl.
288215
pub backing_api: BackingApi,
289216
}
217+
218+
#[derive(Debug)]
219+
pub enum WindowSurface {
220+
X11(x11::WindowSurface),
221+
Wayland(wayland::WindowSurface),
222+
}
223+
224+
impl WindowSurface {
225+
#[inline]
226+
pub fn new<T>(
227+
el: &EventLoop<T>,
228+
ctx: &Context,
229+
wb: WindowBuilder,
230+
) -> Result<(Self, Window), CreationError> {
231+
match ctx {
232+
Context::X11(ref ctx) => x11::WindowSurface::new(el, ctx, wb)
233+
.map(|ws| WindowSurface::X11(ws)),
234+
Context::Wayland(ref ctx) => {
235+
wayland::WindowSurface::new(el, ctx, wb)
236+
.map(|ws| WindowSurface::Wayland(ws))
237+
}
238+
}
239+
}
240+
241+
#[inline]
242+
pub fn get_pixel_format(&self) -> PixelFormat {
243+
match self {
244+
WindowSurface::X11(ws) => ws.get_pixel_format(),
245+
WindowSurface::Wayland(ws) => ws.get_pixel_format(),
246+
}
247+
}
248+
249+
#[inline]
250+
pub fn is_current(&self) -> bool {
251+
match self {
252+
WindowSurface::X11(ws) => ws.is_current(),
253+
WindowSurface::Wayland(ws) => ws.is_current(),
254+
}
255+
}
256+
257+
#[inline]
258+
pub fn update_after_resize(&self, size: dpi::PhysicalSize) {
259+
match self {
260+
Context::Wayland(ref ctx) => ctx.update_after_resize(size),
261+
_ => (),
262+
}
263+
}
264+
}
265+
266+
#[derive(Debug)]
267+
pub enum PBuffer {
268+
X11(x11::PBuffer),
269+
Wayland(wayland::PBuffer),
270+
}
271+
272+
impl PBuffer {
273+
#[inline]
274+
pub fn new<T>(
275+
el: &EventLoop<T>,
276+
ctx: &Context,
277+
size: dpi::PhysicalSize,
278+
) -> Result<Self, CreationError> {
279+
match ctx {
280+
Context::X11(ref ctx) => {
281+
x11::PBuffer::new(el, ctx, size).map(|pb| PBuffer::X11(pb))
282+
}
283+
Context::Wayland(ref ctx) => wayland::PBuffer::new(el, ctx, size)
284+
.map(|pb| PBuffer::Wayland(pb)),
285+
}
286+
}
287+
288+
#[inline]
289+
pub fn get_pixel_format(&self) -> PixelFormat {
290+
match self {
291+
PBuffer::X11(pb) => pb.get_pixel_format(),
292+
PBuffer::Wayland(pb) => pb.get_pixel_format(),
293+
}
294+
}
295+
296+
#[inline]
297+
pub fn is_current(&self) -> bool {
298+
match self {
299+
PBuffer::X11(pb) => pb.is_current(),
300+
PBuffer::Wayland(pb) => pb.is_current(),
301+
}
302+
}
303+
}

0 commit comments

Comments
 (0)