xref: /OK3568_Linux_fs/external/rknpu2/examples/3rdparty/rga/RK3588/include/im2d_common.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1 /*
2  * Copyright (C) 2022 Rockchip Electronics Co., Ltd.
3  * Authors:
4  *  Cerf Yu <cerf.yu@rock-chips.com>
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  *      http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */
18 #ifndef _im2d_common_h_
19 #define _im2d_common_h_
20 
21 #include "im2d_type.h"
22 
23 /**
24  * Query RGA basic information, supported resolution, supported format, etc.
25  *
26  * @param name
27  *      RGA_VENDOR
28  *      RGA_VERSION
29  *      RGA_MAX_INPUT
30  *      RGA_MAX_OUTPUT
31  *      RGA_INPUT_FORMAT
32  *      RGA_OUTPUT_FORMAT
33  *      RGA_EXPECTED
34  *      RGA_ALL
35  *
36  * @returns a string describing properties of RGA.
37  */
38 IM_EXPORT_API const char* querystring(int name);
39 
40 /**
41  * String to output the error message
42  *
43  * @param status
44  *      process result value.
45  *
46  * @returns error message.
47  */
48 #define imStrError(...) \
49     ({ \
50         const char* im2d_api_err; \
51         int __args[] = {__VA_ARGS__}; \
52         int __argc = sizeof(__args)/sizeof(int); \
53         if (__argc == 0) { \
54             im2d_api_err = imStrError_t(IM_STATUS_INVALID_PARAM); \
55         } else if (__argc == 1){ \
56             im2d_api_err = imStrError_t((IM_STATUS)__args[0]); \
57         } else { \
58             im2d_api_err = ("Fatal error, imStrError() too many parameters\n"); \
59             printf("Fatal error, imStrError() too many parameters\n"); \
60         } \
61         im2d_api_err; \
62     })
63 IM_C_API const char* imStrError_t(IM_STATUS status);
64 
65 /**
66  * check im2d api header file
67  *
68  * @param header_version
69  *      Default is RGA_CURRENT_API_HEADER_VERSION, no need to change if there are no special cases.
70  *
71  * @returns no error or else negative error code.
72  */
73 #ifdef __cplusplus
74 IM_API IM_STATUS imcheckHeader(im_api_version_t header_version = RGA_CURRENT_API_HEADER_VERSION);
75 #endif
76 
77 /**
78  * check RGA basic information, supported resolution, supported format, etc.
79  *
80  * @param src
81  * @param dst
82  * @param pat
83  * @param src_rect
84  * @param dst_rect
85  * @param pat_rect
86  * @param mode_usage
87  *
88  * @returns no error or else negative error code.
89  */
90 #define imcheck(src, dst, src_rect, dst_rect, ...) \
91     ({ \
92         IM_STATUS __ret = IM_STATUS_NOERROR; \
93         rga_buffer_t __pat; \
94         im_rect __pat_rect; \
95         memset(&__pat, 0, sizeof(rga_buffer_t)); \
96         memset(&__pat_rect, 0, sizeof(im_rect)); \
97         int __args[] = {__VA_ARGS__}; \
98         int __argc = sizeof(__args)/sizeof(int); \
99         if (__argc == 0) { \
100             __ret = imcheck_t(src, dst, __pat, src_rect, dst_rect, __pat_rect, 0); \
101         } else if (__argc == 1){ \
102             __ret = imcheck_t(src, dst, __pat, src_rect, dst_rect, __pat_rect, __args[0]); \
103         } else { \
104             __ret = IM_STATUS_FAILED; \
105             printf("check failed\n"); \
106         } \
107         __ret; \
108     })
109 #define imcheck_composite(src, dst, pat, src_rect, dst_rect, pat_rect, ...) \
110     ({ \
111         IM_STATUS __ret = IM_STATUS_NOERROR; \
112         int __args[] = {__VA_ARGS__}; \
113         int __argc = sizeof(__args)/sizeof(int); \
114         if (__argc == 0) { \
115             __ret = imcheck_t(src, dst, pat, src_rect, dst_rect, pat_rect, 0); \
116         } else if (__argc == 1){ \
117             __ret = imcheck_t(src, dst, pat, src_rect, dst_rect, pat_rect, __args[0]); \
118         } else { \
119             __ret = IM_STATUS_FAILED; \
120             printf("check failed\n"); \
121         } \
122         __ret; \
123     })
124 IM_C_API IM_STATUS imcheck_t(const rga_buffer_t src, const rga_buffer_t dst, const rga_buffer_t pat,
125                              const im_rect src_rect, const im_rect dst_rect, const im_rect pat_rect, const int mode_usage);
126 /* Compatible with the legacy symbol */
127 IM_C_API void rga_check_perpare(rga_buffer_t *src, rga_buffer_t *dst, rga_buffer_t *pat,
128                                 im_rect *src_rect, im_rect *dst_rect, im_rect *pat_rect, int mode_usage);
129 
130 /**
131  * block until all execution is complete
132  *
133  * @param release_fence_fd
134  *      RGA job release fence fd
135  *
136  * @returns success or else negative error code.
137  */
138 IM_EXPORT_API IM_STATUS imsync(int release_fence_fd);
139 
140 /**
141  * config
142  *
143  * @param name
144  *      enum IM_CONFIG_NAME
145  * @param value
146  *
147  * @returns success or else negative error code.
148  */
149 IM_EXPORT_API IM_STATUS imconfig(IM_CONFIG_NAME name, uint64_t value);
150 
151 #endif /* #ifndef _im2d_common_h_ */
152