1 /*
2 * Copyright (C) 2008 The Android Open Source Project
3 * Copyright (c) 2012-2013, 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
30 __BEGIN_DECLS
31
32 /**
33 * The id of this module
34 */
35 #define COPYBIT_HARDWARE_MODULE_ID "copybit"
36
37 /**
38 * Name of the graphics device to open
39 */
40 #define COPYBIT_HARDWARE_COPYBIT0 "copybit0"
41
42 /* supported pixel-formats. these must be compatible with
43 * graphics/PixelFormat.java, ui/PixelFormat.h, pixelflinger/format.h
44 */
45 enum {
46 COPYBIT_FORMAT_RGBA_8888 = HAL_PIXEL_FORMAT_RGBA_8888,
47 COPYBIT_FORMAT_RGBX_8888 = HAL_PIXEL_FORMAT_RGBX_8888,
48 COPYBIT_FORMAT_RGB_888 = HAL_PIXEL_FORMAT_RGB_888,
49 COPYBIT_FORMAT_RGB_565 = HAL_PIXEL_FORMAT_RGB_565,
50 COPYBIT_FORMAT_BGRA_8888 = HAL_PIXEL_FORMAT_BGRA_8888,
51 COPYBIT_FORMAT_YCbCr_422_SP = 0x10,
52 COPYBIT_FORMAT_YCrCb_420_SP = 0x11,
53 };
54
55 /* name for copybit_set_parameter */
56 enum {
57 /* Default blit destination is offline buffer */
58 /* clients to set this to '1', if blitting to framebuffer */
59 /* and reset to '0', after calling blit/stretch */
60 COPYBIT_BLIT_TO_FRAMEBUFFER = 0,
61 /* rotation of the source image in degrees (0 to 359) */
62 COPYBIT_ROTATION_DEG = 1,
63 /* plane alpha value */
64 COPYBIT_PLANE_ALPHA = 2,
65 /* enable or disable dithering */
66 COPYBIT_DITHER = 3,
67 /* transformation applied (this is a superset of COPYBIT_ROTATION_DEG) */
68 COPYBIT_TRANSFORM = 4,
69 /* blurs the copied bitmap. The amount of blurring cannot be changed
70 * at this time. */
71 COPYBIT_BLUR = 5,
72 /* Blend mode */
73 COPYBIT_BLEND_MODE = 6,
74 /* FB width */
75 COPYBIT_FRAMEBUFFER_WIDTH = 7,
76 /* FB height */
77 COPYBIT_FRAMEBUFFER_HEIGHT = 8,
78 };
79
80 /* values for copybit_set_parameter(COPYBIT_TRANSFORM) */
81 enum {
82 /* flip source image horizontally */
83 COPYBIT_TRANSFORM_FLIP_H = HAL_TRANSFORM_FLIP_H,
84 /* flip source image vertically */
85 COPYBIT_TRANSFORM_FLIP_V = HAL_TRANSFORM_FLIP_V,
86 /* rotate source image 90 degres */
87 COPYBIT_TRANSFORM_ROT_90 = HAL_TRANSFORM_ROT_90,
88 /* rotate source image 180 degres */
89 COPYBIT_TRANSFORM_ROT_180 = HAL_TRANSFORM_ROT_180,
90 /* rotate source image 270 degres */
91 COPYBIT_TRANSFORM_ROT_270 = HAL_TRANSFORM_ROT_270,
92 };
93
94 /* enable/disable value copybit_set_parameter */
95 enum {
96 COPYBIT_DISABLE = 0,
97 COPYBIT_ENABLE = 1
98 };
99
100 /*
101 * copybit blending values. same as HWC blending values
102 */
103 enum {
104 /* no blending */
105 COPYBIT_BLENDING_NONE = 0x0100,
106
107 /* ONE / ONE_MINUS_SRC_ALPHA */
108 COPYBIT_BLENDING_PREMULT = 0x0105,
109
110 /* SRC_ALPHA / ONE_MINUS_SRC_ALPHA */
111 COPYBIT_BLENDING_COVERAGE = 0x0405
112 };
113
114 /* use get_static_info() to query static informations about the hardware */
115 enum {
116 /* Maximum amount of minification supported by the hardware*/
117 COPYBIT_MINIFICATION_LIMIT = 1,
118 /* Maximum amount of magnification supported by the hardware */
119 COPYBIT_MAGNIFICATION_LIMIT = 2,
120 /* Number of fractional bits support by the scaling engine */
121 COPYBIT_SCALING_FRAC_BITS = 3,
122 /* Supported rotation step in degres. */
123 COPYBIT_ROTATION_STEP_DEG = 4,
124 };
125
126 /* Image structure */
127 struct copybit_image_t {
128 /* width */
129 uint32_t w;
130 /* height */
131 uint32_t h;
132 /* format COPYBIT_FORMAT_xxx */
133 int32_t format;
134 /* base of buffer with image */
135 void *base;
136 /* handle to the image */
137 native_handle_t* handle;
138 /* number of pixels added for the stride */
139 uint32_t horiz_padding;
140 /* number of pixels added for the vertical stride */
141 uint32_t vert_padding;
142 };
143
144 /* Rectangle */
145 struct copybit_rect_t {
146 /* left */
147 int l;
148 /* top */
149 int t;
150 /* right */
151 int r;
152 /* bottom */
153 int b;
154 };
155
156 /* Region */
157 struct copybit_region_t {
158 int (*next)(struct copybit_region_t const *region, struct copybit_rect_t *rect);
159 };
160
161 /**
162 * Every hardware module must have a data structure named HAL_MODULE_INFO_SYM
163 * and the fields of this data structure must begin with hw_module_t
164 * followed by module specific information.
165 */
166 struct copybit_module_t {
167 struct hw_module_t common;
168 };
169
170 /**
171 * Every device data structure must begin with hw_device_t
172 * followed by module specific public methods and attributes.
173 */
174 struct copybit_device_t {
175 struct hw_device_t common;
176
177 /**
178 * Set a copybit parameter.
179 *
180 * @param dev from open
181 * @param name one for the COPYBIT_NAME_xxx
182 * @param value one of the COPYBIT_VALUE_xxx
183 *
184 * @return 0 if successful
185 */
186 int (*set_parameter)(struct copybit_device_t *dev, int name, int value);
187
188 /**
189 * Get a static copybit information.
190 *
191 * @param dev from open
192 * @param name one of the COPYBIT_STATIC_xxx
193 *
194 * @return value or -EINVAL if error
195 */
196 int (*get)(struct copybit_device_t *dev, int name);
197
198 /**
199 * Execute the bit blit copy operation
200 *
201 * @param dev from open
202 * @param dst is the destination image
203 * @param src is the source image
204 * @param region the clip region
205 *
206 * @return 0 if successful
207 */
208 int (*blit)(struct copybit_device_t *dev,
209 struct copybit_image_t const *dst,
210 struct copybit_image_t const *src,
211 struct copybit_region_t const *region);
212
213 /**
214 * Execute the stretch bit blit copy operation
215 *
216 * @param dev from open
217 * @param dst is the destination image
218 * @param src is the source image
219 * @param dst_rect is the destination rectangle
220 * @param src_rect is the source rectangle
221 * @param region the clip region
222 *
223 * @return 0 if successful
224 */
225 int (*stretch)(struct copybit_device_t *dev,
226 struct copybit_image_t const *dst,
227 struct copybit_image_t const *src,
228 struct copybit_rect_t const *dst_rect,
229 struct copybit_rect_t const *src_rect,
230 struct copybit_region_t const *region);
231
232 /**
233 * Execute the completion of the copybit draw operation.
234 *
235 * @param dev from open
236 *
237 * @return 0 if successful
238 */
239 int (*finish)(struct copybit_device_t *dev);
240
241 /**
242 * Trigger the copybit draw operation(async).
243 *
244 * @param dev from open
245 *
246 * @param fd - gets the fencefd
247 *
248 * @return 0 if successful
249 */
250 int (*flush_get_fence)(struct copybit_device_t *dev, int* fd);
251
252 /* Clears the buffer
253 */
254 int (*clear)(struct copybit_device_t *dev, struct copybit_image_t const *buf,
255 struct copybit_rect_t *rect);
256 };
257
258
259 /** convenience API for opening and closing a device */
260
copybit_open(const struct hw_module_t * module,struct copybit_device_t ** device)261 static inline int copybit_open(const struct hw_module_t* module,
262 struct copybit_device_t** device) {
263 return module->methods->open(module,
264 COPYBIT_HARDWARE_COPYBIT0, (struct hw_device_t**)device);
265 }
266
copybit_close(struct copybit_device_t * device)267 static inline int copybit_close(struct copybit_device_t* device) {
268 return device->common.close(&device->common);
269 }
270
271
272 __END_DECLS
273
274 #endif // ANDROID_COPYBIT_INTERFACE_H
275