SwCanvas
ThorVG_CAPI (BETA version) » Canvas

A module for rendering the graphical elements using the software engine. More...

Collaboration diagram for SwCanvas:

## Functions

TVG_EXPORT Tvg_Canvas * | tvg_swcanvas_create ()
| Creates a Canvas object. More...
TVG_EXPORT Tvg_Result | tvg_swcanvas_set_target (Tvg_Canvas *canvas, uint32_t *buffer, uint32_t stride, uint32_t w, uint32_t h, uint32_t cs)
| Sets the buffer used in the rasterization process and defines the used colorspace. More...

## Detailed Description

A module for rendering the graphical elements using the software engine.

## Function Documentation

## tvg_swcanvas_create()

TVG_EXPORT Tvg_Canvas* tvg_swcanvas_create | ( |  | ) |

Creates a Canvas object.

Tvg_Canvas *canvas = NULL;
tvg_engine_init(TVG_ENGINE_SW, 4);
canvas = tvg_swcanvas_create();
//set up the canvas buffer
uint32_t *buffer = NULL;
buffer = (uint32_t*) malloc(sizeof(uint32_t) * 100 * 100);
if (!buffer) return;
tvg_swcanvas_set_target(canvas, buffer, 100, 100, 100, TVG_COLORSPACE_ARGB8888);
//set up paints and add them into the canvas before drawing it
tvg_canvas_destroy(canvas);
tvg_engine_term(TVG_ENGINE_SW);

Returns
  A new Tvg_Canvas object.

## tvg_swcanvas_set_target()

TVG_EXPORT Tvg_Result tvg_swcanvas_set_target | ( | Tvg_Canvas * | canvas,
|  | uint32_t * | buffer,
|  | uint32_t | stride,
|  | uint32_t | w,
|  | uint32_t | h,
|  | uint32_t | cs
| ) |  |

Sets the buffer used in the rasterization process and defines the used colorspace.

For optimisation reasons TVG does not allocate memory for the output buffer on its own. The buffer of a desirable size should be allocated and owned by the caller.

Parameters

  [in] | canvas | The Tvg_Canvas object managing the `buffer`.
  [in] | buffer | A pointer to the allocated memory block of the size `stride` x `h`.
  [in] | stride | The stride of the raster image - in most cases same value as `w`.
  [in] | w | The width of the raster image.
  [in] | h | The height of the raster image.

  [in]

  cs

  The colorspace value defining the way the 32-bits colors should be read/written.
  - TVG_COLORSPACE_ABGR8888
  - TVG_COLORSPACE_ARGB8888

Returns
  Tvg_Result enumeration.

Return values

  TVG_RESULT_SUCCESS | Succeed.
  TVG_RESULT_MEMORY_CORRUPTION | Casting in the internal function implementation failed.
  TVG_RESULT_INVALID_ARGUMENTS | An invalid buffer pointer passed or one of the `stride`, `w` or `h` being zero.
  TVG_RESULT_NOT_SUPPORTED | The software engine is not supported.

See also
  TVG_COLORSPACE_ARGB8888, TVG_COLORSPACE_ABGR8888