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" |
| 38 | |
| 39 | // just a helper static thingy |
| 40 | namespace { |
| 41 | struct IOFile { |
| 42 | IOFile(const char* s, const char* mode) : fp(0) { |
| 43 | fp = ::fopen(s, mode); |
| 44 | if(!fp) { |
| 45 | ALOGE("Failed open %s", s); |
| 46 | } |
| 47 | } |
| 48 | template <class T> |
| 49 | size_t read(T& r, size_t elem) { |
| 50 | if(fp) { |
| 51 | return ::fread(&r, sizeof(T), elem, fp); |
| 52 | } |
| 53 | return 0; |
| 54 | } |
| 55 | size_t write(const char* s, uint32_t val) { |
| 56 | if(fp) { |
| 57 | return ::fprintf(fp, s, val); |
| 58 | } |
| 59 | return 0; |
| 60 | } |
| 61 | bool valid() const { return fp != 0; } |
| 62 | ~IOFile() { |
| 63 | if(fp) ::fclose(fp); |
| 64 | fp=0; |
| 65 | } |
| 66 | FILE* fp; |
| 67 | }; |
| 68 | } |
| 69 | |
| 70 | namespace overlay { |
| 71 | |
| 72 | //----------From class Res ------------------------------ |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 73 | const char* const Res::fbPath = "/dev/graphics/fb%u"; |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 74 | const char* const Res::rotPath = "/dev/msm_rotator"; |
| 75 | const char* const Res::format3DFile = |
| 76 | "/sys/class/graphics/fb1/format_3d"; |
| 77 | const char* const Res::edid3dInfoFile = |
| 78 | "/sys/class/graphics/fb1/3d_present"; |
| 79 | const char* const Res::barrierFile = |
| 80 | "/sys/devices/platform/mipi_novatek.0/enable_3d_barrier"; |
| 81 | //-------------------------------------------------------- |
| 82 | |
| 83 | |
| 84 | |
| 85 | namespace utils { |
| 86 | //-------------------------------------------------------- |
| 87 | FrameBufferInfo::FrameBufferInfo() { |
| 88 | mFBWidth = 0; |
| 89 | mFBHeight = 0; |
| 90 | mBorderFillSupported = false; |
| 91 | |
| 92 | OvFD mFd; |
| 93 | |
| 94 | // Use open defined in overlayFD file to open fd for fb0 |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 95 | if(!overlay::open(mFd, 0, Res::fbPath)) { |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 96 | ALOGE("FrameBufferInfo: failed to open fd"); |
| 97 | return; |
| 98 | } |
| 99 | |
| 100 | if (!mFd.valid()) { |
| 101 | ALOGE("FrameBufferInfo: FD not valid"); |
| 102 | return; |
| 103 | } |
| 104 | |
| 105 | fb_var_screeninfo vinfo; |
| 106 | if (!mdp_wrapper::getVScreenInfo(mFd.getFD(), vinfo)) { |
| 107 | ALOGE("FrameBufferInfo: failed getVScreenInfo on fb0"); |
| 108 | mFd.close(); |
| 109 | return; |
| 110 | } |
| 111 | |
| 112 | mdp_overlay ov; |
| 113 | memset(&ov, 0, sizeof(ov)); |
| 114 | ov.id = 1; |
| 115 | if (!mdp_wrapper::getOverlay(mFd.getFD(), ov)) { |
| 116 | ALOGE("FrameBufferInfo: failed getOverlay on fb0"); |
| 117 | mFd.close(); |
| 118 | return; |
| 119 | } |
| 120 | |
| 121 | mFd.close(); |
| 122 | |
| 123 | mFBWidth = vinfo.xres; |
| 124 | mFBHeight = vinfo.yres; |
| 125 | mBorderFillSupported = (ov.flags & MDP_BORDERFILL_SUPPORTED) ? |
| 126 | true : false; |
| 127 | } |
| 128 | |
| 129 | FrameBufferInfo* FrameBufferInfo::getInstance() { |
| 130 | if (!sFBInfoInstance) { |
| 131 | sFBInfoInstance = new FrameBufferInfo; |
| 132 | } |
| 133 | return sFBInfoInstance; |
| 134 | } |
| 135 | |
| 136 | int FrameBufferInfo::getWidth() const { |
| 137 | return mFBWidth; |
| 138 | } |
| 139 | |
| 140 | int FrameBufferInfo::getHeight() const { |
| 141 | return mFBHeight; |
| 142 | } |
| 143 | |
| 144 | bool FrameBufferInfo::supportTrueMirroring() const { |
Naseer Ahmed | 0c8b7b5 | 2012-07-20 09:06:13 -0700 | [diff] [blame] | 145 | char value[PROPERTY_VALUE_MAX] = {0}; |
| 146 | property_get("hw.trueMirrorSupported", value, "0"); |
| 147 | int trueMirroringSupported = atoi(value); |
| 148 | return (trueMirroringSupported && mBorderFillSupported); |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 149 | } |
| 150 | |
| 151 | //-------------------------------------------------------- |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 152 | |
| 153 | int getMdpFormat(int format) { |
| 154 | switch (format) { |
| 155 | case HAL_PIXEL_FORMAT_RGBA_8888 : |
| 156 | return MDP_RGBA_8888; |
| 157 | case HAL_PIXEL_FORMAT_BGRA_8888: |
| 158 | return MDP_BGRA_8888; |
| 159 | case HAL_PIXEL_FORMAT_RGB_565: |
| 160 | return MDP_RGB_565; |
| 161 | case HAL_PIXEL_FORMAT_RGBX_8888: |
| 162 | return MDP_RGBX_8888; |
| 163 | case HAL_PIXEL_FORMAT_YCbCr_422_SP: |
| 164 | return MDP_Y_CBCR_H2V1; |
| 165 | case HAL_PIXEL_FORMAT_YCrCb_422_SP: |
| 166 | return MDP_Y_CRCB_H2V1; |
| 167 | case HAL_PIXEL_FORMAT_YCbCr_420_SP: |
| 168 | return MDP_Y_CBCR_H2V2; |
| 169 | case HAL_PIXEL_FORMAT_YCrCb_420_SP: |
| 170 | return MDP_Y_CRCB_H2V2; |
| 171 | case HAL_PIXEL_FORMAT_YCbCr_420_SP_TILED: |
| 172 | return MDP_Y_CBCR_H2V2_TILE; |
| 173 | case HAL_PIXEL_FORMAT_YV12: |
| 174 | return MDP_Y_CR_CB_H2V2; |
| 175 | default: |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 176 | ALOGE("Error getMdpFormat format=0x%x", format); |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 177 | return -1; |
| 178 | } |
| 179 | // not reached |
| 180 | return -1; |
| 181 | } |
| 182 | |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 183 | //Set by client as HDMI/WFD |
| 184 | void setExtType(const int& type) { |
| 185 | if(type != HDMI && type != WFD) { |
| 186 | ALOGE("%s: Unrecognized type %d", __func__, type); |
| 187 | return; |
| 188 | } |
| 189 | sExtType = type; |
| 190 | } |
| 191 | |
| 192 | //Return External panel type set by client. |
| 193 | int getExtType() { |
| 194 | return sExtType; |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 195 | } |
| 196 | |
| 197 | bool is3DTV() { |
| 198 | char is3DTV = '0'; |
| 199 | IOFile fp(Res::edid3dInfoFile, "r"); |
| 200 | (void)fp.read(is3DTV, 1); |
| 201 | ALOGI("3DTV EDID flag: %d", is3DTV); |
| 202 | return (is3DTV == '0') ? false : true; |
| 203 | } |
| 204 | |
| 205 | bool isPanel3D() { |
| 206 | OvFD fd; |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 207 | if(!overlay::open(fd, 0 /*fb*/, Res::fbPath)){ |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 208 | ALOGE("isPanel3D Can't open framebuffer 0"); |
| 209 | return false; |
| 210 | } |
| 211 | fb_fix_screeninfo finfo; |
| 212 | if(!mdp_wrapper::getFScreenInfo(fd.getFD(), finfo)) { |
| 213 | ALOGE("isPanel3D read fb0 failed"); |
| 214 | } |
| 215 | fd.close(); |
| 216 | return (FB_TYPE_3D_PANEL == finfo.type) ? true : false; |
| 217 | } |
| 218 | |
| 219 | bool usePanel3D() { |
| 220 | if(!isPanel3D()) |
| 221 | return false; |
| 222 | char value[PROPERTY_VALUE_MAX]; |
| 223 | property_get("persist.user.panel3D", value, "0"); |
| 224 | int usePanel3D = atoi(value); |
| 225 | return usePanel3D ? true : false; |
| 226 | } |
| 227 | |
| 228 | bool send3DInfoPacket (uint32_t format3D) { |
| 229 | IOFile fp(Res::format3DFile, "wb"); |
| 230 | (void)fp.write("%d", format3D); |
| 231 | if(!fp.valid()) { |
| 232 | ALOGE("send3DInfoPacket: no sysfs entry for setting 3d mode"); |
| 233 | return false; |
| 234 | } |
| 235 | return true; |
| 236 | } |
| 237 | |
| 238 | bool enableBarrier (uint32_t orientation) { |
| 239 | IOFile fp(Res::barrierFile, "wb"); |
| 240 | (void)fp.write("%d", orientation); |
| 241 | if(!fp.valid()) { |
| 242 | ALOGE("enableBarrier no sysfs entry for " |
| 243 | "enabling barriers on 3D panel"); |
| 244 | return false; |
| 245 | } |
| 246 | return true; |
| 247 | } |
| 248 | |
| 249 | uint32_t getS3DFormat(uint32_t fmt) { |
| 250 | // The S3D is part of the HAL_PIXEL_FORMAT_YV12 value. Add |
| 251 | // an explicit check for the format |
| 252 | if (fmt == HAL_PIXEL_FORMAT_YV12) { |
| 253 | return 0; |
| 254 | } |
| 255 | uint32_t fmt3D = format3D(fmt); |
| 256 | uint32_t fIn3D = format3DInput(fmt3D); // MSB 2 bytes - inp |
| 257 | uint32_t fOut3D = format3DOutput(fmt3D); // LSB 2 bytes - out |
| 258 | fmt3D = fIn3D | fOut3D; |
| 259 | if (!fIn3D) { |
| 260 | fmt3D |= fOut3D << SHIFT_TOT_3D; //Set the input format |
| 261 | } |
| 262 | if (!fOut3D) { |
| 263 | switch (fIn3D) { |
| 264 | case HAL_3D_IN_SIDE_BY_SIDE_L_R: |
| 265 | case HAL_3D_IN_SIDE_BY_SIDE_R_L: |
| 266 | // For all side by side formats, set the output |
| 267 | // format as Side-by-Side i.e 0x1 |
| 268 | fmt3D |= HAL_3D_IN_SIDE_BY_SIDE_L_R >> SHIFT_TOT_3D; |
| 269 | break; |
| 270 | default: |
| 271 | fmt3D |= fIn3D >> SHIFT_TOT_3D; //Set the output format |
| 272 | } |
| 273 | } |
| 274 | return fmt3D; |
| 275 | } |
| 276 | |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 277 | } // utils |
| 278 | |
| 279 | } // overlay |