1 /*
2 * Copyright (C) 2019 The Android Open Source Project
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
17 #include "HalDisplay.h"
18
19 #include <inttypes.h>
20
21 #include <android-base/logging.h>
22 #include <android-base/stringprintf.h>
23 #include <ui/DisplayMode.h>
24 #include <ui/DisplayState.h>
25
26 using android::base::StringAppendF;
27
28 namespace android {
29 namespace automotive {
30 namespace evs {
31 namespace V1_1 {
32 namespace implementation {
33
HalDisplay(sp<IEvsDisplay_1_0> display,int32_t id)34 HalDisplay::HalDisplay(sp<IEvsDisplay_1_0> display, int32_t id) :
35 mHwDisplay(display),
36 mId(id) {
37 // nothing to do.
38 }
39
~HalDisplay()40 HalDisplay::~HalDisplay() {
41 shutdown();
42 }
43
shutdown()44 void HalDisplay::shutdown() {
45 // simply release a strong pointer to remote display object.
46 mHwDisplay = nullptr;
47 }
48
49 /**
50 * Returns a strong pointer to remote display object.
51 */
getHwDisplay()52 sp<IEvsDisplay_1_0> HalDisplay::getHwDisplay() {
53 return mHwDisplay;
54 }
55
56 /**
57 * Gets basic display information from a hardware display object
58 * and returns.
59 */
getDisplayInfo(getDisplayInfo_cb _hidl_cb)60 Return<void> HalDisplay::getDisplayInfo(getDisplayInfo_cb _hidl_cb) {
61 if (mHwDisplay) {
62 mHwDisplay->getDisplayInfo(_hidl_cb);
63 }
64
65 return Void();
66 }
67
68 /**
69 * Sets the display state as what the clients wants.
70 */
setDisplayState(EvsDisplayState state)71 Return<EvsResult> HalDisplay::setDisplayState(EvsDisplayState state) {
72 if (mHwDisplay) {
73 return mHwDisplay->setDisplayState(state);
74 } else {
75 return EvsResult::UNDERLYING_SERVICE_ERROR;
76 }
77 }
78
79 /**
80 * Gets current display state from a hardware display object and return.
81 */
getDisplayState()82 Return<EvsDisplayState> HalDisplay::getDisplayState() {
83 if (mHwDisplay) {
84 return mHwDisplay->getDisplayState();
85 } else {
86 return EvsDisplayState::DEAD;
87 }
88 }
89
90 /**
91 * Returns a handle to a frame buffer associated with the display.
92 */
getTargetBuffer(getTargetBuffer_cb _hidl_cb)93 Return<void> HalDisplay::getTargetBuffer(getTargetBuffer_cb _hidl_cb) {
94 if (mHwDisplay) {
95 mHwDisplay->getTargetBuffer(_hidl_cb);
96 }
97
98 return Void();
99 }
100
101 /**
102 * Notifies the display that the buffer is ready to be used.
103 */
returnTargetBufferForDisplay(const BufferDesc_1_0 & buffer)104 Return<EvsResult> HalDisplay::returnTargetBufferForDisplay(const BufferDesc_1_0& buffer) {
105 if (mHwDisplay) {
106 return mHwDisplay->returnTargetBufferForDisplay(buffer);
107 } else {
108 return EvsResult::OWNERSHIP_LOST;
109 }
110 }
111
112 /**
113 * Gets basic display information from a hardware display object
114 * and returns.
115 */
getDisplayInfo_1_1(getDisplayInfo_1_1_cb _info_cb)116 Return<void> HalDisplay::getDisplayInfo_1_1(getDisplayInfo_1_1_cb _info_cb) {
117 sp<IEvsDisplay_1_1> display = IEvsDisplay_1_1::castFrom(mHwDisplay)
118 .withDefault(nullptr);
119 if (display != nullptr) {
120 display->getDisplayInfo_1_1(_info_cb);
121 }
122
123 return Void();
124 }
125
126
toString(const char * indent)127 std::string HalDisplay::toString(const char* indent) {
128 std::string buffer;
129 android::ui::DisplayMode displayMode;
130 android::ui::DisplayState displayState;
131
132 if (mId == std::numeric_limits<int32_t>::min()) {
133 // Display identifier has not set
134 StringAppendF(&buffer, "HalDisplay: Display port is unknown.\n");
135 } else {
136 StringAppendF(&buffer, "HalDisplay: Display port %" PRId32 "\n", mId);
137 }
138
139 getDisplayInfo_1_1([&](auto& config, auto& state) {
140 displayMode =
141 *(reinterpret_cast<const android::ui::DisplayMode*>(config.data()));
142 displayState =
143 *(reinterpret_cast<const android::ui::DisplayState*>(state.data()));
144 });
145
146 StringAppendF(&buffer, "%sWidth: %" PRId32 "\n",
147 indent, displayMode.resolution.getWidth());
148 StringAppendF(&buffer, "%sHeight: %" PRId32 "\n",
149 indent, displayMode.resolution.getHeight());
150 StringAppendF(&buffer, "%sRefresh rate: %f\n",
151 indent, displayMode.refreshRate);
152 StringAppendF(&buffer, "%sRotation: %" PRId32 "\n",
153 indent, static_cast<int32_t>(displayState.orientation));
154
155 return buffer;
156 }
157
158 } // namespace implementation
159 } // namespace V1_1
160 } // namespace evs
161 } // namespace automotive
162 } // namespace android
163