summaryrefslogtreecommitdiff
path: root/hwc2/common/devices/PrimaryDevice.cpp (plain)
blob: 377db74915bd49d9b0124a7bff827ce74f5ff2c1
1/*
2// Copyright (c) 2014 Intel Corporation
3//
4// Licensed under the Apache License, Version 2.0 (the "License");
5// you may not use this file except in compliance with the License.
6// You may obtain a copy of the License at
7//
8// http://www.apache.org/licenses/LICENSE-2.0
9//
10// Unless required by applicable law or agreed to in writing, software
11// distributed under the License is distributed on an "AS IS" BASIS,
12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13// See the License for the specific language governing permissions and
14// limitations under the License.
15//
16// This file is modified by Amlogic, Inc. 2017.01.17.
17*/
18
19#include <HwcTrace.h>
20#include <Hwcomposer.h>
21#include <PrimaryDevice.h>
22#include <Utils.h>
23#include <SysTokenizer.h>
24
25namespace android {
26namespace amlogic {
27
28PrimaryDevice::PrimaryDevice(Hwcomposer& hwc, IComposeDeviceFactory * controlFactory)
29 : PhysicalDevice(DEVICE_PRIMARY, hwc, controlFactory),
30 pConfigPath(DISPLAY_CFG_FILE),
31 mDisplayType(DISPLAY_TYPE_MBOX)
32{
33 DTRACE("display mode config path: %s", pConfigPath);
34
35 CTRACE();
36}
37
38PrimaryDevice::~PrimaryDevice()
39{
40 CTRACE();
41}
42
43bool PrimaryDevice::initialize()
44{
45 parseConfigFile();
46 updateDisplayInfo(mDefaultMode);
47
48 if (!PhysicalDevice::initialize()) {
49 DEINIT_AND_RETURN_FALSE("failed to initialize physical device");
50 }
51
52 UeventObserver *observer = Hwcomposer::getInstance().getUeventObserver();
53 if (observer) {
54 observer->registerListener(
55 Utils::getHotplugUeventEnvelope(),
56 hotplugEventListener,
57 this);
58 observer->registerListener(
59 Utils::getModeChangeUeventEnvelope(),
60 modeChangeEventListener,
61 this);
62 } else {
63 ETRACE("Uevent observer is NULL");
64 }
65
66 return true;
67}
68
69void PrimaryDevice::deinitialize()
70{
71 PhysicalDevice::deinitialize();
72}
73
74void PrimaryDevice::hotplugEventListener(void *data, bool status)
75{
76 PrimaryDevice *pThis = (PrimaryDevice*)data;
77 if (pThis) {
78 pThis->hotplugListener(status);
79 }
80}
81
82void PrimaryDevice::modeChangeEventListener(void *data, bool status)
83{
84 PrimaryDevice *pThis = (PrimaryDevice*)data;
85 DTRACE("mode change event: %d", status);
86 if (status && pThis) {
87 pThis->changeModeDetectThread();
88 }
89}
90
91void PrimaryDevice::hotplugListener(bool connected)
92{
93 CTRACE();
94 ETRACE("hotpug event: %d", connected);
95
96 updateHotplugState(connected);
97
98 // update display configs
99 onHotplug(getDisplayId(), connected);
100}
101
102int PrimaryDevice::parseConfigFile()
103{
104 const char* WHITESPACE = " \t\r";
105
106 SysTokenizer* tokenizer;
107 int status = SysTokenizer::open(pConfigPath, &tokenizer);
108 if (status) {
109 ETRACE("Error %d opening display config file %s.", status, pConfigPath);
110 } else {
111 while (!tokenizer->isEof()) {
112 ITRACE("Parsing %s: %s", tokenizer->getLocation(), tokenizer->peekRemainderOfLine());
113
114 tokenizer->skipDelimiters(WHITESPACE);
115 if (!tokenizer->isEol() && tokenizer->peekChar() != '#') {
116
117 char *token = tokenizer->nextToken(WHITESPACE);
118 if (!strcmp(token, DEVICE_STR_MBOX)) {
119 mDisplayType = DISPLAY_TYPE_MBOX;
120 } else if (!strcmp(token, DEVICE_STR_TV)) {
121 mDisplayType = DISPLAY_TYPE_TV;
122 } else {
123 DTRACE("%s: Expected keyword, got '%s'.", tokenizer->getLocation(), token);
124 break;
125 }
126 tokenizer->skipDelimiters(WHITESPACE);
127 tokenizer->nextToken(WHITESPACE);
128 tokenizer->skipDelimiters(WHITESPACE);
129 strcpy(mDefaultMode, tokenizer->nextToken(WHITESPACE));
130 }
131
132 tokenizer->nextLine();
133 }
134 delete tokenizer;
135 }
136 return status;
137}
138
139void PrimaryDevice::changeModeDetectThread()
140{
141 pthread_t id;
142 int ret = pthread_create(&id, NULL, changeModeDetect, this);
143 if (ret != 0)
144 ETRACE("Create changeModeDetect error!\n");
145}
146
147void* PrimaryDevice::changeModeDetect(void* data)
148{
149 PrimaryDevice *pThis = (PrimaryDevice*)data;
150 bool modeChanged = false;
151 char lastMode[32];
152 Utils::getSysfsStr(SYSFS_DISPLAY_MODE, lastMode);
153 do {
154 modeChanged = Utils::checkSysfsStatus(SYSFS_DISPLAY_MODE, lastMode, 32);
155 usleep(1000 * 1000);
156 } while (!modeChanged);
157 pThis->setOsdMouse();
158 return NULL;
159}
160
161} // namespace amlogic
162} // namespace android
163