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
RRSImage Class Reference

Raster (software) implementation of RImage. More...

#include <RRSImage.h>

+ Inheritance diagram for RRSImage:

Public Member Functions

std::shared_ptr< RGBMBogbmBo (RDevice *device=nullptr) const noexcept override
 Always returns an empty pointer.
 
std::shared_ptr< RDRMFramebufferdrmFb (RDevice *device=nullptr) const noexcept override
 Always returns an empty pointer.
 
sk_sp< SkImage > skImage (RDevice *device=nullptr) const noexcept override
 Returns the SkImage wrapping the shared-memory pixels.
 
sk_sp< SkSurface > skSurface (RDevice *device=nullptr) const noexcept override
 Returns the SkSurface wrapping the shared-memory pixels.
 
CZBitset< RImageCap > checkDeviceCaps (CZBitset< RImageCap > caps, RDevice *device=nullptr) const noexcept override
 Reports which of the requested capabilities are supported.
 
bool writePixels (const RPixelBufferRegion &region) noexcept override
 Uploads pixels into the image via a CPU memcpy.
 
bool readPixels (const RPixelBufferRegion &region) noexcept override
 Downloads pixels from the image via a CPU memcpy.
 
RRSDeviceallocator () const noexcept
 Returns the allocator device downcast to the Raster backend type.
 
size_t stride () const noexcept
 Returns the row stride of the pixel buffer, in bytes.
 
std::shared_ptr< CZSharedMemory > shm () const noexcept
 Returns the shared memory backing the image pixels.
 
int resize (SkISize size) noexcept
 Resizes the image in place, reallocating the backing SkImage/SkSurface.
 
- Public Member Functions inherited from RImage
SkISize size () const noexcept
 Returns the image size in pixels.
 
const RFormatInfoformatInfo () const noexcept
 Returns information about the image's pixel format.
 
const std::unordered_set< RFormat > & readFormats () const noexcept
 Returns the set of formats the image can be read/sampled as.
 
const std::unordered_set< RFormat > & writeFormats () const noexcept
 Returns the set of formats the image can be written to.
 
SkAlphaType alphaType () const noexcept
 Returns the image's alpha type.
 
RModifier modifier () const noexcept
 Returns the DRM format modifier of the image's storage.
 
RDeviceallocator () const noexcept
 Returns the device that allocated this image.
 
std::shared_ptr< RCorecore () const noexcept
 Returns the RCore instance that owns this image.
 
std::shared_ptr< RSyncreadSync () noexcept
 Returns the read sync fence.
 
void setReadSync (std::shared_ptr< RSync > sync) noexcept
 Sets the read sync fence.
 
std::shared_ptr< RSyncwriteSync () noexcept
 Returns the write sync fence.
 
void setWriteSync (std::shared_ptr< RSync > sync) noexcept
 Sets the write sync fence.
 
UInt32 writeSerial () const noexcept
 Returns the write serial.
 
std::shared_ptr< RGLImageasGL () const noexcept
 Attempts to cast this image to an RGLImage.
 
std::shared_ptr< RRSImageasRS () const noexcept
 Attempts to cast this image to an RRSImage.
 
std::shared_ptr< RVKImageasVK () const noexcept
 Attempts to cast this image to an RVKImage.
 
 ~RImage () noexcept
 Destructor.
 
- Public Member Functions inherited from RObject
 RObject ()=default
 Constructs a default RObject.
 

Static Public Member Functions

static std::shared_ptr< RRSImageMake (SkISize size, const RDRMFormat &format, const RImageConstraints *constraints=nullptr) noexcept
 Creates a Raster image.
 
- Static Public Member Functions inherited from RImage
static std::shared_ptr< RImageMake (SkISize size, const RDRMFormat &format, const RImageConstraints *constraints=nullptr) noexcept
 Allocates a new empty image.
 
static std::shared_ptr< RImageMakeFromPixels (const RPixelBufferInfo &info, const RDRMFormat &format, const RImageConstraints *constraints=nullptr) noexcept
 Allocates a new image and uploads pixel data into it.
 
static std::shared_ptr< RImageLoadFile (const std::filesystem::path &path, const RDRMFormat &format, SkISize size={0, 0}, const RImageConstraints *constraints=nullptr) noexcept
 Loads an image from a file.
 
static std::shared_ptr< RImageFromDMA (const RDMABufferInfo &info, CZOwn ownership, const RImageConstraints *constraints=nullptr) noexcept
 Imports an image from a DMA-buf.
 

Detailed Description

Raster (software) implementation of RImage.

RRSImage backs its pixels with host-visible shared memory (CZSharedMemory) using a linear layout, and wraps that memory in both an SkImage (for sampling) and an SkSurface (for rendering). It can be obtained from an RImage via asRS().

Because it is a CPU buffer, it never exposes GBM buffer objects or DRM framebuffers. The shared memory can be shared with a Wayland compositor (see RRSSwapchainWL) as a wl_shm buffer.

Member Function Documentation

◆ Make()

static std::shared_ptr< RRSImage > Make ( SkISize  size,
const RDRMFormat format,
const RImageConstraints constraints = nullptr 
)
staticnoexcept

Creates a Raster image.

Allocates shared memory sized for size and format (which must be a linear-modifier format supported by the allocator device) and wraps it in an SkImage and SkSurface.

Parameters
sizeImage size in pixels. Must not be empty.
formatDRM format and modifiers. Must resolve to a supported Skia color type and allow the linear (or invalid) modifier.
constraintsOptional constraints. Note that the DRMFb and GBMBo capabilities are not supported and requesting them fails.
Returns
A valid RRSImage on success, nullptr on failure.

◆ gbmBo()

std::shared_ptr< RGBMBo > gbmBo ( RDevice device = nullptr) const
inlineoverridevirtualnoexcept

Always returns an empty pointer.

Raster images are CPU buffers and have no GBM backing.

Implements RImage.

◆ drmFb()

std::shared_ptr< RDRMFramebuffer > drmFb ( RDevice device = nullptr) const
inlineoverridevirtualnoexcept

Always returns an empty pointer.

Raster images cannot be used as DRM framebuffers.

Implements RImage.

◆ skImage()

sk_sp< SkImage > skImage ( RDevice device = nullptr) const
inlineoverridevirtualnoexcept

Returns the SkImage wrapping the shared-memory pixels.

The device argument is ignored; the same object is returned regardless of device.

Implements RImage.

◆ skSurface()

sk_sp< SkSurface > skSurface ( RDevice device = nullptr) const
inlineoverridevirtualnoexcept

Returns the SkSurface wrapping the shared-memory pixels.

The device argument is ignored; the same object is returned regardless of device.

Implements RImage.

◆ checkDeviceCaps()

CZBitset< RImageCap > checkDeviceCaps ( CZBitset< RImageCap >  caps,
RDevice device = nullptr 
) const
overridevirtualnoexcept

Reports which of the requested capabilities are supported.

Implements the RImage contract for the Raster backend: the DRMFb and GBMBo capabilities are always stripped from caps, all others are reported as supported.

Implements RImage.

◆ writePixels()

bool writePixels ( const RPixelBufferRegion region)
overridevirtualnoexcept

Uploads pixels into the image via a CPU memcpy.

The region's format must match the image format. Implements the RImage writePixels() contract.

Implements RImage.

◆ readPixels()

bool readPixels ( const RPixelBufferRegion region)
overridevirtualnoexcept

Downloads pixels from the image via a CPU memcpy.

The region's format must match the image format. Implements the RImage readPixels() contract.

Implements RImage.

◆ allocator()

RRSDevice * allocator ( ) const
inlinenoexcept

Returns the allocator device downcast to the Raster backend type.

◆ stride()

size_t stride ( ) const
inlinenoexcept

Returns the row stride of the pixel buffer, in bytes.

◆ shm()

std::shared_ptr< CZSharedMemory > shm ( ) const
inlinenoexcept

Returns the shared memory backing the image pixels.

◆ resize()

int resize ( SkISize  size)
noexcept

Resizes the image in place, reallocating the backing SkImage/SkSurface.

The underlying shared memory is grown only when the new size needs more bytes than currently allocated; it is never shrunk. Used by RRSSwapchainWL to recycle buffers.

Parameters
sizeThe new image size in pixels. Must not be empty.
Returns
-1 on error, 0 if the shared memory was not truncated (reused as-is), 1 if the shared memory was truncated (resized).