Skip to main content

Crate skia_rs_ffi

Crate skia_rs_ffi 

Source
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 _unref functions)
  • 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 count
  • sk_*_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_recording and accepted by [sk_recording_canvas_*] — it is not interchangeable with sk_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 out with 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 acsp magic, 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_init has 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_t from 16 column-major floats.
sk_matrix44_invert
Invert a 4x4 matrix. Returns true on success; result is 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 failure result is 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 effect is null. The paint takes its own Arc reference; 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) in out_weight. Returns the verb code; SK_PATH_VERB_DONE indicates 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. intervals must be non-null with count positive entries; the pattern is duplicated internally if count is odd, matching Skia’s semantics. phase shifts 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. start and end are 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_release but must call sk_picture_recorder_finish_recording to 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 — call sk_picture_recorder_finish_recording for 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. text and font must 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.