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

Abstraction for rendering into an RImage. More...

#include <RSurface.h>

+ Inheritance diagram for RSurface:

Public Member Functions

std::shared_ptr< RPassbeginPass (CZBitset< RPassCap > caps=RPassCap_Painter|RPassCap_SkCanvas, RDevice *device=nullptr) const noexcept
 Begins a rendering pass.
 
std::shared_ptr< RImageimage () const noexcept
 Returns the backing image used by the surface.
 
bool setGeometry (const RSurfaceGeometry &geometry) noexcept
 Updates the viewport -> (transform) -> dst mapping.
 
const RSurfaceGeometrygeometry () const noexcept
 Returns the current viewport -> (transform) -> dst mapping.
 
bool resize (SkISize size, SkScalar scale, bool shrink=false) noexcept
 Resizes the surface and optionally shrinks the backing image to fit the new destination size.
 
 ~RSurface () noexcept
 Destructor.
 
- Public Member Functions inherited from RObject
 RObject ()=default
 Constructs a default RObject.
 

Static Public Member Functions

static std::shared_ptr< RSurfaceMake (SkISize size, SkScalar scale, bool alpha) noexcept
 Creates a new surface with an internal image.
 
static std::shared_ptr< RSurfaceWrapImage (std::shared_ptr< RImage > image) noexcept
 Creates a surface from an existing RImage.
 

Detailed Description

Abstraction for rendering into an RImage.

RSurface wraps an RImage and provides convenience APIs to render using either RPainter or Skia SkCanvas. It maintains a virtual viewport and pixel destination rectangle to control coordinate mapping.

Constructor & Destructor Documentation

◆ ~RSurface()

~RSurface ( )
noexcept

Destructor.

Member Function Documentation

◆ Make()

static std::shared_ptr< RSurface > Make ( SkISize  size,
SkScalar  scale,
bool  alpha 
)
staticnoexcept

Creates a new surface with an internal image.

The created image will have at least the following caps for the main device:

  • RImageCap_Src
  • RImageCap_Dst
  • RImageCap_SkImage
  • RImageCap_SkSurface
Parameters
sizeViewport size (unscaled).
scaleScale factor.
alphaWhether the RImage format has alpha.
Returns
A shared pointer to the new RSurface, or nullptr on failure.
Note
If additional caps are needed, create an RImage manually and use WrapImage().

◆ WrapImage()

static std::shared_ptr< RSurface > WrapImage ( std::shared_ptr< RImage image)
staticnoexcept

Creates a surface from an existing RImage.

Wraps an existing image without copying it.

Note
The alphaType() of the backing storage/destination image is ignored and always considered premultiplied alpha.
Parameters
imageAn existing image with suitable caps.
Returns
A new surface wrapping the image, or nullptr on failure.

◆ beginPass()

std::shared_ptr< RPass > beginPass ( CZBitset< RPassCap >  caps = RPassCap_Painter|RPassCap_SkCanvas,
RDevice device = nullptr 
) const
noexcept

Begins a rendering pass.

Parameters
deviceOptional device to use. If nullptr, the main device is used.
Returns
A valid RPass object on success, or an invalid RPass on failure.

◆ image()

std::shared_ptr< RImage > image ( ) const
inlinenoexcept

Returns the backing image used by the surface.

Returns
Shared pointer to the underlying RImage. Always valid.

◆ setGeometry()

bool setGeometry ( const RSurfaceGeometry geometry)
noexcept

Updates the viewport -> (transform) -> dst mapping.

Unlike resize(), it never allocates a new image, even if the destination exceeds image bounds.

Parameters
viewportPortion of the world to capture.
dstPixel area within the image to render into.
transformOptional transform to apply (defaults to CZTransform::Normal).
Returns
true if geometry was successfully set, false if invalid.

◆ geometry()

const RSurfaceGeometry & geometry ( ) const
inlinenoexcept

Returns the current viewport -> (transform) -> dst mapping.

◆ resize()

bool resize ( SkISize  size,
SkScalar  scale,
bool  shrink = false 
)
noexcept

Resizes the surface and optionally shrinks the backing image to fit the new destination size.

Parameters
sizeUnscaled image size (viewport size).
scaleScale factor.
shrinkIf true, a new image will be allocated if the new dst size is different than the current image. If false, the existing image is reused as long as it is large enough.
Returns
true if a new image was allocated, false if the current image was reused.