summaryrefslogtreecommitdiff
path: root/hwc2/common/devices/PrimaryDevice.cpp (plain)
blob: 88ac1cbea4fbde6662d643103789e3d5997de60c
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 = Utils::getSysfsInt(DISPLAY_HPD_STATE, 1) == 1 ? true : 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 DTRACE("HDMI Plug State[%s]", status == true ? "Plug" : "UnPlug");
79 PrimaryDevice *pThis = (PrimaryDevice*)data;
80 if (pThis) {
81 pThis->mSignalHpd = status;
82 }
83}
84
85void PrimaryDevice::modeChangeEventListener(void *data, bool status)
86{
87 PrimaryDevice *pThis = (PrimaryDevice*)data;
88 DTRACE("mode state: [%s] display mode.", status == true ? "Begin to change" : "Complete");
89
90 if (!status && pThis) {
91 pThis->setOsdMouse();
92 pThis->hotplugListener(pThis->mSignalHpd);
93 }
94}
95
96void PrimaryDevice::hotplugListener(bool connected)
97{
98 CTRACE();
99 ETRACE("hotpug event: %d", connected);
100
101 updateHotplugState(connected);
102
103 // update display configs
104 // onHotplug(getDisplayId(), connected);
105
106 // notify sf to refresh.
107 getDevice().refresh(getDisplayId());
108}
109
110int PrimaryDevice::parseConfigFile()
111{
112 const char* WHITESPACE = " \t\r";
113
114 SysTokenizer* tokenizer;
115 int status = SysTokenizer::open(pConfigPath, &tokenizer);
116 if (status) {
117 ETRACE("Error %d opening display config file %s.", status, pConfigPath);
118 } else {
119 while (!tokenizer->isEof()) {
120 ITRACE("Parsing %s: %s", tokenizer->getLocation(), tokenizer->peekRemainderOfLine());
121
122 tokenizer->skipDelimiters(WHITESPACE);
123 if (!tokenizer->isEol() && tokenizer->peekChar() != '#') {
124
125 char *token = tokenizer->nextToken(WHITESPACE);
126 if (!strcmp(token, DEVICE_STR_MBOX)) {
127 mDisplayType = DISPLAY_TYPE_MBOX;
128 } else if (!strcmp(token, DEVICE_STR_TV)) {
129 mDisplayType = DISPLAY_TYPE_TV;
130 } else {
131 DTRACE("%s: Expected keyword, got '%s'.", tokenizer->getLocation(), token);
132 break;
133 }
134 tokenizer->skipDelimiters(WHITESPACE);
135 tokenizer->nextToken(WHITESPACE);
136 tokenizer->skipDelimiters(WHITESPACE);
137 strcpy(mDefaultMode, tokenizer->nextToken(WHITESPACE));
138 }
139
140 tokenizer->nextLine();
141 }
142 delete tokenizer;
143 }
144 return status;
145}
146
147} // namespace amlogic
148} // namespace android
149