Iliyan Malchev | 202a77d | 2012-06-11 14:41:12 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2011-2012, Code Aurora Forum. All rights reserved. |
| 3 | |
| 4 | * Redistribution and use in source and binary forms, with or without |
| 5 | * modification, are permitted provided that the following conditions are |
| 6 | * met: |
| 7 | * * Redistributions of source code must retain the above copyright |
| 8 | * notice, this list of conditions and the following disclaimer. |
| 9 | * * Redistributions in binary form must reproduce the above |
| 10 | * copyright notice, this list of conditions and the following |
| 11 | * disclaimer in the documentation and/or other materials provided |
| 12 | * with the distribution. |
| 13 | * * Neither the name of Code Aurora Forum, Inc. nor the names of its |
| 14 | * contributors may be used to endorse or promote products derived |
| 15 | * from this software without specific prior written permission. |
| 16 | * |
| 17 | * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED |
| 18 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
| 19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT |
| 20 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS |
| 21 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 22 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 23 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR |
| 24 | * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
| 25 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE |
| 26 | * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN |
| 27 | * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 28 | */ |
| 29 | |
| 30 | #ifndef INCLUDE_LIBQCOM_UI |
| 31 | #define INCLUDE_LIBQCOM_UI |
| 32 | |
| 33 | #include <cutils/native_handle.h> |
| 34 | #include <ui/GraphicBuffer.h> |
| 35 | #include <hardware/hwcomposer.h> |
Iliyan Malchev | 202a77d | 2012-06-11 14:41:12 -0700 | [diff] [blame] | 36 | #include <ui/Region.h> |
| 37 | #include <EGL/egl.h> |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 38 | #include <GLES/gl.h> |
Iliyan Malchev | 202a77d | 2012-06-11 14:41:12 -0700 | [diff] [blame] | 39 | #include <utils/Singleton.h> |
| 40 | #include <cutils/properties.h> |
Iliyan Malchev | 202a77d | 2012-06-11 14:41:12 -0700 | [diff] [blame] | 41 | |
| 42 | using namespace android; |
| 43 | using android::sp; |
| 44 | using android::GraphicBuffer; |
| 45 | |
| 46 | #define HWC_BYPASS_INDEX_MASK 0x00000030 |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 47 | #define DEFAULT_WIDTH_RATIO 1 |
| 48 | #define DEFAULT_HEIGHT_RATIO 1 |
Iliyan Malchev | 202a77d | 2012-06-11 14:41:12 -0700 | [diff] [blame] | 49 | |
| 50 | /* |
| 51 | * Qcom specific Native Window perform operations |
| 52 | */ |
| 53 | enum { |
| 54 | NATIVE_WINDOW_SET_BUFFERS_SIZE = 0x10000000, |
| 55 | NATIVE_WINDOW_UPDATE_BUFFERS_GEOMETRY = 0x20000000, |
| 56 | NATIVE_WINDOW_SET_S3D_FORMAT = 0x40000000, |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 57 | NATIVE_WINDOW_SET_PIXEL_ASPECT_RATIO = 0x80000000, |
Iliyan Malchev | 202a77d | 2012-06-11 14:41:12 -0700 | [diff] [blame] | 58 | }; |
| 59 | |
| 60 | /* |
| 61 | * Layer Attributes |
| 62 | */ |
| 63 | enum eLayerAttrib { |
| 64 | LAYER_UPDATE_STATUS, |
| 65 | LAYER_ASYNCHRONOUS_STATUS, |
| 66 | }; |
| 67 | |
| 68 | /* |
| 69 | * Layer Flags |
| 70 | */ |
| 71 | enum { |
| 72 | LAYER_UPDATING = 1<<0, |
| 73 | LAYER_ASYNCHRONOUS = 1<<1, |
| 74 | }; |
| 75 | |
| 76 | /* |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 77 | * Layer Transformation - refers to Layer::setGeometry() |
| 78 | */ |
| 79 | #define SHIFT_SRC_TRANSFORM 4 |
| 80 | #define SRC_TRANSFORM_MASK 0x00F0 |
| 81 | #define FINAL_TRANSFORM_MASK 0x000F |
| 82 | |
| 83 | /* |
Iliyan Malchev | 202a77d | 2012-06-11 14:41:12 -0700 | [diff] [blame] | 84 | * Flags set by the layer and sent to HWC |
| 85 | */ |
| 86 | enum { |
| 87 | HWC_LAYER_NOT_UPDATING = 0x00000002, |
| 88 | HWC_LAYER_ASYNCHRONOUS = 0x00000004, |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 89 | HWC_COMP_BYPASS = 0x10000000, |
| 90 | HWC_USE_EXT_ONLY = 0x20000000, //Layer displayed on external only |
| 91 | HWC_USE_EXT_BLOCK = 0x40000000, //Layer displayed on external only |
Iliyan Malchev | 202a77d | 2012-06-11 14:41:12 -0700 | [diff] [blame] | 92 | HWC_BYPASS_RESERVE_0 = 0x00000010, |
| 93 | HWC_BYPASS_RESERVE_1 = 0x00000020, |
| 94 | }; |
| 95 | |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 96 | /* Events to the Display HAL perform function |
| 97 | As of now used for external display related such as |
| 98 | connect, disconnect, orientation, video started etc., |
| 99 | */ |
| 100 | enum { |
| 101 | EVENT_EXTERNAL_DISPLAY, // External display on/off Event |
| 102 | EVENT_VIDEO_OVERLAY, // Video Overlay start/stop Event |
| 103 | EVENT_ORIENTATION_CHANGE, // Orientation Change Event |
| 104 | EVENT_OVERLAY_STATE_CHANGE, // Overlay State Change Event |
| 105 | EVENT_OPEN_SECURE_START, // Start of secure session setup config by stagefright |
| 106 | EVENT_OPEN_SECURE_END, // End of secure session setup config by stagefright |
| 107 | EVENT_CLOSE_SECURE_START, // Start of secure session teardown config |
| 108 | EVENT_CLOSE_SECURE_END, // End of secure session teardown config |
| 109 | EVENT_RESET_POSTBUFFER, // Reset post framebuffer mutex |
| 110 | EVENT_WAIT_POSTBUFFER, // Wait until post framebuffer returns |
| 111 | }; |
| 112 | |
| 113 | // Video information sent to framebuffer HAl |
| 114 | // used for handling UI mirroring. |
| 115 | enum { |
| 116 | VIDEO_OVERLAY_ENDED = 0, |
| 117 | VIDEO_2D_OVERLAY_STARTED, |
| 118 | VIDEO_3D_OVERLAY_STARTED |
| 119 | }; |
| 120 | |
| 121 | // Information about overlay state change |
| 122 | enum { |
| 123 | OVERLAY_STATE_CHANGE_START = 0, |
| 124 | OVERLAY_STATE_CHANGE_END |
Iliyan Malchev | 202a77d | 2012-06-11 14:41:12 -0700 | [diff] [blame] | 125 | }; |
| 126 | |
| 127 | /* |
| 128 | * Structure to hold the buffer geometry |
| 129 | */ |
| 130 | struct qBufGeometry { |
| 131 | int width; |
| 132 | int height; |
| 133 | int format; |
| 134 | void set(int w, int h, int f) { |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 135 | width = w; |
| 136 | height = h; |
| 137 | format = f; |
Iliyan Malchev | 202a77d | 2012-06-11 14:41:12 -0700 | [diff] [blame] | 138 | } |
| 139 | }; |
| 140 | |
Iliyan Malchev | 202a77d | 2012-06-11 14:41:12 -0700 | [diff] [blame] | 141 | #if 0 |
| 142 | class QCBaseLayer |
| 143 | { |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 144 | // int mS3DFormat; |
Iliyan Malchev | 202a77d | 2012-06-11 14:41:12 -0700 | [diff] [blame] | 145 | int32_t mComposeS3DFormat; |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 146 | public: |
Iliyan Malchev | 202a77d | 2012-06-11 14:41:12 -0700 | [diff] [blame] | 147 | QCBaseLayer() |
| 148 | { |
| 149 | mComposeS3DFormat = 0; |
| 150 | } |
| 151 | enum { // S3D formats |
| 152 | eS3D_SIDE_BY_SIDE = 0x10000, |
| 153 | eS3D_TOP_BOTTOM = 0x20000 |
| 154 | }; |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 155 | /* |
| 156 | virtual status_t setStereoscopic3DFormat(int format) { mS3DFormat = format; return 0; } |
| 157 | virtual int getStereoscopic3DFormat() const { return mS3DFormat; } |
| 158 | */ |
Iliyan Malchev | 202a77d | 2012-06-11 14:41:12 -0700 | [diff] [blame] | 159 | void setS3DComposeFormat (int32_t hints) |
| 160 | { |
| 161 | if (hints & HWC_HINT_DRAW_S3D_SIDE_BY_SIDE) |
| 162 | mComposeS3DFormat = eS3D_SIDE_BY_SIDE; |
| 163 | else if (hints & HWC_HINT_DRAW_S3D_TOP_BOTTOM) |
| 164 | mComposeS3DFormat = eS3D_TOP_BOTTOM; |
| 165 | else |
| 166 | mComposeS3DFormat = 0; |
| 167 | } |
| 168 | int32_t needsS3DCompose () const { return mComposeS3DFormat; } |
| 169 | }; |
| 170 | #endif |
| 171 | |
| 172 | /* |
| 173 | * Function to check if the allocated buffer is of the correct size. |
| 174 | * Reallocate the buffer with the correct size, if the size doesn't |
| 175 | * match |
| 176 | * |
| 177 | * @param: handle of the allocated buffer |
| 178 | * @param: requested size for the buffer |
| 179 | * @param: usage flags |
| 180 | * |
| 181 | * return 0 on success |
| 182 | */ |
| 183 | int checkBuffer(native_handle_t *buffer_handle, int size, int usage); |
| 184 | |
| 185 | /* |
| 186 | * Checks if the format is supported by the GPU. |
| 187 | * |
| 188 | * @param: format to check |
| 189 | * |
| 190 | * @return true if the format is supported by the GPU. |
| 191 | */ |
| 192 | bool isGPUSupportedFormat(int format); |
| 193 | |
Iliyan Malchev | 202a77d | 2012-06-11 14:41:12 -0700 | [diff] [blame] | 194 | |
| 195 | /* |
| 196 | * Gets the number of arguments required for this operation. |
| 197 | * |
| 198 | * @param: operation whose argument count is required. |
| 199 | * |
| 200 | * @return -EINVAL if the operation is invalid. |
| 201 | */ |
| 202 | int getNumberOfArgsForOperation(int operation); |
| 203 | |
| 204 | /* |
| 205 | * Checks if memory needs to be reallocated for this buffer. |
| 206 | * |
| 207 | * @param: Geometry of the current buffer. |
| 208 | * @param: Required Geometry. |
| 209 | * @param: Geometry of the updated buffer. |
| 210 | * |
| 211 | * @return True if a memory reallocation is required. |
| 212 | */ |
| 213 | bool needNewBuffer(const qBufGeometry currentGeometry, |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 214 | const qBufGeometry requiredGeometry, |
| 215 | const qBufGeometry updatedGeometry); |
Iliyan Malchev | 202a77d | 2012-06-11 14:41:12 -0700 | [diff] [blame] | 216 | |
| 217 | /* |
| 218 | * Update the geometry of this buffer without reallocation. |
| 219 | * |
| 220 | * @param: buffer whose geometry needs to be updated. |
| 221 | * @param: Updated buffer geometry |
| 222 | */ |
| 223 | int updateBufferGeometry(sp<GraphicBuffer> buffer, const qBufGeometry bufGeometry); |
| 224 | |
| 225 | /* |
| 226 | * Update the S3D format of this buffer. |
| 227 | * |
| 228 | * @param: buffer whosei S3D format needs to be updated. |
| 229 | * @param: Updated buffer S3D format |
| 230 | */ |
| 231 | int updateBufferS3DFormat(sp<GraphicBuffer> buffer, const int s3dFormat); |
| 232 | |
| 233 | /* |
| 234 | * Updates the flags for the layer |
| 235 | * |
| 236 | * @param: Attribute |
| 237 | * @param: Identifies if the attribute was enabled or disabled. |
| 238 | * @param: current Layer flags. |
| 239 | * |
| 240 | * @return: Flags for the layer |
| 241 | */ |
| 242 | int updateLayerQcomFlags(eLayerAttrib attribute, bool enable, int& currentFlags); |
| 243 | |
| 244 | /* |
| 245 | * Gets the per frame HWC flags for this layer. |
| 246 | * |
| 247 | * @param: current hwcl flags |
| 248 | * @param: current layerFlags |
| 249 | * |
| 250 | * @return: the per frame flags. |
| 251 | */ |
| 252 | int getPerFrameFlags(int hwclFlags, int layerFlags); |
| 253 | |
| 254 | /* |
| 255 | * Checks if FB is updated by this composition type |
| 256 | * |
| 257 | * @param: composition type |
| 258 | * @return: true if FB is updated, false if not |
| 259 | */ |
| 260 | |
| 261 | bool isUpdatingFB(HWCCompositionType compositionType); |
| 262 | |
| 263 | /* |
Iliyan Malchev | 202a77d | 2012-06-11 14:41:12 -0700 | [diff] [blame] | 264 | * Clear region implementation for C2D/MDP versions. |
| 265 | * |
| 266 | * @param: region to be cleared |
| 267 | * @param: EGL Display |
| 268 | * @param: EGL Surface |
| 269 | * |
| 270 | * @return 0 on success |
| 271 | */ |
| 272 | int qcomuiClearRegion(Region region, EGLDisplay dpy, EGLSurface sur); |
| 273 | |
| 274 | /* |
| 275 | * Handles the externalDisplay event |
| 276 | * HDMI has highest priority compared to WifiDisplay |
| 277 | * Based on the current and the new display event, decides the |
| 278 | * external display to be enabled |
| 279 | * |
| 280 | * @param: newEvent - new external event |
| 281 | * @param: currEvent - currently enabled external event |
| 282 | * @return: external display to be enabled |
| 283 | * |
| 284 | */ |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 285 | external_display_type handleEventHDMI(external_display_type disp, int value, |
| 286 | external_display_type currDispType); |
Iliyan Malchev | 202a77d | 2012-06-11 14:41:12 -0700 | [diff] [blame] | 287 | /* |
| 288 | * Checks if layers need to be dumped based on system property "debug.sf.dump" |
| 289 | * for raw dumps and "debug.sf.dump.png" for png dumps. |
| 290 | * |
| 291 | * For example, to dump 25 frames in raw format, do, |
| 292 | * adb shell setprop debug.sf.dump 25 |
| 293 | * Layers are dumped in a time-stamped location: /data/sfdump*. |
| 294 | * |
| 295 | * To dump 10 frames in png format, do, |
| 296 | * adb shell setprop debug.sf.dump.png 10 |
| 297 | * To dump another 25 or so frames in raw format, do, |
| 298 | * adb shell setprop debug.sf.dump 26 |
| 299 | * |
| 300 | * To turn off logcat logging of layer-info, set both properties to 0, |
| 301 | * adb shell setprop debug.sf.dump.png 0 |
| 302 | * adb shell setprop debug.sf.dump 0 |
| 303 | * |
| 304 | * @return: true if layers need to be dumped (or logcat-ed). |
| 305 | */ |
| 306 | bool needToDumpLayers(); |
| 307 | |
| 308 | /* |
| 309 | * Dumps a layer's info into logcat and its buffer into raw/png files. |
| 310 | * |
| 311 | * @param: moduleCompositionType - Composition type set in hwcomposer module. |
| 312 | * @param: listFlags - Flags used in hwcomposer's list. |
| 313 | * @param: layerIndex - Index of layer being dumped. |
| 314 | * @param: hwLayers - Address of hwc_layer_t to log and dump. |
| 315 | * |
| 316 | */ |
| 317 | void dumpLayer(int moduleCompositionType, int listFlags, size_t layerIndex, |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 318 | hwc_layer_t hwLayers[]); |
| 319 | |
| 320 | bool needsAspectRatio (int wRatio, int hRatio); |
| 321 | void applyPixelAspectRatio (int wRatio, int hRatio, int orientation, int fbWidth, |
| 322 | int fbHeight, Rect& visibleRect, GLfloat vertices[][2]); |
Iliyan Malchev | 202a77d | 2012-06-11 14:41:12 -0700 | [diff] [blame] | 323 | |
| 324 | #endif // INCLUDE_LIBQCOM_UI |