1 /* 2 * Copyright (C) 2008 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #ifndef ANDROID_COPYBIT_INTERFACE_H 18 #define ANDROID_COPYBIT_INTERFACE_H 19 20 #include <hardware/hardware.h> 21 22 #include <stdint.h> 23 #include <sys/cdefs.h> 24 #include <sys/types.h> 25 26 __BEGIN_DECLS 27 28 /** 29 * The id of this module 30 */ 31 #define COPYBIT_HARDWARE_MODULE_ID "copybit" 32 33 /** 34 * Name of the graphics device to open 35 */ 36 #define COPYBIT_HARDWARE_COPYBIT0 "copybit0" 37 38 /* supported pixel-formats. these must be compatible with 39 * graphics/PixelFormat.java, ui/PixelFormat.h, pixelflinger/format.h 40 */ 41 enum { 42 COPYBIT_FORMAT_RGBA_8888 = HAL_PIXEL_FORMAT_RGBA_8888, 43 COPYBIT_FORMAT_RGBX_8888 = HAL_PIXEL_FORMAT_RGBX_8888, 44 COPYBIT_FORMAT_RGB_888 = HAL_PIXEL_FORMAT_RGB_888, 45 COPYBIT_FORMAT_RGB_565 = HAL_PIXEL_FORMAT_RGB_565, 46 COPYBIT_FORMAT_BGRA_8888 = HAL_PIXEL_FORMAT_BGRA_8888, 47 COPYBIT_FORMAT_RGBA_5551 = HAL_PIXEL_FORMAT_RGBA_5551, 48 COPYBIT_FORMAT_RGBA_4444 = HAL_PIXEL_FORMAT_RGBA_4444, 49 COPYBIT_FORMAT_YCbCr_422_SP = 0x10, 50 COPYBIT_FORMAT_YCrCb_420_SP = 0x11, 51 }; 52 53 /* name for copybit_set_parameter */ 54 enum { 55 /* rotation of the source image in degrees (0 to 359) */ 56 COPYBIT_ROTATION_DEG = 1, 57 /* plane alpha value */ 58 COPYBIT_PLANE_ALPHA = 2, 59 /* enable or disable dithering */ 60 COPYBIT_DITHER = 3, 61 /* transformation applied (this is a superset of COPYBIT_ROTATION_DEG) */ 62 COPYBIT_TRANSFORM = 4, 63 /* blurs the copied bitmap. The amount of blurring cannot be changed 64 * at this time. */ 65 COPYBIT_BLUR = 5 66 }; 67 68 /* values for copybit_set_parameter(COPYBIT_TRANSFORM) */ 69 enum { 70 /* flip source image horizontally */ 71 COPYBIT_TRANSFORM_FLIP_H = HAL_TRANSFORM_FLIP_H, 72 /* flip source image vertically */ 73 COPYBIT_TRANSFORM_FLIP_V = HAL_TRANSFORM_FLIP_V, 74 /* rotate source image 90 degres */ 75 COPYBIT_TRANSFORM_ROT_90 = HAL_TRANSFORM_ROT_90, 76 /* rotate source image 180 degres */ 77 COPYBIT_TRANSFORM_ROT_180 = HAL_TRANSFORM_ROT_180, 78 /* rotate source image 270 degres */ 79 COPYBIT_TRANSFORM_ROT_270 = HAL_TRANSFORM_ROT_270, 80 }; 81 82 /* enable/disable value copybit_set_parameter */ 83 enum { 84 COPYBIT_DISABLE = 0, 85 COPYBIT_ENABLE = 1 86 }; 87 88 /* use get_static_info() to query static informations about the hardware */ 89 enum { 90 /* Maximum amount of minification supported by the hardware*/ 91 COPYBIT_MINIFICATION_LIMIT = 1, 92 /* Maximum amount of magnification supported by the hardware */ 93 COPYBIT_MAGNIFICATION_LIMIT = 2, 94 /* Number of fractional bits support by the scaling engine */ 95 COPYBIT_SCALING_FRAC_BITS = 3, 96 /* Supported rotation step in degres. */ 97 COPYBIT_ROTATION_STEP_DEG = 4, 98 }; 99 100 /* Image structure */ 101 struct copybit_image_t { 102 /* width */ 103 uint32_t w; 104 /* height */ 105 uint32_t h; 106 /* format COPYBIT_FORMAT_xxx */ 107 int32_t format; 108 /* base of buffer with image */ 109 void *base; 110 /* handle to the image */ 111 native_handle_t* handle; 112 }; 113 114 /* Rectangle */ 115 struct copybit_rect_t { 116 /* left */ 117 int l; 118 /* top */ 119 int t; 120 /* right */ 121 int r; 122 /* bottom */ 123 int b; 124 }; 125 126 /* Region */ 127 struct copybit_region_t { 128 int (*next)(struct copybit_region_t const *region, struct copybit_rect_t *rect); 129 }; 130 131 /** 132 * Every hardware module must have a data structure named HAL_MODULE_INFO_SYM 133 * and the fields of this data structure must begin with hw_module_t 134 * followed by module specific information. 135 */ 136 struct copybit_module_t { 137 struct hw_module_t common; 138 }; 139 140 /** 141 * Every device data structure must begin with hw_device_t 142 * followed by module specific public methods and attributes. 143 */ 144 struct copybit_device_t { 145 struct hw_device_t common; 146 147 /** 148 * Set a copybit parameter. 149 * 150 * @param dev from open 151 * @param name one for the COPYBIT_NAME_xxx 152 * @param value one of the COPYBIT_VALUE_xxx 153 * 154 * @return 0 if successful 155 */ 156 int (*set_parameter)(struct copybit_device_t *dev, int name, int value); 157 158 /** 159 * Get a static copybit information. 160 * 161 * @param dev from open 162 * @param name one of the COPYBIT_STATIC_xxx 163 * 164 * @return value or -EINVAL if error 165 */ 166 int (*get)(struct copybit_device_t *dev, int name); 167 168 /** 169 * Execute the bit blit copy operation 170 * 171 * @param dev from open 172 * @param dst is the destination image 173 * @param src is the source image 174 * @param region the clip region 175 * 176 * @return 0 if successful 177 */ 178 int (*blit)(struct copybit_device_t *dev, 179 struct copybit_image_t const *dst, 180 struct copybit_image_t const *src, 181 struct copybit_region_t const *region); 182 183 /** 184 * Execute the stretch bit blit copy operation 185 * 186 * @param dev from open 187 * @param dst is the destination image 188 * @param src is the source image 189 * @param dst_rect is the destination rectangle 190 * @param src_rect is the source rectangle 191 * @param region the clip region 192 * 193 * @return 0 if successful 194 */ 195 int (*stretch)(struct copybit_device_t *dev, 196 struct copybit_image_t const *dst, 197 struct copybit_image_t const *src, 198 struct copybit_rect_t const *dst_rect, 199 struct copybit_rect_t const *src_rect, 200 struct copybit_region_t const *region); 201 }; 202 203 204 /** convenience API for opening and closing a device */ 205 206 static inline int copybit_open(const struct hw_module_t* module, 207 struct copybit_device_t** device) { 208 return module->methods->open(module, 209 COPYBIT_HARDWARE_COPYBIT0, (struct hw_device_t**)device); 210 } 211 212 static inline int copybit_close(struct copybit_device_t* device) { 213 return device->common.close(&device->common); 214 } 215 216 217 __END_DECLS 218 219 #endif // ANDROID_COPYBIT_INTERFACE_H 220