pub struct BufferObject { /* private fields */ }
Expand description
Analogous to gbm_bo
Implementations§
Source§impl BufferObject
impl BufferObject
Sourcepub fn new(
dev: &Device,
width: u32,
height: u32,
format: u32,
flags: u32,
) -> Option<BufferObject>
pub fn new( dev: &Device, width: u32, height: u32, format: u32, flags: u32, ) -> Option<BufferObject>
Allocate a buffer object for the given dimensions
§Arguments
dev: The Device returned from Device::from_fd()
width: The width for the buffer
height: The height for the buffer
format: The fourcc code for the surface
usage: The union of the usage flags for this buffer
§Returns
A newly allocated buffer. If an error occurs during allocation None
will be
returned and errno set.
§Example
let buffer = BufferObject::new(&device, 1920, 1080,
gbm::format::XRGB8888, // GBM_FORMAT_XRGB8888
gbm::USE_SCANOUT | gbm::USE_RENDERING);
Sourcepub fn stride(&self) -> u32
pub fn stride(&self) -> u32
Get the stride of the BufferObject
This is calculated by the backend when it does the allocation in BufferObject::new()
§Returns
The stride of the allocated BufferObject in bytes
Sourcepub fn format(&self) -> u32
pub fn format(&self) -> u32
Get the format of the buffer object
The format of the pixels in the buffer.
§Returns
The format of buffer object, as a fourcc code
Sourcepub fn device(&self) -> Device
pub fn device(&self) -> Device
Get the gbm device used to create the buffer object
§Returns
Returns the gbm device with which the buffer object was created
Sourcepub fn handle_u32(&self) -> u32
pub fn handle_u32(&self) -> u32
Get the handle of the buffer object
This is stored in the platform generic union gbm_bo_handle type. However the format of this handle is platform specific.
§Returns
Returns the handle of the allocated BufferObject as a u32
Sourcepub fn handle_u64(&self) -> u64
pub fn handle_u64(&self) -> u64
Get the handle of the buffer object
This is stored in the platform generic union gbm_bo_handle type. However the format of this handle is platform specific.
§Returns
Returns the handle of the allocated BufferObject as a u64
Sourcepub fn handle_i32(&self) -> i32
pub fn handle_i32(&self) -> i32
Get the handle of the buffer object
This is stored in the platform generic union gbm_bo_handle type. However the format of this handle is platform specific.
§Returns
Returns the handle of the allocated BufferObject as a i32
Sourcepub fn handle_i64(&self) -> i64
pub fn handle_i64(&self) -> i64
Get the handle of the buffer object
This is stored in the platform generic union gbm_bo_handle type. However the format of this handle is platform specific.
§Returns
Returns the handle of the allocated BufferObject as a i64
Sourcepub fn handle_ptr(&self) -> *const c_void
pub fn handle_ptr(&self) -> *const c_void
Get the handle of the buffer object
This is stored in the platform generic union gbm_bo_handle type. However the format of this handle is platform specific.
§Returns
Returns the handle of the allocated BufferObject as a void *
Sourcepub fn fd(&self) -> RawFd
pub fn fd(&self) -> RawFd
Get a DMA-BUF file descriptor for the buffer object
This function creates a DMA-BUF (also known as PRIME) file descriptor handle for the buffer object. Each call to gbm_bo_get_fd() returns a new file descriptor and the caller is responsible for closing the file descriptor.
§Returns
Returns a file descriptor referring to the underlying buffer
Sourcepub fn write<T>(&self, buf: *const T, count: usize) -> bool
pub fn write<T>(&self, buf: *const T, count: usize) -> bool
Write data into the buffer object
If the buffer object was created with the USE_WRITE flag this function can used to write data into the buffer object. The data is copied directly into the object and it’s the responsiblity of the caller to make sure the data represents valid pixel data, according to the width, height, stride and format of the buffer object.
§Arguments
buf: The data to write
count: The number of bytes to write
§Returns
Returns true
on success, otherwise false
is returned an errno set