blob: e7ab62936ccfad1b71120a5a33d87be18ad2cef3 [file] [log] [blame]
Naseer Ahmed72cf9762012-07-21 12:17:13 -07001/*
2 * Copyright (C) 2010 The Android Open Source Project
3 * Copyright (C) 2012, Code Aurora Forum. All rights reserved.
4 *
5 * Not a Contribution, Apache license notifications and license are
6 * retained for attribution purposes only.
7
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
11 *
12 * http://www.apache.org/licenses/LICENSE-2.0
13 *
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 */
20#define DEBUG 0
21#ifndef HWC_OBSERVER_H
22#define HWC_OBSERVER_H
23#include <hardware_legacy/uevent.h>
24#include <utils/Log.h>
25#include <sys/resource.h>
26#include <string.h>
27#include <stdlib.h>
28#include "hwc_utils.h"
29#include "hwc_external.h"
30
31namespace qhwc {
32
Naseer Ahmedf8ec1622012-07-31 18:56:23 -070033const char* MSMFB_DEVICE_FB0 = "change@/devices/virtual/graphics/fb0";
34const char* MSMFB_DEVICE_FB1 = "change@/devices/virtual/graphics/fb1";
Naseer Ahmed72cf9762012-07-21 12:17:13 -070035const char* MSMFB_HDMI_NODE = "fb1";
36
37static void handle_uevent(hwc_context_t* ctx, const char* udata, int len)
38{
Naseer Ahmedf8ec1622012-07-31 18:56:23 -070039 int vsync = 0;
Naseer Ahmed72cf9762012-07-21 12:17:13 -070040 char* hdmi;
41 int64_t timestamp = 0;
42 const char *str = udata;
Naseer Ahmedf8ec1622012-07-31 18:56:23 -070043 hwc_procs* proc = (hwc_procs*)ctx->device.reserved_proc[0];
44 int hdmiconnected = ctx->mExtDisplay->getExternalDisplay();
Naseer Ahmed72cf9762012-07-21 12:17:13 -070045
Naseer Ahmedf8ec1622012-07-31 18:56:23 -070046 if(!strcasestr(str, "@/devices/virtual/graphics/fb")) {
47 ALOGD_IF(DEBUG, "%s: Not Ext Disp Event ", __FUNCTION__);
Naseer Ahmed72cf9762012-07-21 12:17:13 -070048 return;
Naseer Ahmedf8ec1622012-07-31 18:56:23 -070049 }
50
51 if(hdmiconnected)
52 vsync = !strncmp(str, MSMFB_DEVICE_FB1, strlen(MSMFB_DEVICE_FB1));
53 else
54 vsync = !strncmp(str, MSMFB_DEVICE_FB0, strlen(MSMFB_DEVICE_FB0));
55
56 hdmi = strcasestr(str, MSMFB_HDMI_NODE);
Naseer Ahmed72cf9762012-07-21 12:17:13 -070057 if(vsync) {
58 str += strlen(str) + 1;
59 while(*str) {
60 if (!strncmp(str, "VSYNC=", strlen("VSYNC="))) {
61 timestamp = strtoull(str + strlen("VSYNC="), NULL, 0);
Naseer Ahmed5b6708a2012-08-02 13:46:08 -070062 //XXX: Handle vsync from multiple displays
63 proc->vsync(proc, (int)ctx->dpys[0], timestamp);
Naseer Ahmed72cf9762012-07-21 12:17:13 -070064 }
65 str += strlen(str) + 1;
66 if(str - udata >= len)
67 break;
68 }
Naseer Ahmedf8ec1622012-07-31 18:56:23 -070069 return;
Naseer Ahmed72cf9762012-07-21 12:17:13 -070070 }
71
72 if(hdmi) {
73 // parse HDMI events
74 // The event will be of the form:
75 // change@/devices/virtual/graphics/fb1 ACTION=change
76 // DEVPATH=/devices/virtual/graphics/fb1
77 // SUBSYSTEM=graphics HDCP_STATE=FAIL MAJOR=29
78 // for now just parsing onlin/offline info is enough
79 str = udata;
80 int connected = 0;
81 if(!(strncmp(str,"online@",strlen("online@")))) {
82 connected = 1;
Naseer Ahmed31278ad2012-07-31 19:14:54 -070083 ctx->mExtDisplay->setExternalDisplay(connected);
Naseer Ahmed72cf9762012-07-21 12:17:13 -070084 } else if(!(strncmp(str,"offline@",strlen("offline@")))) {
85 connected = 0;
Naseer Ahmed31278ad2012-07-31 19:14:54 -070086 ctx->mExtDisplay->setExternalDisplay(connected);
Naseer Ahmed72cf9762012-07-21 12:17:13 -070087 }
Naseer Ahmed72cf9762012-07-21 12:17:13 -070088 }
89
90}
91
92static void *uevent_loop(void *param)
93{
94 int len = 0;
95 static char udata[4096];
96 memset(udata, 0, sizeof(udata));
97 hwc_context_t * ctx = reinterpret_cast<hwc_context_t *>(param);
98
99 setpriority(PRIO_PROCESS, 0, HAL_PRIORITY_URGENT_DISPLAY);
100 uevent_init();
101
102 while(1) {
103 len = uevent_next_event(udata, sizeof(udata) - 2);
104 handle_uevent(ctx, udata, len);
105 }
106
107 return NULL;
108}
109
110void init_uevent_thread(hwc_context_t* ctx)
111{
112 pthread_t uevent_thread;
113 pthread_create(&uevent_thread, NULL, uevent_loop, (void*) ctx);
114}
115
116}; //namespace
117#endif //HWC_OBSERVER_H