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 | */ |
| 36 | #define OVERLAY_HARDWARE_OVERLAY0 "overlay0" |
| 37 | |
| 38 | /*****************************************************************************/ |
| 39 | |
| 40 | /* possible overlay formats */ |
| 41 | enum { |
| 42 | OVERLAY_FORMAT_RGBA_8888 = 1, |
| 43 | OVERLAY_FORMAT_RGB_565 = 4, |
| 44 | OVERLAY_FORMAT_BGRA_8888 = 5, |
| 45 | OVERLAY_FORMAT_YCbCr_422_SP = 0x10, |
| 46 | OVERLAY_FORMAT_YCbCr_420_SP = 0x11, |
| 47 | OVERLAY_FORMAT_YCbCr_422_P = 0x14, |
| 48 | OVERLAY_FORMAT_YCbCr_420_P = 0x15 |
| 49 | }; |
| 50 | |
| 51 | /* values for rotation */ |
| 52 | enum { |
| 53 | /* flip source image horizontally */ |
| 54 | OVERLAY_TRANSFORM_FLIP_H = 0x01, |
| 55 | /* flip source image vertically */ |
| 56 | OVERLAY_TRANSFORM_FLIP_V = 0x02, |
| 57 | /* rotate source image 90 degrees */ |
| 58 | OVERLAY_TRANSFORM_ROT_90 = 0x04, |
| 59 | /* rotate source image 180 degrees */ |
| 60 | OVERLAY_TRANSFORM_ROT_180 = 0x03, |
| 61 | /* rotate source image 270 degrees */ |
| 62 | OVERLAY_TRANSFORM_ROT_270 = 0x07, |
| 63 | }; |
| 64 | |
| 65 | /* names for setParameter() */ |
| 66 | enum { |
| 67 | OVERLAY_ROTATION_DEG = 1, |
| 68 | OVERLAY_DITHER = 3, |
| 69 | }; |
| 70 | |
| 71 | /* enable/disable value setParameter() */ |
| 72 | enum { |
| 73 | OVERLAY_DISABLE = 0, |
| 74 | OVERLAY_ENABLE = 1 |
| 75 | }; |
| 76 | |
| 77 | /* names for get() */ |
| 78 | enum { |
| 79 | /* Maximum amount of minification supported by the hardware*/ |
| 80 | OVERLAY_MINIFICATION_LIMIT = 1, |
| 81 | /* Maximum amount of magnification supported by the hardware */ |
| 82 | OVERLAY_MAGNIFICATION_LIMIT = 2, |
| 83 | /* Number of fractional bits support by the overlay scaling engine */ |
| 84 | OVERLAY_SCALING_FRAC_BITS = 3, |
| 85 | /* Supported rotation step in degrees. */ |
| 86 | OVERLAY_ROTATION_STEP_DEG = 4, |
| 87 | /* horizontal alignment in pixels */ |
| 88 | OVERLAY_HORIZONTAL_ALIGNMENT = 5, |
| 89 | /* vertical alignment in pixels */ |
| 90 | OVERLAY_VERTICAL_ALIGNMENT = 6, |
| 91 | /* width alignment restrictions. negative number for max. power-of-two */ |
| 92 | OVERLAY_WIDTH_ALIGNMENT = 7, |
| 93 | /* height alignment restrictions. negative number for max. power-of-two */ |
| 94 | OVERLAY_HEIGHT_ALIGNMENT = 8, |
| 95 | }; |
| 96 | |
| 97 | /*****************************************************************************/ |
| 98 | |
| 99 | /* opaque reference to an Overlay kernel object */ |
| 100 | typedef struct { |
| 101 | int numFds; |
| 102 | int fds[4]; |
| 103 | int numInts; |
| 104 | int data[0]; |
| 105 | } overlay_handle_t; |
| 106 | |
| 107 | typedef struct overlay_t { |
| 108 | uint32_t w; |
| 109 | uint32_t h; |
| 110 | int32_t format; |
| 111 | uint32_t w_stride; |
| 112 | uint32_t h_stride; |
| 113 | uint32_t reserved[3]; |
| 114 | /* returns a reference to this overlay's handle (the caller doesn't |
| 115 | * take ownership) */ |
| 116 | overlay_handle_t const* (*getHandleRef)(struct overlay_t* overlay); |
| 117 | uint32_t reserved_procs[7]; |
| 118 | } overlay_t; |
| 119 | |
| 120 | /*****************************************************************************/ |
| 121 | |
| 122 | /** |
| 123 | * Every hardware module must have a data structure named HAL_MODULE_INFO_SYM |
| 124 | * and the fields of this data structure must begin with hw_module_t |
| 125 | * followed by module specific information. |
| 126 | */ |
| 127 | struct overlay_module_t { |
| 128 | struct hw_module_t common; |
| 129 | }; |
| 130 | |
| 131 | /*****************************************************************************/ |
| 132 | |
| 133 | /** |
| 134 | * Every device data structure must begin with hw_device_t |
| 135 | * followed by module specific public methods and attributes. |
| 136 | */ |
| 137 | struct overlay_device_t { |
| 138 | struct hw_device_t common; |
| 139 | |
| 140 | /* get static informations about the capabilities of the overlay engine */ |
| 141 | int (*get)(struct overlay_device_t *dev, int name); |
| 142 | |
| 143 | /* creates an overlay matching the given parameters as closely as possible. |
| 144 | * returns an error if no more overlays are available. The actual |
| 145 | * size and format is returned in overlay_t. */ |
| 146 | overlay_t* (*createOverlay)(struct overlay_device_t *dev, |
| 147 | uint32_t w, uint32_t h, int32_t format); |
| 148 | |
| 149 | /* destroys an overlay. This call releases all |
| 150 | * resources associated with overlay_t and make it invalid */ |
| 151 | void (*destroyOverlay)(struct overlay_device_t *dev, |
| 152 | overlay_t* overlay); |
| 153 | |
| 154 | /* set position and scaling of the given overlay as closely as possible. |
| 155 | * if scaling cannot be performed, overlay must be centered. */ |
| 156 | int (*setPosition)(struct overlay_device_t *dev, |
| 157 | overlay_t* overlay, |
| 158 | int x, int y, uint32_t w, uint32_t h); |
| 159 | |
| 160 | /* returns the actual position and size of the overlay */ |
| 161 | int (*getPosition)(struct overlay_device_t *dev, |
| 162 | overlay_t* overlay, |
| 163 | int* x, int* y, uint32_t* w, uint32_t* h); |
| 164 | |
| 165 | /* sets configurable parameters for this overlay. returns an error if not |
| 166 | * supported. */ |
| 167 | int (*setParameter)(struct overlay_device_t *dev, |
| 168 | overlay_t* overlay, int param, int value); |
| 169 | |
| 170 | /* swaps overlay buffers for double-buffered overlay. the actual swap is |
| 171 | * synchronized with VSYNC. Typically, this function blocks until a new |
| 172 | * buffer is available. */ |
| 173 | int (*swapBuffers)(struct overlay_device_t *dev, |
| 174 | overlay_t* overlay); |
| 175 | |
| 176 | /* returns the offset in bytes of the current available buffer. When this |
| 177 | * function returns, the buffer is ready to be used immediately. Typically, |
| 178 | * this function blocks until a buffer is available. */ |
| 179 | int (*getOffset)(struct overlay_device_t *dev, |
| 180 | overlay_t* overlay); |
| 181 | |
| 182 | /* returns a filedescriptor that can be used to mmap() the overlay's |
| 183 | * memory. If this feature is not supported, an error is returned. */ |
| 184 | int (*getMemory)(struct overlay_device_t *dev); |
| 185 | }; |
| 186 | |
| 187 | /*****************************************************************************/ |
| 188 | |
| 189 | /** convenience API for opening and closing a device */ |
| 190 | |
| 191 | static inline int overlay_open(const struct hw_module_t* module, |
| 192 | struct overlay_device_t** device) { |
| 193 | return module->methods->open(module, |
| 194 | OVERLAY_HARDWARE_OVERLAY0, (struct hw_device_t**)device); |
| 195 | } |
| 196 | |
| 197 | static inline int overlay_close(struct overlay_device_t* device) { |
| 198 | return device->common.close(&device->common); |
| 199 | } |
| 200 | |
| 201 | |
| 202 | __END_DECLS |
| 203 | |
| 204 | #endif // ANDROID_OVERLAY_INTERFACE_H |