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