X-Git-Url: https://git.nihav.org/?a=blobdiff_plain;ds=inline;f=nihed-cros-libva%2Fsrc%2Fdisplay.rs;fp=nihed-cros-libva%2Fsrc%2Fdisplay.rs;h=f5a5b66200318985f3fc5b096acf6bfa2b609318;hb=69e6ce021284f1ebaf148b38b236068d08249e0f;hp=462bc3e8db1dcb154b14bf8026fa06ea579f4842;hpb=51b33b65943d47a3826be9763728815ba2b9e7d5;p=nihav-player.git diff --git a/nihed-cros-libva/src/display.rs b/nihed-cros-libva/src/display.rs index 462bc3e..f5a5b66 100644 --- a/nihed-cros-libva/src/display.rs +++ b/nihed-cros-libva/src/display.rs @@ -9,14 +9,10 @@ use std::path::Path; use std::path::PathBuf; use std::rc::Rc; -use anyhow::anyhow; -use anyhow::Context as AnyhowContext; -use anyhow::Result; - use crate::bindings; use crate::config::Config; use crate::context::Context; -use crate::status::Status; +use crate::status::*; use crate::surface::Surface; use crate::UsageHint; @@ -80,29 +76,26 @@ impl Display { /// Opens and initializes a specific DRM `Display`. /// /// `path` is the path to a DRM device that supports VAAPI, e.g. `/dev/dri/renderD128`. - pub fn open_drm_display>(path: P) -> Result> { + pub fn open_drm_display>(path: P) -> VAResult> { let file = std::fs::File::options() .read(true) .write(true) .open(path.as_ref()) - .context(format!("failed to open {}", path.as_ref().display()))?; + .map_err(|_| VAError::InvalidValue)?; // Safe because fd represents a valid file descriptor and the pointer is checked for // NULL afterwards. let display = unsafe { bindings::vaGetDisplayDRM(file.as_raw_fd()) }; if display.is_null() { // The File will close the DRM fd on drop. - return Err(anyhow!( - "failed to obtain VA display from DRM device {}", - path.as_ref().display() - )); + return Err(VAError::InvalidDisplay); } let mut major = 0i32; let mut minor = 0i32; // Safe because we ensure that the display is valid (i.e not NULL) before calling // vaInitialize. The File will close the DRM fd on drop. - Status(unsafe { bindings::vaInitialize(display, &mut major, &mut minor) }).check()?; + (unsafe { bindings::vaInitialize(display, &mut major, &mut minor) }).check()?; Ok(Rc::new(Self { handle: display, @@ -133,14 +126,14 @@ impl Display { } /// Queries supported profiles by this display. - pub fn query_config_profiles(&self) -> Result> { + pub fn query_config_profiles(&self) -> VAResult> { // Safe because `self` represents a valid VADisplay. let mut max_num_profiles = unsafe { bindings::vaMaxNumProfiles(self.handle) }; let mut profiles = Vec::with_capacity(max_num_profiles as usize); // Safe because `self` represents a valid `VADisplay` and the vector has `max_num_profiles` // as capacity. - Status(unsafe { + (unsafe { bindings::vaQueryConfigProfiles( self.handle, profiles.as_mut_ptr(), @@ -182,14 +175,14 @@ impl Display { pub fn query_config_entrypoints( &self, profile: bindings::VAProfile::Type, - ) -> Result> { + ) -> VAResult> { // Safe because `self` represents a valid VADisplay. let mut max_num_entrypoints = unsafe { bindings::vaMaxNumEntrypoints(self.handle) }; let mut entrypoints = Vec::with_capacity(max_num_entrypoints as usize); // Safe because `self` represents a valid VADisplay and the vector has `max_num_entrypoints` // as capacity. - Status(unsafe { + (unsafe { bindings::vaQueryConfigEntrypoints( self.handle, profile, @@ -218,10 +211,10 @@ impl Display { profile: bindings::VAProfile::Type, entrypoint: bindings::VAEntrypoint::Type, attributes: &mut [bindings::VAConfigAttrib], - ) -> Result<()> { + ) -> VAResult<()> { // Safe because `self` represents a valid VADisplay. The slice length is passed to the C // function, so it is impossible to write past the end of the slice's storage by mistake. - Status(unsafe { + (unsafe { bindings::vaGetConfigAttributes( self.handle, profile, @@ -251,7 +244,7 @@ impl Display { height: u32, usage_hint: Option, num_surfaces: u32, - ) -> Result> { + ) -> VAResult> { Surface::new( Rc::clone(self), rt_format, @@ -279,7 +272,7 @@ impl Display { coded_height: i32, surfaces: Option<&Vec>, progressive: bool, - ) -> Result> { + ) -> VAResult> { Context::new( Rc::clone(self), config, @@ -301,12 +294,12 @@ impl Display { attrs: Vec, profile: bindings::VAProfile::Type, entrypoint: bindings::VAEntrypoint::Type, - ) -> Result { + ) -> VAResult { Config::new(Rc::clone(self), attrs, profile, entrypoint) } /// Returns available image formats for this display by wrapping around `vaQueryImageFormats`. - pub fn query_image_formats(&self) -> Result> { + pub fn query_image_formats(&self) -> VAResult> { // Safe because `self` represents a valid VADisplay. let mut num_image_formats = unsafe { bindings::vaMaxNumImageFormats(self.handle) }; let mut image_formats = Vec::with_capacity(num_image_formats as usize); @@ -314,7 +307,7 @@ impl Display { // Safe because `self` represents a valid VADisplay. The `image_formats` vector is properly // initialized and a valid size is passed to the C function, so it is impossible to write // past the end of their storage by mistake. - Status(unsafe { + (unsafe { bindings::vaQueryImageFormats( self.handle, image_formats.as_mut_ptr(),