Expand description
C FFI bindings for skia-rs.
This crate provides C-compatible bindings for use from other languages. It exposes a C API that mirrors the Skia C API for drop-in compatibility.
§Safety
All FFI functions are inherently unsafe. Callers must ensure:
- Pointers are valid and non-null (unless explicitly documented otherwise)
- Proper lifetime management (using the appropriate
_unreffunctions) - Thread safety requirements are followed (see below)
Every exported sk_* function wraps its body in catch_panic /
catch_panic_void so that a Rust panic can never unwind into C. If a
panic is caught the function returns a default value (null pointer, zero,
false, identity matrix, etc.) and sets a thread-visible flag readable
via sk_last_call_panicked.
§Reference Counting
Objects follow Skia’s reference counting model:
- Objects are created with a reference count of 1
sk_*_ref()increments the reference countsk_*_unref()decrements the reference count and frees when it reaches 0- Use
sk_refcnt_get_count()to query the current count
Reference counting operations (ref/unref) are thread-safe and use
atomic operations internally. The generic sk_refcnt_get_count /
sk_refcnt_is_unique entry points perform a magic-tag check before
reading the refcount field, so passing a non-refcounted pointer returns 0
instead of reading arbitrary memory.
§ABI Initialization
Callers must invoke sk_init once at startup, passing the major /
minor version the client was compiled against. sk_init returns false
if the versions are incompatible; the caller should then abort rather
than calling any other sk_* function.
Modules§
- abi
- Binary ABI Compatibility Layer
Structs§
- RefCounted
- Reference counted wrapper for FFI objects.
- sk_
canvas_ t - Opaque canvas handle.
- sk_
color4f_ t - C-compatible 4-component color (float RGBA).
- sk_
imageinfo_ t - C-compatible image info structure.
- sk_
ipoint_ t - C-compatible integer point structure.
- sk_
irect_ t - C-compatible integer rectangle structure.
- sk_
isize_ t - C-compatible integer size structure.
- sk_
matrix44_ t - C-compatible 4x4 matrix structure (column-major).
- sk_
matrix_ t - C-compatible matrix structure.
- sk_
path_ iter_ t - Stateful iterator over a path’s verbs.
- sk_
picture_ recorder_ t - Opaque picture recorder. Not reference counted — single ownership.
- sk_
point_ t - C-compatible point structure.
- sk_
recording_ canvas_ t - Recording canvas handle. Returned by
sk_picture_recorder_begin_recordingand accepted by [sk_recording_canvas_*] — it is not interchangeable withsk_canvas_t(which is raster-backed). - sk_
rect_ t - C-compatible rectangle structure.
- sk_
size_ t - C-compatible size structure.
Enums§
- sk_
clip_ op_ t - Clip operation for canvas clipping functions.
- sk_
region_ op_ t - Region operation for region manipulation functions.
- sk_
trim_ mode_ t - Trim path effect mode.
Constants§
- SK_
PATH_ VERB_ CLOSE - ABI-stable verb code for a contour close.
- SK_
PATH_ VERB_ CONIC - ABI-stable verb code for a conic section.
- SK_
PATH_ VERB_ CUBIC - ABI-stable verb code for a cubic bezier.
- SK_
PATH_ VERB_ DONE - Sentinel verb code returned once the iterator is exhausted.
- SK_
PATH_ VERB_ LINE - ABI-stable verb code for a line segment.
- SK_
PATH_ VERB_ MOVE - ABI-stable verb codes emitted by
sk_path_iter_next. - SK_
PATH_ VERB_ QUAD - ABI-stable verb code for a quadratic bezier.
Functions§
- sk_
canvas_ ⚠clear - Clear the canvas with a color.
- sk_
canvas_ ⚠clip_ path - Intersect or subtract a path from the clip.
- sk_
canvas_ ⚠clip_ rect - Intersect or subtract a rectangle from the clip.
- sk_
canvas_ ⚠concat - Concatenate a matrix onto the canvas’s current transform.
- sk_
canvas_ ⚠draw_ path - Draw a path on the canvas, honoring the canvas’s current transform and clip stack.
- sk_
canvas_ ⚠draw_ rect - Draw a rect on the canvas, honoring the canvas’s current transform and clip stack.
- sk_
canvas_ ⚠draw_ text_ blob - Draw a text blob on a canvas at
(x, y). - sk_
canvas_ ⚠get_ clip_ ibounds - Fill
outwith the device-space integer clip bounds of this canvas. - sk_
canvas_ ⚠get_ height - Get the height of the canvas.
- sk_
canvas_ ⚠get_ width - Get the width of the canvas.
- sk_
canvas_ ⚠release - Release a canvas acquired via
sk_surface_lock_canvas. - sk_
canvas_ ⚠restore - Restore the most recently saved matrix and clip.
- sk_
canvas_ ⚠rotate - Rotate the canvas coordinate system (degrees).
- sk_
canvas_ ⚠save - Save the current transformation matrix and clip stack.
- sk_
canvas_ ⚠save_ layer - Save a layer — pushes a save frame that records the layer bounds and paint for composition on restore.
- sk_
canvas_ ⚠scale - Scale the canvas coordinate system.
- sk_
canvas_ ⚠translate - Translate the canvas coordinate system.
- sk_
colorfilter_ ⚠new_ identity - Create an identity color-matrix filter.
- sk_
colorfilter_ ⚠new_ matrix - Create a color-matrix filter from 20 floats (row-major 4x5).
- sk_
colorfilter_ ⚠new_ saturation - Create a saturation color filter (1.0 = identity, 0.0 = grayscale).
- sk_
colorfilter_ ⚠ref - Increment color filter refcount.
- sk_
colorfilter_ ⚠unref - Decrement color filter refcount.
- sk_
colorspace_ ⚠from_ icc - Parse a color space from a raw ICC profile byte buffer. Returns null on
failure (malformed profile, missing
acspmagic, etc.). - sk_
colorspace_ ⚠is_ linear - Return true if this color space has a linear transfer function.
- sk_
colorspace_ ⚠is_ srgb - Return true if this color space is sRGB.
- sk_
colorspace_ ⚠new_ display_ p3 - Create a new Display P3 color space.
- sk_
colorspace_ ⚠new_ srgb - Create a new sRGB color space.
- sk_
colorspace_ ⚠new_ srgb_ linear - Create a new linear sRGB color space.
- sk_
colorspace_ ⚠ref - Increment color space refcount.
- sk_
colorspace_ ⚠unref - Decrement color space refcount.
- sk_
font_ ⚠get_ size - Get font size.
- sk_
font_ ⚠measure_ text - Measure a UTF-8 text string at the font’s current size. Returns the advance width in pixels; negative return indicates an invalid font or invalid UTF-8.
- sk_
font_ ⚠new - Create a font from a typeface and size.
- sk_
font_ ⚠ref - Increment font refcount.
- sk_
font_ ⚠unref - Decrement font refcount.
- sk_
image_ ⚠encode_ png - Encode an image as PNG into a caller-allocated buffer.
- sk_
image_ ⚠from_ color - Create an image filled with a single color.
- sk_
image_ ⚠from_ encoded - Decode an encoded image (PNG/JPEG/…) from a byte buffer.
- sk_
image_ ⚠get_ height - Get the image height.
- sk_
image_ ⚠get_ refcnt - Get the reference count of an image.
- sk_
image_ ⚠get_ width - Get the image width.
- sk_
image_ ⚠ref - Increment the reference count of an image.
- sk_
image_ ⚠unref - Decrement the reference count of an image.
- sk_
imagefilter_ ⚠new_ blur - Create a Gaussian blur image filter.
- sk_
imagefilter_ ⚠ref - Increment image filter refcount.
- sk_
imagefilter_ ⚠unref - Decrement image filter refcount.
- sk_init
- Initialize the library and verify ABI compatibility.
- sk_
is_ ⚠available - Check if the library is available.
- sk_
is_ initialized - Check whether
sk_inithas been called successfully. - sk_
last_ call_ panicked - Check if the last FFI call panicked.
- sk_
maskfilter_ ⚠new_ blur - Create a blur mask filter with the given sigma (pixels).
- sk_
maskfilter_ ⚠ref - Increment mask filter refcount.
- sk_
maskfilter_ ⚠unref - Decrement mask filter refcount.
- sk_
matrix44_ ⚠concat - Concatenate two 4x4 matrices:
result = a * b. - sk_
matrix44_ ⚠determinant - Return the determinant of the matrix.
- sk_
matrix44_ ⚠from_ array - Construct a
sk_matrix44_tfrom 16 column-major floats. - sk_
matrix44_ ⚠invert - Invert a 4x4 matrix. Returns true on success;
resultis unchanged if the matrix is singular. - sk_
matrix44_ ⚠is_ identity - Return true if the matrix is the identity matrix.
- sk_
matrix44_ ⚠map_ point - Map a 2D point through a 4x4 matrix (projects through W).
- sk_
matrix44_ ⚠new - Create an identity
sk_matrix44_t. - sk_
matrix_ ⚠concat - Concatenate two matrices.
- sk_
matrix_ ⚠determinant - Return the determinant of the matrix.
- sk_
matrix_ ⚠invert - Invert a matrix into
result. Returns true on success, false if the matrix is singular (non-invertible); on failureresultis unchanged. - sk_
matrix_ ⚠is_ identity - Return true if the matrix is the identity.
- sk_
matrix_ ⚠map_ point - Map a point through a matrix.
- sk_
matrix_ ⚠set_ identity - Set matrix to identity.
- sk_
matrix_ ⚠set_ rotate - Set matrix to rotate (degrees).
- sk_
matrix_ ⚠set_ scale - Set matrix to scale.
- sk_
matrix_ ⚠set_ translate - Set matrix to translate.
- sk_
paint_ ⚠clone - Clone a paint.
- sk_
paint_ ⚠delete - Decrement the reference count of a paint (alias for unref).
- sk_
paint_ ⚠get_ color - Get the paint color.
- sk_
paint_ ⚠get_ color4f - Get the paint color as float RGBA.
- sk_
paint_ ⚠get_ refcnt - Get the reference count of a paint.
- sk_
paint_ ⚠get_ stroke_ width - Get the stroke width.
- sk_
paint_ ⚠is_ antialias - Check if anti-alias is enabled.
- sk_
paint_ ⚠new - Create a new paint.
- sk_
paint_ ⚠ref - Increment the reference count of a paint.
- sk_
paint_ ⚠set_ antialias - Set anti-alias.
- sk_
paint_ ⚠set_ blend_ mode - Set the paint’s blend mode (matches
abi::SkBlendModeABI). - sk_
paint_ ⚠set_ color - Set the paint color.
- sk_
paint_ ⚠set_ color4f - Set the paint color as float RGBA.
- sk_
paint_ ⚠set_ color_ filter - Attach a color filter to the paint. Passing null clears it.
- sk_
paint_ ⚠set_ image_ filter - Attach an image filter to the paint. Passing null clears it.
- sk_
paint_ ⚠set_ mask_ filter - Attach a mask filter to the paint. Passing null clears it.
- sk_
paint_ ⚠set_ path_ effect - Attach a path effect to a paint, or clear it if
effectis null. The paint takes its ownArcreference; the caller retains their own. - sk_
paint_ ⚠set_ shader - Attach a shader to the paint. Passing null clears it.
- sk_
paint_ ⚠set_ stroke_ width - Set the stroke width.
- sk_
paint_ ⚠set_ style - Set the paint style.
- sk_
paint_ ⚠unref - Decrement the reference count of a paint.
- sk_
path_ ⚠clone - Clone a path.
- sk_
path_ ⚠contains - Check if path contains a point.
- sk_
path_ ⚠delete - Decrement the reference count of a path (alias for unref).
- sk_
path_ ⚠get_ bounds - Get the path bounds.
- sk_
path_ ⚠get_ filltype - Get the fill type.
- sk_
path_ ⚠get_ refcnt - Get the reference count of a path.
- sk_
path_ ⚠is_ empty - Check if path is empty.
- sk_
path_ ⚠iter_ delete - Destroy a path iterator.
- sk_
path_ ⚠iter_ new - Create an iterator over a path’s verbs.
- sk_
path_ ⚠iter_ next - Advance the iterator. Fills up to four points in
out_points(caller provides at least 4 slots) and the conic weight (if applicable) inout_weight. Returns the verb code;SK_PATH_VERB_DONEindicates exhaustion. - sk_
path_ ⚠new - Create a new path.
- sk_
path_ ⚠ref - Increment the reference count of a path.
- sk_
path_ ⚠set_ filltype - Set the fill type.
- sk_
path_ ⚠unref - Decrement the reference count of a path.
- sk_
pathbuilder_ ⚠add_ circle - Add a circle.
- sk_
pathbuilder_ ⚠add_ oval - Add an oval.
- sk_
pathbuilder_ ⚠add_ rect - Add a rectangle.
- sk_
pathbuilder_ ⚠close - Close the path.
- sk_
pathbuilder_ ⚠cubic_ to - Cubic bezier to a point.
- sk_
pathbuilder_ ⚠delete - Decrement the reference count of a path builder (alias for unref).
- sk_
pathbuilder_ ⚠detach - Build the path and reset the builder.
- sk_
pathbuilder_ ⚠line_ to - Line to a point.
- sk_
pathbuilder_ ⚠move_ to - Move to a point.
- sk_
pathbuilder_ ⚠new - Create a new path builder.
- sk_
pathbuilder_ ⚠quad_ to - Quadratic bezier to a point.
- sk_
pathbuilder_ ⚠ref - Increment the reference count of a path builder.
- sk_
pathbuilder_ ⚠snapshot - Build the path without resetting the builder.
- sk_
pathbuilder_ ⚠unref - Decrement the reference count of a path builder.
- sk_
patheffect_ ⚠new_ dash - Create a dash path effect.
intervalsmust be non-null withcountpositive entries; the pattern is duplicated internally ifcountis odd, matching Skia’s semantics.phaseshifts where the pattern starts. Returns null if the intervals are invalid (empty, negative, or sum to 0). - sk_
patheffect_ ⚠new_ trim - Create a trim path effect.
startandendare normalized lengths in [0, 1]. - sk_
patheffect_ ⚠ref - Increment path effect refcount.
- sk_
patheffect_ ⚠unref - Decrement path effect refcount.
- sk_
picture_ ⚠approximate_ op_ count - Get the approximate operation count of a picture.
- sk_
picture_ ⚠get_ cull_ rect - Get the picture’s cull rect.
- sk_
picture_ ⚠playback - Play a recorded picture back onto a raster canvas.
- sk_
picture_ ⚠recorder_ begin_ recording - Begin recording into a fresh picture. Returns a recording canvas handle
that draw ops append to. The caller drops the handle via
sk_recording_canvas_releasebut must callsk_picture_recorder_finish_recordingto get the recorded picture. - sk_
picture_ ⚠recorder_ delete - Destroy a picture recorder.
- sk_
picture_ ⚠recorder_ finish_ recording - Finish recording and return the captured picture. Returns null if the
recorder was not recording. After this call the recorder can be reused
with another
sk_picture_recorder_begin_recording. - sk_
picture_ ⚠recorder_ new - Create a new picture recorder.
- sk_
picture_ ⚠ref - Increment picture refcount.
- sk_
picture_ ⚠unref - Decrement picture refcount.
- sk_
recording_ ⚠canvas_ draw_ path - Draw a path into the recording canvas.
- sk_
recording_ ⚠canvas_ draw_ rect - Draw a rect into the recording canvas. The rect is captured in the caller-space coordinates (post-transform) so playback can place it on any target canvas.
- sk_
recording_ ⚠canvas_ release - Release a recording canvas handle acquired via
sk_picture_recorder_begin_recording. Does not finalize the recording — callsk_picture_recorder_finish_recordingfor that. - sk_
recording_ ⚠canvas_ restore - Pop a save on the recording canvas’s state.
- sk_
recording_ ⚠canvas_ save - Push a save onto the recording canvas’s state.
- sk_
recording_ ⚠canvas_ translate - Translate the recording canvas’s current transform.
- sk_
refcnt_ ⚠get_ count - Get the reference count of an object.
- sk_
refcnt_ ⚠is_ unique - Check if an object has only one reference (is unique).
- sk_
region_ ⚠contains - Return true if the region contains a point.
- sk_
region_ ⚠get_ bounds - Get the region’s integer bounds.
- sk_
region_ ⚠is_ empty - Return true if the region is empty.
- sk_
region_ ⚠new - Create a new, empty region.
- sk_
region_ ⚠op_ rect - Apply a rect op on the region.
- sk_
region_ ⚠ref - Increment region refcount.
- sk_
region_ ⚠set_ rect - Set the region to a single integer rectangle. Returns true if the rect was non-empty (the region now holds it), false if empty (the region is cleared).
- sk_
region_ ⚠unref - Decrement region refcount.
- sk_
shader_ ⚠get_ refcnt - Get shader refcount.
- sk_
shader_ ⚠new_ linear_ gradient - Create a linear gradient shader.
- sk_
shader_ ⚠new_ radial_ gradient - Create a radial gradient shader.
- sk_
shader_ ⚠new_ sweep_ gradient - Create a sweep gradient shader.
- sk_
shader_ ⚠ref - Increment shader refcount.
- sk_
shader_ ⚠unref - Decrement shader refcount.
- sk_
surface_ ⚠clear - Clear a surface with a color.
- sk_
surface_ ⚠draw_ circle - Draw a circle on a surface.
- sk_
surface_ ⚠draw_ line - Draw a line on a surface.
- sk_
surface_ ⚠draw_ path - Draw a path on a surface.
- sk_
surface_ ⚠draw_ rect - Draw a rect on a surface.
- sk_
surface_ ⚠get_ height - Get the height of a surface.
- sk_
surface_ ⚠get_ refcnt - Get the reference count of a surface.
- sk_
surface_ ⚠get_ width - Get the width of a surface.
- sk_
surface_ ⚠is_ unique - Check if the surface has only one reference.
- sk_
surface_ ⚠lock_ canvas - Acquire a canvas borrowed from the given surface.
- sk_
surface_ ⚠new_ raster - Create a new raster surface.
- sk_
surface_ ⚠new_ raster_ with_ info - Create a raster surface with specific image info.
- sk_
surface_ ⚠peek_ pixels - Get the pixel data from a surface (unsynchronized borrow).
- sk_
surface_ ⚠read_ pixels - Copy the pixel data from a surface into a caller-owned buffer.
- sk_
surface_ ⚠ref - Increment the reference count of a surface.
- sk_
surface_ ⚠unref - Decrement the reference count of a surface.
- sk_
textblob_ ⚠get_ bounds - Get text blob bounds.
- sk_
textblob_ ⚠make_ from_ text - Build a text blob from a NUL-terminated UTF-8 string.
textandfontmust be valid, non-null pointers; returns null otherwise. - sk_
textblob_ ⚠ref - Increment text blob refcount.
- sk_
textblob_ ⚠unref - Decrement text blob refcount.
- sk_
typeface_ ⚠default - Create the default typeface.
- sk_
typeface_ ⚠from_ data - Load a typeface from raw font file data (TTF/OTF).
- sk_
typeface_ ⚠get_ refcnt - Get typeface refcount.
- sk_
typeface_ ⚠glyph_ count - Get the typeface’s glyph count.
- sk_
typeface_ ⚠ref - Increment typeface refcount.
- sk_
typeface_ ⚠units_ per_ em - Get the typeface’s units-per-em.
- sk_
typeface_ ⚠unref - Decrement typeface refcount.
- sk_
version ⚠ - Get the library version as a NUL-terminated static string.
Type Aliases§
- sk_
color_ t - C-compatible color (ARGB packed).
- sk_
colorfilter_ t - Reference counted color filter.
- sk_
colorspace_ t - Reference counted
ColorSpace. - sk_
font_ t - Reference counted font type (typeface + size + options).
- sk_
image_ t - Reference counted image type.
- sk_
imagefilter_ t - Reference counted image filter.
- sk_
maskfilter_ t - Reference counted mask filter.
- sk_
paint_ t - Reference counted paint type.
- sk_
path_ t - Reference counted path type.
- sk_
pathbuilder_ t - Reference counted path builder type.
- sk_
patheffect_ t - Reference counted
PathEffectRef. - sk_
picture_ t - Reference counted [
Picture]. - sk_
refcnt_ t - Opaque reference counted object type.
- sk_
region_ t - Reference counted
Region. - sk_
shader_ t - Reference counted shader type.
- sk_
surface_ t - Reference counted surface type.
- sk_
textblob_ t - Reference counted
TextBlob. - sk_
typeface_ t - Reference counted typeface type.