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 |
69 ROCKCHIP_BO_WC | ROCKCHIP_BO_SECURE
70 };
71
72 typedef struct bo {
73 int fd;
74 void *ptr;
75 size_t size;
76 size_t offset;
77 size_t pitch;
78 unsigned handle;
79 } bo_t;
80
81 /*
82 @value size: user not need care about.For avoid read/write out of memory
83 */
84 typedef struct rga_rect {
85 int xoffset;
86 int yoffset;
87 int width;
88 int height;
89 int wstride;
90 int hstride;
91 int format;
92 int size;
93 } rga_rect_t;
94
95 typedef struct rga_nn {
96 int nn_flag;
97 int scale_r;
98 int scale_g;
99 int scale_b;
100 int offset_r;
101 int offset_g;
102 int offset_b;
103 } rga_nn_t;
104
105 typedef struct rga_dither {
106 int enable;
107 int mode;
108 int lut0_l;
109 int lut0_h;
110 int lut1_l;
111 int lut1_h;
112 } rga_dither_t;
113
114 /*
115 @value fd: use fd to share memory, it can be ion shard fd,and dma fd.
116 @value virAddr:userspace address
117 @value phyAddr:use phy address
118 @value hnd: use buffer_handle_t
119 */
120 typedef struct rga_info {
121 int fd;
122 void *virAddr;
123 void *phyAddr;
124 unsigned hnd;
125 int format;
126 rga_rect_t rect;
127 unsigned int blend;
128 int bufferSize;
129 int rotation;
130 int color;
131 int testLog;
132 int mmuFlag;
133 int colorkey_en;
134 int colorkey_mode;
135 int colorkey_max;
136 int colorkey_min;
137 int scale_mode;
138 int color_space_mode;
139 int sync_mode;
140 rga_nn_t nn;
141 rga_dither_t dither;
142 int rop_code;
143 int reserve[127];
144 } rga_info_t;
145
146
147 typedef struct drm_rga {
148 rga_rect_t src;
149 rga_rect_t dst;
150 } drm_rga_t;
151
152 /*
153 @fun rga_set_rect:For use to set the rects esayly
154
155 @param rect:The rect user want to set,like setting the src rect:
156 drm_rga_t rects;
157 rga_set_rect(rects.src,0,0,1920,1080,1920,NV12);
158 mean to set the src rect to the value.
159 */
rga_set_rect(rga_rect_t * rect,int x,int y,int w,int h,int sw,int sh,int f)160 static inline int rga_set_rect(rga_rect_t *rect, int x, int y, int w, int h, int sw, int sh, int f)
161 {
162 if (!rect) {
163 return -EINVAL;
164 }
165 rect->xoffset = x;
166 rect->yoffset = y;
167 rect->width = w;
168 rect->height = h;
169 rect->wstride = sw;
170 rect->hstride = sh;
171 rect->format = f;
172 return 0;
173 }
174
rga_set_rotation(rga_info_t * info,int angle)175 static inline void rga_set_rotation(rga_info_t *info, int angle)
176 {
177 if (angle == 90) { // 90:HAL_TRANSFORM_ROT
178 info->rotation = HAL_TRANSFORM_ROT_90;
179 } else if (angle == 180) { // 180:HAL_TRANSFORM_ROT
180 info->rotation = HAL_TRANSFORM_ROT_180;
181 } else if (angle == 270) { // 270:HAL_TRANSFORM_ROT
182 info->rotation = HAL_TRANSFORM_ROT_270;
183 }
184 }
185 /*****************************************************************************/
186
187 #endif
188