Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 1 | /* |
Arun Kumar K.R | 7e5a1f8 | 2014-01-22 10:36:16 -0800 | [diff] [blame] | 2 | * Copyright (c) 2011-2014, 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. |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [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 | #include <stdlib.h> |
Saurabh Shah | db7ae31 | 2013-03-19 15:45:24 -0700 | [diff] [blame] | 31 | #include <math.h> |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 32 | #include <utils/Log.h> |
| 33 | #include <linux/msm_mdp.h> |
| 34 | #include <cutils/properties.h> |
| 35 | #include "gralloc_priv.h" |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 36 | #include "overlayUtils.h" |
| 37 | #include "mdpWrapper.h" |
Saurabh Shah | 94822ee | 2012-08-17 16:48:43 -0700 | [diff] [blame] | 38 | #include "mdp_version.h" |
Manoj Kumar AVM | 8a22081 | 2013-10-10 11:46:06 -0700 | [diff] [blame] | 39 | #include <hardware/hwcomposer_defs.h> |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 40 | |
| 41 | // just a helper static thingy |
| 42 | namespace { |
| 43 | struct IOFile { |
| 44 | IOFile(const char* s, const char* mode) : fp(0) { |
| 45 | fp = ::fopen(s, mode); |
| 46 | if(!fp) { |
| 47 | ALOGE("Failed open %s", s); |
| 48 | } |
| 49 | } |
| 50 | template <class T> |
| 51 | size_t read(T& r, size_t elem) { |
| 52 | if(fp) { |
| 53 | return ::fread(&r, sizeof(T), elem, fp); |
| 54 | } |
| 55 | return 0; |
| 56 | } |
| 57 | size_t write(const char* s, uint32_t val) { |
| 58 | if(fp) { |
| 59 | return ::fprintf(fp, s, val); |
| 60 | } |
| 61 | return 0; |
| 62 | } |
| 63 | bool valid() const { return fp != 0; } |
| 64 | ~IOFile() { |
| 65 | if(fp) ::fclose(fp); |
| 66 | fp=0; |
| 67 | } |
| 68 | FILE* fp; |
| 69 | }; |
| 70 | } |
| 71 | |
| 72 | namespace overlay { |
| 73 | |
| 74 | //----------From class Res ------------------------------ |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 75 | const char* const Res::fbPath = "/dev/graphics/fb%u"; |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 76 | const char* const Res::rotPath = "/dev/msm_rotator"; |
| 77 | const char* const Res::format3DFile = |
| 78 | "/sys/class/graphics/fb1/format_3d"; |
| 79 | const char* const Res::edid3dInfoFile = |
| 80 | "/sys/class/graphics/fb1/3d_present"; |
| 81 | const char* const Res::barrierFile = |
| 82 | "/sys/devices/platform/mipi_novatek.0/enable_3d_barrier"; |
| 83 | //-------------------------------------------------------- |
| 84 | |
| 85 | |
| 86 | |
| 87 | namespace utils { |
Ajay Dudani | cb3da0a | 2012-09-07 13:37:49 -0700 | [diff] [blame] | 88 | |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 89 | //-------------------------------------------------------- |
Naseer Ahmed | af49e21 | 2012-07-31 19:13:41 -0700 | [diff] [blame] | 90 | //Refer to graphics.h, gralloc_priv.h, msm_mdp.h |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 91 | int getMdpFormat(int format) { |
| 92 | switch (format) { |
Naseer Ahmed | af49e21 | 2012-07-31 19:13:41 -0700 | [diff] [blame] | 93 | //From graphics.h |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 94 | case HAL_PIXEL_FORMAT_RGBA_8888 : |
| 95 | return MDP_RGBA_8888; |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 96 | case HAL_PIXEL_FORMAT_RGBX_8888: |
| 97 | return MDP_RGBX_8888; |
Naseer Ahmed | af49e21 | 2012-07-31 19:13:41 -0700 | [diff] [blame] | 98 | case HAL_PIXEL_FORMAT_RGB_888: |
| 99 | return MDP_RGB_888; |
| 100 | case HAL_PIXEL_FORMAT_RGB_565: |
| 101 | return MDP_RGB_565; |
| 102 | case HAL_PIXEL_FORMAT_BGRA_8888: |
| 103 | return MDP_BGRA_8888; |
Sushil Chauhan | 1f6d68f | 2013-10-11 11:49:35 -0700 | [diff] [blame] | 104 | case HAL_PIXEL_FORMAT_BGRX_8888: |
| 105 | return MDP_BGRX_8888; |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 106 | case HAL_PIXEL_FORMAT_YV12: |
Saurabh Shah | ae1044e | 2012-08-21 16:03:32 -0700 | [diff] [blame] | 107 | return MDP_Y_CR_CB_GH2V2; |
Naseer Ahmed | af49e21 | 2012-07-31 19:13:41 -0700 | [diff] [blame] | 108 | case HAL_PIXEL_FORMAT_YCbCr_422_SP: |
| 109 | return MDP_Y_CBCR_H2V1; |
| 110 | case HAL_PIXEL_FORMAT_YCrCb_420_SP: |
| 111 | return MDP_Y_CRCB_H2V2; |
| 112 | |
| 113 | //From gralloc_priv.h |
| 114 | case HAL_PIXEL_FORMAT_YCbCr_420_SP_TILED: |
| 115 | return MDP_Y_CBCR_H2V2_TILE; |
| 116 | case HAL_PIXEL_FORMAT_YCbCr_420_SP: |
| 117 | return MDP_Y_CBCR_H2V2; |
| 118 | case HAL_PIXEL_FORMAT_YCrCb_422_SP: |
| 119 | return MDP_Y_CRCB_H2V1; |
Ramkumar Radhakrishnan | b52399c | 2013-08-06 20:17:29 -0700 | [diff] [blame] | 120 | case HAL_PIXEL_FORMAT_YCbCr_422_I: |
| 121 | return MDP_YCBYCR_H2V1; |
| 122 | case HAL_PIXEL_FORMAT_YCrCb_422_I: |
| 123 | return MDP_YCRYCB_H2V1; |
Naseer Ahmed | af49e21 | 2012-07-31 19:13:41 -0700 | [diff] [blame] | 124 | case HAL_PIXEL_FORMAT_YCbCr_444_SP: |
| 125 | return MDP_Y_CBCR_H1V1; |
| 126 | case HAL_PIXEL_FORMAT_YCrCb_444_SP: |
| 127 | return MDP_Y_CRCB_H1V1; |
Sushil Chauhan | c5e6148 | 2012-08-22 17:13:32 -0700 | [diff] [blame] | 128 | case HAL_PIXEL_FORMAT_YCbCr_420_SP_VENUS: |
Naseer Ahmed | 8f8cb8a | 2013-08-22 15:34:30 -0400 | [diff] [blame] | 129 | case HAL_PIXEL_FORMAT_NV12_ENCODEABLE: |
| 130 | //NV12 encodeable format maps to the venus format on |
| 131 | //B-Family targets |
Sushil Chauhan | c5e6148 | 2012-08-22 17:13:32 -0700 | [diff] [blame] | 132 | return MDP_Y_CBCR_H2V2_VENUS; |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 133 | default: |
Naseer Ahmed | af49e21 | 2012-07-31 19:13:41 -0700 | [diff] [blame] | 134 | //Unsupported by MDP |
| 135 | //---graphics.h-------- |
| 136 | //HAL_PIXEL_FORMAT_RGBA_5551 |
| 137 | //HAL_PIXEL_FORMAT_RGBA_4444 |
Naseer Ahmed | af49e21 | 2012-07-31 19:13:41 -0700 | [diff] [blame] | 138 | //---gralloc_priv.h----- |
| 139 | //HAL_PIXEL_FORMAT_YCrCb_420_SP_ADRENO = 0x7FA30C01 |
| 140 | //HAL_PIXEL_FORMAT_R_8 = 0x10D |
| 141 | //HAL_PIXEL_FORMAT_RG_88 = 0x10E |
Saurabh Shah | fc3652f | 2013-02-15 13:15:45 -0800 | [diff] [blame] | 142 | ALOGE("%s: Unsupported HAL format = 0x%x", __func__, format); |
| 143 | return -1; |
| 144 | } |
| 145 | // not reached |
| 146 | return -1; |
| 147 | } |
| 148 | |
Manoj Kumar AVM | 8a22081 | 2013-10-10 11:46:06 -0700 | [diff] [blame] | 149 | // This function returns corresponding tile format |
| 150 | // MDSS support following RGB tile formats |
| 151 | // 32 bit formats |
| 152 | // 16 bit formats |
| 153 | int getMdpFormat(int format, bool tileEnabled) |
| 154 | { |
| 155 | if(!tileEnabled) { |
| 156 | return getMdpFormat(format); |
| 157 | } |
| 158 | switch (format) { |
| 159 | case HAL_PIXEL_FORMAT_RGBA_8888 : |
| 160 | return MDP_RGBA_8888_TILE; |
| 161 | case HAL_PIXEL_FORMAT_RGBX_8888: |
| 162 | return MDP_RGBX_8888_TILE; |
| 163 | case HAL_PIXEL_FORMAT_RGB_565: |
| 164 | // Currenty Driver doesnt support 565 tile format |
| 165 | return MDP_RGB_565; |
| 166 | case HAL_PIXEL_FORMAT_BGRA_8888: |
| 167 | return MDP_BGRA_8888_TILE; |
| 168 | case HAL_PIXEL_FORMAT_BGRX_8888: |
| 169 | return MDP_BGRX_8888_TILE; |
| 170 | default: |
| 171 | return getMdpFormat(format); |
| 172 | } |
| 173 | } |
| 174 | |
| 175 | |
| 176 | |
Saurabh Shah | fc3652f | 2013-02-15 13:15:45 -0800 | [diff] [blame] | 177 | //Takes mdp format as input and translates to equivalent HAL format |
| 178 | //Refer to graphics.h, gralloc_priv.h, msm_mdp.h for formats. |
| 179 | int getHALFormat(int mdpFormat) { |
| 180 | switch (mdpFormat) { |
| 181 | //From graphics.h |
| 182 | case MDP_RGBA_8888: |
| 183 | return HAL_PIXEL_FORMAT_RGBA_8888; |
| 184 | case MDP_RGBX_8888: |
| 185 | return HAL_PIXEL_FORMAT_RGBX_8888; |
| 186 | case MDP_RGB_888: |
| 187 | return HAL_PIXEL_FORMAT_RGB_888; |
| 188 | case MDP_RGB_565: |
| 189 | return HAL_PIXEL_FORMAT_RGB_565; |
| 190 | case MDP_BGRA_8888: |
| 191 | return HAL_PIXEL_FORMAT_BGRA_8888; |
| 192 | case MDP_Y_CR_CB_GH2V2: |
| 193 | return HAL_PIXEL_FORMAT_YV12; |
| 194 | case MDP_Y_CBCR_H2V1: |
| 195 | return HAL_PIXEL_FORMAT_YCbCr_422_SP; |
| 196 | case MDP_Y_CRCB_H2V2: |
| 197 | return HAL_PIXEL_FORMAT_YCrCb_420_SP; |
| 198 | |
| 199 | //From gralloc_priv.h |
| 200 | case MDP_Y_CBCR_H2V2_TILE: |
| 201 | return HAL_PIXEL_FORMAT_YCbCr_420_SP_TILED; |
| 202 | case MDP_Y_CBCR_H2V2: |
| 203 | return HAL_PIXEL_FORMAT_YCbCr_420_SP; |
| 204 | case MDP_Y_CRCB_H2V1: |
| 205 | return HAL_PIXEL_FORMAT_YCrCb_422_SP; |
Ramkumar Radhakrishnan | b52399c | 2013-08-06 20:17:29 -0700 | [diff] [blame] | 206 | case MDP_YCBYCR_H2V1: |
| 207 | return HAL_PIXEL_FORMAT_YCbCr_422_I; |
| 208 | case MDP_YCRYCB_H2V1: |
| 209 | return HAL_PIXEL_FORMAT_YCrCb_422_I; |
| 210 | case MDP_Y_CBCR_H1V1: |
Saurabh Shah | fc3652f | 2013-02-15 13:15:45 -0800 | [diff] [blame] | 211 | return HAL_PIXEL_FORMAT_YCbCr_444_SP; |
| 212 | case MDP_Y_CRCB_H1V1: |
| 213 | return HAL_PIXEL_FORMAT_YCrCb_444_SP; |
| 214 | case MDP_Y_CBCR_H2V2_VENUS: |
| 215 | return HAL_PIXEL_FORMAT_YCbCr_420_SP_VENUS; |
| 216 | default: |
| 217 | ALOGE("%s: Unsupported MDP format = 0x%x", __func__, mdpFormat); |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 218 | return -1; |
| 219 | } |
| 220 | // not reached |
| 221 | return -1; |
| 222 | } |
| 223 | |
Saurabh Shah | d1a2278 | 2013-04-10 09:09:45 -0700 | [diff] [blame] | 224 | int getMdpOrient(eTransform rotation) { |
| 225 | int retTrans = 0; |
| 226 | bool trans90 = false; |
| 227 | int mdpVersion = qdutils::MDPVersion::getInstance().getMDPVersion(); |
| 228 | bool aFamily = (mdpVersion < qdutils::MDSS_V5); |
| 229 | |
| 230 | ALOGD_IF(DEBUG_OVERLAY, "%s: In rotation = %d", __FUNCTION__, rotation); |
| 231 | if(rotation & OVERLAY_TRANSFORM_ROT_90) { |
| 232 | retTrans |= MDP_ROT_90; |
| 233 | trans90 = true; |
| 234 | } |
| 235 | |
| 236 | if(rotation & OVERLAY_TRANSFORM_FLIP_H) { |
| 237 | if(trans90 && aFamily) { |
| 238 | //Swap for a-family, since its driver does 90 first |
| 239 | retTrans |= MDP_FLIP_UD; |
| 240 | } else { |
| 241 | retTrans |= MDP_FLIP_LR; |
| 242 | } |
| 243 | } |
| 244 | |
| 245 | if(rotation & OVERLAY_TRANSFORM_FLIP_V) { |
| 246 | if(trans90 && aFamily) { |
| 247 | //Swap for a-family, since its driver does 90 first |
| 248 | retTrans |= MDP_FLIP_LR; |
| 249 | } else { |
| 250 | retTrans |= MDP_FLIP_UD; |
| 251 | } |
| 252 | } |
| 253 | |
| 254 | ALOGD_IF(DEBUG_OVERLAY, "%s: Out rotation = %d", __FUNCTION__, retTrans); |
| 255 | return retTrans; |
| 256 | } |
| 257 | |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 258 | int getDownscaleFactor(const int& src_w, const int& src_h, |
| 259 | const int& dst_w, const int& dst_h) { |
| 260 | int dscale_factor = utils::ROT_DS_NONE; |
| 261 | // We need this check to engage the rotator whenever possible to assist MDP |
| 262 | // in performing video downscale. |
| 263 | // This saves bandwidth and avoids causing the driver to make too many panel |
| 264 | // -mode switches between BLT (writeback) and non-BLT (Direct) modes. |
| 265 | // Use-case: Video playback [with downscaling and rotation]. |
| 266 | if (dst_w && dst_h) |
| 267 | { |
Saurabh Shah | db7ae31 | 2013-03-19 15:45:24 -0700 | [diff] [blame] | 268 | float fDscale = (float)(src_w * src_h) / (float)(dst_w * dst_h); |
| 269 | uint32_t dscale = (int)sqrtf(fDscale); |
| 270 | |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 271 | if(dscale < 2) { |
| 272 | // Down-scale to > 50% of orig. |
| 273 | dscale_factor = utils::ROT_DS_NONE; |
| 274 | } else if(dscale < 4) { |
| 275 | // Down-scale to between > 25% to <= 50% of orig. |
| 276 | dscale_factor = utils::ROT_DS_HALF; |
| 277 | } else if(dscale < 8) { |
| 278 | // Down-scale to between > 12.5% to <= 25% of orig. |
| 279 | dscale_factor = utils::ROT_DS_FOURTH; |
| 280 | } else { |
| 281 | // Down-scale to <= 12.5% of orig. |
| 282 | dscale_factor = utils::ROT_DS_EIGHTH; |
| 283 | } |
| 284 | } |
| 285 | return dscale_factor; |
| 286 | } |
| 287 | |
Saurabh Shah | 1a03d48 | 2013-05-29 13:44:20 -0700 | [diff] [blame] | 288 | //Since this is unavailable on Android, defining it in terms of base 10 |
| 289 | static inline float log2f(const float& x) { |
| 290 | return log(x) / log(2); |
| 291 | } |
| 292 | |
| 293 | void getDecimationFactor(const int& src_w, const int& src_h, |
| 294 | const int& dst_w, const int& dst_h, float& horDscale, |
| 295 | float& verDscale) { |
| 296 | horDscale = ceilf((float)src_w / (float)dst_w); |
| 297 | verDscale = ceilf((float)src_h / (float)dst_h); |
| 298 | |
| 299 | //Next power of 2, if not already |
| 300 | horDscale = powf(2.0f, ceilf(log2f(horDscale))); |
| 301 | verDscale = powf(2.0f, ceilf(log2f(verDscale))); |
| 302 | |
| 303 | //Since MDP can do 1/4 dscale and has better quality, split the task |
| 304 | //between decimator and MDP downscale |
| 305 | horDscale /= 4.0f; |
| 306 | verDscale /= 4.0f; |
| 307 | } |
| 308 | |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 309 | static inline int compute(const uint32_t& x, const uint32_t& y, |
| 310 | const uint32_t& z) { |
| 311 | return x - ( y + z ); |
| 312 | } |
| 313 | |
Saurabh Shah | 76fd655 | 2013-03-14 14:45:38 -0700 | [diff] [blame] | 314 | void preRotateSource(const eTransform& tr, Whf& whf, Dim& srcCrop) { |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 315 | if(tr & OVERLAY_TRANSFORM_FLIP_H) { |
| 316 | srcCrop.x = compute(whf.w, srcCrop.x, srcCrop.w); |
| 317 | } |
| 318 | if(tr & OVERLAY_TRANSFORM_FLIP_V) { |
| 319 | srcCrop.y = compute(whf.h, srcCrop.y, srcCrop.h); |
| 320 | } |
| 321 | if(tr & OVERLAY_TRANSFORM_ROT_90) { |
| 322 | int tmp = srcCrop.x; |
| 323 | srcCrop.x = compute(whf.h, |
| 324 | srcCrop.y, |
| 325 | srcCrop.h); |
| 326 | srcCrop.y = tmp; |
| 327 | swap(whf.w, whf.h); |
| 328 | swap(srcCrop.w, srcCrop.h); |
| 329 | } |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 330 | } |
| 331 | |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 332 | bool is3DTV() { |
| 333 | char is3DTV = '0'; |
| 334 | IOFile fp(Res::edid3dInfoFile, "r"); |
| 335 | (void)fp.read(is3DTV, 1); |
| 336 | ALOGI("3DTV EDID flag: %d", is3DTV); |
| 337 | return (is3DTV == '0') ? false : true; |
| 338 | } |
| 339 | |
| 340 | bool isPanel3D() { |
| 341 | OvFD fd; |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 342 | if(!overlay::open(fd, 0 /*fb*/, Res::fbPath)){ |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 343 | ALOGE("isPanel3D Can't open framebuffer 0"); |
| 344 | return false; |
| 345 | } |
| 346 | fb_fix_screeninfo finfo; |
| 347 | if(!mdp_wrapper::getFScreenInfo(fd.getFD(), finfo)) { |
| 348 | ALOGE("isPanel3D read fb0 failed"); |
| 349 | } |
| 350 | fd.close(); |
| 351 | return (FB_TYPE_3D_PANEL == finfo.type) ? true : false; |
| 352 | } |
| 353 | |
| 354 | bool usePanel3D() { |
| 355 | if(!isPanel3D()) |
| 356 | return false; |
| 357 | char value[PROPERTY_VALUE_MAX]; |
| 358 | property_get("persist.user.panel3D", value, "0"); |
| 359 | int usePanel3D = atoi(value); |
| 360 | return usePanel3D ? true : false; |
| 361 | } |
| 362 | |
| 363 | bool send3DInfoPacket (uint32_t format3D) { |
| 364 | IOFile fp(Res::format3DFile, "wb"); |
| 365 | (void)fp.write("%d", format3D); |
| 366 | if(!fp.valid()) { |
| 367 | ALOGE("send3DInfoPacket: no sysfs entry for setting 3d mode"); |
| 368 | return false; |
| 369 | } |
| 370 | return true; |
| 371 | } |
| 372 | |
| 373 | bool enableBarrier (uint32_t orientation) { |
| 374 | IOFile fp(Res::barrierFile, "wb"); |
| 375 | (void)fp.write("%d", orientation); |
| 376 | if(!fp.valid()) { |
| 377 | ALOGE("enableBarrier no sysfs entry for " |
| 378 | "enabling barriers on 3D panel"); |
| 379 | return false; |
| 380 | } |
| 381 | return true; |
| 382 | } |
| 383 | |
| 384 | uint32_t getS3DFormat(uint32_t fmt) { |
| 385 | // The S3D is part of the HAL_PIXEL_FORMAT_YV12 value. Add |
| 386 | // an explicit check for the format |
| 387 | if (fmt == HAL_PIXEL_FORMAT_YV12) { |
| 388 | return 0; |
| 389 | } |
| 390 | uint32_t fmt3D = format3D(fmt); |
| 391 | uint32_t fIn3D = format3DInput(fmt3D); // MSB 2 bytes - inp |
| 392 | uint32_t fOut3D = format3DOutput(fmt3D); // LSB 2 bytes - out |
| 393 | fmt3D = fIn3D | fOut3D; |
| 394 | if (!fIn3D) { |
| 395 | fmt3D |= fOut3D << SHIFT_TOT_3D; //Set the input format |
| 396 | } |
| 397 | if (!fOut3D) { |
| 398 | switch (fIn3D) { |
| 399 | case HAL_3D_IN_SIDE_BY_SIDE_L_R: |
| 400 | case HAL_3D_IN_SIDE_BY_SIDE_R_L: |
| 401 | // For all side by side formats, set the output |
| 402 | // format as Side-by-Side i.e 0x1 |
| 403 | fmt3D |= HAL_3D_IN_SIDE_BY_SIDE_L_R >> SHIFT_TOT_3D; |
| 404 | break; |
| 405 | default: |
| 406 | fmt3D |= fIn3D >> SHIFT_TOT_3D; //Set the output format |
| 407 | } |
| 408 | } |
| 409 | return fmt3D; |
| 410 | } |
| 411 | |
Saurabh Shah | 0d0a7cb | 2013-02-12 17:58:19 -0800 | [diff] [blame] | 412 | void getDump(char *buf, size_t len, const char *prefix, |
| 413 | const mdp_overlay& ov) { |
| 414 | char str[256] = {'\0'}; |
| 415 | snprintf(str, 256, |
Saurabh Shah | bd2d083 | 2013-04-04 14:33:08 -0700 | [diff] [blame] | 416 | "%s id=%d z=%d fg=%d alpha=%d mask=%d flags=0x%x H.Deci=%d," |
| 417 | "V.Deci=%d\n", |
Saurabh Shah | 0d0a7cb | 2013-02-12 17:58:19 -0800 | [diff] [blame] | 418 | prefix, ov.id, ov.z_order, ov.is_fg, ov.alpha, |
Saurabh Shah | bd2d083 | 2013-04-04 14:33:08 -0700 | [diff] [blame] | 419 | ov.transp_mask, ov.flags, ov.horz_deci, ov.vert_deci); |
Ramkumar Radhakrishnan | 36bd527 | 2014-01-31 20:03:01 -0800 | [diff] [blame^] | 420 | strlcat(buf, str, len); |
Saurabh Shah | ae61b2b | 2013-04-10 16:37:25 -0700 | [diff] [blame] | 421 | getDump(buf, len, "\tsrc", ov.src); |
| 422 | getDump(buf, len, "\tsrc_rect", ov.src_rect); |
| 423 | getDump(buf, len, "\tdst_rect", ov.dst_rect); |
Saurabh Shah | 0d0a7cb | 2013-02-12 17:58:19 -0800 | [diff] [blame] | 424 | } |
| 425 | |
Ramkumar Radhakrishnan | 36bd527 | 2014-01-31 20:03:01 -0800 | [diff] [blame^] | 426 | void getDump(char *buf, size_t len, const char *prefix, |
Saurabh Shah | 0d0a7cb | 2013-02-12 17:58:19 -0800 | [diff] [blame] | 427 | const msmfb_img& ov) { |
| 428 | char str_src[256] = {'\0'}; |
| 429 | snprintf(str_src, 256, |
| 430 | "%s w=%d h=%d format=%d %s\n", |
| 431 | prefix, ov.width, ov.height, ov.format, |
| 432 | overlay::utils::getFormatString(ov.format)); |
Ramkumar Radhakrishnan | 36bd527 | 2014-01-31 20:03:01 -0800 | [diff] [blame^] | 433 | strlcat(buf, str_src, len); |
Saurabh Shah | 0d0a7cb | 2013-02-12 17:58:19 -0800 | [diff] [blame] | 434 | } |
| 435 | |
Ramkumar Radhakrishnan | 36bd527 | 2014-01-31 20:03:01 -0800 | [diff] [blame^] | 436 | void getDump(char *buf, size_t len, const char *prefix, |
Saurabh Shah | 0d0a7cb | 2013-02-12 17:58:19 -0800 | [diff] [blame] | 437 | const mdp_rect& ov) { |
| 438 | char str_rect[256] = {'\0'}; |
| 439 | snprintf(str_rect, 256, |
| 440 | "%s x=%d y=%d w=%d h=%d\n", |
| 441 | prefix, ov.x, ov.y, ov.w, ov.h); |
Ramkumar Radhakrishnan | 36bd527 | 2014-01-31 20:03:01 -0800 | [diff] [blame^] | 442 | strlcat(buf, str_rect, len); |
Saurabh Shah | 0d0a7cb | 2013-02-12 17:58:19 -0800 | [diff] [blame] | 443 | } |
| 444 | |
| 445 | void getDump(char *buf, size_t len, const char *prefix, |
| 446 | const msmfb_overlay_data& ov) { |
| 447 | char str[256] = {'\0'}; |
| 448 | snprintf(str, 256, |
| 449 | "%s id=%d\n", |
| 450 | prefix, ov.id); |
Ramkumar Radhakrishnan | 36bd527 | 2014-01-31 20:03:01 -0800 | [diff] [blame^] | 451 | strlcat(buf, str, len); |
Saurabh Shah | ae61b2b | 2013-04-10 16:37:25 -0700 | [diff] [blame] | 452 | getDump(buf, len, "\tdata", ov.data); |
Saurabh Shah | 0d0a7cb | 2013-02-12 17:58:19 -0800 | [diff] [blame] | 453 | } |
| 454 | |
Ramkumar Radhakrishnan | 36bd527 | 2014-01-31 20:03:01 -0800 | [diff] [blame^] | 455 | void getDump(char *buf, size_t len, const char *prefix, |
Saurabh Shah | 0d0a7cb | 2013-02-12 17:58:19 -0800 | [diff] [blame] | 456 | const msmfb_data& ov) { |
| 457 | char str_data[256] = {'\0'}; |
| 458 | snprintf(str_data, 256, |
Saurabh Shah | 7ef9ec9 | 2013-10-29 10:32:23 -0700 | [diff] [blame] | 459 | "%s offset=%d memid=%d id=%d flags=0x%x\n", |
| 460 | prefix, ov.offset, ov.memory_id, ov.id, ov.flags); |
Ramkumar Radhakrishnan | 36bd527 | 2014-01-31 20:03:01 -0800 | [diff] [blame^] | 461 | strlcat(buf, str_data, len); |
Saurabh Shah | 0d0a7cb | 2013-02-12 17:58:19 -0800 | [diff] [blame] | 462 | } |
| 463 | |
| 464 | void getDump(char *buf, size_t len, const char *prefix, |
| 465 | const msm_rotator_img_info& rot) { |
| 466 | char str[256] = {'\0'}; |
| 467 | snprintf(str, 256, "%s sessid=%u rot=%d, enable=%d downscale=%d\n", |
| 468 | prefix, rot.session_id, rot.rotations, rot.enable, |
| 469 | rot.downscale_ratio); |
Ramkumar Radhakrishnan | 36bd527 | 2014-01-31 20:03:01 -0800 | [diff] [blame^] | 470 | strlcat(buf, str, len); |
Saurabh Shah | 0d0a7cb | 2013-02-12 17:58:19 -0800 | [diff] [blame] | 471 | getDump(buf, len, "\tsrc", rot.src); |
| 472 | getDump(buf, len, "\tdst", rot.dst); |
| 473 | getDump(buf, len, "\tsrc_rect", rot.src_rect); |
| 474 | } |
| 475 | |
| 476 | void getDump(char *buf, size_t len, const char *prefix, |
| 477 | const msm_rotator_data_info& rot) { |
| 478 | char str[256] = {'\0'}; |
| 479 | snprintf(str, 256, |
Saurabh Shah | ae61b2b | 2013-04-10 16:37:25 -0700 | [diff] [blame] | 480 | "%s sessid=%u\n", |
| 481 | prefix, rot.session_id); |
Ramkumar Radhakrishnan | 36bd527 | 2014-01-31 20:03:01 -0800 | [diff] [blame^] | 482 | strlcat(buf, str, len); |
Saurabh Shah | 0d0a7cb | 2013-02-12 17:58:19 -0800 | [diff] [blame] | 483 | getDump(buf, len, "\tsrc", rot.src); |
| 484 | getDump(buf, len, "\tdst", rot.dst); |
Saurabh Shah | 0d0a7cb | 2013-02-12 17:58:19 -0800 | [diff] [blame] | 485 | } |
| 486 | |
Sushil Chauhan | 1cac815 | 2013-05-08 15:53:51 -0700 | [diff] [blame] | 487 | //Helper to even out x,w and y,h pairs |
| 488 | //x,y are always evened to ceil and w,h are evened to floor |
| 489 | void normalizeCrop(uint32_t& xy, uint32_t& wh) { |
| 490 | if(xy & 1) { |
| 491 | even_ceil(xy); |
| 492 | if(wh & 1) |
| 493 | even_floor(wh); |
| 494 | else |
| 495 | wh -= 2; |
| 496 | } else { |
| 497 | even_floor(wh); |
| 498 | } |
| 499 | } |
| 500 | |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 501 | } // utils |
| 502 | |
| 503 | } // overlay |