The Android Open Source Project | 51704be | 2008-12-17 18:05:50 -0800 | [diff] [blame] | 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_OVERLAY_INTERFACE_H |
| 18 | #define ANDROID_OVERLAY_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 OVERLAY_HARDWARE_MODULE_ID "overlay" |
| 32 | |
| 33 | /** |
| 34 | * Name of the overlay device to open |
| 35 | */ |
The Android Open Source Project | 699d24a | 2009-01-09 17:51:24 -0800 | [diff] [blame] | 36 | #define OVERLAY_HARDWARE_CONTROL "control" |
| 37 | #define OVERLAY_HARDWARE_DATA "data" |
The Android Open Source Project | 51704be | 2008-12-17 18:05:50 -0800 | [diff] [blame] | 38 | |
| 39 | /*****************************************************************************/ |
| 40 | |
| 41 | /* possible overlay formats */ |
| 42 | enum { |
| 43 | OVERLAY_FORMAT_RGBA_8888 = 1, |
| 44 | OVERLAY_FORMAT_RGB_565 = 4, |
| 45 | OVERLAY_FORMAT_BGRA_8888 = 5, |
| 46 | OVERLAY_FORMAT_YCbCr_422_SP = 0x10, |
| 47 | OVERLAY_FORMAT_YCbCr_420_SP = 0x11, |
The Android Open Source Project | 699d24a | 2009-01-09 17:51:24 -0800 | [diff] [blame] | 48 | OVERLAY_FORMAT_YCbCr_422_I = 0x14, |
| 49 | OVERLAY_FORMAT_YCbCr_420_I = 0x15 |
The Android Open Source Project | 51704be | 2008-12-17 18:05:50 -0800 | [diff] [blame] | 50 | }; |
| 51 | |
The Android Open Source Project | 699d24a | 2009-01-09 17:51:24 -0800 | [diff] [blame] | 52 | /* values for copybit_set_parameter(OVERLAY_TRANSFORM) */ |
The Android Open Source Project | 51704be | 2008-12-17 18:05:50 -0800 | [diff] [blame] | 53 | enum { |
| 54 | /* flip source image horizontally */ |
| 55 | OVERLAY_TRANSFORM_FLIP_H = 0x01, |
| 56 | /* flip source image vertically */ |
| 57 | OVERLAY_TRANSFORM_FLIP_V = 0x02, |
| 58 | /* rotate source image 90 degrees */ |
| 59 | OVERLAY_TRANSFORM_ROT_90 = 0x04, |
| 60 | /* rotate source image 180 degrees */ |
| 61 | OVERLAY_TRANSFORM_ROT_180 = 0x03, |
| 62 | /* rotate source image 270 degrees */ |
| 63 | OVERLAY_TRANSFORM_ROT_270 = 0x07, |
| 64 | }; |
| 65 | |
| 66 | /* names for setParameter() */ |
| 67 | enum { |
The Android Open Source Project | 699d24a | 2009-01-09 17:51:24 -0800 | [diff] [blame] | 68 | /* rotation of the source image in degrees (0 to 359) */ |
The Android Open Source Project | 51704be | 2008-12-17 18:05:50 -0800 | [diff] [blame] | 69 | OVERLAY_ROTATION_DEG = 1, |
The Android Open Source Project | 699d24a | 2009-01-09 17:51:24 -0800 | [diff] [blame] | 70 | /* enable or disable dithering */ |
The Android Open Source Project | 51704be | 2008-12-17 18:05:50 -0800 | [diff] [blame] | 71 | OVERLAY_DITHER = 3, |
The Android Open Source Project | 699d24a | 2009-01-09 17:51:24 -0800 | [diff] [blame] | 72 | /* transformation applied (this is a superset of COPYBIT_ROTATION_DEG) */ |
| 73 | OVERLAY_TRANSFORM = 4, |
The Android Open Source Project | 51704be | 2008-12-17 18:05:50 -0800 | [diff] [blame] | 74 | }; |
| 75 | |
| 76 | /* enable/disable value setParameter() */ |
| 77 | enum { |
| 78 | OVERLAY_DISABLE = 0, |
| 79 | OVERLAY_ENABLE = 1 |
| 80 | }; |
| 81 | |
| 82 | /* names for get() */ |
| 83 | enum { |
| 84 | /* Maximum amount of minification supported by the hardware*/ |
| 85 | OVERLAY_MINIFICATION_LIMIT = 1, |
| 86 | /* Maximum amount of magnification supported by the hardware */ |
| 87 | OVERLAY_MAGNIFICATION_LIMIT = 2, |
| 88 | /* Number of fractional bits support by the overlay scaling engine */ |
| 89 | OVERLAY_SCALING_FRAC_BITS = 3, |
| 90 | /* Supported rotation step in degrees. */ |
| 91 | OVERLAY_ROTATION_STEP_DEG = 4, |
| 92 | /* horizontal alignment in pixels */ |
| 93 | OVERLAY_HORIZONTAL_ALIGNMENT = 5, |
| 94 | /* vertical alignment in pixels */ |
| 95 | OVERLAY_VERTICAL_ALIGNMENT = 6, |
| 96 | /* width alignment restrictions. negative number for max. power-of-two */ |
| 97 | OVERLAY_WIDTH_ALIGNMENT = 7, |
| 98 | /* height alignment restrictions. negative number for max. power-of-two */ |
| 99 | OVERLAY_HEIGHT_ALIGNMENT = 8, |
| 100 | }; |
| 101 | |
| 102 | /*****************************************************************************/ |
| 103 | |
| 104 | /* opaque reference to an Overlay kernel object */ |
| 105 | typedef struct { |
| 106 | int numFds; |
| 107 | int fds[4]; |
| 108 | int numInts; |
| 109 | int data[0]; |
| 110 | } overlay_handle_t; |
| 111 | |
| 112 | typedef struct overlay_t { |
| 113 | uint32_t w; |
| 114 | uint32_t h; |
| 115 | int32_t format; |
| 116 | uint32_t w_stride; |
| 117 | uint32_t h_stride; |
| 118 | uint32_t reserved[3]; |
| 119 | /* returns a reference to this overlay's handle (the caller doesn't |
| 120 | * take ownership) */ |
| 121 | overlay_handle_t const* (*getHandleRef)(struct overlay_t* overlay); |
| 122 | uint32_t reserved_procs[7]; |
| 123 | } overlay_t; |
| 124 | |
The Android Open Source Project | 699d24a | 2009-01-09 17:51:24 -0800 | [diff] [blame] | 125 | typedef void* overlay_buffer_t; |
| 126 | |
The Android Open Source Project | 51704be | 2008-12-17 18:05:50 -0800 | [diff] [blame] | 127 | /*****************************************************************************/ |
| 128 | |
| 129 | /** |
| 130 | * Every hardware module must have a data structure named HAL_MODULE_INFO_SYM |
| 131 | * and the fields of this data structure must begin with hw_module_t |
| 132 | * followed by module specific information. |
| 133 | */ |
| 134 | struct overlay_module_t { |
| 135 | struct hw_module_t common; |
| 136 | }; |
| 137 | |
| 138 | /*****************************************************************************/ |
| 139 | |
| 140 | /** |
| 141 | * Every device data structure must begin with hw_device_t |
| 142 | * followed by module specific public methods and attributes. |
| 143 | */ |
The Android Open Source Project | 699d24a | 2009-01-09 17:51:24 -0800 | [diff] [blame] | 144 | |
| 145 | struct overlay_control_device_t { |
The Android Open Source Project | 51704be | 2008-12-17 18:05:50 -0800 | [diff] [blame] | 146 | struct hw_device_t common; |
| 147 | |
| 148 | /* get static informations about the capabilities of the overlay engine */ |
The Android Open Source Project | 699d24a | 2009-01-09 17:51:24 -0800 | [diff] [blame] | 149 | int (*get)(struct overlay_control_device_t *dev, int name); |
The Android Open Source Project | 51704be | 2008-12-17 18:05:50 -0800 | [diff] [blame] | 150 | |
| 151 | /* creates an overlay matching the given parameters as closely as possible. |
| 152 | * returns an error if no more overlays are available. The actual |
| 153 | * size and format is returned in overlay_t. */ |
The Android Open Source Project | 699d24a | 2009-01-09 17:51:24 -0800 | [diff] [blame] | 154 | overlay_t* (*createOverlay)(struct overlay_control_device_t *dev, |
The Android Open Source Project | 51704be | 2008-12-17 18:05:50 -0800 | [diff] [blame] | 155 | uint32_t w, uint32_t h, int32_t format); |
| 156 | |
| 157 | /* destroys an overlay. This call releases all |
| 158 | * resources associated with overlay_t and make it invalid */ |
The Android Open Source Project | 699d24a | 2009-01-09 17:51:24 -0800 | [diff] [blame] | 159 | void (*destroyOverlay)(struct overlay_control_device_t *dev, |
The Android Open Source Project | 51704be | 2008-12-17 18:05:50 -0800 | [diff] [blame] | 160 | overlay_t* overlay); |
| 161 | |
| 162 | /* set position and scaling of the given overlay as closely as possible. |
| 163 | * if scaling cannot be performed, overlay must be centered. */ |
The Android Open Source Project | 699d24a | 2009-01-09 17:51:24 -0800 | [diff] [blame] | 164 | int (*setPosition)(struct overlay_control_device_t *dev, |
The Android Open Source Project | 51704be | 2008-12-17 18:05:50 -0800 | [diff] [blame] | 165 | overlay_t* overlay, |
| 166 | int x, int y, uint32_t w, uint32_t h); |
| 167 | |
| 168 | /* returns the actual position and size of the overlay */ |
The Android Open Source Project | 699d24a | 2009-01-09 17:51:24 -0800 | [diff] [blame] | 169 | int (*getPosition)(struct overlay_control_device_t *dev, |
The Android Open Source Project | 51704be | 2008-12-17 18:05:50 -0800 | [diff] [blame] | 170 | overlay_t* overlay, |
| 171 | int* x, int* y, uint32_t* w, uint32_t* h); |
| 172 | |
| 173 | /* sets configurable parameters for this overlay. returns an error if not |
| 174 | * supported. */ |
The Android Open Source Project | 699d24a | 2009-01-09 17:51:24 -0800 | [diff] [blame] | 175 | int (*setParameter)(struct overlay_control_device_t *dev, |
The Android Open Source Project | 51704be | 2008-12-17 18:05:50 -0800 | [diff] [blame] | 176 | overlay_t* overlay, int param, int value); |
The Android Open Source Project | 51704be | 2008-12-17 18:05:50 -0800 | [diff] [blame] | 177 | }; |
| 178 | |
The Android Open Source Project | 699d24a | 2009-01-09 17:51:24 -0800 | [diff] [blame] | 179 | |
| 180 | struct overlay_data_device_t { |
| 181 | struct hw_device_t common; |
| 182 | |
| 183 | /* initialize the overlay from the given handle. this associates this |
| 184 | * overlay data module to its control module */ |
| 185 | int (*initialize)(struct overlay_data_device_t *dev, |
| 186 | overlay_handle_t const* handle); |
| 187 | |
| 188 | /* blocks until an overlay buffer is available and return that buffer. */ |
The Android Open Source Project | 0100d51 | 2009-01-15 16:12:12 -0800 | [diff] [blame^] | 189 | int (*dequeueBuffer)(struct overlay_data_device_t *dev, |
| 190 | overlay_buffer_t *buf); |
The Android Open Source Project | 699d24a | 2009-01-09 17:51:24 -0800 | [diff] [blame] | 191 | |
| 192 | /* release the overlay buffer and post it */ |
| 193 | int (*queueBuffer)(struct overlay_data_device_t *dev, |
| 194 | overlay_buffer_t buffer); |
| 195 | |
| 196 | /* returns the address of a given buffer if supported, NULL otherwise. */ |
| 197 | void* (*getBufferAddress)(struct overlay_data_device_t *dev, |
| 198 | overlay_buffer_t buffer); |
| 199 | }; |
| 200 | |
| 201 | |
The Android Open Source Project | 51704be | 2008-12-17 18:05:50 -0800 | [diff] [blame] | 202 | /*****************************************************************************/ |
| 203 | |
| 204 | /** convenience API for opening and closing a device */ |
| 205 | |
The Android Open Source Project | 699d24a | 2009-01-09 17:51:24 -0800 | [diff] [blame] | 206 | static inline int overlay_control_open(const struct hw_module_t* module, |
| 207 | struct overlay_control_device_t** device) { |
The Android Open Source Project | 51704be | 2008-12-17 18:05:50 -0800 | [diff] [blame] | 208 | return module->methods->open(module, |
The Android Open Source Project | 699d24a | 2009-01-09 17:51:24 -0800 | [diff] [blame] | 209 | OVERLAY_HARDWARE_CONTROL, (struct hw_device_t**)device); |
The Android Open Source Project | 51704be | 2008-12-17 18:05:50 -0800 | [diff] [blame] | 210 | } |
| 211 | |
The Android Open Source Project | 699d24a | 2009-01-09 17:51:24 -0800 | [diff] [blame] | 212 | static inline int overlay_control_close(struct overlay_control_device_t* device) { |
The Android Open Source Project | 51704be | 2008-12-17 18:05:50 -0800 | [diff] [blame] | 213 | return device->common.close(&device->common); |
| 214 | } |
| 215 | |
The Android Open Source Project | 699d24a | 2009-01-09 17:51:24 -0800 | [diff] [blame] | 216 | static inline int overlay_data_open(const struct hw_module_t* module, |
| 217 | struct overlay_data_device_t** device) { |
| 218 | return module->methods->open(module, |
| 219 | OVERLAY_HARDWARE_DATA, (struct hw_device_t**)device); |
| 220 | } |
| 221 | |
| 222 | static inline int overlay_data_close(struct overlay_data_device_t* device) { |
| 223 | return device->common.close(&device->common); |
| 224 | } |
The Android Open Source Project | 51704be | 2008-12-17 18:05:50 -0800 | [diff] [blame] | 225 | |
| 226 | __END_DECLS |
| 227 | |
| 228 | #endif // ANDROID_OVERLAY_INTERFACE_H |