copybit.h revision 10a67f20cf26b7a6e37ced8443b66c1cd93cc4d2
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 */ 45enum { 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 */ 58enum { 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) */ 83enum { 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 */ 97enum { 98 COPYBIT_DISABLE = 0, 99 COPYBIT_ENABLE = 1 100}; 101 102/* 103 * copybit blending values. same as HWC blending values 104 */ 105enum { 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 */ 117enum { 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 */ 129struct 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 */ 147struct 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 */ 159struct 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 */ 168struct 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 */ 176struct 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 * Give acquire fence to copybit to be used in upcoming stretch 217 * call 218 * 219 * @param dev from open 220 * @param acquireFenceFd is the acquire fence 221 * 222 * @return 0 if successful 223 */ 224 int (*set_sync)(struct copybit_device_t *dev, 225 int acquireFenceFd); 226 227 /** 228 * Execute the stretch bit blit copy operation 229 * 230 * @param dev from open 231 * @param dst is the destination image 232 * @param src is the source image 233 * @param dst_rect is the destination rectangle 234 * @param src_rect is the source rectangle 235 * @param region the clip region 236 * 237 * @return 0 if successful 238 */ 239 int (*stretch)(struct copybit_device_t *dev, 240 struct copybit_image_t const *dst, 241 struct copybit_image_t const *src, 242 struct copybit_rect_t const *dst_rect, 243 struct copybit_rect_t const *src_rect, 244 struct copybit_region_t const *region); 245 246 /** 247 * Execute the completion of the copybit draw operation. 248 * 249 * @param dev from open 250 * 251 * @return 0 if successful 252 */ 253 int (*finish)(struct copybit_device_t *dev); 254 255 /** 256 * Trigger the copybit draw operation(async). 257 * 258 * @param dev from open 259 * 260 * @param fd - gets the fencefd 261 * 262 * @return 0 if successful 263 */ 264 int (*flush_get_fence)(struct copybit_device_t *dev, int* fd); 265 266 /* Clears the buffer 267 */ 268 int (*clear)(struct copybit_device_t *dev, struct copybit_image_t const *buf, 269 struct copybit_rect_t *rect); 270}; 271 272 273/** convenience API for opening and closing a device */ 274 275static inline int copybit_open(const struct hw_module_t* module, 276 struct copybit_device_t** device) { 277 return module->methods->open(module, 278 COPYBIT_HARDWARE_COPYBIT0, (struct hw_device_t**)device); 279} 280 281static inline int copybit_close(struct copybit_device_t* device) { 282 return device->common.close(&device->common); 283} 284 285 286__END_DECLS 287 288#endif // ANDROID_COPYBIT_INTERFACE_H 289