Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 1 | /* |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 2 | * Copyright (c) 2011-2012, The Linux Foundation. All rights reserved. |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 3 | * |
| 4 | * Redistribution and use in source and binary forms, with or without |
| 5 | * modification, are permitted provided that the following conditions are |
| 6 | * met: |
| 7 | * * Redistributions of source code must retain the above copyright |
| 8 | * notice, this list of conditions and the following disclaimer. |
| 9 | * * Redistributions in binary form must reproduce the above |
| 10 | * copyright notice, this list of conditions and the following |
| 11 | * disclaimer in the documentation and/or other materials provided |
| 12 | * with the distribution. |
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> |
| 31 | #include <utils/Log.h> |
| 32 | #include <linux/msm_mdp.h> |
| 33 | #include <cutils/properties.h> |
| 34 | #include "gralloc_priv.h" |
| 35 | #include "fb_priv.h" |
| 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" |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 39 | |
| 40 | // just a helper static thingy |
| 41 | namespace { |
| 42 | struct IOFile { |
| 43 | IOFile(const char* s, const char* mode) : fp(0) { |
| 44 | fp = ::fopen(s, mode); |
| 45 | if(!fp) { |
| 46 | ALOGE("Failed open %s", s); |
| 47 | } |
| 48 | } |
| 49 | template <class T> |
| 50 | size_t read(T& r, size_t elem) { |
| 51 | if(fp) { |
| 52 | return ::fread(&r, sizeof(T), elem, fp); |
| 53 | } |
| 54 | return 0; |
| 55 | } |
| 56 | size_t write(const char* s, uint32_t val) { |
| 57 | if(fp) { |
| 58 | return ::fprintf(fp, s, val); |
| 59 | } |
| 60 | return 0; |
| 61 | } |
| 62 | bool valid() const { return fp != 0; } |
| 63 | ~IOFile() { |
| 64 | if(fp) ::fclose(fp); |
| 65 | fp=0; |
| 66 | } |
| 67 | FILE* fp; |
| 68 | }; |
| 69 | } |
| 70 | |
| 71 | namespace overlay { |
| 72 | |
| 73 | //----------From class Res ------------------------------ |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 74 | const char* const Res::fbPath = "/dev/graphics/fb%u"; |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 75 | const char* const Res::rotPath = "/dev/msm_rotator"; |
| 76 | const char* const Res::format3DFile = |
| 77 | "/sys/class/graphics/fb1/format_3d"; |
| 78 | const char* const Res::edid3dInfoFile = |
| 79 | "/sys/class/graphics/fb1/3d_present"; |
| 80 | const char* const Res::barrierFile = |
| 81 | "/sys/devices/platform/mipi_novatek.0/enable_3d_barrier"; |
| 82 | //-------------------------------------------------------- |
| 83 | |
| 84 | |
| 85 | |
| 86 | namespace utils { |
Ajay Dudani | cb3da0a | 2012-09-07 13:37:49 -0700 | [diff] [blame] | 87 | //------------------ defines ----------------------------- |
| 88 | #define FB_DEVICE_TEMPLATE "/dev/graphics/fb%u" |
| 89 | #define NUM_FB_DEVICES 3 |
| 90 | |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 91 | //-------------------------------------------------------- |
| 92 | FrameBufferInfo::FrameBufferInfo() { |
| 93 | mFBWidth = 0; |
| 94 | mFBHeight = 0; |
| 95 | mBorderFillSupported = false; |
| 96 | |
| 97 | OvFD mFd; |
| 98 | |
| 99 | // Use open defined in overlayFD file to open fd for fb0 |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 100 | if(!overlay::open(mFd, 0, Res::fbPath)) { |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 101 | ALOGE("FrameBufferInfo: failed to open fd"); |
| 102 | return; |
| 103 | } |
| 104 | |
| 105 | if (!mFd.valid()) { |
| 106 | ALOGE("FrameBufferInfo: FD not valid"); |
| 107 | return; |
| 108 | } |
| 109 | |
| 110 | fb_var_screeninfo vinfo; |
| 111 | if (!mdp_wrapper::getVScreenInfo(mFd.getFD(), vinfo)) { |
| 112 | ALOGE("FrameBufferInfo: failed getVScreenInfo on fb0"); |
| 113 | mFd.close(); |
| 114 | return; |
| 115 | } |
| 116 | |
Saurabh Shah | 94822ee | 2012-08-17 16:48:43 -0700 | [diff] [blame] | 117 | int mdpVersion = qdutils::MDPVersion::getInstance().getMDPVersion(); |
| 118 | if (mdpVersion < qdutils::MDSS_V5) { |
| 119 | mdp_overlay ov; |
| 120 | memset(&ov, 0, sizeof(ov)); |
| 121 | ov.id = 1; |
| 122 | if (!mdp_wrapper::getOverlay(mFd.getFD(), ov)) { |
| 123 | ALOGE("FrameBufferInfo: failed getOverlay on fb0"); |
| 124 | mFd.close(); |
| 125 | return; |
| 126 | } |
| 127 | mBorderFillSupported = (ov.flags & MDP_BORDERFILL_SUPPORTED) ? |
| 128 | true : false; |
| 129 | } else { |
| 130 | // badger always support border fill |
| 131 | mBorderFillSupported = true; |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 132 | } |
| 133 | |
| 134 | mFd.close(); |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 135 | mFBWidth = vinfo.xres; |
| 136 | mFBHeight = vinfo.yres; |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 137 | } |
| 138 | |
| 139 | FrameBufferInfo* FrameBufferInfo::getInstance() { |
| 140 | if (!sFBInfoInstance) { |
| 141 | sFBInfoInstance = new FrameBufferInfo; |
| 142 | } |
| 143 | return sFBInfoInstance; |
| 144 | } |
| 145 | |
| 146 | int FrameBufferInfo::getWidth() const { |
| 147 | return mFBWidth; |
| 148 | } |
| 149 | |
| 150 | int FrameBufferInfo::getHeight() const { |
| 151 | return mFBHeight; |
| 152 | } |
| 153 | |
Ajay Dudani | cb3da0a | 2012-09-07 13:37:49 -0700 | [diff] [blame] | 154 | /* clears any VG pipes allocated to the fb devices */ |
| 155 | int initOverlay() { |
Naseer Ahmed | ff5c530 | 2012-12-03 16:00:13 -0500 | [diff] [blame] | 156 | int mdpVersion = qdutils::MDPVersion::getInstance().getMDPVersion(); |
| 157 | if (mdpVersion < qdutils::MDSS_V5) { |
| 158 | msmfb_mixer_info_req req; |
| 159 | mdp_mixer_info *minfo = NULL; |
| 160 | char name[64]; |
| 161 | int fd = -1; |
| 162 | for(int i = 0; i < NUM_FB_DEVICES; i++) { |
| 163 | snprintf(name, 64, FB_DEVICE_TEMPLATE, i); |
| 164 | ALOGD("initoverlay:: opening the device:: %s", name); |
| 165 | fd = ::open(name, O_RDWR, 0); |
| 166 | if(fd < 0) { |
| 167 | ALOGE("cannot open framebuffer(%d)", i); |
| 168 | return -1; |
Ajay Dudani | cb3da0a | 2012-09-07 13:37:49 -0700 | [diff] [blame] | 169 | } |
Naseer Ahmed | ff5c530 | 2012-12-03 16:00:13 -0500 | [diff] [blame] | 170 | //Get the mixer configuration */ |
| 171 | req.mixer_num = i; |
| 172 | if (ioctl(fd, MSMFB_MIXER_INFO, &req) == -1) { |
| 173 | ALOGE("ERROR: MSMFB_MIXER_INFO ioctl failed"); |
| 174 | close(fd); |
| 175 | return -1; |
| 176 | } |
| 177 | minfo = req.info; |
| 178 | for (int j = 0; j < req.cnt; j++) { |
| 179 | ALOGD("ndx=%d num=%d z_order=%d", minfo->pndx, minfo->pnum, |
| 180 | minfo->z_order); |
| 181 | // except the RGB base layer with z_order of -1, clear any |
| 182 | // other pipes connected to mixer. |
| 183 | if((minfo->z_order) != -1) { |
| 184 | int index = minfo->pndx; |
| 185 | ALOGD("Unset overlay with index: %d at mixer %d", index, i); |
| 186 | if(ioctl(fd, MSMFB_OVERLAY_UNSET, &index) == -1) { |
| 187 | ALOGE("ERROR: MSMFB_OVERLAY_UNSET failed"); |
| 188 | close(fd); |
| 189 | return -1; |
| 190 | } |
| 191 | } |
| 192 | minfo++; |
| 193 | } |
| 194 | close(fd); |
| 195 | fd = -1; |
Ajay Dudani | cb3da0a | 2012-09-07 13:37:49 -0700 | [diff] [blame] | 196 | } |
Ajay Dudani | cb3da0a | 2012-09-07 13:37:49 -0700 | [diff] [blame] | 197 | } |
| 198 | return 0; |
| 199 | } |
| 200 | |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 201 | //-------------------------------------------------------- |
Naseer Ahmed | af49e21 | 2012-07-31 19:13:41 -0700 | [diff] [blame] | 202 | //Refer to graphics.h, gralloc_priv.h, msm_mdp.h |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 203 | int getMdpFormat(int format) { |
| 204 | switch (format) { |
Naseer Ahmed | af49e21 | 2012-07-31 19:13:41 -0700 | [diff] [blame] | 205 | //From graphics.h |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 206 | case HAL_PIXEL_FORMAT_RGBA_8888 : |
| 207 | return MDP_RGBA_8888; |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 208 | case HAL_PIXEL_FORMAT_RGBX_8888: |
| 209 | return MDP_RGBX_8888; |
Naseer Ahmed | af49e21 | 2012-07-31 19:13:41 -0700 | [diff] [blame] | 210 | case HAL_PIXEL_FORMAT_RGB_888: |
| 211 | return MDP_RGB_888; |
| 212 | case HAL_PIXEL_FORMAT_RGB_565: |
| 213 | return MDP_RGB_565; |
| 214 | case HAL_PIXEL_FORMAT_BGRA_8888: |
| 215 | return MDP_BGRA_8888; |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 216 | case HAL_PIXEL_FORMAT_YV12: |
Saurabh Shah | ae1044e | 2012-08-21 16:03:32 -0700 | [diff] [blame] | 217 | return MDP_Y_CR_CB_GH2V2; |
Naseer Ahmed | af49e21 | 2012-07-31 19:13:41 -0700 | [diff] [blame] | 218 | case HAL_PIXEL_FORMAT_YCbCr_422_SP: |
| 219 | return MDP_Y_CBCR_H2V1; |
| 220 | case HAL_PIXEL_FORMAT_YCrCb_420_SP: |
| 221 | return MDP_Y_CRCB_H2V2; |
| 222 | |
| 223 | //From gralloc_priv.h |
| 224 | case HAL_PIXEL_FORMAT_YCbCr_420_SP_TILED: |
| 225 | return MDP_Y_CBCR_H2V2_TILE; |
| 226 | case HAL_PIXEL_FORMAT_YCbCr_420_SP: |
| 227 | return MDP_Y_CBCR_H2V2; |
| 228 | case HAL_PIXEL_FORMAT_YCrCb_422_SP: |
| 229 | return MDP_Y_CRCB_H2V1; |
| 230 | case HAL_PIXEL_FORMAT_YCbCr_444_SP: |
| 231 | return MDP_Y_CBCR_H1V1; |
| 232 | case HAL_PIXEL_FORMAT_YCrCb_444_SP: |
| 233 | return MDP_Y_CRCB_H1V1; |
Sushil Chauhan | c5e6148 | 2012-08-22 17:13:32 -0700 | [diff] [blame] | 234 | case HAL_PIXEL_FORMAT_YCbCr_420_SP_VENUS: |
| 235 | return MDP_Y_CBCR_H2V2_VENUS; |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 236 | default: |
Naseer Ahmed | af49e21 | 2012-07-31 19:13:41 -0700 | [diff] [blame] | 237 | //Unsupported by MDP |
| 238 | //---graphics.h-------- |
| 239 | //HAL_PIXEL_FORMAT_RGBA_5551 |
| 240 | //HAL_PIXEL_FORMAT_RGBA_4444 |
| 241 | //HAL_PIXEL_FORMAT_YCbCr_422_I |
| 242 | //---gralloc_priv.h----- |
| 243 | //HAL_PIXEL_FORMAT_YCrCb_420_SP_ADRENO = 0x7FA30C01 |
| 244 | //HAL_PIXEL_FORMAT_R_8 = 0x10D |
| 245 | //HAL_PIXEL_FORMAT_RG_88 = 0x10E |
| 246 | ALOGE("%s: Unsupported format = 0x%x", __func__, format); |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 247 | return -1; |
| 248 | } |
| 249 | // not reached |
| 250 | return -1; |
| 251 | } |
| 252 | |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 253 | bool is3DTV() { |
| 254 | char is3DTV = '0'; |
| 255 | IOFile fp(Res::edid3dInfoFile, "r"); |
| 256 | (void)fp.read(is3DTV, 1); |
| 257 | ALOGI("3DTV EDID flag: %d", is3DTV); |
| 258 | return (is3DTV == '0') ? false : true; |
| 259 | } |
| 260 | |
| 261 | bool isPanel3D() { |
| 262 | OvFD fd; |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 263 | if(!overlay::open(fd, 0 /*fb*/, Res::fbPath)){ |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 264 | ALOGE("isPanel3D Can't open framebuffer 0"); |
| 265 | return false; |
| 266 | } |
| 267 | fb_fix_screeninfo finfo; |
| 268 | if(!mdp_wrapper::getFScreenInfo(fd.getFD(), finfo)) { |
| 269 | ALOGE("isPanel3D read fb0 failed"); |
| 270 | } |
| 271 | fd.close(); |
| 272 | return (FB_TYPE_3D_PANEL == finfo.type) ? true : false; |
| 273 | } |
| 274 | |
| 275 | bool usePanel3D() { |
| 276 | if(!isPanel3D()) |
| 277 | return false; |
| 278 | char value[PROPERTY_VALUE_MAX]; |
| 279 | property_get("persist.user.panel3D", value, "0"); |
| 280 | int usePanel3D = atoi(value); |
| 281 | return usePanel3D ? true : false; |
| 282 | } |
| 283 | |
| 284 | bool send3DInfoPacket (uint32_t format3D) { |
| 285 | IOFile fp(Res::format3DFile, "wb"); |
| 286 | (void)fp.write("%d", format3D); |
| 287 | if(!fp.valid()) { |
| 288 | ALOGE("send3DInfoPacket: no sysfs entry for setting 3d mode"); |
| 289 | return false; |
| 290 | } |
| 291 | return true; |
| 292 | } |
| 293 | |
| 294 | bool enableBarrier (uint32_t orientation) { |
| 295 | IOFile fp(Res::barrierFile, "wb"); |
| 296 | (void)fp.write("%d", orientation); |
| 297 | if(!fp.valid()) { |
| 298 | ALOGE("enableBarrier no sysfs entry for " |
| 299 | "enabling barriers on 3D panel"); |
| 300 | return false; |
| 301 | } |
| 302 | return true; |
| 303 | } |
| 304 | |
| 305 | uint32_t getS3DFormat(uint32_t fmt) { |
| 306 | // The S3D is part of the HAL_PIXEL_FORMAT_YV12 value. Add |
| 307 | // an explicit check for the format |
| 308 | if (fmt == HAL_PIXEL_FORMAT_YV12) { |
| 309 | return 0; |
| 310 | } |
| 311 | uint32_t fmt3D = format3D(fmt); |
| 312 | uint32_t fIn3D = format3DInput(fmt3D); // MSB 2 bytes - inp |
| 313 | uint32_t fOut3D = format3DOutput(fmt3D); // LSB 2 bytes - out |
| 314 | fmt3D = fIn3D | fOut3D; |
| 315 | if (!fIn3D) { |
| 316 | fmt3D |= fOut3D << SHIFT_TOT_3D; //Set the input format |
| 317 | } |
| 318 | if (!fOut3D) { |
| 319 | switch (fIn3D) { |
| 320 | case HAL_3D_IN_SIDE_BY_SIDE_L_R: |
| 321 | case HAL_3D_IN_SIDE_BY_SIDE_R_L: |
| 322 | // For all side by side formats, set the output |
| 323 | // format as Side-by-Side i.e 0x1 |
| 324 | fmt3D |= HAL_3D_IN_SIDE_BY_SIDE_L_R >> SHIFT_TOT_3D; |
| 325 | break; |
| 326 | default: |
| 327 | fmt3D |= fIn3D >> SHIFT_TOT_3D; //Set the output format |
| 328 | } |
| 329 | } |
| 330 | return fmt3D; |
| 331 | } |
| 332 | |
Sushil Chauhan | b4d184f | 2013-02-11 16:13:10 -0800 | [diff] [blame] | 333 | bool isMdssRotator() { |
| 334 | int mdpVersion = qdutils::MDPVersion::getInstance().getMDPVersion(); |
| 335 | return (mdpVersion >= qdutils::MDSS_V5); |
| 336 | } |
| 337 | |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 338 | } // utils |
| 339 | |
| 340 | } // overlay |