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

OpenGL backend implementation of RImage. More...

#include <RGLImage.h>

+ Inheritance diagram for RGLImage:

Public Member Functions

RGLTexture texture (RGLDevice *device=nullptr) const noexcept
 Returns the OpenGL texture id and target for the given device.
 
std::optional< GLuint > glFb (RGLDevice *device=nullptr) const noexcept
 Returns a GL framebuffer object that renders into this image, for the given device.
 
std::shared_ptr< REGLImageeglImage (RGLDevice *device=nullptr) const noexcept
 Returns the EGLImage backing this image on the given device.
 
EGLSurface eglSurface (RGLDevice *device=nullptr) const noexcept
 Returns the EGLSurface this image renders into, if any.
 
std::shared_ptr< RGBMBogbmBo (RDevice *device=nullptr) const noexcept override
 Returns the GBM buffer object backing this image, if any.
 
std::shared_ptr< RDRMFramebufferdrmFb (RDevice *device=nullptr) const noexcept override
 Returns a DRM framebuffer for this image, if supported.
 
sk_sp< SkImage > skImage (RDevice *device=nullptr) const noexcept override
 Returns an SkImage view of this image, if supported (RImageCap_SkImage).
 
sk_sp< SkSurface > skSurface (RDevice *device=nullptr) const noexcept override
 Returns an SkSurface targeting this image, if supported (RImageCap_SkSurface).
 
CZBitset< RImageCap > checkDeviceCaps (CZBitset< RImageCap > caps, RDevice *device=nullptr) const noexcept override
 Checks which of the given capabilities are supported on a device.
 
bool writePixels (const RPixelBufferRegion &region) noexcept override
 Uploads pixel data into a region of the image.
 
bool readPixels (const RPixelBufferRegion &region) noexcept override
 Downloads pixel data from a region of the image.
 
RGLDeviceallocator () const noexcept
 Returns the device that allocated this image as an RGLDevice.
 
- 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< RGLImageMake (SkISize size, const RDRMFormat &format, const RImageConstraints *constraints=nullptr) noexcept
 Creates an OpenGL-backed image.
 
static std::shared_ptr< RGLImageFromDMA (const RDMABufferInfo &info, CZOwn ownership, const RImageConstraints *constraints=nullptr) noexcept
 Creates an image by importing an existing DMA-buffer.
 
static std::shared_ptr< RGLImageBorrowFramebuffer (const RGLFramebufferInfo &info, RGLDevice *allocator=nullptr) noexcept
 Wraps an existing OpenGL framebuffer as an image.
 
static std::shared_ptr< RGLImageFromEGLSurface (const REGLSurfaceInfo &info, CZOwn ownership, RGLDevice *allocator=nullptr) noexcept
 Wraps an existing EGLSurface as an 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

OpenGL backend implementation of RImage.

Backs a Ream image with OpenGL ES/EGL resources. Depending on how it was created, storage is either GBM/DMA-buf (importable across devices as an EGLImage/texture) or native GL. GL objects (textures, framebuffers, EGLImages, Skia images/surfaces) are created lazily per device and, for context-specific objects, per GL context, and cached.

Obtain it from an RImage via RImage::asGL().

Member Function Documentation

◆ texture()

RGLTexture texture ( RGLDevice device = nullptr) const
noexcept

Returns the OpenGL texture id and target for the given device.

The texture is created lazily by importing the image's EGLImage on first use and cached per device.

Parameters
deviceTarget device, or nullptr for the main device.
Returns
{0, 0} if no device is bound or the image couldn't be imported.

◆ glFb()

std::optional< GLuint > glFb ( RGLDevice device = nullptr) const
noexcept

Returns a GL framebuffer object that renders into this image, for the given device.

Created lazily and cached per GL context: for EGLSurface-backed images this is the default framebuffer (0); for native storage a new FBO is generated and the texture attached; otherwise the framebuffer is obtained from the backing EGLImage.

Parameters
deviceTarget device, or nullptr for the main device.
Returns
The framebuffer name, or std::nullopt if the image cannot be used as a render target.

◆ eglImage()

std::shared_ptr< REGLImage > eglImage ( RGLDevice device = nullptr) const
noexcept

Returns the EGLImage backing this image on the given device.

Created lazily by exporting the backing buffer as a DMA-buf and importing it as an EGLImage; cached per device.

Parameters
deviceTarget device, or nullptr for the main device.
Returns
The EGLImage, or nullptr if one could not be created.

◆ eglSurface()

EGLSurface eglSurface ( RGLDevice device = nullptr) const
noexcept

Returns the EGLSurface this image renders into, if any.

Only images created via FromEGLSurface() are backed by a surface.

Parameters
deviceTarget device, or nullptr for the main device.
Returns
The EGL surface, or EGL_NO_SURFACE if the image is not surface-backed.

◆ Make()

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

Creates an OpenGL-backed image.

Attempts native GL storage first, falling back to GBM/DMA-buf storage.

Parameters
sizeImage size in pixels.
formatRequested DRM format(s) and modifiers.
constraintsOptional capability/format constraints.
Returns
The new image, or nullptr on failure.

◆ FromDMA()

static std::shared_ptr< RGLImage > FromDMA ( const RDMABufferInfo info,
CZOwn  ownership,
const RImageConstraints constraints = nullptr 
)
staticnoexcept

Creates an image by importing an existing DMA-buffer.

Parameters
infoDescription of the DMA-buffer to import.
ownershipWhether Ream takes ownership of the buffer's file descriptors.
constraintsOptional capability/format constraints.
Returns
The new image, or nullptr on failure.

◆ BorrowFramebuffer()

static std::shared_ptr< RGLImage > BorrowFramebuffer ( const RGLFramebufferInfo info,
RGLDevice allocator = nullptr 
)
staticnoexcept

Wraps an existing OpenGL framebuffer as an image.

Parameters
infoDescription of the framebuffer to wrap.
allocatorOwning device, or nullptr for the main device.
Returns
The new image, or nullptr on failure.

◆ FromEGLSurface()

static std::shared_ptr< RGLImage > FromEGLSurface ( const REGLSurfaceInfo info,
CZOwn  ownership,
RGLDevice allocator = nullptr 
)
staticnoexcept

Wraps an existing EGLSurface as an image.

Parameters
infoDescription of the EGL surface to wrap.
ownershipWhether Ream takes ownership of the EGL surface.
allocatorOwning device, or nullptr for the main device.
Returns
The new image, or nullptr on failure.

◆ gbmBo()

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

Returns the GBM buffer object backing this image, if any.

Parameters
deviceDevice to query. If nullptr, the main device is used.
Returns
The GBM buffer object, or nullptr if unavailable.

Implements RImage.

◆ drmFb()

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

Returns a DRM framebuffer for this image, if supported.

Parameters
deviceDevice to query. If nullptr, the main device is used.
Returns
The DRM framebuffer, or nullptr if unavailable.

Implements RImage.

◆ skImage()

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

Returns an SkImage view of this image, if supported (RImageCap_SkImage).

Parameters
deviceDevice to query. If nullptr, the main device is used.
Returns
The SkImage, or nullptr if unavailable.

Implements RImage.

◆ skSurface()

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

Returns an SkSurface targeting this image, if supported (RImageCap_SkSurface).

Parameters
deviceDevice to query. If nullptr, the main device is used.
Returns
The SkSurface, or nullptr if unavailable.

Implements RImage.

◆ checkDeviceCaps()

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

Checks which of the given capabilities are supported on a device.

Parameters
capsThe capabilities to test.
deviceDevice to query. If nullptr, the main device is used.
Returns
The subset of caps that is supported; equals caps when all are supported.

Implements RImage.

◆ writePixels()

bool writePixels ( const RPixelBufferRegion region)
overridevirtualnoexcept

Uploads pixel data into a region of the image.

Increments writeSerial() on success.

Parameters
regionSource buffer and set of rectangles to copy.
Returns
true on success, false otherwise.

Implements RImage.

◆ readPixels()

bool readPixels ( const RPixelBufferRegion region)
overridevirtualnoexcept

Downloads pixel data from a region of the image.

Parameters
regionDestination buffer and set of rectangles to copy.
Returns
true on success, false otherwise.

Implements RImage.

◆ allocator()

RGLDevice * allocator ( ) const
inlinenoexcept

Returns the device that allocated this image as an RGLDevice.