blob: 6b8f4e36e386dc34d0eafbaea6f6d551e1e22cc6 [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
Naseer Ahmed72cf9762012-07-21 12:17:13 -070038static void handle_uevent(hwc_context_t* ctx, const char* udata, int len)
39{
Naseer Ahmedf8ec1622012-07-31 18:56:23 -070040 int vsync = 0;
Naseer Ahmed72cf9762012-07-21 12:17:13 -070041 int64_t timestamp = 0;
42 const char *str = udata;
Arun Kumar K.R361da4f2012-11-28 10:42:59 -080043 bool usecopybit = false;
44 int compositionType =
45 qdutils::QCCompositionType::getInstance().getCompositionType();
46
47 if (compositionType & (qdutils::COMPOSITION_TYPE_DYN |
48 qdutils::COMPOSITION_TYPE_MDP |
49 qdutils::COMPOSITION_TYPE_C2D)) {
50 usecopybit = true;
51
52 }
Naseer Ahmed72cf9762012-07-21 12:17:13 -070053
Amara Venkata Mastan Manoj Kumare37e5712012-12-17 17:36:02 -080054 if(!strcasestr("change@/devices/virtual/switch/hdmi", str) &&
55 !strcasestr("change@/devices/virtual/switch/wfd", str)) {
Saurabh Shah649cda62012-09-16 16:05:58 -070056 ALOGD_IF(UEVENT_DEBUG, "%s: Not Ext Disp Event ", __FUNCTION__);
Naseer Ahmed72cf9762012-07-21 12:17:13 -070057 return;
Naseer Ahmedf8ec1622012-07-31 18:56:23 -070058 }
Amara Venkata Mastan Manoj Kumar5182a782012-12-03 12:08:48 -080059
Arun Kumar K.Rf6f49a12012-11-27 11:46:50 -080060 int connected = -1; // initial value - will be set to 1/0 based on hotplug
Amara Venkata Mastan Manoj Kumar5182a782012-12-03 12:08:48 -080061 // parse HDMI/WFD switch state for connect/disconnect
62 // for HDMI:
Naseer Ahmedff4f0252012-10-01 13:03:01 -040063 // The event will be of the form:
Arun Kumar K.Rf6f49a12012-11-27 11:46:50 -080064 // change@/devices/virtual/switch/hdmi ACTION=change
65 // SWITCH_STATE=1 or SWITCH_STATE=0
Amara Venkata Mastan Manoj Kumar5182a782012-12-03 12:08:48 -080066
Arun Kumar K.Rf6f49a12012-11-27 11:46:50 -080067 while(*str) {
68 if (!strncmp(str, "SWITCH_STATE=", strlen("SWITCH_STATE="))) {
69 connected = atoi(str + strlen("SWITCH_STATE="));
Saurabh Shah1a8cda02012-10-12 17:00:39 -070070 //Disabled until SF calls unblank
71 ctx->dpyAttr[HWC_DISPLAY_EXTERNAL].isActive = false;
Arun Kumar K.Rf6f49a12012-11-27 11:46:50 -080072 break;
Saurabh Shah1a8cda02012-10-12 17:00:39 -070073 }
Arun Kumar K.Rf6f49a12012-11-27 11:46:50 -080074 str += strlen(str) + 1;
75 if (str - udata >= len)
76 break;
77 }
78
79 if(connected != -1) { //either we got switch_state connected or disconnect
80 ctx->dpyAttr[HWC_DISPLAY_EXTERNAL].connected = connected;
Saurabh Shahcf053c62012-12-13 12:32:55 -080081 if (connected) {
Amara Venkata Mastan Manoj Kumar75526f52012-12-27 18:27:01 -080082 ctx->mExtDispConfiguring = true;
Amara Venkata Mastan Manoj Kumar5182a782012-12-03 12:08:48 -080083 ctx->mExtDisplay->processUEventOnline(udata);
Saurabh Shahcf053c62012-12-13 12:32:55 -080084 ctx->mFBUpdate[HWC_DISPLAY_EXTERNAL] =
85 IFBUpdate::getObject(ctx->dpyAttr[HWC_DISPLAY_EXTERNAL].xres,
86 HWC_DISPLAY_EXTERNAL);
Arun Kumar K.R361da4f2012-11-28 10:42:59 -080087 if(usecopybit)
88 ctx->mCopyBit[HWC_DISPLAY_EXTERNAL] = new CopyBit();
Saurabh Shahcf053c62012-12-13 12:32:55 -080089 } else {
Amara Venkata Mastan Manoj Kumar5182a782012-12-03 12:08:48 -080090 ctx->mExtDisplay->processUEventOffline(udata);
Saurabh Shahcf053c62012-12-13 12:32:55 -080091 if(ctx->mFBUpdate[HWC_DISPLAY_EXTERNAL]) {
92 Locker::Autolock _l(ctx->mExtSetLock);
93 delete ctx->mFBUpdate[HWC_DISPLAY_EXTERNAL];
94 ctx->mFBUpdate[HWC_DISPLAY_EXTERNAL] = NULL;
95 }
Arun Kumar K.R361da4f2012-11-28 10:42:59 -080096 if(ctx->mCopyBit[HWC_DISPLAY_EXTERNAL]){
97 Locker::Autolock _l(ctx->mExtSetLock);
98 delete ctx->mCopyBit[HWC_DISPLAY_EXTERNAL];
99 ctx->mCopyBit[HWC_DISPLAY_EXTERNAL] = NULL;
100 }
Amara Venkata Mastan Manoj Kumar5182a782012-12-03 12:08:48 -0800101 }
102 ALOGD("%s sending hotplug: connected = %d", __FUNCTION__, connected);
Arun Kumar K.Rf6f49a12012-11-27 11:46:50 -0800103 Locker::Autolock _l(ctx->mExtSetLock); //hwc comp could be on
104 ctx->proc->hotplug(ctx->proc, HWC_DISPLAY_EXTERNAL, connected);
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700105 }
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700106}
107
108static void *uevent_loop(void *param)
109{
110 int len = 0;
Naseer Ahmedff4f0252012-10-01 13:03:01 -0400111 static char udata[PAGE_SIZE];
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700112 hwc_context_t * ctx = reinterpret_cast<hwc_context_t *>(param);
Iliyan Malchev0f9c3972012-10-11 15:16:15 -0700113 char thread_name[64] = HWC_UEVENT_THREAD_NAME;
Naseer Ahmedff4f0252012-10-01 13:03:01 -0400114 prctl(PR_SET_NAME, (unsigned long) &thread_name, 0, 0, 0);
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700115 setpriority(PRIO_PROCESS, 0, HAL_PRIORITY_URGENT_DISPLAY);
116 uevent_init();
117
118 while(1) {
119 len = uevent_next_event(udata, sizeof(udata) - 2);
120 handle_uevent(ctx, udata, len);
121 }
122
123 return NULL;
124}
125
126void init_uevent_thread(hwc_context_t* ctx)
127{
128 pthread_t uevent_thread;
Iliyan Malchev0f9c3972012-10-11 15:16:15 -0700129 int ret;
130
131 ALOGI("Initializing UEVENT Thread");
132 ret = pthread_create(&uevent_thread, NULL, uevent_loop, (void*) ctx);
133 if (ret) {
134 ALOGE("%s: failed to create %s: %s", __FUNCTION__,
135 HWC_UEVENT_THREAD_NAME, strerror(ret));
136 }
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700137}
138
139}; //namespace