Cookies info

This website uses Google cookies to analyse traffic. Information about your use of our site is shared with Google for that purpose. See details.

Create a drawing surface

Create a drawing surface

SVG documents can be drawn on surfaces (a “rectangular” memory region made of pixels). Each pixel is a 32bit integer number, represented as a packed ARGB value (A = Most Significant Byte, B = Least Significant Byte on little endian machines). A drawing surface can be created through the svgtSurfaceCreate function:

/*
    Create a new drawing surface, specifying its dimensions in pixels.
    Specified width and height must be greater than zero; they are silently
    clamped to the value returned by the svgtSurfaceMaxDimension function.

    The user should call svgtSurfaceWidth and svgtSurfaceHeight after
    svgtSurfaceCreate in order to check real drawing surface dimensions.

    Return SVGT_INVALID_HANDLE in case of errors, else a valid drawing surface handle.
*/
SVGTHandle svgtSurfaceCreate(SVGTuint width, SVGTuint height);
/*
    Get the maximum dimension allowed for drawing surfaces.

    This is the maximum valid value that can be specified as 'width' and
    'height' for the svgtSurfaceCreate and svgtSurfaceResize functions.

    Bigger values are silently clamped to it.
*/
SVGTuint svgtSurfaceMaxDimension(void);

After a drawing surface has been created, it is possible to retrieve its dimensions (in pixels) and a pointer to its pixels using the following functions:

/*
    Get width dimension (in pixels), of the specified drawing surface.
    If the specified surface handle is not valid, 0 is returned.
*/
SVGTuint svgtSurfaceWidth(SVGTHandle surface);
/*
    Get height dimension (in pixels), of the specified drawing surface.
    If the specified surface handle is not valid, 0 is returned.
*/
SVGTuint svgtSurfaceHeight(SVGTHandle surface);
/*
    Get access to the drawing surface pixels.
    If the specified surface handle is not valid, NULL is returned.

    Please use this function to access surface pixels for read-only purposes (e.g. blit
    the surface on the screen according to the platform graphic subsystem, upload pixels
    into a GPU texture, and so on).
    
    Writing or modifying surface pixels by hand is still possible, but NOT ADVISABLE.
*/
const void* svgtSurfacePixels(SVGTHandle surface);

When it is no longer needed, a surface can be destroyed using the svgtSurfaceDestroy function:

/*
    Destroy a previously created drawing surface.

    Returns SVGT_NO_ERROR if the operation was completed successfully,
    else an error code.
*/
SVGTErrorCode svgtSurfaceDestroy(SVGTHandle surface);