Naseer Ahmed | 0c8b7b5 | 2012-07-20 09:06:13 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2010 The Android Open Source Project |
Saurabh Shah | 56f610d | 2012-08-07 15:27:06 -0700 | [diff] [blame] | 3 | * Copyright (C) 2012, The Linux Foundation. All rights reserved. |
Naseer Ahmed | 0c8b7b5 | 2012-07-20 09:06:13 -0700 | [diff] [blame] | 4 | * |
| 5 | * Not a Contribution, Apache license notifications and license are |
| 6 | * retained for attribution purposes only. |
| 7 | * |
| 8 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 9 | * you may not use this file except in compliance with the License. |
| 10 | * You may obtain a copy of the License at |
| 11 | * |
| 12 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 13 | * |
| 14 | * Unless required by applicable law or agreed to in writing, software |
| 15 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 17 | * See the License for the specific language governing permissions and |
| 18 | * limitations under the License. |
| 19 | */ |
| 20 | |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 21 | #define DEBUG 0 |
Naseer Ahmed | 0c8b7b5 | 2012-07-20 09:06:13 -0700 | [diff] [blame] | 22 | #include <ctype.h> |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 23 | #include <fcntl.h> |
Naseer Ahmed | 0c8b7b5 | 2012-07-20 09:06:13 -0700 | [diff] [blame] | 24 | #include <media/IAudioPolicyService.h> |
| 25 | #include <media/AudioSystem.h> |
| 26 | #include <utils/threads.h> |
| 27 | #include <utils/Errors.h> |
| 28 | #include <utils/Log.h> |
| 29 | |
| 30 | #include <linux/msm_mdp.h> |
| 31 | #include <linux/fb.h> |
| 32 | #include <sys/ioctl.h> |
| 33 | #include <sys/poll.h> |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 34 | #include <sys/resource.h> |
Naseer Ahmed | 0c8b7b5 | 2012-07-20 09:06:13 -0700 | [diff] [blame] | 35 | #include <cutils/properties.h> |
| 36 | #include "hwc_utils.h" |
Saurabh Shah | 56f610d | 2012-08-07 15:27:06 -0700 | [diff] [blame] | 37 | #include "external.h" |
| 38 | #include "overlayUtils.h" |
Amara Venkata Mastan Manoj Kumar | 5182a78 | 2012-12-03 12:08:48 -0800 | [diff] [blame] | 39 | #include "overlay.h" |
Saurabh Shah | 56f610d | 2012-08-07 15:27:06 -0700 | [diff] [blame] | 40 | |
| 41 | using namespace android; |
Naseer Ahmed | 0c8b7b5 | 2012-07-20 09:06:13 -0700 | [diff] [blame] | 42 | |
| 43 | namespace qhwc { |
| 44 | |
Amara Venkata Mastan Manoj Kumar | 5182a78 | 2012-12-03 12:08:48 -0800 | [diff] [blame] | 45 | #define MAX_FRAME_BUFFER_NAME_SIZE (80) |
| 46 | #define MAX_DISPLAY_DEVICES (3) |
Naseer Ahmed | 0c8b7b5 | 2012-07-20 09:06:13 -0700 | [diff] [blame] | 47 | |
Naseer Ahmed | 0c8b7b5 | 2012-07-20 09:06:13 -0700 | [diff] [blame] | 48 | |
Amara Venkata Mastan Manoj Kumar | 5182a78 | 2012-12-03 12:08:48 -0800 | [diff] [blame] | 49 | const char* msmFbDevicePath[] = { "/dev/graphics/fb1", |
| 50 | "/dev/graphics/fb2"}; |
Naseer Ahmed | 0c8b7b5 | 2012-07-20 09:06:13 -0700 | [diff] [blame] | 51 | |
Amara Venkata Mastan Manoj Kumar | 5182a78 | 2012-12-03 12:08:48 -0800 | [diff] [blame] | 52 | /* |
| 53 | * Updates extDeviceFbIndex Array with the correct frame buffer indices |
| 54 | * of avaiable external devices |
| 55 | * |
| 56 | */ |
| 57 | void ExternalDisplay::updateExtDispDevFbIndex() |
| 58 | { |
| 59 | FILE *displayDeviceFP = NULL; |
| 60 | char fbType[MAX_FRAME_BUFFER_NAME_SIZE]; |
| 61 | char msmFbTypePath[MAX_FRAME_BUFFER_NAME_SIZE]; |
| 62 | |
| 63 | for(int j = 1; j < MAX_DISPLAY_DEVICES; j++) { |
| 64 | sprintf (msmFbTypePath,"/sys/class/graphics/fb%d/msm_fb_type", j); |
| 65 | displayDeviceFP = fopen(msmFbTypePath, "r"); |
| 66 | if(displayDeviceFP){ |
| 67 | fread(fbType, sizeof(char), MAX_FRAME_BUFFER_NAME_SIZE, |
| 68 | displayDeviceFP); |
| 69 | if(strncmp(fbType, "dtv panel", strlen("dtv panel")) == 0){ |
| 70 | ALOGD_IF(DEBUG,"hdmi framebuffer index is %d",j); |
| 71 | mHdmiFbNum = j; |
| 72 | } else if(strncmp(fbType, "writeback panel", |
| 73 | strlen("writeback panel")) == 0){ |
| 74 | ALOGD_IF(DEBUG,"wfd framebuffer index is %d",j); |
| 75 | mWfdFbNum = j; |
| 76 | } |
| 77 | fclose(displayDeviceFP); |
| 78 | } |
| 79 | } |
| 80 | ALOGD_IF(DEBUG,"%s: mHdmiFbNum: %d mWfdFbNum: %d ",__FUNCTION__, |
| 81 | mHdmiFbNum, mWfdFbNum); |
| 82 | } |
| 83 | |
| 84 | int ExternalDisplay::configureHDMIDisplay() { |
| 85 | openFrameBuffer(mHdmiFbNum); |
| 86 | if(mFd == -1) |
| 87 | return -1; |
Arun Kumar K.R | feb2d8a | 2013-02-01 02:53:13 -0800 | [diff] [blame] | 88 | readCEUnderscanInfo(); |
Amara Venkata Mastan Manoj Kumar | 5182a78 | 2012-12-03 12:08:48 -0800 | [diff] [blame] | 89 | readResolution(); |
Amara Venkata Mastan Manoj Kumar | 5182a78 | 2012-12-03 12:08:48 -0800 | [diff] [blame] | 90 | // TODO: Move this to activate |
Arun Kumar K.R | 37552c5 | 2012-12-10 12:47:18 -0800 | [diff] [blame] | 91 | /* Used for changing the resolution |
| 92 | * getUserMode will get the preferred |
| 93 | * mode set thru adb shell */ |
| 94 | int mode = getUserMode(); |
| 95 | if (mode == -1) { |
| 96 | //Get the best mode and set |
| 97 | mode = getBestMode(); |
| 98 | } |
| 99 | setResolution(mode); |
Amara Venkata Mastan Manoj Kumar | 5182a78 | 2012-12-03 12:08:48 -0800 | [diff] [blame] | 100 | setDpyHdmiAttr(); |
| 101 | setExternalDisplay(true, mHdmiFbNum); |
| 102 | return 0; |
| 103 | } |
| 104 | |
| 105 | int ExternalDisplay::configureWFDDisplay() { |
| 106 | int ret = 0; |
| 107 | if(mConnectedFbNum == mHdmiFbNum) { |
| 108 | ALOGE("%s: Cannot process WFD connection while HDMI is active", |
| 109 | __FUNCTION__); |
| 110 | return -1; |
| 111 | } |
| 112 | openFrameBuffer(mWfdFbNum); |
| 113 | if(mFd == -1) |
| 114 | return -1; |
| 115 | ret = ioctl(mFd, FBIOGET_VSCREENINFO, &mVInfo); |
| 116 | if(ret < 0) { |
| 117 | ALOGD("In %s: FBIOGET_VSCREENINFO failed Err Str = %s", __FUNCTION__, |
| 118 | strerror(errno)); |
| 119 | } |
| 120 | setDpyWfdAttr(); |
| 121 | setExternalDisplay(true, mWfdFbNum); |
| 122 | return 0; |
| 123 | } |
| 124 | |
| 125 | int ExternalDisplay::teardownHDMIDisplay() { |
| 126 | if(mConnectedFbNum == mHdmiFbNum) { |
| 127 | // hdmi offline event..! |
| 128 | closeFrameBuffer(); |
| 129 | resetInfo(); |
| 130 | setExternalDisplay(false); |
| 131 | } |
| 132 | return 0; |
| 133 | } |
| 134 | |
| 135 | int ExternalDisplay::teardownWFDDisplay() { |
| 136 | if(mConnectedFbNum == mWfdFbNum) { |
| 137 | // wfd offline event..! |
| 138 | closeFrameBuffer(); |
| 139 | memset(&mVInfo, 0, sizeof(mVInfo)); |
| 140 | setExternalDisplay(false); |
| 141 | } |
| 142 | return 0; |
| 143 | } |
| 144 | |
| 145 | void ExternalDisplay::processUEventOnline(const char *str) { |
| 146 | const char *s1 = str + strlen("change@/devices/virtual/switch/"); |
| 147 | if(!strncmp(s1,"hdmi",strlen(s1))) { |
| 148 | // hdmi online event..! |
| 149 | configureHDMIDisplay(); |
Arun Kumar K.R | bfc79c2 | 2013-01-15 13:34:05 -0800 | [diff] [blame] | 150 | // set system property |
| 151 | property_set("hw.hdmiON", "1"); |
Amara Venkata Mastan Manoj Kumar | 5182a78 | 2012-12-03 12:08:48 -0800 | [diff] [blame] | 152 | }else if(!strncmp(s1,"wfd",strlen(s1))) { |
| 153 | // wfd online event..! |
| 154 | configureWFDDisplay(); |
| 155 | } |
| 156 | } |
| 157 | |
| 158 | void ExternalDisplay::processUEventOffline(const char *str) { |
| 159 | const char *s1 = str + strlen("change@/devices/virtual/switch/"); |
| 160 | if(!strncmp(s1,"hdmi",strlen(s1))) { |
| 161 | teardownHDMIDisplay(); |
Arun Kumar K.R | bfc79c2 | 2013-01-15 13:34:05 -0800 | [diff] [blame] | 162 | // unset system property |
| 163 | property_set("hw.hdmiON", "0"); |
Amara Venkata Mastan Manoj Kumar | 5182a78 | 2012-12-03 12:08:48 -0800 | [diff] [blame] | 164 | }else if(!strncmp(s1,"wfd",strlen(s1))) { |
| 165 | teardownWFDDisplay(); |
| 166 | } |
| 167 | } |
Naseer Ahmed | 0c8b7b5 | 2012-07-20 09:06:13 -0700 | [diff] [blame] | 168 | |
Naseer Ahmed | f8ec162 | 2012-07-31 18:56:23 -0700 | [diff] [blame] | 169 | ExternalDisplay::ExternalDisplay(hwc_context_t* ctx):mFd(-1), |
Amara Venkata Mastan Manoj Kumar | 5182a78 | 2012-12-03 12:08:48 -0800 | [diff] [blame] | 170 | mCurrentMode(-1), mConnected(0), mConnectedFbNum(0), mModeCount(0), |
Amara Venkata Mastan Manoj Kumar | 11a380d | 2013-01-17 09:30:56 -0800 | [diff] [blame] | 171 | mUnderscanSupported(false), mHwcContext(ctx), mHdmiFbNum(-1), |
| 172 | mWfdFbNum(-1), mExtDpyNum(HWC_DISPLAY_EXTERNAL) |
Naseer Ahmed | 0c8b7b5 | 2012-07-20 09:06:13 -0700 | [diff] [blame] | 173 | { |
Naseer Ahmed | f8ec162 | 2012-07-31 18:56:23 -0700 | [diff] [blame] | 174 | memset(&mVInfo, 0, sizeof(mVInfo)); |
Amara Venkata Mastan Manoj Kumar | 5182a78 | 2012-12-03 12:08:48 -0800 | [diff] [blame] | 175 | //Determine the fb index for external display devices. |
| 176 | updateExtDispDevFbIndex(); |
Amara Venkata Mastan Manoj Kumar | 11a380d | 2013-01-17 09:30:56 -0800 | [diff] [blame] | 177 | |
Naseer Ahmed | 0c8b7b5 | 2012-07-20 09:06:13 -0700 | [diff] [blame] | 178 | } |
| 179 | |
Saurabh Shah | 56f610d | 2012-08-07 15:27:06 -0700 | [diff] [blame] | 180 | void ExternalDisplay::setEDIDMode(int resMode) { |
| 181 | ALOGD_IF(DEBUG,"resMode=%d ", resMode); |
Saurabh Shah | 56f610d | 2012-08-07 15:27:06 -0700 | [diff] [blame] | 182 | { |
| 183 | Mutex::Autolock lock(mExtDispLock); |
Amara Venkata Mastan Manoj Kumar | 5182a78 | 2012-12-03 12:08:48 -0800 | [diff] [blame] | 184 | setExternalDisplay(false); |
| 185 | openFrameBuffer(mHdmiFbNum); |
Saurabh Shah | 56f610d | 2012-08-07 15:27:06 -0700 | [diff] [blame] | 186 | setResolution(resMode); |
| 187 | } |
Amara Venkata Mastan Manoj Kumar | 5182a78 | 2012-12-03 12:08:48 -0800 | [diff] [blame] | 188 | setExternalDisplay(true, mHdmiFbNum); |
Saurabh Shah | 56f610d | 2012-08-07 15:27:06 -0700 | [diff] [blame] | 189 | } |
| 190 | |
| 191 | void ExternalDisplay::setHPD(uint32_t startEnd) { |
| 192 | ALOGD_IF(DEBUG,"HPD enabled=%d", startEnd); |
| 193 | writeHPDOption(startEnd); |
| 194 | } |
| 195 | |
| 196 | void ExternalDisplay::setActionSafeDimension(int w, int h) { |
| 197 | ALOGD_IF(DEBUG,"ActionSafe w=%d h=%d", w, h); |
| 198 | Mutex::Autolock lock(mExtDispLock); |
Arun Kumar K.R | feb2d8a | 2013-02-01 02:53:13 -0800 | [diff] [blame] | 199 | char actionsafeWidth[PROPERTY_VALUE_MAX]; |
| 200 | char actionsafeHeight[PROPERTY_VALUE_MAX]; |
| 201 | sprintf(actionsafeWidth, "%d", w); |
| 202 | property_set("hw.actionsafe.width", actionsafeWidth); |
| 203 | sprintf(actionsafeHeight, "%d", h); |
| 204 | property_set("hw.actionsafe.height", actionsafeHeight); |
Amara Venkata Mastan Manoj Kumar | 5182a78 | 2012-12-03 12:08:48 -0800 | [diff] [blame] | 205 | setExternalDisplay(true, mHdmiFbNum); |
Saurabh Shah | 56f610d | 2012-08-07 15:27:06 -0700 | [diff] [blame] | 206 | } |
| 207 | |
| 208 | int ExternalDisplay::getModeCount() const { |
| 209 | ALOGD_IF(DEBUG,"HPD mModeCount=%d", mModeCount); |
| 210 | Mutex::Autolock lock(mExtDispLock); |
| 211 | return mModeCount; |
| 212 | } |
| 213 | |
| 214 | void ExternalDisplay::getEDIDModes(int *out) const { |
| 215 | Mutex::Autolock lock(mExtDispLock); |
| 216 | for(int i = 0;i < mModeCount;i++) { |
| 217 | out[i] = mEDIDModes[i]; |
| 218 | } |
| 219 | } |
| 220 | |
Arun Kumar K.R | feb2d8a | 2013-02-01 02:53:13 -0800 | [diff] [blame] | 221 | void ExternalDisplay::readCEUnderscanInfo() |
| 222 | { |
| 223 | int hdmiScanInfoFile = -1; |
| 224 | int len = -1; |
| 225 | char scanInfo[17]; |
| 226 | char *ce_info_str = NULL; |
| 227 | const char token[] = ", \n"; |
| 228 | int ce_info = -1; |
| 229 | char sysFsScanInfoFilePath[128]; |
| 230 | sprintf(sysFsScanInfoFilePath, "/sys/devices/virtual/graphics/fb%d/" |
| 231 | "scan_info", mHdmiFbNum); |
| 232 | |
| 233 | memset(scanInfo, 0, sizeof(scanInfo)); |
| 234 | hdmiScanInfoFile = open(sysFsScanInfoFilePath, O_RDONLY, 0); |
| 235 | if (hdmiScanInfoFile < 0) { |
| 236 | ALOGD_IF(DEBUG, "%s: scan_info file '%s' not found", |
| 237 | __FUNCTION__, sysFsScanInfoFilePath); |
| 238 | return; |
| 239 | } else { |
| 240 | len = read(hdmiScanInfoFile, scanInfo, sizeof(scanInfo)-1); |
| 241 | ALOGD("%s: Scan Info string: %s length = %d", |
| 242 | __FUNCTION__, scanInfo, len); |
| 243 | if (len <= 0) { |
| 244 | close(hdmiScanInfoFile); |
| 245 | ALOGE("%s: Scan Info file empty '%s'", |
| 246 | __FUNCTION__, sysFsScanInfoFilePath); |
| 247 | return; |
| 248 | } |
| 249 | scanInfo[len] = '\0'; /* null terminate the string */ |
| 250 | } |
| 251 | close(hdmiScanInfoFile); |
| 252 | |
| 253 | /* |
| 254 | * The scan_info contains the three fields |
| 255 | * PT - preferred video format |
| 256 | * IT - video format |
| 257 | * CE video format - containing the underscan support information |
| 258 | */ |
| 259 | |
| 260 | /* PT */ |
| 261 | ce_info_str = strtok(scanInfo, token); |
| 262 | if (ce_info_str) { |
| 263 | /* IT */ |
| 264 | ce_info_str = strtok(NULL, token); |
| 265 | if (ce_info_str) { |
| 266 | /* CE */ |
| 267 | ce_info_str = strtok(NULL, token); |
| 268 | if (ce_info_str) |
| 269 | ce_info = atoi(ce_info_str); |
| 270 | } |
| 271 | } |
| 272 | |
| 273 | if (ce_info_str) { |
| 274 | // ce_info contains the underscan information |
| 275 | if (ce_info == EXT_SCAN_ALWAYS_UNDERSCANED || |
| 276 | ce_info == EXT_SCAN_BOTH_SUPPORTED) |
| 277 | // if TV supported underscan, then driver will always underscan |
| 278 | // hence no need to apply action safe rectangle |
| 279 | mUnderscanSupported = true; |
| 280 | } else { |
| 281 | ALOGE("%s: scan_info string error", __FUNCTION__); |
| 282 | } |
| 283 | |
| 284 | // Store underscan support info in a system property |
| 285 | const char* prop = (mUnderscanSupported) ? "1" : "0"; |
| 286 | property_set("hw.underscan_supported", prop); |
| 287 | return; |
| 288 | } |
| 289 | |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 290 | ExternalDisplay::~ExternalDisplay() |
| 291 | { |
Naseer Ahmed | f8ec162 | 2012-07-31 18:56:23 -0700 | [diff] [blame] | 292 | closeFrameBuffer(); |
Naseer Ahmed | 0c8b7b5 | 2012-07-20 09:06:13 -0700 | [diff] [blame] | 293 | } |
| 294 | |
Naseer Ahmed | 0c8b7b5 | 2012-07-20 09:06:13 -0700 | [diff] [blame] | 295 | struct disp_mode_timing_type { |
| 296 | int video_format; |
| 297 | |
| 298 | int active_h; |
| 299 | int active_v; |
| 300 | |
| 301 | int front_porch_h; |
| 302 | int pulse_width_h; |
| 303 | int back_porch_h; |
| 304 | |
| 305 | int front_porch_v; |
| 306 | int pulse_width_v; |
| 307 | int back_porch_v; |
| 308 | |
| 309 | int pixel_freq; |
| 310 | bool interlaced; |
| 311 | |
| 312 | void set_info(struct fb_var_screeninfo &info) const; |
| 313 | }; |
| 314 | |
| 315 | void disp_mode_timing_type::set_info(struct fb_var_screeninfo &info) const |
| 316 | { |
| 317 | info.reserved[0] = 0; |
| 318 | info.reserved[1] = 0; |
| 319 | info.reserved[2] = 0; |
Ken Zhang | 7b03a95 | 2013-01-16 13:23:48 -0500 | [diff] [blame] | 320 | #ifndef FB_METADATA_VIDEO_INFO_CODE_SUPPORT |
Saurabh Shah | 56f610d | 2012-08-07 15:27:06 -0700 | [diff] [blame] | 321 | info.reserved[3] = (info.reserved[3] & 0xFFFF) | (video_format << 16); |
Ken Zhang | 7b03a95 | 2013-01-16 13:23:48 -0500 | [diff] [blame] | 322 | #endif |
Naseer Ahmed | 0c8b7b5 | 2012-07-20 09:06:13 -0700 | [diff] [blame] | 323 | info.xoffset = 0; |
| 324 | info.yoffset = 0; |
| 325 | info.xres = active_h; |
| 326 | info.yres = active_v; |
| 327 | |
| 328 | info.pixclock = pixel_freq*1000; |
| 329 | info.vmode = interlaced ? FB_VMODE_INTERLACED : FB_VMODE_NONINTERLACED; |
| 330 | |
| 331 | info.right_margin = front_porch_h; |
| 332 | info.hsync_len = pulse_width_h; |
| 333 | info.left_margin = back_porch_h; |
| 334 | info.lower_margin = front_porch_v; |
| 335 | info.vsync_len = pulse_width_v; |
| 336 | info.upper_margin = back_porch_v; |
| 337 | } |
| 338 | |
| 339 | /* Video formates supported by the HDMI Standard */ |
| 340 | /* Indicates the resolution, pix clock and the aspect ratio */ |
| 341 | #define m640x480p60_4_3 1 |
| 342 | #define m720x480p60_4_3 2 |
| 343 | #define m720x480p60_16_9 3 |
| 344 | #define m1280x720p60_16_9 4 |
| 345 | #define m1920x1080i60_16_9 5 |
| 346 | #define m1440x480i60_4_3 6 |
| 347 | #define m1440x480i60_16_9 7 |
| 348 | #define m1920x1080p60_16_9 16 |
| 349 | #define m720x576p50_4_3 17 |
| 350 | #define m720x576p50_16_9 18 |
| 351 | #define m1280x720p50_16_9 19 |
| 352 | #define m1440x576i50_4_3 21 |
| 353 | #define m1440x576i50_16_9 22 |
| 354 | #define m1920x1080p50_16_9 31 |
| 355 | #define m1920x1080p24_16_9 32 |
| 356 | #define m1920x1080p25_16_9 33 |
| 357 | #define m1920x1080p30_16_9 34 |
| 358 | |
| 359 | static struct disp_mode_timing_type supported_video_mode_lut[] = { |
| 360 | {m640x480p60_4_3, 640, 480, 16, 96, 48, 10, 2, 33, 25200, false}, |
| 361 | {m720x480p60_4_3, 720, 480, 16, 62, 60, 9, 6, 30, 27030, false}, |
| 362 | {m720x480p60_16_9, 720, 480, 16, 62, 60, 9, 6, 30, 27030, false}, |
| 363 | {m1280x720p60_16_9, 1280, 720, 110, 40, 220, 5, 5, 20, 74250, false}, |
| 364 | {m1920x1080i60_16_9, 1920, 540, 88, 44, 148, 2, 5, 5, 74250, false}, |
| 365 | {m1440x480i60_4_3, 1440, 240, 38, 124, 114, 4, 3, 15, 27000, true}, |
| 366 | {m1440x480i60_16_9, 1440, 240, 38, 124, 114, 4, 3, 15, 27000, true}, |
| 367 | {m1920x1080p60_16_9, 1920, 1080, 88, 44, 148, 4, 5, 36, 148500, false}, |
| 368 | {m720x576p50_4_3, 720, 576, 12, 64, 68, 5, 5, 39, 27000, false}, |
| 369 | {m720x576p50_16_9, 720, 576, 12, 64, 68, 5, 5, 39, 27000, false}, |
| 370 | {m1280x720p50_16_9, 1280, 720, 440, 40, 220, 5, 5, 20, 74250, false}, |
| 371 | {m1440x576i50_4_3, 1440, 288, 24, 126, 138, 2, 3, 19, 27000, true}, |
| 372 | {m1440x576i50_16_9, 1440, 288, 24, 126, 138, 2, 3, 19, 27000, true}, |
| 373 | {m1920x1080p50_16_9, 1920, 1080, 528, 44, 148, 4, 5, 36, 148500, false}, |
| 374 | {m1920x1080p24_16_9, 1920, 1080, 638, 44, 148, 4, 5, 36, 74250, false}, |
| 375 | {m1920x1080p25_16_9, 1920, 1080, 528, 44, 148, 4, 5, 36, 74250, false}, |
| 376 | {m1920x1080p30_16_9, 1920, 1080, 88, 44, 148, 4, 5, 36, 74250, false}, |
| 377 | }; |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 378 | |
Naseer Ahmed | f8ec162 | 2012-07-31 18:56:23 -0700 | [diff] [blame] | 379 | int ExternalDisplay::parseResolution(char* edidStr, int* edidModes) |
Naseer Ahmed | 0c8b7b5 | 2012-07-20 09:06:13 -0700 | [diff] [blame] | 380 | { |
| 381 | char delim = ','; |
| 382 | int count = 0; |
| 383 | char *start, *end; |
| 384 | // EDIDs are string delimited by ',' |
| 385 | // Ex: 16,4,5,3,32,34,1 |
| 386 | // Parse this string to get mode(int) |
| 387 | start = (char*) edidStr; |
Naseer Ahmed | f8ec162 | 2012-07-31 18:56:23 -0700 | [diff] [blame] | 388 | end = &delim; |
| 389 | while(*end == delim) { |
| 390 | edidModes[count] = (int) strtol(start, &end, 10); |
Naseer Ahmed | 0c8b7b5 | 2012-07-20 09:06:13 -0700 | [diff] [blame] | 391 | start = end+1; |
| 392 | count++; |
| 393 | } |
Naseer Ahmed | f8ec162 | 2012-07-31 18:56:23 -0700 | [diff] [blame] | 394 | ALOGD_IF(DEBUG, "In %s: count = %d", __FUNCTION__, count); |
| 395 | for (int i = 0; i < count; i++) |
| 396 | ALOGD_IF(DEBUG, "Mode[%d] = %d", i, edidModes[i]); |
Naseer Ahmed | 0c8b7b5 | 2012-07-20 09:06:13 -0700 | [diff] [blame] | 397 | return count; |
| 398 | } |
Naseer Ahmed | f8ec162 | 2012-07-31 18:56:23 -0700 | [diff] [blame] | 399 | |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 400 | bool ExternalDisplay::readResolution() |
Naseer Ahmed | 0c8b7b5 | 2012-07-20 09:06:13 -0700 | [diff] [blame] | 401 | { |
Amara Venkata Mastan Manoj Kumar | 5182a78 | 2012-12-03 12:08:48 -0800 | [diff] [blame] | 402 | char sysFsEDIDFilePath[255]; |
| 403 | sprintf(sysFsEDIDFilePath , "/sys/devices/virtual/graphics/fb%d/edid_modes", |
| 404 | mHdmiFbNum); |
| 405 | |
| 406 | int hdmiEDIDFile = open(sysFsEDIDFilePath, O_RDONLY, 0); |
Naseer Ahmed | 0c8b7b5 | 2012-07-20 09:06:13 -0700 | [diff] [blame] | 407 | int len = -1; |
| 408 | |
Naseer Ahmed | 0c8b7b5 | 2012-07-20 09:06:13 -0700 | [diff] [blame] | 409 | if (hdmiEDIDFile < 0) { |
Naseer Ahmed | f8ec162 | 2012-07-31 18:56:23 -0700 | [diff] [blame] | 410 | ALOGE("%s: edid_modes file '%s' not found", |
Amara Venkata Mastan Manoj Kumar | 5182a78 | 2012-12-03 12:08:48 -0800 | [diff] [blame] | 411 | __FUNCTION__, sysFsEDIDFilePath); |
Naseer Ahmed | 0c8b7b5 | 2012-07-20 09:06:13 -0700 | [diff] [blame] | 412 | return false; |
| 413 | } else { |
| 414 | len = read(hdmiEDIDFile, mEDIDs, sizeof(mEDIDs)-1); |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 415 | ALOGD_IF(DEBUG, "%s: EDID string: %s length = %d", |
| 416 | __FUNCTION__, mEDIDs, len); |
Naseer Ahmed | 0c8b7b5 | 2012-07-20 09:06:13 -0700 | [diff] [blame] | 417 | if ( len <= 0) { |
Naseer Ahmed | f8ec162 | 2012-07-31 18:56:23 -0700 | [diff] [blame] | 418 | ALOGE("%s: edid_modes file empty '%s'", |
Amara Venkata Mastan Manoj Kumar | 5182a78 | 2012-12-03 12:08:48 -0800 | [diff] [blame] | 419 | __FUNCTION__, sysFsEDIDFilePath); |
Naseer Ahmed | 0c8b7b5 | 2012-07-20 09:06:13 -0700 | [diff] [blame] | 420 | } |
| 421 | else { |
| 422 | while (len > 1 && isspace(mEDIDs[len-1])) |
| 423 | --len; |
| 424 | mEDIDs[len] = 0; |
| 425 | } |
| 426 | } |
| 427 | close(hdmiEDIDFile); |
| 428 | if(len > 0) { |
Amara Venkata Mastan Manoj Kumar | 5182a78 | 2012-12-03 12:08:48 -0800 | [diff] [blame] | 429 | // Get EDID modes from the EDID strings |
Naseer Ahmed | f8ec162 | 2012-07-31 18:56:23 -0700 | [diff] [blame] | 430 | mModeCount = parseResolution(mEDIDs, mEDIDModes); |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 431 | ALOGD_IF(DEBUG, "%s: mModeCount = %d", __FUNCTION__, |
| 432 | mModeCount); |
Naseer Ahmed | 0c8b7b5 | 2012-07-20 09:06:13 -0700 | [diff] [blame] | 433 | } |
| 434 | |
| 435 | return (strlen(mEDIDs) > 0); |
| 436 | } |
| 437 | |
Amara Venkata Mastan Manoj Kumar | 5182a78 | 2012-12-03 12:08:48 -0800 | [diff] [blame] | 438 | bool ExternalDisplay::openFrameBuffer(int fbNum) |
Naseer Ahmed | 0c8b7b5 | 2012-07-20 09:06:13 -0700 | [diff] [blame] | 439 | { |
Naseer Ahmed | f8ec162 | 2012-07-31 18:56:23 -0700 | [diff] [blame] | 440 | if (mFd == -1) { |
Amara Venkata Mastan Manoj Kumar | 5182a78 | 2012-12-03 12:08:48 -0800 | [diff] [blame] | 441 | mFd = open(msmFbDevicePath[fbNum-1], O_RDWR); |
Naseer Ahmed | f8ec162 | 2012-07-31 18:56:23 -0700 | [diff] [blame] | 442 | if (mFd < 0) |
Amara Venkata Mastan Manoj Kumar | 5182a78 | 2012-12-03 12:08:48 -0800 | [diff] [blame] | 443 | ALOGE("%s: %s is not available", __FUNCTION__, |
| 444 | msmFbDevicePath[fbNum-1]); |
| 445 | if(mHwcContext) { |
Amara Venkata Mastan Manoj Kumar | 11a380d | 2013-01-17 09:30:56 -0800 | [diff] [blame] | 446 | mHwcContext->dpyAttr[mExtDpyNum].fd = mFd; |
Amara Venkata Mastan Manoj Kumar | 5182a78 | 2012-12-03 12:08:48 -0800 | [diff] [blame] | 447 | } |
Saurabh Shah | 3e858eb | 2012-09-17 16:53:21 -0700 | [diff] [blame] | 448 | } |
Naseer Ahmed | f8ec162 | 2012-07-31 18:56:23 -0700 | [diff] [blame] | 449 | return (mFd > 0); |
Naseer Ahmed | 0c8b7b5 | 2012-07-20 09:06:13 -0700 | [diff] [blame] | 450 | } |
| 451 | |
Naseer Ahmed | f8ec162 | 2012-07-31 18:56:23 -0700 | [diff] [blame] | 452 | bool ExternalDisplay::closeFrameBuffer() |
| 453 | { |
| 454 | int ret = 0; |
Naseer Ahmed | f53b377 | 2013-02-15 19:13:50 -0500 | [diff] [blame] | 455 | if(mFd >= 0) { |
Naseer Ahmed | f8ec162 | 2012-07-31 18:56:23 -0700 | [diff] [blame] | 456 | ret = close(mFd); |
| 457 | mFd = -1; |
| 458 | } |
Saurabh Shah | 3e858eb | 2012-09-17 16:53:21 -0700 | [diff] [blame] | 459 | if(mHwcContext) { |
Amara Venkata Mastan Manoj Kumar | 11a380d | 2013-01-17 09:30:56 -0800 | [diff] [blame] | 460 | mHwcContext->dpyAttr[mExtDpyNum].fd = mFd; |
Saurabh Shah | 3e858eb | 2012-09-17 16:53:21 -0700 | [diff] [blame] | 461 | } |
Naseer Ahmed | f8ec162 | 2012-07-31 18:56:23 -0700 | [diff] [blame] | 462 | return (ret == 0); |
| 463 | } |
| 464 | |
| 465 | // clears the vinfo, edid, best modes |
| 466 | void ExternalDisplay::resetInfo() |
| 467 | { |
| 468 | memset(&mVInfo, 0, sizeof(mVInfo)); |
| 469 | memset(mEDIDs, 0, sizeof(mEDIDs)); |
| 470 | memset(mEDIDModes, 0, sizeof(mEDIDModes)); |
| 471 | mModeCount = 0; |
| 472 | mCurrentMode = -1; |
Arun Kumar K.R | feb2d8a | 2013-02-01 02:53:13 -0800 | [diff] [blame] | 473 | mUnderscanSupported = false; |
| 474 | // Reset the underscan supported system property |
| 475 | const char* prop = "0"; |
| 476 | property_set("hw.underscan_supported", prop); |
Naseer Ahmed | f8ec162 | 2012-07-31 18:56:23 -0700 | [diff] [blame] | 477 | } |
Naseer Ahmed | 0c8b7b5 | 2012-07-20 09:06:13 -0700 | [diff] [blame] | 478 | |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 479 | int ExternalDisplay::getModeOrder(int mode) |
Naseer Ahmed | 0c8b7b5 | 2012-07-20 09:06:13 -0700 | [diff] [blame] | 480 | { |
Arun Kumar K.R | 37552c5 | 2012-12-10 12:47:18 -0800 | [diff] [blame] | 481 | // XXX: We dont support interlaced modes but having |
| 482 | // it here for for future |
Naseer Ahmed | 0c8b7b5 | 2012-07-20 09:06:13 -0700 | [diff] [blame] | 483 | switch (mode) { |
| 484 | default: |
| 485 | case m1440x480i60_4_3: |
| 486 | return 1; // 480i 4:3 |
| 487 | case m1440x480i60_16_9: |
| 488 | return 2; // 480i 16:9 |
| 489 | case m1440x576i50_4_3: |
| 490 | return 3; // i576i 4:3 |
| 491 | case m1440x576i50_16_9: |
| 492 | return 4; // 576i 16:9 |
| 493 | case m640x480p60_4_3: |
| 494 | return 5; // 640x480 4:3 |
| 495 | case m720x480p60_4_3: |
| 496 | return 6; // 480p 4:3 |
| 497 | case m720x480p60_16_9: |
| 498 | return 7; // 480p 16:9 |
| 499 | case m720x576p50_4_3: |
| 500 | return 8; // 576p 4:3 |
| 501 | case m720x576p50_16_9: |
| 502 | return 9; // 576p 16:9 |
| 503 | case m1920x1080i60_16_9: |
| 504 | return 10; // 1080i 16:9 |
| 505 | case m1280x720p50_16_9: |
| 506 | return 11; // 720p@50Hz |
| 507 | case m1280x720p60_16_9: |
| 508 | return 12; // 720p@60Hz |
| 509 | case m1920x1080p24_16_9: |
| 510 | return 13; //1080p@24Hz |
| 511 | case m1920x1080p25_16_9: |
| 512 | return 14; //108-p@25Hz |
| 513 | case m1920x1080p30_16_9: |
| 514 | return 15; //1080p@30Hz |
| 515 | case m1920x1080p50_16_9: |
| 516 | return 16; //1080p@50Hz |
| 517 | case m1920x1080p60_16_9: |
| 518 | return 17; //1080p@60Hz |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 519 | } |
Naseer Ahmed | 0c8b7b5 | 2012-07-20 09:06:13 -0700 | [diff] [blame] | 520 | } |
| 521 | |
Arun Kumar K.R | 37552c5 | 2012-12-10 12:47:18 -0800 | [diff] [blame] | 522 | /// Returns the user mode set(if any) using adb shell |
| 523 | int ExternalDisplay::getUserMode() { |
| 524 | /* Based on the property set the resolution */ |
| 525 | char property_value[PROPERTY_VALUE_MAX]; |
Arun Kumar K.R | c31bdcb | 2013-02-25 17:47:42 -0800 | [diff] [blame^] | 526 | property_get("hw.hdmi.resolution", property_value, "-1"); |
Arun Kumar K.R | 37552c5 | 2012-12-10 12:47:18 -0800 | [diff] [blame] | 527 | int mode = atoi(property_value); |
| 528 | // We dont support interlaced modes |
| 529 | if(isValidMode(mode) && !isInterlacedMode(mode)) { |
Naseer Ahmed | 7421472 | 2013-02-09 08:11:36 -0500 | [diff] [blame] | 530 | ALOGD_IF(DEBUG, "%s: setting the HDMI mode = %d", __FUNCTION__, mode); |
Arun Kumar K.R | 37552c5 | 2012-12-10 12:47:18 -0800 | [diff] [blame] | 531 | return mode; |
| 532 | } |
| 533 | return -1; |
| 534 | } |
| 535 | |
Naseer Ahmed | 0c8b7b5 | 2012-07-20 09:06:13 -0700 | [diff] [blame] | 536 | // Get the best mode for the current HD TV |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 537 | int ExternalDisplay::getBestMode() { |
Naseer Ahmed | 0c8b7b5 | 2012-07-20 09:06:13 -0700 | [diff] [blame] | 538 | int bestOrder = 0; |
| 539 | int bestMode = m640x480p60_4_3; |
Saurabh Shah | 56f610d | 2012-08-07 15:27:06 -0700 | [diff] [blame] | 540 | Mutex::Autolock lock(mExtDispLock); |
Naseer Ahmed | 0c8b7b5 | 2012-07-20 09:06:13 -0700 | [diff] [blame] | 541 | // for all the edid read, get the best mode |
| 542 | for(int i = 0; i < mModeCount; i++) { |
| 543 | int mode = mEDIDModes[i]; |
| 544 | int order = getModeOrder(mode); |
| 545 | if (order > bestOrder) { |
| 546 | bestOrder = order; |
| 547 | bestMode = mode; |
| 548 | } |
| 549 | } |
| 550 | return bestMode; |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 551 | } |
Naseer Ahmed | 0c8b7b5 | 2012-07-20 09:06:13 -0700 | [diff] [blame] | 552 | |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 553 | inline bool ExternalDisplay::isValidMode(int ID) |
Naseer Ahmed | 0c8b7b5 | 2012-07-20 09:06:13 -0700 | [diff] [blame] | 554 | { |
Arun Kumar K.R | 37552c5 | 2012-12-10 12:47:18 -0800 | [diff] [blame] | 555 | bool valid = false; |
| 556 | for (int i = 0; i < mModeCount; i++) { |
| 557 | if(ID == mEDIDModes[i]) { |
| 558 | valid = true; |
| 559 | break; |
| 560 | } |
| 561 | } |
| 562 | return valid; |
| 563 | } |
| 564 | |
| 565 | // returns true if the mode(ID) is interlaced mode format |
| 566 | bool ExternalDisplay::isInterlacedMode(int ID) { |
| 567 | bool interlaced = false; |
| 568 | switch(ID) { |
| 569 | case m1440x480i60_4_3: |
| 570 | case m1440x480i60_16_9: |
| 571 | case m1440x576i50_4_3: |
| 572 | case m1440x576i50_16_9: |
| 573 | case m1920x1080i60_16_9: |
| 574 | interlaced = true; |
| 575 | default: |
| 576 | interlaced = false; |
| 577 | } |
| 578 | return interlaced; |
Naseer Ahmed | 0c8b7b5 | 2012-07-20 09:06:13 -0700 | [diff] [blame] | 579 | } |
| 580 | |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 581 | void ExternalDisplay::setResolution(int ID) |
Naseer Ahmed | 0c8b7b5 | 2012-07-20 09:06:13 -0700 | [diff] [blame] | 582 | { |
| 583 | struct fb_var_screeninfo info; |
Naseer Ahmed | f8ec162 | 2012-07-31 18:56:23 -0700 | [diff] [blame] | 584 | int ret = 0; |
Naseer Ahmed | f8ec162 | 2012-07-31 18:56:23 -0700 | [diff] [blame] | 585 | ret = ioctl(mFd, FBIOGET_VSCREENINFO, &mVInfo); |
| 586 | if(ret < 0) { |
| 587 | ALOGD("In %s: FBIOGET_VSCREENINFO failed Err Str = %s", __FUNCTION__, |
| 588 | strerror(errno)); |
| 589 | } |
| 590 | |
| 591 | ALOGD_IF(DEBUG, "%s: GET Info<ID=%d %dx%d (%d,%d,%d)," |
| 592 | "(%d,%d,%d) %dMHz>", __FUNCTION__, |
| 593 | mVInfo.reserved[3], mVInfo.xres, mVInfo.yres, |
| 594 | mVInfo.right_margin, mVInfo.hsync_len, mVInfo.left_margin, |
| 595 | mVInfo.lower_margin, mVInfo.vsync_len, mVInfo.upper_margin, |
| 596 | mVInfo.pixclock/1000/1000); |
Arun Kumar K.R | 37552c5 | 2012-12-10 12:47:18 -0800 | [diff] [blame] | 597 | //If its a new ID - update var_screeninfo |
Naseer Ahmed | f8ec162 | 2012-07-31 18:56:23 -0700 | [diff] [blame] | 598 | if ((isValidMode(ID)) && mCurrentMode != ID) { |
Naseer Ahmed | 0c8b7b5 | 2012-07-20 09:06:13 -0700 | [diff] [blame] | 599 | const struct disp_mode_timing_type *mode = |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 600 | &supported_video_mode_lut[0]; |
Naseer Ahmed | 0c8b7b5 | 2012-07-20 09:06:13 -0700 | [diff] [blame] | 601 | unsigned count = sizeof(supported_video_mode_lut)/sizeof |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 602 | (*supported_video_mode_lut); |
Naseer Ahmed | 0c8b7b5 | 2012-07-20 09:06:13 -0700 | [diff] [blame] | 603 | for (unsigned int i = 0; i < count; ++i) { |
| 604 | const struct disp_mode_timing_type *cur = |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 605 | &supported_video_mode_lut[i]; |
Naseer Ahmed | 0c8b7b5 | 2012-07-20 09:06:13 -0700 | [diff] [blame] | 606 | if (cur->video_format == ID) |
| 607 | mode = cur; |
| 608 | } |
Naseer Ahmed | f8ec162 | 2012-07-31 18:56:23 -0700 | [diff] [blame] | 609 | mode->set_info(mVInfo); |
| 610 | ALOGD_IF(DEBUG, "%s: SET Info<ID=%d => Info<ID=%d %dx %d" |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 611 | "(%d,%d,%d), (%d,%d,%d) %dMHz>", __FUNCTION__, ID, |
Arun Kumar K.R | e1cea3e | 2013-02-06 16:57:43 -0800 | [diff] [blame] | 612 | mode->video_format, mVInfo.xres, mVInfo.yres, |
Naseer Ahmed | f8ec162 | 2012-07-31 18:56:23 -0700 | [diff] [blame] | 613 | mVInfo.right_margin, mVInfo.hsync_len, mVInfo.left_margin, |
| 614 | mVInfo.lower_margin, mVInfo.vsync_len, mVInfo.upper_margin, |
| 615 | mVInfo.pixclock/1000/1000); |
Ken Zhang | 7b03a95 | 2013-01-16 13:23:48 -0500 | [diff] [blame] | 616 | #ifdef FB_METADATA_VIDEO_INFO_CODE_SUPPORT |
| 617 | struct msmfb_metadata metadata; |
| 618 | memset(&metadata, 0 , sizeof(metadata)); |
| 619 | metadata.op = metadata_op_vic; |
| 620 | metadata.data.video_info_code = mode->video_format; |
| 621 | if (ioctl(mFd, MSMFB_METADATA_SET, &metadata) == -1) { |
| 622 | ALOGD("In %s: MSMFB_METADATA_SET failed Err Str = %s", |
| 623 | __FUNCTION__, strerror(errno)); |
| 624 | } |
| 625 | #endif |
Arun Kumar K.R | e1cea3e | 2013-02-06 16:57:43 -0800 | [diff] [blame] | 626 | mVInfo.activate = FB_ACTIVATE_NOW | FB_ACTIVATE_ALL | FB_ACTIVATE_FORCE; |
| 627 | ret = ioctl(mFd, FBIOPUT_VSCREENINFO, &mVInfo); |
| 628 | if(ret < 0) { |
| 629 | ALOGD("In %s: FBIOPUT_VSCREENINFO failed Err Str = %s", |
| 630 | __FUNCTION__, strerror(errno)); |
| 631 | } |
Naseer Ahmed | f8ec162 | 2012-07-31 18:56:23 -0700 | [diff] [blame] | 632 | mCurrentMode = ID; |
Naseer Ahmed | 0c8b7b5 | 2012-07-20 09:06:13 -0700 | [diff] [blame] | 633 | } |
Naseer Ahmed | 0c8b7b5 | 2012-07-20 09:06:13 -0700 | [diff] [blame] | 634 | } |
| 635 | |
Amara Venkata Mastan Manoj Kumar | 5182a78 | 2012-12-03 12:08:48 -0800 | [diff] [blame] | 636 | void ExternalDisplay::setExternalDisplay(bool connected, int extFbNum) |
Naseer Ahmed | 0c8b7b5 | 2012-07-20 09:06:13 -0700 | [diff] [blame] | 637 | { |
Naseer Ahmed | 0c8b7b5 | 2012-07-20 09:06:13 -0700 | [diff] [blame] | 638 | hwc_context_t* ctx = mHwcContext; |
| 639 | if(ctx) { |
Amara Venkata Mastan Manoj Kumar | 5182a78 | 2012-12-03 12:08:48 -0800 | [diff] [blame] | 640 | ALOGD_IF(DEBUG, "%s: connected = %d", __FUNCTION__, connected); |
Naseer Ahmed | 0c8b7b5 | 2012-07-20 09:06:13 -0700 | [diff] [blame] | 641 | // Store the external display |
Amara Venkata Mastan Manoj Kumar | 5182a78 | 2012-12-03 12:08:48 -0800 | [diff] [blame] | 642 | mConnected = connected; |
| 643 | mConnectedFbNum = extFbNum; |
Amara Venkata Mastan Manoj Kumar | 11a380d | 2013-01-17 09:30:56 -0800 | [diff] [blame] | 644 | mHwcContext->dpyAttr[mExtDpyNum].connected = connected; |
Amara Venkata Mastan Manoj Kumar | 5182a78 | 2012-12-03 12:08:48 -0800 | [diff] [blame] | 645 | // Update external fb number in Overlay context |
| 646 | overlay::Overlay::getInstance()->setExtFbNum(extFbNum); |
Naseer Ahmed | 0c8b7b5 | 2012-07-20 09:06:13 -0700 | [diff] [blame] | 647 | } |
Amara Venkata Mastan Manoj Kumar | 5182a78 | 2012-12-03 12:08:48 -0800 | [diff] [blame] | 648 | } |
| 649 | |
| 650 | int ExternalDisplay::getExtFbNum(int &fbNum) { |
| 651 | int ret = -1; |
| 652 | if(mConnected) { |
| 653 | fbNum = mConnectedFbNum; |
| 654 | ret = 0; |
| 655 | } |
| 656 | return ret; |
Naseer Ahmed | 0c8b7b5 | 2012-07-20 09:06:13 -0700 | [diff] [blame] | 657 | } |
| 658 | |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 659 | bool ExternalDisplay::writeHPDOption(int userOption) const |
Naseer Ahmed | 0c8b7b5 | 2012-07-20 09:06:13 -0700 | [diff] [blame] | 660 | { |
| 661 | bool ret = true; |
Amara Venkata Mastan Manoj Kumar | 5182a78 | 2012-12-03 12:08:48 -0800 | [diff] [blame] | 662 | char sysFsHPDFilePath[255]; |
| 663 | sprintf(sysFsHPDFilePath ,"/sys/devices/virtual/graphics/fb%d/hpd", |
| 664 | mHdmiFbNum); |
| 665 | int hdmiHPDFile = open(sysFsHPDFilePath,O_RDWR, 0); |
Naseer Ahmed | 0c8b7b5 | 2012-07-20 09:06:13 -0700 | [diff] [blame] | 666 | if (hdmiHPDFile < 0) { |
Amara Venkata Mastan Manoj Kumar | 5182a78 | 2012-12-03 12:08:48 -0800 | [diff] [blame] | 667 | ALOGE("%s: state file '%s' not found : ret%d err str: %s", __FUNCTION__, |
| 668 | sysFsHPDFilePath, hdmiHPDFile, strerror(errno)); |
Naseer Ahmed | 0c8b7b5 | 2012-07-20 09:06:13 -0700 | [diff] [blame] | 669 | ret = false; |
| 670 | } else { |
| 671 | int err = -1; |
Amara Venkata Mastan Manoj Kumar | 5182a78 | 2012-12-03 12:08:48 -0800 | [diff] [blame] | 672 | ALOGD_IF(DEBUG, "%s: option = %d", __FUNCTION__, userOption); |
Naseer Ahmed | 0c8b7b5 | 2012-07-20 09:06:13 -0700 | [diff] [blame] | 673 | if(userOption) |
| 674 | err = write(hdmiHPDFile, "1", 2); |
| 675 | else |
| 676 | err = write(hdmiHPDFile, "0" , 2); |
| 677 | if (err <= 0) { |
Amara Venkata Mastan Manoj Kumar | 5182a78 | 2012-12-03 12:08:48 -0800 | [diff] [blame] | 678 | ALOGE("%s: file write failed '%s'", __FUNCTION__, sysFsHPDFilePath); |
Naseer Ahmed | 0c8b7b5 | 2012-07-20 09:06:13 -0700 | [diff] [blame] | 679 | ret = false; |
| 680 | } |
| 681 | close(hdmiHPDFile); |
| 682 | } |
| 683 | return ret; |
| 684 | } |
Naseer Ahmed | f8ec162 | 2012-07-31 18:56:23 -0700 | [diff] [blame] | 685 | |
Saurabh Shah | 3825f25 | 2012-09-21 16:32:18 -0700 | [diff] [blame] | 686 | /* |
| 687 | * commits the changes to the external display |
Saurabh Shah | 3825f25 | 2012-09-21 16:32:18 -0700 | [diff] [blame] | 688 | */ |
Saurabh Shah | 3e858eb | 2012-09-17 16:53:21 -0700 | [diff] [blame] | 689 | bool ExternalDisplay::post() |
Naseer Ahmed | f8ec162 | 2012-07-31 18:56:23 -0700 | [diff] [blame] | 690 | { |
Naseer Ahmed | 54821fe | 2012-11-28 18:44:38 -0500 | [diff] [blame] | 691 | if(mFd == -1) |
Naseer Ahmed | f8ec162 | 2012-07-31 18:56:23 -0700 | [diff] [blame] | 692 | return false; |
Amara Venkata Mastan Manoj Kumar | 11a380d | 2013-01-17 09:30:56 -0800 | [diff] [blame] | 693 | |
Naseer Ahmed | 54821fe | 2012-11-28 18:44:38 -0500 | [diff] [blame] | 694 | struct mdp_display_commit ext_commit; |
Naseer Ahmed | 9da8466 | 2012-12-06 19:29:29 -0500 | [diff] [blame] | 695 | memset(&ext_commit, 0, sizeof(struct mdp_display_commit)); |
| 696 | ext_commit.flags = MDP_DISPLAY_COMMIT_OVERLAY; |
Naseer Ahmed | 54821fe | 2012-11-28 18:44:38 -0500 | [diff] [blame] | 697 | if (ioctl(mFd, MSMFB_DISPLAY_COMMIT, &ext_commit) == -1) { |
Amara Venkata Mastan Manoj Kumar | 5182a78 | 2012-12-03 12:08:48 -0800 | [diff] [blame] | 698 | ALOGE("%s: MSMFB_DISPLAY_COMMIT for external failed, str: %s", |
| 699 | __FUNCTION__, strerror(errno)); |
| 700 | return false; |
Naseer Ahmed | f8ec162 | 2012-07-31 18:56:23 -0700 | [diff] [blame] | 701 | } |
| 702 | return true; |
| 703 | } |
| 704 | |
Amara Venkata Mastan Manoj Kumar | 5182a78 | 2012-12-03 12:08:48 -0800 | [diff] [blame] | 705 | void ExternalDisplay::setDpyWfdAttr() { |
| 706 | if(mHwcContext) { |
Amara Venkata Mastan Manoj Kumar | 11a380d | 2013-01-17 09:30:56 -0800 | [diff] [blame] | 707 | mHwcContext->dpyAttr[mExtDpyNum].xres = mVInfo.xres; |
| 708 | mHwcContext->dpyAttr[mExtDpyNum].yres = mVInfo.yres; |
| 709 | mHwcContext->dpyAttr[mExtDpyNum].vsync_period = |
Amara Venkata Mastan Manoj Kumar | 5182a78 | 2012-12-03 12:08:48 -0800 | [diff] [blame] | 710 | 1000000000l /60; |
| 711 | ALOGD_IF(DEBUG,"%s: wfd...connected..!",__FUNCTION__); |
| 712 | } |
| 713 | } |
| 714 | |
| 715 | void ExternalDisplay::setDpyHdmiAttr() { |
Saurabh Shah | 3e858eb | 2012-09-17 16:53:21 -0700 | [diff] [blame] | 716 | int width = 0, height = 0, fps = 0; |
| 717 | getAttrForMode(width, height, fps); |
| 718 | if(mHwcContext) { |
Saurabh Shah | c4d034f | 2012-09-27 15:55:15 -0700 | [diff] [blame] | 719 | ALOGD("ExtDisplay setting xres = %d, yres = %d", width, height); |
Saurabh Shah | 3e858eb | 2012-09-17 16:53:21 -0700 | [diff] [blame] | 720 | mHwcContext->dpyAttr[HWC_DISPLAY_EXTERNAL].xres = width; |
| 721 | mHwcContext->dpyAttr[HWC_DISPLAY_EXTERNAL].yres = height; |
Saurabh Shah | c4d034f | 2012-09-27 15:55:15 -0700 | [diff] [blame] | 722 | mHwcContext->dpyAttr[HWC_DISPLAY_EXTERNAL].vsync_period = |
| 723 | 1000000000l / fps; |
Naseer Ahmed | f8ec162 | 2012-07-31 18:56:23 -0700 | [diff] [blame] | 724 | } |
Saurabh Shah | 3e858eb | 2012-09-17 16:53:21 -0700 | [diff] [blame] | 725 | } |
| 726 | |
Amara Venkata Mastan Manoj Kumar | 5182a78 | 2012-12-03 12:08:48 -0800 | [diff] [blame] | 727 | void ExternalDisplay::getAttrForMode(int& width, int& height, int& fps) { |
Saurabh Shah | 3e858eb | 2012-09-17 16:53:21 -0700 | [diff] [blame] | 728 | switch (mCurrentMode) { |
| 729 | case m640x480p60_4_3: |
| 730 | width = 640; |
| 731 | height = 480; |
| 732 | fps = 60; |
| 733 | break; |
| 734 | case m720x480p60_4_3: |
| 735 | case m720x480p60_16_9: |
| 736 | width = 720; |
| 737 | height = 480; |
| 738 | fps = 60; |
| 739 | break; |
| 740 | case m720x576p50_4_3: |
| 741 | case m720x576p50_16_9: |
| 742 | width = 720; |
| 743 | height = 576; |
| 744 | fps = 50; |
| 745 | break; |
| 746 | case m1280x720p50_16_9: |
| 747 | width = 1280; |
| 748 | height = 720; |
| 749 | fps = 50; |
| 750 | break; |
| 751 | case m1280x720p60_16_9: |
| 752 | width = 1280; |
| 753 | height = 720; |
| 754 | fps = 60; |
| 755 | break; |
| 756 | case m1920x1080p24_16_9: |
| 757 | width = 1920; |
| 758 | height = 1080; |
| 759 | fps = 24; |
| 760 | break; |
| 761 | case m1920x1080p25_16_9: |
| 762 | width = 1920; |
| 763 | height = 1080; |
| 764 | fps = 25; |
| 765 | break; |
| 766 | case m1920x1080p30_16_9: |
| 767 | width = 1920; |
| 768 | height = 1080; |
| 769 | fps = 30; |
| 770 | break; |
| 771 | case m1920x1080p50_16_9: |
| 772 | width = 1920; |
| 773 | height = 1080; |
| 774 | fps = 50; |
| 775 | break; |
| 776 | case m1920x1080p60_16_9: |
| 777 | width = 1920; |
| 778 | height = 1080; |
| 779 | fps = 60; |
| 780 | break; |
| 781 | } |
Naseer Ahmed | f8ec162 | 2012-07-31 18:56:23 -0700 | [diff] [blame] | 782 | } |
| 783 | |
Naseer Ahmed | 0c8b7b5 | 2012-07-20 09:06:13 -0700 | [diff] [blame] | 784 | }; |