blob: d27128eb8f3757fbf362573f023d3a3edca9b064 [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"
Saurabh Shahacf10202013-02-26 10:15:15 -080030#include "hwc_video.h"
Arun Kumar K.R361da4f2012-11-28 10:42:59 -080031#include "hwc_copybit.h"
32#include "comptype.h"
Saurabh Shah56f610d2012-08-07 15:27:06 -070033#include "external.h"
Naseer Ahmed72cf9762012-07-21 12:17:13 -070034
35namespace qhwc {
36
Iliyan Malchev0f9c3972012-10-11 15:16:15 -070037#define HWC_UEVENT_THREAD_NAME "hwcUeventThread"
38
Amara Venkata Mastan Manoj Kumar11a380d2013-01-17 09:30:56 -080039/* External Display states */
40enum {
41 EXTERNAL_OFFLINE = 0,
42 EXTERNAL_ONLINE,
43 EXTERNAL_PAUSE,
44 EXTERNAL_RESUME
45};
46
47static bool isHDMI(const char* str)
48{
49 if(strcasestr("change@/devices/virtual/switch/hdmi", str))
50 return true;
51 return false;
52}
53
Naseer Ahmed72cf9762012-07-21 12:17:13 -070054static void handle_uevent(hwc_context_t* ctx, const char* udata, int len)
55{
Naseer Ahmedf8ec1622012-07-31 18:56:23 -070056 int vsync = 0;
Naseer Ahmed72cf9762012-07-21 12:17:13 -070057 int64_t timestamp = 0;
58 const char *str = udata;
Arun Kumar K.R361da4f2012-11-28 10:42:59 -080059 bool usecopybit = false;
60 int compositionType =
61 qdutils::QCCompositionType::getInstance().getCompositionType();
62
63 if (compositionType & (qdutils::COMPOSITION_TYPE_DYN |
64 qdutils::COMPOSITION_TYPE_MDP |
65 qdutils::COMPOSITION_TYPE_C2D)) {
66 usecopybit = true;
Arun Kumar K.R361da4f2012-11-28 10:42:59 -080067 }
Naseer Ahmed72cf9762012-07-21 12:17:13 -070068
Amara Venkata Mastan Manoj Kumare37e5712012-12-17 17:36:02 -080069 if(!strcasestr("change@/devices/virtual/switch/hdmi", str) &&
70 !strcasestr("change@/devices/virtual/switch/wfd", str)) {
Saurabh Shah649cda62012-09-16 16:05:58 -070071 ALOGD_IF(UEVENT_DEBUG, "%s: Not Ext Disp Event ", __FUNCTION__);
Naseer Ahmed72cf9762012-07-21 12:17:13 -070072 return;
Naseer Ahmedf8ec1622012-07-31 18:56:23 -070073 }
Arun Kumar K.Rf6f49a12012-11-27 11:46:50 -080074 int connected = -1; // initial value - will be set to 1/0 based on hotplug
Amara Venkata Mastan Manoj Kumar11a380d2013-01-17 09:30:56 -080075 int extDpyNum = HWC_DISPLAY_EXTERNAL;
76 char property[PROPERTY_VALUE_MAX];
77 if((property_get("persist.sys.wfd.virtual", property, NULL) > 0) &&
78 (!strncmp(property, "1", PROPERTY_VALUE_MAX ) ||
79 (!strncasecmp(property,"true", PROPERTY_VALUE_MAX )))) {
80 // This means we are using Google API to trigger WFD Display
81 extDpyNum = HWC_DISPLAY_VIRTUAL;
82
83 }
84
85 int dpy = isHDMI(str) ? HWC_DISPLAY_EXTERNAL : extDpyNum;
86
87 // update extDpyNum
88 ctx->mExtDisplay->setExtDpyNum(dpy);
89
Amara Venkata Mastan Manoj Kumar5182a782012-12-03 12:08:48 -080090 // parse HDMI/WFD switch state for connect/disconnect
91 // for HDMI:
Naseer Ahmedff4f0252012-10-01 13:03:01 -040092 // The event will be of the form:
Arun Kumar K.Rf6f49a12012-11-27 11:46:50 -080093 // change@/devices/virtual/switch/hdmi ACTION=change
94 // SWITCH_STATE=1 or SWITCH_STATE=0
95 while(*str) {
96 if (!strncmp(str, "SWITCH_STATE=", strlen("SWITCH_STATE="))) {
97 connected = atoi(str + strlen("SWITCH_STATE="));
Saurabh Shah1a8cda02012-10-12 17:00:39 -070098 //Disabled until SF calls unblank
99 ctx->dpyAttr[HWC_DISPLAY_EXTERNAL].isActive = false;
Amara Venkata Mastan Manoj Kumar11a380d2013-01-17 09:30:56 -0800100 //Ignored for Virtual Displays
101 //ToDo: we can do this in a much better way
102 ctx->dpyAttr[HWC_DISPLAY_VIRTUAL].isActive = true;
Arun Kumar K.Rf6f49a12012-11-27 11:46:50 -0800103 break;
Saurabh Shah1a8cda02012-10-12 17:00:39 -0700104 }
Arun Kumar K.Rf6f49a12012-11-27 11:46:50 -0800105 str += strlen(str) + 1;
106 if (str - udata >= len)
107 break;
108 }
109
Amara Venkata Mastan Manoj Kumar11a380d2013-01-17 09:30:56 -0800110 switch(connected) {
111 case EXTERNAL_OFFLINE:
112 { // disconnect event
113 ctx->mExtDisplay->processUEventOffline(udata);
114 if(ctx->mFBUpdate[dpy]) {
115 Locker::Autolock _l(ctx->mExtSetLock);
116 delete ctx->mFBUpdate[dpy];
117 ctx->mFBUpdate[dpy] = NULL;
118 }
Saurabh Shahacf10202013-02-26 10:15:15 -0800119 if(ctx->mVidOv[dpy]) {
120 Locker::Autolock _l(ctx->mExtSetLock);
121 delete ctx->mVidOv[dpy];
122 ctx->mVidOv[dpy] = NULL;
123 }
Amara Venkata Mastan Manoj Kumar11a380d2013-01-17 09:30:56 -0800124 if(ctx->mCopyBit[dpy]){
125 Locker::Autolock _l(ctx->mExtSetLock);
126 delete ctx->mCopyBit[dpy];
127 ctx->mCopyBit[dpy] = NULL;
128 }
129 ALOGD("%s sending hotplug: connected = %d and dpy:%d",
130 __FUNCTION__, connected, dpy);
131 ctx->dpyAttr[dpy].connected = false;
Saurabh Shahcf053c62012-12-13 12:32:55 -0800132 Locker::Autolock _l(ctx->mExtSetLock);
Amara Venkata Mastan Manoj Kumar11a380d2013-01-17 09:30:56 -0800133 //hwc comp could be on
134 ctx->proc->hotplug(ctx->proc, dpy, connected);
135 break;
Saurabh Shahcf053c62012-12-13 12:32:55 -0800136 }
Amara Venkata Mastan Manoj Kumar11a380d2013-01-17 09:30:56 -0800137 case EXTERNAL_ONLINE:
138 { // connect case
139 ctx->mExtDispConfiguring = true;
140 ctx->mExtDisplay->processUEventOnline(udata);
141 ctx->mFBUpdate[dpy] =
142 IFBUpdate::getObject(ctx->dpyAttr[dpy].xres, dpy);
Saurabh Shahacf10202013-02-26 10:15:15 -0800143 ctx->mVidOv[dpy] =
144 IVideoOverlay::getObject(ctx->dpyAttr[dpy].xres, dpy);
Amara Venkata Mastan Manoj Kumar11a380d2013-01-17 09:30:56 -0800145 ctx->dpyAttr[dpy].isPause = false;
146 if(usecopybit)
147 ctx->mCopyBit[dpy] = new CopyBit();
148 ALOGD("%s sending hotplug: connected = %d", __FUNCTION__,
149 connected);
150 ctx->dpyAttr[dpy].connected = true;
151 Locker::Autolock _l(ctx->mExtSetLock); //hwc comp could be on
152 ctx->proc->hotplug(ctx->proc, dpy, connected);
153 break;
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800154 }
Amara Venkata Mastan Manoj Kumar11a380d2013-01-17 09:30:56 -0800155 case EXTERNAL_PAUSE:
156 { // pause case
157 ALOGD("%s Received Pause event",__FUNCTION__);
158 ctx->dpyAttr[dpy].isActive = true;
159 ctx->dpyAttr[dpy].isPause = true;
160 break;
161 }
162 case EXTERNAL_RESUME:
163 { // resume case
164 ALOGD("%s Received resume event",__FUNCTION__);
165 ctx->dpyAttr[dpy].isActive = true;
166 ctx->dpyAttr[dpy].isPause = false;
167 break;
168 }
169 default:
170 {
171 ALOGE("ignore event and connected:%d",connected);
172 break;
173 }
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700174 }
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700175}
176
177static void *uevent_loop(void *param)
178{
179 int len = 0;
Naseer Ahmedff4f0252012-10-01 13:03:01 -0400180 static char udata[PAGE_SIZE];
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700181 hwc_context_t * ctx = reinterpret_cast<hwc_context_t *>(param);
Iliyan Malchev0f9c3972012-10-11 15:16:15 -0700182 char thread_name[64] = HWC_UEVENT_THREAD_NAME;
Naseer Ahmedff4f0252012-10-01 13:03:01 -0400183 prctl(PR_SET_NAME, (unsigned long) &thread_name, 0, 0, 0);
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700184 setpriority(PRIO_PROCESS, 0, HAL_PRIORITY_URGENT_DISPLAY);
185 uevent_init();
186
187 while(1) {
188 len = uevent_next_event(udata, sizeof(udata) - 2);
189 handle_uevent(ctx, udata, len);
190 }
191
192 return NULL;
193}
194
195void init_uevent_thread(hwc_context_t* ctx)
196{
197 pthread_t uevent_thread;
Iliyan Malchev0f9c3972012-10-11 15:16:15 -0700198 int ret;
199
200 ALOGI("Initializing UEVENT Thread");
201 ret = pthread_create(&uevent_thread, NULL, uevent_loop, (void*) ctx);
202 if (ret) {
203 ALOGE("%s: failed to create %s: %s", __FUNCTION__,
204 HWC_UEVENT_THREAD_NAME, strerror(ret));
205 }
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700206}
207
208}; //namespace