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_RGBA_5551 = HAL_PIXEL_FORMAT_RGBA_5551, 52 COPYBIT_FORMAT_RGBA_4444 = HAL_PIXEL_FORMAT_RGBA_4444, 53 COPYBIT_FORMAT_YCbCr_422_SP = 0x10, 54 COPYBIT_FORMAT_YCrCb_420_SP = 0x11, 55 }; 56 57 /* name for copybit_set_parameter */ 58 enum { 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, 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, 74 /* Blend mode */ 75 COPYBIT_BLEND_MODE = 6, 76 /* FB width */ 77 COPYBIT_FRAMEBUFFER_WIDTH = 7, 78 /* FB height */ 79 COPYBIT_FRAMEBUFFER_HEIGHT = 8, 80 }; 81 82 /* values for copybit_set_parameter(COPYBIT_TRANSFORM) */ 83 enum { 84 /* flip source image horizontally */ 85 COPYBIT_TRANSFORM_FLIP_H = HAL_TRANSFORM_FLIP_H, 86 /* flip source image vertically */ 87 COPYBIT_TRANSFORM_FLIP_V = HAL_TRANSFORM_FLIP_V, 88 /* rotate source image 90 degres */ 89 COPYBIT_TRANSFORM_ROT_90 = HAL_TRANSFORM_ROT_90, 90 /* rotate source image 180 degres */ 91 COPYBIT_TRANSFORM_ROT_180 = HAL_TRANSFORM_ROT_180, 92 /* rotate source image 270 degres */ 93 COPYBIT_TRANSFORM_ROT_270 = HAL_TRANSFORM_ROT_270, 94 }; 95 96 /* enable/disable value copybit_set_parameter */ 97 enum { 98 COPYBIT_DISABLE = 0, 99 COPYBIT_ENABLE = 1 100 }; 101 102 /* 103 * copybit blending values. same as HWC blending values 104 */ 105 enum { 106 /* no blending */ 107 COPYBIT_BLENDING_NONE = 0x0100, 108 109 /* ONE / ONE_MINUS_SRC_ALPHA */ 110 COPYBIT_BLENDING_PREMULT = 0x0105, 111 112 /* SRC_ALPHA / ONE_MINUS_SRC_ALPHA */ 113 COPYBIT_BLENDING_COVERAGE = 0x0405 114 }; 115 116 /* use get_static_info() to query static informations about the hardware */ 117 enum { 118 /* Maximum amount of minification supported by the hardware*/ 119 COPYBIT_MINIFICATION_LIMIT = 1, 120 /* Maximum amount of magnification supported by the hardware */ 121 COPYBIT_MAGNIFICATION_LIMIT = 2, 122 /* Number of fractional bits support by the scaling engine */ 123 COPYBIT_SCALING_FRAC_BITS = 3, 124 /* Supported rotation step in degres. */ 125 COPYBIT_ROTATION_STEP_DEG = 4, 126 }; 127 128 /* Image structure */ 129 struct copybit_image_t { 130 /* width */ 131 uint32_t w; 132 /* height */ 133 uint32_t h; 134 /* format COPYBIT_FORMAT_xxx */ 135 int32_t format; 136 /* base of buffer with image */ 137 void *base; 138 /* handle to the image */ 139 native_handle_t* handle; 140 /* number of pixels added for the stride */ 141 uint32_t horiz_padding; 142 /* number of pixels added for the vertical stride */ 143 uint32_t vert_padding; 144 }; 145 146 /* Rectangle */ 147 struct copybit_rect_t { 148 /* left */ 149 int l; 150 /* top */ 151 int t; 152 /* right */ 153 int r; 154 /* bottom */ 155 int b; 156 }; 157 158 /* Region */ 159 struct copybit_region_t { 160 int (*next)(struct copybit_region_t const *region, struct copybit_rect_t *rect); 161 }; 162 163 /** 164 * Every hardware module must have a data structure named HAL_MODULE_INFO_SYM 165 * and the fields of this data structure must begin with hw_module_t 166 * followed by module specific information. 167 */ 168 struct copybit_module_t { 169 struct hw_module_t common; 170 }; 171 172 /** 173 * Every device data structure must begin with hw_device_t 174 * followed by module specific public methods and attributes. 175 */ 176 struct copybit_device_t { 177 struct hw_device_t common; 178 179 /** 180 * Set a copybit parameter. 181 * 182 * @param dev from open 183 * @param name one for the COPYBIT_NAME_xxx 184 * @param value one of the COPYBIT_VALUE_xxx 185 * 186 * @return 0 if successful 187 */ 188 int (*set_parameter)(struct copybit_device_t *dev, int name, int value); 189 190 /** 191 * Get a static copybit information. 192 * 193 * @param dev from open 194 * @param name one of the COPYBIT_STATIC_xxx 195 * 196 * @return value or -EINVAL if error 197 */ 198 int (*get)(struct copybit_device_t *dev, int name); 199 200 /** 201 * Execute the bit blit copy operation 202 * 203 * @param dev from open 204 * @param dst is the destination image 205 * @param src is the source image 206 * @param region the clip region 207 * 208 * @return 0 if successful 209 */ 210 int (*blit)(struct copybit_device_t *dev, 211 struct copybit_image_t const *dst, 212 struct copybit_image_t const *src, 213 struct copybit_region_t const *region); 214 215 /** 216 * Execute the stretch bit blit copy operation 217 * 218 * @param dev from open 219 * @param dst is the destination image 220 * @param src is the source image 221 * @param dst_rect is the destination rectangle 222 * @param src_rect is the source rectangle 223 * @param region the clip region 224 * 225 * @return 0 if successful 226 */ 227 int (*stretch)(struct copybit_device_t *dev, 228 struct copybit_image_t const *dst, 229 struct copybit_image_t const *src, 230 struct copybit_rect_t const *dst_rect, 231 struct copybit_rect_t const *src_rect, 232 struct copybit_region_t const *region); 233 234 /** 235 * Execute the completion of the copybit draw operation. 236 * 237 * @param dev from open 238 * 239 * @return 0 if successful 240 */ 241 int (*finish)(struct copybit_device_t *dev); 242 243 /** 244 * Trigger the copybit draw operation(async). 245 * 246 * @param dev from open 247 * 248 * @param fd - gets the fencefd 249 * 250 * @return 0 if successful 251 */ 252 int (*flush_get_fence)(struct copybit_device_t *dev, int* fd); 253 254 /* Clears the buffer 255 */ 256 int (*clear)(struct copybit_device_t *dev, struct copybit_image_t const *buf, 257 struct copybit_rect_t *rect); 258 }; 259 260 261 /** convenience API for opening and closing a device */ 262 263 static inline int copybit_open(const struct hw_module_t* module, 264 struct copybit_device_t** device) { 265 return module->methods->open(module, 266 COPYBIT_HARDWARE_COPYBIT0, (struct hw_device_t**)device); 267 } 268 269 static inline int copybit_close(struct copybit_device_t* device) { 270 return device->common.close(&device->common); 271 } 272 273 274 __END_DECLS 275 276 #endif // ANDROID_COPYBIT_INTERFACE_H 277