1 /*
2 * Copyright (C) 2021 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
19 #ifndef _RGA_IM2D_COMMON_H_
20 #define _RGA_IM2D_COMMON_H_
21
22 #include "drmrga.h"
23 #include "im2d.h"
24 #include "im2d_hardware.h"
25
26 #define ALIGN(val, align) (((val) + ((align) - 1)) & ~((align) - 1))
27 #define DOWN_ALIGN(val, align) ((val) & ~((align) - 1))
28 #define UNUSED(...) (void)(__VA_ARGS__)
29 /*
30 * version bit:
31 * 0~7b build
32 * 8~15b revision
33 * 16~23b minor
34 * 24~31b major
35 */
36 #define RGA_GET_API_VERSION(v) {\
37 (((v) >> 24) & 0xff), \
38 (((v) >> 16) & 0xff), \
39 (((v) >> 8) & 0xff), \
40 {0}\
41 }
42
43 #define ERR_MSG_LEN 300
44
45 int imSetErrorMsg(const char* format, ...);
46
47 bool rga_is_buffer_valid(rga_buffer_t buf);
48 bool rga_is_rect_valid(im_rect rect);
49 void empty_structure(rga_buffer_t *src, rga_buffer_t *dst, rga_buffer_t *pat,
50 im_rect *srect, im_rect *drect, im_rect *prect, im_opt_t *opt);
51 IM_STATUS rga_set_buffer_info(rga_buffer_t dst, rga_info_t* dstinfo);
52 IM_STATUS rga_set_buffer_info(const rga_buffer_t src, rga_buffer_t dst, rga_info_t* srcinfo, rga_info_t* dstinfo);
rga_apply_rect(rga_buffer_t * image,im_rect * rect)53 inline void rga_apply_rect(rga_buffer_t *image, im_rect *rect) {
54 if (rect->width > 0 && rect->height > 0) {
55 image->width = rect->width;
56 image->height = rect->height;
57 }
58 }
59
60 IM_STATUS rga_get_info(rga_info_table_entry *return_table);
61 IM_STATUS rga_check_driver(void);
62
63 IM_STATUS rga_check_info(const char *name, const rga_buffer_t info, const im_rect rect, int resolution_usage);
64 IM_STATUS rga_check_limit(rga_buffer_t src, rga_buffer_t dst, int scale_usage, int mode_usage);
65 IM_STATUS rga_check_format(const char *name, rga_buffer_t info, im_rect rect, int format_usage, int mode_usgae);
66 IM_STATUS rga_check_align(const char *name, rga_buffer_t info, int byte_stride);
67 IM_STATUS rga_check_blend(rga_buffer_t src, rga_buffer_t pat, rga_buffer_t dst, int pat_enable, int mode_usage);
68 IM_STATUS rga_check_rotate(int mode_usage, rga_info_table_entry &table);
69 IM_STATUS rga_check_feature(rga_buffer_t src, rga_buffer_t pat, rga_buffer_t dst,
70 int pat_enable, int mode_usage, int feature_usage);
71
72 IM_API IM_STATUS rga_import_buffers(struct rga_buffer_pool *buffer_pool);
73 IM_API IM_STATUS rga_release_buffers(struct rga_buffer_pool *buffer_pool);
74 IM_API rga_buffer_handle_t rga_import_buffer(uint64_t memory, int type, uint32_t size);
75 IM_API rga_buffer_handle_t rga_import_buffer(uint64_t memory, int type, im_handle_param_t *param);
76 IM_API IM_STATUS rga_release_buffer(int handle);
77
78 IM_STATUS rga_get_opt(im_opt_t *opt, void *ptr);
79
80 IM_API im_ctx_id_t rga_begin_job(uint32_t flags);
81 IM_API IM_STATUS rga_cancel(im_ctx_id_t id);
82
83 #endif
84