Skip to content

Commit 7471d39

Browse files
committed
Wayland finally builds, but still needs some changes to be correct.
Signed-off-by: Hal Gentz <zegentzy@protonmail.com>
1 parent 623effb commit 7471d39

File tree

13 files changed

+521
-266
lines changed

13 files changed

+521
-266
lines changed

glutin/src/api/egl/mod.rs

+100-38
Original file line numberDiff line numberDiff line change
@@ -555,58 +555,61 @@ impl Context {
555555
})
556556
}
557557

558-
unsafe fn check_make_current(
558+
unsafe fn make_current(
559559
&self,
560-
ret: Option<u32>,
560+
surface: ffi::egl::types::EGLSurface,
561561
) -> Result<(), ContextError> {
562562
let egl = EGL.as_ref().unwrap();
563-
if ret == Some(0) {
564-
match egl.GetError() as u32 {
565-
ffi::egl::CONTEXT_LOST => Err(ContextError::ContextLost),
566-
err => panic!(
567-
"make_current: eglMakeCurrent failed (eglGetError returned 0x{:x})",
568-
err
569-
),
570-
}
571-
} else {
572-
Ok(())
573-
}
563+
let ret =
564+
egl.MakeCurrent(**self.display, surface, surface, self.context);
565+
566+
check_make_current(Some(ret))
574567
}
575568

576-
pub unsafe fn make_current(&self) -> Result<(), ContextError> {
569+
#[inline]
570+
pub unsafe fn make_current_surfaceless(&self) -> Result<(), ContextError> {
577571
let egl = EGL.as_ref().unwrap();
578-
let surface = if self.surface.is_null() {
579-
ffi::egl::NO_SURFACE
580-
} else {
581-
self.surface
582-
};
583-
let ret =
584-
egl.MakeCurrent(**self.display, surface, surface, self.context);
572+
let ret = egl.MakeCurrent(
573+
**self.display,
574+
ffi::egl::NO_SURFACE,
575+
ffi::egl::NO_SURFACE,
576+
self.context,
577+
);
578+
579+
check_make_current(Some(ret))
580+
}
585581

586-
self.check_make_current(Some(ret))
582+
#[inline]
583+
pub unsafe fn make_current_window(
584+
&self,
585+
surface: &WindowSurface,
586+
) -> Result<(), ContextError> {
587+
self.make_current(surface.surface)
587588
}
588589

590+
#[inline]
591+
pub unsafe fn make_current_pbuffer(
592+
&self,
593+
pbuffer: &PBuffer,
594+
) -> Result<(), ContextError> {
595+
self.make_current(pbuffer.surface)
596+
}
597+
598+
#[inline]
589599
pub unsafe fn make_not_current(&self) -> Result<(), ContextError> {
590600
let egl = EGL.as_ref().unwrap();
591601

592-
let surface_eq = if let Some(surface) = self.surface {
593-
egl.GetCurrentSurface(ffi::egl::DRAW as i32) == surface
594-
|| egl.GetCurrentSurface(ffi::egl::READ as i32) == surface
595-
} else {
596-
false
597-
};
598-
599-
if surface_eq || egl.GetCurrentContext() == self.context {
602+
if egl.GetCurrentContext() == self.context {
600603
let ret = egl.MakeCurrent(
601604
**self.display,
602605
ffi::egl::NO_SURFACE,
603606
ffi::egl::NO_SURFACE,
604607
ffi::egl::NO_CONTEXT,
605608
);
606609

607-
self.check_make_current(Some(ret))
610+
check_make_current(Some(ret))
608611
} else {
609-
self.check_make_current(None)
612+
check_make_current(None)
610613
}
611614
}
612615

@@ -709,6 +712,23 @@ impl Context {
709712
}
710713
}
711714

715+
unsafe fn check_make_current(
716+
ret: Option<u32>,
717+
) -> Result<(), ContextError> {
718+
let egl = EGL.as_ref().unwrap();
719+
if ret == Some(0) {
720+
match egl.GetError() as u32 {
721+
ffi::egl::CONTEXT_LOST => Err(ContextError::ContextLost),
722+
err => panic!(
723+
"make_current: eglMakeCurrent failed (eglGetError returned 0x{:x})",
724+
err
725+
),
726+
}
727+
} else {
728+
Ok(())
729+
}
730+
}
731+
712732
unsafe impl Send for Context {}
713733
unsafe impl Sync for Context {}
714734

@@ -857,12 +877,12 @@ pub fn get_native_visual_id(
857877
// ))]
858878
// }
859879

860-
trait SurfaceTypeTrait {}
880+
pub trait SurfaceTypeTrait {}
861881

862882
#[derive(Debug)]
863-
enum WindowSurfaceType {}
883+
pub enum WindowSurfaceType {}
864884
#[derive(Debug)]
865-
enum PBufferSurfaceType {}
885+
pub enum PBufferSurfaceType {}
866886

867887
impl SurfaceTypeTrait for WindowSurfaceType {}
868888
impl SurfaceTypeTrait for PBufferSurfaceType {}
@@ -933,6 +953,27 @@ impl WindowSurface {
933953
Ok(())
934954
}
935955
}
956+
957+
#[inline]
958+
pub unsafe fn make_not_current(&self) -> Result<(), ContextError> {
959+
let egl = EGL.as_ref().unwrap();
960+
961+
if
962+
egl.GetCurrentSurface(ffi::egl::DRAW as i32) == self.surface
963+
|| egl.GetCurrentSurface(ffi::egl::READ as i32) == self.surface {
964+
let ret = egl.MakeCurrent(
965+
**self.display,
966+
ffi::egl::NO_SURFACE,
967+
ffi::egl::NO_SURFACE,
968+
ffi::egl::NO_CONTEXT,
969+
);
970+
971+
check_make_current(Some(ret))
972+
} else {
973+
check_make_current(None)
974+
}
975+
}
976+
936977
}
937978

938979
impl PBuffer {
@@ -961,17 +1002,17 @@ impl PBuffer {
9611002
];
9621003

9631004
let surface = unsafe {
964-
let surface = egl.CreatePbufferSurface(
1005+
let pbuffer = egl.CreatePbufferSurface(
9651006
**ctx.display,
9661007
ctx.config_id,
9671008
attrs.as_ptr(),
9681009
);
969-
if surface.is_null() || surface == ffi::egl::NO_SURFACE {
1010+
if pbuffer.is_null() || pbuffer == ffi::egl::NO_SURFACE {
9701011
return Err(CreationError::OsError(
9711012
"eglCreatePbufferSurface failed".to_string(),
9721013
));
9731014
}
974-
surface
1015+
pbuffer
9751016
};
9761017

9771018
Ok(PBuffer {
@@ -981,6 +1022,27 @@ impl PBuffer {
9811022
phantom: PhantomData,
9821023
})
9831024
}
1025+
1026+
#[inline]
1027+
pub unsafe fn make_not_current(&self) -> Result<(), ContextError> {
1028+
let egl = EGL.as_ref().unwrap();
1029+
1030+
if
1031+
egl.GetCurrentSurface(ffi::egl::DRAW as i32) == self.surface
1032+
|| egl.GetCurrentSurface(ffi::egl::READ as i32) == self.surface {
1033+
let ret = egl.MakeCurrent(
1034+
**self.display,
1035+
ffi::egl::NO_SURFACE,
1036+
ffi::egl::NO_SURFACE,
1037+
ffi::egl::NO_CONTEXT,
1038+
);
1039+
1040+
check_make_current(Some(ret))
1041+
} else {
1042+
check_make_current(None)
1043+
}
1044+
}
1045+
9841046
}
9851047

9861048
impl<T: SurfaceTypeTrait> EGLSurface<T> {

0 commit comments

Comments
 (0)