Shorten surface type matching

This commit is contained in:
Drakulix 2017-06-20 10:50:20 +02:00
parent f70cc6bf55
commit b131f8168e
1 changed files with 6 additions and 18 deletions

View File

@ -67,7 +67,7 @@ pub enum NativeSurface {
Gbm(ffi::NativeWindowType), Gbm(ffi::NativeWindowType),
} }
#[derive(PartialEq)] #[derive(Clone, Copy, PartialEq)]
enum NativeType { enum NativeType {
X11, X11,
Wayland, Wayland,
@ -568,30 +568,18 @@ impl EGLContext {
-> Result<EGLSurface<'a>, CreationError> { -> Result<EGLSurface<'a>, CreationError> {
trace!(self.logger, "Creating EGL window surface..."); trace!(self.logger, "Creating EGL window surface...");
match native {
NativeSurface::X11(_) if self.backend_type != NativeType::X11 => {
return Err(CreationError::NonMatchingSurfaceType)
}
NativeSurface::Wayland(_) if self.backend_type != NativeType::Wayland => {
return Err(CreationError::NonMatchingSurfaceType)
}
NativeSurface::Gbm(_) if self.backend_type != NativeType::Gbm => {
return Err(CreationError::NonMatchingSurfaceType)
}
_ => {}
};
let surface = { let surface = {
let surface = match native { let surface = match (native, self.backend_type) {
NativeSurface::X11(window) | (NativeSurface::X11(window), NativeType::X11) |
NativeSurface::Wayland(window) | (NativeSurface::Wayland(window), NativeType::Wayland) |
NativeSurface::Gbm(window) => { (NativeSurface::Gbm(window), NativeType::Gbm) => {
self.egl self.egl
.CreateWindowSurface(self.display, .CreateWindowSurface(self.display,
self.config_id, self.config_id,
window, window,
self.surface_attributes.as_ptr()) self.surface_attributes.as_ptr())
} }
_ => return Err(CreationError::NonMatchingSurfaceType),
}; };
if surface.is_null() { if surface.is_null() {