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 /* flip source image horizontally (around the vertical axis) */
23 #define HAL_TRANSFORM_FLIP_H 0x01
24 /* flip source image vertically (around the horizontal axis) */
25 #define HAL_TRANSFORM_FLIP_V 0x02
26 /* rotate source image 90 degrees clockwise */
27 #define HAL_TRANSFORM_ROT_90 0x04
28 /* rotate source image 180 degrees */
29 #define HAL_TRANSFORM_ROT_180 0x03
30 /* rotate source image 270 degrees clockwise */
31 #define HAL_TRANSFORM_ROT_270 0x07
32
33 #define HAL_TRANSFORM_FLIP_H_V 0x08
34
35 /*****************************************************************************/
36
37 /* for compatibility */
38
39 #define DRM_RGA_TRANSFORM_ROT_MASK 0x0000000F
40 #define DRM_RGA_TRANSFORM_ROT_0 0x00000000
41 #define DRM_RGA_TRANSFORM_ROT_90 HAL_TRANSFORM_ROT_90
42 #define DRM_RGA_TRANSFORM_ROT_180 HAL_TRANSFORM_ROT_180
43 #define DRM_RGA_TRANSFORM_ROT_270 HAL_TRANSFORM_ROT_270
44
45 #define DRM_RGA_TRANSFORM_FLIP_MASK 0x00000003
46 #define DRM_RGA_TRANSFORM_FLIP_H HAL_TRANSFORM_FLIP_H
47 #define DRM_RGA_TRANSFORM_FLIP_V HAL_TRANSFORM_FLIP_V
48
49 enum {
50 AWIDTH = 0,
51 AHEIGHT,
52 ASTRIDE,
53 AFORMAT,
54 ASIZE,
55 ATYPE,
56 };
57 /*****************************************************************************/
58
59 /* memory type definitions. */
60 enum drm_rockchip_gem_mem_type {
61 /* Physically Continuous memory and used as default. */
62 ROCKCHIP_BO_CONTIG = 1 << 0,
63 /* cachable mapping. */
64 ROCKCHIP_BO_CACHABLE = 1 << 1,
65 /* write-combine mapping. */
66 ROCKCHIP_BO_WC = 1 << 2,
67 ROCKCHIP_BO_SECURE = 1 << 3,
68 ROCKCHIP_BO_MASK = ROCKCHIP_BO_CONTIG | ROCKCHIP_BO_CACHABLE | ROCKCHIP_BO_WC | ROCKCHIP_BO_SECURE
69 };
70
71 typedef struct bo {
72 int fd;
73 void *ptr;
74 size_t size;
75 size_t offset;
76 size_t pitch;
77 unsigned handle;
78 } bo_t;
79
80 /*
81 @value size: user not need care about.For avoid read/write out of memory
82 */
83 typedef struct rga_rect {
84 int xoffset;
85 int yoffset;
86 int width;
87 int height;
88 int wstride;
89 int hstride;
90 int format;
91 int size;
92 } rga_rect_t;
93
94 typedef struct rga_nn {
95 int nn_flag;
96 int scale_r;
97 int scale_g;
98 int scale_b;
99 int offset_r;
100 int offset_g;
101 int offset_b;
102 } rga_nn_t;
103
104 typedef struct rga_dither {
105 int enable;
106 int mode;
107 int lut0_l;
108 int lut0_h;
109 int lut1_l;
110 int lut1_h;
111 } rga_dither_t;
112
113 /*
114 @value fd: use fd to share memory, it can be ion shard fd,and dma fd.
115 @value virAddr:userspace address
116 @value phyAddr:use phy address
117 @value hnd: use buffer_handle_t
118 */
119 typedef struct rga_info {
120 int fd;
121 void *virAddr;
122 void *phyAddr;
123 unsigned hnd;
124 int format;
125 rga_rect_t rect;
126 unsigned int blend;
127 int bufferSize;
128 int rotation;
129 int color;
130 int testLog;
131 int mmuFlag;
132 int colorkey_en;
133 int colorkey_mode;
134 int colorkey_max;
135 int colorkey_min;
136 int scale_mode;
137 int color_space_mode;
138 int sync_mode;
139 rga_nn_t nn;
140 rga_dither_t dither;
141 int rop_code;
142 int reserve[127];
143 } rga_info_t;
144
145 typedef struct drm_rga {
146 rga_rect_t src;
147 rga_rect_t dst;
148 } drm_rga_t;
149
150 /*
151 @fun rga_set_rect:For use to set the rects esayly
152
153 @param rect:The rect user want to set,like setting the src rect:
154 drm_rga_t rects;
155 rga_set_rect(rects.src,0,0,1920,1080,1920,NV12);
156 mean to set the src rect to the value.
157 */
rga_set_rect(rga_rect_t * rect,int x,int y,int w,int h,int sw,int sh,int f)158 static inline int rga_set_rect(rga_rect_t *rect, int x, int y, int w, int h, int sw, int sh, int f)
159 {
160 if (!rect) {
161 return -EINVAL;
162 }
163 rect->xoffset = x;
164 rect->yoffset = y;
165 rect->width = w;
166 rect->height = h;
167 rect->wstride = sw;
168 rect->hstride = sh;
169 rect->format = f;
170 return 0;
171 }
172
rga_set_rotation(rga_info_t * info,int angle)173 static inline void rga_set_rotation(rga_info_t *info, int angle)
174 {
175 if (angle == 90) { // 90:HAL_TRANSFORM_ROT
176 info->rotation = HAL_TRANSFORM_ROT_90;
177 } else if (angle == 180) { // 180:HAL_TRANSFORM_ROT
178 info->rotation = HAL_TRANSFORM_ROT_180;
179 } else if (angle == 270) { // 270:HAL_TRANSFORM_ROT
180 info->rotation = HAL_TRANSFORM_ROT_270;
181 }
182 }
183 /*****************************************************************************/
184
185 #endif
186