x11: add option to make extensions optional

This commit is contained in:
i509VCB 2021-11-04 00:37:12 -05:00 committed by Victor Berger
parent 0d2c3acdc7
commit d00197052c
2 changed files with 37 additions and 25 deletions

View File

@ -129,7 +129,7 @@ where
} }
// We need dri3 >= 1.2 in order to use the enhanced dri3_pixmap_from_buffers function. // We need dri3 >= 1.2 in order to use the enhanced dri3_pixmap_from_buffers function.
let xid = if window_inner.extensions.dri3 >= (1, 2) { let xid = if window_inner.extensions.dri3 >= Some((1, 2)) {
if dmabuf.num_planes() > 4 { if dmabuf.num_planes() > 4 {
return Err(CreatePixmapError::TooManyPlanes); return Err(CreatePixmapError::TooManyPlanes);
} }

View File

@ -25,6 +25,7 @@ macro_rules! extensions {
$( $(
$extension:ident { // Extension name for path lookup $extension:ident { // Extension name for path lookup
$extension_fn:ident, // Function used to look up the version of the extension $extension_fn:ident, // Function used to look up the version of the extension
required: $required:expr,
minimum: ($min_major:expr, $min_minor:expr), minimum: ($min_major:expr, $min_minor:expr),
request: ($req_major:expr, $req_minor:expr), request: ($req_major:expr, $req_minor:expr),
}, },
@ -34,7 +35,7 @@ macro_rules! extensions {
pub struct Extensions { pub struct Extensions {
$( $(
#[doc = concat!(" The version of the `", stringify!($extension), "` extension.")] #[doc = concat!(" The version of the `", stringify!($extension), "` extension.")]
pub $extension: (u32, u32), pub $extension: Option<(u32, u32)>,
)* )*
} }
@ -59,35 +60,43 @@ macro_rules! extensions {
version.minor_version, version.minor_version,
); );
(version.major_version, version.minor_version) Some((version.major_version, version.minor_version))
} else { } else {
slog::error!( if $required {
logger, slog::error!(
"{} extension version is too low (have {}.{}, expected {}.{})", logger,
X11_EXTENSION_NAME, "required extension {} version is too low (have {}.{}, expected {}.{})",
version.major_version, X11_EXTENSION_NAME,
version.minor_version, version.major_version,
$req_major, version.minor_version,
$req_minor, $req_major,
); $req_minor,
);
return Err(MissingExtensionError::WrongVersion { return Err(MissingExtensionError::WrongVersion {
name: X11_EXTENSION_NAME, name: X11_EXTENSION_NAME,
required_major: $req_major, required_major: $req_major,
required_minor: $req_minor, required_minor: $req_minor,
available_major: version.major_version, available_major: version.major_version,
available_minor: version.minor_version, available_minor: version.minor_version,
}.into()); }.into());
} else {
None
}
} }
} else { } else {
slog::error!(logger, "{} extension not found", X11_EXTENSION_NAME); if $required {
slog::error!(logger, "required extension {} not found", X11_EXTENSION_NAME);
return Err(MissingExtensionError::NotFound { return Err(MissingExtensionError::NotFound {
name: X11_EXTENSION_NAME, name: X11_EXTENSION_NAME,
major: $min_major, major: $min_major,
minor: $min_minor, minor: $min_minor,
}
.into());
} else {
None
} }
.into());
} }
}; };
)* )*
@ -105,18 +114,21 @@ macro_rules! extensions {
extensions! { extensions! {
present { present {
present_query_version, present_query_version,
required: true,
minimum: (1, 0), minimum: (1, 0),
request: (1, 0), request: (1, 0),
}, },
xfixes { xfixes {
xfixes_query_version, xfixes_query_version,
required: true,
minimum: (4, 0), minimum: (4, 0),
request: (4, 0), request: (4, 0),
}, },
dri3 { dri3 {
dri3_query_version, dri3_query_version,
required: true,
minimum: (1, 0), minimum: (1, 0),
request: (1, 2), request: (1, 2),
}, },