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 | |
| 96 | enum HWCCompositionType { |
| 97 | HWC_USE_GPU = HWC_FRAMEBUFFER, // This layer is to be handled by Surfaceflinger |
| 98 | HWC_USE_OVERLAY = HWC_OVERLAY, // This layer is to be handled by the overlay |
| 99 | HWC_USE_COPYBIT // This layer is to be handled by copybit |
| 100 | }; |
| 101 | |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame^] | 102 | enum external_display_type { |
| 103 | EXT_TYPE_NONE, |
| 104 | EXT_TYPE_HDMI, |
| 105 | EXT_TYPE_WIFI |
| 106 | }; |
| 107 | |
| 108 | /* Events to the Display HAL perform function |
| 109 | As of now used for external display related such as |
| 110 | connect, disconnect, orientation, video started etc., |
| 111 | */ |
| 112 | enum { |
| 113 | EVENT_EXTERNAL_DISPLAY, // External display on/off Event |
| 114 | EVENT_VIDEO_OVERLAY, // Video Overlay start/stop Event |
| 115 | EVENT_ORIENTATION_CHANGE, // Orientation Change Event |
| 116 | EVENT_OVERLAY_STATE_CHANGE, // Overlay State Change Event |
| 117 | EVENT_OPEN_SECURE_START, // Start of secure session setup config by stagefright |
| 118 | EVENT_OPEN_SECURE_END, // End of secure session setup config by stagefright |
| 119 | EVENT_CLOSE_SECURE_START, // Start of secure session teardown config |
| 120 | EVENT_CLOSE_SECURE_END, // End of secure session teardown config |
| 121 | EVENT_RESET_POSTBUFFER, // Reset post framebuffer mutex |
| 122 | EVENT_WAIT_POSTBUFFER, // Wait until post framebuffer returns |
| 123 | }; |
| 124 | |
| 125 | // Video information sent to framebuffer HAl |
| 126 | // used for handling UI mirroring. |
| 127 | enum { |
| 128 | VIDEO_OVERLAY_ENDED = 0, |
| 129 | VIDEO_2D_OVERLAY_STARTED, |
| 130 | VIDEO_3D_OVERLAY_STARTED |
| 131 | }; |
| 132 | |
| 133 | // Information about overlay state change |
| 134 | enum { |
| 135 | OVERLAY_STATE_CHANGE_START = 0, |
| 136 | OVERLAY_STATE_CHANGE_END |
Iliyan Malchev | 202a77d | 2012-06-11 14:41:12 -0700 | [diff] [blame] | 137 | }; |
| 138 | |
| 139 | /* |
| 140 | * Structure to hold the buffer geometry |
| 141 | */ |
| 142 | struct qBufGeometry { |
| 143 | int width; |
| 144 | int height; |
| 145 | int format; |
| 146 | void set(int w, int h, int f) { |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame^] | 147 | width = w; |
| 148 | height = h; |
| 149 | format = f; |
Iliyan Malchev | 202a77d | 2012-06-11 14:41:12 -0700 | [diff] [blame] | 150 | } |
| 151 | }; |
| 152 | |
Iliyan Malchev | 202a77d | 2012-06-11 14:41:12 -0700 | [diff] [blame] | 153 | #if 0 |
| 154 | class QCBaseLayer |
| 155 | { |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame^] | 156 | // int mS3DFormat; |
Iliyan Malchev | 202a77d | 2012-06-11 14:41:12 -0700 | [diff] [blame] | 157 | int32_t mComposeS3DFormat; |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame^] | 158 | public: |
Iliyan Malchev | 202a77d | 2012-06-11 14:41:12 -0700 | [diff] [blame] | 159 | QCBaseLayer() |
| 160 | { |
| 161 | mComposeS3DFormat = 0; |
| 162 | } |
| 163 | enum { // S3D formats |
| 164 | eS3D_SIDE_BY_SIDE = 0x10000, |
| 165 | eS3D_TOP_BOTTOM = 0x20000 |
| 166 | }; |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame^] | 167 | /* |
| 168 | virtual status_t setStereoscopic3DFormat(int format) { mS3DFormat = format; return 0; } |
| 169 | virtual int getStereoscopic3DFormat() const { return mS3DFormat; } |
| 170 | */ |
Iliyan Malchev | 202a77d | 2012-06-11 14:41:12 -0700 | [diff] [blame] | 171 | void setS3DComposeFormat (int32_t hints) |
| 172 | { |
| 173 | if (hints & HWC_HINT_DRAW_S3D_SIDE_BY_SIDE) |
| 174 | mComposeS3DFormat = eS3D_SIDE_BY_SIDE; |
| 175 | else if (hints & HWC_HINT_DRAW_S3D_TOP_BOTTOM) |
| 176 | mComposeS3DFormat = eS3D_TOP_BOTTOM; |
| 177 | else |
| 178 | mComposeS3DFormat = 0; |
| 179 | } |
| 180 | int32_t needsS3DCompose () const { return mComposeS3DFormat; } |
| 181 | }; |
| 182 | #endif |
| 183 | |
| 184 | /* |
| 185 | * Function to check if the allocated buffer is of the correct size. |
| 186 | * Reallocate the buffer with the correct size, if the size doesn't |
| 187 | * match |
| 188 | * |
| 189 | * @param: handle of the allocated buffer |
| 190 | * @param: requested size for the buffer |
| 191 | * @param: usage flags |
| 192 | * |
| 193 | * return 0 on success |
| 194 | */ |
| 195 | int checkBuffer(native_handle_t *buffer_handle, int size, int usage); |
| 196 | |
| 197 | /* |
| 198 | * Checks if the format is supported by the GPU. |
| 199 | * |
| 200 | * @param: format to check |
| 201 | * |
| 202 | * @return true if the format is supported by the GPU. |
| 203 | */ |
| 204 | bool isGPUSupportedFormat(int format); |
| 205 | |
Iliyan Malchev | 202a77d | 2012-06-11 14:41:12 -0700 | [diff] [blame] | 206 | |
| 207 | /* |
| 208 | * Gets the number of arguments required for this operation. |
| 209 | * |
| 210 | * @param: operation whose argument count is required. |
| 211 | * |
| 212 | * @return -EINVAL if the operation is invalid. |
| 213 | */ |
| 214 | int getNumberOfArgsForOperation(int operation); |
| 215 | |
| 216 | /* |
| 217 | * Checks if memory needs to be reallocated for this buffer. |
| 218 | * |
| 219 | * @param: Geometry of the current buffer. |
| 220 | * @param: Required Geometry. |
| 221 | * @param: Geometry of the updated buffer. |
| 222 | * |
| 223 | * @return True if a memory reallocation is required. |
| 224 | */ |
| 225 | bool needNewBuffer(const qBufGeometry currentGeometry, |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame^] | 226 | const qBufGeometry requiredGeometry, |
| 227 | const qBufGeometry updatedGeometry); |
Iliyan Malchev | 202a77d | 2012-06-11 14:41:12 -0700 | [diff] [blame] | 228 | |
| 229 | /* |
| 230 | * Update the geometry of this buffer without reallocation. |
| 231 | * |
| 232 | * @param: buffer whose geometry needs to be updated. |
| 233 | * @param: Updated buffer geometry |
| 234 | */ |
| 235 | int updateBufferGeometry(sp<GraphicBuffer> buffer, const qBufGeometry bufGeometry); |
| 236 | |
| 237 | /* |
| 238 | * Update the S3D format of this buffer. |
| 239 | * |
| 240 | * @param: buffer whosei S3D format needs to be updated. |
| 241 | * @param: Updated buffer S3D format |
| 242 | */ |
| 243 | int updateBufferS3DFormat(sp<GraphicBuffer> buffer, const int s3dFormat); |
| 244 | |
| 245 | /* |
| 246 | * Updates the flags for the layer |
| 247 | * |
| 248 | * @param: Attribute |
| 249 | * @param: Identifies if the attribute was enabled or disabled. |
| 250 | * @param: current Layer flags. |
| 251 | * |
| 252 | * @return: Flags for the layer |
| 253 | */ |
| 254 | int updateLayerQcomFlags(eLayerAttrib attribute, bool enable, int& currentFlags); |
| 255 | |
| 256 | /* |
| 257 | * Gets the per frame HWC flags for this layer. |
| 258 | * |
| 259 | * @param: current hwcl flags |
| 260 | * @param: current layerFlags |
| 261 | * |
| 262 | * @return: the per frame flags. |
| 263 | */ |
| 264 | int getPerFrameFlags(int hwclFlags, int layerFlags); |
| 265 | |
| 266 | /* |
| 267 | * Checks if FB is updated by this composition type |
| 268 | * |
| 269 | * @param: composition type |
| 270 | * @return: true if FB is updated, false if not |
| 271 | */ |
| 272 | |
| 273 | bool isUpdatingFB(HWCCompositionType compositionType); |
| 274 | |
| 275 | /* |
Iliyan Malchev | 202a77d | 2012-06-11 14:41:12 -0700 | [diff] [blame] | 276 | * Clear region implementation for C2D/MDP versions. |
| 277 | * |
| 278 | * @param: region to be cleared |
| 279 | * @param: EGL Display |
| 280 | * @param: EGL Surface |
| 281 | * |
| 282 | * @return 0 on success |
| 283 | */ |
| 284 | int qcomuiClearRegion(Region region, EGLDisplay dpy, EGLSurface sur); |
| 285 | |
| 286 | /* |
| 287 | * Handles the externalDisplay event |
| 288 | * HDMI has highest priority compared to WifiDisplay |
| 289 | * Based on the current and the new display event, decides the |
| 290 | * external display to be enabled |
| 291 | * |
| 292 | * @param: newEvent - new external event |
| 293 | * @param: currEvent - currently enabled external event |
| 294 | * @return: external display to be enabled |
| 295 | * |
| 296 | */ |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame^] | 297 | external_display_type handleEventHDMI(external_display_type disp, int value, |
| 298 | external_display_type currDispType); |
Iliyan Malchev | 202a77d | 2012-06-11 14:41:12 -0700 | [diff] [blame] | 299 | /* |
| 300 | * Checks if layers need to be dumped based on system property "debug.sf.dump" |
| 301 | * for raw dumps and "debug.sf.dump.png" for png dumps. |
| 302 | * |
| 303 | * For example, to dump 25 frames in raw format, do, |
| 304 | * adb shell setprop debug.sf.dump 25 |
| 305 | * Layers are dumped in a time-stamped location: /data/sfdump*. |
| 306 | * |
| 307 | * To dump 10 frames in png format, do, |
| 308 | * adb shell setprop debug.sf.dump.png 10 |
| 309 | * To dump another 25 or so frames in raw format, do, |
| 310 | * adb shell setprop debug.sf.dump 26 |
| 311 | * |
| 312 | * To turn off logcat logging of layer-info, set both properties to 0, |
| 313 | * adb shell setprop debug.sf.dump.png 0 |
| 314 | * adb shell setprop debug.sf.dump 0 |
| 315 | * |
| 316 | * @return: true if layers need to be dumped (or logcat-ed). |
| 317 | */ |
| 318 | bool needToDumpLayers(); |
| 319 | |
| 320 | /* |
| 321 | * Dumps a layer's info into logcat and its buffer into raw/png files. |
| 322 | * |
| 323 | * @param: moduleCompositionType - Composition type set in hwcomposer module. |
| 324 | * @param: listFlags - Flags used in hwcomposer's list. |
| 325 | * @param: layerIndex - Index of layer being dumped. |
| 326 | * @param: hwLayers - Address of hwc_layer_t to log and dump. |
| 327 | * |
| 328 | */ |
| 329 | void dumpLayer(int moduleCompositionType, int listFlags, size_t layerIndex, |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame^] | 330 | hwc_layer_t hwLayers[]); |
| 331 | |
| 332 | bool needsAspectRatio (int wRatio, int hRatio); |
| 333 | void applyPixelAspectRatio (int wRatio, int hRatio, int orientation, int fbWidth, |
| 334 | int fbHeight, Rect& visibleRect, GLfloat vertices[][2]); |
Iliyan Malchev | 202a77d | 2012-06-11 14:41:12 -0700 | [diff] [blame] | 335 | |
| 336 | #endif // INCLUDE_LIBQCOM_UI |