Skip to content

Commit 6220e4b

Browse files
committed
OSMesa and drop CI
Signed-off-by: Hal Gentz <zegentzy@protonmail.com>
1 parent c5f3eb8 commit 6220e4b

File tree

8 files changed

+64
-110
lines changed

8 files changed

+64
-110
lines changed

.circleci/config.yml

-56
This file was deleted.

glutin/src/api/osmesa/mod.rs

+42-20
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ pub mod ffi {
1212

1313
use crate::{
1414
Api, ContextError, CreationError, GlAttributes, GlProfile, GlRequest,
15-
PixelFormatRequirements, Robustness,
15+
PixelFormatRequirements, Robustness, ContextBuilderWrapper, PixelFormat
1616
};
1717
use crate::platform_impl::PlatformAttributes;
1818

@@ -24,6 +24,10 @@ use std::os::raw;
2424
#[derive(Debug)]
2525
pub struct OsMesaContext {
2626
context: osmesa_sys::OSMesaContext,
27+
}
28+
29+
#[derive(Debug)]
30+
pub struct OsMesaBuffer {
2731
buffer: Vec<u32>,
2832
width: u32,
2933
height: u32,
@@ -70,20 +74,17 @@ impl std::error::Error for LoadingError {
7074

7175
impl OsMesaContext {
7276
pub fn new(
73-
_pf_reqs: &PixelFormatRequirements,
74-
opengl: &GlAttributes<&OsMesaContext>,
75-
_: &PlatformAttributes,
76-
size: dpi::PhysicalSize,
77+
cb: ContextBuilderWrapper<&'_ OsMesaContext>,
7778
) -> Result<Self, CreationError> {
7879
osmesa_sys::OsMesa::try_loading()
7980
.map_err(LoadingError::new)
8081
.map_err(|e| CreationError::NoBackendAvailable(Box::new(e)))?;
8182

82-
if opengl.sharing.is_some() {
83+
if cb.gl_attr.sharing.is_some() {
8384
panic!("Context sharing not possible with OsMesa")
8485
}
8586

86-
match opengl.robustness {
87+
match cb.gl_attr.robustness {
8788
Robustness::RobustNoResetNotification
8889
| Robustness::RobustLoseContextOnReset => {
8990
return Err(CreationError::RobustnessNotSupported.into());
@@ -95,7 +96,7 @@ impl OsMesaContext {
9596

9697
let mut attribs = Vec::new();
9798

98-
if let Some(profile) = opengl.profile {
99+
if let Some(profile) = cb.gl_attr.profile {
99100
attribs.push(osmesa_sys::OSMESA_PROFILE);
100101

101102
match profile {
@@ -108,7 +109,7 @@ impl OsMesaContext {
108109
}
109110
}
110111

111-
match opengl.version {
112+
match cb.gl_attr.version {
112113
GlRequest::Latest => {}
113114
GlRequest::Specific(Api::OpenGl, (major, minor)) => {
114115
attribs.push(osmesa_sys::OSMESA_CONTEXT_MAJOR_VERSION);
@@ -136,14 +137,7 @@ impl OsMesaContext {
136137
// attribs array must be NULL terminated.
137138
attribs.push(0);
138139

139-
let size: (u32, u32) = size.into();
140-
141140
Ok(OsMesaContext {
142-
width: size.0,
143-
height: size.1,
144-
buffer: std::iter::repeat(unsafe { std::mem::uninitialized() })
145-
.take((size.0 * size.1) as usize)
146-
.collect(),
147141
context: unsafe {
148142
let ctx = osmesa_sys::OSMesaCreateContextAttribs(
149143
attribs.as_ptr(),
@@ -160,13 +154,13 @@ impl OsMesaContext {
160154
}
161155

162156
#[inline]
163-
pub unsafe fn make_current(&self) -> Result<(), ContextError> {
157+
pub unsafe fn make_current_osmesa_buffer(&self, buffer: &mut OsMesaBuffer) -> Result<(), ContextError> {
164158
let ret = osmesa_sys::OSMesaMakeCurrent(
165159
self.context,
166-
self.buffer.as_ptr() as *mut _,
160+
buffer.buffer.as_ptr() as *mut _,
167161
0x1401,
168-
self.width as raw::c_int,
169-
self.height as raw::c_int,
162+
buffer.width as raw::c_int,
163+
buffer.height as raw::c_int,
170164
);
171165

172166
// an error can only happen in case of invalid parameter, which would
@@ -190,6 +184,11 @@ impl OsMesaContext {
190184
// and seeing if it work.
191185
//
192186
// https://gitlab.freedesktop.org/mesa/mesa/merge_requests/533
187+
//
188+
// EDIT: 2019/06/13: This PR has recieved no attention, and will
189+
// likely never be merged in my lifetime :/
190+
//
191+
// Honestly, just go use EGL-Surfaceless!
193192
let ret = osmesa_sys::OSMesaMakeCurrent(
194193
std::ptr::null_mut(),
195194
std::ptr::null_mut(),
@@ -243,3 +242,26 @@ impl Drop for OsMesaContext {
243242

244243
unsafe impl Send for OsMesaContext {}
245244
unsafe impl Sync for OsMesaContext {}
245+
246+
impl OsMesaBuffer {
247+
pub fn new(ctx: &OsMesaContext, size: dpi::PhysicalSize) -> Result<Self, CreationError> {
248+
let size: (u32, u32) = size.into();
249+
Ok(OsMesaBuffer {
250+
width: size.0,
251+
height: size.1,
252+
buffer: std::iter::repeat(unsafe { std::mem::uninitialized() })
253+
.take((size.0 * size.1) as usize)
254+
.collect(),
255+
})
256+
}
257+
258+
#[inline]
259+
pub fn is_current(&self) -> bool {
260+
panic!("This cannot be implemented with OsMesa.")
261+
}
262+
263+
#[inline]
264+
pub fn get_pixel_format(&self) -> PixelFormat {
265+
unimplemented!()
266+
}
267+
}

glutin/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@
7878
target_os = "emscripten",
7979
))]
8080
#![deny(
81-
warnings,
81+
//warnings,
8282
missing_debug_implementations,
8383
//missing_docs,
8484
)]

glutin/src/platform/unix.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
target_os = "openbsd",
77
))]
88

9-
mod osmesa;
9+
pub mod osmesa;
1010
//mod rawext;
1111

1212
use crate::platform::ContextTraitExt;
@@ -16,7 +16,6 @@ pub use glutin_egl_sys::EGLContext;
1616
pub use glutin_glx_sys::GLXContext;
1717

1818
pub use winit::platform::unix::*;
19-
pub use self::osmesa::*;
2019
//pub use self::rawext::*;
2120

2221
use std::os::raw;

glutin/src/platform/unix/osmesa.rs

+6-10
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ pub trait OsMesaContextExt {
1919
/// [`Context`]: struct.Context.html
2020
fn build_osmesa(
2121
self,
22-
size: dpi::PhysicalSize,
2322
) -> Result<OsMesaContext<NotCurrent>, CreationError>
2423
where
2524
Self: Sized;
@@ -31,24 +30,17 @@ impl<'a, T: ContextCurrentState> OsMesaContextExt
3130
#[inline]
3231
fn build_osmesa(
3332
self,
34-
size: dpi::PhysicalSize,
3533
) -> Result<OsMesaContext<NotCurrent>, CreationError>
3634
where
3735
Self: Sized,
3836
{
3937
let cb = self.map_sharing(|ctx| &ctx.context);
40-
osmesa::OsMesaContext::new(cb, size).map(
38+
osmesa::OsMesaContext::new(cb).map(
4139
|context| OsMesaContext {
4240
context,
4341
phantom: PhantomData,
4442
}
4543
)
46-
//osmesa::OsMesaContext::new(&pf_reqs, &gl_attr, &plat_attr, size)
47-
// .map(|context| Context::OsMesa(context))
48-
// .map(|context| crate::Context {
49-
// context,
50-
// phantom: PhantomData,
51-
// })
5244
}
5345
}
5446

@@ -130,12 +122,16 @@ impl Surface for OsMesaBuffer {
130122
fn get_pixel_format(&self) -> PixelFormat {
131123
self.surface.get_pixel_format()
132124
}
125+
126+
fn is_current(&self) -> bool {
127+
self.surface.is_current()
128+
}
133129
}
134130

135131
impl OsMesaBuffer {
136132
pub fn new<CS: ContextCurrentState>(ctx: &OsMesaContext<CS>, size: dpi::PhysicalSize) -> Result<Self, CreationError> {
137133
let ctx = ctx.inner();
138-
osmesa::OsMesaContext::new(ctx, size)
134+
osmesa::OsMesaBuffer::new(ctx, size)
139135
.map(|surface| OsMesaBuffer {
140136
surface,
141137
})

glutin/src/platform_impl/unix/mod.rs

+2-19
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,12 @@ pub enum RawHandle {
3939
pub enum ContextType {
4040
X11,
4141
Wayland,
42-
OsMesa,
4342
}
4443

4544
#[derive(Debug)]
4645
pub enum Context {
4746
X11(x11::Context),
4847
Wayland(wayland::Context),
49-
OsMesa(osmesa::OsMesaContext),
5048
}
5149

5250
impl Context {
@@ -56,15 +54,6 @@ impl Context {
5654
) -> Result<(), CreationError> {
5755
if let Some(c) = *c {
5856
match ct {
59-
ContextType::OsMesa => match *c {
60-
Context::OsMesa(_) => Ok(()),
61-
_ => {
62-
let msg = "Cannot share an OSMesa context with a non-OSMesa context";
63-
return Err(CreationError::PlatformSpecific(
64-
msg.into(),
65-
));
66-
}
67-
},
6857
ContextType::X11 => match *c {
6958
Context::X11(_) => Ok(()),
7059
_ => {
@@ -159,7 +148,6 @@ impl Context {
159148
match *self {
160149
Context::X11(ref ctx) => ctx.make_current(),
161150
Context::Wayland(ref ctx) => ctx.make_current(),
162-
Context::OsMesa(ref ctx) => ctx.make_current(),
163151
}
164152
}
165153

@@ -168,7 +156,6 @@ impl Context {
168156
match *self {
169157
Context::X11(ref ctx) => ctx.make_not_current(),
170158
Context::Wayland(ref ctx) => ctx.make_not_current(),
171-
Context::OsMesa(ref ctx) => ctx.make_not_current(),
172159
}
173160
}
174161

@@ -177,7 +164,6 @@ impl Context {
177164
match *self {
178165
Context::X11(ref ctx) => ctx.is_current(),
179166
Context::Wayland(ref ctx) => ctx.is_current(),
180-
Context::OsMesa(ref ctx) => ctx.is_current(),
181167
}
182168
}
183169

@@ -186,7 +172,6 @@ impl Context {
186172
match *self {
187173
Context::X11(ref ctx) => ctx.get_api(),
188174
Context::Wayland(ref ctx) => ctx.get_api(),
189-
Context::OsMesa(ref ctx) => ctx.get_api(),
190175
}
191176
}
192177

@@ -198,7 +183,6 @@ impl Context {
198183
X11Context::Egl(ref ctx) => RawHandle::Egl(ctx.raw_handle()),
199184
},
200185
Context::Wayland(ref ctx) => RawHandle::Egl(ctx.raw_handle()),
201-
Context::OsMesa(ref ctx) => RawHandle::Egl(ctx.raw_handle()),
202186
}
203187
}
204188

@@ -212,10 +196,10 @@ impl Context {
212196
}
213197

214198
#[inline]
215-
pub fn resize(&self, width: u32, height: u32) {
199+
pub fn resize(&self, size: dpi::PhysicalSize) {
216200
match *self {
217201
Context::X11(_) => (),
218-
Context::Wayland(ref ctx) => ctx.resize(width, height),
202+
Context::Wayland(ref ctx) => ctx.resize(size),
219203
_ => unreachable!(),
220204
}
221205
}
@@ -225,7 +209,6 @@ impl Context {
225209
match *self {
226210
Context::X11(ref ctx) => ctx.get_proc_address(addr),
227211
Context::Wayland(ref ctx) => ctx.get_proc_address(addr),
228-
Context::OsMesa(ref ctx) => ctx.get_proc_address(addr),
229212
}
230213
}
231214

glutin/src/platform_impl/unix/wayland.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -189,10 +189,10 @@ impl Context {
189189
}
190190

191191
#[inline]
192-
pub fn resize(&self, width: u32, height: u32) {
192+
pub fn resize(&self, size: dpi::PhysicalSize) {
193193
match self {
194194
Context::Windowed(_, surface) => {
195-
surface.0.resize(width as i32, height as i32, 0, 0)
195+
surface.0.resize(size.width as i32, size.height as i32, 0, 0)
196196
}
197197
_ => unreachable!(),
198198
}

0 commit comments

Comments
 (0)