blob: 1fc17ed9d310afbc3323970076e7e8e6337738f8 [file] [log] [blame]
Naseer Ahmed29a26812012-06-14 00:56:20 -07001/*
2 * Copyright (C) 2008 The Android Open Source Project
Arun Kumar K.R6364fa62015-01-08 16:08:51 -08003 * Copyright (c) 2012-2015, The Linux Foundation. All rights reserved.
Arun Kumar K.R6b353bd2012-11-27 17:18:45 -08004 *
5 * Not a Contribution, Apache license notifications and license are retained
6 * for attribution purposes only.
Naseer Ahmed29a26812012-06-14 00:56:20 -07007 *
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>
Arun Kumar K.R6364fa62015-01-08 16:08:51 -080029#include <gralloc_priv.h>
Naseer Ahmed29a26812012-06-14 00:56:20 -070030
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 */
46enum {
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,
Ramkumar Radhakrishnan96439522014-10-09 13:37:52 -070052 COPYBIT_FORMAT_RGBA_5551 = HAL_PIXEL_FORMAT_RGBA_5551,
53 COPYBIT_FORMAT_RGBA_4444 = HAL_PIXEL_FORMAT_RGBA_4444,
Naseer Ahmed29a26812012-06-14 00:56:20 -070054 COPYBIT_FORMAT_YCbCr_422_SP = 0x10,
55 COPYBIT_FORMAT_YCrCb_420_SP = 0x11,
56};
57
58/* name for copybit_set_parameter */
59enum {
Naseer Ahmed31da0b12012-07-31 18:55:33 -070060 /* 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,
Naseer Ahmed29a26812012-06-14 00:56:20 -070064 /* 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,
Arun Kumar K.R6b353bd2012-11-27 17:18:45 -080075 /* Blend mode */
76 COPYBIT_BLEND_MODE = 6,
Naseer Ahmed29a26812012-06-14 00:56:20 -070077 /* FB width */
78 COPYBIT_FRAMEBUFFER_WIDTH = 7,
79 /* FB height */
80 COPYBIT_FRAMEBUFFER_HEIGHT = 8,
Shivaraj Shettye86506a2013-08-06 12:56:30 +053081 COPYBIT_FG_LAYER = 9,
Ramakant Singh140965d2015-01-08 23:45:04 +053082 COPYBIT_DYNAMIC_FPS = 10,
Naseer Ahmed29a26812012-06-14 00:56:20 -070083};
84
85/* values for copybit_set_parameter(COPYBIT_TRANSFORM) */
86enum {
87 /* flip source image horizontally */
88 COPYBIT_TRANSFORM_FLIP_H = HAL_TRANSFORM_FLIP_H,
89 /* flip source image vertically */
90 COPYBIT_TRANSFORM_FLIP_V = HAL_TRANSFORM_FLIP_V,
91 /* rotate source image 90 degres */
92 COPYBIT_TRANSFORM_ROT_90 = HAL_TRANSFORM_ROT_90,
93 /* rotate source image 180 degres */
94 COPYBIT_TRANSFORM_ROT_180 = HAL_TRANSFORM_ROT_180,
95 /* rotate source image 270 degres */
96 COPYBIT_TRANSFORM_ROT_270 = HAL_TRANSFORM_ROT_270,
97};
98
99/* enable/disable value copybit_set_parameter */
100enum {
101 COPYBIT_DISABLE = 0,
102 COPYBIT_ENABLE = 1
103};
104
Arun Kumar K.R6b353bd2012-11-27 17:18:45 -0800105/*
106 * copybit blending values. same as HWC blending values
107 */
108enum {
109 /* no blending */
110 COPYBIT_BLENDING_NONE = 0x0100,
111
112 /* ONE / ONE_MINUS_SRC_ALPHA */
113 COPYBIT_BLENDING_PREMULT = 0x0105,
114
115 /* SRC_ALPHA / ONE_MINUS_SRC_ALPHA */
116 COPYBIT_BLENDING_COVERAGE = 0x0405
117};
118
Naseer Ahmed29a26812012-06-14 00:56:20 -0700119/* use get_static_info() to query static informations about the hardware */
120enum {
121 /* Maximum amount of minification supported by the hardware*/
122 COPYBIT_MINIFICATION_LIMIT = 1,
123 /* Maximum amount of magnification supported by the hardware */
124 COPYBIT_MAGNIFICATION_LIMIT = 2,
125 /* Number of fractional bits support by the scaling engine */
126 COPYBIT_SCALING_FRAC_BITS = 3,
127 /* Supported rotation step in degres. */
128 COPYBIT_ROTATION_STEP_DEG = 4,
129};
130
131/* Image structure */
132struct copybit_image_t {
133 /* width */
134 uint32_t w;
135 /* height */
136 uint32_t h;
137 /* format COPYBIT_FORMAT_xxx */
138 int32_t format;
139 /* base of buffer with image */
140 void *base;
141 /* handle to the image */
142 native_handle_t* handle;
143 /* number of pixels added for the stride */
144 uint32_t horiz_padding;
145 /* number of pixels added for the vertical stride */
146 uint32_t vert_padding;
147};
148
149/* Rectangle */
150struct copybit_rect_t {
151 /* left */
152 int l;
153 /* top */
154 int t;
155 /* right */
156 int r;
157 /* bottom */
158 int b;
159};
160
161/* Region */
162struct copybit_region_t {
163 int (*next)(struct copybit_region_t const *region, struct copybit_rect_t *rect);
164};
165
166/**
167 * Every hardware module must have a data structure named HAL_MODULE_INFO_SYM
168 * and the fields of this data structure must begin with hw_module_t
169 * followed by module specific information.
170 */
171struct copybit_module_t {
172 struct hw_module_t common;
173};
174
175/**
176 * Every device data structure must begin with hw_device_t
177 * followed by module specific public methods and attributes.
178 */
179struct copybit_device_t {
180 struct hw_device_t common;
181
182 /**
183 * Set a copybit parameter.
184 *
185 * @param dev from open
186 * @param name one for the COPYBIT_NAME_xxx
187 * @param value one of the COPYBIT_VALUE_xxx
188 *
189 * @return 0 if successful
190 */
191 int (*set_parameter)(struct copybit_device_t *dev, int name, int value);
192
193 /**
194 * Get a static copybit information.
195 *
196 * @param dev from open
197 * @param name one of the COPYBIT_STATIC_xxx
198 *
199 * @return value or -EINVAL if error
200 */
201 int (*get)(struct copybit_device_t *dev, int name);
202
203 /**
204 * Execute the bit blit copy operation
205 *
206 * @param dev from open
207 * @param dst is the destination image
208 * @param src is the source image
209 * @param region the clip region
210 *
211 * @return 0 if successful
212 */
213 int (*blit)(struct copybit_device_t *dev,
214 struct copybit_image_t const *dst,
215 struct copybit_image_t const *src,
216 struct copybit_region_t const *region);
217
218 /**
Terence Hampsonadf47302013-05-23 12:21:02 -0400219 * Give acquire fence to copybit to be used in upcoming stretch
220 * call
221 *
222 * @param dev from open
223 * @param acquireFenceFd is the acquire fence
224 *
225 * @return 0 if successful
226 */
227 int (*set_sync)(struct copybit_device_t *dev,
228 int acquireFenceFd);
229
230 /**
Naseer Ahmed29a26812012-06-14 00:56:20 -0700231 * Execute the stretch bit blit copy operation
232 *
233 * @param dev from open
234 * @param dst is the destination image
235 * @param src is the source image
236 * @param dst_rect is the destination rectangle
237 * @param src_rect is the source rectangle
238 * @param region the clip region
239 *
240 * @return 0 if successful
241 */
242 int (*stretch)(struct copybit_device_t *dev,
243 struct copybit_image_t const *dst,
244 struct copybit_image_t const *src,
245 struct copybit_rect_t const *dst_rect,
246 struct copybit_rect_t const *src_rect,
247 struct copybit_region_t const *region);
Arun Kumar K.R6b353bd2012-11-27 17:18:45 -0800248
Sushil Chauhan943797c2013-10-21 17:35:55 -0700249 /**
250 * Fill the rect on dst with RGBA color
251 *
252 * @param dev from open
253 * @param dst is destination image
254 * @param rect is destination rectangle
255 * @param color is RGBA color to fill
256 *
257 * @return 0 if successful
258 */
259 int (*fill_color)(struct copybit_device_t *dev,
260 struct copybit_image_t const *dst,
261 struct copybit_rect_t const *rect,
262 uint32_t color);
263
Arun Kumar K.R6b353bd2012-11-27 17:18:45 -0800264 /**
265 * Execute the completion of the copybit draw operation.
266 *
267 * @param dev from open
268 *
269 * @return 0 if successful
270 */
271 int (*finish)(struct copybit_device_t *dev);
272
Arun Kumar K.Reb128aa2012-12-18 12:38:28 -0800273 /**
274 * Trigger the copybit draw operation(async).
275 *
276 * @param dev from open
277 *
278 * @param fd - gets the fencefd
279 *
280 * @return 0 if successful
281 */
282 int (*flush_get_fence)(struct copybit_device_t *dev, int* fd);
Naseer Ahmed183939d2013-03-14 20:44:17 -0400283
284 /* Clears the buffer
285 */
286 int (*clear)(struct copybit_device_t *dev, struct copybit_image_t const *buf,
287 struct copybit_rect_t *rect);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700288};
289
290
291/** convenience API for opening and closing a device */
292
293static inline int copybit_open(const struct hw_module_t* module,
294 struct copybit_device_t** device) {
295 return module->methods->open(module,
296 COPYBIT_HARDWARE_COPYBIT0, (struct hw_device_t**)device);
297}
298
299static inline int copybit_close(struct copybit_device_t* device) {
300 return device->common.close(&device->common);
301}
302
303
304__END_DECLS
305
306#endif // ANDROID_COPYBIT_INTERFACE_H