Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -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 OVERLAY_UTILS_H |
| 31 | #define OVERLAY_UTILS_H |
| 32 | |
| 33 | #include <cutils/log.h> // ALOGE, etc |
| 34 | #include <errno.h> |
| 35 | #include <fcntl.h> // open, O_RDWR, etc |
| 36 | #include <hardware/hardware.h> |
| 37 | #include <hardware/gralloc.h> // buffer_handle_t |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 38 | #include <linux/msm_mdp.h> // flags |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 39 | #include <stdio.h> |
| 40 | #include <stdlib.h> |
| 41 | #include <string.h> |
| 42 | #include <sys/stat.h> |
| 43 | #include <sys/types.h> |
| 44 | #include <utils/Log.h> |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 45 | #include "gralloc_priv.h" //for interlace |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 46 | /* |
| 47 | * |
| 48 | * Collection of utilities functions/structs/enums etc... |
| 49 | * |
| 50 | * */ |
| 51 | |
| 52 | // comment that out if you want to remove asserts |
| 53 | // or put it as -D in Android.mk. your choice. |
| 54 | #define OVERLAY_HAS_ASSERT |
| 55 | |
| 56 | #ifdef OVERLAY_HAS_ASSERT |
| 57 | # define OVASSERT(x, ...) if(!(x)) { ALOGE(__VA_ARGS__); abort(); } |
| 58 | #else |
| 59 | # define OVASSERT(x, ...) ALOGE_IF(!(x), __VA_ARGS__) |
| 60 | #endif // OVERLAY_HAS_ASSERT |
| 61 | |
| 62 | #define DEBUG_OVERLAY 0 |
| 63 | #define PROFILE_OVERLAY 0 |
| 64 | |
| 65 | namespace overlay { |
| 66 | |
| 67 | // fwd |
| 68 | class Overlay; |
Saurabh Shah | e012f7a | 2012-08-18 15:11:57 -0700 | [diff] [blame] | 69 | class OvFD; |
| 70 | |
| 71 | /* helper function to open by using fbnum */ |
| 72 | bool open(OvFD& fd, uint32_t fbnum, const char* const dev, |
| 73 | int flags = O_RDWR); |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 74 | |
| 75 | namespace utils { |
| 76 | struct Whf; |
| 77 | struct Dim; |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 78 | |
| 79 | inline uint32_t setBit(uint32_t x, uint32_t mask) { |
| 80 | return (x | mask); |
| 81 | } |
| 82 | |
| 83 | inline uint32_t clrBit(uint32_t x, uint32_t mask) { |
| 84 | return (x & ~mask); |
| 85 | } |
| 86 | |
| 87 | /* Utility class to help avoid copying instances by making the copy ctor |
| 88 | * and assignment operator private |
| 89 | * |
| 90 | * Usage: |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 91 | * class SomeClass : utils::NoCopy {...}; |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 92 | */ |
| 93 | class NoCopy { |
| 94 | protected: |
| 95 | NoCopy(){} |
| 96 | ~NoCopy() {} |
| 97 | private: |
| 98 | NoCopy(const NoCopy&); |
| 99 | const NoCopy& operator=(const NoCopy&); |
| 100 | }; |
| 101 | |
| 102 | /* |
| 103 | * Utility class to query the framebuffer info for primary display |
| 104 | * |
| 105 | * Usage: |
| 106 | * Outside of functions: |
| 107 | * utils::FrameBufferInfo* utils::FrameBufferInfo::sFBInfoInstance = 0; |
| 108 | * Inside functions: |
| 109 | * utils::FrameBufferInfo::getInstance()->supportTrueMirroring() |
| 110 | */ |
| 111 | class FrameBufferInfo { |
| 112 | |
| 113 | public: |
| 114 | /* ctor init */ |
| 115 | explicit FrameBufferInfo(); |
| 116 | |
| 117 | /* Gets an instance if one does not already exist */ |
| 118 | static FrameBufferInfo* getInstance(); |
| 119 | |
| 120 | /* Gets width of primary framebuffer */ |
| 121 | int getWidth() const; |
| 122 | |
| 123 | /* Gets height of primary framebuffer */ |
| 124 | int getHeight() const; |
| 125 | |
| 126 | /* Indicates whether true mirroring is supported */ |
| 127 | bool supportTrueMirroring() const; |
| 128 | |
| 129 | private: |
| 130 | int mFBWidth; |
| 131 | int mFBHeight; |
| 132 | bool mBorderFillSupported; |
| 133 | static FrameBufferInfo *sFBInfoInstance; |
| 134 | }; |
| 135 | |
| 136 | /* 3D related utils, defines etc... |
| 137 | * The compound format passed to the overlay is |
| 138 | * ABCCC where A is the input 3D format |
| 139 | * B is the output 3D format |
| 140 | * CCC is the color format e.g YCbCr420SP YCrCb420SP etc */ |
| 141 | enum { SHIFT_OUT_3D = 12, |
| 142 | SHIFT_TOT_3D = 16 }; |
| 143 | enum { INPUT_3D_MASK = 0xFFFF0000, |
| 144 | OUTPUT_3D_MASK = 0x0000FFFF }; |
| 145 | enum { BARRIER_LAND = 1, |
| 146 | BARRIER_PORT = 2 }; |
| 147 | |
| 148 | inline uint32_t format3D(uint32_t x) { return x & 0xFF000; } |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 149 | inline uint32_t colorFormat(uint32_t fmt) { |
| 150 | /*TODO enable this block only if format has interlace / 3D info in top bits. |
| 151 | if(fmt & INTERLACE_MASK) { |
| 152 | fmt = fmt ^ HAL_PIXEL_FORMAT_INTERLACE; |
| 153 | } |
| 154 | fmt = fmt & 0xFFF;*/ |
| 155 | return fmt; |
| 156 | } |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 157 | inline uint32_t format3DOutput(uint32_t x) { |
| 158 | return (x & 0xF000) >> SHIFT_OUT_3D; } |
| 159 | inline uint32_t format3DInput(uint32_t x) { return x & 0xF0000; } |
| 160 | uint32_t getColorFormat(uint32_t format); |
| 161 | |
| 162 | bool isHDMIConnected (); |
| 163 | bool is3DTV(); |
| 164 | bool isPanel3D(); |
| 165 | bool usePanel3D(); |
| 166 | bool send3DInfoPacket (uint32_t fmt); |
| 167 | bool enableBarrier (uint32_t orientation); |
| 168 | uint32_t getS3DFormat(uint32_t fmt); |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 169 | |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 170 | template <int CHAN> |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 171 | bool getPositionS3D(const Whf& whf, Dim& out); |
| 172 | |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 173 | template <int CHAN> |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 174 | bool getCropS3D(const Dim& in, Dim& out, uint32_t fmt); |
| 175 | |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 176 | template <class Type> |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 177 | void swapWidthHeight(Type& width, Type& height); |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 178 | |
| 179 | struct Dim { |
| 180 | Dim () : x(0), y(0), |
| 181 | w(0), h(0), |
| 182 | o(0) {} |
| 183 | Dim(uint32_t _x, uint32_t _y, uint32_t _w, uint32_t _h) : |
| 184 | x(_x), y(_y), |
| 185 | w(_w), h(_h) {} |
| 186 | Dim(uint32_t _x, uint32_t _y, uint32_t _w, uint32_t _h, uint32_t _o) : |
| 187 | x(_x), y(_y), |
| 188 | w(_w), h(_h), |
| 189 | o(_o) {} |
| 190 | bool check(uint32_t _w, uint32_t _h) const { |
| 191 | return (x+w <= _w && y+h <= _h); |
| 192 | |
| 193 | } |
| 194 | |
| 195 | bool operator==(const Dim& d) const { |
| 196 | return d.x == x && d.y == y && |
| 197 | d.w == w && d.h == h && |
| 198 | d.o == o; |
| 199 | } |
| 200 | |
| 201 | bool operator!=(const Dim& d) const { |
| 202 | return !operator==(d); |
| 203 | } |
| 204 | |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 205 | void dump() const; |
| 206 | uint32_t x; |
| 207 | uint32_t y; |
| 208 | uint32_t w; |
| 209 | uint32_t h; |
| 210 | uint32_t o; |
| 211 | }; |
| 212 | |
| 213 | // TODO have Whfz |
| 214 | |
| 215 | struct Whf { |
| 216 | Whf() : w(0), h(0), format(0), size(0) {} |
| 217 | Whf(uint32_t wi, uint32_t he, uint32_t f) : |
| 218 | w(wi), h(he), format(f), size(0) {} |
| 219 | Whf(uint32_t wi, uint32_t he, uint32_t f, uint32_t s) : |
| 220 | w(wi), h(he), format(f), size(s) {} |
| 221 | // FIXME not comparing size at the moment |
| 222 | bool operator==(const Whf& whf) const { |
| 223 | return whf.w == w && whf.h == h && |
| 224 | whf.format == format; |
| 225 | } |
| 226 | bool operator!=(const Whf& whf) const { |
| 227 | return !operator==(whf); |
| 228 | } |
| 229 | void dump() const; |
| 230 | uint32_t w; |
| 231 | uint32_t h; |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 232 | uint32_t format; |
| 233 | uint32_t size; |
| 234 | }; |
| 235 | |
| 236 | enum { MAX_PATH_LEN = 256 }; |
| 237 | |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 238 | /** |
| 239 | * Rotator flags: not to be confused with orientation flags. |
| 240 | * Ususally, you want to open the rotator to make sure it is |
| 241 | * ready for business. |
| 242 | * ROT_FLAG_DISABLED: Rotator would not kick in. (ioctl will emit errors). |
| 243 | * ROT_FLAG_ENABLED: and when rotation is needed. |
| 244 | * (prim video playback) |
| 245 | * (UI mirroring on HDMI w/ 0 degree rotator. - just memcpy) |
| 246 | * In HDMI UI mirroring, rotator is always used. |
| 247 | * Even when w/o orienation change on primary, |
| 248 | * we do 0 rotation on HDMI and using rotator buffers. |
| 249 | * That is because we might see tearing otherwise. so |
| 250 | * we use another buffer (rotator). |
| 251 | * When a simple video playback on HDMI, no rotator is being used.(null r). |
| 252 | * */ |
| 253 | enum eRotFlags { |
| 254 | ROT_FLAG_DISABLED = 0, |
| 255 | ROT_FLAG_ENABLED = 1 // needed in rot |
| 256 | }; |
| 257 | |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 258 | /* The values for is_fg flag for control alpha and transp |
| 259 | * IS_FG_OFF means is_fg = 0 |
| 260 | * IS_FG_SET means is_fg = 1 |
| 261 | */ |
| 262 | enum eIsFg { |
| 263 | IS_FG_OFF = 0, |
| 264 | IS_FG_SET = 1 |
| 265 | }; |
| 266 | |
| 267 | /* |
| 268 | * Various mdp flags like PIPE SHARE, DEINTERLACE etc... |
| 269 | * kernel/common/linux/msm_mdp.h |
| 270 | * INTERLACE_MASK: hardware/qcom/display/libgralloc/badger/fb_priv.h |
| 271 | * */ |
| 272 | enum eMdpFlags { |
| 273 | OV_MDP_FLAGS_NONE = 0, |
| 274 | OV_MDP_PIPE_SHARE = MDP_OV_PIPE_SHARE, |
| 275 | OV_MDP_DEINTERLACE = MDP_DEINTERLACE, |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 276 | OV_MDP_SECURE_OVERLAY_SESSION = MDP_SECURE_OVERLAY_SESSION, |
| 277 | OV_MDP_SOURCE_ROTATED_90 = MDP_SOURCE_ROTATED_90, |
| 278 | OV_MDP_MEMORY_ID_TYPE_FB = MDP_MEMORY_ID_TYPE_FB, |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 279 | }; |
| 280 | |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 281 | enum eZorder { |
| 282 | ZORDER_0, |
| 283 | ZORDER_1, |
| 284 | ZORDER_2, |
| 285 | Z_SYSTEM_ALLOC = 0xFFFF |
| 286 | }; |
| 287 | |
| 288 | enum eMdpPipeType { |
| 289 | OV_MDP_PIPE_RGB, |
| 290 | OV_MDP_PIPE_VG |
| 291 | }; |
| 292 | |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 293 | // Max pipes via overlay (VG0, VG1, RGB1) |
| 294 | enum { MAX_PIPES = 3 }; |
| 295 | |
| 296 | /* Used to identify destination channels and |
| 297 | * also 3D channels e.g. when in 3D mode with 2 |
| 298 | * pipes opened and it is used in get crop/pos 3D |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 299 | * */ |
| 300 | enum eDest { |
| 301 | OV_PIPE0 = 1 << 0, |
| 302 | OV_PIPE1 = 1 << 1, |
| 303 | OV_PIPE2 = 1 << 2, |
| 304 | OV_PIPE_ALL = (OV_PIPE0 | OV_PIPE1 | OV_PIPE2) |
| 305 | }; |
| 306 | |
| 307 | /* values for copybit_set_parameter(OVERLAY_TRANSFORM) */ |
| 308 | enum eTransform { |
| 309 | /* No rot */ |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 310 | OVERLAY_TRANSFORM_0 = 0x0, |
| 311 | /* flip source image horizontally 0x1 */ |
| 312 | OVERLAY_TRANSFORM_FLIP_H = HAL_TRANSFORM_FLIP_H, |
| 313 | /* flip source image vertically 0x2 */ |
| 314 | OVERLAY_TRANSFORM_FLIP_V = HAL_TRANSFORM_FLIP_V, |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 315 | /* rotate source image 180 degrees |
| 316 | * It is basically bit-or-ed H | V == 0x3 */ |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 317 | OVERLAY_TRANSFORM_ROT_180 = HAL_TRANSFORM_ROT_180, |
| 318 | /* rotate source image 90 degrees 0x4 */ |
| 319 | OVERLAY_TRANSFORM_ROT_90 = HAL_TRANSFORM_ROT_90, |
| 320 | /* rotate source image 90 degrees and flip horizontally 0x5 */ |
| 321 | OVERLAY_TRANSFORM_ROT_90_FLIP_H = HAL_TRANSFORM_ROT_90 | |
| 322 | HAL_TRANSFORM_FLIP_H, |
| 323 | /* rotate source image 90 degrees and flip vertically 0x6 */ |
| 324 | OVERLAY_TRANSFORM_ROT_90_FLIP_V = HAL_TRANSFORM_ROT_90 | |
| 325 | HAL_TRANSFORM_FLIP_V, |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 326 | /* rotate source image 270 degrees |
| 327 | * Basically 180 | 90 == 0x7 */ |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 328 | OVERLAY_TRANSFORM_ROT_270 = HAL_TRANSFORM_ROT_270, |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 329 | /* rotate invalid like in Transform.h */ |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 330 | OVERLAY_TRANSFORM_INV = 0x80 |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 331 | }; |
| 332 | |
| 333 | // Used to consolidate pipe params |
| 334 | struct PipeArgs { |
| 335 | PipeArgs() : mdpFlags(OV_MDP_FLAGS_NONE), |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 336 | zorder(Z_SYSTEM_ALLOC), |
| 337 | isFg(IS_FG_OFF), |
| 338 | rotFlags(ROT_FLAG_DISABLED){ |
| 339 | } |
| 340 | |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 341 | PipeArgs(eMdpFlags f, Whf _whf, |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 342 | eZorder z, eIsFg fg, eRotFlags r) : |
| 343 | mdpFlags(f), |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 344 | whf(_whf), |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 345 | zorder(z), |
| 346 | isFg(fg), |
| 347 | rotFlags(r) { |
| 348 | } |
| 349 | |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 350 | eMdpFlags mdpFlags; // for mdp_overlay flags |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 351 | Whf whf; |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 352 | eZorder zorder; // stage number |
| 353 | eIsFg isFg; // control alpha & transp |
| 354 | eRotFlags rotFlags; |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 355 | }; |
| 356 | |
| 357 | enum eOverlayState{ |
| 358 | /* No pipes from overlay open */ |
| 359 | OV_CLOSED = 0, |
| 360 | |
| 361 | /* 2D Video */ |
| 362 | OV_2D_VIDEO_ON_PANEL, |
| 363 | OV_2D_VIDEO_ON_PANEL_TV, |
Naseer Ahmed | 2cc53dd | 2012-07-31 19:11:48 -0700 | [diff] [blame] | 364 | OV_2D_VIDEO_ON_TV, |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 365 | |
| 366 | /* 3D Video on one display (panel or TV) */ |
| 367 | OV_3D_VIDEO_ON_2D_PANEL, |
| 368 | OV_3D_VIDEO_ON_3D_PANEL, |
| 369 | OV_3D_VIDEO_ON_3D_TV, |
| 370 | |
| 371 | /* 3D Video on two displays (panel and TV) */ |
| 372 | OV_3D_VIDEO_ON_2D_PANEL_2D_TV, |
| 373 | |
| 374 | /* UI Mirroring */ |
| 375 | OV_UI_MIRROR, |
| 376 | OV_2D_TRUE_UI_MIRROR, |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 377 | |
| 378 | /* Composition Bypass */ |
| 379 | OV_BYPASS_1_LAYER, |
| 380 | OV_BYPASS_2_LAYER, |
| 381 | OV_BYPASS_3_LAYER, |
Naseer Ahmed | 2cc53dd | 2012-07-31 19:11:48 -0700 | [diff] [blame] | 382 | |
| 383 | /* External only for dual-disp */ |
| 384 | OV_DUAL_DISP, |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 385 | }; |
| 386 | |
| 387 | inline void setMdpFlags(eMdpFlags& f, eMdpFlags v) { |
| 388 | f = static_cast<eMdpFlags>(setBit(f, v)); |
| 389 | } |
| 390 | |
| 391 | inline void clearMdpFlags(eMdpFlags& f, eMdpFlags v) { |
| 392 | f = static_cast<eMdpFlags>(clrBit(f, v)); |
| 393 | } |
| 394 | |
| 395 | // fb 0/1/2 |
| 396 | enum { FB0, FB1, FB2 }; |
| 397 | |
| 398 | //Panels could be categorized as primary and external |
| 399 | enum { PRIMARY, EXTERNAL }; |
| 400 | |
| 401 | //External Panels could use HDMI or WFD |
| 402 | enum { |
| 403 | HDMI = 1, |
| 404 | WFD = 2 |
| 405 | }; |
| 406 | |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 407 | //TODO Make this a part of some appropriate class |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 408 | static int sExtType = HDMI; //HDMI or WFD |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 409 | //Set by client as HDMI/WFD |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 410 | void setExtType(const int& type); |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 411 | //Return External panel type set by client. |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 412 | int getExtType(); |
| 413 | |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 414 | |
| 415 | //Gets the FB number for the external type. |
| 416 | //As of now, HDMI always has fb1, WFD could use fb1 or fb2 |
| 417 | //Assumes Ext type set by setExtType() from client. |
| 418 | static int getFBForPanel(int panel) { // PRIMARY OR EXTERNAL |
| 419 | switch(panel) { |
| 420 | case PRIMARY: return FB0; |
| 421 | break; |
| 422 | case EXTERNAL: |
| 423 | switch(getExtType()) { |
| 424 | case HDMI: return FB1; |
| 425 | break; |
| 426 | case WFD: return FB2;//Hardcoding fb2 for wfd. Will change. |
| 427 | break; |
| 428 | } |
| 429 | break; |
| 430 | default: |
| 431 | ALOGE("%s: Unrecognized PANEL category %d", __func__, panel); |
| 432 | break; |
| 433 | } |
| 434 | return -1; |
| 435 | } |
| 436 | |
| 437 | // number of rgb pipes bufs (max) |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 438 | |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 439 | // 2 for rgb0/1 double bufs |
| 440 | enum { RGB_PIPE_NUM_BUFS = 2 }; |
| 441 | |
| 442 | struct ScreenInfo { |
| 443 | ScreenInfo() : mFBWidth(0), |
| 444 | mFBHeight(0), |
| 445 | mFBbpp(0), |
| 446 | mFBystride(0) {} |
| 447 | void dump(const char* const s) const; |
| 448 | uint32_t mFBWidth; |
| 449 | uint32_t mFBHeight; |
| 450 | uint32_t mFBbpp; |
| 451 | uint32_t mFBystride; |
| 452 | }; |
| 453 | |
| 454 | int getMdpFormat(int format); |
| 455 | int getRotOutFmt(uint32_t format); |
| 456 | /* flip is upside down and such. V, H flip |
| 457 | * rotation is 90, 180 etc |
| 458 | * It returns MDP related enum/define that match rot+flip*/ |
| 459 | int getMdpOrient(eTransform rotation); |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 460 | const char* getFormatString(uint32_t format); |
| 461 | const char* getStateString(eOverlayState state); |
| 462 | |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 463 | // Cannot use HW_OVERLAY_MAGNIFICATION_LIMIT, since at the time |
| 464 | // of integration, HW_OVERLAY_MAGNIFICATION_LIMIT was a define |
| 465 | enum { HW_OV_MAGNIFICATION_LIMIT = 20, |
| 466 | HW_OV_MINIFICATION_LIMIT = 8 |
| 467 | }; |
| 468 | |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 469 | template <class T> |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 470 | inline void memset0(T& t) { ::memset(&t, 0, sizeof(T)); } |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 471 | |
| 472 | template <class T> inline void swap ( T& a, T& b ) |
| 473 | { |
| 474 | T c(a); a=b; b=c; |
| 475 | } |
| 476 | |
| 477 | inline int alignup(int value, int a) { |
| 478 | //if align = 0, return the value. Else, do alignment. |
| 479 | return a ? ((((value - 1) / a) + 1) * a) : value; |
| 480 | } |
| 481 | |
| 482 | // FIXME that align should replace the upper one. |
| 483 | inline int align(int value, int a) { |
| 484 | //if align = 0, return the value. Else, do alignment. |
| 485 | return a ? ((value + (a-1)) & ~(a-1)) : value; |
| 486 | } |
| 487 | |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 488 | enum eRotOutFmt { |
| 489 | ROT_OUT_FMT_DEFAULT, |
| 490 | ROT_OUT_FMT_Y_CRCB_H2V2 |
| 491 | }; |
| 492 | |
| 493 | template <int ROT_OUT_FMT> struct RotOutFmt; |
| 494 | |
| 495 | // FIXME, taken from gralloc_priv.h. Need to |
| 496 | // put it back as soon as overlay takes place of the old one |
| 497 | /* possible formats for 3D content*/ |
| 498 | enum { |
| 499 | HAL_NO_3D = 0x0000, |
| 500 | HAL_3D_IN_SIDE_BY_SIDE_L_R = 0x10000, |
| 501 | HAL_3D_IN_TOP_BOTTOM = 0x20000, |
| 502 | HAL_3D_IN_INTERLEAVE = 0x40000, |
| 503 | HAL_3D_IN_SIDE_BY_SIDE_R_L = 0x80000, |
| 504 | HAL_3D_OUT_SIDE_BY_SIDE = 0x1000, |
| 505 | HAL_3D_OUT_TOP_BOTTOM = 0x2000, |
| 506 | HAL_3D_OUT_INTERLEAVE = 0x4000, |
| 507 | HAL_3D_OUT_MONOSCOPIC = 0x8000 |
| 508 | }; |
| 509 | |
| 510 | enum { HAL_3D_OUT_SBS_MASK = |
| 511 | HAL_3D_OUT_SIDE_BY_SIDE >> overlay::utils::SHIFT_OUT_3D, |
| 512 | HAL_3D_OUT_TOP_BOT_MASK = |
| 513 | HAL_3D_OUT_TOP_BOTTOM >> overlay::utils::SHIFT_OUT_3D, |
| 514 | HAL_3D_OUT_INTERL_MASK = |
| 515 | HAL_3D_OUT_INTERLEAVE >> overlay::utils::SHIFT_OUT_3D, |
| 516 | HAL_3D_OUT_MONOS_MASK = |
| 517 | HAL_3D_OUT_MONOSCOPIC >> overlay::utils::SHIFT_OUT_3D |
| 518 | }; |
| 519 | |
| 520 | |
| 521 | inline bool isYuv(uint32_t format) { |
| 522 | switch(format){ |
| 523 | case MDP_Y_CBCR_H2V1: |
| 524 | case MDP_Y_CBCR_H2V2: |
| 525 | case MDP_Y_CRCB_H2V2: |
| 526 | case MDP_Y_CRCB_H2V2_TILE: |
| 527 | case MDP_Y_CBCR_H2V2_TILE: |
| 528 | return true; |
| 529 | default: |
| 530 | return false; |
| 531 | } |
| 532 | return false; |
| 533 | } |
| 534 | |
| 535 | inline bool isRgb(uint32_t format) { |
| 536 | switch(format) { |
| 537 | case MDP_RGBA_8888: |
| 538 | case MDP_BGRA_8888: |
| 539 | case MDP_RGBX_8888: |
| 540 | case MDP_RGB_565: |
| 541 | return true; |
| 542 | default: |
| 543 | return false; |
| 544 | } |
| 545 | return false; |
| 546 | } |
| 547 | |
| 548 | inline bool isValidDest(eDest dest) |
| 549 | { |
| 550 | if ((OV_PIPE0 & dest) || |
| 551 | (OV_PIPE1 & dest) || |
| 552 | (OV_PIPE2 & dest)) { |
| 553 | return true; |
| 554 | } |
| 555 | return false; |
| 556 | } |
| 557 | |
| 558 | inline const char* getFormatString(uint32_t format){ |
| 559 | static const char* const formats[] = { |
| 560 | "MDP_RGB_565", |
| 561 | "MDP_XRGB_8888", |
| 562 | "MDP_Y_CBCR_H2V2", |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 563 | "MDP_Y_CBCR_H2V2_ADRENO", |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 564 | "MDP_ARGB_8888", |
| 565 | "MDP_RGB_888", |
| 566 | "MDP_Y_CRCB_H2V2", |
| 567 | "MDP_YCRYCB_H2V1", |
| 568 | "MDP_Y_CRCB_H2V1", |
| 569 | "MDP_Y_CBCR_H2V1", |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 570 | "MDP_Y_CRCB_H1V2", |
| 571 | "MDP_Y_CBCR_H1V2", |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 572 | "MDP_RGBA_8888", |
| 573 | "MDP_BGRA_8888", |
| 574 | "MDP_RGBX_8888", |
| 575 | "MDP_Y_CRCB_H2V2_TILE", |
| 576 | "MDP_Y_CBCR_H2V2_TILE", |
| 577 | "MDP_Y_CR_CB_H2V2", |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 578 | "MDP_Y_CR_CB_GH2V2", |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 579 | "MDP_Y_CB_CR_H2V2", |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 580 | "MDP_Y_CRCB_H1V1", |
| 581 | "MDP_Y_CBCR_H1V1", |
| 582 | "MDP_YCRCB_H1V1", |
| 583 | "MDP_YCBCR_H1V1", |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 584 | "MDP_BGR_565", |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 585 | "MDP_IMGTYPE_LIMIT", |
| 586 | "MDP_RGB_BORDERFILL", |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 587 | "MDP_FB_FORMAT", |
| 588 | "MDP_IMGTYPE_LIMIT2" |
| 589 | }; |
| 590 | OVASSERT(format < sizeof(formats) / sizeof(formats[0]), |
| 591 | "getFormatString wrong fmt %d", format); |
| 592 | return formats[format]; |
| 593 | } |
| 594 | |
| 595 | inline const char* getStateString(eOverlayState state){ |
| 596 | switch (state) { |
| 597 | case OV_CLOSED: |
| 598 | return "OV_CLOSED"; |
| 599 | case OV_2D_VIDEO_ON_PANEL: |
| 600 | return "OV_2D_VIDEO_ON_PANEL"; |
| 601 | case OV_2D_VIDEO_ON_PANEL_TV: |
| 602 | return "OV_2D_VIDEO_ON_PANEL_TV"; |
Naseer Ahmed | 2cc53dd | 2012-07-31 19:11:48 -0700 | [diff] [blame] | 603 | case OV_2D_VIDEO_ON_TV: |
| 604 | return "OV_2D_VIDEO_ON_TV"; |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 605 | case OV_3D_VIDEO_ON_2D_PANEL: |
| 606 | return "OV_3D_VIDEO_ON_2D_PANEL"; |
| 607 | case OV_3D_VIDEO_ON_3D_PANEL: |
| 608 | return "OV_3D_VIDEO_ON_3D_PANEL"; |
| 609 | case OV_3D_VIDEO_ON_3D_TV: |
| 610 | return "OV_3D_VIDEO_ON_3D_TV"; |
| 611 | case OV_3D_VIDEO_ON_2D_PANEL_2D_TV: |
| 612 | return "OV_3D_VIDEO_ON_2D_PANEL_2D_TV"; |
| 613 | case OV_UI_MIRROR: |
| 614 | return "OV_UI_MIRROR"; |
| 615 | case OV_2D_TRUE_UI_MIRROR: |
| 616 | return "OV_2D_TRUE_UI_MIRROR"; |
| 617 | case OV_BYPASS_1_LAYER: |
| 618 | return "OV_BYPASS_1_LAYER"; |
| 619 | case OV_BYPASS_2_LAYER: |
| 620 | return "OV_BYPASS_2_LAYER"; |
| 621 | case OV_BYPASS_3_LAYER: |
| 622 | return "OV_BYPASS_3_LAYER"; |
Naseer Ahmed | 2cc53dd | 2012-07-31 19:11:48 -0700 | [diff] [blame] | 623 | case OV_DUAL_DISP: |
| 624 | return "OV_DUAL_DISP"; |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 625 | default: |
| 626 | return "UNKNOWN_STATE"; |
| 627 | } |
| 628 | return "BAD_STATE"; |
| 629 | } |
| 630 | |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 631 | inline void Whf::dump() const { |
| 632 | ALOGE("== Dump WHF w=%d h=%d f=%d s=%d start/end ==", |
| 633 | w, h, format, size); |
| 634 | } |
| 635 | |
| 636 | inline void Dim::dump() const { |
| 637 | ALOGE("== Dump Dim x=%d y=%d w=%d h=%d start/end ==", x, y, w, h); |
| 638 | } |
| 639 | |
| 640 | inline int getMdpOrient(eTransform rotation) { |
| 641 | ALOGE_IF(DEBUG_OVERLAY, "%s: rot=%d", __FUNCTION__, rotation); |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 642 | switch(rotation) |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 643 | { |
| 644 | case OVERLAY_TRANSFORM_0 : return 0; |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 645 | case OVERLAY_TRANSFORM_FLIP_V: return MDP_FLIP_UD; |
| 646 | case OVERLAY_TRANSFORM_FLIP_H: return MDP_FLIP_LR; |
| 647 | case OVERLAY_TRANSFORM_ROT_90: return MDP_ROT_90; |
Saurabh Shah | a73738d | 2012-08-09 18:15:18 -0700 | [diff] [blame] | 648 | //getMdpOrient will switch the flips if the source is 90 rotated. |
| 649 | //Clients in Android dont factor in 90 rotation while deciding flip. |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 650 | case OVERLAY_TRANSFORM_ROT_90_FLIP_V: |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 651 | return MDP_ROT_90 | MDP_FLIP_LR; |
Saurabh Shah | a73738d | 2012-08-09 18:15:18 -0700 | [diff] [blame] | 652 | case OVERLAY_TRANSFORM_ROT_90_FLIP_H: |
| 653 | return MDP_ROT_90 | MDP_FLIP_UD; |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 654 | case OVERLAY_TRANSFORM_ROT_180: return MDP_ROT_180; |
| 655 | case OVERLAY_TRANSFORM_ROT_270: return MDP_ROT_270; |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 656 | default: |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 657 | ALOGE("%s: invalid rotation value (value = 0x%x", |
| 658 | __FUNCTION__, rotation); |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 659 | } |
| 660 | return -1; |
| 661 | } |
| 662 | |
| 663 | inline int getRotOutFmt(uint32_t format) { |
| 664 | switch (format) { |
| 665 | case MDP_Y_CRCB_H2V2_TILE: |
| 666 | return MDP_Y_CRCB_H2V2; |
| 667 | case MDP_Y_CBCR_H2V2_TILE: |
| 668 | return MDP_Y_CBCR_H2V2; |
| 669 | case MDP_Y_CB_CR_H2V2: |
| 670 | return MDP_Y_CBCR_H2V2; |
| 671 | default: |
| 672 | return format; |
| 673 | } |
| 674 | // not reached |
| 675 | OVASSERT(false, "%s not reached", __FUNCTION__); |
| 676 | return -1; |
| 677 | } |
| 678 | |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 679 | |
| 680 | inline uint32_t getColorFormat(uint32_t format) |
| 681 | { |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 682 | return (format == HAL_PIXEL_FORMAT_YV12) ? |
| 683 | format : colorFormat(format); |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 684 | } |
| 685 | |
| 686 | // FB0 |
| 687 | template <int CHAN> |
| 688 | inline Dim getPositionS3DImpl(const Whf& whf) |
| 689 | { |
| 690 | switch (whf.format & OUTPUT_3D_MASK) |
| 691 | { |
| 692 | case HAL_3D_OUT_SBS_MASK: |
| 693 | // x, y, w, h |
| 694 | return Dim(0, 0, whf.w/2, whf.h); |
| 695 | case HAL_3D_OUT_TOP_BOT_MASK: |
| 696 | return Dim(0, 0, whf.w, whf.h/2); |
| 697 | case HAL_3D_OUT_MONOS_MASK: |
| 698 | return Dim(); |
| 699 | case HAL_3D_OUT_INTERL_MASK: |
| 700 | // FIXME error? |
| 701 | ALOGE("%s HAL_3D_OUT_INTERLEAVE_MASK", __FUNCTION__); |
| 702 | return Dim(); |
| 703 | default: |
| 704 | ALOGE("%s Unsupported 3D output format %d", __FUNCTION__, |
| 705 | whf.format); |
| 706 | } |
| 707 | return Dim(); |
| 708 | } |
| 709 | |
| 710 | template <> |
| 711 | inline Dim getPositionS3DImpl<utils::OV_PIPE1>(const Whf& whf) |
| 712 | { |
| 713 | switch (whf.format & OUTPUT_3D_MASK) |
| 714 | { |
| 715 | case HAL_3D_OUT_SBS_MASK: |
| 716 | return Dim(whf.w/2, 0, whf.w/2, whf.h); |
| 717 | case HAL_3D_OUT_TOP_BOT_MASK: |
| 718 | return Dim(0, whf.h/2, whf.w, whf.h/2); |
| 719 | case HAL_3D_OUT_MONOS_MASK: |
| 720 | return Dim(0, 0, whf.w, whf.h); |
| 721 | case HAL_3D_OUT_INTERL_MASK: |
| 722 | // FIXME error? |
| 723 | ALOGE("%s HAL_3D_OUT_INTERLEAVE_MASK", __FUNCTION__); |
| 724 | return Dim(); |
| 725 | default: |
| 726 | ALOGE("%s Unsupported 3D output format %d", __FUNCTION__, |
| 727 | whf.format); |
| 728 | } |
| 729 | return Dim(); |
| 730 | } |
| 731 | |
| 732 | template <int CHAN> |
| 733 | inline bool getPositionS3D(const Whf& whf, Dim& out) { |
| 734 | out = getPositionS3DImpl<CHAN>(whf); |
| 735 | return (out != Dim()); |
| 736 | } |
| 737 | |
| 738 | template <int CHAN> |
| 739 | inline Dim getCropS3DImpl(const Dim& in, uint32_t fmt) { |
| 740 | switch (fmt & INPUT_3D_MASK) |
| 741 | { |
| 742 | case HAL_3D_IN_SIDE_BY_SIDE_L_R: |
| 743 | return Dim(0, 0, in.w/2, in.h); |
| 744 | case HAL_3D_IN_SIDE_BY_SIDE_R_L: |
| 745 | return Dim(in.w/2, 0, in.w/2, in.h); |
| 746 | case HAL_3D_IN_TOP_BOTTOM: |
| 747 | return Dim(0, 0, in.w, in.h/2); |
| 748 | case HAL_3D_IN_INTERLEAVE: |
| 749 | ALOGE("%s HAL_3D_IN_INTERLEAVE", __FUNCTION__); |
| 750 | break; |
| 751 | default: |
| 752 | ALOGE("%s Unsupported 3D format %d", __FUNCTION__, fmt); |
| 753 | break; |
| 754 | } |
| 755 | return Dim(); |
| 756 | } |
| 757 | |
| 758 | template <> |
| 759 | inline Dim getCropS3DImpl<utils::OV_PIPE1>(const Dim& in, uint32_t fmt) { |
| 760 | switch (fmt & INPUT_3D_MASK) |
| 761 | { |
| 762 | case HAL_3D_IN_SIDE_BY_SIDE_L_R: |
| 763 | return Dim(in.w/2, 0, in.w/2, in.h); |
| 764 | case HAL_3D_IN_SIDE_BY_SIDE_R_L: |
| 765 | return Dim(0, 0, in.w/2, in.h); |
| 766 | case HAL_3D_IN_TOP_BOTTOM: |
| 767 | return Dim(0, in.h/2, in.w, in.h/2); |
| 768 | case HAL_3D_IN_INTERLEAVE: |
| 769 | ALOGE("%s HAL_3D_IN_INTERLEAVE", __FUNCTION__); |
| 770 | break; |
| 771 | default: |
| 772 | ALOGE("%s Unsupported 3D format %d", __FUNCTION__, fmt); |
| 773 | break; |
| 774 | } |
| 775 | return Dim(); |
| 776 | } |
| 777 | |
| 778 | template <int CHAN> |
| 779 | inline bool getCropS3D(const Dim& in, Dim& out, uint32_t fmt) |
| 780 | { |
| 781 | out = getCropS3DImpl<CHAN>(in, fmt); |
| 782 | return (out != Dim()); |
| 783 | } |
| 784 | |
| 785 | template <class Type> |
| 786 | void swapWidthHeight(Type& width, Type& height) { |
| 787 | Type tmp = width; |
| 788 | width = height; |
| 789 | height = tmp; |
| 790 | } |
| 791 | |
| 792 | inline void ScreenInfo::dump(const char* const s) const { |
| 793 | ALOGE("== Dump %s ScreenInfo w=%d h=%d" |
| 794 | " bpp=%d stride=%d start/end ==", |
| 795 | s, mFBWidth, mFBHeight, mFBbpp, mFBystride); |
| 796 | } |
| 797 | |
Saurabh Shah | e012f7a | 2012-08-18 15:11:57 -0700 | [diff] [blame] | 798 | inline bool openDev(OvFD& fd, int fbnum, |
| 799 | const char* const devpath, int flags) { |
| 800 | return overlay::open(fd, fbnum, devpath, flags); |
| 801 | } |
| 802 | |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 803 | } // namespace utils ends |
| 804 | |
| 805 | //--------------------Class Res stuff (namespace overlay only) ----------- |
| 806 | |
| 807 | class Res { |
| 808 | public: |
| 809 | // /dev/graphics/fb%u |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 810 | static const char* const fbPath; |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 811 | // /dev/msm_rotator |
| 812 | static const char* const rotPath; |
| 813 | // /sys/class/graphics/fb1/format_3d |
| 814 | static const char* const format3DFile; |
| 815 | // /sys/class/graphics/fb1/3d_present |
| 816 | static const char* const edid3dInfoFile; |
| 817 | // /sys/devices/platform/mipi_novatek.0/enable_3d_barrier |
| 818 | static const char* const barrierFile; |
| 819 | }; |
| 820 | |
| 821 | |
| 822 | //--------------------Class OvFD stuff (namespace overlay only) ----------- |
| 823 | |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 824 | /* |
| 825 | * Holds one FD |
| 826 | * Dtor will NOT close the underlying FD. |
| 827 | * That enables us to copy that object around |
| 828 | * */ |
| 829 | class OvFD { |
| 830 | public: |
| 831 | /* Ctor */ |
| 832 | explicit OvFD(); |
| 833 | |
| 834 | /* dtor will NOT close the underlying FD */ |
| 835 | ~OvFD(); |
| 836 | |
| 837 | /* Open fd using the path given by dev. |
| 838 | * return false in failure */ |
| 839 | bool open(const char* const dev, |
| 840 | int flags = O_RDWR); |
| 841 | |
| 842 | /* populate path */ |
| 843 | void setPath(const char* const dev); |
| 844 | |
| 845 | /* Close fd if we have a valid fd. */ |
| 846 | bool close(); |
| 847 | |
| 848 | /* returns underlying fd.*/ |
| 849 | int getFD() const; |
| 850 | |
| 851 | /* returns true if fd is valid */ |
| 852 | bool valid() const; |
| 853 | |
| 854 | /* like operator= */ |
| 855 | void copy(int fd); |
| 856 | |
| 857 | /* dump the state of the instance */ |
| 858 | void dump() const; |
| 859 | private: |
| 860 | /* helper enum for determine valid/invalid fd */ |
| 861 | enum { INVAL = -1 }; |
| 862 | |
| 863 | /* actual os fd */ |
| 864 | int mFD; |
| 865 | |
| 866 | /* path, for debugging */ |
| 867 | char mPath[utils::MAX_PATH_LEN]; |
| 868 | }; |
| 869 | |
| 870 | //-------------------Inlines-------------------------- |
| 871 | |
| 872 | inline bool open(OvFD& fd, uint32_t fbnum, const char* const dev, int flags) |
| 873 | { |
| 874 | char dev_name[64] = {0}; |
| 875 | snprintf(dev_name, sizeof(dev_name), dev, fbnum); |
| 876 | return fd.open(dev_name, flags); |
| 877 | } |
| 878 | |
| 879 | inline OvFD::OvFD() : mFD (INVAL) { |
| 880 | mPath[0] = 0; |
| 881 | } |
| 882 | |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 883 | inline OvFD::~OvFD() { |
| 884 | //no op since copy() can be used to share fd, in 3d cases. |
| 885 | } |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 886 | |
| 887 | inline bool OvFD::open(const char* const dev, int flags) |
| 888 | { |
| 889 | mFD = ::open(dev, flags, 0); |
| 890 | if (mFD < 0) { |
| 891 | // FIXME errno, strerror in bionic? |
| 892 | ALOGE("Cant open device %s err=%d", dev, errno); |
| 893 | return false; |
| 894 | } |
| 895 | setPath(dev); |
| 896 | return true; |
| 897 | } |
| 898 | |
| 899 | inline void OvFD::setPath(const char* const dev) |
| 900 | { |
| 901 | ::strncpy(mPath, dev, utils::MAX_PATH_LEN); |
| 902 | } |
| 903 | |
| 904 | inline bool OvFD::close() |
| 905 | { |
| 906 | int ret = 0; |
| 907 | if(valid()) { |
| 908 | ret = ::close(mFD); |
| 909 | mFD = INVAL; |
| 910 | } |
| 911 | return (ret == 0); |
| 912 | } |
| 913 | |
| 914 | inline bool OvFD::valid() const |
| 915 | { |
| 916 | return (mFD != INVAL); |
| 917 | } |
| 918 | |
| 919 | inline int OvFD::getFD() const { return mFD; } |
| 920 | |
| 921 | inline void OvFD::copy(int fd) { |
| 922 | mFD = fd; |
| 923 | } |
| 924 | |
| 925 | inline void OvFD::dump() const |
| 926 | { |
| 927 | ALOGE("== Dump OvFD fd=%d path=%s start/end ==", |
| 928 | mFD, mPath); |
| 929 | } |
| 930 | |
| 931 | //--------------- class OvFD stuff ends --------------------- |
| 932 | |
| 933 | } // overlay |
| 934 | |
| 935 | |
| 936 | #endif // OVERLAY_UTILS_H |