Skip to main content

Surface (surface)

The core object of the graphics system, representing a 32-bit premultiplied ARGB pixel buffer.

Struct

struct surface_t {
int width;
int height;
int stride;
int pixlen;
void * pixels;
struct g2d_t * g2d;
struct cg_render_t * cg;
void * priv;
};

Creation & Loading

FunctionDescription
surface_alloc(width, height)Create a blank Surface
surface_alloc_from_xfs(ctx, filename)Load image from XFS
surface_alloc_from_buf(buf, len)Load from memory buffer
surface_alloc_qrcode(pixsz, fmt, ...)Generate QR code Surface
surface_free(s)Free Surface
surface_clone(s, x, y, w, h)Clone sub-region
surface_extend(s, w, h, type)Extend dimensions

Basic Operations

FunctionDescription
surface_clear(s, c, x, y, w, h)Clear region
surface_set_pixel(s, x, y, c)Set pixel
surface_get_pixel(s, x, y, c)Get pixel
surface_blit(s, clip, m, o)Bit block transfer (with clipping and matrix transform)
surface_fill(s, clip, m, w, h, c)Fill rectangle
surface_text(s, clip, x, y, wrap, family, style, size, c, fmt, ...)Render text
surface_icon(s, clip, x, y, family, size, code, c)Render icon glyph

Property Access

FunctionDescription
surface_get_width(s)Get width
surface_get_height(s)Get height
surface_get_stride(s)Get stride
surface_get_pixels(s)Get pixel pointer
surface_get_pixlen(s)Get pixel data length

CG Integration

FunctionDescription
surface_get_cg_surface(s)Get associated cg_surface_t (lazy init)
surface_get_cg_ctx(s)Get associated cg_ctx_t (lazy init)

The cg context enables vector drawing (paths, fills, strokes, gradients, etc.), see the Vector Graphics docs. surface_blit() and surface_fill() automatically fall back to cg rendering when G2D hardware acceleration is unavailable.