blob: 752aaa2dccffbdf599333f9aa0fb9a5911228cb2 [file] [log] [blame]
Arun Kumar K.Rf6f49a12012-11-27 11:46:50 -08001
Naseer Ahmed72cf9762012-07-21 12:17:13 -07002/*
3 * Copyright (C) 2010 The Android Open Source Project
Saurabh Shah56f610d2012-08-07 15:27:06 -07004 * Copyright (C) 2012, The Linux Foundation. All rights reserved.
Naseer Ahmed72cf9762012-07-21 12:17:13 -07005 *
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 Shah649cda62012-09-16 16:05:58 -070021#define UEVENT_DEBUG 0
Naseer Ahmed72cf9762012-07-21 12:17:13 -070022#include <hardware_legacy/uevent.h>
23#include <utils/Log.h>
24#include <sys/resource.h>
Naseer Ahmedff4f0252012-10-01 13:03:01 -040025#include <sys/prctl.h>
Naseer Ahmed72cf9762012-07-21 12:17:13 -070026#include <string.h>
27#include <stdlib.h>
28#include "hwc_utils.h"
Saurabh Shahcf053c62012-12-13 12:32:55 -080029#include "hwc_fbupdate.h"
Arun Kumar K.R361da4f2012-11-28 10:42:59 -080030#include "hwc_copybit.h"
31#include "comptype.h"
Saurabh Shah56f610d2012-08-07 15:27:06 -070032#include "external.h"
Naseer Ahmed72cf9762012-07-21 12:17:13 -070033
34namespace qhwc {
35
Iliyan Malchev0f9c3972012-10-11 15:16:15 -070036#define HWC_UEVENT_THREAD_NAME "hwcUeventThread"
37
Amara Venkata Mastan Manoj Kumar11a380d2013-01-17 09:30:56 -080038/* External Display states */
39enum {
40 EXTERNAL_OFFLINE = 0,
41 EXTERNAL_ONLINE,
42 EXTERNAL_PAUSE,
43 EXTERNAL_RESUME
44};
45
46static bool isHDMI(const char* str)
47{
48 if(strcasestr("change@/devices/virtual/switch/hdmi", str))
49 return true;
50 return false;
51}
52
Naseer Ahmed72cf9762012-07-21 12:17:13 -070053static void handle_uevent(hwc_context_t* ctx, const char* udata, int len)
54{
Naseer Ahmedf8ec1622012-07-31 18:56:23 -070055 int vsync = 0;
Naseer Ahmed72cf9762012-07-21 12:17:13 -070056 int64_t timestamp = 0;
57 const char *str = udata;
Arun Kumar K.R361da4f2012-11-28 10:42:59 -080058 bool usecopybit = false;
59 int compositionType =
60 qdutils::QCCompositionType::getInstance().getCompositionType();
61
62 if (compositionType & (qdutils::COMPOSITION_TYPE_DYN |
63 qdutils::COMPOSITION_TYPE_MDP |
64 qdutils::COMPOSITION_TYPE_C2D)) {
65 usecopybit = true;
Arun Kumar K.R361da4f2012-11-28 10:42:59 -080066 }
Naseer Ahmed72cf9762012-07-21 12:17:13 -070067
Amara Venkata Mastan Manoj Kumare37e5712012-12-17 17:36:02 -080068 if(!strcasestr("change@/devices/virtual/switch/hdmi", str) &&
69 !strcasestr("change@/devices/virtual/switch/wfd", str)) {
Saurabh Shah649cda62012-09-16 16:05:58 -070070 ALOGD_IF(UEVENT_DEBUG, "%s: Not Ext Disp Event ", __FUNCTION__);
Naseer Ahmed72cf9762012-07-21 12:17:13 -070071 return;
Naseer Ahmedf8ec1622012-07-31 18:56:23 -070072 }
Arun Kumar K.Rf6f49a12012-11-27 11:46:50 -080073 int connected = -1; // initial value - will be set to 1/0 based on hotplug
Amara Venkata Mastan Manoj Kumar11a380d2013-01-17 09:30:56 -080074 int extDpyNum = HWC_DISPLAY_EXTERNAL;
75 char property[PROPERTY_VALUE_MAX];
76 if((property_get("persist.sys.wfd.virtual", property, NULL) > 0) &&
77 (!strncmp(property, "1", PROPERTY_VALUE_MAX ) ||
78 (!strncasecmp(property,"true", PROPERTY_VALUE_MAX )))) {
79 // This means we are using Google API to trigger WFD Display
80 extDpyNum = HWC_DISPLAY_VIRTUAL;
81
82 }
83
84 int dpy = isHDMI(str) ? HWC_DISPLAY_EXTERNAL : extDpyNum;
85
86 // update extDpyNum
87 ctx->mExtDisplay->setExtDpyNum(dpy);
88
Amara Venkata Mastan Manoj Kumar5182a782012-12-03 12:08:48 -080089 // parse HDMI/WFD switch state for connect/disconnect
90 // for HDMI:
Naseer Ahmedff4f0252012-10-01 13:03:01 -040091 // The event will be of the form:
Arun Kumar K.Rf6f49a12012-11-27 11:46:50 -080092 // change@/devices/virtual/switch/hdmi ACTION=change
93 // SWITCH_STATE=1 or SWITCH_STATE=0
94 while(*str) {
95 if (!strncmp(str, "SWITCH_STATE=", strlen("SWITCH_STATE="))) {
96 connected = atoi(str + strlen("SWITCH_STATE="));
Saurabh Shah1a8cda02012-10-12 17:00:39 -070097 //Disabled until SF calls unblank
98 ctx->dpyAttr[HWC_DISPLAY_EXTERNAL].isActive = false;
Amara Venkata Mastan Manoj Kumar11a380d2013-01-17 09:30:56 -080099 //Ignored for Virtual Displays
100 //ToDo: we can do this in a much better way
101 ctx->dpyAttr[HWC_DISPLAY_VIRTUAL].isActive = true;
Arun Kumar K.Rf6f49a12012-11-27 11:46:50 -0800102 break;
Saurabh Shah1a8cda02012-10-12 17:00:39 -0700103 }
Arun Kumar K.Rf6f49a12012-11-27 11:46:50 -0800104 str += strlen(str) + 1;
105 if (str - udata >= len)
106 break;
107 }
108
Amara Venkata Mastan Manoj Kumar11a380d2013-01-17 09:30:56 -0800109 switch(connected) {
110 case EXTERNAL_OFFLINE:
111 { // disconnect event
112 ctx->mExtDisplay->processUEventOffline(udata);
113 if(ctx->mFBUpdate[dpy]) {
114 Locker::Autolock _l(ctx->mExtSetLock);
115 delete ctx->mFBUpdate[dpy];
116 ctx->mFBUpdate[dpy] = NULL;
117 }
118 if(ctx->mCopyBit[dpy]){
119 Locker::Autolock _l(ctx->mExtSetLock);
120 delete ctx->mCopyBit[dpy];
121 ctx->mCopyBit[dpy] = NULL;
122 }
123 ALOGD("%s sending hotplug: connected = %d and dpy:%d",
124 __FUNCTION__, connected, dpy);
125 ctx->dpyAttr[dpy].connected = false;
Saurabh Shahcf053c62012-12-13 12:32:55 -0800126 Locker::Autolock _l(ctx->mExtSetLock);
Amara Venkata Mastan Manoj Kumar11a380d2013-01-17 09:30:56 -0800127 //hwc comp could be on
128 ctx->proc->hotplug(ctx->proc, dpy, connected);
129 break;
Saurabh Shahcf053c62012-12-13 12:32:55 -0800130 }
Amara Venkata Mastan Manoj Kumar11a380d2013-01-17 09:30:56 -0800131 case EXTERNAL_ONLINE:
132 { // connect case
133 ctx->mExtDispConfiguring = true;
134 ctx->mExtDisplay->processUEventOnline(udata);
135 ctx->mFBUpdate[dpy] =
136 IFBUpdate::getObject(ctx->dpyAttr[dpy].xres, dpy);
137 ctx->dpyAttr[dpy].isPause = false;
138 if(usecopybit)
139 ctx->mCopyBit[dpy] = new CopyBit();
140 ALOGD("%s sending hotplug: connected = %d", __FUNCTION__,
141 connected);
142 ctx->dpyAttr[dpy].connected = true;
143 Locker::Autolock _l(ctx->mExtSetLock); //hwc comp could be on
144 ctx->proc->hotplug(ctx->proc, dpy, connected);
145 break;
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800146 }
Amara Venkata Mastan Manoj Kumar11a380d2013-01-17 09:30:56 -0800147 case EXTERNAL_PAUSE:
148 { // pause case
149 ALOGD("%s Received Pause event",__FUNCTION__);
150 ctx->dpyAttr[dpy].isActive = true;
151 ctx->dpyAttr[dpy].isPause = true;
152 break;
153 }
154 case EXTERNAL_RESUME:
155 { // resume case
156 ALOGD("%s Received resume event",__FUNCTION__);
157 ctx->dpyAttr[dpy].isActive = true;
158 ctx->dpyAttr[dpy].isPause = false;
159 break;
160 }
161 default:
162 {
163 ALOGE("ignore event and connected:%d",connected);
164 break;
165 }
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700166 }
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700167}
168
169static void *uevent_loop(void *param)
170{
171 int len = 0;
Naseer Ahmedff4f0252012-10-01 13:03:01 -0400172 static char udata[PAGE_SIZE];
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700173 hwc_context_t * ctx = reinterpret_cast<hwc_context_t *>(param);
Iliyan Malchev0f9c3972012-10-11 15:16:15 -0700174 char thread_name[64] = HWC_UEVENT_THREAD_NAME;
Naseer Ahmedff4f0252012-10-01 13:03:01 -0400175 prctl(PR_SET_NAME, (unsigned long) &thread_name, 0, 0, 0);
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700176 setpriority(PRIO_PROCESS, 0, HAL_PRIORITY_URGENT_DISPLAY);
177 uevent_init();
178
179 while(1) {
180 len = uevent_next_event(udata, sizeof(udata) - 2);
181 handle_uevent(ctx, udata, len);
182 }
183
184 return NULL;
185}
186
187void init_uevent_thread(hwc_context_t* ctx)
188{
189 pthread_t uevent_thread;
Iliyan Malchev0f9c3972012-10-11 15:16:15 -0700190 int ret;
191
192 ALOGI("Initializing UEVENT Thread");
193 ret = pthread_create(&uevent_thread, NULL, uevent_loop, (void*) ctx);
194 if (ret) {
195 ALOGE("%s: failed to create %s: %s", __FUNCTION__,
196 HWC_UEVENT_THREAD_NAME, strerror(ret));
197 }
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700198}
199
200}; //namespace