chore: refresco desde el monorepo (pin tawasuyu.git v0.2.0)
1use super::*;
2use crate::backend::SwapBuffersError;
3
4#[cfg(feature = "wayland_frontend")]
5use wayland_server::protocol::wl_shm;
6
7/// Error returned during rendering using GL ES
8#[derive(thiserror::Error, Debug)]
9pub enum GlesError {
10 /// A shader could not be compiled
11 #[error("Failed to compile Shader")]
12 ShaderCompileError,
13 /// A program could not be linked
14 #[error("Failed to link Program")]
15 ProgramLinkError,
16 /// A framebuffer could not be bound
17 #[error("Failed to bind Framebuffer")]
18 FramebufferBindingError,
19 /// Required GL functions could not be loaded
20 #[error("Failed to load GL functions from EGL")]
21 GLFunctionLoaderError,
22 /// Required GL extension are not supported by the underlying implementation
23 #[error("None of the following GL extensions is supported by the underlying GL implementation, at least one is required: {0:?}")]
24 GLExtensionNotSupported(&'static [&'static str]),
25 /// Required EGL extension are not supported by the underlying implementation
26 #[error("None of the following EGL extensions is supported by the underlying implementation, at least one is required: {0:?}")]
27 EGLExtensionNotSupported(&'static [&'static str]),
28 /// Required GL version is not available by the underlying implementation
29 #[error(
30 "The OpenGL ES version of the underlying GL implementation is too low, at least required: {0:?}"
31 )]
32 GLVersionNotSupported(version::GlVersion),
33 /// The underlying egl context could not be activated
34 #[error("Failed to active egl context")]
35 ContextActivationError(#[from] crate::backend::egl::MakeCurrentError),
36 ///The given dmabuf could not be converted to an EGLImage for framebuffer use
37 #[error("Failed to convert between dmabuf and EGLImage")]
38 BindBufferEGLError(#[source] crate::backend::egl::Error),
39 /// The given buffer has an unknown pixel format
40 #[error("Unknown pixel format")]
41 UnknownPixelFormat,
42 /// The given buffer has an unsupported pixel format
43 #[error("Unsupported pixel format: {0:?}")]
44 UnsupportedPixelFormat(Fourcc),
45 /// The given buffer has an unknown pixel layout
46 #[error("Unsupported pixel layout")]
47 UnsupportedPixelLayout,
48 /// The given wl buffer has an unsupported pixel format
49 #[error("Unsupported wl_shm format: {0:?}")]
50 #[cfg(feature = "wayland_frontend")]
51 UnsupportedWlPixelFormat(wl_shm::Format),
52 /// The given buffer was not accessible
53 #[error("Error accessing the buffer ({0:?})")]
54 #[cfg(feature = "wayland_frontend")]
55 BufferAccessError(crate::wayland::shm::BufferAccessError),
56 /// The given egl buffer was not accessible
57 #[error("Error accessing the buffer ({0:?})")]
58 #[cfg(feature = "wayland_frontend")]
59 EGLBufferAccessError(crate::backend::egl::BufferAccessError),
60 /// There was an error mapping the buffer
61 #[error("Error mapping the buffer")]
62 MappingError,
63 /// The provided buffer's size did not match the requested one.
64 #[error("Error reading buffer, size is too small for the given dimensions")]
65 UnexpectedSize,
66 /// Unable to determine the size of the framebuffer
67 #[error("Error determining the size of the provided framebuffer")]
68 UnknownSize,
69 /// The blitting operation was unsuccessful
70 #[error("Error blitting between framebuffers")]
71 BlitError,
72 /// An error occured while creating the shader object.
73 #[error("An error occured while creating the shader object.")]
74 CreateShaderObject,
75 /// Uniform was not declared when compiling shader
76 #[error("Uniform {0:?} was not declared when compiling the provided shader")]
77 UnknownUniform(String),
78 /// The provided uniform has a different type then was provided when compiling the shader
79 #[error("Uniform with different type (got {provided:?}, expected: {declared:?})")]
80 UniformTypeMismatch {
81 /// Uniform type that was provided during the call
82 provided: UniformType,
83 /// Uniform type that was declared when compiling
84 declared: UniformType,
85 },
86 /// Blocking for a synchronization primitive failed
87 #[error("Blocking for a synchronization primitive got interrupted")]
88 SyncInterrupted,
89}
90
91impl From<GlesError> for SwapBuffersError {
92 #[cfg(feature = "wayland_frontend")]
93 #[inline]
94 fn from(err: GlesError) -> SwapBuffersError {
95 match err {
96 x @ GlesError::ShaderCompileError
97 | x @ GlesError::ProgramLinkError
98 | x @ GlesError::GLFunctionLoaderError
99 | x @ GlesError::GLExtensionNotSupported(_)
100 | x @ GlesError::EGLExtensionNotSupported(_)
101 | x @ GlesError::GLVersionNotSupported(_) => SwapBuffersError::ContextLost(Box::new(x)),
102 GlesError::ContextActivationError(err) => err.into(),
103 x @ GlesError::FramebufferBindingError
104 | x @ GlesError::BindBufferEGLError(_)
105 | x @ GlesError::UnknownPixelFormat
106 | x @ GlesError::UnsupportedPixelFormat(_)
107 | x @ GlesError::UnsupportedWlPixelFormat(_)
108 | x @ GlesError::UnsupportedPixelLayout
109 | x @ GlesError::BufferAccessError(_)
110 | x @ GlesError::MappingError
111 | x @ GlesError::UnexpectedSize
112 | x @ GlesError::UnknownSize
113 | x @ GlesError::BlitError
114 | x @ GlesError::CreateShaderObject
115 | x @ GlesError::UniformTypeMismatch { .. }
116 | x @ GlesError::UnknownUniform(_)
117 | x @ GlesError::EGLBufferAccessError(_)
118 | x @ GlesError::SyncInterrupted => SwapBuffersError::TemporaryFailure(Box::new(x)),
119 }
120 }
121 #[cfg(not(feature = "wayland_frontend"))]
122 #[inline]
123 fn from(err: GlesError) -> SwapBuffersError {
124 match err {
125 x @ GlesError::ShaderCompileError
126 | x @ GlesError::ProgramLinkError
127 | x @ GlesError::GLFunctionLoaderError
128 | x @ GlesError::GLExtensionNotSupported(_)
129 | x @ GlesError::EGLExtensionNotSupported(_)
130 | x @ GlesError::GLVersionNotSupported(_) => SwapBuffersError::ContextLost(Box::new(x)),
131 GlesError::ContextActivationError(err) => err.into(),
132 x @ GlesError::FramebufferBindingError
133 | x @ GlesError::MappingError
134 | x @ GlesError::UnknownPixelFormat
135 | x @ GlesError::UnsupportedPixelFormat(_)
136 | x @ GlesError::UnsupportedPixelLayout
137 | x @ GlesError::UnexpectedSize
138 | x @ GlesError::UnknownSize
139 | x @ GlesError::BlitError
140 | x @ GlesError::CreateShaderObject
141 | x @ GlesError::UniformTypeMismatch { .. }
142 | x @ GlesError::UnknownUniform(_)
143 | x @ GlesError::BindBufferEGLError(_)
144 | x @ GlesError::SyncInterrupted => SwapBuffersError::TemporaryFailure(Box::new(x)),
145 }
146 }
147}