blob: 2f59469ef9392e21d048b8b7b0ee051bf63c6cd8 [file] [log] [blame]
Mathias Agopiana350ff92010-08-10 17:14:02 -07001/*
2 * Copyright (C) 2010 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
Ady Abrahamb0dbdaa2020-01-06 16:19:42 -080017// TODO(b/129481165): remove the #pragma below and fix conversion issues
18#pragma clang diagnostic push
19#pragma clang diagnostic ignored "-Wconversion"
20
Dan Stoza9e56aa02015-11-02 13:00:03 -080021// #define LOG_NDEBUG 0
22
23#undef LOG_TAG
24#define LOG_TAG "HWComposer"
Mathias Agopian2965b262012-04-08 15:13:32 -070025#define ATRACE_TAG ATRACE_TAG_GRAPHICS
26
Lloyd Pique66d68602019-02-13 14:23:31 -080027#include "HWComposer.h"
28
Lloyd Pique37c2c9b2018-12-04 17:25:10 -080029#include <compositionengine/Output.h>
30#include <compositionengine/OutputLayer.h>
31#include <compositionengine/impl/OutputLayerCompositionState.h>
32#include <log/log.h>
Dominik Laskowskifc2c0322018-04-19 14:47:33 -070033#include <ui/DebugUtils.h>
Mathias Agopian921e6ac2012-07-23 23:11:29 -070034#include <ui/GraphicBuffer.h>
Lloyd Pique37c2c9b2018-12-04 17:25:10 -080035#include <utils/Errors.h>
36#include <utils/Trace.h>
Mathias Agopiana350ff92010-08-10 17:14:02 -070037
Lloyd Pique66d68602019-02-13 14:23:31 -080038#include "../Layer.h" // needed only for debugging
Mathias Agopian33ceeb32013-04-01 16:54:58 -070039#include "../SurfaceFlinger.h"
Lloyd Pique66d68602019-02-13 14:23:31 -080040#include "ComposerHal.h"
41#include "HWC2.h"
Mathias Agopiana350ff92010-08-10 17:14:02 -070042
Dominik Laskowskic1f18f62018-06-13 15:17:55 -070043#define LOG_HWC_DISPLAY_ERROR(hwcDisplayId, msg) \
44 ALOGE("%s failed for HWC display %" PRIu64 ": %s", __FUNCTION__, hwcDisplayId, msg)
45
Dominik Laskowskifc2c0322018-04-19 14:47:33 -070046#define LOG_DISPLAY_ERROR(displayId, msg) \
Dominik Laskowski34157762018-10-31 13:07:19 -070047 ALOGE("%s failed for display %s: %s", __FUNCTION__, to_string(displayId).c_str(), msg)
Dominik Laskowskifc2c0322018-04-19 14:47:33 -070048
Dominik Laskowski34157762018-10-31 13:07:19 -070049#define LOG_HWC_ERROR(what, error, displayId) \
50 ALOGE("%s: %s failed for display %s: %s (%d)", __FUNCTION__, what, \
51 to_string(displayId).c_str(), to_string(error).c_str(), static_cast<int32_t>(error))
Dominik Laskowskifc2c0322018-04-19 14:47:33 -070052
53#define RETURN_IF_INVALID_DISPLAY(displayId, ...) \
54 do { \
Dominik Laskowski075d3172018-05-24 15:50:06 -070055 if (mDisplayData.count(displayId) == 0) { \
Dominik Laskowskifc2c0322018-04-19 14:47:33 -070056 LOG_DISPLAY_ERROR(displayId, "Invalid display"); \
57 return __VA_ARGS__; \
58 } \
59 } while (false)
60
61#define RETURN_IF_HWC_ERROR_FOR(what, error, displayId, ...) \
62 do { \
Peiyong Line9d809e2020-04-14 13:10:48 -070063 if (error != hal::Error::NONE) { \
Dominik Laskowskifc2c0322018-04-19 14:47:33 -070064 LOG_HWC_ERROR(what, error, displayId); \
65 return __VA_ARGS__; \
66 } \
67 } while (false)
68
69#define RETURN_IF_HWC_ERROR(error, displayId, ...) \
70 RETURN_IF_HWC_ERROR_FOR(__FUNCTION__, error, displayId, __VA_ARGS__)
71
Peiyong Line9d809e2020-04-14 13:10:48 -070072namespace hal = android::hardware::graphics::composer::hal;
73
Peiyong Linbdd08cc2019-12-17 21:35:14 -080074namespace {
75
76using android::hardware::Return;
77using android::hardware::Void;
Peiyong Line9d809e2020-04-14 13:10:48 -070078using android::HWC2::ComposerCallback;
Peiyong Linbdd08cc2019-12-17 21:35:14 -080079
Peiyong Line9d809e2020-04-14 13:10:48 -070080class ComposerCallbackBridge : public hal::IComposerCallback {
Peiyong Linbdd08cc2019-12-17 21:35:14 -080081public:
Peiyong Line9d809e2020-04-14 13:10:48 -070082 ComposerCallbackBridge(ComposerCallback* callback, int32_t sequenceId,
Peiyong Linbdd08cc2019-12-17 21:35:14 -080083 bool vsyncSwitchingSupported)
84 : mCallback(callback),
85 mSequenceId(sequenceId),
86 mVsyncSwitchingSupported(vsyncSwitchingSupported) {}
87
Peiyong Line9d809e2020-04-14 13:10:48 -070088 android::hardware::Return<void> onHotplug(hal::HWDisplayId display,
89 hal::Connection conn) override {
90 mCallback->onHotplugReceived(mSequenceId, display, conn);
Peiyong Linbdd08cc2019-12-17 21:35:14 -080091 return android::hardware::Void();
92 }
93
Peiyong Line9d809e2020-04-14 13:10:48 -070094 android::hardware::Return<void> onRefresh(hal::HWDisplayId display) override {
Peiyong Linbdd08cc2019-12-17 21:35:14 -080095 mCallback->onRefreshReceived(mSequenceId, display);
96 return android::hardware::Void();
97 }
98
Peiyong Line9d809e2020-04-14 13:10:48 -070099 android::hardware::Return<void> onVsync(hal::HWDisplayId display, int64_t timestamp) override {
Peiyong Linbdd08cc2019-12-17 21:35:14 -0800100 if (!mVsyncSwitchingSupported) {
101 mCallback->onVsyncReceived(mSequenceId, display, timestamp, std::nullopt);
102 } else {
103 ALOGW("Unexpected onVsync callback on composer >= 2.4, ignoring.");
104 }
105 return android::hardware::Void();
106 }
107
Peiyong Line9d809e2020-04-14 13:10:48 -0700108 android::hardware::Return<void> onVsync_2_4(hal::HWDisplayId display, int64_t timestamp,
109 hal::VsyncPeriodNanos vsyncPeriodNanos) override {
Peiyong Linbdd08cc2019-12-17 21:35:14 -0800110 if (mVsyncSwitchingSupported) {
Peiyong Linbdd08cc2019-12-17 21:35:14 -0800111 mCallback->onVsyncReceived(mSequenceId, display, timestamp,
112 std::make_optional(vsyncPeriodNanos));
113 } else {
114 ALOGW("Unexpected onVsync_2_4 callback on composer <= 2.3, ignoring.");
115 }
116 return android::hardware::Void();
117 }
118
119 android::hardware::Return<void> onVsyncPeriodTimingChanged(
Peiyong Line9d809e2020-04-14 13:10:48 -0700120 hal::HWDisplayId display,
121 const hal::VsyncPeriodChangeTimeline& updatedTimeline) override {
122 mCallback->onVsyncPeriodTimingChangedReceived(mSequenceId, display, updatedTimeline);
Peiyong Linbdd08cc2019-12-17 21:35:14 -0800123 return android::hardware::Void();
124 }
125
Peiyong Line9d809e2020-04-14 13:10:48 -0700126 android::hardware::Return<void> onSeamlessPossible(hal::HWDisplayId display) override {
Ady Abrahamb0433bc2020-01-08 17:31:06 -0800127 mCallback->onSeamlessPossible(mSequenceId, display);
128 return android::hardware::Void();
129 }
130
Peiyong Linbdd08cc2019-12-17 21:35:14 -0800131private:
Peiyong Line9d809e2020-04-14 13:10:48 -0700132 ComposerCallback* mCallback;
Peiyong Linbdd08cc2019-12-17 21:35:14 -0800133 const int32_t mSequenceId;
134 const bool mVsyncSwitchingSupported;
135};
136
137} // namespace
138
Mathias Agopiana350ff92010-08-10 17:14:02 -0700139namespace android {
Jesse Hall5880cc52012-06-05 23:40:32 -0700140
Lloyd Pique441d5042018-10-18 16:49:51 -0700141HWComposer::~HWComposer() = default;
142
143namespace impl {
144
Peiyong Linbdd08cc2019-12-17 21:35:14 -0800145HWComposer::HWComposer(std::unique_ptr<Hwc2::Composer> composer) : mComposer(std::move(composer)) {
Peiyong Linbdd08cc2019-12-17 21:35:14 -0800146}
147
148HWComposer::HWComposer(const std::string& composerServiceName)
149 : mComposer(std::make_unique<Hwc2::impl::Composer>(composerServiceName)) {
Peiyong Linbdd08cc2019-12-17 21:35:14 -0800150}
Mathias Agopianbef42c52013-08-21 17:45:46 -0700151
Dominik Laskowskib04f98a2018-11-07 21:07:16 -0800152HWComposer::~HWComposer() {
153 mDisplayData.clear();
154}
Dan Stoza9e56aa02015-11-02 13:00:03 -0800155
Lloyd Pique4603f3c2020-02-11 12:06:56 -0800156void HWComposer::setConfiguration(HWC2::ComposerCallback* callback, int32_t sequenceId) {
157 loadCapabilities();
158 loadLayerMetadataSupport();
159
Peiyong Linbdd08cc2019-12-17 21:35:14 -0800160 if (mRegisteredCallback) {
161 ALOGW("Callback already registered. Ignored extra registration attempt.");
162 return;
163 }
164 mRegisteredCallback = true;
165 sp<ComposerCallbackBridge> callbackBridge(
166 new ComposerCallbackBridge(callback, sequenceId,
167 mComposer->isVsyncPeriodSwitchSupported()));
168 mComposer->registerCallback(callbackBridge);
Dan Stoza9e56aa02015-11-02 13:00:03 -0800169}
170
Peiyong Line9d809e2020-04-14 13:10:48 -0700171bool HWComposer::getDisplayIdentificationData(hal::HWDisplayId hwcDisplayId, uint8_t* outPort,
Dominik Laskowskie9ef7c42018-03-12 19:34:30 -0700172 DisplayIdentificationData* outData) const {
Peiyong Line9d809e2020-04-14 13:10:48 -0700173 const auto error = static_cast<hal::Error>(
Peiyong Linbdd08cc2019-12-17 21:35:14 -0800174 mComposer->getDisplayIdentificationData(hwcDisplayId, outPort, outData));
Peiyong Line9d809e2020-04-14 13:10:48 -0700175 if (error != hal::Error::NONE) {
176 if (error != hal::Error::UNSUPPORTED) {
Chia-I Wud0aff9d2018-06-21 13:39:09 +0800177 LOG_HWC_DISPLAY_ERROR(hwcDisplayId, to_string(error).c_str());
178 }
Dominik Laskowskie9ef7c42018-03-12 19:34:30 -0700179 return false;
180 }
181 return true;
182}
183
Peiyong Line9d809e2020-04-14 13:10:48 -0700184bool HWComposer::hasCapability(hal::Capability capability) const {
Peiyong Linbdd08cc2019-12-17 21:35:14 -0800185 return mCapabilities.count(capability) > 0;
Dan Stoza9f26a9c2016-06-22 14:51:09 -0700186}
187
Dominik Laskowski1162e472020-04-02 19:02:47 -0700188bool HWComposer::hasDisplayCapability(DisplayId displayId,
Peiyong Line9d809e2020-04-14 13:10:48 -0700189 hal::DisplayCapability capability) const {
Dominik Laskowski1162e472020-04-02 19:02:47 -0700190 RETURN_IF_INVALID_DISPLAY(displayId, false);
191 return mDisplayData.at(displayId).hwcDisplay->getCapabilities().count(capability) > 0;
Peiyong Lined531a32018-10-26 18:27:56 -0700192}
193
Peiyong Line9d809e2020-04-14 13:10:48 -0700194std::optional<DisplayIdentificationInfo> HWComposer::onHotplug(hal::HWDisplayId hwcDisplayId,
195 hal::Connection connection) {
Marin Shalamanovbdd59152020-02-14 15:30:06 +0100196 switch (connection) {
Peiyong Line9d809e2020-04-14 13:10:48 -0700197 case hal::Connection::CONNECTED:
Marin Shalamanovbdd59152020-02-14 15:30:06 +0100198 return onHotplugConnect(hwcDisplayId);
Peiyong Line9d809e2020-04-14 13:10:48 -0700199 case hal::Connection::DISCONNECTED:
Marin Shalamanovbdd59152020-02-14 15:30:06 +0100200 return onHotplugDisconnect(hwcDisplayId);
Peiyong Line9d809e2020-04-14 13:10:48 -0700201 case hal::Connection::INVALID:
Dominik Laskowski075d3172018-05-24 15:50:06 -0700202 return {};
Dominik Laskowskie9ef7c42018-03-12 19:34:30 -0700203 }
Andy McFaddenb0d1dd32012-09-10 14:08:09 -0700204}
205
Peiyong Line9d809e2020-04-14 13:10:48 -0700206bool HWComposer::onVsync(hal::HWDisplayId hwcDisplayId, int64_t timestamp) {
Dominik Laskowski075d3172018-05-24 15:50:06 -0700207 const auto displayId = toPhysicalDisplayId(hwcDisplayId);
208 if (!displayId) {
209 LOG_HWC_DISPLAY_ERROR(hwcDisplayId, "Invalid HWC display");
Steven Thomas94e35b92017-07-26 18:48:28 -0700210 return false;
Jesse Hall1bd20e02012-08-29 10:47:52 -0700211 }
Jesse Hall1bd20e02012-08-29 10:47:52 -0700212
Dominik Laskowski075d3172018-05-24 15:50:06 -0700213 RETURN_IF_INVALID_DISPLAY(*displayId, false);
Dominik Laskowskic1f18f62018-06-13 15:17:55 -0700214
Dominik Laskowski1af47932018-11-12 10:20:46 -0800215 auto& displayData = mDisplayData[*displayId];
Dominik Laskowskic1f18f62018-06-13 15:17:55 -0700216 if (displayData.isVirtual) {
Dominik Laskowski075d3172018-05-24 15:50:06 -0700217 LOG_DISPLAY_ERROR(*displayId, "Invalid operation on virtual display");
Steven Thomas94e35b92017-07-26 18:48:28 -0700218 return false;
Jesse Hall1bd20e02012-08-29 10:47:52 -0700219 }
220
Dan Stoza9e56aa02015-11-02 13:00:03 -0800221 {
Dominik Laskowski1af47932018-11-12 10:20:46 -0800222 std::lock_guard lock(displayData.lastHwVsyncLock);
Jesse Hall1bd20e02012-08-29 10:47:52 -0700223
Dan Stoza9e56aa02015-11-02 13:00:03 -0800224 // There have been reports of HWCs that signal several vsync events
225 // with the same timestamp when turning the display off and on. This
226 // is a bug in the HWC implementation, but filter the extra events
227 // out here so they don't cause havoc downstream.
Dominik Laskowski1af47932018-11-12 10:20:46 -0800228 if (timestamp == displayData.lastHwVsync) {
Dominik Laskowski34157762018-10-31 13:07:19 -0700229 ALOGW("Ignoring duplicate VSYNC event from HWC for display %s (t=%" PRId64 ")",
230 to_string(*displayId).c_str(), timestamp);
Steven Thomas94e35b92017-07-26 18:48:28 -0700231 return false;
Dan Stoza9e56aa02015-11-02 13:00:03 -0800232 }
233
Dominik Laskowski1af47932018-11-12 10:20:46 -0800234 displayData.lastHwVsync = timestamp;
Jesse Hall1c569c42013-04-05 13:44:52 -0700235 }
Dan Stoza9e56aa02015-11-02 13:00:03 -0800236
Dominik Laskowski34157762018-10-31 13:07:19 -0700237 const auto tag = "HW_VSYNC_" + to_string(*displayId);
Dominik Laskowski1af47932018-11-12 10:20:46 -0800238 ATRACE_INT(tag.c_str(), displayData.vsyncTraceToggle);
239 displayData.vsyncTraceToggle = !displayData.vsyncTraceToggle;
Dan Stoza9e56aa02015-11-02 13:00:03 -0800240
Steven Thomas94e35b92017-07-26 18:48:28 -0700241 return true;
Jesse Hall1c569c42013-04-05 13:44:52 -0700242}
243
Dominik Laskowski075d3172018-05-24 15:50:06 -0700244std::optional<DisplayId> HWComposer::allocateVirtualDisplay(uint32_t width, uint32_t height,
245 ui::PixelFormat* format) {
Dan Stoza9e56aa02015-11-02 13:00:03 -0800246 if (mRemainingHwcVirtualDisplays == 0) {
Dominik Laskowskif3749f82018-06-13 15:49:25 -0700247 ALOGE("%s: No remaining virtual displays", __FUNCTION__);
Dominik Laskowski075d3172018-05-24 15:50:06 -0700248 return {};
Mathias Agopiane60b0682012-08-21 23:34:09 -0700249 }
Mathias Agopiane60b0682012-08-21 23:34:09 -0700250
Fabien Sanglardc8e387e2017-03-10 10:30:28 -0800251 if (SurfaceFlinger::maxVirtualDisplaySize != 0 &&
252 (width > SurfaceFlinger::maxVirtualDisplaySize ||
253 height > SurfaceFlinger::maxVirtualDisplaySize)) {
Dominik Laskowskif3749f82018-06-13 15:49:25 -0700254 ALOGE("%s: Display size %ux%u exceeds maximum dimension of %" PRIu64, __FUNCTION__, width,
255 height, SurfaceFlinger::maxVirtualDisplaySize);
Dominik Laskowski075d3172018-05-24 15:50:06 -0700256 return {};
Fabien Sanglarde29055f2017-03-08 11:36:46 -0800257 }
Peiyong Line9d809e2020-04-14 13:10:48 -0700258 hal::HWDisplayId hwcDisplayId = 0;
259 const auto error = static_cast<hal::Error>(
Peiyong Linbdd08cc2019-12-17 21:35:14 -0800260 mComposer->createVirtualDisplay(width, height, format, &hwcDisplayId));
Peiyong Line9d809e2020-04-14 13:10:48 -0700261 if (error != hal::Error::NONE) {
Dominik Laskowskif3749f82018-06-13 15:49:25 -0700262 ALOGE("%s: Failed to create HWC virtual display", __FUNCTION__);
Dominik Laskowski075d3172018-05-24 15:50:06 -0700263 return {};
Mathias Agopiane60b0682012-08-21 23:34:09 -0700264 }
Dan Stoza9e56aa02015-11-02 13:00:03 -0800265
Peiyong Linbdd08cc2019-12-17 21:35:14 -0800266 auto display = std::make_unique<HWC2::impl::Display>(*mComposer.get(), mCapabilities,
Peiyong Line9d809e2020-04-14 13:10:48 -0700267 hwcDisplayId, hal::DisplayType::VIRTUAL);
Peiyong Linbdd08cc2019-12-17 21:35:14 -0800268 display->setConnected(true);
269
Dominik Laskowski075d3172018-05-24 15:50:06 -0700270 DisplayId displayId;
271 if (mFreeVirtualDisplayIds.empty()) {
272 displayId = getVirtualDisplayId(mNextVirtualDisplayId++);
Dan Stoza9e56aa02015-11-02 13:00:03 -0800273 } else {
Dominik Laskowski075d3172018-05-24 15:50:06 -0700274 displayId = *mFreeVirtualDisplayIds.begin();
275 mFreeVirtualDisplayIds.erase(displayId);
Mathias Agopiane60b0682012-08-21 23:34:09 -0700276 }
Dan Stoza9e56aa02015-11-02 13:00:03 -0800277
Dominik Laskowski075d3172018-05-24 15:50:06 -0700278 auto& displayData = mDisplayData[displayId];
Peiyong Linbdd08cc2019-12-17 21:35:14 -0800279 displayData.hwcDisplay = std::move(display);
Dominik Laskowskic1f18f62018-06-13 15:17:55 -0700280 displayData.isVirtual = true;
Dan Stoza9e56aa02015-11-02 13:00:03 -0800281
282 --mRemainingHwcVirtualDisplays;
Dominik Laskowski075d3172018-05-24 15:50:06 -0700283 return displayId;
Mathias Agopiane60b0682012-08-21 23:34:09 -0700284}
285
Peiyong Line9d809e2020-04-14 13:10:48 -0700286void HWComposer::allocatePhysicalDisplay(hal::HWDisplayId hwcDisplayId, DisplayId displayId) {
Marin Shalamanovbdd59152020-02-14 15:30:06 +0100287 if (!mInternalHwcDisplayId) {
288 mInternalHwcDisplayId = hwcDisplayId;
289 } else if (mInternalHwcDisplayId != hwcDisplayId && !mExternalHwcDisplayId) {
290 mExternalHwcDisplayId = hwcDisplayId;
291 }
292
293 auto& displayData = mDisplayData[displayId];
294 auto newDisplay =
295 std::make_unique<HWC2::impl::Display>(*mComposer.get(), mCapabilities, hwcDisplayId,
Peiyong Line9d809e2020-04-14 13:10:48 -0700296 hal::DisplayType::PHYSICAL);
Marin Shalamanovbdd59152020-02-14 15:30:06 +0100297 newDisplay->setConnected(true);
298 displayData.hwcDisplay = std::move(newDisplay);
299 mPhysicalDisplayIdMap[hwcDisplayId] = displayId;
300}
301
Dominik Laskowski075d3172018-05-24 15:50:06 -0700302HWC2::Layer* HWComposer::createLayer(DisplayId displayId) {
Dominik Laskowskifc2c0322018-04-19 14:47:33 -0700303 RETURN_IF_INVALID_DISPLAY(displayId, nullptr);
304
Steven Thomas94e35b92017-07-26 18:48:28 -0700305 HWC2::Layer* layer;
Peiyong Linbdd08cc2019-12-17 21:35:14 -0800306 auto error = mDisplayData[displayId].hwcDisplay->createLayer(&layer);
Dominik Laskowskifc2c0322018-04-19 14:47:33 -0700307 RETURN_IF_HWC_ERROR(error, displayId, nullptr);
Dan Stoza9e56aa02015-11-02 13:00:03 -0800308 return layer;
309}
310
Dominik Laskowski075d3172018-05-24 15:50:06 -0700311void HWComposer::destroyLayer(DisplayId displayId, HWC2::Layer* layer) {
Dominik Laskowskifc2c0322018-04-19 14:47:33 -0700312 RETURN_IF_INVALID_DISPLAY(displayId);
313
Peiyong Linbdd08cc2019-12-17 21:35:14 -0800314 auto error = mDisplayData[displayId].hwcDisplay->destroyLayer(layer);
Dominik Laskowskifc2c0322018-04-19 14:47:33 -0700315 RETURN_IF_HWC_ERROR(error, displayId);
Steven Thomas94e35b92017-07-26 18:48:28 -0700316}
317
Dominik Laskowski075d3172018-05-24 15:50:06 -0700318nsecs_t HWComposer::getRefreshTimestamp(DisplayId displayId) const {
319 RETURN_IF_INVALID_DISPLAY(displayId, 0);
Dominik Laskowski1af47932018-11-12 10:20:46 -0800320 const auto& displayData = mDisplayData.at(displayId);
Mathias Agopiand3ee2312012-08-02 14:01:42 -0700321 // this returns the last refresh timestamp.
322 // if the last one is not available, we estimate it based on
323 // the refresh period and whatever closest timestamp we have.
Dominik Laskowski1af47932018-11-12 10:20:46 -0800324 std::lock_guard lock(displayData.lastHwVsyncLock);
Mathias Agopiand3ee2312012-08-02 14:01:42 -0700325 nsecs_t now = systemTime(CLOCK_MONOTONIC);
Ady Abraham3a77a7b2019-12-02 18:46:59 -0800326 auto vsyncPeriodNanos = getDisplayVsyncPeriod(displayId);
327 return now - ((now - displayData.lastHwVsync) % vsyncPeriodNanos);
Mathias Agopian3eb38cb2012-04-03 22:09:52 -0700328}
329
Dominik Laskowski075d3172018-05-24 15:50:06 -0700330bool HWComposer::isConnected(DisplayId displayId) const {
Dominik Laskowskifc2c0322018-04-19 14:47:33 -0700331 RETURN_IF_INVALID_DISPLAY(displayId, false);
Dominik Laskowski075d3172018-05-24 15:50:06 -0700332 return mDisplayData.at(displayId).hwcDisplay->isConnected();
Mathias Agopian9c6e2972011-09-20 17:21:56 -0700333}
334
Dominik Laskowski075d3172018-05-24 15:50:06 -0700335std::vector<std::shared_ptr<const HWC2::Display::Config>> HWComposer::getConfigs(
336 DisplayId displayId) const {
Dominik Laskowskifc2c0322018-04-19 14:47:33 -0700337 RETURN_IF_INVALID_DISPLAY(displayId, {});
338
Dominik Laskowski075d3172018-05-24 15:50:06 -0700339 const auto& displayData = mDisplayData.at(displayId);
340 auto configs = displayData.hwcDisplay->getConfigs();
Dan Stoza9e56aa02015-11-02 13:00:03 -0800341 if (displayData.configMap.empty()) {
342 for (size_t i = 0; i < configs.size(); ++i) {
343 displayData.configMap[i] = configs[i];
Mathias Agopianda27af92012-09-13 18:17:13 -0700344 }
345 }
Dan Stoza9e56aa02015-11-02 13:00:03 -0800346 return configs;
Mathias Agopianda27af92012-09-13 18:17:13 -0700347}
348
Dominik Laskowski075d3172018-05-24 15:50:06 -0700349std::shared_ptr<const HWC2::Display::Config> HWComposer::getActiveConfig(
350 DisplayId displayId) const {
Dominik Laskowskifc2c0322018-04-19 14:47:33 -0700351 RETURN_IF_INVALID_DISPLAY(displayId, nullptr);
352
Dan Stoza9e56aa02015-11-02 13:00:03 -0800353 std::shared_ptr<const HWC2::Display::Config> config;
Dominik Laskowski075d3172018-05-24 15:50:06 -0700354 auto error = mDisplayData.at(displayId).hwcDisplay->getActiveConfig(&config);
Peiyong Line9d809e2020-04-14 13:10:48 -0700355 if (error == hal::Error::BAD_CONFIG) {
Dominik Laskowskifc2c0322018-04-19 14:47:33 -0700356 LOG_DISPLAY_ERROR(displayId, "No active config");
Dan Stoza9e56aa02015-11-02 13:00:03 -0800357 return nullptr;
Dominik Laskowskifc2c0322018-04-19 14:47:33 -0700358 }
359
360 RETURN_IF_HWC_ERROR(error, displayId, nullptr);
361
362 if (!config) {
363 LOG_DISPLAY_ERROR(displayId, "Unknown config");
Dan Stoza9e56aa02015-11-02 13:00:03 -0800364 return nullptr;
365 }
366
367 return config;
Mathias Agopiana350ff92010-08-10 17:14:02 -0700368}
369
Ady Abraham3a77a7b2019-12-02 18:46:59 -0800370// Composer 2.4
371
Dominik Laskowski55c85402020-01-21 16:25:47 -0800372DisplayConnectionType HWComposer::getDisplayConnectionType(DisplayId displayId) const {
373 RETURN_IF_INVALID_DISPLAY(displayId, DisplayConnectionType::Internal);
374 const auto& hwcDisplay = mDisplayData.at(displayId).hwcDisplay;
375
376 DisplayConnectionType type;
377 const auto error = hwcDisplay->getConnectionType(&type);
378
379 const auto FALLBACK_TYPE = hwcDisplay->getId() == mInternalHwcDisplayId
380 ? DisplayConnectionType::Internal
381 : DisplayConnectionType::External;
382
383 RETURN_IF_HWC_ERROR(error, displayId, FALLBACK_TYPE);
384 return type;
385}
386
Ady Abraham3a77a7b2019-12-02 18:46:59 -0800387bool HWComposer::isVsyncPeriodSwitchSupported(DisplayId displayId) const {
Dominik Laskowski55c85402020-01-21 16:25:47 -0800388 RETURN_IF_INVALID_DISPLAY(displayId, false);
Ady Abraham3a77a7b2019-12-02 18:46:59 -0800389 return mDisplayData.at(displayId).hwcDisplay->isVsyncPeriodSwitchSupported();
390}
391
392nsecs_t HWComposer::getDisplayVsyncPeriod(DisplayId displayId) const {
Dominik Laskowski55c85402020-01-21 16:25:47 -0800393 RETURN_IF_INVALID_DISPLAY(displayId, 0);
394
Ady Abraham3a77a7b2019-12-02 18:46:59 -0800395 nsecs_t vsyncPeriodNanos;
396 auto error = mDisplayData.at(displayId).hwcDisplay->getDisplayVsyncPeriod(&vsyncPeriodNanos);
Dominik Laskowski55c85402020-01-21 16:25:47 -0800397 RETURN_IF_HWC_ERROR(error, displayId, 0);
Ady Abraham3a77a7b2019-12-02 18:46:59 -0800398 return vsyncPeriodNanos;
399}
400
Dominik Laskowski075d3172018-05-24 15:50:06 -0700401int HWComposer::getActiveConfigIndex(DisplayId displayId) const {
Dominik Laskowskif3749f82018-06-13 15:49:25 -0700402 RETURN_IF_INVALID_DISPLAY(displayId, -1);
403
Lloyd Pique3c085a02018-05-09 19:38:32 -0700404 int index;
Dominik Laskowski075d3172018-05-24 15:50:06 -0700405 auto error = mDisplayData.at(displayId).hwcDisplay->getActiveConfigIndex(&index);
Peiyong Line9d809e2020-04-14 13:10:48 -0700406 if (error == hal::Error::BAD_CONFIG) {
Dominik Laskowskif3749f82018-06-13 15:49:25 -0700407 LOG_DISPLAY_ERROR(displayId, "No active config");
Lloyd Pique3c085a02018-05-09 19:38:32 -0700408 return -1;
Dominik Laskowskif3749f82018-06-13 15:49:25 -0700409 }
410
411 RETURN_IF_HWC_ERROR(error, displayId, -1);
412
413 if (index < 0) {
414 LOG_DISPLAY_ERROR(displayId, "Unknown config");
Lloyd Pique3c085a02018-05-09 19:38:32 -0700415 return -1;
416 }
417
418 return index;
419}
420
Dominik Laskowski075d3172018-05-24 15:50:06 -0700421std::vector<ui::ColorMode> HWComposer::getColorModes(DisplayId displayId) const {
Dominik Laskowskifc2c0322018-04-19 14:47:33 -0700422 RETURN_IF_INVALID_DISPLAY(displayId, {});
423
Peiyong Linfd997e02018-03-28 15:29:00 -0700424 std::vector<ui::ColorMode> modes;
Dominik Laskowski075d3172018-05-24 15:50:06 -0700425 auto error = mDisplayData.at(displayId).hwcDisplay->getColorModes(&modes);
Dominik Laskowskifc2c0322018-04-19 14:47:33 -0700426 RETURN_IF_HWC_ERROR(error, displayId, {});
Courtney Goeltzenleuchterfad9d8c2016-06-23 11:49:50 -0600427 return modes;
428}
429
Dominik Laskowski075d3172018-05-24 15:50:06 -0700430status_t HWComposer::setActiveColorMode(DisplayId displayId, ui::ColorMode mode,
431 ui::RenderIntent renderIntent) {
Dominik Laskowskifc2c0322018-04-19 14:47:33 -0700432 RETURN_IF_INVALID_DISPLAY(displayId, BAD_INDEX);
Michael Wright28f24d02016-07-12 13:30:53 -0700433
434 auto& displayData = mDisplayData[displayId];
Peiyong Lin0e7a7912018-04-05 14:36:36 -0700435 auto error = displayData.hwcDisplay->setColorMode(mode, renderIntent);
Dominik Laskowskifc2c0322018-04-19 14:47:33 -0700436 RETURN_IF_HWC_ERROR_FOR(("setColorMode(" + decodeColorMode(mode) + ", " +
437 decodeRenderIntent(renderIntent) + ")")
438 .c_str(),
439 error, displayId, UNKNOWN_ERROR);
Michael Wright28f24d02016-07-12 13:30:53 -0700440
441 return NO_ERROR;
442}
443
Peiyong Line9d809e2020-04-14 13:10:48 -0700444void HWComposer::setVsyncEnabled(DisplayId displayId, hal::Vsync enabled) {
Dominik Laskowskic1f18f62018-06-13 15:17:55 -0700445 RETURN_IF_INVALID_DISPLAY(displayId);
446 auto& displayData = mDisplayData[displayId];
447
448 if (displayData.isVirtual) {
449 LOG_DISPLAY_ERROR(displayId, "Invalid operation on virtual display");
Dan Stoza9e56aa02015-11-02 13:00:03 -0800450 return;
451 }
452
Dan Stoza9e56aa02015-11-02 13:00:03 -0800453 // NOTE: we use our own internal lock here because we have to call
454 // into the HWC with the lock held, and we want to make sure
455 // that even if HWC blocks (which it shouldn't), it won't
456 // affect other threads.
Dominik Laskowski1af47932018-11-12 10:20:46 -0800457 std::lock_guard lock(displayData.vsyncEnabledLock);
458 if (enabled == displayData.vsyncEnabled) {
459 return;
Colin Cross10fbdb62012-07-12 17:56:34 -0700460 }
Dominik Laskowski1af47932018-11-12 10:20:46 -0800461
462 ATRACE_CALL();
463 auto error = displayData.hwcDisplay->setVsyncEnabled(enabled);
464 RETURN_IF_HWC_ERROR(error, displayId);
465
466 displayData.vsyncEnabled = enabled;
467
468 const auto tag = "HW_VSYNC_ON_" + to_string(displayId);
Peiyong Line9d809e2020-04-14 13:10:48 -0700469 ATRACE_INT(tag.c_str(), enabled == hal::Vsync::ENABLE ? 1 : 0);
Colin Cross10fbdb62012-07-12 17:56:34 -0700470}
471
Dominik Laskowski075d3172018-05-24 15:50:06 -0700472status_t HWComposer::setClientTarget(DisplayId displayId, uint32_t slot,
473 const sp<Fence>& acquireFence, const sp<GraphicBuffer>& target,
474 ui::Dataspace dataspace) {
Dominik Laskowskifc2c0322018-04-19 14:47:33 -0700475 RETURN_IF_INVALID_DISPLAY(displayId, BAD_INDEX);
Jesse Hall851cfe82013-03-20 13:44:00 -0700476
Dominik Laskowski34157762018-10-31 13:07:19 -0700477 ALOGV("%s for display %s", __FUNCTION__, to_string(displayId).c_str());
Dan Stoza9e56aa02015-11-02 13:00:03 -0800478 auto& hwcDisplay = mDisplayData[displayId].hwcDisplay;
Daniel Nicoara1f42e3a2017-04-10 13:27:32 -0400479 auto error = hwcDisplay->setClientTarget(slot, target, acquireFence, dataspace);
Dominik Laskowskifc2c0322018-04-19 14:47:33 -0700480 RETURN_IF_HWC_ERROR(error, displayId, BAD_VALUE);
Jesse Hall851cfe82013-03-20 13:44:00 -0700481 return NO_ERROR;
482}
483
Lloyd Pique66d68602019-02-13 14:23:31 -0800484status_t HWComposer::getDeviceCompositionChanges(
485 DisplayId displayId, bool frameUsesClientComposition,
486 std::optional<android::HWComposer::DeviceRequestedChanges>* outChanges) {
Dan Stoza9e56aa02015-11-02 13:00:03 -0800487 ATRACE_CALL();
488
Dominik Laskowskifc2c0322018-04-19 14:47:33 -0700489 RETURN_IF_INVALID_DISPLAY(displayId, BAD_INDEX);
Dan Stoza9e56aa02015-11-02 13:00:03 -0800490
491 auto& displayData = mDisplayData[displayId];
492 auto& hwcDisplay = displayData.hwcDisplay;
493 if (!hwcDisplay->isConnected()) {
494 return NO_ERROR;
495 }
496
497 uint32_t numTypes = 0;
498 uint32_t numRequests = 0;
Fabien Sanglard249c0ae2017-06-19 19:22:36 -0700499
Peiyong Line9d809e2020-04-14 13:10:48 -0700500 hal::Error error = hal::Error::NONE;
Fabien Sanglard249c0ae2017-06-19 19:22:36 -0700501
Chia-I Wu41b98d42017-12-11 11:04:36 -0800502 // First try to skip validate altogether when there is no client
503 // composition. When there is client composition, since we haven't
504 // rendered to the client target yet, we should not attempt to skip
505 // validate.
Fabien Sanglard249c0ae2017-06-19 19:22:36 -0700506 displayData.validateWasSkipped = false;
Lloyd Pique66d68602019-02-13 14:23:31 -0800507 if (!frameUsesClientComposition) {
Dominik Laskowski1af47932018-11-12 10:20:46 -0800508 sp<Fence> outPresentFence;
Fabien Sanglard249c0ae2017-06-19 19:22:36 -0700509 uint32_t state = UINT32_MAX;
510 error = hwcDisplay->presentOrValidate(&numTypes, &numRequests, &outPresentFence , &state);
Peiyong Line9d809e2020-04-14 13:10:48 -0700511 if (!hasChangesError(error)) {
Dominik Laskowskifc2c0322018-04-19 14:47:33 -0700512 RETURN_IF_HWC_ERROR_FOR("presentOrValidate", error, displayId, UNKNOWN_ERROR);
Fabien Sanglard249c0ae2017-06-19 19:22:36 -0700513 }
514 if (state == 1) { //Present Succeeded.
Steven Thomas94e35b92017-07-26 18:48:28 -0700515 std::unordered_map<HWC2::Layer*, sp<Fence>> releaseFences;
Fabien Sanglard249c0ae2017-06-19 19:22:36 -0700516 error = hwcDisplay->getReleaseFences(&releaseFences);
517 displayData.releaseFences = std::move(releaseFences);
518 displayData.lastPresentFence = outPresentFence;
519 displayData.validateWasSkipped = true;
520 displayData.presentError = error;
521 return NO_ERROR;
522 }
523 // Present failed but Validate ran.
524 } else {
525 error = hwcDisplay->validate(&numTypes, &numRequests);
526 }
527 ALOGV("SkipValidate failed, Falling back to SLOW validate/present");
Peiyong Line9d809e2020-04-14 13:10:48 -0700528 if (!hasChangesError(error)) {
Dominik Laskowskifc2c0322018-04-19 14:47:33 -0700529 RETURN_IF_HWC_ERROR_FOR("validate", error, displayId, BAD_INDEX);
Dan Stoza9e56aa02015-11-02 13:00:03 -0800530 }
531
Lloyd Pique66d68602019-02-13 14:23:31 -0800532 android::HWComposer::DeviceRequestedChanges::ChangedTypes changedTypes;
Dan Stoza9e56aa02015-11-02 13:00:03 -0800533 changedTypes.reserve(numTypes);
534 error = hwcDisplay->getChangedCompositionTypes(&changedTypes);
Dominik Laskowskifc2c0322018-04-19 14:47:33 -0700535 RETURN_IF_HWC_ERROR_FOR("getChangedCompositionTypes", error, displayId, BAD_INDEX);
Dan Stoza9e56aa02015-11-02 13:00:03 -0800536
Peiyong Line9d809e2020-04-14 13:10:48 -0700537 auto displayRequests = static_cast<hal::DisplayRequest>(0);
Lloyd Pique66d68602019-02-13 14:23:31 -0800538 android::HWComposer::DeviceRequestedChanges::LayerRequests layerRequests;
Dan Stoza9e56aa02015-11-02 13:00:03 -0800539 layerRequests.reserve(numRequests);
Lloyd Pique66d68602019-02-13 14:23:31 -0800540 error = hwcDisplay->getRequests(&displayRequests, &layerRequests);
Dominik Laskowskifc2c0322018-04-19 14:47:33 -0700541 RETURN_IF_HWC_ERROR_FOR("getRequests", error, displayId, BAD_INDEX);
Dan Stoza9e56aa02015-11-02 13:00:03 -0800542
Lloyd Pique66d68602019-02-13 14:23:31 -0800543 outChanges->emplace(DeviceRequestedChanges{std::move(changedTypes), std::move(displayRequests),
544 std::move(layerRequests)});
Dan Stoza9e56aa02015-11-02 13:00:03 -0800545
546 error = hwcDisplay->acceptChanges();
Dominik Laskowskifc2c0322018-04-19 14:47:33 -0700547 RETURN_IF_HWC_ERROR_FOR("acceptChanges", error, displayId, BAD_INDEX);
Dan Stoza9e56aa02015-11-02 13:00:03 -0800548
549 return NO_ERROR;
550}
551
Dominik Laskowski075d3172018-05-24 15:50:06 -0700552sp<Fence> HWComposer::getPresentFence(DisplayId displayId) const {
Dominik Laskowskifc2c0322018-04-19 14:47:33 -0700553 RETURN_IF_INVALID_DISPLAY(displayId, Fence::NO_FENCE);
Dominik Laskowski075d3172018-05-24 15:50:06 -0700554 return mDisplayData.at(displayId).lastPresentFence;
Jesse Hall851cfe82013-03-20 13:44:00 -0700555}
556
Dominik Laskowski075d3172018-05-24 15:50:06 -0700557sp<Fence> HWComposer::getLayerReleaseFence(DisplayId displayId, HWC2::Layer* layer) const {
Dominik Laskowskifc2c0322018-04-19 14:47:33 -0700558 RETURN_IF_INVALID_DISPLAY(displayId, Fence::NO_FENCE);
Tim Murray2d3f8b82019-12-04 16:24:17 -0800559 const auto& displayFences = mDisplayData.at(displayId).releaseFences;
560 auto fence = displayFences.find(layer);
561 if (fence == displayFences.end()) {
Dan Stoza9e56aa02015-11-02 13:00:03 -0800562 ALOGV("getLayerReleaseFence: Release fence not found");
563 return Fence::NO_FENCE;
Riley Andrews03414a12014-07-01 14:22:59 -0700564 }
Tim Murray2d3f8b82019-12-04 16:24:17 -0800565 return fence->second;
Riley Andrews03414a12014-07-01 14:22:59 -0700566}
567
Dominik Laskowski075d3172018-05-24 15:50:06 -0700568status_t HWComposer::presentAndGetReleaseFences(DisplayId displayId) {
Dan Stoza9e56aa02015-11-02 13:00:03 -0800569 ATRACE_CALL();
Mathias Agopian3e8b8532012-05-13 20:42:01 -0700570
Dominik Laskowskifc2c0322018-04-19 14:47:33 -0700571 RETURN_IF_INVALID_DISPLAY(displayId, BAD_INDEX);
Pablo Ceballosd814cf22015-09-11 14:37:39 -0700572
Dan Stoza9e56aa02015-11-02 13:00:03 -0800573 auto& displayData = mDisplayData[displayId];
574 auto& hwcDisplay = displayData.hwcDisplay;
Fabien Sanglard249c0ae2017-06-19 19:22:36 -0700575
576 if (displayData.validateWasSkipped) {
Chia-I Wuae5a6b82017-10-10 09:09:22 -0700577 // explicitly flush all pending commands
Peiyong Line9d809e2020-04-14 13:10:48 -0700578 auto error = static_cast<hal::Error>(mComposer->executeCommands());
Peiyong Linbdd08cc2019-12-17 21:35:14 -0800579 RETURN_IF_HWC_ERROR_FOR("executeCommands", error, displayId, UNKNOWN_ERROR);
Dominik Laskowskifc2c0322018-04-19 14:47:33 -0700580 RETURN_IF_HWC_ERROR_FOR("present", displayData.presentError, displayId, UNKNOWN_ERROR);
Fabien Sanglard249c0ae2017-06-19 19:22:36 -0700581 return NO_ERROR;
582 }
583
Fabien Sanglard11d0fc32016-12-01 15:43:01 -0800584 auto error = hwcDisplay->present(&displayData.lastPresentFence);
Dominik Laskowskifc2c0322018-04-19 14:47:33 -0700585 RETURN_IF_HWC_ERROR_FOR("present", error, displayId, UNKNOWN_ERROR);
Mathias Agopian3e8b8532012-05-13 20:42:01 -0700586
Steven Thomas94e35b92017-07-26 18:48:28 -0700587 std::unordered_map<HWC2::Layer*, sp<Fence>> releaseFences;
Dan Stoza9e56aa02015-11-02 13:00:03 -0800588 error = hwcDisplay->getReleaseFences(&releaseFences);
Dominik Laskowskifc2c0322018-04-19 14:47:33 -0700589 RETURN_IF_HWC_ERROR_FOR("getReleaseFences", error, displayId, UNKNOWN_ERROR);
Dan Stoza9e56aa02015-11-02 13:00:03 -0800590
591 displayData.releaseFences = std::move(releaseFences);
592
593 return NO_ERROR;
Mathias Agopiana350ff92010-08-10 17:14:02 -0700594}
595
Dominik Laskowski075d3172018-05-24 15:50:06 -0700596status_t HWComposer::setPowerMode(DisplayId displayId, int32_t intMode) {
Dominik Laskowskifc2c0322018-04-19 14:47:33 -0700597 RETURN_IF_INVALID_DISPLAY(displayId, BAD_INDEX);
598
Dominik Laskowskic1f18f62018-06-13 15:17:55 -0700599 const auto& displayData = mDisplayData[displayId];
600 if (displayData.isVirtual) {
Dominik Laskowskifc2c0322018-04-19 14:47:33 -0700601 LOG_DISPLAY_ERROR(displayId, "Invalid operation on virtual display");
602 return INVALID_OPERATION;
Dan Stoza9e56aa02015-11-02 13:00:03 -0800603 }
Mathias Agopian3e8b8532012-05-13 20:42:01 -0700604
Peiyong Line9d809e2020-04-14 13:10:48 -0700605 auto mode = static_cast<hal::PowerMode>(intMode);
606 if (mode == hal::PowerMode::OFF) {
607 setVsyncEnabled(displayId, hal::Vsync::DISABLE);
Dan Stoza9e56aa02015-11-02 13:00:03 -0800608 }
609
Dominik Laskowskic1f18f62018-06-13 15:17:55 -0700610 auto& hwcDisplay = displayData.hwcDisplay;
Dan Stoza9e56aa02015-11-02 13:00:03 -0800611 switch (mode) {
Peiyong Line9d809e2020-04-14 13:10:48 -0700612 case hal::PowerMode::OFF:
613 case hal::PowerMode::ON:
Dan Stoza9e56aa02015-11-02 13:00:03 -0800614 ALOGV("setPowerMode: Calling HWC %s", to_string(mode).c_str());
615 {
616 auto error = hwcDisplay->setPowerMode(mode);
Peiyong Line9d809e2020-04-14 13:10:48 -0700617 if (error != hal::Error::NONE) {
618 LOG_HWC_ERROR(("setPowerMode(" + to_string(mode) + ")").c_str(), error,
619 displayId);
Peiyong Lin306e4992018-05-07 16:18:22 -0700620 }
Mathias Agopianda27af92012-09-13 18:17:13 -0700621 }
Dan Stoza9e56aa02015-11-02 13:00:03 -0800622 break;
Peiyong Line9d809e2020-04-14 13:10:48 -0700623 case hal::PowerMode::DOZE:
624 case hal::PowerMode::DOZE_SUSPEND:
Dan Stoza9e56aa02015-11-02 13:00:03 -0800625 ALOGV("setPowerMode: Calling HWC %s", to_string(mode).c_str());
626 {
627 bool supportsDoze = false;
628 auto error = hwcDisplay->supportsDoze(&supportsDoze);
Peiyong Line9d809e2020-04-14 13:10:48 -0700629 if (error != hal::Error::NONE) {
Peiyong Lin306e4992018-05-07 16:18:22 -0700630 LOG_HWC_ERROR("supportsDoze", error, displayId);
631 }
Dominik Laskowskifc2c0322018-04-19 14:47:33 -0700632
Dan Stoza9e56aa02015-11-02 13:00:03 -0800633 if (!supportsDoze) {
Peiyong Line9d809e2020-04-14 13:10:48 -0700634 mode = hal::PowerMode::ON;
Dan Stoza9e56aa02015-11-02 13:00:03 -0800635 }
636
637 error = hwcDisplay->setPowerMode(mode);
Peiyong Line9d809e2020-04-14 13:10:48 -0700638 if (error != hal::Error::NONE) {
639 LOG_HWC_ERROR(("setPowerMode(" + to_string(mode) + ")").c_str(), error,
640 displayId);
Peiyong Lin306e4992018-05-07 16:18:22 -0700641 }
Dan Stoza9e56aa02015-11-02 13:00:03 -0800642 }
643 break;
644 default:
645 ALOGV("setPowerMode: Not calling HWC");
646 break;
Mathias Agopianda27af92012-09-13 18:17:13 -0700647 }
Dan Stoza9e56aa02015-11-02 13:00:03 -0800648
649 return NO_ERROR;
650}
651
Ady Abraham3a77a7b2019-12-02 18:46:59 -0800652status_t HWComposer::setActiveConfigWithConstraints(
Peiyong Line9d809e2020-04-14 13:10:48 -0700653 DisplayId displayId, size_t configId, const hal::VsyncPeriodChangeConstraints& constraints,
654 hal::VsyncPeriodChangeTimeline* outTimeline) {
Dominik Laskowskifc2c0322018-04-19 14:47:33 -0700655 RETURN_IF_INVALID_DISPLAY(displayId, BAD_INDEX);
Dan Stoza9e56aa02015-11-02 13:00:03 -0800656
657 auto& displayData = mDisplayData[displayId];
658 if (displayData.configMap.count(configId) == 0) {
Dominik Laskowskifc2c0322018-04-19 14:47:33 -0700659 LOG_DISPLAY_ERROR(displayId, ("Invalid config " + std::to_string(configId)).c_str());
Dan Stoza9e56aa02015-11-02 13:00:03 -0800660 return BAD_INDEX;
661 }
662
Ady Abraham3a77a7b2019-12-02 18:46:59 -0800663 auto error =
664 displayData.hwcDisplay->setActiveConfigWithConstraints(displayData.configMap[configId],
665 constraints, outTimeline);
Dominik Laskowskifc2c0322018-04-19 14:47:33 -0700666 RETURN_IF_HWC_ERROR(error, displayId, UNKNOWN_ERROR);
Dan Stoza9e56aa02015-11-02 13:00:03 -0800667 return NO_ERROR;
668}
669
Dominik Laskowski075d3172018-05-24 15:50:06 -0700670status_t HWComposer::setColorTransform(DisplayId displayId, const mat4& transform) {
Dominik Laskowskifc2c0322018-04-19 14:47:33 -0700671 RETURN_IF_INVALID_DISPLAY(displayId, BAD_INDEX);
Dan Stoza9f26a9c2016-06-22 14:51:09 -0700672
673 auto& displayData = mDisplayData[displayId];
674 bool isIdentity = transform == mat4();
Peiyong Line9d809e2020-04-14 13:10:48 -0700675 auto error = displayData.hwcDisplay
676 ->setColorTransform(transform,
677 isIdentity ? hal::ColorTransform::IDENTITY
678 : hal::ColorTransform::ARBITRARY_MATRIX);
Dominik Laskowskifc2c0322018-04-19 14:47:33 -0700679 RETURN_IF_HWC_ERROR(error, displayId, UNKNOWN_ERROR);
Dan Stoza9f26a9c2016-06-22 14:51:09 -0700680 return NO_ERROR;
681}
682
Dominik Laskowski075d3172018-05-24 15:50:06 -0700683void HWComposer::disconnectDisplay(DisplayId displayId) {
Dominik Laskowskic1f18f62018-06-13 15:17:55 -0700684 RETURN_IF_INVALID_DISPLAY(displayId);
Dan Stoza9e56aa02015-11-02 13:00:03 -0800685 auto& displayData = mDisplayData[displayId];
686
Dan Stoza9e56aa02015-11-02 13:00:03 -0800687 // If this was a virtual display, add its slot back for reuse by future
688 // virtual displays
Dominik Laskowskic1f18f62018-06-13 15:17:55 -0700689 if (displayData.isVirtual) {
Dominik Laskowski075d3172018-05-24 15:50:06 -0700690 mFreeVirtualDisplayIds.insert(displayId);
Dan Stoza9e56aa02015-11-02 13:00:03 -0800691 ++mRemainingHwcVirtualDisplays;
692 }
693
Dominik Laskowski7e045462018-05-30 13:02:02 -0700694 const auto hwcDisplayId = displayData.hwcDisplay->getId();
Dominik Laskowski075d3172018-05-24 15:50:06 -0700695
696 // TODO(b/74619554): Select internal/external display from remaining displays.
697 if (hwcDisplayId == mInternalHwcDisplayId) {
698 mInternalHwcDisplayId.reset();
699 } else if (hwcDisplayId == mExternalHwcDisplayId) {
700 mExternalHwcDisplayId.reset();
701 }
Peiyong Linbdd08cc2019-12-17 21:35:14 -0800702 mPhysicalDisplayIdMap.erase(hwcDisplayId);
703 mDisplayData.erase(displayId);
Dan Stoza9e56aa02015-11-02 13:00:03 -0800704}
705
Dominik Laskowski075d3172018-05-24 15:50:06 -0700706status_t HWComposer::setOutputBuffer(DisplayId displayId, const sp<Fence>& acquireFence,
707 const sp<GraphicBuffer>& buffer) {
Dominik Laskowskifc2c0322018-04-19 14:47:33 -0700708 RETURN_IF_INVALID_DISPLAY(displayId, BAD_INDEX);
Dominik Laskowskic1f18f62018-06-13 15:17:55 -0700709 const auto& displayData = mDisplayData[displayId];
Dan Stoza9e56aa02015-11-02 13:00:03 -0800710
Dominik Laskowskic1f18f62018-06-13 15:17:55 -0700711 if (!displayData.isVirtual) {
Dominik Laskowskifc2c0322018-04-19 14:47:33 -0700712 LOG_DISPLAY_ERROR(displayId, "Invalid operation on physical display");
Dan Stoza9e56aa02015-11-02 13:00:03 -0800713 return INVALID_OPERATION;
714 }
715
Dominik Laskowskic1f18f62018-06-13 15:17:55 -0700716 auto error = displayData.hwcDisplay->setOutputBuffer(buffer, acquireFence);
Dominik Laskowskifc2c0322018-04-19 14:47:33 -0700717 RETURN_IF_HWC_ERROR(error, displayId, UNKNOWN_ERROR);
Dan Stoza9e56aa02015-11-02 13:00:03 -0800718 return NO_ERROR;
719}
720
Dominik Laskowski075d3172018-05-24 15:50:06 -0700721void HWComposer::clearReleaseFences(DisplayId displayId) {
Dominik Laskowskifc2c0322018-04-19 14:47:33 -0700722 RETURN_IF_INVALID_DISPLAY(displayId);
Dan Stoza9e56aa02015-11-02 13:00:03 -0800723 mDisplayData[displayId].releaseFences.clear();
Mathias Agopian3e8b8532012-05-13 20:42:01 -0700724}
725
Dominik Laskowski075d3172018-05-24 15:50:06 -0700726status_t HWComposer::getHdrCapabilities(DisplayId displayId, HdrCapabilities* outCapabilities) {
Dominik Laskowskifc2c0322018-04-19 14:47:33 -0700727 RETURN_IF_INVALID_DISPLAY(displayId, BAD_INDEX);
Dan Stozac4f471e2016-03-24 09:31:08 -0700728
729 auto& hwcDisplay = mDisplayData[displayId].hwcDisplay;
Peiyong Lin62665892018-04-16 11:07:44 -0700730 auto error = hwcDisplay->getHdrCapabilities(outCapabilities);
Dominik Laskowskifc2c0322018-04-19 14:47:33 -0700731 RETURN_IF_HWC_ERROR(error, displayId, UNKNOWN_ERROR);
Peiyong Lin62665892018-04-16 11:07:44 -0700732 return NO_ERROR;
Dan Stozac4f471e2016-03-24 09:31:08 -0700733}
734
Dominik Laskowski075d3172018-05-24 15:50:06 -0700735int32_t HWComposer::getSupportedPerFrameMetadata(DisplayId displayId) const {
Dominik Laskowskifc2c0322018-04-19 14:47:33 -0700736 RETURN_IF_INVALID_DISPLAY(displayId, 0);
Dominik Laskowski075d3172018-05-24 15:50:06 -0700737 return mDisplayData.at(displayId).hwcDisplay->getSupportedPerFrameMetadata();
Peiyong Lin0ac5f4e2018-04-19 22:06:34 -0700738}
739
Dominik Laskowski075d3172018-05-24 15:50:06 -0700740std::vector<ui::RenderIntent> HWComposer::getRenderIntents(DisplayId displayId,
741 ui::ColorMode colorMode) const {
Dominik Laskowskifc2c0322018-04-19 14:47:33 -0700742 RETURN_IF_INVALID_DISPLAY(displayId, {});
Peiyong Lin0e7a7912018-04-05 14:36:36 -0700743
744 std::vector<ui::RenderIntent> renderIntents;
Dominik Laskowski075d3172018-05-24 15:50:06 -0700745 auto error = mDisplayData.at(displayId).hwcDisplay->getRenderIntents(colorMode, &renderIntents);
Dominik Laskowskifc2c0322018-04-19 14:47:33 -0700746 RETURN_IF_HWC_ERROR(error, displayId, {});
Peiyong Lin0e7a7912018-04-05 14:36:36 -0700747 return renderIntents;
748}
749
Dominik Laskowski075d3172018-05-24 15:50:06 -0700750mat4 HWComposer::getDataspaceSaturationMatrix(DisplayId displayId, ui::Dataspace dataspace) {
Dominik Laskowskifc2c0322018-04-19 14:47:33 -0700751 RETURN_IF_INVALID_DISPLAY(displayId, {});
Peiyong Lin0e7a7912018-04-05 14:36:36 -0700752
753 mat4 matrix;
754 auto error = mDisplayData[displayId].hwcDisplay->getDataspaceSaturationMatrix(dataspace,
755 &matrix);
Dominik Laskowskifc2c0322018-04-19 14:47:33 -0700756 RETURN_IF_HWC_ERROR(error, displayId, {});
Peiyong Lin0e7a7912018-04-05 14:36:36 -0700757 return matrix;
758}
759
Kevin DuBois9c0a1762018-10-16 13:32:31 -0700760status_t HWComposer::getDisplayedContentSamplingAttributes(DisplayId displayId,
761 ui::PixelFormat* outFormat,
762 ui::Dataspace* outDataspace,
763 uint8_t* outComponentMask) {
764 RETURN_IF_INVALID_DISPLAY(displayId, BAD_INDEX);
765 const auto error =
766 mDisplayData[displayId]
767 .hwcDisplay->getDisplayedContentSamplingAttributes(outFormat, outDataspace,
768 outComponentMask);
Peiyong Line9d809e2020-04-14 13:10:48 -0700769 if (error == hal::Error::UNSUPPORTED) RETURN_IF_HWC_ERROR(error, displayId, INVALID_OPERATION);
Kevin DuBois9c0a1762018-10-16 13:32:31 -0700770 RETURN_IF_HWC_ERROR(error, displayId, UNKNOWN_ERROR);
771 return NO_ERROR;
772}
773
Kevin DuBois74e53772018-11-19 10:52:38 -0800774status_t HWComposer::setDisplayContentSamplingEnabled(DisplayId displayId, bool enabled,
775 uint8_t componentMask, uint64_t maxFrames) {
776 RETURN_IF_INVALID_DISPLAY(displayId, BAD_INDEX);
777 const auto error =
778 mDisplayData[displayId].hwcDisplay->setDisplayContentSamplingEnabled(enabled,
779 componentMask,
780 maxFrames);
781
Peiyong Line9d809e2020-04-14 13:10:48 -0700782 if (error == hal::Error::UNSUPPORTED) RETURN_IF_HWC_ERROR(error, displayId, INVALID_OPERATION);
783 if (error == hal::Error::BAD_PARAMETER) RETURN_IF_HWC_ERROR(error, displayId, BAD_VALUE);
Kevin DuBois74e53772018-11-19 10:52:38 -0800784 RETURN_IF_HWC_ERROR(error, displayId, UNKNOWN_ERROR);
785 return NO_ERROR;
786}
787
Kevin DuBois1d4249a2018-08-29 10:45:14 -0700788status_t HWComposer::getDisplayedContentSample(DisplayId displayId, uint64_t maxFrames,
789 uint64_t timestamp, DisplayedFrameStats* outStats) {
790 RETURN_IF_INVALID_DISPLAY(displayId, BAD_INDEX);
791 const auto error =
792 mDisplayData[displayId].hwcDisplay->getDisplayedContentSample(maxFrames, timestamp,
793 outStats);
794 RETURN_IF_HWC_ERROR(error, displayId, UNKNOWN_ERROR);
795 return NO_ERROR;
796}
797
Dan Gittik57e63c52019-01-18 16:37:54 +0000798status_t HWComposer::setDisplayBrightness(DisplayId displayId, float brightness) {
799 RETURN_IF_INVALID_DISPLAY(displayId, BAD_INDEX);
800 const auto error = mDisplayData[displayId].hwcDisplay->setDisplayBrightness(brightness);
Peiyong Line9d809e2020-04-14 13:10:48 -0700801 if (error == hal::Error::UNSUPPORTED) {
Dan Gittik57e63c52019-01-18 16:37:54 +0000802 RETURN_IF_HWC_ERROR(error, displayId, INVALID_OPERATION);
803 }
Peiyong Line9d809e2020-04-14 13:10:48 -0700804 if (error == hal::Error::BAD_PARAMETER) {
Dan Gittik57e63c52019-01-18 16:37:54 +0000805 RETURN_IF_HWC_ERROR(error, displayId, BAD_VALUE);
806 }
807 RETURN_IF_HWC_ERROR(error, displayId, UNKNOWN_ERROR);
808 return NO_ERROR;
809}
810
Hendrik Wagenaar87670ff2017-02-01 12:10:46 -0800811bool HWComposer::isUsingVrComposer() const {
Hendrik Wagenaar87670ff2017-02-01 12:10:46 -0800812 return getComposer()->isUsingVrComposer();
Hendrik Wagenaar87670ff2017-02-01 12:10:46 -0800813}
814
Galia Peycheva5492cb52019-10-30 14:13:16 +0100815status_t HWComposer::setAutoLowLatencyMode(DisplayId displayId, bool on) {
816 RETURN_IF_INVALID_DISPLAY(displayId, BAD_INDEX);
817 const auto error = mDisplayData[displayId].hwcDisplay->setAutoLowLatencyMode(on);
Peiyong Line9d809e2020-04-14 13:10:48 -0700818 if (error == hal::Error::UNSUPPORTED) {
Galia Peycheva5492cb52019-10-30 14:13:16 +0100819 RETURN_IF_HWC_ERROR(error, displayId, INVALID_OPERATION);
820 }
Peiyong Line9d809e2020-04-14 13:10:48 -0700821 if (error == hal::Error::BAD_PARAMETER) {
Galia Peycheva5492cb52019-10-30 14:13:16 +0100822 RETURN_IF_HWC_ERROR(error, displayId, BAD_VALUE);
823 }
824 RETURN_IF_HWC_ERROR(error, displayId, UNKNOWN_ERROR);
825 return NO_ERROR;
826}
827
828status_t HWComposer::getSupportedContentTypes(
Peiyong Line9d809e2020-04-14 13:10:48 -0700829 DisplayId displayId, std::vector<hal::ContentType>* outSupportedContentTypes) {
Galia Peycheva5492cb52019-10-30 14:13:16 +0100830 RETURN_IF_INVALID_DISPLAY(displayId, BAD_INDEX);
831 const auto error =
832 mDisplayData[displayId].hwcDisplay->getSupportedContentTypes(outSupportedContentTypes);
833
834 RETURN_IF_HWC_ERROR(error, displayId, UNKNOWN_ERROR);
835
836 return NO_ERROR;
837}
838
Peiyong Line9d809e2020-04-14 13:10:48 -0700839status_t HWComposer::setContentType(DisplayId displayId, hal::ContentType contentType) {
Galia Peycheva5492cb52019-10-30 14:13:16 +0100840 RETURN_IF_INVALID_DISPLAY(displayId, BAD_INDEX);
841 const auto error = mDisplayData[displayId].hwcDisplay->setContentType(contentType);
Peiyong Line9d809e2020-04-14 13:10:48 -0700842 if (error == hal::Error::UNSUPPORTED) {
Galia Peycheva5492cb52019-10-30 14:13:16 +0100843 RETURN_IF_HWC_ERROR(error, displayId, INVALID_OPERATION);
844 }
Peiyong Line9d809e2020-04-14 13:10:48 -0700845 if (error == hal::Error::BAD_PARAMETER) {
Galia Peycheva5492cb52019-10-30 14:13:16 +0100846 RETURN_IF_HWC_ERROR(error, displayId, BAD_VALUE);
847 }
848 RETURN_IF_HWC_ERROR(error, displayId, UNKNOWN_ERROR);
849
850 return NO_ERROR;
851}
852
Lloyd Pique4603f3c2020-02-11 12:06:56 -0800853const std::unordered_map<std::string, bool>& HWComposer::getSupportedLayerGenericMetadata() const {
854 return mSupportedLayerGenericMetadata;
855}
856
Yiwei Zhang5434a782018-12-05 18:06:32 -0800857void HWComposer::dump(std::string& result) const {
Peiyong Linbdd08cc2019-12-17 21:35:14 -0800858 result.append(mComposer->dumpDebugInfo());
Mathias Agopian83727852010-09-23 18:13:21 -0700859}
860
Peiyong Line9d809e2020-04-14 13:10:48 -0700861std::optional<DisplayId> HWComposer::toPhysicalDisplayId(hal::HWDisplayId hwcDisplayId) const {
Dominik Laskowski075d3172018-05-24 15:50:06 -0700862 if (const auto it = mPhysicalDisplayIdMap.find(hwcDisplayId);
863 it != mPhysicalDisplayIdMap.end()) {
864 return it->second;
865 }
866 return {};
867}
868
Peiyong Line9d809e2020-04-14 13:10:48 -0700869std::optional<hal::HWDisplayId> HWComposer::fromPhysicalDisplayId(DisplayId displayId) const {
Dominik Laskowski075d3172018-05-24 15:50:06 -0700870 if (const auto it = mDisplayData.find(displayId);
871 it != mDisplayData.end() && !it->second.isVirtual) {
872 return it->second.hwcDisplay->getId();
873 }
874 return {};
875}
876
Peiyong Line9d809e2020-04-14 13:10:48 -0700877bool HWComposer::shouldIgnoreHotplugConnect(hal::HWDisplayId hwcDisplayId,
Marin Shalamanovbdd59152020-02-14 15:30:06 +0100878 bool hasDisplayIdentificationData) const {
Dominik Laskowski075d3172018-05-24 15:50:06 -0700879 if (isUsingVrComposer() && mInternalHwcDisplayId) {
880 ALOGE("Ignoring connection of external display %" PRIu64 " in VR mode", hwcDisplayId);
Marin Shalamanovbdd59152020-02-14 15:30:06 +0100881 return true;
Steven Thomas6e8f7062017-11-22 14:15:29 -0800882 }
Dominik Laskowski075d3172018-05-24 15:50:06 -0700883
Marin Shalamanovbdd59152020-02-14 15:30:06 +0100884 if (mHasMultiDisplaySupport && !hasDisplayIdentificationData) {
Dominik Laskowski075d3172018-05-24 15:50:06 -0700885 ALOGE("Ignoring connection of display %" PRIu64 " without identification data",
886 hwcDisplayId);
Marin Shalamanovbdd59152020-02-14 15:30:06 +0100887 return true;
Dominik Laskowski075d3172018-05-24 15:50:06 -0700888 }
889
Marin Shalamanovbdd59152020-02-14 15:30:06 +0100890 if (!mHasMultiDisplaySupport && mInternalHwcDisplayId && mExternalHwcDisplayId) {
Dominik Laskowski075d3172018-05-24 15:50:06 -0700891 ALOGE("Ignoring connection of tertiary display %" PRIu64, hwcDisplayId);
Marin Shalamanovbdd59152020-02-14 15:30:06 +0100892 return true;
893 }
894
895 return false;
896}
897
Peiyong Line9d809e2020-04-14 13:10:48 -0700898std::optional<DisplayIdentificationInfo> HWComposer::onHotplugConnect(
899 hal::HWDisplayId hwcDisplayId) {
Marin Shalamanovbdd59152020-02-14 15:30:06 +0100900 std::optional<DisplayIdentificationInfo> info;
901 if (const auto displayId = toPhysicalDisplayId(hwcDisplayId)) {
902 info = DisplayIdentificationInfo{.id = *displayId,
903 .name = std::string(),
904 .deviceProductInfo = std::nullopt};
Dominik Laskowski075d3172018-05-24 15:50:06 -0700905 } else {
Marin Shalamanovbdd59152020-02-14 15:30:06 +0100906 uint8_t port;
907 DisplayIdentificationData data;
908 const bool hasDisplayIdentificationData =
909 getDisplayIdentificationData(hwcDisplayId, &port, &data);
910 if (mPhysicalDisplayIdMap.empty()) {
911 mHasMultiDisplaySupport = hasDisplayIdentificationData;
912 ALOGI("Switching to %s multi-display mode",
913 mHasMultiDisplaySupport ? "generalized" : "legacy");
914 }
915
916 if (shouldIgnoreHotplugConnect(hwcDisplayId, hasDisplayIdentificationData)) {
917 return {};
918 }
919
920 info = [this, hwcDisplayId, &port, &data, hasDisplayIdentificationData] {
921 const bool isPrimary = !mInternalHwcDisplayId;
922 if (mHasMultiDisplaySupport) {
923 if (const auto info = parseDisplayIdentificationData(port, data)) {
924 return *info;
925 }
926 ALOGE("Failed to parse identification data for display %" PRIu64, hwcDisplayId);
927 } else {
928 ALOGW_IF(hasDisplayIdentificationData,
929 "Ignoring identification data for display %" PRIu64, hwcDisplayId);
930 port = isPrimary ? HWC_DISPLAY_PRIMARY : HWC_DISPLAY_EXTERNAL;
931 }
932
933 return DisplayIdentificationInfo{.id = getFallbackDisplayId(port),
934 .name = isPrimary ? "Internal display"
935 : "External display",
936 .deviceProductInfo = std::nullopt};
937 }();
Dominik Laskowski075d3172018-05-24 15:50:06 -0700938 }
939
Marin Shalamanovbdd59152020-02-14 15:30:06 +0100940 if (!isConnected(info->id)) {
941 allocatePhysicalDisplay(hwcDisplayId, info->id);
942 }
943 return info;
944}
945
946std::optional<DisplayIdentificationInfo> HWComposer::onHotplugDisconnect(
Peiyong Line9d809e2020-04-14 13:10:48 -0700947 hal::HWDisplayId hwcDisplayId) {
Marin Shalamanovbdd59152020-02-14 15:30:06 +0100948 const auto displayId = toPhysicalDisplayId(hwcDisplayId);
949 if (!displayId) {
950 ALOGE("Ignoring disconnection of invalid HWC display %" PRIu64, hwcDisplayId);
951 return {};
Dominik Laskowski075d3172018-05-24 15:50:06 -0700952 }
953
Marin Shalamanovbdd59152020-02-14 15:30:06 +0100954 // The display will later be destroyed by a call to
955 // destroyDisplay(). For now we just mark it disconnected.
956 if (isConnected(*displayId)) {
957 mDisplayData[*displayId].hwcDisplay->setConnected(false);
958 } else {
959 ALOGW("Attempted to disconnect unknown display %" PRIu64, hwcDisplayId);
960 }
961 // The cleanup of Disconnect is handled through HWComposer::disconnectDisplay
962 // via SurfaceFlinger's onHotplugReceived callback handling
963 return DisplayIdentificationInfo{.id = *displayId,
964 .name = std::string(),
Marin Shalamanovf5de90d2019-10-08 10:57:25 +0200965 .deviceProductInfo = std::nullopt};
Steven Thomas6e8f7062017-11-22 14:15:29 -0800966}
967
Peiyong Linbdd08cc2019-12-17 21:35:14 -0800968void HWComposer::loadCapabilities() {
Peiyong Line9d809e2020-04-14 13:10:48 -0700969 static_assert(sizeof(hal::Capability) == sizeof(int32_t), "Capability size has changed");
Peiyong Linbdd08cc2019-12-17 21:35:14 -0800970 auto capabilities = mComposer->getCapabilities();
971 for (auto capability : capabilities) {
Peiyong Line9d809e2020-04-14 13:10:48 -0700972 mCapabilities.emplace(static_cast<hal::Capability>(capability));
Peiyong Linbdd08cc2019-12-17 21:35:14 -0800973 }
974}
975
Lloyd Pique4603f3c2020-02-11 12:06:56 -0800976void HWComposer::loadLayerMetadataSupport() {
977 mSupportedLayerGenericMetadata.clear();
978
979 std::vector<Hwc2::IComposerClient::LayerGenericMetadataKey> supportedMetadataKeyInfo;
980 const auto error = mComposer->getLayerGenericMetadataKeys(&supportedMetadataKeyInfo);
981 if (error != hardware::graphics::composer::V2_4::Error::NONE) {
982 ALOGE("%s: %s failed: %s (%d)", __FUNCTION__, "getLayerGenericMetadataKeys",
983 toString(error).c_str(), static_cast<int32_t>(error));
984 return;
985 }
986
987 for (const auto& [name, mandatory] : supportedMetadataKeyInfo) {
988 mSupportedLayerGenericMetadata.emplace(name, mandatory);
989 }
990}
991
Peiyong Linbdd08cc2019-12-17 21:35:14 -0800992uint32_t HWComposer::getMaxVirtualDisplayCount() const {
993 return mComposer->getMaxVirtualDisplayCount();
994}
995
Lloyd Pique441d5042018-10-18 16:49:51 -0700996} // namespace impl
Dominik Laskowskif9750f22018-06-06 12:24:53 -0700997} // namespace android
Ady Abrahamb0dbdaa2020-01-06 16:19:42 -0800998
999// TODO(b/129481165): remove the #pragma below and fix conversion issues
1000#pragma clang diagnostic pop // ignored "-Wconversion"