1 /*
2 * Copyright (C) 2016 Rockchip Electronics Co., Ltd.
3 * Authors:
4 * Zhiqin Wei <wzq@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 _rk_drm_rga_
20 #define _rk_drm_rga_
21
22 #include <stdint.h>
23 #include <errno.h>
24 //#include <sys/cdefs.h>
25
26 #include "rga.h"
27
28 #ifdef ANDROID
29 #define DRMRGA_HARDWARE_MODULE_ID "librga"
30
31 #include <hardware/gralloc.h>
32 #include <hardware/hardware.h>
33 #include <system/graphics.h>
34 #include <cutils/native_handle.h>
35
36 #ifdef ANDROID_12
37 #include <hardware/hardware_rockchip.h>
38 #endif
39
40 #endif
41
42 #ifndef ANDROID /* LINUX */
43 /* flip source image horizontally (around the vertical axis) */
44 #define HAL_TRANSFORM_FLIP_H 0x01
45 /* flip source image vertically (around the horizontal axis)*/
46 #define HAL_TRANSFORM_FLIP_V 0x02
47 /* rotate source image 90 degrees clockwise */
48 #define HAL_TRANSFORM_ROT_90 0x04
49 /* rotate source image 180 degrees */
50 #define HAL_TRANSFORM_ROT_180 0x03
51 /* rotate source image 270 degrees clockwise */
52 #define HAL_TRANSFORM_ROT_270 0x07
53 #endif
54
55 #define HAL_TRANSFORM_FLIP_H_V 0x08
56
57 /*****************************************************************************/
58
59 /* for compatibility */
60 #define DRM_RGA_MODULE_API_VERSION HWC_MODULE_API_VERSION_0_1
61 #define DRM_RGA_DEVICE_API_VERSION HWC_DEVICE_API_VERSION_0_1
62 #define DRM_RGA_API_VERSION HWC_DEVICE_API_VERSION
63
64 #define DRM_RGA_TRANSFORM_ROT_MASK 0x0000000F
65 #define DRM_RGA_TRANSFORM_ROT_0 0x00000000
66 #define DRM_RGA_TRANSFORM_ROT_90 HAL_TRANSFORM_ROT_90
67 #define DRM_RGA_TRANSFORM_ROT_180 HAL_TRANSFORM_ROT_180
68 #define DRM_RGA_TRANSFORM_ROT_270 HAL_TRANSFORM_ROT_270
69
70 #define DRM_RGA_TRANSFORM_FLIP_MASK 0x00000003
71 #define DRM_RGA_TRANSFORM_FLIP_H HAL_TRANSFORM_FLIP_H
72 #define DRM_RGA_TRANSFORM_FLIP_V HAL_TRANSFORM_FLIP_V
73
74 enum {
75 AWIDTH = 0,
76 AHEIGHT,
77 ASTRIDE,
78 AFORMAT,
79 ASIZE,
80 ATYPE,
81 };
82 /*****************************************************************************/
83
84 #ifndef ANDROID
85 /* memory type definitions. */
86 enum drm_rockchip_gem_mem_type {
87 /* Physically Continuous memory and used as default. */
88 ROCKCHIP_BO_CONTIG = 1 << 0,
89 /* cachable mapping. */
90 ROCKCHIP_BO_CACHABLE = 1 << 1,
91 /* write-combine mapping. */
92 ROCKCHIP_BO_WC = 1 << 2,
93 ROCKCHIP_BO_SECURE = 1 << 3,
94 ROCKCHIP_BO_MASK = ROCKCHIP_BO_CONTIG | ROCKCHIP_BO_CACHABLE |
95 ROCKCHIP_BO_WC | ROCKCHIP_BO_SECURE
96 };
97
98 typedef struct bo {
99 int fd;
100 void *ptr;
101 size_t size;
102 size_t offset;
103 size_t pitch;
104 unsigned handle;
105 } bo_t;
106 #endif
107
108 /*
109 @value size: user not need care about.For avoid read/write out of memory
110 */
111 typedef struct rga_rect {
112 int xoffset;
113 int yoffset;
114 int width;
115 int height;
116 int wstride;
117 int hstride;
118 int format;
119 int size;
120 } rga_rect_t;
121
122 typedef struct rga_nn {
123 int nn_flag;
124 int scale_r;
125 int scale_g;
126 int scale_b;
127 int offset_r;
128 int offset_g;
129 int offset_b;
130 } rga_nn_t;
131
132 typedef struct rga_dither {
133 int enable;
134 int mode;
135 int lut0_l;
136 int lut0_h;
137 int lut1_l;
138 int lut1_h;
139 } rga_dither_t;
140
141 /*
142 @value fd: use fd to share memory, it can be ion shard fd,and dma fd.
143 @value virAddr:userspace address
144 @value phyAddr:use phy address
145 @value hnd: use buffer_handle_t
146 */
147 typedef struct rga_info {
148 int fd;
149 void *virAddr;
150 void *phyAddr;
151 #ifndef ANDROID /* LINUX */
152 unsigned hnd;
153 #else /* Android */
154 buffer_handle_t hnd;
155 #endif
156 int format;
157 rga_rect_t rect;
158 unsigned int blend;
159 int bufferSize;
160 int rotation;
161 int color;
162 int testLog;
163 int mmuFlag;
164 int colorkey_en;
165 int colorkey_mode;
166 int colorkey_max;
167 int colorkey_min;
168 int scale_mode;
169 int color_space_mode;
170 int sync_mode;
171 rga_nn_t nn;
172 rga_dither_t dither;
173 int rop_code;
174 int rd_mode;
175 unsigned short is_10b_compact;
176 unsigned short is_10b_endian;
177
178 int in_fence_fd;
179 int out_fence_fd;
180
181 int core;
182 int priority;
183
184 unsigned short enable;
185
186 int handle;
187
188 struct rga_mosaic_info mosaic_info;
189
190 struct rga_osd_info osd_info;
191
192 struct rga_pre_intr_info pre_intr;
193
194 int mpi_mode;
195 int ctx_id;
196
197 char reserve[402];
198 } rga_info_t;
199
200
201 typedef struct drm_rga {
202 rga_rect_t src;
203 rga_rect_t dst;
204 } drm_rga_t;
205
206 /*
207 @fun rga_set_rect:For use to set the rects esayly
208
209 @param rect:The rect user want to set,like setting the src rect:
210 drm_rga_t rects;
211 rga_set_rect(rects.src,0,0,1920,1080,1920,NV12);
212 mean to set the src rect to the value.
213 */
rga_set_rect(rga_rect_t * rect,int x,int y,int w,int h,int sw,int sh,int f)214 static inline int rga_set_rect(rga_rect_t *rect,
215 int x, int y, int w, int h, int sw, int sh, int f) {
216 if (!rect)
217 return -EINVAL;
218
219 rect->xoffset = x;
220 rect->yoffset = y;
221 rect->width = w;
222 rect->height = h;
223 rect->wstride = sw;
224 rect->hstride = sh;
225 rect->format = f;
226
227 return 0;
228 }
229
230 #ifndef ANDROID /* LINUX */
rga_set_rotation(rga_info_t * info,int angle)231 static inline void rga_set_rotation(rga_info_t *info, int angle) {
232 if (angle == 90)
233 info->rotation = HAL_TRANSFORM_ROT_90;
234 else if (angle == 180)
235 info->rotation = HAL_TRANSFORM_ROT_180;
236 else if (angle == 270)
237 info->rotation = HAL_TRANSFORM_ROT_270;
238 }
239 #endif
240 /*****************************************************************************/
241
242 #endif
243