* Copyright (c) 2021 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
* @addtogroup Display
* @{
*
* @brief Defines driver functions of the display module.
*
* This module provides driver functions for the graphics subsystem, including graphics layer management,
* device control, graphics hardware acceleration, display memory management, and callbacks.
*
* @since 3.0
*/
* @file display_vgu.h
*
* @brief Declares the driver functions for implementing 2D vector hardware acceleration.
*
* @since 3.0
*/
#ifndef DISPLAY_VGU_H
#define DISPLAY_VGU_H
#include "display_type.h"
#ifdef __cplusplus
extern "C" {
#endif
#undef HDI_VGU_SCALAR_IS_FLOAT
#define HDI_VGU_SCALAR_IS_FLOAT 1
#ifdef HDI_VGU_SCALAR_IS_FLOAT
typedef float VGUScalar;
#else
typedef int32_t VGUScalar;
#endif
typedef PixelFormat VGUPixelFormat;
typedef BlendType VGUBlendType;
* @brief Enumerates data types of paths.
*
*/
typedef enum {
VGU_DATA_TYPE_S16 = 0,
VGU_DATA_TYPE_S32,
VGU_DATA_TYPE_F32
} VGUPathDataType;
* @brief Enumerates supported hardware acceleration capabilities.
*
*/
typedef enum {
VGU_CAP_BLIT = (1 << 0),
VGU_CAP_BLIT_NUM = (1 << 1),
VGU_CAP_PATH = (1 << 2),
VGU_CAP_FILTER_BLUR = (1 << 3),
} VGUCapability;
* @brief Enumerates result codes that may return.
*
*/
typedef enum {
VGU_SUCCESS = 0,
VGU_NO_SUPPORT = -1,
VGU_OPERATION_FAILED = -2,
VGU_OUT_OF_MEMORY = -3,
VGU_TIMEOUT = -4,
VGU_INVALID_PARAMETER = -5,
VGU_BUSY = -6,
VGU_NO_CONTEXT = -7,
} VGUResult;
* @brief Enumerates styles for the endpoints of a stroked line.
*
*/
typedef enum {
VGU_LINECAP_BUTT = 0,
VGU_LINECAP_ROUND,
VGU_LINECAP_SQUARE
} VGULineCap;
* @brief Enumerates join types for stroked lines.
*
*/
typedef enum {
VGU_LINE_JOIN_MITER = 0,
VGU_LINE_JOIN_ROUND,
VGU_LINE_JOIN_BEVEL,
VGU_LINE_JOIN_BUTT
} VGUJointType;
* @brief Defines the coordinates of a point.
*
*/
typedef struct {
VGUScalar x;
VGUScalar y;
} VGUPoint;
* @brief Defines a rectangle.
*
*/
typedef struct {
VGUScalar x;
VGUScalar y;
VGUScalar w;
VGUScalar h;
} VGURect;
* @brief Enumerates filter types for rendering an image.
*
*/
typedef enum {
VGU_FILTER_BILINEAR = 0,
VGU_FILTER_NEAREST,
VGU_FILTER_LINEAR,
VGU_FILTER_BUTT
} VGUFilter;
* @brief Enumerates fill rules for graphics.
*
*/
typedef enum {
VGU_RULE_WINDING = 0,
VGU_RULE_EVEN_ODD,
VGU_RULE_BUTT
} VGUFillRule;
* @brief Enumerates fill types of the outside of the gradient area.
*
*/
typedef enum {
VGU_SPREAD_PAD = 0,
VGU_SPREAD_REFLECT,
VGU_SPREAD_REPEAT,
VGU_SPREAD_BUTT
} VGUFillSpread;
* @brief Enumerates wrap types of a pattern.
*
*/
typedef enum {
VGU_WRAP_REFLECT = 0,
VGU_WRAP_REPEAT,
VGU_WRAP_BUTT
} VGUWrapType;
* @brief Enumerates commands for drawing a path.
*
*/
typedef enum {
VGU_PATH_CMD_CLOSE = 0,
VGU_PATH_CMD_MOVE,
VGU_PATH_CMD_LINE,
VGU_PATH_CMD_HLINE,
VGU_PATH_CMD_VLINE,
VGU_PATH_CMD_QUAD,
VGU_PATH_CMD_CUBIC,
VGU_PATH_CMD_SQUAD,
VGU_PATH_CMD_SCUBIC,
VGU_PATH_CMD_BUTT,
} VGUPathCmd;
* @brief Defines a path object, which stores path-related commands and coordinates.
*
*/
typedef struct {
uint8_t *segment;
int32_t numSegments;
uint8_t *data;
VGUPathDataType type;
bool enAlias;
VGURect boundBox;
} VGUPath;
* @brief Enumerates transform types.
*
*/
typedef enum {
VGU_TRANSFORM_TRANSLATE = (1 << 0),
VGU_TRANSFORM_SCALE = (1 << 1),
VGU_TRANSFORM_ROTATE_90 = (1 << 2),
VGU_TRANSFORM_ROTATE_180 = (1 << 3),
VGU_TRANSFORM_ROTATE_270 = (1 << 4),
VGU_TRANSFORM_OTHER = (1 << 16)
} VGUTransformType;
* @brief Defines a transformation matrix.
*
*/
typedef struct {
float m[3][3];
uint32_t type;
} VGUMatrix3;
* @brief Stores bitmap information for hardware acceleration.
*
*/
typedef struct {
VGUPixelFormat pixelFormat;
uint32_t width;
uint32_t height;
uint32_t stride;
void *virAddr;
uint64_t phyAddr;
} VGUBuffer;
* @brief Enumerates clip types of a surface.
*
*/
typedef enum {
VGU_CLIP_RECT = 0,
VGU_CLIP_PATH,
VGU_CLIP_BUTT
} VGUClipType;
* @brief Defines a mask layer.
*
*/
typedef struct {
VGUBuffer *buffer;
VGURect *rect;
} VGUMaskLayer;
* @brief Stores surface information for 2D hardware acceleration.
*
*/
typedef struct {
VGUBuffer *buffer;
union {
VGURect *clipRect;
VGUPath *clipPath;
};
VGUClipType clipType;
VGUMaskLayer *mask;
VGUBlendType blend;
VGUFilter filter;
} VGUSurface;
* @brief Defines how the colors are distributed along the gradient.
*
*/
typedef struct {
float stop;
uint32_t color;
} VGUColorStop;
* @brief Defines a linear gradient.
*
*/
typedef struct {
VGUScalar x1;
VGUScalar y1;
VGUScalar x2;
VGUScalar y2;
} VGULinear;
* @brief Defines a radial gradient.
*
*/
typedef struct {
VGUScalar x0;
VGUScalar y0;
VGUScalar r0;
VGUScalar x1;
VGUScalar y1;
VGUScalar r1;
} VGURadial;
* @brief Defines a conic gradient.
*
*/
typedef struct {
VGUScalar cx;
VGUScalar cy;
} VGUConic;
* @brief Defines an image.
*
*/
typedef struct {
VGUBuffer *buffer;
VGUMatrix3 *matrix;
VGURect *rect;
uint8_t opacity;
} VGUImage;
* @brief Defines an image pattern.
*
*/
typedef struct {
VGUImage *image;
VGUWrapType wrapx;
VGUWrapType wrapy;
} VGUPattern;
* @brief Enumerates gradient types.
*
*/
typedef enum {
VGU_GRADIENT_LINEAR = 0,
VGU_GRADIENT_RADIAL,
VGU_GRADIENT_CONIC,
VGU_GRADIENT_BUTT
} VGUGradientType;
* @brief Defines a gradient object.
*
*/
typedef struct {
VGUMatrix3 *matrix;
VGUColorStop *colorStops;
uint16_t stopCount;
union {
VGULinear linear;
VGURadial radial;
VGUConic conic;
};
VGUGradientType type;
VGUFillSpread spread;
uint8_t opacity;
} VGUGradient;
* @brief Defines a solid color.
*
*/
typedef struct {
uint32_t color;
uint8_t opacity;
} VGUSolid;
* @brief Enumerates paint types.
*
*/
typedef enum {
VGU_PAINT_SOLID = 0,
VGU_PAINT_GRADIENT,
VGU_PAINT_PATTERN,
VGU_PAINT_BUTT
} VGUPaintType;
* @brief Defines the paint style when filling or stroking a path.
*
*/
typedef struct {
union {
VGUGradient *gradient;
VGUPattern *pattern;
VGUSolid *solid;
};
VGUPaintType type;
} VGUPaintStyle;
* @brief Defines path filling attributes.
*
*/
typedef struct {
VGUFillRule rule;
} VGUFillAttr;
* @brief Defines path stroking attributes.
*
*/
typedef struct {
VGULineCap cap;
VGUJointType join;
float miterLimit;
float width;
} VGUStrokeAttr;
* @brief Defines driver functions for 2D hardware acceleration.
*/
typedef struct {
* @brief Initializes hardware acceleration.
*
* @return Returns <b>VGU_SUCCESS</b> if the operation is successful; returns an error code defined in
* {@link VGUResult} otherwise.
* @see DeinitVgu
* @since 3.0
*/
VGUResult (*InitVgu)(void);
* @brief Deinitializes hardware acceleration.
*
* @return Returns <b>VGU_SUCCESS</b> if the operation is successful; returns an error code defined in
* {@link VGUResult} otherwise.
* @see InitVgu
* @since 3.0
*/
VGUResult (*DeinitVgu)(void);
* @brief Queries hardware acceleration capabilities.
*
* @param cap Indicates the capabilities to query, which are defined by <b>VGUCapability</b>.
*
* @return Returns a value greater than or equal to 0 if the operation is successful; returns an error code defined
* in {@link VGUResult} otherwise.
* @since 3.0
*/
int32_t (*QueryCapability)(uint32_t cap);
* @brief Fills the given path with a specified paint style.
*
* @param target Indicates the pointer to the target surface.
* @param path Indicates the pointer to the path object.
* @param matrix Indicates the pointer to the transformation matrix object. If this parameter is null,
* the identity matrix is used by default.
* @param attr Indicates the pointer to the path filling attributes.
* @param style Indicates the pointer to the paint style to use.
*
* @return Returns <b>VGU_SUCCESS</b> if the operation is successful; returns an error code defined in
* {@link VGUResult} otherwise.
* @since 3.0
*/
VGUResult (*RenderFill)(VGUSurface *target, const VGUPath *path, const VGUMatrix3 *matrix, const VGUFillAttr *attr,
const VGUPaintStyle *style);
* @brief Strokes the given path with a specified paint style.
*
* @param target Indicates the pointer to the target surface.
* @param path Indicates the pointer to the path object.
* @param matrix Indicates the pointer to the transformation matrix object. If this parameter is null,
* the identity matrix is used by default.
* @param attr Indicates the pointer to the path stroking attributes.
* @param style Indicates the pointer to the paint style to use.
*
* @return Returns <b>VGU_SUCCESS</b> if the operation is successful; returns an error code defined in
* {@link VGUResult} otherwise.
* @since 3.0
*/
VGUResult (*RenderStroke)(VGUSurface *target, const VGUPath *path, const VGUMatrix3 *matrix,
const VGUStrokeAttr *attr, const VGUPaintStyle *style);
* @brief Blurs a specified surface.
*
* @param target Indicates the pointer to the target surface.
* @param blur Indicates the blur radius.
*
* @return Returns <b>VGU_SUCCESS</b> if the operation is successful; returns an error code defined in
* {@link VGUResult} otherwise.
* @since 3.0
*/
VGUResult (*RenderBlur)(VGUSurface *target, uint16_t blur);
* @brief Blits an image to the target surface.
*
* During bit blit, color space conversion (CSC) and transformation can be implemented.
*
* @param target Indicates the pointer to the target surface.
* @param src Indicates the pointer to the source image.
* @param color Indicates the color for blending. If this parameter is <b>0</b>, color blending is not performed.
*
* @return Returns <b>VGU_SUCCESS</b> if the operation is successful; returns an error code defined in
* {@link VGUResult} otherwise.
* @since 3.0
*/
VGUResult (*RenderBlit)(VGUSurface *target, const VGUImage *src, uint32_t color);
* @brief Blits multiple images to the target surface.
*
* During bit blit, color space conversion (CSC) and transformation can be implemented. You can use this
* function to combine multiple source images to the target surface.
* To query the maximum number of source images allowed, call the <b>QueryCapability<b/> function.
*
* @param target Indicates the pointer to the target surface.
* @param src Indicates the pointer to the array of source images.
* @param count Indicates the number of source images.
* @param color Indicates the color for blending. If this parameter is <b>0</b>, color blending is not performed.
*
* @return Returns <b>VGU_SUCCESS</b> if the operation is successful; returns an error code defined in
* {@link VGUResult} otherwise.
* @since 3.0
*/
VGUResult (*RenderBlitN)(VGUSurface *target, const VGUImage *src, uint16_t count, uint32_t color);
* @brief Clears a rectangle with a given color on the target surface.
*
* @param target Indicates the pointer to the target surface.
* @param rect Indicates the pointer to the rectangle to clear. If this parameter is null, the entire surface
* will be cleared.
* @param color Indicates the color to fill.
* @param opacity Indicates the opacity to set.
*
* @return Returns <b>VGU_SUCCESS</b> if the operation is successful; returns an error code defined in
* {@link VGUResult} otherwise.
* @since 3.0
*/
VGUResult (*RenderClearRect)(VGUSurface *target, const VGURect *rect, uint32_t color, uint8_t opacity);
* @brief Disables hardware acceleration for rendering.
*
* @return Returns <b>VGU_SUCCESS</b> if the operation is successful; returns an error code defined in
* {@link VGUResult} otherwise.
* @since 3.0
*/
VGUResult (*RenderCancel)();
* @brief Synchronizes hardware acceleration when it is used to draw and blit bitmaps.
*
* This function blocks the process until hardware acceleration is complete.
*
* @param timeOut Indicates the timeout duration for hardware acceleration synchronization.
* The value <b>0</b> indicates no timeout, so the process keeps waiting until hardware acceleration is complete.
*
* @return Returns <b>VGU_SUCCESS</b> if the operation is successful; returns an error code defined in
* {@link VGUResult} otherwise.
* @since 3.0
*/
VGUResult (*RenderSync)(int32_t timeOut);
} VGUFuncs;
* @brief Initializes a path object.
*
* @param path Indicates the pointer to the path object.
* @param type Indicates the data type of the path.
* @param segments Indicates the pointer to the path commands.
* @param numSegments Indicates the total number of path commands.
* @param data Indicates the pointer to the coordinate data used in the path commands.
* @param enAlias Specifies whether to enable anti-aliasing.
* @param boundBox Indicates the bounding box of the path.
*
* @return Returns <b>VGU_SUCCESS</b> if the operation is successful; returns an error code defined in
* {@link VGUResult} otherwise.
* @since 3.0
*/
VGUResult VGUPathInit(VGUPath *path, VGUPathDataType type, const uint8_t* segments, int numSegments,
const uint8_t *data, bool enAlias, VGURect boundBox);
* @brief Adds a subpath to a specified path.
*
* @param path Indicates the pointer to the path object.
* @param subpath Indicates the pointer to the subpath object.
*
* @return Returns <b>VGU_SUCCESS</b> if the operation is successful; returns an error code defined in
* {@link VGUResult} otherwise.
* @since 3.0
*/
VGUResult VGUPathAppend(VGUPath *path, const VGUPath *subpath);
* @brief Clears the memory of a specified path object.
*
* @param path Indicates the pointer to the path object.
*
* @return Returns <b>VGU_SUCCESS</b> if the operation is successful; returns an error code defined in
* {@link VGUResult} otherwise.
* @since 3.0
*/
VGUResult VGUPathClear(VGUPath *path);
* @brief Loads an identity matrix into a specified matrix object.
*
* @param matrix Indicates the pointer to the transformation matrix object.
*
* @return Returns <b>VGU_SUCCESS</b> if the operation is successful; returns an error code defined in
* {@link VGUResult} otherwise.
* @since 3.0
*/
VGUResult VGUMatrixIdentity(VGUMatrix3 *matrix);
* @brief Scales a specified transformation matrix.
*
* @param matrix Indicates the pointer to the transformation matrix object.
* @param xScale Indicates how much you want to scale the horizontal coordinate by.
* @param yScale Indicates how much you want to scale the vertical coordinate by.
*
* @return Returns <b>VGU_SUCCESS</b> if the operation is successful; returns an error code defined in
* {@link VGUResult} otherwise.
* @since 3.0
*/
VGUResult VGUMatrixScale(VGUMatrix3 *matrix, float xScale, float yScale);
* @brief Rotates a specified transformation matrix.
*
* @param matrix Indicates the pointer to the transformation matrix object.
* @param degree Indicates the number of degrees to rotate.
*
* @return Returns <b>VGU_SUCCESS</b> if the operation is successful; returns an error code defined in
* {@link VGUResult} otherwise.
* @since 3.0
*/
VGUResult VGUMatrixRotate(VGUMatrix3 *matrix, float degree);
* @brief Translates a specified transformation matrix.
*
* @param matrix Indicates the pointer to the transformation matrix object.
* @param x Indicates how much you want to translate the horizontal coordinate by.
* @param y Indicates how much you want to translate the vertical coordinate by.
*
* @return Returns <b>VGU_SUCCESS</b> if the operation is successful; returns an error code defined in
* {@link VGUResult} otherwise.
* @since 3.0
*/
VGUResult VGUMatrixTranslate(VGUMatrix3 *matrix, float x, float y);
* @brief Adds color stops to a specified gradient.
*
* @param gradient Indicates the pointer to the gradient object.
* @param colorStop Indicates the pointer to the color stop array.
* @param count Indicates the total number of color stops.
*
* @return Returns <b>VGU_SUCCESS</b> if the operation is successful; returns an error code defined in
* {@link VGUResult} otherwise.
* @since 3.0
*/
VGUResult VGUGradientColorStop(VGUGradient *gradient, const VGUColorStop *colorStop, uint32_t count);
* @brief Clears color stops of a specified gradient.
*
* @param gradient Indicates the pointer to the gradient object.
*
* @return Returns <b>VGU_SUCCESS</b> if the operation is successful; returns an error code defined in
* {@link VGUResult} otherwise.
* @since 3.0
*/
VGUResult VGUGradientClearStop(VGUGradient *gradient);
* @brief Sets a transformation matrix for a specified gradient.
*
* @param gradient Indicates the pointer to the gradient object.
* @param matrix Indicates the pointer to the transformation matrix object to set.
*
* @return Returns <b>VGU_SUCCESS</b> if the operation is successful; returns an error code defined in
* {@link VGUResult} otherwise.
* @since 3.0
*/
VGUResult VGUGradientMatrix(VGUGradient *gradient, const VGUMatrix3 *matrix);
* @brief Creates a linear gradient object.
*
* @param gradient Indicates the pointer to the gradient object.
* @param p1 Indicates the pointer to the coordinates of the start point.
* @param p2 Indicates the pointer to the coordinates of the end point.
*
* @return Returns <b>VGU_SUCCESS</b> if the operation is successful; returns an error code defined in
* {@link VGUResult} otherwise.
* @since 3.0
*/
VGUResult VGUGradientLinear(VGUGradient *gradient, const VGUPoint *p1, const VGUPoint *p2);
* @brief Creates a radial gradient object.
*
* @param gradient Indicates the pointer to the gradient object.
* @param p1 Indicates the pointer to the center point coordinates of the inner circle.
* @param r1 Indicates the radius of the inner circle.
* @param p2 Indicates the pointer to the center point coordinates of the outer circle.
* @param r2 Indicates the radius of the outer circle.
*
* @return Returns <b>VGU_SUCCESS</b> if the operation is successful; returns an error code defined in
* {@link VGUResult} otherwise.
* @since 3.0
*/
VGUResult VGUGradientRadial(VGUGradient *gradient, const VGUPoint *p1, VGUScalar r1, const VGUPoint *p2, VGUScalar r2);
* @brief Creates a conic gradient object.
*
* @param gradient Indicates the pointer to the gradient object.
* @param cx Indicates the horizontal coordinate of the center point of the gradient.
* @param cy Indicates the vertical coordinate of the center point of the gradient.
*
* @return Returns <b>VGU_SUCCESS</b> if the operation is successful; returns an error code defined in
* {@link VGUResult} otherwise.
* @since 3.0
*/
VGUResult VGUGradientConic(VGUGradient *gradient, VGUScalar cx, VGUScalar cy);
* @brief Initializes the hardware acceleration module to obtain the pointer to functions for
* hardware acceleration operations.
*
* @param funcs Indicates the double pointer to the functions for hardware acceleration operations.
* Memory is allocated automatically when you initiate the hardware acceleration module, so you can simply use
* the pointer to gain access to the functions.
*
* @return Returns <b>VGU_SUCCESS</b> if the operation is successful; returns an error code defined in
* {@link VGUResult} otherwise.
*
* @since 3.0
*/
VGUResult VGUInitialize(VGUFuncs **funcs);
* @brief Deinitializes the hardware acceleration module to release the pointer to functions
* for hardware acceleration operations.
*
* @param funcs Indicates the pointer to the functions for hardware acceleration operations.
*
* @return Returns <b>VGU_SUCCESS</b> if the operation is successful; returns an error code defined in
* {@link VGUResult} otherwise.
* @since 3.0
*/
VGUResult VGUUninitialize(VGUFuncs *funcs);
#ifdef __cplusplus
}
#endif
#endif