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