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