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" |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 34 | |
| 35 | namespace qhwc { |
Amara Venkata Mastan Manoj Kumar | b156a2f | 2013-02-07 16:42:50 -0800 | [diff] [blame] | 36 | #define HWC_UEVENT_SWITCH_STR "change@/devices/virtual/switch/" |
Iliyan Malchev | 0f9c397 | 2012-10-11 15:16:15 -0700 | [diff] [blame] | 37 | #define HWC_UEVENT_THREAD_NAME "hwcUeventThread" |
| 38 | |
Amara Venkata Mastan Manoj Kumar | 11a380d | 2013-01-17 09:30:56 -0800 | [diff] [blame] | 39 | /* External Display states */ |
| 40 | enum { |
| 41 | EXTERNAL_OFFLINE = 0, |
| 42 | EXTERNAL_ONLINE, |
| 43 | EXTERNAL_PAUSE, |
| 44 | EXTERNAL_RESUME |
| 45 | }; |
| 46 | |
| 47 | static bool isHDMI(const char* str) |
| 48 | { |
| 49 | if(strcasestr("change@/devices/virtual/switch/hdmi", str)) |
| 50 | return true; |
| 51 | return false; |
| 52 | } |
| 53 | |
Amara Venkata Mastan Manoj Kumar | b156a2f | 2013-02-07 16:42:50 -0800 | [diff] [blame] | 54 | static void setup(hwc_context_t* ctx, int dpy, bool usecopybit) |
| 55 | { |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame^] | 56 | ctx->mFBUpdate[dpy] = IFBUpdate::getObject(ctx->dpyAttr[dpy].xres, dpy); |
| 57 | ctx->mMDPComp[dpy] = MDPComp::getObject(ctx->dpyAttr[dpy].xres, dpy); |
Amara Venkata Mastan Manoj Kumar | b156a2f | 2013-02-07 16:42:50 -0800 | [diff] [blame] | 58 | if(usecopybit) |
| 59 | ctx->mCopyBit[dpy] = new CopyBit(); |
Amara Venkata Mastan Manoj Kumar | b156a2f | 2013-02-07 16:42:50 -0800 | [diff] [blame] | 60 | } |
| 61 | |
| 62 | static void clear(hwc_context_t* ctx, int dpy) |
| 63 | { |
| 64 | if(ctx->mFBUpdate[dpy]) { |
| 65 | delete ctx->mFBUpdate[dpy]; |
| 66 | ctx->mFBUpdate[dpy] = NULL; |
| 67 | } |
| 68 | if(ctx->mCopyBit[dpy]){ |
| 69 | delete ctx->mCopyBit[dpy]; |
| 70 | ctx->mCopyBit[dpy] = NULL; |
| 71 | } |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame^] | 72 | if(ctx->mMDPComp[dpy]) { |
| 73 | delete ctx->mMDPComp[dpy]; |
| 74 | ctx->mMDPComp[dpy] = NULL; |
Amara Venkata Mastan Manoj Kumar | b156a2f | 2013-02-07 16:42:50 -0800 | [diff] [blame] | 75 | } |
| 76 | } |
| 77 | |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 78 | static void handle_uevent(hwc_context_t* ctx, const char* udata, int len) |
| 79 | { |
Naseer Ahmed | f8ec162 | 2012-07-31 18:56:23 -0700 | [diff] [blame] | 80 | int vsync = 0; |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 81 | int64_t timestamp = 0; |
| 82 | const char *str = udata; |
Arun Kumar K.R | 361da4f | 2012-11-28 10:42:59 -0800 | [diff] [blame] | 83 | bool usecopybit = false; |
| 84 | int compositionType = |
| 85 | qdutils::QCCompositionType::getInstance().getCompositionType(); |
| 86 | |
| 87 | if (compositionType & (qdutils::COMPOSITION_TYPE_DYN | |
| 88 | qdutils::COMPOSITION_TYPE_MDP | |
| 89 | qdutils::COMPOSITION_TYPE_C2D)) { |
| 90 | usecopybit = true; |
Arun Kumar K.R | 361da4f | 2012-11-28 10:42:59 -0800 | [diff] [blame] | 91 | } |
Amara Venkata Mastan Manoj Kumar | e37e571 | 2012-12-17 17:36:02 -0800 | [diff] [blame] | 92 | if(!strcasestr("change@/devices/virtual/switch/hdmi", str) && |
| 93 | !strcasestr("change@/devices/virtual/switch/wfd", str)) { |
Saurabh Shah | 649cda6 | 2012-09-16 16:05:58 -0700 | [diff] [blame] | 94 | ALOGD_IF(UEVENT_DEBUG, "%s: Not Ext Disp Event ", __FUNCTION__); |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 95 | return; |
Naseer Ahmed | f8ec162 | 2012-07-31 18:56:23 -0700 | [diff] [blame] | 96 | } |
Arun Kumar K.R | f6f49a1 | 2012-11-27 11:46:50 -0800 | [diff] [blame] | 97 | int connected = -1; // initial value - will be set to 1/0 based on hotplug |
Amara Venkata Mastan Manoj Kumar | 11a380d | 2013-01-17 09:30:56 -0800 | [diff] [blame] | 98 | int extDpyNum = HWC_DISPLAY_EXTERNAL; |
| 99 | char property[PROPERTY_VALUE_MAX]; |
| 100 | if((property_get("persist.sys.wfd.virtual", property, NULL) > 0) && |
| 101 | (!strncmp(property, "1", PROPERTY_VALUE_MAX ) || |
| 102 | (!strncasecmp(property,"true", PROPERTY_VALUE_MAX )))) { |
| 103 | // This means we are using Google API to trigger WFD Display |
| 104 | extDpyNum = HWC_DISPLAY_VIRTUAL; |
| 105 | |
| 106 | } |
| 107 | |
| 108 | int dpy = isHDMI(str) ? HWC_DISPLAY_EXTERNAL : extDpyNum; |
| 109 | |
Amara Venkata Mastan Manoj Kumar | 5182a78 | 2012-12-03 12:08:48 -0800 | [diff] [blame] | 110 | // parse HDMI/WFD switch state for connect/disconnect |
| 111 | // for HDMI: |
Naseer Ahmed | ff4f025 | 2012-10-01 13:03:01 -0400 | [diff] [blame] | 112 | // The event will be of the form: |
Arun Kumar K.R | f6f49a1 | 2012-11-27 11:46:50 -0800 | [diff] [blame] | 113 | // change@/devices/virtual/switch/hdmi ACTION=change |
| 114 | // SWITCH_STATE=1 or SWITCH_STATE=0 |
| 115 | while(*str) { |
| 116 | if (!strncmp(str, "SWITCH_STATE=", strlen("SWITCH_STATE="))) { |
| 117 | connected = atoi(str + strlen("SWITCH_STATE=")); |
Saurabh Shah | 1a8cda0 | 2012-10-12 17:00:39 -0700 | [diff] [blame] | 118 | //Disabled until SF calls unblank |
| 119 | ctx->dpyAttr[HWC_DISPLAY_EXTERNAL].isActive = false; |
Amara Venkata Mastan Manoj Kumar | 11a380d | 2013-01-17 09:30:56 -0800 | [diff] [blame] | 120 | //Ignored for Virtual Displays |
| 121 | //ToDo: we can do this in a much better way |
| 122 | ctx->dpyAttr[HWC_DISPLAY_VIRTUAL].isActive = true; |
Arun Kumar K.R | f6f49a1 | 2012-11-27 11:46:50 -0800 | [diff] [blame] | 123 | break; |
Saurabh Shah | 1a8cda0 | 2012-10-12 17:00:39 -0700 | [diff] [blame] | 124 | } |
Arun Kumar K.R | f6f49a1 | 2012-11-27 11:46:50 -0800 | [diff] [blame] | 125 | str += strlen(str) + 1; |
| 126 | if (str - udata >= len) |
| 127 | break; |
| 128 | } |
Amara Venkata Mastan Manoj Kumar | b156a2f | 2013-02-07 16:42:50 -0800 | [diff] [blame] | 129 | ALOGD_IF(UEVENT_DEBUG, "Received str:%s",udata); |
Arun Kumar K.R | f6f49a1 | 2012-11-27 11:46:50 -0800 | [diff] [blame] | 130 | |
Amara Venkata Mastan Manoj Kumar | b156a2f | 2013-02-07 16:42:50 -0800 | [diff] [blame] | 131 | if(connected != EXTERNAL_ONLINE) { |
| 132 | if(ctx->mExtDisplay->ignoreRequest(udata)) { |
| 133 | ALOGD_IF(UEVENT_DEBUG,"No need to process this connection request" |
| 134 | "str:%s",udata); |
| 135 | ctx->dpyAttr[dpy].isActive = true; |
| 136 | return; |
| 137 | } |
| 138 | } |
| 139 | |
| 140 | // update extDpyNum |
| 141 | ctx->mExtDisplay->setExtDpyNum(dpy); |
Amara Venkata Mastan Manoj Kumar | 11a380d | 2013-01-17 09:30:56 -0800 | [diff] [blame] | 142 | switch(connected) { |
| 143 | case EXTERNAL_OFFLINE: |
| 144 | { // disconnect event |
Amara Venkata Mastan Manoj Kumar | b156a2f | 2013-02-07 16:42:50 -0800 | [diff] [blame] | 145 | const char *s1 = udata + strlen(HWC_UEVENT_SWITCH_STR); |
| 146 | if(!strncmp(s1,"hdmi",strlen(s1))) { |
| 147 | ctx->mExtDisplay->teardownHDMIDisplay(); |
| 148 | }else if(!strncmp(s1,"wfd",strlen(s1))) { |
| 149 | ctx->mExtDisplay->teardownWFDDisplay(); |
Amara Venkata Mastan Manoj Kumar | 11a380d | 2013-01-17 09:30:56 -0800 | [diff] [blame] | 150 | } |
Amara Venkata Mastan Manoj Kumar | b156a2f | 2013-02-07 16:42:50 -0800 | [diff] [blame] | 151 | Locker::Autolock _l(ctx->mExtSetLock); |
| 152 | clear(ctx, dpy); |
Amara Venkata Mastan Manoj Kumar | 11a380d | 2013-01-17 09:30:56 -0800 | [diff] [blame] | 153 | ALOGD("%s sending hotplug: connected = %d and dpy:%d", |
| 154 | __FUNCTION__, connected, dpy); |
| 155 | ctx->dpyAttr[dpy].connected = false; |
Amara Venkata Mastan Manoj Kumar | 11a380d | 2013-01-17 09:30:56 -0800 | [diff] [blame] | 156 | //hwc comp could be on |
| 157 | ctx->proc->hotplug(ctx->proc, dpy, connected); |
| 158 | break; |
Saurabh Shah | cf053c6 | 2012-12-13 12:32:55 -0800 | [diff] [blame] | 159 | } |
Amara Venkata Mastan Manoj Kumar | 11a380d | 2013-01-17 09:30:56 -0800 | [diff] [blame] | 160 | case EXTERNAL_ONLINE: |
| 161 | { // connect case |
| 162 | ctx->mExtDispConfiguring = true; |
Amara Venkata Mastan Manoj Kumar | b156a2f | 2013-02-07 16:42:50 -0800 | [diff] [blame] | 163 | const char *s1 = udata + strlen(HWC_UEVENT_SWITCH_STR); |
| 164 | if(!strncmp(s1,"hdmi",strlen(s1))) { |
| 165 | // hdmi online event..! |
| 166 | // check if WFD is configured |
| 167 | if(ctx->mExtDisplay->isWFDActive()) { |
| 168 | ALOGD_IF(UEVENT_DEBUG,"Received HDMI connection request" |
| 169 | "when WFD is active"); |
| 170 | // teardown Active WFD Display |
| 171 | ctx->mExtDisplay->teardownWFDDisplay(); |
| 172 | { |
| 173 | Locker::Autolock _l(ctx->mExtSetLock); |
| 174 | clear(ctx, dpy); |
| 175 | //send hotplug disconnect event |
| 176 | ALOGD_IF(UEVENT_DEBUG, "sending hotplug: disconnect" |
| 177 | "for WFD"); |
| 178 | // hwc comp could be on |
| 179 | ctx->proc->hotplug(ctx->proc, dpy, EXTERNAL_OFFLINE); |
| 180 | } |
| 181 | //Invalidate |
| 182 | ctx->proc->invalidate(ctx->proc); |
| 183 | //wait for 1 second |
| 184 | ALOGE_IF(UEVENT_DEBUG, "wait for 1 second -- padding" |
| 185 | "round"); |
| 186 | sleep(1); |
| 187 | } |
| 188 | ctx->mExtDisplay->configureHDMIDisplay(); |
| 189 | } else if(!strncmp(s1,"wfd",strlen(s1))) { |
| 190 | // wfd online event..! |
| 191 | ctx->mExtDisplay->configureWFDDisplay(); |
| 192 | } |
Amara Venkata Mastan Manoj Kumar | 11a380d | 2013-01-17 09:30:56 -0800 | [diff] [blame] | 193 | ctx->dpyAttr[dpy].isPause = false; |
Amara Venkata Mastan Manoj Kumar | b156a2f | 2013-02-07 16:42:50 -0800 | [diff] [blame] | 194 | setup(ctx, dpy, usecopybit); |
Amara Venkata Mastan Manoj Kumar | 11a380d | 2013-01-17 09:30:56 -0800 | [diff] [blame] | 195 | ALOGD("%s sending hotplug: connected = %d", __FUNCTION__, |
| 196 | connected); |
| 197 | ctx->dpyAttr[dpy].connected = true; |
| 198 | Locker::Autolock _l(ctx->mExtSetLock); //hwc comp could be on |
| 199 | ctx->proc->hotplug(ctx->proc, dpy, connected); |
| 200 | break; |
Arun Kumar K.R | 361da4f | 2012-11-28 10:42:59 -0800 | [diff] [blame] | 201 | } |
Amara Venkata Mastan Manoj Kumar | 11a380d | 2013-01-17 09:30:56 -0800 | [diff] [blame] | 202 | case EXTERNAL_PAUSE: |
| 203 | { // pause case |
| 204 | ALOGD("%s Received Pause event",__FUNCTION__); |
Amara Venkata Mastan Manoj Kumar | 460350e | 2013-02-14 16:14:33 -0800 | [diff] [blame] | 205 | // This is required to ensure that composition |
| 206 | // fall back to FB, closing all MDP pipes. |
| 207 | ctx->mExtDispConfiguring = true; |
Amara Venkata Mastan Manoj Kumar | 11a380d | 2013-01-17 09:30:56 -0800 | [diff] [blame] | 208 | ctx->dpyAttr[dpy].isActive = true; |
| 209 | ctx->dpyAttr[dpy].isPause = true; |
| 210 | break; |
| 211 | } |
| 212 | case EXTERNAL_RESUME: |
| 213 | { // resume case |
| 214 | ALOGD("%s Received resume event",__FUNCTION__); |
| 215 | ctx->dpyAttr[dpy].isActive = true; |
| 216 | ctx->dpyAttr[dpy].isPause = false; |
| 217 | break; |
| 218 | } |
| 219 | default: |
| 220 | { |
| 221 | ALOGE("ignore event and connected:%d",connected); |
| 222 | break; |
| 223 | } |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 224 | } |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 225 | } |
| 226 | |
| 227 | static void *uevent_loop(void *param) |
| 228 | { |
| 229 | int len = 0; |
Naseer Ahmed | ff4f025 | 2012-10-01 13:03:01 -0400 | [diff] [blame] | 230 | static char udata[PAGE_SIZE]; |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 231 | hwc_context_t * ctx = reinterpret_cast<hwc_context_t *>(param); |
Iliyan Malchev | 0f9c397 | 2012-10-11 15:16:15 -0700 | [diff] [blame] | 232 | char thread_name[64] = HWC_UEVENT_THREAD_NAME; |
Naseer Ahmed | ff4f025 | 2012-10-01 13:03:01 -0400 | [diff] [blame] | 233 | prctl(PR_SET_NAME, (unsigned long) &thread_name, 0, 0, 0); |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 234 | setpriority(PRIO_PROCESS, 0, HAL_PRIORITY_URGENT_DISPLAY); |
| 235 | uevent_init(); |
| 236 | |
| 237 | while(1) { |
| 238 | len = uevent_next_event(udata, sizeof(udata) - 2); |
| 239 | handle_uevent(ctx, udata, len); |
| 240 | } |
| 241 | |
| 242 | return NULL; |
| 243 | } |
| 244 | |
| 245 | void init_uevent_thread(hwc_context_t* ctx) |
| 246 | { |
| 247 | pthread_t uevent_thread; |
Iliyan Malchev | 0f9c397 | 2012-10-11 15:16:15 -0700 | [diff] [blame] | 248 | int ret; |
| 249 | |
| 250 | ALOGI("Initializing UEVENT Thread"); |
| 251 | ret = pthread_create(&uevent_thread, NULL, uevent_loop, (void*) ctx); |
| 252 | if (ret) { |
| 253 | ALOGE("%s: failed to create %s: %s", __FUNCTION__, |
| 254 | HWC_UEVENT_THREAD_NAME, strerror(ret)); |
| 255 | } |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 256 | } |
| 257 | |
| 258 | }; //namespace |