wayland.shm: review docs

This commit is contained in:
Victor Berger 2021-07-01 22:16:47 +02:00 committed by Victor Berger
parent 7b3585ad36
commit 4214cb9fc5
2 changed files with 11 additions and 12 deletions

View File

@ -5,7 +5,7 @@
//! //!
//! Most utilities provided in this module work in the same way: //! Most utilities provided in this module work in the same way:
//! //!
//! - An `init` function or method will take the event loop as argument and //! - An `init` function or method will take the wayland display as argument and
//! insert one or more globals into it. //! insert one or more globals into it.
//! - If you want to remove a previously inserted global, just call the //! - If you want to remove a previously inserted global, just call the
//! `destroy()` method on the associated `Global`. If you don't plan to //! `destroy()` method on the associated `Global`. If you don't plan to

View File

@ -13,7 +13,7 @@
//! //!
//! To use it, first add a `ShmGlobal` to your display, specifying the formats //! To use it, first add a `ShmGlobal` to your display, specifying the formats
//! you want to support (ARGB8888 and XRGB8888 are always considered as supported, //! you want to support (ARGB8888 and XRGB8888 are always considered as supported,
//! as specified by the wayland protocol) and obtain its `ShmToken`. //! as specified by the wayland protocol).
//! //!
//! ``` //! ```
//! extern crate wayland_server; //! extern crate wayland_server;
@ -26,7 +26,7 @@
//! // Insert the ShmGlobal into your event loop //! // Insert the ShmGlobal into your event loop
//! // Here, we specify that Yuyv and C8 format are supported //! // Here, we specify that Yuyv and C8 format are supported
//! // additionally to the standard Argb8888 and Xrgb8888. //! // additionally to the standard Argb8888 and Xrgb8888.
//! let shm_global = init_shm_global( //! init_shm_global(
//! &mut display, //! &mut display,
//! vec![Format::Yuyv, Format::C8], //! vec![Format::Yuyv, Format::C8],
//! None // we don't provide a logger here //! None // we don't provide a logger here
@ -52,7 +52,7 @@
//! //!
//! match content { //! match content {
//! Ok(something) => { //! Ok(something) => {
//! /* `something` is the content you returned from the closure */ //! /* `something` is the value you returned from the closure */
//! }, //! },
//! Err(BufferAccessError::NotManaged) => { //! Err(BufferAccessError::NotManaged) => {
//! /* This buffer is not managed by the SHM global, but by something else */ //! /* This buffer is not managed by the SHM global, but by something else */
@ -83,11 +83,7 @@ use wayland_server::{
mod pool; mod pool;
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
/// Internal data storage of `ShmGlobal` struct ShmGlobalData {
///
/// This type is only visible as type parameter of
/// the `Global` handle you are provided.
pub struct ShmGlobalData {
formats: Rc<[wl_shm::Format]>, formats: Rc<[wl_shm::Format]>,
log: ::slog::Logger, log: ::slog::Logger,
} }
@ -136,9 +132,10 @@ where
} }
/// Error that can occur when accessing an SHM buffer /// Error that can occur when accessing an SHM buffer
#[derive(Debug)] #[derive(Debug, thiserror::Error)]
pub enum BufferAccessError { pub enum BufferAccessError {
/// This buffer is not managed by the SHM handler /// This buffer is not managed by the SHM handler
#[error("non-SHM buffer")]
NotManaged, NotManaged,
/// An error occurred while accessing the memory map /// An error occurred while accessing the memory map
/// ///
@ -146,6 +143,7 @@ pub enum BufferAccessError {
/// for the memory map. /// for the memory map.
/// ///
/// If this error occurs, the client has been killed as a result. /// If this error occurs, the client has been killed as a result.
#[error("invalid client buffer")]
BadMap, BadMap,
} }
@ -158,7 +156,8 @@ pub enum BufferAccessError {
/// - The second argument is the specification of this buffer is this pool /// - The second argument is the specification of this buffer is this pool
/// ///
/// If the buffer is not managed by the provided `ShmGlobal`, the closure is not called /// If the buffer is not managed by the provided `ShmGlobal`, the closure is not called
/// and this method will return `Err(())` (this will be the case for an EGL buffer for example). /// and this method will return `Err(BufferAccessError::NotManaged)` (this will be the case for an
/// EGL buffer for example).
pub fn with_buffer_contents<F, T>(buffer: &wl_buffer::WlBuffer, f: F) -> Result<T, BufferAccessError> pub fn with_buffer_contents<F, T>(buffer: &wl_buffer::WlBuffer, f: F) -> Result<T, BufferAccessError>
where where
F: FnOnce(&[u8], BufferData) -> T, F: FnOnce(&[u8], BufferData) -> T,
@ -219,7 +218,7 @@ impl ShmGlobalData {
pub struct BufferData { pub struct BufferData {
/// Offset of the start of the buffer relative to the beginning of the pool in bytes /// Offset of the start of the buffer relative to the beginning of the pool in bytes
pub offset: i32, pub offset: i32,
/// Wwidth of the buffer in bytes /// Width of the buffer in bytes
pub width: i32, pub width: i32,
/// Height of the buffer in bytes /// Height of the buffer in bytes
pub height: i32, pub height: i32,