Skip to content

Commit a77c18c

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

21 files changed

+720
-502
lines changed

.travis.yml

+2
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,13 @@ env:
5858
install:
5959
- rustup self update
6060
- rustup target add $TARGET; true
61+
- rustup component add rustfmt
6162

6263
script:
6364
- cargo build --target $TARGET --verbose
6465
# Running iOS apps on OSX requires the simulator so we skip that for now
6566
- if [ "$TARGET" != "x86_64-apple-ios" ]; then cargo test --target $TARGET --verbose; fi
67+
- cargo fmt --all -- --check
6668

6769
after_success:
6870
- |

glutin/src/api/egl/mod.rs

+20-22
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,12 @@ mod make_current_guard;
6060

6161
pub use self::egl::Egl;
6262
use self::make_current_guard::MakeCurrentGuard;
63+
use crate::platform_impl::PlatformAttributes;
6364
use crate::{
64-
Api, ContextError, CreationError, GlAttributes, GlRequest, PixelFormat,
65-
PixelFormatRequirements, ReleaseBehavior, Robustness,
65+
Api, ContextBuilderWrapper, ContextError, CreationError, GlAttributes,
66+
GlRequest, PixelFormat, PixelFormatRequirements, ReleaseBehavior,
67+
Robustness,
6668
};
67-
use crate::platform_impl::PlatformAttributes;
6869

6970
use glutin_egl_sys as ffi;
7071
use parking_lot::Mutex;
@@ -390,9 +391,7 @@ impl Context {
390391
/// To finish the process, you must call `.finish(window)` on the
391392
/// `ContextPrototype`.
392393
pub fn new<'a, F>(
393-
pf_reqs: &PixelFormatRequirements,
394-
gl_attr: &'a GlAttributes<&'a Context>,
395-
plat_attr: &PlatformAttributes,
394+
cb: &'a ContextBuilderWrapper<&'a Context>,
396395
native_display: NativeDisplay,
397396
surface_type: SurfaceType,
398397
config_selector: F,
@@ -431,23 +430,23 @@ impl Context {
431430
};
432431

433432
// binding the right API and choosing the version
434-
let (version, api) = unsafe { bind_and_get_api(&gl_attr, egl_version)? };
433+
let (version, api) =
434+
unsafe { bind_and_get_api(&cb.gl_attr, egl_version)? };
435435

436436
let (config_id, pixel_format) = unsafe {
437437
choose_fbconfig(
438438
display,
439439
&egl_version,
440440
api,
441441
version,
442-
pf_reqs,
443-
plat_attr,
442+
cb,
444443
surface_type,
445444
config_selector,
446445
)?
447446
};
448447

449448
Ok(ContextPrototype {
450-
gl_attr,
449+
gl_attr: &cb.gl_attr,
451450
display,
452451
egl_version,
453452
extensions,
@@ -997,8 +996,7 @@ unsafe fn choose_fbconfig<F>(
997996
egl_version: &(ffi::egl::types::EGLint, ffi::egl::types::EGLint),
998997
api: Api,
999998
version: Option<(u8, u8)>,
1000-
pf_reqs: &PixelFormatRequirements,
1001-
plat_attr: &PlatformAttributes,
999+
cb: &ContextBuilderWrapper<&Context>,
10021000
surface_type: SurfaceType,
10031001
mut config_selector: F,
10041002
) -> Result<(ffi::egl::types::EGLConfig, PixelFormat), CreationError>
@@ -1066,7 +1064,7 @@ where
10661064
(_, _) => unimplemented!(),
10671065
};
10681066

1069-
if let Some(hardware_accelerated) = pf_reqs.hardware_accelerated {
1067+
if let Some(hardware_accelerated) = cb.pf_reqs.hardware_accelerated {
10701068
out.push(ffi::egl::CONFIG_CAVEAT as raw::c_int);
10711069
out.push(if hardware_accelerated {
10721070
ffi::egl::NONE as raw::c_int
@@ -1075,7 +1073,7 @@ where
10751073
});
10761074
}
10771075

1078-
if let Some(color) = pf_reqs.color_bits {
1076+
if let Some(color) = cb.pf_reqs.color_bits {
10791077
out.push(ffi::egl::RED_SIZE as raw::c_int);
10801078
out.push((color / 3) as raw::c_int);
10811079
out.push(ffi::egl::GREEN_SIZE as raw::c_int);
@@ -1088,42 +1086,42 @@ where
10881086
);
10891087
}
10901088

1091-
if let Some(alpha) = pf_reqs.alpha_bits {
1089+
if let Some(alpha) = cb.pf_reqs.alpha_bits {
10921090
out.push(ffi::egl::ALPHA_SIZE as raw::c_int);
10931091
out.push(alpha as raw::c_int);
10941092
}
10951093

1096-
if let Some(depth) = pf_reqs.depth_bits {
1094+
if let Some(depth) = cb.pf_reqs.depth_bits {
10971095
out.push(ffi::egl::DEPTH_SIZE as raw::c_int);
10981096
out.push(depth as raw::c_int);
10991097
}
11001098

1101-
if let Some(stencil) = pf_reqs.stencil_bits {
1099+
if let Some(stencil) = cb.pf_reqs.stencil_bits {
11021100
out.push(ffi::egl::STENCIL_SIZE as raw::c_int);
11031101
out.push(stencil as raw::c_int);
11041102
}
11051103

1106-
if let Some(true) = pf_reqs.double_buffer {
1104+
if let Some(true) = cb.pf_reqs.double_buffer {
11071105
return Err(CreationError::NoAvailablePixelFormat);
11081106
}
11091107

1110-
if let Some(multisampling) = pf_reqs.multisampling {
1108+
if let Some(multisampling) = cb.pf_reqs.multisampling {
11111109
out.push(ffi::egl::SAMPLES as raw::c_int);
11121110
out.push(multisampling as raw::c_int);
11131111
}
11141112

1115-
if pf_reqs.stereoscopy {
1113+
if cb.pf_reqs.stereoscopy {
11161114
return Err(CreationError::NoAvailablePixelFormat);
11171115
}
11181116

1119-
if let Some(xid) = plat_attr.x11_visual_xid {
1117+
if let Some(xid) = cb.plat_attr.x11_visual_xid {
11201118
out.push(ffi::egl::NATIVE_VISUAL_ID as raw::c_int);
11211119
out.push(xid as raw::c_int);
11221120
}
11231121

11241122
// FIXME: srgb is not taken into account
11251123

1126-
match pf_reqs.release_behavior {
1124+
match cb.pf_reqs.release_behavior {
11271125
ReleaseBehavior::Flush => (),
11281126
ReleaseBehavior::None => {
11291127
// TODO: with EGL you need to manually set the behavior

glutin/src/api/glx/mod.rs

+19-22
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,9 @@ mod glx {
5353
pub use self::glx::Glx;
5454
use self::make_current_guard::MakeCurrentGuard;
5555
use crate::{
56-
Api, ContextError, CreationError, GlAttributes, GlProfile, GlRequest,
57-
PixelFormat, PixelFormatRequirements, ReleaseBehavior, Robustness,
56+
Api, ContextBuilderWrapper, ContextError, CreationError, GlAttributes,
57+
GlProfile, GlRequest, PixelFormat, PixelFormatRequirements,
58+
ReleaseBehavior, Robustness,
5859
};
5960

6061
use crate::platform::unix::x11::XConnection;
@@ -83,9 +84,7 @@ impl Context {
8384
// transparent is `None` if window is raw.
8485
pub fn new<'a>(
8586
xconn: Arc<XConnection>,
86-
pf_reqs: &PixelFormatRequirements,
87-
gl_attr: &'a GlAttributes<&'a Context>,
88-
plat_attr: &PlatformAttributes,
87+
cb: &'a ContextBuilderWrapper<&'a Context>,
8988
screen_id: raw::c_int,
9089
surface_type: SurfaceType,
9190
transparent: Option<bool>,
@@ -113,8 +112,7 @@ impl Context {
113112
&extensions,
114113
&xconn,
115114
screen_id,
116-
pf_reqs,
117-
plat_attr,
115+
cb,
118116
surface_type,
119117
transparent,
120118
)?
@@ -123,7 +121,7 @@ impl Context {
123121
Ok(ContextPrototype {
124122
extensions,
125123
xconn,
126-
gl_attr,
124+
gl_attr: &cb.gl_attr,
127125
fb_config,
128126
visual_infos: unsafe { std::mem::transmute(visual_infos) },
129127
pixel_format,
@@ -610,8 +608,7 @@ unsafe fn choose_fbconfig(
610608
extensions: &str,
611609
xconn: &Arc<XConnection>,
612610
screen_id: raw::c_int,
613-
pf_reqs: &PixelFormatRequirements,
614-
plat_attr: &PlatformAttributes,
611+
cb: &ContextBuilderWrapper<&Context>,
615612
surface_type: SurfaceType,
616613
transparent: Option<bool>,
617614
) -> Result<
@@ -626,7 +623,7 @@ unsafe fn choose_fbconfig(
626623
out.push(ffi::glx::X_RENDERABLE as raw::c_int);
627624
out.push(1);
628625

629-
if let Some(xid) = plat_attr.x11_visual_xid {
626+
if let Some(xid) = cb.plat_attr.x11_visual_xid {
630627
// getting the visual infos
631628
let fvi = crate::platform_impl::x11_utils::get_visual_info_from_xid(
632629
&xconn, xid,
@@ -653,7 +650,7 @@ unsafe fn choose_fbconfig(
653650
// TODO: Use RGB/RGB_FLOAT_BIT_ARB if they don't want alpha bits,
654651
// fallback to it if they don't care
655652
out.push(ffi::glx::RENDER_TYPE as raw::c_int);
656-
if pf_reqs.float_color_buffer {
653+
if cb.pf_reqs.float_color_buffer {
657654
if check_ext(extensions, "GLX_ARB_fbconfig_float") {
658655
out.push(ffi::glx_extra::RGBA_FLOAT_BIT_ARB as raw::c_int);
659656
} else {
@@ -663,7 +660,7 @@ unsafe fn choose_fbconfig(
663660
out.push(ffi::glx::RGBA_BIT as raw::c_int);
664661
}
665662

666-
if let Some(color) = pf_reqs.color_bits {
663+
if let Some(color) = cb.pf_reqs.color_bits {
667664
out.push(ffi::glx::RED_SIZE as raw::c_int);
668665
out.push((color / 3) as raw::c_int);
669666
out.push(ffi::glx::GREEN_SIZE as raw::c_int);
@@ -676,26 +673,26 @@ unsafe fn choose_fbconfig(
676673
);
677674
}
678675

679-
if let Some(alpha) = pf_reqs.alpha_bits {
676+
if let Some(alpha) = cb.pf_reqs.alpha_bits {
680677
out.push(ffi::glx::ALPHA_SIZE as raw::c_int);
681678
out.push(alpha as raw::c_int);
682679
}
683680

684-
if let Some(depth) = pf_reqs.depth_bits {
681+
if let Some(depth) = cb.pf_reqs.depth_bits {
685682
out.push(ffi::glx::DEPTH_SIZE as raw::c_int);
686683
out.push(depth as raw::c_int);
687684
}
688685

689-
if let Some(stencil) = pf_reqs.stencil_bits {
686+
if let Some(stencil) = cb.pf_reqs.stencil_bits {
690687
out.push(ffi::glx::STENCIL_SIZE as raw::c_int);
691688
out.push(stencil as raw::c_int);
692689
}
693690

694-
let double_buffer = pf_reqs.double_buffer.unwrap_or(true);
691+
let double_buffer = cb.pf_reqs.double_buffer.unwrap_or(true);
695692
out.push(ffi::glx::DOUBLEBUFFER as raw::c_int);
696693
out.push(if double_buffer { 1 } else { 0 });
697694

698-
if let Some(multisampling) = pf_reqs.multisampling {
695+
if let Some(multisampling) = cb.pf_reqs.multisampling {
699696
if check_ext(extensions, "GLX_ARB_multisample") {
700697
out.push(ffi::glx_extra::SAMPLE_BUFFERS_ARB as raw::c_int);
701698
out.push(if multisampling == 0 { 0 } else { 1 });
@@ -707,9 +704,9 @@ unsafe fn choose_fbconfig(
707704
}
708705

709706
out.push(ffi::glx::STEREO as raw::c_int);
710-
out.push(if pf_reqs.stereoscopy { 1 } else { 0 });
707+
out.push(if cb.pf_reqs.stereoscopy { 1 } else { 0 });
711708

712-
if pf_reqs.srgb {
709+
if cb.pf_reqs.srgb {
713710
if check_ext(extensions, "GLX_ARB_framebuffer_sRGB") {
714711
out.push(
715712
ffi::glx_extra::FRAMEBUFFER_SRGB_CAPABLE_ARB as raw::c_int,
@@ -725,7 +722,7 @@ unsafe fn choose_fbconfig(
725722
}
726723
}
727724

728-
match pf_reqs.release_behavior {
725+
match cb.pf_reqs.release_behavior {
729726
ReleaseBehavior::Flush => (),
730727
ReleaseBehavior::None => {
731728
if check_ext(extensions, "GLX_ARB_context_flush_control") {
@@ -770,7 +767,7 @@ unsafe fn choose_fbconfig(
770767
match crate::platform_impl::x11_utils::select_config(
771768
xconn,
772769
transparent,
773-
plat_attr,
770+
cb,
774771
(0..num_configs).collect(),
775772
|config_id| {
776773
let visual_infos_raw = glx.GetVisualFromFBConfig(

glutin/src/api/osmesa/mod.rs

+11-5
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ pub mod ffi {
1010
pub use osmesa_sys::OSMesaContext;
1111
}
1212

13+
use crate::platform_impl::PlatformAttributes;
1314
use crate::{
14-
Api, ContextError, CreationError, GlAttributes, GlProfile, GlRequest,
15-
PixelFormatRequirements, Robustness, ContextBuilderWrapper, PixelFormat
15+
Api, ContextBuilderWrapper, ContextError, CreationError, GlAttributes,
16+
GlProfile, GlRequest, PixelFormat, PixelFormatRequirements, Robustness,
1617
};
17-
use crate::platform_impl::PlatformAttributes;
1818

1919
use winit::dpi;
2020

@@ -154,7 +154,10 @@ impl OsMesaContext {
154154
}
155155

156156
#[inline]
157-
pub unsafe fn make_current_osmesa_buffer(&self, buffer: &mut OsMesaBuffer) -> Result<(), ContextError> {
157+
pub unsafe fn make_current_osmesa_buffer(
158+
&self,
159+
buffer: &mut OsMesaBuffer,
160+
) -> Result<(), ContextError> {
158161
let ret = osmesa_sys::OSMesaMakeCurrent(
159162
self.context,
160163
buffer.buffer.as_ptr() as *mut _,
@@ -244,7 +247,10 @@ unsafe impl Send for OsMesaContext {}
244247
unsafe impl Sync for OsMesaContext {}
245248

246249
impl OsMesaBuffer {
247-
pub fn new(ctx: &OsMesaContext, size: dpi::PhysicalSize) -> Result<Self, CreationError> {
250+
pub fn new(
251+
ctx: &OsMesaContext,
252+
size: dpi::PhysicalSize,
253+
) -> Result<Self, CreationError> {
248254
let size: (u32, u32) = size.into();
249255
Ok(OsMesaBuffer {
250256
width: size.0,

0 commit comments

Comments
 (0)