Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2008 The Android Open Source Project |
Arun Kumar K.R | 6b353bd | 2012-11-27 17:18:45 -0800 | [diff] [blame] | 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. |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 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, |
Ramkumar Radhakrishnan | 9643952 | 2014-10-09 13:37:52 -0700 | [diff] [blame^] | 51 | COPYBIT_FORMAT_RGBA_5551 = HAL_PIXEL_FORMAT_RGBA_5551, |
| 52 | COPYBIT_FORMAT_RGBA_4444 = HAL_PIXEL_FORMAT_RGBA_4444, |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 53 | COPYBIT_FORMAT_YCbCr_422_SP = 0x10, |
| 54 | COPYBIT_FORMAT_YCrCb_420_SP = 0x11, |
| 55 | }; |
| 56 | |
| 57 | /* name for copybit_set_parameter */ |
| 58 | enum { |
Naseer Ahmed | 31da0b1 | 2012-07-31 18:55:33 -0700 | [diff] [blame] | 59 | /* Default blit destination is offline buffer */ |
| 60 | /* clients to set this to '1', if blitting to framebuffer */ |
| 61 | /* and reset to '0', after calling blit/stretch */ |
| 62 | COPYBIT_BLIT_TO_FRAMEBUFFER = 0, |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 63 | /* rotation of the source image in degrees (0 to 359) */ |
| 64 | COPYBIT_ROTATION_DEG = 1, |
| 65 | /* plane alpha value */ |
| 66 | COPYBIT_PLANE_ALPHA = 2, |
| 67 | /* enable or disable dithering */ |
| 68 | COPYBIT_DITHER = 3, |
| 69 | /* transformation applied (this is a superset of COPYBIT_ROTATION_DEG) */ |
| 70 | COPYBIT_TRANSFORM = 4, |
| 71 | /* blurs the copied bitmap. The amount of blurring cannot be changed |
| 72 | * at this time. */ |
| 73 | COPYBIT_BLUR = 5, |
Arun Kumar K.R | 6b353bd | 2012-11-27 17:18:45 -0800 | [diff] [blame] | 74 | /* Blend mode */ |
| 75 | COPYBIT_BLEND_MODE = 6, |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 76 | /* FB width */ |
| 77 | COPYBIT_FRAMEBUFFER_WIDTH = 7, |
| 78 | /* FB height */ |
| 79 | COPYBIT_FRAMEBUFFER_HEIGHT = 8, |
Shivaraj Shetty | e86506a | 2013-08-06 12:56:30 +0530 | [diff] [blame] | 80 | COPYBIT_FG_LAYER = 9, |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 81 | }; |
| 82 | |
| 83 | /* values for copybit_set_parameter(COPYBIT_TRANSFORM) */ |
| 84 | enum { |
| 85 | /* flip source image horizontally */ |
| 86 | COPYBIT_TRANSFORM_FLIP_H = HAL_TRANSFORM_FLIP_H, |
| 87 | /* flip source image vertically */ |
| 88 | COPYBIT_TRANSFORM_FLIP_V = HAL_TRANSFORM_FLIP_V, |
| 89 | /* rotate source image 90 degres */ |
| 90 | COPYBIT_TRANSFORM_ROT_90 = HAL_TRANSFORM_ROT_90, |
| 91 | /* rotate source image 180 degres */ |
| 92 | COPYBIT_TRANSFORM_ROT_180 = HAL_TRANSFORM_ROT_180, |
| 93 | /* rotate source image 270 degres */ |
| 94 | COPYBIT_TRANSFORM_ROT_270 = HAL_TRANSFORM_ROT_270, |
| 95 | }; |
| 96 | |
| 97 | /* enable/disable value copybit_set_parameter */ |
| 98 | enum { |
| 99 | COPYBIT_DISABLE = 0, |
| 100 | COPYBIT_ENABLE = 1 |
| 101 | }; |
| 102 | |
Arun Kumar K.R | 6b353bd | 2012-11-27 17:18:45 -0800 | [diff] [blame] | 103 | /* |
| 104 | * copybit blending values. same as HWC blending values |
| 105 | */ |
| 106 | enum { |
| 107 | /* no blending */ |
| 108 | COPYBIT_BLENDING_NONE = 0x0100, |
| 109 | |
| 110 | /* ONE / ONE_MINUS_SRC_ALPHA */ |
| 111 | COPYBIT_BLENDING_PREMULT = 0x0105, |
| 112 | |
| 113 | /* SRC_ALPHA / ONE_MINUS_SRC_ALPHA */ |
| 114 | COPYBIT_BLENDING_COVERAGE = 0x0405 |
| 115 | }; |
| 116 | |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 117 | /* use get_static_info() to query static informations about the hardware */ |
| 118 | enum { |
| 119 | /* Maximum amount of minification supported by the hardware*/ |
| 120 | COPYBIT_MINIFICATION_LIMIT = 1, |
| 121 | /* Maximum amount of magnification supported by the hardware */ |
| 122 | COPYBIT_MAGNIFICATION_LIMIT = 2, |
| 123 | /* Number of fractional bits support by the scaling engine */ |
| 124 | COPYBIT_SCALING_FRAC_BITS = 3, |
| 125 | /* Supported rotation step in degres. */ |
| 126 | COPYBIT_ROTATION_STEP_DEG = 4, |
| 127 | }; |
| 128 | |
| 129 | /* Image structure */ |
| 130 | struct copybit_image_t { |
| 131 | /* width */ |
| 132 | uint32_t w; |
| 133 | /* height */ |
| 134 | uint32_t h; |
| 135 | /* format COPYBIT_FORMAT_xxx */ |
| 136 | int32_t format; |
| 137 | /* base of buffer with image */ |
| 138 | void *base; |
| 139 | /* handle to the image */ |
| 140 | native_handle_t* handle; |
| 141 | /* number of pixels added for the stride */ |
| 142 | uint32_t horiz_padding; |
| 143 | /* number of pixels added for the vertical stride */ |
| 144 | uint32_t vert_padding; |
| 145 | }; |
| 146 | |
| 147 | /* Rectangle */ |
| 148 | struct copybit_rect_t { |
| 149 | /* left */ |
| 150 | int l; |
| 151 | /* top */ |
| 152 | int t; |
| 153 | /* right */ |
| 154 | int r; |
| 155 | /* bottom */ |
| 156 | int b; |
| 157 | }; |
| 158 | |
| 159 | /* Region */ |
| 160 | struct copybit_region_t { |
| 161 | int (*next)(struct copybit_region_t const *region, struct copybit_rect_t *rect); |
| 162 | }; |
| 163 | |
| 164 | /** |
| 165 | * Every hardware module must have a data structure named HAL_MODULE_INFO_SYM |
| 166 | * and the fields of this data structure must begin with hw_module_t |
| 167 | * followed by module specific information. |
| 168 | */ |
| 169 | struct copybit_module_t { |
| 170 | struct hw_module_t common; |
| 171 | }; |
| 172 | |
| 173 | /** |
| 174 | * Every device data structure must begin with hw_device_t |
| 175 | * followed by module specific public methods and attributes. |
| 176 | */ |
| 177 | struct copybit_device_t { |
| 178 | struct hw_device_t common; |
| 179 | |
| 180 | /** |
| 181 | * Set a copybit parameter. |
| 182 | * |
| 183 | * @param dev from open |
| 184 | * @param name one for the COPYBIT_NAME_xxx |
| 185 | * @param value one of the COPYBIT_VALUE_xxx |
| 186 | * |
| 187 | * @return 0 if successful |
| 188 | */ |
| 189 | int (*set_parameter)(struct copybit_device_t *dev, int name, int value); |
| 190 | |
| 191 | /** |
| 192 | * Get a static copybit information. |
| 193 | * |
| 194 | * @param dev from open |
| 195 | * @param name one of the COPYBIT_STATIC_xxx |
| 196 | * |
| 197 | * @return value or -EINVAL if error |
| 198 | */ |
| 199 | int (*get)(struct copybit_device_t *dev, int name); |
| 200 | |
| 201 | /** |
| 202 | * Execute the bit blit copy operation |
| 203 | * |
| 204 | * @param dev from open |
| 205 | * @param dst is the destination image |
| 206 | * @param src is the source image |
| 207 | * @param region the clip region |
| 208 | * |
| 209 | * @return 0 if successful |
| 210 | */ |
| 211 | int (*blit)(struct copybit_device_t *dev, |
| 212 | struct copybit_image_t const *dst, |
| 213 | struct copybit_image_t const *src, |
| 214 | struct copybit_region_t const *region); |
| 215 | |
| 216 | /** |
Terence Hampson | adf4730 | 2013-05-23 12:21:02 -0400 | [diff] [blame] | 217 | * Give acquire fence to copybit to be used in upcoming stretch |
| 218 | * call |
| 219 | * |
| 220 | * @param dev from open |
| 221 | * @param acquireFenceFd is the acquire fence |
| 222 | * |
| 223 | * @return 0 if successful |
| 224 | */ |
| 225 | int (*set_sync)(struct copybit_device_t *dev, |
| 226 | int acquireFenceFd); |
| 227 | |
| 228 | /** |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 229 | * Execute the stretch bit blit copy operation |
| 230 | * |
| 231 | * @param dev from open |
| 232 | * @param dst is the destination image |
| 233 | * @param src is the source image |
| 234 | * @param dst_rect is the destination rectangle |
| 235 | * @param src_rect is the source rectangle |
| 236 | * @param region the clip region |
| 237 | * |
| 238 | * @return 0 if successful |
| 239 | */ |
| 240 | int (*stretch)(struct copybit_device_t *dev, |
| 241 | struct copybit_image_t const *dst, |
| 242 | struct copybit_image_t const *src, |
| 243 | struct copybit_rect_t const *dst_rect, |
| 244 | struct copybit_rect_t const *src_rect, |
| 245 | struct copybit_region_t const *region); |
Arun Kumar K.R | 6b353bd | 2012-11-27 17:18:45 -0800 | [diff] [blame] | 246 | |
Sushil Chauhan | 943797c | 2013-10-21 17:35:55 -0700 | [diff] [blame] | 247 | /** |
| 248 | * Fill the rect on dst with RGBA color |
| 249 | * |
| 250 | * @param dev from open |
| 251 | * @param dst is destination image |
| 252 | * @param rect is destination rectangle |
| 253 | * @param color is RGBA color to fill |
| 254 | * |
| 255 | * @return 0 if successful |
| 256 | */ |
| 257 | int (*fill_color)(struct copybit_device_t *dev, |
| 258 | struct copybit_image_t const *dst, |
| 259 | struct copybit_rect_t const *rect, |
| 260 | uint32_t color); |
| 261 | |
Arun Kumar K.R | 6b353bd | 2012-11-27 17:18:45 -0800 | [diff] [blame] | 262 | /** |
| 263 | * Execute the completion of the copybit draw operation. |
| 264 | * |
| 265 | * @param dev from open |
| 266 | * |
| 267 | * @return 0 if successful |
| 268 | */ |
| 269 | int (*finish)(struct copybit_device_t *dev); |
| 270 | |
Arun Kumar K.R | eb128aa | 2012-12-18 12:38:28 -0800 | [diff] [blame] | 271 | /** |
| 272 | * Trigger the copybit draw operation(async). |
| 273 | * |
| 274 | * @param dev from open |
| 275 | * |
| 276 | * @param fd - gets the fencefd |
| 277 | * |
| 278 | * @return 0 if successful |
| 279 | */ |
| 280 | int (*flush_get_fence)(struct copybit_device_t *dev, int* fd); |
Naseer Ahmed | 183939d | 2013-03-14 20:44:17 -0400 | [diff] [blame] | 281 | |
| 282 | /* Clears the buffer |
| 283 | */ |
| 284 | int (*clear)(struct copybit_device_t *dev, struct copybit_image_t const *buf, |
| 285 | struct copybit_rect_t *rect); |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 286 | }; |
| 287 | |
| 288 | |
| 289 | /** convenience API for opening and closing a device */ |
| 290 | |
| 291 | static inline int copybit_open(const struct hw_module_t* module, |
| 292 | struct copybit_device_t** device) { |
| 293 | return module->methods->open(module, |
| 294 | COPYBIT_HARDWARE_COPYBIT0, (struct hw_device_t**)device); |
| 295 | } |
| 296 | |
| 297 | static inline int copybit_close(struct copybit_device_t* device) { |
| 298 | return device->common.close(&device->common); |
| 299 | } |
| 300 | |
| 301 | |
| 302 | __END_DECLS |
| 303 | |
| 304 | #endif // ANDROID_COPYBIT_INTERFACE_H |