@@ -82,97 +82,42 @@ impl Context {
82
82
#[ inline]
83
83
pub fn new < T > (
84
84
el : & EventLoop < T > ,
85
- cb : ContextBuilderWrapper < & ' _ Context > ,
85
+ cb : ContextBuilderWrapper < & Context > ,
86
86
pbuffer_support : bool ,
87
87
window_surface_support : bool ,
88
88
surfaceless_support : bool ,
89
89
) -> Result < Self , CreationError > {
90
90
if el. is_wayland ( ) {
91
- unimplemented ! ( )
92
- /*Context::is_compatible(&gl_attr.sharing, ContextType::Wayland)?;
93
-
94
- let gl_attr = gl_attr.clone().map_sharing(|ctx| match *ctx {
91
+ Context :: is_compatible ( & cb. gl_attr . sharing , ContextType :: Wayland ) ?;
92
+ let cb = cb. clone ( ) . map_sharing ( |ctx| match * ctx {
95
93
Context :: Wayland ( ref ctx) => ctx,
96
94
_ => unreachable ! ( ) ,
97
95
} ) ;
98
- wayland::Context::new(wb, el, pf_reqs, &gl_attr, plat_attr)
99
- .map(|(win, context)| (win, Context::Wayland(context)))*/
96
+ wayland:: Context :: new (
97
+ el,
98
+ cb,
99
+ pbuffer_support,
100
+ window_surface_support,
101
+ surfaceless_support,
102
+ )
103
+ . map ( |context| Context :: Wayland ( context) )
100
104
} else {
101
105
Context :: is_compatible ( & cb. gl_attr . sharing , ContextType :: X11 ) ?;
102
106
let cb = cb. map_sharing ( |ctx| match * ctx {
103
107
Context :: X11 ( ref ctx) => ctx,
104
108
_ => unreachable ! ( ) ,
105
109
} ) ;
106
- x11:: Context :: new ( el, cb, pbuffer_support, window_surface_support, surfaceless_support)
107
- . map ( |context| Context :: X11 ( context) )
110
+ x11:: Context :: new (
111
+ el,
112
+ cb,
113
+ pbuffer_support,
114
+ window_surface_support,
115
+ surfaceless_support,
116
+ )
117
+ . map ( |context| Context :: X11 ( context) )
108
118
}
109
119
}
110
120
111
- // #[inline]
112
- // pub fn new_windowed<T>(
113
- // wb: WindowBuilder,
114
- // el: &EventLoop<T>,
115
- // pf_reqs: &PixelFormatRequirements,
116
- // gl_attr: &GlAttributes<&Context>,
117
- // plat_attr: &PlatformAttributes,
118
- // ) -> Result<(Window, Self), CreationError> {
119
- // if el.is_wayland() {
120
- // Context::is_compatible(&gl_attr.sharing, ContextType::Wayland)?;
121
- //
122
- // let gl_attr = gl_attr.clone().map_sharing(|ctx| match *ctx {
123
- // Context::Wayland(ref ctx) => ctx,
124
- // _ => unreachable!(),
125
- // });
126
- // wayland::Context::new(wb, el, pf_reqs, &gl_attr, plat_attr)
127
- // .map(|(win, context)| (win, Context::Wayland(context)))
128
- // } else {
129
- // Context::is_compatible(&gl_attr.sharing, ContextType::X11)?;
130
- // let gl_attr = gl_attr.clone().map_sharing(|ctx| match *ctx {
131
- // Context::X11(ref ctx) => ctx,
132
- // _ => unreachable!(),
133
- // });
134
- // x11::Context::new(wb, el, pf_reqs, &gl_attr, plat_attr)
135
- // .map(|(win, context)| (win, Context::X11(context)))
136
- // }
137
- // }
138
- //
139
- // #[inline]
140
- // pub fn new_headless<T>(
141
- // el: &EventLoop<T>,
142
- // pf_reqs: &PixelFormatRequirements,
143
- // gl_attr: &GlAttributes<&Context>,
144
- // plat_attr: &PlatformAttributes,
145
- // size: dpi::PhysicalSize,
146
- // ) -> Result<Self, CreationError> {
147
- // Self::new_headless_impl(el, pf_reqs, gl_attr, plat_attr, Some(size))
148
- // }
149
- //
150
- // pub fn new_headless_impl<T>(
151
- // el: &EventLoop<T>,
152
- // pf_reqs: &PixelFormatRequirements,
153
- // gl_attr: &GlAttributes<&Context>,
154
- // plat_attr: &PlatformAttributes,
155
- // size: Option<dpi::PhysicalSize>,
156
- // ) -> Result<Self, CreationError> {
157
- // if el.is_wayland() {
158
- // Context::is_compatible(&gl_attr.sharing, ContextType::Wayland)?;
159
- // let gl_attr = gl_attr.clone().map_sharing(|ctx| match *ctx {
160
- // Context::Wayland(ref ctx) => ctx,
161
- // _ => unreachable!(),
162
- // });
163
- // wayland::Context::new_headless(&el, pf_reqs, &gl_attr, plat_attr, size)
164
- // .map(|ctx| Context::Wayland(ctx))
165
- // } else {
166
- // Context::is_compatible(&gl_attr.sharing, ContextType::X11)?;
167
- // let gl_attr = gl_attr.clone().map_sharing(|ctx| match *ctx {
168
- // Context::X11(ref ctx) => ctx,
169
- // _ => unreachable!(),
170
- // });
171
- // x11::Context::new_headless(&el, pf_reqs, &gl_attr, plat_attr, size)
172
- // .map(|ctx| Context::X11(ctx))
173
- // }
174
- // }
175
-
176
121
#[ inline]
177
122
pub unsafe fn make_current ( & self ) -> Result < ( ) , ContextError > {
178
123
match * self {
@@ -225,15 +170,6 @@ impl Context {
225
170
}
226
171
}
227
172
228
- #[ inline]
229
- pub fn resize ( & self , size : dpi:: PhysicalSize ) {
230
- match * self {
231
- Context :: X11 ( _) => ( ) ,
232
- Context :: Wayland ( ref ctx) => ctx. resize ( size) ,
233
- _ => unreachable ! ( ) ,
234
- }
235
- }
236
-
237
173
#[ inline]
238
174
pub fn get_proc_address ( & self , addr : & str ) -> * const ( ) {
239
175
match * self {
@@ -250,15 +186,6 @@ impl Context {
250
186
_ => unreachable ! ( ) ,
251
187
}
252
188
}
253
-
254
- #[ inline]
255
- pub fn get_pixel_format ( & self ) -> PixelFormat {
256
- match * self {
257
- Context :: X11 ( ref ctx) => ctx. get_pixel_format ( ) ,
258
- Context :: Wayland ( ref ctx) => ctx. get_pixel_format ( ) ,
259
- _ => unreachable ! ( ) ,
260
- }
261
- }
262
189
}
263
190
264
191
#[ derive( Debug , Clone ) ]
@@ -284,6 +211,93 @@ pub struct PlatformAttributes {
284
211
/// GLX only: Whether the context will have transparency support.
285
212
pub glx_transparency : Option < bool > ,
286
213
287
- /// Ignored by surfaceless.
214
+ /// Ignored by surfaceless, which is always egl .
288
215
pub backing_api : BackingApi ,
289
216
}
217
+
218
+ #[ derive( Debug ) ]
219
+ pub enum WindowSurface {
220
+ X11 ( x11:: WindowSurface ) ,
221
+ Wayland ( wayland:: WindowSurface ) ,
222
+ }
223
+
224
+ impl WindowSurface {
225
+ #[ inline]
226
+ pub fn new < T > (
227
+ el : & EventLoop < T > ,
228
+ ctx : & Context ,
229
+ wb : WindowBuilder ,
230
+ ) -> Result < ( Self , Window ) , CreationError > {
231
+ match ctx {
232
+ Context :: X11 ( ref ctx) => x11:: WindowSurface :: new ( el, ctx, wb)
233
+ . map ( |ws| WindowSurface :: X11 ( ws) ) ,
234
+ Context :: Wayland ( ref ctx) => {
235
+ wayland:: WindowSurface :: new ( el, ctx, wb)
236
+ . map ( |ws| WindowSurface :: Wayland ( ws) )
237
+ }
238
+ }
239
+ }
240
+
241
+ #[ inline]
242
+ pub fn get_pixel_format ( & self ) -> PixelFormat {
243
+ match self {
244
+ WindowSurface :: X11 ( ws) => ws. get_pixel_format ( ) ,
245
+ WindowSurface :: Wayland ( ws) => ws. get_pixel_format ( ) ,
246
+ }
247
+ }
248
+
249
+ #[ inline]
250
+ pub fn is_current ( & self ) -> bool {
251
+ match self {
252
+ WindowSurface :: X11 ( ws) => ws. is_current ( ) ,
253
+ WindowSurface :: Wayland ( ws) => ws. is_current ( ) ,
254
+ }
255
+ }
256
+
257
+ #[ inline]
258
+ pub fn update_after_resize ( & self , size : dpi:: PhysicalSize ) {
259
+ match self {
260
+ Context :: Wayland ( ref ctx) => ctx. update_after_resize ( size) ,
261
+ _ => ( ) ,
262
+ }
263
+ }
264
+ }
265
+
266
+ #[ derive( Debug ) ]
267
+ pub enum PBuffer {
268
+ X11 ( x11:: PBuffer ) ,
269
+ Wayland ( wayland:: PBuffer ) ,
270
+ }
271
+
272
+ impl PBuffer {
273
+ #[ inline]
274
+ pub fn new < T > (
275
+ el : & EventLoop < T > ,
276
+ ctx : & Context ,
277
+ size : dpi:: PhysicalSize ,
278
+ ) -> Result < Self , CreationError > {
279
+ match ctx {
280
+ Context :: X11 ( ref ctx) => {
281
+ x11:: PBuffer :: new ( el, ctx, size) . map ( |pb| PBuffer :: X11 ( pb) )
282
+ }
283
+ Context :: Wayland ( ref ctx) => wayland:: PBuffer :: new ( el, ctx, size)
284
+ . map ( |pb| PBuffer :: Wayland ( pb) ) ,
285
+ }
286
+ }
287
+
288
+ #[ inline]
289
+ pub fn get_pixel_format ( & self ) -> PixelFormat {
290
+ match self {
291
+ PBuffer :: X11 ( pb) => pb. get_pixel_format ( ) ,
292
+ PBuffer :: Wayland ( pb) => pb. get_pixel_format ( ) ,
293
+ }
294
+ }
295
+
296
+ #[ inline]
297
+ pub fn is_current ( & self ) -> bool {
298
+ match self {
299
+ PBuffer :: X11 ( pb) => pb. is_current ( ) ,
300
+ PBuffer :: Wayland ( pb) => pb. is_current ( ) ,
301
+ }
302
+ }
303
+ }
0 commit comments