Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 1 | /* |
| 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 | |
| 31 | namespace qhwc { |
| 32 | |
Naseer Ahmed | f8ec162 | 2012-07-31 18:56:23 -0700 | [diff] [blame] | 33 | const char* MSMFB_DEVICE_FB0 = "change@/devices/virtual/graphics/fb0"; |
| 34 | const char* MSMFB_DEVICE_FB1 = "change@/devices/virtual/graphics/fb1"; |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 35 | const char* MSMFB_HDMI_NODE = "fb1"; |
| 36 | |
| 37 | static void handle_uevent(hwc_context_t* ctx, const char* udata, int len) |
| 38 | { |
Naseer Ahmed | f8ec162 | 2012-07-31 18:56:23 -0700 | [diff] [blame] | 39 | int vsync = 0; |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 40 | char* hdmi; |
| 41 | int64_t timestamp = 0; |
| 42 | const char *str = udata; |
Naseer Ahmed | f8ec162 | 2012-07-31 18:56:23 -0700 | [diff] [blame] | 43 | int hdmiconnected = ctx->mExtDisplay->getExternalDisplay(); |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 44 | |
Naseer Ahmed | f8ec162 | 2012-07-31 18:56:23 -0700 | [diff] [blame] | 45 | if(!strcasestr(str, "@/devices/virtual/graphics/fb")) { |
| 46 | ALOGD_IF(DEBUG, "%s: Not Ext Disp Event ", __FUNCTION__); |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 47 | return; |
Naseer Ahmed | f8ec162 | 2012-07-31 18:56:23 -0700 | [diff] [blame] | 48 | } |
| 49 | |
| 50 | if(hdmiconnected) |
| 51 | vsync = !strncmp(str, MSMFB_DEVICE_FB1, strlen(MSMFB_DEVICE_FB1)); |
| 52 | else |
| 53 | vsync = !strncmp(str, MSMFB_DEVICE_FB0, strlen(MSMFB_DEVICE_FB0)); |
| 54 | |
| 55 | hdmi = strcasestr(str, MSMFB_HDMI_NODE); |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 56 | if(vsync) { |
| 57 | str += strlen(str) + 1; |
| 58 | while(*str) { |
| 59 | if (!strncmp(str, "VSYNC=", strlen("VSYNC="))) { |
| 60 | timestamp = strtoull(str + strlen("VSYNC="), NULL, 0); |
Naseer Ahmed | 5b6708a | 2012-08-02 13:46:08 -0700 | [diff] [blame] | 61 | //XXX: Handle vsync from multiple displays |
Jesse Hall | 3be78d9 | 2012-08-21 15:12:23 -0700 | [diff] [blame] | 62 | ctx->proc->vsync(ctx->proc, (int)ctx->dpys[0], timestamp); |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 63 | } |
| 64 | str += strlen(str) + 1; |
| 65 | if(str - udata >= len) |
| 66 | break; |
| 67 | } |
Naseer Ahmed | f8ec162 | 2012-07-31 18:56:23 -0700 | [diff] [blame] | 68 | return; |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 69 | } |
| 70 | |
| 71 | if(hdmi) { |
| 72 | // parse HDMI events |
| 73 | // The event will be of the form: |
| 74 | // change@/devices/virtual/graphics/fb1 ACTION=change |
| 75 | // DEVPATH=/devices/virtual/graphics/fb1 |
| 76 | // SUBSYSTEM=graphics HDCP_STATE=FAIL MAJOR=29 |
| 77 | // for now just parsing onlin/offline info is enough |
| 78 | str = udata; |
| 79 | int connected = 0; |
| 80 | if(!(strncmp(str,"online@",strlen("online@")))) { |
| 81 | connected = 1; |
Naseer Ahmed | 31278ad | 2012-07-31 19:14:54 -0700 | [diff] [blame] | 82 | ctx->mExtDisplay->setExternalDisplay(connected); |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 83 | } else if(!(strncmp(str,"offline@",strlen("offline@")))) { |
| 84 | connected = 0; |
Naseer Ahmed | 31278ad | 2012-07-31 19:14:54 -0700 | [diff] [blame] | 85 | ctx->mExtDisplay->setExternalDisplay(connected); |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 86 | } |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 87 | } |
| 88 | |
| 89 | } |
| 90 | |
| 91 | static void *uevent_loop(void *param) |
| 92 | { |
| 93 | int len = 0; |
| 94 | static char udata[4096]; |
| 95 | memset(udata, 0, sizeof(udata)); |
| 96 | hwc_context_t * ctx = reinterpret_cast<hwc_context_t *>(param); |
| 97 | |
| 98 | setpriority(PRIO_PROCESS, 0, HAL_PRIORITY_URGENT_DISPLAY); |
| 99 | uevent_init(); |
| 100 | |
| 101 | while(1) { |
| 102 | len = uevent_next_event(udata, sizeof(udata) - 2); |
| 103 | handle_uevent(ctx, udata, len); |
| 104 | } |
| 105 | |
| 106 | return NULL; |
| 107 | } |
| 108 | |
| 109 | void init_uevent_thread(hwc_context_t* ctx) |
| 110 | { |
| 111 | pthread_t uevent_thread; |
| 112 | pthread_create(&uevent_thread, NULL, uevent_loop, (void*) ctx); |
| 113 | } |
| 114 | |
| 115 | }; //namespace |
| 116 | #endif //HWC_OBSERVER_H |