1 /*
2  * Copyright (c) 2023 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 #ifndef DISPLAY_GFX_H
17 #define DISPLAY_GFX_H
18 #include "v1_0/display_composer_type.h"
19 
20 namespace OHOS {
21 namespace HDI {
22 namespace DISPLAY {
23 using namespace OHOS::HDI::Display::Composer::V1_0;
24 /**
25  * @brief Defines pointers to the hardware acceleration driver functions.
26  */
27 using GfxFuncs = struct {
28     /**
29      * @brief Initializes hardware acceleration.
30      *
31      * @return Returns <b>0</b> if the operation is successful; returns an error code defined in {@link DispErrCode}
32      * otherwise.
33      */
34     int32_t (*InitGfx)(void);
35 
36     /**
37      * @brief Deinitializes hardware acceleration.
38      *
39      * @return Returns <b>0</b> if the operation is successful; returns an error code defined in {@link DispErrCode}
40      * otherwise.
41      */
42     int32_t (*DeinitGfx)(void);
43 
44     /**
45      * @brief Fills a rectangle with a given color on the canvas.
46      *
47      * @param surface Indicates the pointer to the canvas.
48      * @param rect Indicates the pointer to the rectangle to fill.
49      * @param color Indicates the color to fill.
50      * @param opt Indicates the pointer to the hardware acceleration option.
51      *
52      * @return Returns <b>0</b> if the operation is successful; returns an error code defined in {@link DispErrCode}
53      * otherwise.
54      */
55     int32_t (*FillRect)(ISurface *surface, IRect *rect, uint32_t color, GfxOpt *opt);
56 
57     /**
58      * @brief Draws a rectangle with a given color on the canvas.
59      *
60      * @param surface Indicates the pointer to the canvas.
61      * @param rect Indicates the pointer to the rectangle to draw.
62      * @param color Indicates the color to draw.
63      * @param opt Indicates the pointer to the hardware acceleration option.
64      *
65      * @return Returns <b>0</b> if the operation is successful; returns an error code defined in {@link DispErrCode}
66      * otherwise.
67      */
68     int32_t (*DrawRectangle)(ISurface *surface, Rectangle *rect, uint32_t color, GfxOpt *opt);
69 
70     /**
71      * @brief Draws a straight line with a given color on the canvas.
72      *
73      * @param surface Indicates the pointer to the canvas.
74      * @param line Indicates the pointer to the line to draw.
75      * @param opt Indicates the pointer to the hardware acceleration option.
76      *
77      * @return Returns <b>0</b> if the operation is successful; returns an error code defined in {@link DispErrCode}
78      * otherwise.
79      */
80     int32_t (*DrawLine)(ISurface *surface, ILine *line, GfxOpt *opt);
81 
82     /**
83      * @brief Draws a circle with a specified center and radius on the canvas using a given color.
84      *
85      * @param surface Indicates the pointer to the canvas.
86      * @param circle Indicates the pointer to the circle to draw.
87      * @param opt Indicates the pointer to the hardware acceleration option.
88      *
89      * @return Returns <b>0</b> if the operation is successful; returns an error code defined in {@link DispErrCode}
90      * otherwise.
91      */
92     int32_t (*DrawCircle)(ISurface *surface, ICircle *circle, GfxOpt *opt);
93 
94     /**
95      * @brief Blits bitmaps.
96      *
97      * During bit blit, color space conversion (CSC), scaling, and rotation can be implemented.
98      *
99      * @param srcSurface Indicates the pointer to the source bitmap.
100      * @param srcRect Indicates the pointer to the rectangle of the source bitmap.
101      * @param dstSurface Indicates the pointer to the destination bitmap.
102      * @param dstRect Indicates the pointer to the rectangle of the destination bitmap.
103      * @param opt Indicates the pointer to the hardware acceleration option.
104      *
105      * @return Returns <b>0</b> if the operation is successful; returns an error code defined in {@link DispErrCode}
106      * otherwise.
107      */
108     int32_t (*Blit)(ISurface *srcSurface, IRect *srcRect, ISurface *dstSurface, IRect *dstRect, GfxOpt *opt);
109 
110     /**
111      * @brief Synchronizes hardware acceleration when it is used to draw and blit bitmaps.
112      *
113      * This function blocks the process until hardware acceleration is complete.
114      *
115      * @param timeOut Indicates the timeout duration for hardware acceleration synchronization. The value <b>0</b>
116      * indicates no timeout, so the process waits until hardware acceleration is complete.
117      *
118      * @return Returns <b>0</b> if the operation is successful; returns an error code defined in {@link DispErrCode}
119      * otherwise.
120      */
121     int32_t (*Sync)(int32_t timeOut);
122 };
123 
124 /**
125  * @brief Initializes the hardware acceleration module to obtain the pointer to functions for hardware acceleration
126  * operations.
127  *
128  * @param funcs Indicates the double pointer to functions for hardware acceleration operations. Memory is allocated
129  * automatically when you initiate the hardware acceleration module, so you can simply use the pointer to gain access
130  * to the functions.
131  *
132  * @return Returns <b>0</b> if the operation is successful; returns an error code defined in {@link DispErrCode}
133  * otherwise.
134  */
135 int32_t GfxInitialize(GfxFuncs **funcs);
136 
137 /**
138  * @brief Deinitializes the hardware acceleration module to release the pointer to functions for hardware
139  * acceleration operations.
140  *
141  * @param funcs Indicates the pointer to the functions for hardware acceleration operations.
142  *
143  * @return Returns <b>0</b> if the operation is successful; returns an error code defined in {@link DispErrCode}
144  * otherwise.
145  */
146 int32_t GfxUninitialize(GfxFuncs *funcs);
147 } // DISPLAY
148 }  // HDI
149 }  // OHOS
150 #endif
151 /** @} */
152