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