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