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