Ream v0.1.0-1
C++ graphics library for Linux
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | List of all members
RDRMFramebuffer Class Referencefinal

A DRM framebuffer usable for KMS scanout. More...

#include <RDRMFramebuffer.h>

+ Inheritance diagram for RDRMFramebuffer:

Public Member Functions

bool hasModifier () const noexcept
 Whether the framebuffer was created with an explicit format modifier.
 
RModifier modifier () const noexcept
 Returns the DRM format modifier of the framebuffer.
 
RFormat format () const noexcept
 Returns the DRM pixel format of the framebuffer.
 
UInt32 id () const noexcept
 Returns the DRM framebuffer id, as used by KMS APIs.
 
RDevicedevice () const noexcept
 Returns the DRM device that owns this framebuffer.
 
std::shared_ptr< RCorecore () const noexcept
 Returns the internal shared reference to the core instance.
 
 ~RDRMFramebuffer () noexcept
 Destroys the framebuffer and closes any owned GEM handles.
 
- Public Member Functions inherited from RObject
 RObject ()=default
 Constructs a default RObject.
 

Static Public Member Functions

static std::shared_ptr< RDRMFramebufferMakeFromGBMBo (std::shared_ptr< RGBMBo > bo) noexcept
 Creates a framebuffer from a GBM buffer object (bo).
 
static std::shared_ptr< RDRMFramebufferMakeFromDMA (const RDMABufferInfo &dmaInfo, RDevice *importer=nullptr) noexcept
 Creates a framebuffer from DMA-BUF file descriptors.
 
static std::shared_ptr< RDRMFramebufferWrapHandle (SkISize size, UInt32 stride, RFormat format, RModifier modifier, UInt32 handle, CZOwn ownership, RDevice *device) noexcept
 Creates a single-plane framebuffer from an existing GEM buffer handle.
 

Detailed Description

A DRM framebuffer usable for KMS scanout.

Wraps a DRM framebuffer object created via drmModeAddFB2 (with a fallback to drmModeAddFB2WithModifiers or the legacy drmModeAddFB when necessary). A framebuffer binds one or more GEM buffer handles, together with their strides, offsets, format and modifier, into a single object that can be presented on a CRTC/plane.

Instances are created through the static factory methods from an existing GBM buffer object (MakeFromGBMBo()), imported DMA-BUF file descriptors (MakeFromDMA()), or a raw GEM handle (WrapHandle()). The framebuffer is always tied to the DRM device that created it.

On destruction the underlying framebuffer is removed (drmModeCloseFB, falling back to drmModeRmFB), and any GEM handles owned by this object (CZOwn::Own) are closed.

Constructor & Destructor Documentation

◆ ~RDRMFramebuffer()

~RDRMFramebuffer ( )
noexcept

Destroys the framebuffer and closes any owned GEM handles.

Member Function Documentation

◆ MakeFromGBMBo()

static std::shared_ptr< RDRMFramebuffer > MakeFromGBMBo ( std::shared_ptr< RGBMBo bo)
staticnoexcept

Creates a framebuffer from a GBM buffer object (bo).

This creates a framebuffer that can be used by the DRM device which allocated the provided GBM buffer object.

Parameters
boA shared pointer to the GBM buffer object.
Returns
A shared pointer to the created RDRMFramebuffer instance, or nullptr on failure.
Note
The buffer object is retained internally and will remain alive until the framebuffer is destroyed.

◆ MakeFromDMA()

static std::shared_ptr< RDRMFramebuffer > MakeFromDMA ( const RDMABufferInfo dmaInfo,
RDevice importer = nullptr 
)
staticnoexcept

Creates a framebuffer from DMA-BUF file descriptors.

Does not take ownership of the provided file descriptors.

Note
The DMA-BUF file descriptors can be safely closed after this call, as this object retains a reference to the buffers via GEM handles.
Parameters
dmaInfoInformation describing the DMA-BUF to import.
importerThe DRM device that will import the DMA-BUF fds and use the framebuffer. If nullptr, RCore::mainDevice() is used instead.
Returns
A shared pointer to the created RDRMFramebuffer instance, or nullptr on failure.

◆ WrapHandle()

static std::shared_ptr< RDRMFramebuffer > WrapHandle ( SkISize  size,
UInt32  stride,
RFormat  format,
RModifier  modifier,
UInt32  handle,
CZOwn  ownership,
RDevice device 
)
staticnoexcept

Creates a single-plane framebuffer from an existing GEM buffer handle.

Parameters
sizeThe width and height of the framebuffer in pixels.
strideThe stride (bytes per row) of the buffer.
formatThe DRM pixel format.
modifierThe DRM format modifier of the buffer.
handleThe GEM handle of the buffer, valid on device.
ownershipCZOwn::Own to take ownership of the handle (closed when this object is destroyed, including on failure), or CZOwn::Borrow to leave it untouched.
deviceThe DRM device that owns the handle and will use the framebuffer. If nullptr, RCore::mainDevice() is used instead.
Returns
A shared pointer to the created RDRMFramebuffer instance, or nullptr on failure.

◆ hasModifier()

bool hasModifier ( ) const
inlinenoexcept

Whether the framebuffer was created with an explicit format modifier.

Returns
true if an explicit modifier was used, false otherwise (in which case modifier() may not describe the actual buffer layout).

◆ modifier()

RModifier modifier ( ) const
inlinenoexcept

Returns the DRM format modifier of the framebuffer.

See also
hasModifier()

◆ format()

RFormat format ( ) const
inlinenoexcept

Returns the DRM pixel format of the framebuffer.

◆ id()

UInt32 id ( ) const
inlinenoexcept

Returns the DRM framebuffer id, as used by KMS APIs.

◆ device()

RDevice * device ( ) const
inlinenoexcept

Returns the DRM device that owns this framebuffer.

◆ core()

std::shared_ptr< RCore > core ( ) const
inlinenoexcept

Returns the internal shared reference to the core instance.

This ensures the current RCore instance stays alive while the framebuffer exists.