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, |
Saurabh Shah | 799a397 | 2012-09-01 12:16:12 -0700 | [diff] [blame] | 279 | OV_MDP_BACKEND_COMPOSITION = MDP_BACKEND_COMPOSITION, |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 280 | }; |
| 281 | |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 282 | enum eZorder { |
| 283 | ZORDER_0, |
| 284 | ZORDER_1, |
| 285 | ZORDER_2, |
| 286 | Z_SYSTEM_ALLOC = 0xFFFF |
| 287 | }; |
| 288 | |
| 289 | enum eMdpPipeType { |
| 290 | OV_MDP_PIPE_RGB, |
| 291 | OV_MDP_PIPE_VG |
| 292 | }; |
| 293 | |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 294 | // Max pipes via overlay (VG0, VG1, RGB1) |
| 295 | enum { MAX_PIPES = 3 }; |
| 296 | |
| 297 | /* Used to identify destination channels and |
| 298 | * also 3D channels e.g. when in 3D mode with 2 |
| 299 | * pipes opened and it is used in get crop/pos 3D |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 300 | * */ |
| 301 | enum eDest { |
| 302 | OV_PIPE0 = 1 << 0, |
| 303 | OV_PIPE1 = 1 << 1, |
| 304 | OV_PIPE2 = 1 << 2, |
| 305 | OV_PIPE_ALL = (OV_PIPE0 | OV_PIPE1 | OV_PIPE2) |
| 306 | }; |
| 307 | |
| 308 | /* values for copybit_set_parameter(OVERLAY_TRANSFORM) */ |
| 309 | enum eTransform { |
| 310 | /* No rot */ |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 311 | OVERLAY_TRANSFORM_0 = 0x0, |
| 312 | /* flip source image horizontally 0x1 */ |
| 313 | OVERLAY_TRANSFORM_FLIP_H = HAL_TRANSFORM_FLIP_H, |
| 314 | /* flip source image vertically 0x2 */ |
| 315 | OVERLAY_TRANSFORM_FLIP_V = HAL_TRANSFORM_FLIP_V, |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 316 | /* rotate source image 180 degrees |
| 317 | * It is basically bit-or-ed H | V == 0x3 */ |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 318 | OVERLAY_TRANSFORM_ROT_180 = HAL_TRANSFORM_ROT_180, |
| 319 | /* rotate source image 90 degrees 0x4 */ |
| 320 | OVERLAY_TRANSFORM_ROT_90 = HAL_TRANSFORM_ROT_90, |
| 321 | /* rotate source image 90 degrees and flip horizontally 0x5 */ |
| 322 | OVERLAY_TRANSFORM_ROT_90_FLIP_H = HAL_TRANSFORM_ROT_90 | |
| 323 | HAL_TRANSFORM_FLIP_H, |
| 324 | /* rotate source image 90 degrees and flip vertically 0x6 */ |
| 325 | OVERLAY_TRANSFORM_ROT_90_FLIP_V = HAL_TRANSFORM_ROT_90 | |
| 326 | HAL_TRANSFORM_FLIP_V, |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 327 | /* rotate source image 270 degrees |
| 328 | * Basically 180 | 90 == 0x7 */ |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 329 | OVERLAY_TRANSFORM_ROT_270 = HAL_TRANSFORM_ROT_270, |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 330 | /* rotate invalid like in Transform.h */ |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 331 | OVERLAY_TRANSFORM_INV = 0x80 |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 332 | }; |
| 333 | |
| 334 | // Used to consolidate pipe params |
| 335 | struct PipeArgs { |
| 336 | PipeArgs() : mdpFlags(OV_MDP_FLAGS_NONE), |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 337 | zorder(Z_SYSTEM_ALLOC), |
| 338 | isFg(IS_FG_OFF), |
| 339 | rotFlags(ROT_FLAG_DISABLED){ |
| 340 | } |
| 341 | |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 342 | PipeArgs(eMdpFlags f, Whf _whf, |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 343 | eZorder z, eIsFg fg, eRotFlags r) : |
| 344 | mdpFlags(f), |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 345 | whf(_whf), |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 346 | zorder(z), |
| 347 | isFg(fg), |
| 348 | rotFlags(r) { |
| 349 | } |
| 350 | |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 351 | eMdpFlags mdpFlags; // for mdp_overlay flags |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 352 | Whf whf; |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 353 | eZorder zorder; // stage number |
| 354 | eIsFg isFg; // control alpha & transp |
| 355 | eRotFlags rotFlags; |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 356 | }; |
| 357 | |
| 358 | enum eOverlayState{ |
| 359 | /* No pipes from overlay open */ |
| 360 | OV_CLOSED = 0, |
| 361 | |
| 362 | /* 2D Video */ |
| 363 | OV_2D_VIDEO_ON_PANEL, |
| 364 | OV_2D_VIDEO_ON_PANEL_TV, |
Naseer Ahmed | 2cc53dd | 2012-07-31 19:11:48 -0700 | [diff] [blame] | 365 | OV_2D_VIDEO_ON_TV, |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 366 | |
| 367 | /* 3D Video on one display (panel or TV) */ |
| 368 | OV_3D_VIDEO_ON_2D_PANEL, |
| 369 | OV_3D_VIDEO_ON_3D_PANEL, |
| 370 | OV_3D_VIDEO_ON_3D_TV, |
| 371 | |
| 372 | /* 3D Video on two displays (panel and TV) */ |
| 373 | OV_3D_VIDEO_ON_2D_PANEL_2D_TV, |
| 374 | |
| 375 | /* UI Mirroring */ |
| 376 | OV_UI_MIRROR, |
| 377 | OV_2D_TRUE_UI_MIRROR, |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 378 | |
| 379 | /* Composition Bypass */ |
| 380 | OV_BYPASS_1_LAYER, |
| 381 | OV_BYPASS_2_LAYER, |
| 382 | OV_BYPASS_3_LAYER, |
Naseer Ahmed | 2cc53dd | 2012-07-31 19:11:48 -0700 | [diff] [blame] | 383 | |
| 384 | /* External only for dual-disp */ |
| 385 | OV_DUAL_DISP, |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 386 | }; |
| 387 | |
| 388 | inline void setMdpFlags(eMdpFlags& f, eMdpFlags v) { |
| 389 | f = static_cast<eMdpFlags>(setBit(f, v)); |
| 390 | } |
| 391 | |
| 392 | inline void clearMdpFlags(eMdpFlags& f, eMdpFlags v) { |
| 393 | f = static_cast<eMdpFlags>(clrBit(f, v)); |
| 394 | } |
| 395 | |
| 396 | // fb 0/1/2 |
| 397 | enum { FB0, FB1, FB2 }; |
| 398 | |
| 399 | //Panels could be categorized as primary and external |
| 400 | enum { PRIMARY, EXTERNAL }; |
| 401 | |
| 402 | //External Panels could use HDMI or WFD |
| 403 | enum { |
| 404 | HDMI = 1, |
| 405 | WFD = 2 |
| 406 | }; |
| 407 | |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 408 | //TODO Make this a part of some appropriate class |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 409 | static int sExtType = HDMI; //HDMI or WFD |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 410 | //Set by client as HDMI/WFD |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 411 | void setExtType(const int& type); |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 412 | //Return External panel type set by client. |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 413 | int getExtType(); |
| 414 | |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 415 | |
| 416 | //Gets the FB number for the external type. |
| 417 | //As of now, HDMI always has fb1, WFD could use fb1 or fb2 |
| 418 | //Assumes Ext type set by setExtType() from client. |
| 419 | static int getFBForPanel(int panel) { // PRIMARY OR EXTERNAL |
| 420 | switch(panel) { |
| 421 | case PRIMARY: return FB0; |
| 422 | break; |
| 423 | case EXTERNAL: |
| 424 | switch(getExtType()) { |
| 425 | case HDMI: return FB1; |
| 426 | break; |
| 427 | case WFD: return FB2;//Hardcoding fb2 for wfd. Will change. |
| 428 | break; |
| 429 | } |
| 430 | break; |
| 431 | default: |
| 432 | ALOGE("%s: Unrecognized PANEL category %d", __func__, panel); |
| 433 | break; |
| 434 | } |
| 435 | return -1; |
| 436 | } |
| 437 | |
| 438 | // number of rgb pipes bufs (max) |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 439 | |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 440 | // 2 for rgb0/1 double bufs |
| 441 | enum { RGB_PIPE_NUM_BUFS = 2 }; |
| 442 | |
| 443 | struct ScreenInfo { |
| 444 | ScreenInfo() : mFBWidth(0), |
| 445 | mFBHeight(0), |
| 446 | mFBbpp(0), |
| 447 | mFBystride(0) {} |
| 448 | void dump(const char* const s) const; |
| 449 | uint32_t mFBWidth; |
| 450 | uint32_t mFBHeight; |
| 451 | uint32_t mFBbpp; |
| 452 | uint32_t mFBystride; |
| 453 | }; |
| 454 | |
| 455 | int getMdpFormat(int format); |
| 456 | int getRotOutFmt(uint32_t format); |
| 457 | /* flip is upside down and such. V, H flip |
| 458 | * rotation is 90, 180 etc |
| 459 | * It returns MDP related enum/define that match rot+flip*/ |
| 460 | int getMdpOrient(eTransform rotation); |
Saurabh Shah | 9c876d9 | 2012-08-25 19:29:53 -0700 | [diff] [blame] | 461 | const char* getFormatString(int format); |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 462 | const char* getStateString(eOverlayState state); |
| 463 | |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 464 | // Cannot use HW_OVERLAY_MAGNIFICATION_LIMIT, since at the time |
| 465 | // of integration, HW_OVERLAY_MAGNIFICATION_LIMIT was a define |
| 466 | enum { HW_OV_MAGNIFICATION_LIMIT = 20, |
| 467 | HW_OV_MINIFICATION_LIMIT = 8 |
| 468 | }; |
| 469 | |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 470 | template <class T> |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 471 | inline void memset0(T& t) { ::memset(&t, 0, sizeof(T)); } |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 472 | |
| 473 | template <class T> inline void swap ( T& a, T& b ) |
| 474 | { |
| 475 | T c(a); a=b; b=c; |
| 476 | } |
| 477 | |
| 478 | inline int alignup(int value, int a) { |
| 479 | //if align = 0, return the value. Else, do alignment. |
| 480 | return a ? ((((value - 1) / a) + 1) * a) : value; |
| 481 | } |
| 482 | |
| 483 | // FIXME that align should replace the upper one. |
| 484 | inline int align(int value, int a) { |
| 485 | //if align = 0, return the value. Else, do alignment. |
| 486 | return a ? ((value + (a-1)) & ~(a-1)) : value; |
| 487 | } |
| 488 | |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 489 | enum eRotOutFmt { |
| 490 | ROT_OUT_FMT_DEFAULT, |
| 491 | ROT_OUT_FMT_Y_CRCB_H2V2 |
| 492 | }; |
| 493 | |
| 494 | template <int ROT_OUT_FMT> struct RotOutFmt; |
| 495 | |
| 496 | // FIXME, taken from gralloc_priv.h. Need to |
| 497 | // put it back as soon as overlay takes place of the old one |
| 498 | /* possible formats for 3D content*/ |
| 499 | enum { |
| 500 | HAL_NO_3D = 0x0000, |
| 501 | HAL_3D_IN_SIDE_BY_SIDE_L_R = 0x10000, |
| 502 | HAL_3D_IN_TOP_BOTTOM = 0x20000, |
| 503 | HAL_3D_IN_INTERLEAVE = 0x40000, |
| 504 | HAL_3D_IN_SIDE_BY_SIDE_R_L = 0x80000, |
| 505 | HAL_3D_OUT_SIDE_BY_SIDE = 0x1000, |
| 506 | HAL_3D_OUT_TOP_BOTTOM = 0x2000, |
| 507 | HAL_3D_OUT_INTERLEAVE = 0x4000, |
| 508 | HAL_3D_OUT_MONOSCOPIC = 0x8000 |
| 509 | }; |
| 510 | |
| 511 | enum { HAL_3D_OUT_SBS_MASK = |
| 512 | HAL_3D_OUT_SIDE_BY_SIDE >> overlay::utils::SHIFT_OUT_3D, |
| 513 | HAL_3D_OUT_TOP_BOT_MASK = |
| 514 | HAL_3D_OUT_TOP_BOTTOM >> overlay::utils::SHIFT_OUT_3D, |
| 515 | HAL_3D_OUT_INTERL_MASK = |
| 516 | HAL_3D_OUT_INTERLEAVE >> overlay::utils::SHIFT_OUT_3D, |
| 517 | HAL_3D_OUT_MONOS_MASK = |
| 518 | HAL_3D_OUT_MONOSCOPIC >> overlay::utils::SHIFT_OUT_3D |
| 519 | }; |
| 520 | |
| 521 | |
| 522 | inline bool isYuv(uint32_t format) { |
| 523 | switch(format){ |
| 524 | case MDP_Y_CBCR_H2V1: |
| 525 | case MDP_Y_CBCR_H2V2: |
| 526 | case MDP_Y_CRCB_H2V2: |
Saurabh Shah | b121e14 | 2012-08-20 17:59:13 -0700 | [diff] [blame] | 527 | case MDP_Y_CRCB_H1V1: |
| 528 | case MDP_Y_CRCB_H2V1: |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 529 | case MDP_Y_CRCB_H2V2_TILE: |
| 530 | case MDP_Y_CBCR_H2V2_TILE: |
Saurabh Shah | b121e14 | 2012-08-20 17:59:13 -0700 | [diff] [blame] | 531 | case MDP_Y_CR_CB_H2V2: |
Saurabh Shah | ae1044e | 2012-08-21 16:03:32 -0700 | [diff] [blame] | 532 | case MDP_Y_CR_CB_GH2V2: |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 533 | return true; |
| 534 | default: |
| 535 | return false; |
| 536 | } |
| 537 | return false; |
| 538 | } |
| 539 | |
| 540 | inline bool isRgb(uint32_t format) { |
| 541 | switch(format) { |
| 542 | case MDP_RGBA_8888: |
| 543 | case MDP_BGRA_8888: |
| 544 | case MDP_RGBX_8888: |
| 545 | case MDP_RGB_565: |
| 546 | return true; |
| 547 | default: |
| 548 | return false; |
| 549 | } |
| 550 | return false; |
| 551 | } |
| 552 | |
| 553 | inline bool isValidDest(eDest dest) |
| 554 | { |
| 555 | if ((OV_PIPE0 & dest) || |
| 556 | (OV_PIPE1 & dest) || |
| 557 | (OV_PIPE2 & dest)) { |
| 558 | return true; |
| 559 | } |
| 560 | return false; |
| 561 | } |
| 562 | |
Saurabh Shah | 9c876d9 | 2012-08-25 19:29:53 -0700 | [diff] [blame] | 563 | inline const char* getFormatString(int format){ |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 564 | static const char* const formats[] = { |
| 565 | "MDP_RGB_565", |
| 566 | "MDP_XRGB_8888", |
| 567 | "MDP_Y_CBCR_H2V2", |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 568 | "MDP_Y_CBCR_H2V2_ADRENO", |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 569 | "MDP_ARGB_8888", |
| 570 | "MDP_RGB_888", |
| 571 | "MDP_Y_CRCB_H2V2", |
| 572 | "MDP_YCRYCB_H2V1", |
| 573 | "MDP_Y_CRCB_H2V1", |
| 574 | "MDP_Y_CBCR_H2V1", |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 575 | "MDP_Y_CRCB_H1V2", |
| 576 | "MDP_Y_CBCR_H1V2", |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 577 | "MDP_RGBA_8888", |
| 578 | "MDP_BGRA_8888", |
| 579 | "MDP_RGBX_8888", |
| 580 | "MDP_Y_CRCB_H2V2_TILE", |
| 581 | "MDP_Y_CBCR_H2V2_TILE", |
| 582 | "MDP_Y_CR_CB_H2V2", |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 583 | "MDP_Y_CR_CB_GH2V2", |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 584 | "MDP_Y_CB_CR_H2V2", |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 585 | "MDP_Y_CRCB_H1V1", |
| 586 | "MDP_Y_CBCR_H1V1", |
| 587 | "MDP_YCRCB_H1V1", |
| 588 | "MDP_YCBCR_H1V1", |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 589 | "MDP_BGR_565", |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 590 | "MDP_IMGTYPE_LIMIT", |
| 591 | "MDP_RGB_BORDERFILL", |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 592 | "MDP_FB_FORMAT", |
| 593 | "MDP_IMGTYPE_LIMIT2" |
| 594 | }; |
Saurabh Shah | 9c876d9 | 2012-08-25 19:29:53 -0700 | [diff] [blame] | 595 | if(format < 0 || format >= (int)(sizeof(formats) / sizeof(formats[0]))) { |
| 596 | ALOGE("%s wrong fmt %d", __FUNCTION__, format); |
| 597 | return "Unsupported format"; |
| 598 | } |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 599 | return formats[format]; |
| 600 | } |
| 601 | |
| 602 | inline const char* getStateString(eOverlayState state){ |
| 603 | switch (state) { |
| 604 | case OV_CLOSED: |
| 605 | return "OV_CLOSED"; |
| 606 | case OV_2D_VIDEO_ON_PANEL: |
| 607 | return "OV_2D_VIDEO_ON_PANEL"; |
| 608 | case OV_2D_VIDEO_ON_PANEL_TV: |
| 609 | return "OV_2D_VIDEO_ON_PANEL_TV"; |
Naseer Ahmed | 2cc53dd | 2012-07-31 19:11:48 -0700 | [diff] [blame] | 610 | case OV_2D_VIDEO_ON_TV: |
| 611 | return "OV_2D_VIDEO_ON_TV"; |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 612 | case OV_3D_VIDEO_ON_2D_PANEL: |
| 613 | return "OV_3D_VIDEO_ON_2D_PANEL"; |
| 614 | case OV_3D_VIDEO_ON_3D_PANEL: |
| 615 | return "OV_3D_VIDEO_ON_3D_PANEL"; |
| 616 | case OV_3D_VIDEO_ON_3D_TV: |
| 617 | return "OV_3D_VIDEO_ON_3D_TV"; |
| 618 | case OV_3D_VIDEO_ON_2D_PANEL_2D_TV: |
| 619 | return "OV_3D_VIDEO_ON_2D_PANEL_2D_TV"; |
| 620 | case OV_UI_MIRROR: |
| 621 | return "OV_UI_MIRROR"; |
| 622 | case OV_2D_TRUE_UI_MIRROR: |
| 623 | return "OV_2D_TRUE_UI_MIRROR"; |
| 624 | case OV_BYPASS_1_LAYER: |
| 625 | return "OV_BYPASS_1_LAYER"; |
| 626 | case OV_BYPASS_2_LAYER: |
| 627 | return "OV_BYPASS_2_LAYER"; |
| 628 | case OV_BYPASS_3_LAYER: |
| 629 | return "OV_BYPASS_3_LAYER"; |
Naseer Ahmed | 2cc53dd | 2012-07-31 19:11:48 -0700 | [diff] [blame] | 630 | case OV_DUAL_DISP: |
| 631 | return "OV_DUAL_DISP"; |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 632 | default: |
| 633 | return "UNKNOWN_STATE"; |
| 634 | } |
| 635 | return "BAD_STATE"; |
| 636 | } |
| 637 | |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 638 | inline void Whf::dump() const { |
| 639 | ALOGE("== Dump WHF w=%d h=%d f=%d s=%d start/end ==", |
| 640 | w, h, format, size); |
| 641 | } |
| 642 | |
| 643 | inline void Dim::dump() const { |
| 644 | ALOGE("== Dump Dim x=%d y=%d w=%d h=%d start/end ==", x, y, w, h); |
| 645 | } |
| 646 | |
| 647 | inline int getMdpOrient(eTransform rotation) { |
| 648 | ALOGE_IF(DEBUG_OVERLAY, "%s: rot=%d", __FUNCTION__, rotation); |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 649 | switch(rotation) |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 650 | { |
| 651 | case OVERLAY_TRANSFORM_0 : return 0; |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 652 | case OVERLAY_TRANSFORM_FLIP_V: return MDP_FLIP_UD; |
| 653 | case OVERLAY_TRANSFORM_FLIP_H: return MDP_FLIP_LR; |
| 654 | case OVERLAY_TRANSFORM_ROT_90: return MDP_ROT_90; |
Saurabh Shah | a73738d | 2012-08-09 18:15:18 -0700 | [diff] [blame] | 655 | //getMdpOrient will switch the flips if the source is 90 rotated. |
| 656 | //Clients in Android dont factor in 90 rotation while deciding flip. |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 657 | case OVERLAY_TRANSFORM_ROT_90_FLIP_V: |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 658 | return MDP_ROT_90 | MDP_FLIP_LR; |
Saurabh Shah | a73738d | 2012-08-09 18:15:18 -0700 | [diff] [blame] | 659 | case OVERLAY_TRANSFORM_ROT_90_FLIP_H: |
| 660 | return MDP_ROT_90 | MDP_FLIP_UD; |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 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; |
Saurabh Shah | ae1044e | 2012-08-21 16:03:32 -0700 | [diff] [blame] | 678 | case MDP_Y_CR_CB_GH2V2: |
| 679 | return MDP_Y_CRCB_H2V2; |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 680 | default: |
| 681 | return format; |
| 682 | } |
| 683 | // not reached |
| 684 | OVASSERT(false, "%s not reached", __FUNCTION__); |
| 685 | return -1; |
| 686 | } |
| 687 | |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 688 | |
| 689 | inline uint32_t getColorFormat(uint32_t format) |
| 690 | { |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 691 | return (format == HAL_PIXEL_FORMAT_YV12) ? |
| 692 | format : colorFormat(format); |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 693 | } |
| 694 | |
| 695 | // FB0 |
| 696 | template <int CHAN> |
| 697 | inline Dim getPositionS3DImpl(const Whf& whf) |
| 698 | { |
| 699 | switch (whf.format & OUTPUT_3D_MASK) |
| 700 | { |
| 701 | case HAL_3D_OUT_SBS_MASK: |
| 702 | // x, y, w, h |
| 703 | return Dim(0, 0, whf.w/2, whf.h); |
| 704 | case HAL_3D_OUT_TOP_BOT_MASK: |
| 705 | return Dim(0, 0, whf.w, whf.h/2); |
| 706 | case HAL_3D_OUT_MONOS_MASK: |
| 707 | return Dim(); |
| 708 | case HAL_3D_OUT_INTERL_MASK: |
| 709 | // FIXME error? |
| 710 | ALOGE("%s HAL_3D_OUT_INTERLEAVE_MASK", __FUNCTION__); |
| 711 | return Dim(); |
| 712 | default: |
| 713 | ALOGE("%s Unsupported 3D output format %d", __FUNCTION__, |
| 714 | whf.format); |
| 715 | } |
| 716 | return Dim(); |
| 717 | } |
| 718 | |
| 719 | template <> |
| 720 | inline Dim getPositionS3DImpl<utils::OV_PIPE1>(const Whf& whf) |
| 721 | { |
| 722 | switch (whf.format & OUTPUT_3D_MASK) |
| 723 | { |
| 724 | case HAL_3D_OUT_SBS_MASK: |
| 725 | return Dim(whf.w/2, 0, whf.w/2, whf.h); |
| 726 | case HAL_3D_OUT_TOP_BOT_MASK: |
| 727 | return Dim(0, whf.h/2, whf.w, whf.h/2); |
| 728 | case HAL_3D_OUT_MONOS_MASK: |
| 729 | return Dim(0, 0, whf.w, whf.h); |
| 730 | case HAL_3D_OUT_INTERL_MASK: |
| 731 | // FIXME error? |
| 732 | ALOGE("%s HAL_3D_OUT_INTERLEAVE_MASK", __FUNCTION__); |
| 733 | return Dim(); |
| 734 | default: |
| 735 | ALOGE("%s Unsupported 3D output format %d", __FUNCTION__, |
| 736 | whf.format); |
| 737 | } |
| 738 | return Dim(); |
| 739 | } |
| 740 | |
| 741 | template <int CHAN> |
| 742 | inline bool getPositionS3D(const Whf& whf, Dim& out) { |
| 743 | out = getPositionS3DImpl<CHAN>(whf); |
| 744 | return (out != Dim()); |
| 745 | } |
| 746 | |
| 747 | template <int CHAN> |
| 748 | inline Dim getCropS3DImpl(const Dim& in, uint32_t fmt) { |
| 749 | switch (fmt & INPUT_3D_MASK) |
| 750 | { |
| 751 | case HAL_3D_IN_SIDE_BY_SIDE_L_R: |
| 752 | return Dim(0, 0, in.w/2, in.h); |
| 753 | case HAL_3D_IN_SIDE_BY_SIDE_R_L: |
| 754 | return Dim(in.w/2, 0, in.w/2, in.h); |
| 755 | case HAL_3D_IN_TOP_BOTTOM: |
| 756 | return Dim(0, 0, in.w, in.h/2); |
| 757 | case HAL_3D_IN_INTERLEAVE: |
| 758 | ALOGE("%s HAL_3D_IN_INTERLEAVE", __FUNCTION__); |
| 759 | break; |
| 760 | default: |
| 761 | ALOGE("%s Unsupported 3D format %d", __FUNCTION__, fmt); |
| 762 | break; |
| 763 | } |
| 764 | return Dim(); |
| 765 | } |
| 766 | |
| 767 | template <> |
| 768 | inline Dim getCropS3DImpl<utils::OV_PIPE1>(const Dim& in, uint32_t fmt) { |
| 769 | switch (fmt & INPUT_3D_MASK) |
| 770 | { |
| 771 | case HAL_3D_IN_SIDE_BY_SIDE_L_R: |
| 772 | return Dim(in.w/2, 0, in.w/2, in.h); |
| 773 | case HAL_3D_IN_SIDE_BY_SIDE_R_L: |
| 774 | return Dim(0, 0, in.w/2, in.h); |
| 775 | case HAL_3D_IN_TOP_BOTTOM: |
| 776 | return Dim(0, in.h/2, in.w, in.h/2); |
| 777 | case HAL_3D_IN_INTERLEAVE: |
| 778 | ALOGE("%s HAL_3D_IN_INTERLEAVE", __FUNCTION__); |
| 779 | break; |
| 780 | default: |
| 781 | ALOGE("%s Unsupported 3D format %d", __FUNCTION__, fmt); |
| 782 | break; |
| 783 | } |
| 784 | return Dim(); |
| 785 | } |
| 786 | |
| 787 | template <int CHAN> |
| 788 | inline bool getCropS3D(const Dim& in, Dim& out, uint32_t fmt) |
| 789 | { |
| 790 | out = getCropS3DImpl<CHAN>(in, fmt); |
| 791 | return (out != Dim()); |
| 792 | } |
| 793 | |
| 794 | template <class Type> |
| 795 | void swapWidthHeight(Type& width, Type& height) { |
| 796 | Type tmp = width; |
| 797 | width = height; |
| 798 | height = tmp; |
| 799 | } |
| 800 | |
| 801 | inline void ScreenInfo::dump(const char* const s) const { |
| 802 | ALOGE("== Dump %s ScreenInfo w=%d h=%d" |
| 803 | " bpp=%d stride=%d start/end ==", |
| 804 | s, mFBWidth, mFBHeight, mFBbpp, mFBystride); |
| 805 | } |
| 806 | |
Saurabh Shah | e012f7a | 2012-08-18 15:11:57 -0700 | [diff] [blame] | 807 | inline bool openDev(OvFD& fd, int fbnum, |
| 808 | const char* const devpath, int flags) { |
| 809 | return overlay::open(fd, fbnum, devpath, flags); |
| 810 | } |
| 811 | |
Saurabh Shah | b121e14 | 2012-08-20 17:59:13 -0700 | [diff] [blame] | 812 | template <class T> |
| 813 | inline void even_ceil(T& value) { |
| 814 | if(value & 1) |
| 815 | value++; |
| 816 | } |
| 817 | |
| 818 | template <class T> |
| 819 | inline void even_floor(T& value) { |
| 820 | if(value & 1) |
| 821 | value--; |
| 822 | } |
| 823 | |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 824 | } // namespace utils ends |
| 825 | |
| 826 | //--------------------Class Res stuff (namespace overlay only) ----------- |
| 827 | |
| 828 | class Res { |
| 829 | public: |
| 830 | // /dev/graphics/fb%u |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 831 | static const char* const fbPath; |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 832 | // /dev/msm_rotator |
| 833 | static const char* const rotPath; |
| 834 | // /sys/class/graphics/fb1/format_3d |
| 835 | static const char* const format3DFile; |
| 836 | // /sys/class/graphics/fb1/3d_present |
| 837 | static const char* const edid3dInfoFile; |
| 838 | // /sys/devices/platform/mipi_novatek.0/enable_3d_barrier |
| 839 | static const char* const barrierFile; |
| 840 | }; |
| 841 | |
| 842 | |
| 843 | //--------------------Class OvFD stuff (namespace overlay only) ----------- |
| 844 | |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 845 | /* |
| 846 | * Holds one FD |
| 847 | * Dtor will NOT close the underlying FD. |
| 848 | * That enables us to copy that object around |
| 849 | * */ |
| 850 | class OvFD { |
| 851 | public: |
| 852 | /* Ctor */ |
| 853 | explicit OvFD(); |
| 854 | |
| 855 | /* dtor will NOT close the underlying FD */ |
| 856 | ~OvFD(); |
| 857 | |
| 858 | /* Open fd using the path given by dev. |
| 859 | * return false in failure */ |
| 860 | bool open(const char* const dev, |
| 861 | int flags = O_RDWR); |
| 862 | |
| 863 | /* populate path */ |
| 864 | void setPath(const char* const dev); |
| 865 | |
| 866 | /* Close fd if we have a valid fd. */ |
| 867 | bool close(); |
| 868 | |
| 869 | /* returns underlying fd.*/ |
| 870 | int getFD() const; |
| 871 | |
| 872 | /* returns true if fd is valid */ |
| 873 | bool valid() const; |
| 874 | |
| 875 | /* like operator= */ |
| 876 | void copy(int fd); |
| 877 | |
| 878 | /* dump the state of the instance */ |
| 879 | void dump() const; |
| 880 | private: |
| 881 | /* helper enum for determine valid/invalid fd */ |
| 882 | enum { INVAL = -1 }; |
| 883 | |
| 884 | /* actual os fd */ |
| 885 | int mFD; |
| 886 | |
| 887 | /* path, for debugging */ |
| 888 | char mPath[utils::MAX_PATH_LEN]; |
| 889 | }; |
| 890 | |
| 891 | //-------------------Inlines-------------------------- |
| 892 | |
| 893 | inline bool open(OvFD& fd, uint32_t fbnum, const char* const dev, int flags) |
| 894 | { |
| 895 | char dev_name[64] = {0}; |
| 896 | snprintf(dev_name, sizeof(dev_name), dev, fbnum); |
| 897 | return fd.open(dev_name, flags); |
| 898 | } |
| 899 | |
| 900 | inline OvFD::OvFD() : mFD (INVAL) { |
| 901 | mPath[0] = 0; |
| 902 | } |
| 903 | |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 904 | inline OvFD::~OvFD() { |
| 905 | //no op since copy() can be used to share fd, in 3d cases. |
| 906 | } |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 907 | |
| 908 | inline bool OvFD::open(const char* const dev, int flags) |
| 909 | { |
| 910 | mFD = ::open(dev, flags, 0); |
| 911 | if (mFD < 0) { |
| 912 | // FIXME errno, strerror in bionic? |
| 913 | ALOGE("Cant open device %s err=%d", dev, errno); |
| 914 | return false; |
| 915 | } |
| 916 | setPath(dev); |
| 917 | return true; |
| 918 | } |
| 919 | |
| 920 | inline void OvFD::setPath(const char* const dev) |
| 921 | { |
| 922 | ::strncpy(mPath, dev, utils::MAX_PATH_LEN); |
| 923 | } |
| 924 | |
| 925 | inline bool OvFD::close() |
| 926 | { |
| 927 | int ret = 0; |
| 928 | if(valid()) { |
| 929 | ret = ::close(mFD); |
| 930 | mFD = INVAL; |
| 931 | } |
| 932 | return (ret == 0); |
| 933 | } |
| 934 | |
| 935 | inline bool OvFD::valid() const |
| 936 | { |
| 937 | return (mFD != INVAL); |
| 938 | } |
| 939 | |
| 940 | inline int OvFD::getFD() const { return mFD; } |
| 941 | |
| 942 | inline void OvFD::copy(int fd) { |
| 943 | mFD = fd; |
| 944 | } |
| 945 | |
| 946 | inline void OvFD::dump() const |
| 947 | { |
| 948 | ALOGE("== Dump OvFD fd=%d path=%s start/end ==", |
| 949 | mFD, mPath); |
| 950 | } |
| 951 | |
| 952 | //--------------- class OvFD stuff ends --------------------- |
| 953 | |
| 954 | } // overlay |
| 955 | |
| 956 | |
| 957 | #endif // OVERLAY_UTILS_H |