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