summaryrefslogtreecommitdiff
path: root/hwc2/common/devices/PrimaryDevice.cpp (plain)
blob: 797f9ff000872fba5a79b7fa6f73b2d180f75c2f
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 mSignalHpd = false;
53
54 UeventObserver *observer = Hwcomposer::getInstance().getUeventObserver();
55 if (observer) {
56 observer->registerListener(
57 Utils::getHotplugUeventEnvelope(),
58 hotplugEventListener,
59 this);
60 observer->registerListener(
61 Utils::getModeChangeUeventEnvelope(),
62 modeChangeEventListener,
63 this);
64 } else {
65 ETRACE("Uevent observer is NULL");
66 }
67
68 return true;
69}
70
71void PrimaryDevice::deinitialize()
72{
73 PhysicalDevice::deinitialize();
74}
75
76void PrimaryDevice::hotplugEventListener(void *data, bool status)
77{
78 PrimaryDevice *pThis = (PrimaryDevice*)data;
79 if (pThis) {
80 pThis->hotplugListener(0);
81 if (status) pThis->mSignalHpd = true;
82 }
83}
84
85void PrimaryDevice::modeChangeEventListener(void *data, bool status)
86{
87 PrimaryDevice *pThis = (PrimaryDevice*)data;
88 DTRACE("mode change event: %d", status);
89
90 if (status && pThis) {
91 pThis->changeModeDetectThread();
92 }
93}
94
95void PrimaryDevice::hotplugListener(bool connected)
96{
97 CTRACE();
98 ETRACE("hotpug event: %d", connected);
99
100 updateHotplugState(connected);
101
102 // update display configs
103 // onHotplug(getDisplayId(), connected);
104
105 // notify sf to refresh.
106 getDevice().refresh(getDisplayId());
107}
108
109int PrimaryDevice::parseConfigFile()
110{
111 const char* WHITESPACE = " \t\r";
112
113 SysTokenizer* tokenizer;
114 int status = SysTokenizer::open(pConfigPath, &tokenizer);
115 if (status) {
116 ETRACE("Error %d opening display config file %s.", status, pConfigPath);
117 } else {
118 while (!tokenizer->isEof()) {
119 ITRACE("Parsing %s: %s", tokenizer->getLocation(), tokenizer->peekRemainderOfLine());
120
121 tokenizer->skipDelimiters(WHITESPACE);
122 if (!tokenizer->isEol() && tokenizer->peekChar() != '#') {
123
124 char *token = tokenizer->nextToken(WHITESPACE);
125 if (!strcmp(token, DEVICE_STR_MBOX)) {
126 mDisplayType = DISPLAY_TYPE_MBOX;
127 } else if (!strcmp(token, DEVICE_STR_TV)) {
128 mDisplayType = DISPLAY_TYPE_TV;
129 } else {
130 DTRACE("%s: Expected keyword, got '%s'.", tokenizer->getLocation(), token);
131 break;
132 }
133 tokenizer->skipDelimiters(WHITESPACE);
134 tokenizer->nextToken(WHITESPACE);
135 tokenizer->skipDelimiters(WHITESPACE);
136 strcpy(mDefaultMode, tokenizer->nextToken(WHITESPACE));
137 }
138
139 tokenizer->nextLine();
140 }
141 delete tokenizer;
142 }
143 return status;
144}
145
146void PrimaryDevice::changeModeDetectThread()
147{
148 pthread_t id;
149 int ret = pthread_create(&id, NULL, changeModeDetect, this);
150 if (ret != 0)
151 ETRACE("Create changeModeDetect error!\n");
152}
153
154void* PrimaryDevice::changeModeDetect(void* data)
155{
156 PrimaryDevice *pThis = (PrimaryDevice*)data;
157 bool modeChanged = false;
158 char lastMode[32];
159 Utils::getSysfsStr(SYSFS_DISPLAY_MODE, lastMode);
160 do {
161 modeChanged = Utils::checkSysfsStatus(SYSFS_DISPLAY_MODE, lastMode, 32);
162 usleep(500 * 1000);
163 } while (!modeChanged);
164
165 if (pThis->mSignalHpd) {
166 pThis->setOsdMouse();
167 pThis->hotplugListener(1);
168 pThis->mSignalHpd = false;
169 }
170 return NULL;
171}
172
173} // namespace amlogic
174} // namespace android
175