Arun Kumar K.R | f6f49a1 | 2012-11-27 11:46:50 -0800 | [diff] [blame] | 1 | |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (C) 2010 The Android Open Source Project |
Saurabh Shah | 56f610d | 2012-08-07 15:27:06 -0700 | [diff] [blame] | 4 | * Copyright (C) 2012, The Linux Foundation. All rights reserved. |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 5 | * |
| 6 | * Not a Contribution, Apache license notifications and license are |
| 7 | * retained for attribution purposes only. |
| 8 | |
| 9 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 10 | * you may not use this file except in compliance with the License. |
| 11 | * You may obtain a copy of the License at |
| 12 | * |
| 13 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 14 | * |
| 15 | * Unless required by applicable law or agreed to in writing, software |
| 16 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 17 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 18 | * See the License for the specific language governing permissions and |
| 19 | * limitations under the License. |
| 20 | */ |
Saurabh Shah | 649cda6 | 2012-09-16 16:05:58 -0700 | [diff] [blame] | 21 | #define UEVENT_DEBUG 0 |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 22 | #include <hardware_legacy/uevent.h> |
| 23 | #include <utils/Log.h> |
| 24 | #include <sys/resource.h> |
Naseer Ahmed | ff4f025 | 2012-10-01 13:03:01 -0400 | [diff] [blame] | 25 | #include <sys/prctl.h> |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 26 | #include <string.h> |
| 27 | #include <stdlib.h> |
| 28 | #include "hwc_utils.h" |
Saurabh Shah | cf053c6 | 2012-12-13 12:32:55 -0800 | [diff] [blame] | 29 | #include "hwc_fbupdate.h" |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 30 | #include "hwc_mdpcomp.h" |
Arun Kumar K.R | 361da4f | 2012-11-28 10:42:59 -0800 | [diff] [blame] | 31 | #include "hwc_copybit.h" |
| 32 | #include "comptype.h" |
Saurabh Shah | 56f610d | 2012-08-07 15:27:06 -0700 | [diff] [blame] | 33 | #include "external.h" |
Jeykumar Sankaran | 27dee26 | 2013-08-01 17:09:54 -0700 | [diff] [blame^] | 34 | #include "virtual.h" |
Saurabh Shah | 67a38c3 | 2013-06-10 16:23:15 -0700 | [diff] [blame] | 35 | #include "mdp_version.h" |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 36 | |
| 37 | namespace qhwc { |
Amara Venkata Mastan Manoj Kumar | b156a2f | 2013-02-07 16:42:50 -0800 | [diff] [blame] | 38 | #define HWC_UEVENT_SWITCH_STR "change@/devices/virtual/switch/" |
Iliyan Malchev | 0f9c397 | 2012-10-11 15:16:15 -0700 | [diff] [blame] | 39 | #define HWC_UEVENT_THREAD_NAME "hwcUeventThread" |
| 40 | |
Amara Venkata Mastan Manoj Kumar | 11a380d | 2013-01-17 09:30:56 -0800 | [diff] [blame] | 41 | /* External Display states */ |
| 42 | enum { |
| 43 | EXTERNAL_OFFLINE = 0, |
| 44 | EXTERNAL_ONLINE, |
| 45 | EXTERNAL_PAUSE, |
| 46 | EXTERNAL_RESUME |
| 47 | }; |
| 48 | |
Jeykumar Sankaran | 27dee26 | 2013-08-01 17:09:54 -0700 | [diff] [blame^] | 49 | static void setup(hwc_context_t* ctx, int dpy) |
Amara Venkata Mastan Manoj Kumar | b156a2f | 2013-02-07 16:42:50 -0800 | [diff] [blame] | 50 | { |
Saurabh Shah | 67a38c3 | 2013-06-10 16:23:15 -0700 | [diff] [blame] | 51 | const int rSplit = 0; //Even split for external if at all |
| 52 | ctx->mFBUpdate[dpy] = IFBUpdate::getObject(ctx->dpyAttr[dpy].xres, |
| 53 | rSplit, dpy); |
| 54 | ctx->mMDPComp[dpy] = MDPComp::getObject(ctx->dpyAttr[dpy].xres, |
| 55 | rSplit, dpy); |
Jeykumar Sankaran | 27dee26 | 2013-08-01 17:09:54 -0700 | [diff] [blame^] | 56 | int compositionType = |
| 57 | qdutils::QCCompositionType::getInstance().getCompositionType(); |
| 58 | if (compositionType & (qdutils::COMPOSITION_TYPE_DYN | |
| 59 | qdutils::COMPOSITION_TYPE_MDP | |
| 60 | qdutils::COMPOSITION_TYPE_C2D)) { |
Amara Venkata Mastan Manoj Kumar | b156a2f | 2013-02-07 16:42:50 -0800 | [diff] [blame] | 61 | ctx->mCopyBit[dpy] = new CopyBit(); |
Jeykumar Sankaran | 27dee26 | 2013-08-01 17:09:54 -0700 | [diff] [blame^] | 62 | } |
Amara Venkata Mastan Manoj Kumar | b156a2f | 2013-02-07 16:42:50 -0800 | [diff] [blame] | 63 | } |
| 64 | |
| 65 | static void clear(hwc_context_t* ctx, int dpy) |
| 66 | { |
| 67 | if(ctx->mFBUpdate[dpy]) { |
| 68 | delete ctx->mFBUpdate[dpy]; |
| 69 | ctx->mFBUpdate[dpy] = NULL; |
| 70 | } |
| 71 | if(ctx->mCopyBit[dpy]){ |
| 72 | delete ctx->mCopyBit[dpy]; |
| 73 | ctx->mCopyBit[dpy] = NULL; |
| 74 | } |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 75 | if(ctx->mMDPComp[dpy]) { |
| 76 | delete ctx->mMDPComp[dpy]; |
| 77 | ctx->mMDPComp[dpy] = NULL; |
Amara Venkata Mastan Manoj Kumar | b156a2f | 2013-02-07 16:42:50 -0800 | [diff] [blame] | 78 | } |
| 79 | } |
| 80 | |
Jeykumar Sankaran | 27dee26 | 2013-08-01 17:09:54 -0700 | [diff] [blame^] | 81 | /* Parse uevent data for devices which we are interested */ |
| 82 | static int getConnectedDisplay(const char* strUdata) |
| 83 | { |
| 84 | if(strcasestr("change@/devices/virtual/switch/hdmi", strUdata)) |
| 85 | return HWC_DISPLAY_EXTERNAL; |
| 86 | if(strcasestr("change@/devices/virtual/switch/wfd", strUdata)) |
| 87 | return HWC_DISPLAY_VIRTUAL; |
| 88 | return -1; |
| 89 | } |
| 90 | |
| 91 | /* Parse uevent data for action requested for the display */ |
| 92 | static int getConnectedState(const char* strUdata, int len) |
| 93 | { |
| 94 | const char* iter_str = strUdata; |
| 95 | while(((iter_str - strUdata) <= len) && (*iter_str)) { |
| 96 | char* pstr = strstr(iter_str, "SWITCH_STATE="); |
| 97 | if (pstr != NULL) { |
| 98 | return (atoi(pstr + strlen("SWITCH_STATE="))); |
| 99 | } |
| 100 | iter_str += strlen(iter_str)+1; |
| 101 | } |
| 102 | return -1; |
| 103 | } |
| 104 | |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 105 | static void handle_uevent(hwc_context_t* ctx, const char* udata, int len) |
| 106 | { |
Jeykumar Sankaran | 27dee26 | 2013-08-01 17:09:54 -0700 | [diff] [blame^] | 107 | int dpy = getConnectedDisplay(udata); |
| 108 | if(dpy < 0) { |
| 109 | ALOGD_IF(UEVENT_DEBUG, "%s: Not disp Event ", __FUNCTION__); |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 110 | return; |
Naseer Ahmed | f8ec162 | 2012-07-31 18:56:23 -0700 | [diff] [blame] | 111 | } |
Amara Venkata Mastan Manoj Kumar | 11a380d | 2013-01-17 09:30:56 -0800 | [diff] [blame] | 112 | |
Jeykumar Sankaran | 27dee26 | 2013-08-01 17:09:54 -0700 | [diff] [blame^] | 113 | int switch_state = getConnectedState(udata, len); |
Amara Venkata Mastan Manoj Kumar | 11a380d | 2013-01-17 09:30:56 -0800 | [diff] [blame] | 114 | |
Jeykumar Sankaran | 27dee26 | 2013-08-01 17:09:54 -0700 | [diff] [blame^] | 115 | ALOGE_IF(UEVENT_DEBUG,"%s: uevent recieved: %s switch state: %d", |
| 116 | __FUNCTION__,udata, switch_state); |
Amara Venkata Mastan Manoj Kumar | 11a380d | 2013-01-17 09:30:56 -0800 | [diff] [blame] | 117 | |
Jeykumar Sankaran | 27dee26 | 2013-08-01 17:09:54 -0700 | [diff] [blame^] | 118 | switch(switch_state) { |
| 119 | case EXTERNAL_OFFLINE: |
| 120 | { |
| 121 | /* Display not connected */ |
| 122 | if(!ctx->dpyAttr[dpy].connected){ |
| 123 | ALOGE_IF(UEVENT_DEBUG,"%s: Ignoring EXTERNAL_OFFLINE event" |
| 124 | "for display: %d", __FUNCTION__, dpy); |
Amara Venkata Mastan Manoj Kumar | 11a380d | 2013-01-17 09:30:56 -0800 | [diff] [blame] | 125 | break; |
Saurabh Shah | cf053c6 | 2012-12-13 12:32:55 -0800 | [diff] [blame] | 126 | } |
Jeykumar Sankaran | 27dee26 | 2013-08-01 17:09:54 -0700 | [diff] [blame^] | 127 | |
| 128 | Locker::Autolock _l(ctx->mExtLock); |
| 129 | clear(ctx, dpy); |
| 130 | ctx->dpyAttr[dpy].connected = false; |
| 131 | ctx->dpyAttr[dpy].isActive = false; |
| 132 | |
| 133 | if(dpy == HWC_DISPLAY_EXTERNAL) { |
| 134 | ctx->mExtDisplay->teardown(); |
| 135 | } else { |
| 136 | ctx->mVirtualDisplay->teardown(); |
| 137 | } |
| 138 | |
| 139 | /* We need to send hotplug to SF only when we are disconnecting |
| 140 | * (1) HDMI OR (2) proprietary WFD session */ |
| 141 | if(dpy == HWC_DISPLAY_EXTERNAL || |
| 142 | ctx->mVirtualonExtActive) { |
| 143 | ALOGE_IF(UEVENT_DEBUG,"%s:Sending EXTERNAL OFFLINE hotplug" |
| 144 | "event", __FUNCTION__); |
| 145 | ctx->proc->hotplug(ctx->proc, HWC_DISPLAY_EXTERNAL, |
| 146 | EXTERNAL_OFFLINE); |
| 147 | } |
| 148 | break; |
| 149 | } |
| 150 | case EXTERNAL_ONLINE: |
| 151 | { |
| 152 | /* Display already connected */ |
| 153 | if(ctx->dpyAttr[dpy].connected) { |
| 154 | ALOGE_IF(UEVENT_DEBUG,"%s: Ignoring EXTERNAL_ONLINE event" |
| 155 | "for display: %d", __FUNCTION__, dpy); |
| 156 | break; |
| 157 | } |
| 158 | { |
| 159 | //Force composition to give up resources like pipes and |
| 160 | //close fb. For example if assertive display is going on, |
| 161 | //fb2 could be open, thus connecting Layer Mixer#0 to |
| 162 | //WriteBack module. If HDMI attempts to open fb1, the driver |
| 163 | //will try to attach Layer Mixer#0 to HDMI INT, which will |
| 164 | //fail, since Layer Mixer#0 is still connected to WriteBack. |
| 165 | //This block will force composition to close fb2 in above |
| 166 | //example. |
| 167 | Locker::Autolock _l(ctx->mExtLock); |
| 168 | ctx->dpyAttr[dpy].isConfiguring = true; |
| 169 | ctx->proc->invalidate(ctx->proc); |
| 170 | } |
| 171 | //2 cycles for slower content |
| 172 | usleep(ctx->dpyAttr[HWC_DISPLAY_PRIMARY].vsync_period |
| 173 | * 2 / 1000); |
| 174 | |
| 175 | if(dpy == HWC_DISPLAY_EXTERNAL) { |
| 176 | if(ctx->dpyAttr[HWC_DISPLAY_VIRTUAL].connected) { |
| 177 | ALOGD_IF(UEVENT_DEBUG,"Received HDMI connection request" |
| 178 | "when WFD is active"); |
| 179 | { |
| 180 | Locker::Autolock _l(ctx->mExtLock); |
| 181 | clear(ctx, HWC_DISPLAY_VIRTUAL); |
| 182 | ctx->dpyAttr[HWC_DISPLAY_VIRTUAL].connected = false; |
| 183 | ctx->dpyAttr[HWC_DISPLAY_VIRTUAL].isActive = false; |
| 184 | } |
| 185 | |
| 186 | ctx->mVirtualDisplay->teardown(); |
| 187 | |
| 188 | /* Need to send hotplug only when connected WFD in |
| 189 | * proprietary path */ |
| 190 | if(ctx->mVirtualonExtActive) { |
| 191 | ALOGE_IF(UEVENT_DEBUG,"%s: Sending EXTERNAL OFFLINE" |
| 192 | "hotplug event", __FUNCTION__); |
| 193 | ctx->proc->hotplug(ctx->proc, HWC_DISPLAY_EXTERNAL, |
| 194 | EXTERNAL_OFFLINE); |
Amara Venkata Mastan Manoj Kumar | b156a2f | 2013-02-07 16:42:50 -0800 | [diff] [blame] | 195 | { |
Raj kamal | e3e68ae | 2013-05-02 17:28:23 +0530 | [diff] [blame] | 196 | Locker::Autolock _l(ctx->mExtLock); |
Jeykumar Sankaran | 27dee26 | 2013-08-01 17:09:54 -0700 | [diff] [blame^] | 197 | ctx->mVirtualonExtActive = false; |
Amara Venkata Mastan Manoj Kumar | b156a2f | 2013-02-07 16:42:50 -0800 | [diff] [blame] | 198 | } |
Amara Venkata Mastan Manoj Kumar | b156a2f | 2013-02-07 16:42:50 -0800 | [diff] [blame] | 199 | } |
Jeykumar Sankaran | 27dee26 | 2013-08-01 17:09:54 -0700 | [diff] [blame^] | 200 | /* Wait for few frames for SF to tear down |
| 201 | * the WFD session. */ |
| 202 | usleep(ctx->dpyAttr[HWC_DISPLAY_PRIMARY].vsync_period |
| 203 | * 2 / 1000); |
Amara Venkata Mastan Manoj Kumar | b156a2f | 2013-02-07 16:42:50 -0800 | [diff] [blame] | 204 | } |
Jeykumar Sankaran | 27dee26 | 2013-08-01 17:09:54 -0700 | [diff] [blame^] | 205 | ctx->mExtDisplay->configure(); |
| 206 | } else { |
Saurabh Shah | 188e433 | 2013-07-18 10:33:22 -0700 | [diff] [blame] | 207 | { |
| 208 | Locker::Autolock _l(ctx->mExtLock); |
Jeykumar Sankaran | 27dee26 | 2013-08-01 17:09:54 -0700 | [diff] [blame^] | 209 | /* TRUE only when we are on proprietary WFD session */ |
| 210 | ctx->mVirtualonExtActive = true; |
| 211 | char property[PROPERTY_VALUE_MAX]; |
| 212 | if((property_get("persist.sys.wfd.virtual", |
| 213 | property, NULL) > 0) && |
| 214 | (!strncmp(property, "1", PROPERTY_VALUE_MAX ) || |
| 215 | (!strncasecmp(property,"true", PROPERTY_VALUE_MAX )))) { |
| 216 | // This means we are on Google's WFD session |
| 217 | ctx->mVirtualonExtActive = false; |
| 218 | } |
Saurabh Shah | 188e433 | 2013-07-18 10:33:22 -0700 | [diff] [blame] | 219 | } |
Jeykumar Sankaran | 27dee26 | 2013-08-01 17:09:54 -0700 | [diff] [blame^] | 220 | ctx->mVirtualDisplay->configure(); |
Arun Kumar K.R | 361da4f | 2012-11-28 10:42:59 -0800 | [diff] [blame] | 221 | } |
Jeykumar Sankaran | 27dee26 | 2013-08-01 17:09:54 -0700 | [diff] [blame^] | 222 | |
| 223 | Locker::Autolock _l(ctx->mExtLock); |
| 224 | setup(ctx, dpy); |
| 225 | ctx->dpyAttr[dpy].isPause = false; |
| 226 | ctx->dpyAttr[dpy].connected = true; |
| 227 | ctx->dpyAttr[dpy].isConfiguring = true; |
| 228 | |
| 229 | if(dpy == HWC_DISPLAY_VIRTUAL) { |
| 230 | /* We wont be getting unblank for VIRTUAL DISPLAY and its |
| 231 | * always guaranteed from WFD stack that CONNECT uevent for |
| 232 | * VIRTUAL DISPLAY will be triggered before creating |
| 233 | * surface for the same. */ |
| 234 | ctx->dpyAttr[HWC_DISPLAY_VIRTUAL].isActive = true; |
Amara Venkata Mastan Manoj Kumar | 11a380d | 2013-01-17 09:30:56 -0800 | [diff] [blame] | 235 | } |
Jeykumar Sankaran | 27dee26 | 2013-08-01 17:09:54 -0700 | [diff] [blame^] | 236 | |
| 237 | if(dpy == HWC_DISPLAY_EXTERNAL || |
| 238 | ctx->mVirtualonExtActive) { |
| 239 | ALOGE_IF(UEVENT_DEBUG, "%s: Sending EXTERNAL_OFFLINE ONLINE" |
| 240 | "hotplug event", __FUNCTION__); |
| 241 | ctx->proc->hotplug(ctx->proc,HWC_DISPLAY_EXTERNAL, |
| 242 | EXTERNAL_ONLINE); |
Amara Venkata Mastan Manoj Kumar | 11a380d | 2013-01-17 09:30:56 -0800 | [diff] [blame] | 243 | } |
Jeykumar Sankaran | 27dee26 | 2013-08-01 17:09:54 -0700 | [diff] [blame^] | 244 | break; |
| 245 | } |
| 246 | case EXTERNAL_PAUSE: |
| 247 | { |
| 248 | ctx->dpyAttr[dpy].isActive = true; |
| 249 | ctx->dpyAttr[dpy].isPause = true; |
| 250 | break; |
| 251 | } |
| 252 | case EXTERNAL_RESUME: |
| 253 | { |
| 254 | //Treat Resume as Online event |
| 255 | //Since external didnt have any pipes, force primary to give up |
| 256 | //its pipes; we don't allow inter-mixer pipe transfers. |
Amara Venkata Mastan Manoj Kumar | 11a380d | 2013-01-17 09:30:56 -0800 | [diff] [blame] | 257 | { |
Jeykumar Sankaran | 27dee26 | 2013-08-01 17:09:54 -0700 | [diff] [blame^] | 258 | Locker::Autolock _l(ctx->mExtLock); |
| 259 | ctx->dpyAttr[dpy].isConfiguring = true; |
| 260 | ctx->dpyAttr[dpy].isActive = true; |
| 261 | ctx->proc->invalidate(ctx->proc); |
Amara Venkata Mastan Manoj Kumar | 11a380d | 2013-01-17 09:30:56 -0800 | [diff] [blame] | 262 | } |
Jeykumar Sankaran | 27dee26 | 2013-08-01 17:09:54 -0700 | [diff] [blame^] | 263 | usleep(ctx->dpyAttr[HWC_DISPLAY_PRIMARY].vsync_period |
| 264 | * 2 / 1000); |
| 265 | { |
| 266 | //At this point external has all the pipes it would need. |
| 267 | Locker::Autolock _l(ctx->mExtLock); |
| 268 | ctx->dpyAttr[dpy].isPause = false; |
| 269 | ctx->proc->invalidate(ctx->proc); |
| 270 | } |
| 271 | break; |
| 272 | } |
| 273 | default: |
| 274 | { |
| 275 | ALOGE("%s: Invalid state to swtich:%d", __FUNCTION__, switch_state); |
| 276 | break; |
| 277 | } |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 278 | } |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 279 | } |
| 280 | |
| 281 | static void *uevent_loop(void *param) |
| 282 | { |
| 283 | int len = 0; |
Naseer Ahmed | ff4f025 | 2012-10-01 13:03:01 -0400 | [diff] [blame] | 284 | static char udata[PAGE_SIZE]; |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 285 | hwc_context_t * ctx = reinterpret_cast<hwc_context_t *>(param); |
Iliyan Malchev | 0f9c397 | 2012-10-11 15:16:15 -0700 | [diff] [blame] | 286 | char thread_name[64] = HWC_UEVENT_THREAD_NAME; |
Naseer Ahmed | ff4f025 | 2012-10-01 13:03:01 -0400 | [diff] [blame] | 287 | prctl(PR_SET_NAME, (unsigned long) &thread_name, 0, 0, 0); |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 288 | setpriority(PRIO_PROCESS, 0, HAL_PRIORITY_URGENT_DISPLAY); |
| 289 | uevent_init(); |
| 290 | |
| 291 | while(1) { |
| 292 | len = uevent_next_event(udata, sizeof(udata) - 2); |
| 293 | handle_uevent(ctx, udata, len); |
| 294 | } |
| 295 | |
| 296 | return NULL; |
| 297 | } |
| 298 | |
| 299 | void init_uevent_thread(hwc_context_t* ctx) |
| 300 | { |
| 301 | pthread_t uevent_thread; |
Iliyan Malchev | 0f9c397 | 2012-10-11 15:16:15 -0700 | [diff] [blame] | 302 | int ret; |
| 303 | |
| 304 | ALOGI("Initializing UEVENT Thread"); |
| 305 | ret = pthread_create(&uevent_thread, NULL, uevent_loop, (void*) ctx); |
| 306 | if (ret) { |
| 307 | ALOGE("%s: failed to create %s: %s", __FUNCTION__, |
| 308 | HWC_UEVENT_THREAD_NAME, strerror(ret)); |
| 309 | } |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 310 | } |
| 311 | |
| 312 | }; //namespace |