1 /*
2  * Copyright (c) 2021-2022 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 /**
17  * @addtogroup Display
18  * @{
19  *
20  * @brief Defines driver functions of the display module.
21  *
22  * This module provides driver functions for the graphics subsystem, including graphics layer management,
23  * device control, graphics hardware acceleration, display memory management, and callbacks.
24  *
25  * @since 1.0
26  * @version 2.0
27  */
28 
29 /**
30  * @file display_gfx.h
31  *
32  * @brief Declares the driver functions for implementing hardware acceleration.
33  *
34  * @since 1.0
35  * @version 1.0
36  */
37 
38 #ifndef DISPLAY_GFX_H
39 #define DISPLAY_GFX_H
40 #include "display_type.h"
41 
42 #ifdef __cplusplus
43 extern "C" {
44 #endif
45 
46 /**
47  * @brief Defines pointers to the hardware acceleration driver functions.
48  */
49 typedef struct {
50     /**
51      * @brief Initializes hardware acceleration.
52      *
53      * @return Returns <b>0</b> if the operation is successful; returns an error code defined in {@link DispErrCode}
54      * otherwise.
55      * @see DeinitGfx
56      * @since 1.0
57      * @version 1.0
58      */
59     int32_t (*InitGfx)(void);
60 
61     /**
62      * @brief Deinitializes hardware acceleration.
63      *
64      * @return Returns <b>0</b> if the operation is successful; returns an error code defined in {@link DispErrCode}
65      * otherwise.
66      * @see InitGfx
67      * @since 1.0
68      * @version 1.0
69      */
70     int32_t (*DeinitGfx)(void);
71 
72     /**
73      * @brief Fills a rectangle with a given color on the canvas.
74      *
75      * @param surface Indicates the pointer to the canvas.
76      * @param rect Indicates the pointer to the rectangle to fill.
77      * @param color Indicates the color to fill.
78      * @param opt Indicates the pointer to the hardware acceleration option.
79      *
80      * @return Returns <b>0</b> if the operation is successful; returns an error code defined in {@link DispErrCode}
81      * otherwise.
82      * @since 1.0
83      * @version 1.0
84      */
85     int32_t (*FillRect)(ISurface *surface, IRect *rect, uint32_t color, GfxOpt *opt);
86 
87     /**
88      * @brief Draws a rectangle with a given color on the canvas.
89      *
90      * @param surface Indicates the pointer to the canvas.
91      * @param rect Indicates the pointer to the rectangle to draw.
92      * @param color Indicates the color to draw.
93      * @param opt Indicates the pointer to the hardware acceleration option.
94      *
95      * @return Returns <b>0</b> if the operation is successful; returns an error code defined in {@link DispErrCode}
96      * otherwise.
97      * @since 1.0
98      * @version 1.0
99      */
100     int32_t (*DrawRectangle)(ISurface *surface, Rectangle *rect, uint32_t color, GfxOpt *opt);
101 
102     /**
103      * @brief Draws a straight line with a given color on the canvas.
104      *
105      * @param surface Indicates the pointer to the canvas.
106      * @param line Indicates the pointer to the line to draw.
107      * @param opt Indicates the pointer to the hardware acceleration option.
108      *
109      * @return Returns <b>0</b> if the operation is successful; returns an error code defined in {@link DispErrCode}
110      * otherwise.
111      * @since 1.0
112      * @version 1.0
113      */
114     int32_t (*DrawLine)(ISurface *surface, ILine *line, GfxOpt *opt);
115 
116     /**
117      * @brief Draws a circle with a specified center and radius on the canvas using a given color.
118      *
119      * @param surface Indicates the pointer to the canvas.
120      * @param circle Indicates the pointer to the circle to draw.
121      * @param opt Indicates the pointer to the hardware acceleration option.
122      *
123      * @return Returns <b>0</b> if the operation is successful; returns an error code defined in {@link DispErrCode}
124      * otherwise.
125      * @since 1.0
126      * @version 1.0
127      */
128     int32_t (*DrawCircle)(ISurface *surface, ICircle *circle, GfxOpt *opt);
129 
130     /**
131      * @brief Blits bitmaps.
132      *
133      * During bit blit, color space conversion (CSC), scaling, and rotation can be implemented.
134      *
135      * @param srcSurface Indicates the pointer to the source bitmap.
136      * @param srcRect Indicates the pointer to the rectangle of the source bitmap.
137      * @param dstSurface Indicates the pointer to the destination bitmap.
138      * @param dstRect Indicates the pointer to the rectangle of the destination bitmap.
139      * @param opt Indicates the pointer to the hardware acceleration option.
140      *
141      * @return Returns <b>0</b> if the operation is successful; returns an error code defined in {@link DispErrCode}
142      * otherwise.
143      * @since 1.0
144      * @version 1.0
145      */
146     int32_t (*Blit)(ISurface *srcSurface, IRect *srcRect, ISurface *dstSurface, IRect *dstRect, GfxOpt *opt);
147 
148     /**
149      * @brief Synchronizes hardware acceleration when it is used to draw and blit bitmaps.
150      *
151      * This function blocks the process until hardware acceleration is complete.
152      *
153      * @param timeOut Indicates the timeout duration for hardware acceleration synchronization. The value <b>0</b>
154      * indicates no timeout, so the process waits until hardware acceleration is complete.
155      *
156      * @return Returns <b>0</b> if the operation is successful; returns an error code defined in {@link DispErrCode}
157      * otherwise.
158      * @since 1.0
159      * @version 1.0
160      */
161     int32_t (*Sync)(int32_t timeOut);
162 } GfxFuncs;
163 
164 /**
165  * @brief Initializes the hardware acceleration module to obtain the pointer to functions for hardware acceleration
166  * operations.
167  *
168  * @param funcs Indicates the double pointer to functions for hardware acceleration operations. Memory is allocated
169  * automatically when you initiate the hardware acceleration module, so you can simply use the pointer to gain access
170  * to the functions.
171  *
172  * @return Returns <b>0</b> if the operation is successful; returns an error code defined in {@link DispErrCode}
173  * otherwise.
174  * @since 1.0
175  * @version 1.0
176  */
177 int32_t GfxInitialize(GfxFuncs **funcs);
178 
179 /**
180  * @brief Deinitializes the hardware acceleration module to release the pointer to functions for hardware
181  * acceleration operations.
182  *
183  * @param funcs Indicates the pointer to the functions for hardware acceleration operations.
184  *
185  * @return Returns <b>0</b> if the operation is successful; returns an error code defined in {@link DispErrCode}
186  * otherwise.
187  * @since 1.0
188  * @version 1.0
189  */
190 int32_t GfxUninitialize(GfxFuncs *funcs);
191 
192 #ifdef __cplusplus
193 }
194 #endif
195 #endif
196 /** @} */
197