Skip to content

Commit cff3caf

Browse files
committed
Refactoring as of 2019-07-13
Signed-off-by: Hal Gentz <zegentzy@protonmail.com>
1 parent 92ca12d commit cff3caf

38 files changed

+1049
-1143
lines changed

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
[workspace]
22
members = [
33
"glutin",
4+
"glutin_lighter",
45
"glutin_examples",
56
"glutin_egl_sys",
67
"glutin_glx_sys",
78
"glutin_wgl_sys",
89
"glutin_gles2_sys",
9-
"glutin_emscripten_sys",
1010
]
1111

1212
[replace]

README.md

-21
Original file line numberDiff line numberDiff line change
@@ -52,27 +52,6 @@ To compile the examples for android, you have to use the `cargo apk` utility.
5252

5353
See [the `android-rs-glue` repository](https://github.com/rust-windowing/android-rs-glue) for instructions.
5454

55-
### Emscripten with asmjs
56-
57-
In order to use glutin with emscripten, start by compiling your code with `--target=asmjs-unknown-emscripten`.
58-
59-
Then create an HTML document that contains this:
60-
61-
```html
62-
<canvas id="canvas"></canvas>
63-
<script type="text/javascript">
64-
var Module = {
65-
canvas: document.getElementById('canvas')
66-
};
67-
</script>
68-
<script type="text/javascript" src="target/asmjs-unknown-emscripten/debug/..." async></script>
69-
```
70-
71-
*Note: adjust the `src` element of the script to point to the .js file that was produced by the compilation.*
72-
73-
The `Module` object is the link between emscripten and the HTML page.
74-
See also [this documentation](https://kripken.github.io/emscripten-site/docs/api_reference/module.html).
75-
7655
### X11
7756

7857
The plan is that glutin tries to dynamically link-to and use wayland if possible. If it doesn't work, it will try xlib instead. This is work-in-progress.

glutin/Cargo.toml

+1-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "glutin"
3-
version = "0.22.0-alpha1"
3+
version = "0.23.0-alpha1"
44
authors = ["The glutin contributors", "Pierre Krieger <pierre.krieger1708@gmail.com>"]
55
description = "Cross-platform OpenGL context provider."
66
keywords = ["windowing", "opengl"]
@@ -27,9 +27,6 @@ android_glue = "0.2"
2727
glutin_egl_sys = { version = "0.1.3", path = "../glutin_egl_sys" }
2828
parking_lot = "0.8"
2929

30-
[target.'cfg(target_os = "emscripten")'.dependencies]
31-
glutin_emscripten_sys = { version = "0.1.0", path = "../glutin_emscripten_sys" }
32-
3330
[target.'cfg(any(target_os = "ios", target_os = "macos"))'.dependencies]
3431
objc = "0.2.6"
3532
glutin_gles2_sys = { version = "0.1.3", path = "../glutin_gles2_sys" }
File renamed without changes.

glutin/src/api/android/mod.rs glutin/src/api/android.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@ use crate::{
88
Api, ContextError, GlAttributes, PixelFormat, PixelFormatRequirements,
99
};
1010

11-
use winit::window::WindowBuilder;
12-
use winit::event_loop::EventLoopWindowTarget;
1311
use crate::platform::android::EventLoopExtAndroid;
1412
use glutin_egl_sys as ffi;
1513
use parking_lot::Mutex;
1614
use winit;
1715
use winit::dpi;
16+
use winit::event_loop::EventLoopWindowTarget;
17+
use winit::window::WindowBuilder;
1818

1919
use std::sync::Arc;
2020

glutin/src/api/egl/mod.rs glutin/src/api/egl.rs

+10-5
Original file line numberDiff line numberDiff line change
@@ -156,8 +156,8 @@ fn get_egl_version(
156156
) -> Result<(ffi::egl::types::EGLint, ffi::egl::types::EGLint), CreationError> {
157157
unsafe {
158158
let egl = EGL.as_ref().unwrap();
159-
let mut major: ffi::egl::types::EGLint = std::mem::uninitialized();
160-
let mut minor: ffi::egl::types::EGLint = std::mem::uninitialized();
159+
let mut major: ffi::egl::types::EGLint = 0;
160+
let mut minor: ffi::egl::types::EGLint = 0;
161161

162162
if egl.Initialize(display, &mut major, &mut minor) == 0 {
163163
return Err(CreationError::OsError(
@@ -624,6 +624,11 @@ impl Context {
624624
unsafe { egl.GetCurrentContext() == self.context }
625625
}
626626

627+
#[inline]
628+
pub fn get_pixel_format(&self) -> PixelFormat {
629+
self.pixel_format.clone()
630+
}
631+
627632
#[inline]
628633
pub fn get_api(&self) -> Api {
629634
self.api
@@ -826,7 +831,7 @@ pub fn get_native_visual_id(
826831
config_id: ffi::egl::types::EGLConfig,
827832
) -> ffi::egl::types::EGLint {
828833
let egl = EGL.as_ref().unwrap();
829-
let mut value = unsafe { std::mem::uninitialized() };
834+
let mut value = 0;
830835
let ret = unsafe {
831836
egl.GetConfigAttrib(
832837
display,
@@ -1172,7 +1177,7 @@ where
11721177
};
11731178

11741179
// calling `eglChooseConfig`
1175-
let mut num_configs = std::mem::uninitialized();
1180+
let mut num_configs = 0;
11761181
if egl.ChooseConfig(
11771182
display,
11781183
descriptor.as_ptr(),
@@ -1215,7 +1220,7 @@ where
12151220
// analyzing each config
12161221
macro_rules! attrib {
12171222
($egl:expr, $display:expr, $config:expr, $attr:expr) => {{
1218-
let mut value = std::mem::uninitialized();
1223+
let mut value = 0;
12191224
let res = $egl.GetConfigAttrib(
12201225
$display,
12211226
$config,

glutin/src/api/glx/mod.rs glutin/src/api/glx.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -425,7 +425,7 @@ impl<'a> ContextPrototype<'a> {
425425
);
426426
}
427427

428-
let mut swap = unsafe { std::mem::uninitialized() };
428+
let mut swap = 0;
429429
unsafe {
430430
glx.QueryDrawable(
431431
self.xconn.display as *mut _,

glutin/src/api/ios/mod.rs glutin/src/api/ios.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,8 @@ use glutin_gles2_sys as ffi;
7070
use objc::declare::ClassDecl;
7171
use objc::runtime::{Class, Object, Sel, BOOL, NO, YES};
7272
use winit::dpi;
73-
use winit::window::WindowBuilder;
7473
use winit::event_loop::EventLoopWindowTarget;
74+
use winit::window::WindowBuilder;
7575

7676
use std::ffi::CString;
7777
use std::os::raw;

glutin/src/api/osmesa/mod.rs glutin/src/api/osmesa.rs

+8-5
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,18 @@ use winit::dpi;
2020

2121
use std::ffi::CString;
2222
use std::os::raw;
23+
use std::mem::MaybeUninit;
2324

2425
#[derive(Debug)]
2526
pub struct OsMesaContext {
2627
context: osmesa_sys::OSMesaContext,
2728
}
2829

29-
#[derive(Debug)]
30+
#[derive(Derivative)]
31+
#[derivative(Debug)]
3032
pub struct OsMesaBuffer {
31-
buffer: Vec<u32>,
33+
#[derivative(Debug = "ignore")]
34+
buffer: Vec<MaybeUninit<u8>>,
3235
width: u32,
3336
height: u32,
3437
}
@@ -161,7 +164,7 @@ impl OsMesaContext {
161164
let ret = osmesa_sys::OSMesaMakeCurrent(
162165
self.context,
163166
buffer.buffer.as_ptr() as *mut _,
164-
0x1401,
167+
0x1401, // GL_UNSIGNED_BYTE
165168
buffer.width as raw::c_int,
166169
buffer.height as raw::c_int,
167170
);
@@ -255,8 +258,8 @@ impl OsMesaBuffer {
255258
Ok(OsMesaBuffer {
256259
width: size.0,
257260
height: size.1,
258-
buffer: std::iter::repeat(unsafe { std::mem::uninitialized() })
259-
.take((size.0 * size.1) as usize)
261+
buffer: std::iter::repeat(MaybeUninit::uninit())
262+
.take(size.0 as usize * size.1 as usize * 4)
260263
.collect(),
261264
})
262265
}

glutin/src/api/wgl/mod.rs glutin/src/api/wgl.rs

+5-9
Original file line numberDiff line numberDiff line change
@@ -708,18 +708,14 @@ unsafe fn choose_arb_pixel_format_id(
708708
.find(|&i| i == "WGL_ARB_framebuffer_sRGB")
709709
.is_some()
710710
{
711-
out.push(
712-
gl::wgl_extra::FRAMEBUFFER_SRGB_CAPABLE_ARB as raw::c_int,
713-
);
711+
out.push(gl::wgl_extra::FRAMEBUFFER_SRGB_CAPABLE_ARB as raw::c_int);
714712
out.push(pf_reqs.srgb as raw::c_int);
715713
} else if extensions
716714
.split(' ')
717715
.find(|&i| i == "WGL_EXT_framebuffer_sRGB")
718716
.is_some()
719717
{
720-
out.push(
721-
gl::wgl_extra::FRAMEBUFFER_SRGB_CAPABLE_EXT as raw::c_int,
722-
);
718+
out.push(gl::wgl_extra::FRAMEBUFFER_SRGB_CAPABLE_EXT as raw::c_int);
723719
out.push(pf_reqs.srgb as raw::c_int);
724720
} else if pf_reqs.srgb {
725721
return Err(());
@@ -749,8 +745,8 @@ unsafe fn choose_arb_pixel_format_id(
749745
out
750746
};
751747

752-
let mut format_id = std::mem::uninitialized();
753-
let mut num_formats = std::mem::uninitialized();
748+
let mut format_id = 0;
749+
let mut num_formats = 0;
754750
if extra.ChoosePixelFormatARB(
755751
hdc as *const _,
756752
descriptor.as_ptr(),
@@ -777,7 +773,7 @@ unsafe fn choose_arb_pixel_format(
777773
format_id: raw::c_int,
778774
) -> Result<PixelFormat, ()> {
779775
let get_info = |attrib: u32| {
780-
let mut value = std::mem::uninitialized();
776+
let mut value = 0;
781777
extra.GetPixelFormatAttribivARB(
782778
hdc as *const _,
783779
format_id as raw::c_int,

0 commit comments

Comments
 (0)