Skip to content

Commit 623effb

Browse files
committed
Refactoring as of 2019-06-27.
Signed-off-by: Hal Gentz <zegentzy@protonmail.com>
1 parent 9cae0d3 commit 623effb

File tree

7 files changed

+319
-261
lines changed

7 files changed

+319
-261
lines changed

glutin/src/api/egl/make_current_guard.rs

+39-5
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ pub struct MakeCurrentGuard {
77
display: ffi::egl::types::EGLDisplay,
88
old_display: ffi::egl::types::EGLDisplay,
99
possibly_invalid: Option<MakeCurrentGuardInner>,
10+
keep: bool,
1011
}
1112

1213
#[derive(Debug, PartialEq)]
@@ -36,6 +37,7 @@ impl MakeCurrentGuard {
3637
.GetCurrentSurface(ffi::egl::READ as i32),
3738
old_context: egl.GetCurrentContext(),
3839
}),
40+
keep: false,
3941
};
4042

4143
if ret.old_display == ffi::egl::NO_DISPLAY {
@@ -54,6 +56,31 @@ impl MakeCurrentGuard {
5456
}
5557
}
5658

59+
pub fn new_keep(display: ffi::egl::types::EGLDisplay) -> Self {
60+
unsafe {
61+
let egl = super::EGL.as_ref().unwrap();
62+
63+
let mut ret = MakeCurrentGuard {
64+
display,
65+
old_display: egl.GetCurrentDisplay(),
66+
possibly_invalid: Some(MakeCurrentGuardInner {
67+
old_draw_surface: egl
68+
.GetCurrentSurface(ffi::egl::DRAW as i32),
69+
old_read_surface: egl
70+
.GetCurrentSurface(ffi::egl::READ as i32),
71+
old_context: egl.GetCurrentContext(),
72+
}),
73+
keep: true,
74+
};
75+
76+
if ret.old_display == ffi::egl::NO_DISPLAY {
77+
ret.invalidate();
78+
}
79+
80+
ret
81+
}
82+
}
83+
5784
pub fn if_any_same_then_invalidate(
5885
&mut self,
5986
draw_surface: ffi::egl::types::EGLSurface,
@@ -67,6 +94,7 @@ impl MakeCurrentGuard {
6794
|| pi.old_read_surface == read_surface
6895
&& read_surface != ffi::egl::NO_SURFACE
6996
|| pi.old_context == context
97+
&& pi.old_context != ffi::egl::NO_CONTEXT
7098
{
7199
self.invalidate();
72100
}
@@ -83,11 +111,17 @@ impl Drop for MakeCurrentGuard {
83111
let egl = super::EGL.as_ref().unwrap();
84112
let (draw_surface, read_surface, context) =
85113
match self.possibly_invalid.take() {
86-
Some(inner) => (
87-
inner.old_draw_surface,
88-
inner.old_read_surface,
89-
inner.old_context,
90-
),
114+
Some(inner) => {
115+
if self.keep {
116+
return;
117+
} else {
118+
(
119+
inner.old_draw_surface,
120+
inner.old_read_surface,
121+
inner.old_context,
122+
)
123+
}
124+
}
91125
None => (
92126
ffi::egl::NO_SURFACE,
93127
ffi::egl::NO_SURFACE,

0 commit comments

Comments
 (0)