API Reference
The API documentation is automatically generated from the C++ source code using Doxygen and Breathe.
Full API Index
-
class Canvas
- #include <canvas.hpp>
User-facing drawing API.
Canvas provides high-level drawing commands that are recorded through a Device. Use save()/restore() for state management and clipRect() for clipping.
Paint-based drawing (advanced)
Public Functions
-
explicit Canvas(Device *device)
Construct a Canvas that records into a device.
- Parameters:
device – The device to record drawing commands into.
-
void clipRect(Rect r)
Intersect the current clip with a rectangle.
- Parameters:
r – The clipping rectangle.
Draw an image at the given position (alpha-blended).
- Parameters:
image – Shared pointer to the image.
x – X position.
y – Y position.
-
void drawLine(Point p1, Point p2, Color c, f32 width = 1.0f)
Draw a line between two points.
- Parameters:
p1 – Start point.
p2 – End point.
c – Line color.
width – Line width (default 1.0).
-
void drawPolyline(const Point *pts, i32 count, Color c, f32 width = 1.0f)
Draw a connected series of line segments.
- Parameters:
pts – Array of vertices.
count – Number of points.
c – Line color.
width – Line width (default 1.0).
-
void drawText(Point p, std::string_view text, Color c)
Draw text at the given position.
- Parameters:
p – Position of the text baseline.
text – UTF-8 text to draw.
c – Text color.
-
void fillCircle(f32 cx, f32 cy, f32 radius, Color c)
Fill a circle with a solid color.
- Parameters:
cx – Center X.
cy – Center Y.
radius – Circle radius.
c – Fill color.
-
void fillRect(Rect r, Color c)
Fill a rectangle with a solid color.
- Parameters:
r – The rectangle to fill.
c – Fill color.
-
void fillRoundRect(Rect r, f32 rx, f32 ry, Color c)
Fill a rounded rectangle with a solid color.
- Parameters:
r – The rectangle.
rx – Corner radius in X.
ry – Corner radius in Y.
c – Fill color.
-
void restore()
Restore the most recently saved clip state.
-
void save()
Save the current clip state onto the stack.
-
void strokeCircle(f32 cx, f32 cy, f32 radius, Color c, f32 width = 1.0f)
Stroke a circle outline.
- Parameters:
cx – Center X.
cy – Center Y.
radius – Circle radius.
c – Stroke color.
width – Stroke line width (default 1.0).
-
void strokeRect(Rect r, Color c, f32 width = 1.0f)
Stroke a rectangle outline.
- Parameters:
r – The rectangle to stroke.
c – Stroke color.
width – Stroke line width (default 1.0).
-
explicit Canvas(Device *device)
-
struct Color
- #include <types.hpp>
An RGBA color with 8-bit components.
-
struct CompactDrawOp
- #include <recording.hpp>
Compact draw operation structure (28 bytes).
Public Members
-
union ink::CompactDrawOp::Data data
Per-operation payload (16 bytes).
-
union ink::CompactDrawOp::Data data
-
union Data
- #include <recording.hpp>
Union of per-operation data variants.
Public Functions
-
inline Data()
Public Members
-
struct ink::CompactDrawOp::Data circle
Circle data (12 bytes).
-
struct ink::CompactDrawOp::Data clip
SetClip data.
-
struct ink::CompactDrawOp::Data fill
FillRect data.
-
struct ink::CompactDrawOp::Data image
DrawImage data.
-
struct ink::CompactDrawOp::Data line
Line data.
-
struct ink::CompactDrawOp::Data polyline
Polyline data (arena offset + count).
-
struct ink::CompactDrawOp::Data roundRect
RoundRect data (arena offset).
-
struct ink::CompactDrawOp::Data stroke
StrokeRect data.
-
struct ink::CompactDrawOp::Data text
Text data (position + arena offset + length).
-
struct ink::CompactDrawOp::Data transform
SetTransform data (arena offset).
-
inline Data()
-
class Device
- #include <device.hpp>
The single recording device.
Device converts Canvas high-level commands into low-level Recording ops. All Surfaces use the same Device — it always records, never draws directly. The actual rendering is done by a Renderer that consumes the Recording.
Drawing commands (Paint-based)
-
struct DrawOp
- #include <recording.hpp>
Draw operation type tag.
Public Types
-
enum class Type : u8
Operation type enumeration.
Values:
-
enumerator FillRect
Fill a rectangle.
-
enumerator StrokeRect
Stroke a rectangle outline.
-
enumerator Line
Draw a line segment.
-
enumerator Polyline
Draw connected line segments.
-
enumerator Text
Draw text.
-
enumerator DrawImage
Draw an image.
-
enumerator SetClip
Set a clip rectangle.
-
enumerator ClearClip
Clear the clip rectangle.
-
enumerator SetTransform
Set a transform matrix.
-
enumerator ClearTransform
Clear the transform matrix.
-
enumerator FillCircle
Fill a circle.
-
enumerator StrokeCircle
Stroke a circle outline.
-
enumerator FillRoundRect
Fill a rounded rectangle.
-
enumerator StrokeRoundRect
Stroke a rounded rectangle outline.
-
enumerator FillRect
-
enum class Type : u8
-
class DrawOpArena
- #include <recording.hpp>
Arena allocator for variable-length DrawOp data (strings, point arrays).
Public Functions
-
explicit DrawOpArena(size_t initialCapacity = 4096)
Construct an arena with the given initial capacity.
- Parameters:
initialCapacity – Initial byte capacity (default 4096).
-
u32 allocate(size_t bytes)
Allocate raw storage.
- Parameters:
bytes – Number of bytes to allocate.
- Returns:
Byte offset into the arena.
-
const Matrix *getMatrix(u32 offset) const
Retrieve a stored matrix by offset.
- Parameters:
offset – Byte offset returned by storeMatrix().
- Returns:
Pointer to the Matrix.
-
const Point *getPoints(u32 offset) const
Retrieve stored points by offset.
- Parameters:
offset – Byte offset returned by storePoints().
- Returns:
Pointer to the first Point.
-
void getRoundRect(u32 offset, Rect &r, f32 &rx, f32 &ry) const
Retrieve stored rounded rectangle data.
- Parameters:
offset – Byte offset returned by storeRoundRect().
r – Output rectangle.
rx – Output corner radius in X.
ry – Output corner radius in Y.
-
const char *getString(u32 offset) const
Retrieve a stored string by offset.
- Parameters:
offset – Byte offset returned by storeString().
- Returns:
Pointer to the null-terminated string.
-
void reset()
Reset the arena, discarding all stored data.
-
u32 storeMatrix(const Matrix &m)
Store a matrix in the arena.
- Parameters:
m – The matrix to store.
- Returns:
Byte offset to the stored matrix.
-
u32 storePoints(const Point *pts, i32 count)
Store a points array in the arena.
- Parameters:
pts – Pointer to the points array.
count – Number of points.
- Returns:
Byte offset to the stored points.
-
explicit DrawOpArena(size_t initialCapacity = 4096)
-
class DrawOpVisitor
- #include <draw_op_visitor.hpp>
Visitor interface for traversing recorded draw operations.
Implement this interface to process drawing commands dispatched by Recording::accept() or Recording::dispatch().
Public Functions
-
virtual ~DrawOpVisitor() = default
-
virtual void visitClearClip() = 0
Visit a clear-clip command (removes current clip).
-
virtual void visitClearTransform() = 0
Visit a clear-transform command (resets to identity).
-
virtual void visitDrawImage(const Image *image, f32 x, f32 y, BlendMode blend, u8 opacity) = 0
Visit an image drawing command.
- Parameters:
image – Pointer to the image to draw.
x – X position to draw at.
y – Y position to draw at.
blend – Blend mode.
opacity – Opacity 0-255.
-
virtual void visitFillCircle(f32 cx, f32 cy, f32 radius, Color color, BlendMode blend, u8 opacity) = 0
Visit a filled circle command.
- Parameters:
cx – Center X coordinate.
cy – Center Y coordinate.
radius – Circle radius.
color – Fill color.
blend – Blend mode.
opacity – Opacity 0-255.
-
virtual void visitFillRect(Rect rect, Color color, BlendMode blend, u8 opacity) = 0
Visit a filled rectangle command.
- Parameters:
rect – The rectangle to fill.
color – Fill color.
blend – Blend mode.
opacity – Opacity 0-255.
-
virtual void visitFillRoundRect(Rect rect, f32 rx, f32 ry, Color color, BlendMode blend, u8 opacity) = 0
Visit a filled rounded rectangle command.
- Parameters:
rect – The rectangle.
rx – Corner radius in X.
ry – Corner radius in Y.
color – Fill color.
blend – Blend mode.
opacity – Opacity 0-255.
-
virtual void visitLine(Point p1, Point p2, Color color, f32 width, BlendMode blend, u8 opacity) = 0
Visit a line segment command.
- Parameters:
p1 – Start point.
p2 – End point.
color – Line color.
width – Line width.
blend – Blend mode.
opacity – Opacity 0-255.
-
virtual void visitPolyline(const Point *points, i32 count, Color color, f32 width, BlendMode blend, u8 opacity) = 0
Visit a polyline command.
- Parameters:
points – Array of vertices.
count – Number of points.
color – Line color.
width – Line width.
blend – Blend mode.
opacity – Opacity 0-255.
-
virtual void visitSetClip(Rect rect) = 0
Visit a clip rectangle command.
- Parameters:
rect – The clipping rectangle.
-
virtual void visitSetTransform(const Matrix &m) = 0
Visit a set-transform command.
- Parameters:
m – The transformation matrix.
-
virtual void visitStrokeCircle(f32 cx, f32 cy, f32 radius, Color color, f32 width, BlendMode blend, u8 opacity) = 0
Visit a stroked circle command.
- Parameters:
cx – Center X coordinate.
cy – Center Y coordinate.
radius – Circle radius.
color – Stroke color.
width – Stroke line width.
blend – Blend mode.
opacity – Opacity 0-255.
-
virtual void visitStrokeRect(Rect rect, Color color, f32 width, BlendMode blend, u8 opacity) = 0
Visit a stroked rectangle command.
- Parameters:
rect – The rectangle to stroke.
color – Stroke color.
width – Stroke line width.
blend – Blend mode.
opacity – Opacity 0-255.
-
virtual void visitStrokeRoundRect(Rect rect, f32 rx, f32 ry, Color color, f32 width, BlendMode blend, u8 opacity) = 0
Visit a stroked rounded rectangle command.
- Parameters:
rect – The rectangle.
rx – Corner radius in X.
ry – Corner radius in Y.
color – Stroke color.
width – Stroke line width.
blend – Blend mode.
opacity – Opacity 0-255.
-
virtual void visitText(Point pos, const char *text, u32 len, Color color, BlendMode blend, u8 opacity) = 0
Visit a text drawing command.
- Parameters:
pos – Position of the text baseline.
text – UTF-8 text string.
len – Length of the text in bytes.
color – Text color.
blend – Blend mode.
opacity – Opacity 0-255.
-
virtual ~DrawOpVisitor() = default
-
class DrawPass
- #include <draw_pass.hpp>
Sorts recorded draw operations for optimal execution order.
DrawPass reorders operations by clip group, type, and color to minimize state changes in the rendering backend.
Public Functions
-
inline const std::vector<u32> &sortedIndices() const
Get the sorted operation indices.
- Returns:
Indices into Recording::ops() in sorted execution order.
Public Static Functions
-
inline const std::vector<u32> &sortedIndices() const
-
class GlyphCache
- #include <glyph_cache.hpp>
Font rasterization cache backed by a texture atlas.
Rasterizes glyphs on demand using stb_truetype and stores them in a greyscale atlas that can be uploaded to the GPU.
Public Functions
-
~GlyphCache()
-
inline const u8 *atlasData() const
Get the raw atlas pixel data.
- Returns:
Pointer to the greyscale atlas buffer.
-
inline bool atlasDirty() const
Check if the atlas has been modified since last upload.
- Returns:
True if dirty.
-
void drawText(u32 *pixels, i32 stride, i32 bufH, i32 x, i32 y, std::string_view text, Color c)
Rasterize text directly into a pixel buffer (CPU path).
- Parameters:
pixels – Destination pixel buffer (RGBA u32).
stride – Row stride of the destination buffer in pixels.
bufH – Height of the destination buffer in pixels.
x – X position to start drawing.
y – Y position to start drawing.
text – UTF-8 text to rasterize.
c – Text color.
-
const GlyphMetrics *getGlyph(char ch)
Get (or rasterize) metrics for a character.
- Parameters:
ch – The character to look up.
- Returns:
Pointer to the glyph metrics, or nullptr on failure.
-
bool init(const char *fontPath, f32 fontSize)
Initialize with a TrueType font file and pixel size.
- Parameters:
fontPath – Path to the .ttf font file.
fontSize – Desired font size in pixels.
- Returns:
True on success, false if the font could not be loaded.
-
inline i32 lineHeight() const
Get the line height for the loaded font.
- Returns:
Line height in pixels.
-
inline void markClean()
Mark the atlas as clean (after uploading to GPU).
-
i32 measureText(std::string_view text)
Measure the horizontal advance width of a text string.
- Parameters:
text – UTF-8 text to measure.
- Returns:
Width in pixels.
-
void release()
Release all resources.
Private Members
-
bool dirty_ = true
-
void *fontInfo_ = nullptr
-
std::unordered_map<char, GlyphMetrics> glyphs_
-
~GlyphCache()
-
struct GlyphMetrics
- #include <glyph_cache.hpp>
Metrics for a single rasterized glyph.
-
class GpuContext : public ink::Renderer
- #include <gpu_context.hpp>
GPU rendering context.
Implements the Renderer interface for GPU rendering. Create via backend-specific factory functions:
Renderer interface
-
virtual void beginFrame(Color clearColor = {0, 0, 0, 255}) override
Begin a new frame, clearing the render target.
- Parameters:
clearColor – The color to clear the render target to (default: opaque black).
-
virtual void endFrame() override
End the current frame.
-
virtual void execute(const Recording &recording, const DrawPass &pass) override
Execute recorded drawing commands.
- Parameters:
recording – The recorded drawing commands.
pass – The draw pass defining execution order.
-
virtual void resize(i32 w, i32 h) override
Resize the render target.
- Parameters:
w – New width in pixels.
h – New height in pixels.
-
virtual std::shared_ptr<Image> makeSnapshot() const override
Create an immutable snapshot of the current render target.
- Returns:
Shared pointer to the snapshot Image.
-
virtual void setGlyphCache(GlyphCache *cache) override
Set the glyph cache used for text rendering.
- Parameters:
cache – Pointer to the glyph cache.
GPU-specific operations
-
void readPixels(void *dst, i32 x, i32 y, i32 w, i32 h) const
Read pixels from the GPU framebuffer into a buffer.
- Parameters:
dst – Destination buffer (must be large enough for w×h×4 bytes).
x – X offset in the framebuffer.
y – Y offset in the framebuffer.
w – Width of the region to read.
h – Height of the region to read.
-
unsigned int textureId() const
Get the GL texture ID of the offscreen color attachment.
- Returns:
OpenGL texture name.
-
unsigned int fboId() const
Get the GL framebuffer object ID.
- Returns:
OpenGL FBO name.
Public Functions
-
~GpuContext() override
-
bool valid() const
Check if the underlying GPU implementation is valid.
- Returns:
True if the GPU backend was initialized successfully.
Friends
- friend class Surface
-
virtual void beginFrame(Color clearColor = {0, 0, 0, 255}) override
-
class Image
- #include <image.hpp>
An immutable snapshot of pixel data.
Images are created from Surfaces via makeSnapshot() and can be drawn onto any Surface via canvas->drawImage(). This is the mechanism for compositing multiple surfaces together.
Public Types
Public Functions
-
inline u64 backendTextureHandle() const
Get the opaque backend texture handle.
- Returns:
Texture handle for GPU-backed images; 0 otherwise.
-
inline PixelFormat format() const
Get pixel format.
- Returns:
The pixel format of this image.
-
inline u32 glTextureId() const
Get the GL texture ID.
- Returns:
OpenGL texture name (truncated from u64 to u32).
-
inline const PixmapInfo &info() const
Get full pixmap info.
- Returns:
Reference to the PixmapInfo descriptor.
-
inline bool isCpuBacked() const
Check if image is CPU-backed.
- Returns:
True if stored as a CPU pixmap.
-
inline bool isGpuBacked() const
Check if image is GPU-backed.
- Returns:
True if stored as a GPU texture.
-
inline const void *pixels() const
Get raw pixel pointer (CPU-backed images only).
- Returns:
Pointer to pixel data, or nullptr for GPU-backed images.
-
inline const u32 *pixels32() const
Get pixel data as 32-bit words.
- Returns:
Pointer to pixel data cast to u32*.
-
inline StorageType storageType() const
Get the storage type.
- Returns:
-
inline u64 uniqueId() const
Get a stable unique identity for backend caches.
- Returns:
Unique image ID.
-
inline bool valid() const
Check if the image contains valid data.
- Returns:
True if dimensions are positive and backing storage is present.
Public Static Functions
Create an image from a backend-specific GPU texture handle.
- Parameters:
textureHandle – Opaque handle (e.g. GLuint for GL, VkImage for Vulkan).
width – Texture width in pixels.
height – Texture height in pixels.
fmt – Pixel format (default RGBA8888).
lifetimeToken – Optional shared_ptr whose destructor releases the texture.
- Returns:
Shared pointer to the new Image.
Convenience: create from a GL texture ID.
- Parameters:
textureId – OpenGL texture name.
width – Texture width in pixels.
height – Texture height in pixels.
fmt – Pixel format (default RGBA8888).
lifetimeToken – Optional shared_ptr whose destructor releases the texture.
- Returns:
Shared pointer to the new Image.
Private Members
-
PixmapInfo info_
-
const void *pixels_ = nullptr
-
StorageType storageType_ = StorageType::CpuPixmap
-
inline u64 backendTextureHandle() const
-
struct Matrix
- #include <matrix.hpp>
3x3 affine transformation matrix (stored as 6 floats).
Represents the matrix: | scaleX skewX transX | | skewY scaleY transY | | 0 0 1 |
Points are transformed as: x’ = scaleX * x + skewX * y + transX y’ = skewY * x + scaleY * y + transY
Public Functions
-
inline Matrix inverted(bool *ok = nullptr) const
Compute the inverse matrix.
Returns identity if not invertible.
- Parameters:
ok – If non-null, set to true on success, false if not invertible.
-
inline bool isIdentity() const
Check if this is the identity matrix.
-
inline bool isScaleTranslateOnly() const
Check if this is scale+translate only (no rotation/skew).
-
inline bool isTranslateOnly() const
Check if this is translate-only (no rotation/scale/skew).
Public Members
-
inline Matrix inverted(bool *ok = nullptr) const
-
struct Paint
- #include <paint.hpp>
Describes how to draw: color, style, blend mode, stroke width, opacity.
Public Functions
-
explicit Paint() = default
Default construct a paint (black, fill, SrcOver, full opacity).
Public Members
-
PaintStyle style = PaintStyle::Fill
-
explicit Paint() = default
-
struct PixelData
- #include <pixel_data.hpp>
Non-owning pixel data descriptor for host integration.
Does not own the pixel data — the caller must ensure the pixels remain valid for the lifetime of this descriptor.
Public Functions
-
PixelData() = default
-
inline PixelData(const void *data_, i32 w, i32 h, i32 stride, PixelFormat fmt)
Construct a PixelData descriptor.
- Parameters:
data_ – Pointer to the raw pixel buffer.
w – Width in pixels.
h – Height in pixels.
stride – Bytes per row.
fmt – Pixel format.
-
inline bool isValid() const
Check if the descriptor points to valid pixel data.
- Returns:
True if data is non-null and dimensions are positive.
-
PixelData() = default
-
class Pixmap
- #include <pixmap.hpp>
Owning or non-owning pixel buffer.
Use Alloc() to create an owned buffer, or Wrap() to reference external memory.
Public Functions
-
Pixmap() = default
-
~Pixmap()
-
inline void *addr()
Get raw pixel pointer (mutable).
-
inline const void *addr() const
Get raw pixel pointer (const).
-
inline PixelFormat format() const
Get pixel format.
-
inline const PixmapInfo &info() const
Get the pixmap info descriptor.
-
void reallocate(const PixmapInfo &info)
Reallocate the buffer with new dimensions/format.
- Parameters:
info – New pixmap descriptor.
-
void reset()
Release pixel data and reset to empty state.
-
inline void *rowAddr(i32 y)
Get pointer to the start of a specific row (mutable).
- Parameters:
y – Row index.
-
inline const void *rowAddr(i32 y) const
Get pointer to the start of a specific row (const).
- Parameters:
y – Row index.
-
inline bool valid() const
Check if the pixmap has valid pixel data.
- Returns:
True if pixels are non-null and dimensions are positive.
Public Static Functions
-
static Pixmap Alloc(const PixmapInfo &info)
Allocate a new pixel buffer described by info.
- Parameters:
info – Dimensions, stride, and format of the buffer.
- Returns:
A new Pixmap that owns its pixel data.
-
static Pixmap Wrap(const PixmapInfo &info, void *pixels)
Wrap existing pixel memory (caller keeps ownership).
- Parameters:
info – Dimensions, stride, and format of the buffer.
pixels – Pointer to the external pixel data.
- Returns:
A non-owning Pixmap.
Private Functions
-
Pixmap(const PixmapInfo &info, void *pixels, bool ownsPixels)
-
Pixmap() = default
-
struct PixmapInfo
- #include <pixmap.hpp>
Descriptor for pixel buffer dimensions, stride, and format.
Public Functions
Public Members
-
PixelFormat format = PixelFormat::BGRA8888
Pixel format (BGRA is native on most platforms).
Public Static Functions
-
static inline PixmapInfo Make(i32 w, i32 h, PixelFormat fmt)
Create a PixmapInfo with the given dimensions and format.
- Parameters:
w – Width in pixels.
h – Height in pixels.
fmt – Pixel format.
- Returns:
A new PixmapInfo.
-
static inline PixmapInfo MakeBGRA(i32 w, i32 h)
Create a PixmapInfo with BGRA8888 format.
- Parameters:
w – Width in pixels.
h – Height in pixels.
- Returns:
A new PixmapInfo with BGRA8888 format.
-
static inline PixmapInfo MakeRGBA(i32 w, i32 h)
Create a PixmapInfo with RGBA8888 format.
- Parameters:
w – Width in pixels.
h – Height in pixels.
- Returns:
A new PixmapInfo with RGBA8888 format.
-
PixelFormat format = PixelFormat::BGRA8888
-
struct Point
- #include <types.hpp>
A 2D point with floating-point coordinates.
-
class Recorder
- #include <recording.hpp>
Records draw operations into a compact command buffer.
Call drawing methods to accumulate operations, then finish() to produce an immutable Recording.
Public Functions
-
void clearClip()
Record a clear-clip operation.
-
void clearTransform()
Record a clear-transform operation.
Record an image-drawing operation.
- Parameters:
image – Shared pointer to the image.
x – X position.
y – Y position.
-
void drawLine(Point p1, Point p2, Color c, f32 width)
Record a line-drawing operation.
- Parameters:
p1 – Start point.
p2 – End point.
c – Line color.
width – Line width.
-
void drawLine(Point p1, Point p2, const Paint &p)
Record a line-drawing operation using a Paint.
- Parameters:
p1 – Start point.
p2 – End point.
p – Paint describing style, color, blend, opacity.
-
void drawPolyline(const Point *pts, i32 count, Color c, f32 width)
Record a polyline-drawing operation.
- Parameters:
pts – Array of vertices.
count – Number of points.
c – Line color.
width – Line width.
-
void drawPolyline(const Point *pts, i32 count, const Paint &p)
Record a polyline-drawing operation using a Paint.
- Parameters:
pts – Array of vertices.
count – Number of points.
p – Paint describing style, color, blend, opacity.
-
void drawText(Point p, std::string_view text, Color c)
Record a text-drawing operation.
- Parameters:
p – Position of the text baseline.
text – UTF-8 text to draw.
c – Text color.
-
void drawText(Point pos, std::string_view text, const Paint &p)
Record a text-drawing operation using a Paint.
- Parameters:
pos – Position of the text baseline.
text – UTF-8 text to draw.
p – Paint describing style, color, blend, opacity.
-
void fillCircle(f32 cx, f32 cy, f32 radius, Color c)
Record a fill-circle operation.
- Parameters:
cx – Center X.
cy – Center Y.
radius – Circle radius.
c – Fill color.
-
void fillCircle(f32 cx, f32 cy, f32 radius, const Paint &p)
Record a fill-circle operation using a Paint.
- Parameters:
cx – Center X.
cy – Center Y.
radius – Circle radius.
p – Paint describing style, color, blend, opacity.
-
void fillRect(Rect r, Color c)
Record a fill-rectangle operation.
- Parameters:
r – Rectangle to fill.
c – Fill color.
-
void fillRect(Rect r, const Paint &p)
Record a fill-rectangle operation using a Paint.
- Parameters:
r – Rectangle to fill.
p – Paint describing style, color, blend, opacity.
-
void fillRoundRect(Rect r, f32 rx, f32 ry, Color c)
Record a fill-rounded-rectangle operation.
- Parameters:
r – The rectangle.
rx – Corner radius in X.
ry – Corner radius in Y.
c – Fill color.
-
void fillRoundRect(Rect r, f32 rx, f32 ry, const Paint &p)
Record a fill-rounded-rectangle operation using a Paint.
- Parameters:
r – The rectangle.
rx – Corner radius in X.
ry – Corner radius in Y.
p – Paint describing style, color, blend, opacity.
-
std::unique_ptr<Recording> finish()
Finish recording and produce an immutable Recording.
- Returns:
Unique pointer to the completed Recording.
-
void reset()
Reset the recorder, discarding all accumulated operations.
-
void setTransform(const Matrix &m)
Record a set-transform operation.
- Parameters:
m – The transformation matrix.
-
void strokeCircle(f32 cx, f32 cy, f32 radius, Color c, f32 width)
Record a stroke-circle operation.
- Parameters:
cx – Center X.
cy – Center Y.
radius – Circle radius.
c – Stroke color.
width – Stroke line width.
-
void strokeCircle(f32 cx, f32 cy, f32 radius, const Paint &p)
Record a stroke-circle operation using a Paint.
- Parameters:
cx – Center X.
cy – Center Y.
radius – Circle radius.
p – Paint describing style, color, blend, opacity.
-
void strokeRect(Rect r, Color c, f32 width)
Record a stroke-rectangle operation.
- Parameters:
r – Rectangle to stroke.
c – Stroke color.
width – Stroke line width.
-
void strokeRect(Rect r, const Paint &p)
Record a stroke-rectangle operation using a Paint.
- Parameters:
r – Rectangle to stroke.
p – Paint describing style, color, blend, opacity.
-
void clearClip()
-
class Recording
- #include <recording.hpp>
Immutable command buffer containing recorded draw operations.
Created by Recorder::finish(). Operations can be traversed in original order via accept() or in sorted order via dispatch().
Public Functions
Construct a Recording from operations, arena, and images.
- Parameters:
ops – Vector of compact draw operations.
arena – Arena holding variable-length data.
images – Vector of referenced images.
-
void accept(DrawOpVisitor &visitor) const
Traverse operations in original recording order.
- Parameters:
visitor – The visitor to receive each operation.
-
inline const DrawOpArena &arena() const
Get the data arena.
-
void dispatch(DrawOpVisitor &visitor, const class DrawPass &pass) const
Dispatch operations in sorted order defined by a draw pass.
- Parameters:
visitor – The visitor to receive each operation.
pass – The draw pass defining execution order.
-
const Image *getImage(u32 index) const
Get an image by index.
- Parameters:
index – Index into the images list.
- Returns:
Pointer to the Image, or nullptr if out of range.
-
inline const std::vector<std::shared_ptr<Image>> &images() const
Get the list of referenced images.
-
inline const std::vector<CompactDrawOp> &ops() const
Get the list of recorded operations.
Private Functions
-
void dispatchOp(const CompactDrawOp &op, DrawOpVisitor &visitor) const
-
struct Rect
- #include <types.hpp>
An axis-aligned rectangle defined by position and size.
-
class Renderer
- #include <renderer.hpp>
Abstract rendering interface.
Implemented by CPU and GPU renderers to execute drawing commands. This abstraction allows Surface to work with any rendering backend through a unified interface.
Subclassed by ink::GpuContext
Public Functions
-
virtual ~Renderer() = default
-
virtual void beginFrame(Color clearColor = {0, 0, 0, 255}) = 0
Begin a new frame, clearing the render target.
- Parameters:
clearColor – The color to clear the render target to (default: opaque black).
-
virtual void endFrame() = 0
End the current frame (no GPU submission; see flush()).
-
virtual void execute(const Recording &recording, const DrawPass &pass) = 0
Execute recorded drawing commands in the order defined by a draw pass.
- Parameters:
recording – The recorded drawing commands.
pass – The draw pass defining execution order.
-
virtual std::shared_ptr<Image> makeSnapshot() const = 0
Create an immutable snapshot of the current render target contents.
- Returns:
Shared pointer to the snapshot Image.
-
virtual void resize(i32 w, i32 h) = 0
Resize the render target.
- Parameters:
w – New width in pixels.
h – New height in pixels.
-
inline virtual void setGlyphCache(GlyphCache *cache)
Set the glyph cache used for text rendering.
- Parameters:
cache – Pointer to the glyph cache (may be null to disable text).
-
virtual ~Renderer() = default
-
struct SortKey
- #include <draw_pass.hpp>
64-bit sort key for DrawOp ordering.
Layout: [63:48] clip_id, [47:40] op_type, [39:8] color_hash, [7:0] sequence.
Public Members
-
struct State
-
class Surface
- #include <surface.hpp>
Top-level rendering target.
A Surface owns a Canvas, a Device, and a Renderer. The typical frame cycle is: beginFrame() → draw via canvas() → endFrame() → flush().
Note
The caller must ensure the GL context is current when using a GPU-backed surface.
Public Functions
-
~Surface()
-
void beginFrame(Color clearColor = {0, 0, 0, 255})
Begin a new frame, clearing to the specified color.
- Parameters:
clearColor – The color to clear the render target to (default: opaque black).
-
inline Canvas *canvas() const
Get the Canvas used for drawing on this surface.
- Returns:
Pointer to the Canvas.
-
void endFrame()
End the current frame (finishes recording).
-
void flush()
Execute recorded commands and submit to the backend.
-
PixelData getPixelData() const
Get a non-owning pixel data descriptor for host integration.
- Returns:
A PixelData descriptor.
-
bool isGPU() const
Check if this is a GPU-backed surface.
- Returns:
True if GPU-backed.
-
std::shared_ptr<Image> makeSnapshot() const
Create an immutable snapshot of current surface contents.
- Returns:
Shared pointer to the snapshot Image.
-
Pixmap *peekPixels()
Direct pixel access (raster surfaces only).
- Returns:
Pointer to the underlying Pixmap, or nullptr for GPU/recording surfaces.
-
const Pixmap *peekPixels() const
Direct pixel access (raster surfaces only).
- Returns:
Pointer to the underlying Pixmap, or nullptr for GPU/recording surfaces.
-
void resize(i32 w, i32 h)
Resize the surface to new dimensions.
- Parameters:
w – New width in pixels.
h – New height in pixels.
-
void setGlyphCache(GlyphCache *cache)
Set the glyph cache used for text rendering.
- Parameters:
cache – Pointer to the glyph cache.
Public Static Functions
Create a GPU surface.
Falls back to CPU if context is null or invalid.
- Parameters:
context – Shared pointer to the GPU context.
w – Width in pixels.
h – Height in pixels.
fmt – Pixel format (default BGRA8888).
- Returns:
Unique pointer to the new Surface.
-
static std::unique_ptr<Surface> MakeRaster(i32 w, i32 h, PixelFormat fmt = PixelFormat::BGRA8888)
Create a CPU raster surface that allocates its own pixel buffer.
- Parameters:
w – Width in pixels.
h – Height in pixels.
fmt – Pixel format (default BGRA8888).
- Returns:
Unique pointer to the new Surface.
-
static std::unique_ptr<Surface> MakeRasterDirect(const PixmapInfo &info, void *pixels)
Create a CPU raster surface wrapping a caller-owned pixel buffer (zero-copy).
Private Functions
-
~Surface()
-
namespace ink
Typedefs
-
using f32 = float
32-bit floating point.
-
using f64 = double
64-bit floating point.
-
using i32 = int32_t
Signed 32-bit integer.
-
using u16 = uint16_t
Unsigned 16-bit integer.
-
using u32 = uint32_t
Unsigned 32-bit integer.
-
using u64 = uint64_t
Unsigned 64-bit integer.
-
using u8 = uint8_t
Unsigned 8-bit integer.
Enums
-
enum class BlendMode : u8
Blend mode for compositing.
Values:
-
enumerator SrcOver
-
enumerator Src
-
enumerator Dst
-
enumerator SrcIn
-
enumerator DstIn
-
enumerator SrcOut
-
enumerator DstOut
-
enumerator SrcAtop
-
enumerator DstAtop
-
enumerator Xor
-
enumerator Clear
-
enumerator SrcOver
Functions
-
inline const char *version()
Return the library version string (e.g.
“0.2.0”).
- Returns:
Null-terminated version string in “major.minor.patch” format.
-
inline int versionMajor()
Return the major version number.
- Returns:
Major version as an integer.
-
inline int versionMinor()
Return the minor version number.
- Returns:
Minor version as an integer.
-
inline int versionPatch()
Return the patch version number.
- Returns:
Patch version as an integer.
-
using f32 = float
-
namespace GpuContexts
GL-specific GpuContext factory functions.
Vulkan-specific GpuContext factory functions.
Metal-specific GpuContext factory functions.
Usage: #include <ink/gpu/gl/gl_context.hpp> auto ctx = GpuContexts::MakeGL();
Usage: #include <ink/gpu/metal/metal_context.hpp> auto ctx = GpuContexts::MakeMetal();
Usage: #include <ink/gpu/vk/vk_context.hpp> auto ctx = GpuContexts::MakeVulkan();
Functions
-
std::shared_ptr<GpuContext> MakeGL()
Create a GpuContext bound to the currently active OpenGL context.
Host must have created and made current a GL context before calling. Returns nullptr if no GL context is current or GL init fails.
-
std::shared_ptr<GpuContext> MakeMetal()
Create a GpuContext using the default Metal device.
Returns nullptr if no Metal-capable GPU is available or init fails.
-
std::shared_ptr<GpuContext> MakeVulkan()
Create a GpuContext for Vulkan.
Host must have initialized Vulkan before calling. Returns nullptr if Vulkan init fails.
TODO: Implement Vulkan backend
-
std::shared_ptr<GpuContext> MakeGL()
-
namespace std
STL namespace.
- file canvas.hpp
- #include “ink/types.hpp”#include “ink/matrix.hpp”#include “ink/paint.hpp”#include <string_view>#include <vector>#include <memory>
User-facing drawing API with state management.
- file device.hpp
- #include “ink/types.hpp”#include “ink/matrix.hpp”#include “ink/paint.hpp”#include “ink/recording.hpp”#include <memory>
Recording device that converts Canvas commands into low-level draw operations.
- file draw_op_visitor.hpp
- #include “ink/types.hpp”#include “ink/matrix.hpp”#include “ink/paint.hpp”
Visitor interface for traversing recorded draw operations.
- file draw_pass.hpp
- #include “ink/types.hpp”#include “ink/recording.hpp”#include <vector>#include <algorithm>
Sort key and draw pass for optimizing draw operation execution order.
- file glyph_cache.hpp
- #include “ink/types.hpp”#include <string_view>#include <unordered_map>#include <vector>#include <string>
Font rasterization cache with texture atlas for text rendering.
- file gl_context.hpp
- #include “ink/gpu/gpu_context.hpp”
- file gpu_context.hpp
- #include “ink/renderer.hpp”#include <memory>
GPU rendering context implementing the Renderer interface.
- file metal_context.hpp
- #include “ink/gpu/gpu_context.hpp”
- file vk_context.hpp
- #include “ink/gpu/gpu_context.hpp”
- file image.hpp
- #include “ink/types.hpp”#include “ink/pixmap.hpp”#include <memory>
Immutable image snapshot for compositing and drawing.
- file ink.hpp
- #include “ink/version.hpp”#include “ink/types.hpp”#include “ink/matrix.hpp”#include “ink/paint.hpp”#include “ink/pixmap.hpp”#include “ink/pixel_data.hpp”#include “ink/image.hpp”#include “ink/recording.hpp”#include “ink/draw_op_visitor.hpp”#include “ink/draw_pass.hpp”#include “ink/device.hpp”#include “ink/canvas.hpp”#include “ink/gpu/gpu_context.hpp”#include “ink/surface.hpp”#include “ink/glyph_cache.hpp”
Convenience header that includes the entire ink public API.
Ink - A lightweight 2D rendering library
Usage:
// CPU rendering #include <ink/ink.hpp> auto surface = ink::Surface::MakeRaster(800, 600); surface->canvas()->fillRect({0, 0, 100, 100}, {255, 0, 0, 255}); surface->flush();
// GPU rendering (requires #include <ink/gpu/gl/gl_context.hpp>) auto ctx = ink::GpuContexts::MakeGL(); auto surface = ink::Surface::MakeGpu(ctx, 800, 600); surface->canvas()->fillRect({0, 0, 100, 100}, {255, 0, 0, 255}); surface->flush();
- file matrix.hpp
- #include “ink/types.hpp”#include <algorithm>#include <cmath>
2D affine transformation matrix.
- file paint.hpp
- #include “ink/types.hpp”
- file pixel_data.hpp
- #include “ink/types.hpp”#include “ink/pixmap.hpp”#include <cstdint>
Non-owning pixel data descriptor for host integration.
- file pixmap.hpp
- #include “ink/types.hpp”#include <cstdlib>#include <cstring>
Pixel format, pixel buffer descriptor, and owning/non-owning pixel buffer.
- file recording.hpp
- #include “ink/types.hpp”#include “ink/matrix.hpp”#include “ink/paint.hpp”#include <string_view>#include <vector>#include <memory>#include <cstring>
Draw operation types, arena allocator, recording, and recorder.
- file renderer.hpp
- #include “ink/types.hpp”#include <memory>
Abstract rendering interface for CPU and GPU backends.
- file surface.hpp
- #include “ink/types.hpp”#include “ink/pixmap.hpp”#include “ink/canvas.hpp”#include “ink/device.hpp”#include “ink/pixel_data.hpp”#include “ink/image.hpp”#include “ink/renderer.hpp”#include <memory>
Top-level rendering target (CPU raster, GPU, or recording-only).
- file types.hpp
- #include <cstdint>
Core type aliases and basic geometric/color types for the ink library.
- file version.hpp
Library version information.
- dir include/ink/gpu/gl
- dir include/ink/gpu
- dir include
- dir include/ink
- dir include/ink/gpu/metal
- dir include/ink/gpu/vk