summaryrefslogtreecommitdiff
path: root/hwc2/common/devices/PrimaryDevice.cpp (plain)
blob: da28b8e1780dfc28722b8d0753c63e2323c9bcc3
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
25
26namespace android {
27namespace amlogic {
28
29PrimaryDevice::PrimaryDevice(Hwcomposer& hwc, IComposeDeviceFactory * controlFactory)
30 : PhysicalDevice(DEVICE_PRIMARY, hwc, controlFactory),
31 pConfigPath(DISPLAY_CFG_FILE),
32 mDisplayType(DISPLAY_TYPE_MBOX)
33{
34 DTRACE("display mode config path: %s", pConfigPath);
35
36 CTRACE();
37}
38
39PrimaryDevice::~PrimaryDevice()
40{
41 CTRACE();
42}
43
44bool PrimaryDevice::initialize()
45{
46 parseConfigFile();
47 updateDisplayInfo(mDefaultMode);
48
49 if (!PhysicalDevice::initialize()) {
50 DEINIT_AND_RETURN_FALSE("failed to initialize physical device");
51 }
52
53 UeventObserver *observer = Hwcomposer::getInstance().getUeventObserver();
54 if (observer) {
55 observer->registerListener(
56 Utils::getHotplugUeventEnvelope(),
57 hotplugEventListener,
58 this);
59 } else {
60 ETRACE("Uevent observer is NULL");
61 }
62
63 return true;
64}
65
66void PrimaryDevice::deinitialize()
67{
68 PhysicalDevice::deinitialize();
69}
70
71void PrimaryDevice::hotplugEventListener(void *data, bool status)
72{
73 PrimaryDevice *pThis = (PrimaryDevice*)data;
74 if (pThis) {
75 pThis->hotplugListener(status);
76 }
77}
78
79void PrimaryDevice::hotplugListener(bool connected)
80{
81 CTRACE();
82 ETRACE("hotpug event: %d", connected);
83
84 updateHotplugState(connected);
85
86 // update display configs
87 onHotplug(getDisplayId(), connected);
88}
89
90int PrimaryDevice::parseConfigFile()
91{
92 const char* WHITESPACE = " \t\r";
93
94 SysTokenizer* tokenizer;
95 int status = SysTokenizer::open(pConfigPath, &tokenizer);
96 if (status) {
97 ETRACE("Error %d opening display config file %s.", status, pConfigPath);
98 } else {
99 while (!tokenizer->isEof()) {
100 ITRACE("Parsing %s: %s", tokenizer->getLocation(), tokenizer->peekRemainderOfLine());
101
102 tokenizer->skipDelimiters(WHITESPACE);
103 if (!tokenizer->isEol() && tokenizer->peekChar() != '#') {
104
105 char *token = tokenizer->nextToken(WHITESPACE);
106 if (!strcmp(token, DEVICE_STR_MBOX)) {
107 mDisplayType = DISPLAY_TYPE_MBOX;
108 } else if (!strcmp(token, DEVICE_STR_TV)) {
109 mDisplayType = DISPLAY_TYPE_TV;
110 } else {
111 DTRACE("%s: Expected keyword, got '%s'.", tokenizer->getLocation(), token);
112 break;
113 }
114 tokenizer->skipDelimiters(WHITESPACE);
115 tokenizer->nextToken(WHITESPACE);
116 tokenizer->skipDelimiters(WHITESPACE);
117 strcpy(mDefaultMode, tokenizer->nextToken(WHITESPACE));
118 }
119
120 tokenizer->nextLine();
121 }
122 delete tokenizer;
123 }
124 return status;
125}
126
127} // namespace amlogic
128} // namespace android
129