@@ -7,6 +7,7 @@ pub struct MakeCurrentGuard {
7
7
display : ffi:: egl:: types:: EGLDisplay ,
8
8
old_display : ffi:: egl:: types:: EGLDisplay ,
9
9
possibly_invalid : Option < MakeCurrentGuardInner > ,
10
+ keep : bool ,
10
11
}
11
12
12
13
#[ derive( Debug , PartialEq ) ]
@@ -36,6 +37,7 @@ impl MakeCurrentGuard {
36
37
. GetCurrentSurface ( ffi:: egl:: READ as i32 ) ,
37
38
old_context : egl. GetCurrentContext ( ) ,
38
39
} ) ,
40
+ keep : false ,
39
41
} ;
40
42
41
43
if ret. old_display == ffi:: egl:: NO_DISPLAY {
@@ -54,6 +56,31 @@ impl MakeCurrentGuard {
54
56
}
55
57
}
56
58
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
+
57
84
pub fn if_any_same_then_invalidate (
58
85
& mut self ,
59
86
draw_surface : ffi:: egl:: types:: EGLSurface ,
@@ -67,6 +94,7 @@ impl MakeCurrentGuard {
67
94
|| pi. old_read_surface == read_surface
68
95
&& read_surface != ffi:: egl:: NO_SURFACE
69
96
|| pi. old_context == context
97
+ && pi. old_context != ffi:: egl:: NO_CONTEXT
70
98
{
71
99
self . invalidate ( ) ;
72
100
}
@@ -83,11 +111,17 @@ impl Drop for MakeCurrentGuard {
83
111
let egl = super :: EGL . as_ref ( ) . unwrap ( ) ;
84
112
let ( draw_surface, read_surface, context) =
85
113
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
+ }
91
125
None => (
92
126
ffi:: egl:: NO_SURFACE ,
93
127
ffi:: egl:: NO_SURFACE ,
0 commit comments