Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2011-2012, Code Aurora Forum. All rights reserved. |
| 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. |
| 13 | * * Neither the name of Code Aurora Forum, Inc. nor the names of its |
| 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 { |
| 87 | //-------------------------------------------------------- |
| 88 | FrameBufferInfo::FrameBufferInfo() { |
| 89 | mFBWidth = 0; |
| 90 | mFBHeight = 0; |
| 91 | mBorderFillSupported = false; |
| 92 | |
| 93 | OvFD mFd; |
| 94 | |
| 95 | // Use open defined in overlayFD file to open fd for fb0 |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 96 | if(!overlay::open(mFd, 0, Res::fbPath)) { |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 97 | ALOGE("FrameBufferInfo: failed to open fd"); |
| 98 | return; |
| 99 | } |
| 100 | |
| 101 | if (!mFd.valid()) { |
| 102 | ALOGE("FrameBufferInfo: FD not valid"); |
| 103 | return; |
| 104 | } |
| 105 | |
| 106 | fb_var_screeninfo vinfo; |
| 107 | if (!mdp_wrapper::getVScreenInfo(mFd.getFD(), vinfo)) { |
| 108 | ALOGE("FrameBufferInfo: failed getVScreenInfo on fb0"); |
| 109 | mFd.close(); |
| 110 | return; |
| 111 | } |
| 112 | |
Saurabh Shah | 94822ee | 2012-08-17 16:48:43 -0700 | [diff] [blame] | 113 | int mdpVersion = qdutils::MDPVersion::getInstance().getMDPVersion(); |
| 114 | if (mdpVersion < qdutils::MDSS_V5) { |
| 115 | mdp_overlay ov; |
| 116 | memset(&ov, 0, sizeof(ov)); |
| 117 | ov.id = 1; |
| 118 | if (!mdp_wrapper::getOverlay(mFd.getFD(), ov)) { |
| 119 | ALOGE("FrameBufferInfo: failed getOverlay on fb0"); |
| 120 | mFd.close(); |
| 121 | return; |
| 122 | } |
| 123 | mBorderFillSupported = (ov.flags & MDP_BORDERFILL_SUPPORTED) ? |
| 124 | true : false; |
| 125 | } else { |
| 126 | // badger always support border fill |
| 127 | mBorderFillSupported = true; |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 128 | } |
| 129 | |
| 130 | mFd.close(); |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 131 | mFBWidth = vinfo.xres; |
| 132 | mFBHeight = vinfo.yres; |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 133 | } |
| 134 | |
| 135 | FrameBufferInfo* FrameBufferInfo::getInstance() { |
| 136 | if (!sFBInfoInstance) { |
| 137 | sFBInfoInstance = new FrameBufferInfo; |
| 138 | } |
| 139 | return sFBInfoInstance; |
| 140 | } |
| 141 | |
| 142 | int FrameBufferInfo::getWidth() const { |
| 143 | return mFBWidth; |
| 144 | } |
| 145 | |
| 146 | int FrameBufferInfo::getHeight() const { |
| 147 | return mFBHeight; |
| 148 | } |
| 149 | |
| 150 | bool FrameBufferInfo::supportTrueMirroring() const { |
Naseer Ahmed | 0c8b7b5 | 2012-07-20 09:06:13 -0700 | [diff] [blame] | 151 | char value[PROPERTY_VALUE_MAX] = {0}; |
| 152 | property_get("hw.trueMirrorSupported", value, "0"); |
| 153 | int trueMirroringSupported = atoi(value); |
| 154 | return (trueMirroringSupported && mBorderFillSupported); |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 155 | } |
| 156 | |
| 157 | //-------------------------------------------------------- |
Naseer Ahmed | af49e21 | 2012-07-31 19:13:41 -0700 | [diff] [blame] | 158 | //Refer to graphics.h, gralloc_priv.h, msm_mdp.h |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 159 | int getMdpFormat(int format) { |
| 160 | switch (format) { |
Naseer Ahmed | af49e21 | 2012-07-31 19:13:41 -0700 | [diff] [blame] | 161 | //From graphics.h |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 162 | case HAL_PIXEL_FORMAT_RGBA_8888 : |
| 163 | return MDP_RGBA_8888; |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 164 | case HAL_PIXEL_FORMAT_RGBX_8888: |
| 165 | return MDP_RGBX_8888; |
Naseer Ahmed | af49e21 | 2012-07-31 19:13:41 -0700 | [diff] [blame] | 166 | case HAL_PIXEL_FORMAT_RGB_888: |
| 167 | return MDP_RGB_888; |
| 168 | case HAL_PIXEL_FORMAT_RGB_565: |
| 169 | return MDP_RGB_565; |
| 170 | case HAL_PIXEL_FORMAT_BGRA_8888: |
| 171 | return MDP_BGRA_8888; |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 172 | case HAL_PIXEL_FORMAT_YV12: |
Saurabh Shah | ae1044e | 2012-08-21 16:03:32 -0700 | [diff] [blame^] | 173 | return MDP_Y_CR_CB_GH2V2; |
Naseer Ahmed | af49e21 | 2012-07-31 19:13:41 -0700 | [diff] [blame] | 174 | case HAL_PIXEL_FORMAT_YCbCr_422_SP: |
| 175 | return MDP_Y_CBCR_H2V1; |
| 176 | case HAL_PIXEL_FORMAT_YCrCb_420_SP: |
| 177 | return MDP_Y_CRCB_H2V2; |
| 178 | |
| 179 | //From gralloc_priv.h |
| 180 | case HAL_PIXEL_FORMAT_YCbCr_420_SP_TILED: |
| 181 | return MDP_Y_CBCR_H2V2_TILE; |
| 182 | case HAL_PIXEL_FORMAT_YCbCr_420_SP: |
| 183 | return MDP_Y_CBCR_H2V2; |
| 184 | case HAL_PIXEL_FORMAT_YCrCb_422_SP: |
| 185 | return MDP_Y_CRCB_H2V1; |
| 186 | case HAL_PIXEL_FORMAT_YCbCr_444_SP: |
| 187 | return MDP_Y_CBCR_H1V1; |
| 188 | case HAL_PIXEL_FORMAT_YCrCb_444_SP: |
| 189 | return MDP_Y_CRCB_H1V1; |
| 190 | |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 191 | default: |
Naseer Ahmed | af49e21 | 2012-07-31 19:13:41 -0700 | [diff] [blame] | 192 | //Unsupported by MDP |
| 193 | //---graphics.h-------- |
| 194 | //HAL_PIXEL_FORMAT_RGBA_5551 |
| 195 | //HAL_PIXEL_FORMAT_RGBA_4444 |
| 196 | //HAL_PIXEL_FORMAT_YCbCr_422_I |
| 197 | //---gralloc_priv.h----- |
| 198 | //HAL_PIXEL_FORMAT_YCrCb_420_SP_ADRENO = 0x7FA30C01 |
| 199 | //HAL_PIXEL_FORMAT_R_8 = 0x10D |
| 200 | //HAL_PIXEL_FORMAT_RG_88 = 0x10E |
| 201 | ALOGE("%s: Unsupported format = 0x%x", __func__, format); |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 202 | return -1; |
| 203 | } |
| 204 | // not reached |
| 205 | return -1; |
| 206 | } |
| 207 | |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 208 | //Set by client as HDMI/WFD |
| 209 | void setExtType(const int& type) { |
| 210 | if(type != HDMI && type != WFD) { |
| 211 | ALOGE("%s: Unrecognized type %d", __func__, type); |
| 212 | return; |
| 213 | } |
| 214 | sExtType = type; |
| 215 | } |
| 216 | |
| 217 | //Return External panel type set by client. |
| 218 | int getExtType() { |
| 219 | return sExtType; |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 220 | } |
| 221 | |
| 222 | bool is3DTV() { |
| 223 | char is3DTV = '0'; |
| 224 | IOFile fp(Res::edid3dInfoFile, "r"); |
| 225 | (void)fp.read(is3DTV, 1); |
| 226 | ALOGI("3DTV EDID flag: %d", is3DTV); |
| 227 | return (is3DTV == '0') ? false : true; |
| 228 | } |
| 229 | |
| 230 | bool isPanel3D() { |
| 231 | OvFD fd; |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 232 | if(!overlay::open(fd, 0 /*fb*/, Res::fbPath)){ |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 233 | ALOGE("isPanel3D Can't open framebuffer 0"); |
| 234 | return false; |
| 235 | } |
| 236 | fb_fix_screeninfo finfo; |
| 237 | if(!mdp_wrapper::getFScreenInfo(fd.getFD(), finfo)) { |
| 238 | ALOGE("isPanel3D read fb0 failed"); |
| 239 | } |
| 240 | fd.close(); |
| 241 | return (FB_TYPE_3D_PANEL == finfo.type) ? true : false; |
| 242 | } |
| 243 | |
| 244 | bool usePanel3D() { |
| 245 | if(!isPanel3D()) |
| 246 | return false; |
| 247 | char value[PROPERTY_VALUE_MAX]; |
| 248 | property_get("persist.user.panel3D", value, "0"); |
| 249 | int usePanel3D = atoi(value); |
| 250 | return usePanel3D ? true : false; |
| 251 | } |
| 252 | |
| 253 | bool send3DInfoPacket (uint32_t format3D) { |
| 254 | IOFile fp(Res::format3DFile, "wb"); |
| 255 | (void)fp.write("%d", format3D); |
| 256 | if(!fp.valid()) { |
| 257 | ALOGE("send3DInfoPacket: no sysfs entry for setting 3d mode"); |
| 258 | return false; |
| 259 | } |
| 260 | return true; |
| 261 | } |
| 262 | |
| 263 | bool enableBarrier (uint32_t orientation) { |
| 264 | IOFile fp(Res::barrierFile, "wb"); |
| 265 | (void)fp.write("%d", orientation); |
| 266 | if(!fp.valid()) { |
| 267 | ALOGE("enableBarrier no sysfs entry for " |
| 268 | "enabling barriers on 3D panel"); |
| 269 | return false; |
| 270 | } |
| 271 | return true; |
| 272 | } |
| 273 | |
| 274 | uint32_t getS3DFormat(uint32_t fmt) { |
| 275 | // The S3D is part of the HAL_PIXEL_FORMAT_YV12 value. Add |
| 276 | // an explicit check for the format |
| 277 | if (fmt == HAL_PIXEL_FORMAT_YV12) { |
| 278 | return 0; |
| 279 | } |
| 280 | uint32_t fmt3D = format3D(fmt); |
| 281 | uint32_t fIn3D = format3DInput(fmt3D); // MSB 2 bytes - inp |
| 282 | uint32_t fOut3D = format3DOutput(fmt3D); // LSB 2 bytes - out |
| 283 | fmt3D = fIn3D | fOut3D; |
| 284 | if (!fIn3D) { |
| 285 | fmt3D |= fOut3D << SHIFT_TOT_3D; //Set the input format |
| 286 | } |
| 287 | if (!fOut3D) { |
| 288 | switch (fIn3D) { |
| 289 | case HAL_3D_IN_SIDE_BY_SIDE_L_R: |
| 290 | case HAL_3D_IN_SIDE_BY_SIDE_R_L: |
| 291 | // For all side by side formats, set the output |
| 292 | // format as Side-by-Side i.e 0x1 |
| 293 | fmt3D |= HAL_3D_IN_SIDE_BY_SIDE_L_R >> SHIFT_TOT_3D; |
| 294 | break; |
| 295 | default: |
| 296 | fmt3D |= fIn3D >> SHIFT_TOT_3D; //Set the output format |
| 297 | } |
| 298 | } |
| 299 | return fmt3D; |
| 300 | } |
| 301 | |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 302 | } // utils |
| 303 | |
| 304 | } // overlay |