1 /*
2 * Copyright (C) 2008 The Android Open Source Project
3 * Copyright (c) 2012-2015, The Linux Foundation. All rights reserved.
4 *
5 * Not a Contribution, Apache license notifications and license are retained
6 * for attribution purposes only.
7 *
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
11 *
12 * http://www.apache.org/licenses/LICENSE-2.0
13 *
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 */
20
21 #ifndef ANDROID_COPYBIT_INTERFACE_H
22 #define ANDROID_COPYBIT_INTERFACE_H
23
24 #include <hardware/hardware.h>
25
26 #include <stdint.h>
27 #include <sys/cdefs.h>
28 #include <sys/types.h>
29 #include <gralloc_priv.h>
30
31 __BEGIN_DECLS
32
33 /**
34 * The id of this module
35 */
36 #define COPYBIT_HARDWARE_MODULE_ID "copybit"
37
38 /**
39 * Name of the graphics device to open
40 */
41 #define COPYBIT_HARDWARE_COPYBIT0 "copybit0"
42
43 /* supported pixel-formats. these must be compatible with
44 * graphics/PixelFormat.java, ui/PixelFormat.h, pixelflinger/format.h
45 */
46 enum {
47 COPYBIT_FORMAT_RGBA_8888 = HAL_PIXEL_FORMAT_RGBA_8888,
48 COPYBIT_FORMAT_RGBX_8888 = HAL_PIXEL_FORMAT_RGBX_8888,
49 COPYBIT_FORMAT_RGB_888 = HAL_PIXEL_FORMAT_RGB_888,
50 COPYBIT_FORMAT_RGB_565 = HAL_PIXEL_FORMAT_RGB_565,
51 COPYBIT_FORMAT_BGRA_8888 = HAL_PIXEL_FORMAT_BGRA_8888,
52 COPYBIT_FORMAT_RGBA_5551 = HAL_PIXEL_FORMAT_RGBA_5551,
53 COPYBIT_FORMAT_RGBA_4444 = HAL_PIXEL_FORMAT_RGBA_4444,
54 COPYBIT_FORMAT_YCbCr_422_SP = 0x10,
55 COPYBIT_FORMAT_YCrCb_420_SP = 0x11,
56 };
57
58 /* name for copybit_set_parameter */
59 enum {
60 /* Default blit destination is offline buffer */
61 /* clients to set this to '1', if blitting to framebuffer */
62 /* and reset to '0', after calling blit/stretch */
63 COPYBIT_BLIT_TO_FRAMEBUFFER = 0,
64 /* rotation of the source image in degrees (0 to 359) */
65 COPYBIT_ROTATION_DEG = 1,
66 /* plane alpha value */
67 COPYBIT_PLANE_ALPHA = 2,
68 /* enable or disable dithering */
69 COPYBIT_DITHER = 3,
70 /* transformation applied (this is a superset of COPYBIT_ROTATION_DEG) */
71 COPYBIT_TRANSFORM = 4,
72 /* blurs the copied bitmap. The amount of blurring cannot be changed
73 * at this time. */
74 COPYBIT_BLUR = 5,
75 /* Blend mode */
76 COPYBIT_BLEND_MODE = 6,
77 /* FB width */
78 COPYBIT_FRAMEBUFFER_WIDTH = 7,
79 /* FB height */
80 COPYBIT_FRAMEBUFFER_HEIGHT = 8,
81 COPYBIT_FG_LAYER = 9,
82 };
83
84 /* values for copybit_set_parameter(COPYBIT_TRANSFORM) */
85 enum {
86 /* flip source image horizontally */
87 COPYBIT_TRANSFORM_FLIP_H = HAL_TRANSFORM_FLIP_H,
88 /* flip source image vertically */
89 COPYBIT_TRANSFORM_FLIP_V = HAL_TRANSFORM_FLIP_V,
90 /* rotate source image 90 degres */
91 COPYBIT_TRANSFORM_ROT_90 = HAL_TRANSFORM_ROT_90,
92 /* rotate source image 180 degres */
93 COPYBIT_TRANSFORM_ROT_180 = HAL_TRANSFORM_ROT_180,
94 /* rotate source image 270 degres */
95 COPYBIT_TRANSFORM_ROT_270 = HAL_TRANSFORM_ROT_270,
96 };
97
98 /* enable/disable value copybit_set_parameter */
99 enum {
100 COPYBIT_DISABLE = 0,
101 COPYBIT_ENABLE = 1
102 };
103
104 /*
105 * copybit blending values. same as HWC blending values
106 */
107 enum {
108 /* no blending */
109 COPYBIT_BLENDING_NONE = 0x0100,
110
111 /* ONE / ONE_MINUS_SRC_ALPHA */
112 COPYBIT_BLENDING_PREMULT = 0x0105,
113
114 /* SRC_ALPHA / ONE_MINUS_SRC_ALPHA */
115 COPYBIT_BLENDING_COVERAGE = 0x0405
116 };
117
118 /* use get_static_info() to query static informations about the hardware */
119 enum {
120 /* Maximum amount of minification supported by the hardware*/
121 COPYBIT_MINIFICATION_LIMIT = 1,
122 /* Maximum amount of magnification supported by the hardware */
123 COPYBIT_MAGNIFICATION_LIMIT = 2,
124 /* Number of fractional bits support by the scaling engine */
125 COPYBIT_SCALING_FRAC_BITS = 3,
126 /* Supported rotation step in degres. */
127 COPYBIT_ROTATION_STEP_DEG = 4,
128 };
129
130 /* Image structure */
131 struct copybit_image_t {
132 /* width */
133 uint32_t w;
134 /* height */
135 uint32_t h;
136 /* format COPYBIT_FORMAT_xxx */
137 int32_t format;
138 /* base of buffer with image */
139 void *base;
140 /* handle to the image */
141 native_handle_t* handle;
142 /* number of pixels added for the stride */
143 uint32_t horiz_padding;
144 /* number of pixels added for the vertical stride */
145 uint32_t vert_padding;
146 };
147
148 /* Rectangle */
149 struct copybit_rect_t {
150 /* left */
151 int l;
152 /* top */
153 int t;
154 /* right */
155 int r;
156 /* bottom */
157 int b;
158 };
159
160 /* Region */
161 struct copybit_region_t {
162 int (*next)(struct copybit_region_t const *region, struct copybit_rect_t *rect);
163 };
164
165 /**
166 * Every hardware module must have a data structure named HAL_MODULE_INFO_SYM
167 * and the fields of this data structure must begin with hw_module_t
168 * followed by module specific information.
169 */
170 struct copybit_module_t {
171 struct hw_module_t common;
172 };
173
174 /**
175 * Every device data structure must begin with hw_device_t
176 * followed by module specific public methods and attributes.
177 */
178 struct copybit_device_t {
179 struct hw_device_t common;
180
181 /**
182 * Set a copybit parameter.
183 *
184 * @param dev from open
185 * @param name one for the COPYBIT_NAME_xxx
186 * @param value one of the COPYBIT_VALUE_xxx
187 *
188 * @return 0 if successful
189 */
190 int (*set_parameter)(struct copybit_device_t *dev, int name, int value);
191
192 /**
193 * Get a static copybit information.
194 *
195 * @param dev from open
196 * @param name one of the COPYBIT_STATIC_xxx
197 *
198 * @return value or -EINVAL if error
199 */
200 int (*get)(struct copybit_device_t *dev, int name);
201
202 /**
203 * Execute the bit blit copy operation
204 *
205 * @param dev from open
206 * @param dst is the destination image
207 * @param src is the source image
208 * @param region the clip region
209 *
210 * @return 0 if successful
211 */
212 int (*blit)(struct copybit_device_t *dev,
213 struct copybit_image_t const *dst,
214 struct copybit_image_t const *src,
215 struct copybit_region_t const *region);
216
217 /**
218 * Give acquire fence to copybit to be used in upcoming stretch
219 * call
220 *
221 * @param dev from open
222 * @param acquireFenceFd is the acquire fence
223 *
224 * @return 0 if successful
225 */
226 int (*set_sync)(struct copybit_device_t *dev,
227 int acquireFenceFd);
228
229 /**
230 * Execute the stretch bit blit copy operation
231 *
232 * @param dev from open
233 * @param dst is the destination image
234 * @param src is the source image
235 * @param dst_rect is the destination rectangle
236 * @param src_rect is the source rectangle
237 * @param region the clip region
238 *
239 * @return 0 if successful
240 */
241 int (*stretch)(struct copybit_device_t *dev,
242 struct copybit_image_t const *dst,
243 struct copybit_image_t const *src,
244 struct copybit_rect_t const *dst_rect,
245 struct copybit_rect_t const *src_rect,
246 struct copybit_region_t const *region);
247
248 /**
249 * Fill the rect on dst with RGBA color
250 *
251 * @param dev from open
252 * @param dst is destination image
253 * @param rect is destination rectangle
254 * @param color is RGBA color to fill
255 *
256 * @return 0 if successful
257 */
258 int (*fill_color)(struct copybit_device_t *dev,
259 struct copybit_image_t const *dst,
260 struct copybit_rect_t const *rect,
261 uint32_t color);
262
263 /**
264 * Execute the completion of the copybit draw operation.
265 *
266 * @param dev from open
267 *
268 * @return 0 if successful
269 */
270 int (*finish)(struct copybit_device_t *dev);
271
272 /**
273 * Trigger the copybit draw operation(async).
274 *
275 * @param dev from open
276 *
277 * @param fd - gets the fencefd
278 *
279 * @return 0 if successful
280 */
281 int (*flush_get_fence)(struct copybit_device_t *dev, int* fd);
282
283 /* Clears the buffer
284 */
285 int (*clear)(struct copybit_device_t *dev, struct copybit_image_t const *buf,
286 struct copybit_rect_t *rect);
287 };
288
289
290 /** convenience API for opening and closing a device */
291
copybit_open(const struct hw_module_t * module,struct copybit_device_t ** device)292 static inline int copybit_open(const struct hw_module_t* module,
293 struct copybit_device_t** device) {
294 return module->methods->open(module,
295 COPYBIT_HARDWARE_COPYBIT0, (struct hw_device_t**)device);
296 }
297
copybit_close(struct copybit_device_t * device)298 static inline int copybit_close(struct copybit_device_t* device) {
299 return device->common.close(&device->common);
300 }
301
302
303 __END_DECLS
304
305 #endif // ANDROID_COPYBIT_INTERFACE_H
306