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