blob: 4344a8deeccde44ec2f578f0f36c0513a019746a [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
Peiyong Lin65248e02020-04-18 21:15:07 -0700596status_t HWComposer::setPowerMode(DisplayId displayId, hal::PowerMode mode) {
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 if (mode == hal::PowerMode::OFF) {
606 setVsyncEnabled(displayId, hal::Vsync::DISABLE);
Dan Stoza9e56aa02015-11-02 13:00:03 -0800607 }
608
Dominik Laskowskic1f18f62018-06-13 15:17:55 -0700609 auto& hwcDisplay = displayData.hwcDisplay;
Dan Stoza9e56aa02015-11-02 13:00:03 -0800610 switch (mode) {
Peiyong Line9d809e2020-04-14 13:10:48 -0700611 case hal::PowerMode::OFF:
612 case hal::PowerMode::ON:
Dan Stoza9e56aa02015-11-02 13:00:03 -0800613 ALOGV("setPowerMode: Calling HWC %s", to_string(mode).c_str());
614 {
615 auto error = hwcDisplay->setPowerMode(mode);
Peiyong Line9d809e2020-04-14 13:10:48 -0700616 if (error != hal::Error::NONE) {
617 LOG_HWC_ERROR(("setPowerMode(" + to_string(mode) + ")").c_str(), error,
618 displayId);
Peiyong Lin306e4992018-05-07 16:18:22 -0700619 }
Mathias Agopianda27af92012-09-13 18:17:13 -0700620 }
Dan Stoza9e56aa02015-11-02 13:00:03 -0800621 break;
Peiyong Line9d809e2020-04-14 13:10:48 -0700622 case hal::PowerMode::DOZE:
623 case hal::PowerMode::DOZE_SUSPEND:
Dan Stoza9e56aa02015-11-02 13:00:03 -0800624 ALOGV("setPowerMode: Calling HWC %s", to_string(mode).c_str());
625 {
626 bool supportsDoze = false;
627 auto error = hwcDisplay->supportsDoze(&supportsDoze);
Peiyong Line9d809e2020-04-14 13:10:48 -0700628 if (error != hal::Error::NONE) {
Peiyong Lin306e4992018-05-07 16:18:22 -0700629 LOG_HWC_ERROR("supportsDoze", error, displayId);
630 }
Dominik Laskowskifc2c0322018-04-19 14:47:33 -0700631
Dan Stoza9e56aa02015-11-02 13:00:03 -0800632 if (!supportsDoze) {
Peiyong Line9d809e2020-04-14 13:10:48 -0700633 mode = hal::PowerMode::ON;
Dan Stoza9e56aa02015-11-02 13:00:03 -0800634 }
635
636 error = hwcDisplay->setPowerMode(mode);
Peiyong Line9d809e2020-04-14 13:10:48 -0700637 if (error != hal::Error::NONE) {
638 LOG_HWC_ERROR(("setPowerMode(" + to_string(mode) + ")").c_str(), error,
639 displayId);
Peiyong Lin306e4992018-05-07 16:18:22 -0700640 }
Dan Stoza9e56aa02015-11-02 13:00:03 -0800641 }
642 break;
643 default:
644 ALOGV("setPowerMode: Not calling HWC");
645 break;
Mathias Agopianda27af92012-09-13 18:17:13 -0700646 }
Dan Stoza9e56aa02015-11-02 13:00:03 -0800647
648 return NO_ERROR;
649}
650
Ady Abraham3a77a7b2019-12-02 18:46:59 -0800651status_t HWComposer::setActiveConfigWithConstraints(
Peiyong Line9d809e2020-04-14 13:10:48 -0700652 DisplayId displayId, size_t configId, const hal::VsyncPeriodChangeConstraints& constraints,
653 hal::VsyncPeriodChangeTimeline* outTimeline) {
Dominik Laskowskifc2c0322018-04-19 14:47:33 -0700654 RETURN_IF_INVALID_DISPLAY(displayId, BAD_INDEX);
Dan Stoza9e56aa02015-11-02 13:00:03 -0800655
656 auto& displayData = mDisplayData[displayId];
657 if (displayData.configMap.count(configId) == 0) {
Dominik Laskowskifc2c0322018-04-19 14:47:33 -0700658 LOG_DISPLAY_ERROR(displayId, ("Invalid config " + std::to_string(configId)).c_str());
Dan Stoza9e56aa02015-11-02 13:00:03 -0800659 return BAD_INDEX;
660 }
661
Ady Abraham3a77a7b2019-12-02 18:46:59 -0800662 auto error =
663 displayData.hwcDisplay->setActiveConfigWithConstraints(displayData.configMap[configId],
664 constraints, outTimeline);
Dominik Laskowskifc2c0322018-04-19 14:47:33 -0700665 RETURN_IF_HWC_ERROR(error, displayId, UNKNOWN_ERROR);
Dan Stoza9e56aa02015-11-02 13:00:03 -0800666 return NO_ERROR;
667}
668
Dominik Laskowski075d3172018-05-24 15:50:06 -0700669status_t HWComposer::setColorTransform(DisplayId displayId, const mat4& transform) {
Dominik Laskowskifc2c0322018-04-19 14:47:33 -0700670 RETURN_IF_INVALID_DISPLAY(displayId, BAD_INDEX);
Dan Stoza9f26a9c2016-06-22 14:51:09 -0700671
672 auto& displayData = mDisplayData[displayId];
673 bool isIdentity = transform == mat4();
Peiyong Line9d809e2020-04-14 13:10:48 -0700674 auto error = displayData.hwcDisplay
675 ->setColorTransform(transform,
676 isIdentity ? hal::ColorTransform::IDENTITY
677 : hal::ColorTransform::ARBITRARY_MATRIX);
Dominik Laskowskifc2c0322018-04-19 14:47:33 -0700678 RETURN_IF_HWC_ERROR(error, displayId, UNKNOWN_ERROR);
Dan Stoza9f26a9c2016-06-22 14:51:09 -0700679 return NO_ERROR;
680}
681
Dominik Laskowski075d3172018-05-24 15:50:06 -0700682void HWComposer::disconnectDisplay(DisplayId displayId) {
Dominik Laskowskic1f18f62018-06-13 15:17:55 -0700683 RETURN_IF_INVALID_DISPLAY(displayId);
Dan Stoza9e56aa02015-11-02 13:00:03 -0800684 auto& displayData = mDisplayData[displayId];
685
Dan Stoza9e56aa02015-11-02 13:00:03 -0800686 // If this was a virtual display, add its slot back for reuse by future
687 // virtual displays
Dominik Laskowskic1f18f62018-06-13 15:17:55 -0700688 if (displayData.isVirtual) {
Dominik Laskowski075d3172018-05-24 15:50:06 -0700689 mFreeVirtualDisplayIds.insert(displayId);
Dan Stoza9e56aa02015-11-02 13:00:03 -0800690 ++mRemainingHwcVirtualDisplays;
691 }
692
Dominik Laskowski7e045462018-05-30 13:02:02 -0700693 const auto hwcDisplayId = displayData.hwcDisplay->getId();
Dominik Laskowski075d3172018-05-24 15:50:06 -0700694
695 // TODO(b/74619554): Select internal/external display from remaining displays.
696 if (hwcDisplayId == mInternalHwcDisplayId) {
697 mInternalHwcDisplayId.reset();
698 } else if (hwcDisplayId == mExternalHwcDisplayId) {
699 mExternalHwcDisplayId.reset();
700 }
Peiyong Linbdd08cc2019-12-17 21:35:14 -0800701 mPhysicalDisplayIdMap.erase(hwcDisplayId);
702 mDisplayData.erase(displayId);
Dan Stoza9e56aa02015-11-02 13:00:03 -0800703}
704
Dominik Laskowski075d3172018-05-24 15:50:06 -0700705status_t HWComposer::setOutputBuffer(DisplayId displayId, const sp<Fence>& acquireFence,
706 const sp<GraphicBuffer>& buffer) {
Dominik Laskowskifc2c0322018-04-19 14:47:33 -0700707 RETURN_IF_INVALID_DISPLAY(displayId, BAD_INDEX);
Dominik Laskowskic1f18f62018-06-13 15:17:55 -0700708 const auto& displayData = mDisplayData[displayId];
Dan Stoza9e56aa02015-11-02 13:00:03 -0800709
Dominik Laskowskic1f18f62018-06-13 15:17:55 -0700710 if (!displayData.isVirtual) {
Dominik Laskowskifc2c0322018-04-19 14:47:33 -0700711 LOG_DISPLAY_ERROR(displayId, "Invalid operation on physical display");
Dan Stoza9e56aa02015-11-02 13:00:03 -0800712 return INVALID_OPERATION;
713 }
714
Dominik Laskowskic1f18f62018-06-13 15:17:55 -0700715 auto error = displayData.hwcDisplay->setOutputBuffer(buffer, acquireFence);
Dominik Laskowskifc2c0322018-04-19 14:47:33 -0700716 RETURN_IF_HWC_ERROR(error, displayId, UNKNOWN_ERROR);
Dan Stoza9e56aa02015-11-02 13:00:03 -0800717 return NO_ERROR;
718}
719
Dominik Laskowski075d3172018-05-24 15:50:06 -0700720void HWComposer::clearReleaseFences(DisplayId displayId) {
Dominik Laskowskifc2c0322018-04-19 14:47:33 -0700721 RETURN_IF_INVALID_DISPLAY(displayId);
Dan Stoza9e56aa02015-11-02 13:00:03 -0800722 mDisplayData[displayId].releaseFences.clear();
Mathias Agopian3e8b8532012-05-13 20:42:01 -0700723}
724
Dominik Laskowski075d3172018-05-24 15:50:06 -0700725status_t HWComposer::getHdrCapabilities(DisplayId displayId, HdrCapabilities* outCapabilities) {
Dominik Laskowskifc2c0322018-04-19 14:47:33 -0700726 RETURN_IF_INVALID_DISPLAY(displayId, BAD_INDEX);
Dan Stozac4f471e2016-03-24 09:31:08 -0700727
728 auto& hwcDisplay = mDisplayData[displayId].hwcDisplay;
Peiyong Lin62665892018-04-16 11:07:44 -0700729 auto error = hwcDisplay->getHdrCapabilities(outCapabilities);
Dominik Laskowskifc2c0322018-04-19 14:47:33 -0700730 RETURN_IF_HWC_ERROR(error, displayId, UNKNOWN_ERROR);
Peiyong Lin62665892018-04-16 11:07:44 -0700731 return NO_ERROR;
Dan Stozac4f471e2016-03-24 09:31:08 -0700732}
733
Dominik Laskowski075d3172018-05-24 15:50:06 -0700734int32_t HWComposer::getSupportedPerFrameMetadata(DisplayId displayId) const {
Dominik Laskowskifc2c0322018-04-19 14:47:33 -0700735 RETURN_IF_INVALID_DISPLAY(displayId, 0);
Dominik Laskowski075d3172018-05-24 15:50:06 -0700736 return mDisplayData.at(displayId).hwcDisplay->getSupportedPerFrameMetadata();
Peiyong Lin0ac5f4e2018-04-19 22:06:34 -0700737}
738
Dominik Laskowski075d3172018-05-24 15:50:06 -0700739std::vector<ui::RenderIntent> HWComposer::getRenderIntents(DisplayId displayId,
740 ui::ColorMode colorMode) const {
Dominik Laskowskifc2c0322018-04-19 14:47:33 -0700741 RETURN_IF_INVALID_DISPLAY(displayId, {});
Peiyong Lin0e7a7912018-04-05 14:36:36 -0700742
743 std::vector<ui::RenderIntent> renderIntents;
Dominik Laskowski075d3172018-05-24 15:50:06 -0700744 auto error = mDisplayData.at(displayId).hwcDisplay->getRenderIntents(colorMode, &renderIntents);
Dominik Laskowskifc2c0322018-04-19 14:47:33 -0700745 RETURN_IF_HWC_ERROR(error, displayId, {});
Peiyong Lin0e7a7912018-04-05 14:36:36 -0700746 return renderIntents;
747}
748
Dominik Laskowski075d3172018-05-24 15:50:06 -0700749mat4 HWComposer::getDataspaceSaturationMatrix(DisplayId displayId, ui::Dataspace dataspace) {
Dominik Laskowskifc2c0322018-04-19 14:47:33 -0700750 RETURN_IF_INVALID_DISPLAY(displayId, {});
Peiyong Lin0e7a7912018-04-05 14:36:36 -0700751
752 mat4 matrix;
753 auto error = mDisplayData[displayId].hwcDisplay->getDataspaceSaturationMatrix(dataspace,
754 &matrix);
Dominik Laskowskifc2c0322018-04-19 14:47:33 -0700755 RETURN_IF_HWC_ERROR(error, displayId, {});
Peiyong Lin0e7a7912018-04-05 14:36:36 -0700756 return matrix;
757}
758
Kevin DuBois9c0a1762018-10-16 13:32:31 -0700759status_t HWComposer::getDisplayedContentSamplingAttributes(DisplayId displayId,
760 ui::PixelFormat* outFormat,
761 ui::Dataspace* outDataspace,
762 uint8_t* outComponentMask) {
763 RETURN_IF_INVALID_DISPLAY(displayId, BAD_INDEX);
764 const auto error =
765 mDisplayData[displayId]
766 .hwcDisplay->getDisplayedContentSamplingAttributes(outFormat, outDataspace,
767 outComponentMask);
Peiyong Line9d809e2020-04-14 13:10:48 -0700768 if (error == hal::Error::UNSUPPORTED) RETURN_IF_HWC_ERROR(error, displayId, INVALID_OPERATION);
Kevin DuBois9c0a1762018-10-16 13:32:31 -0700769 RETURN_IF_HWC_ERROR(error, displayId, UNKNOWN_ERROR);
770 return NO_ERROR;
771}
772
Kevin DuBois74e53772018-11-19 10:52:38 -0800773status_t HWComposer::setDisplayContentSamplingEnabled(DisplayId displayId, bool enabled,
774 uint8_t componentMask, uint64_t maxFrames) {
775 RETURN_IF_INVALID_DISPLAY(displayId, BAD_INDEX);
776 const auto error =
777 mDisplayData[displayId].hwcDisplay->setDisplayContentSamplingEnabled(enabled,
778 componentMask,
779 maxFrames);
780
Peiyong Line9d809e2020-04-14 13:10:48 -0700781 if (error == hal::Error::UNSUPPORTED) RETURN_IF_HWC_ERROR(error, displayId, INVALID_OPERATION);
782 if (error == hal::Error::BAD_PARAMETER) RETURN_IF_HWC_ERROR(error, displayId, BAD_VALUE);
Kevin DuBois74e53772018-11-19 10:52:38 -0800783 RETURN_IF_HWC_ERROR(error, displayId, UNKNOWN_ERROR);
784 return NO_ERROR;
785}
786
Kevin DuBois1d4249a2018-08-29 10:45:14 -0700787status_t HWComposer::getDisplayedContentSample(DisplayId displayId, uint64_t maxFrames,
788 uint64_t timestamp, DisplayedFrameStats* outStats) {
789 RETURN_IF_INVALID_DISPLAY(displayId, BAD_INDEX);
790 const auto error =
791 mDisplayData[displayId].hwcDisplay->getDisplayedContentSample(maxFrames, timestamp,
792 outStats);
793 RETURN_IF_HWC_ERROR(error, displayId, UNKNOWN_ERROR);
794 return NO_ERROR;
795}
796
Dan Gittik57e63c52019-01-18 16:37:54 +0000797status_t HWComposer::setDisplayBrightness(DisplayId displayId, float brightness) {
798 RETURN_IF_INVALID_DISPLAY(displayId, BAD_INDEX);
799 const auto error = mDisplayData[displayId].hwcDisplay->setDisplayBrightness(brightness);
Peiyong Line9d809e2020-04-14 13:10:48 -0700800 if (error == hal::Error::UNSUPPORTED) {
Dan Gittik57e63c52019-01-18 16:37:54 +0000801 RETURN_IF_HWC_ERROR(error, displayId, INVALID_OPERATION);
802 }
Peiyong Line9d809e2020-04-14 13:10:48 -0700803 if (error == hal::Error::BAD_PARAMETER) {
Dan Gittik57e63c52019-01-18 16:37:54 +0000804 RETURN_IF_HWC_ERROR(error, displayId, BAD_VALUE);
805 }
806 RETURN_IF_HWC_ERROR(error, displayId, UNKNOWN_ERROR);
807 return NO_ERROR;
808}
809
Hendrik Wagenaar87670ff2017-02-01 12:10:46 -0800810bool HWComposer::isUsingVrComposer() const {
Hendrik Wagenaar87670ff2017-02-01 12:10:46 -0800811 return getComposer()->isUsingVrComposer();
Hendrik Wagenaar87670ff2017-02-01 12:10:46 -0800812}
813
Galia Peycheva5492cb52019-10-30 14:13:16 +0100814status_t HWComposer::setAutoLowLatencyMode(DisplayId displayId, bool on) {
815 RETURN_IF_INVALID_DISPLAY(displayId, BAD_INDEX);
816 const auto error = mDisplayData[displayId].hwcDisplay->setAutoLowLatencyMode(on);
Peiyong Line9d809e2020-04-14 13:10:48 -0700817 if (error == hal::Error::UNSUPPORTED) {
Galia Peycheva5492cb52019-10-30 14:13:16 +0100818 RETURN_IF_HWC_ERROR(error, displayId, INVALID_OPERATION);
819 }
Peiyong Line9d809e2020-04-14 13:10:48 -0700820 if (error == hal::Error::BAD_PARAMETER) {
Galia Peycheva5492cb52019-10-30 14:13:16 +0100821 RETURN_IF_HWC_ERROR(error, displayId, BAD_VALUE);
822 }
823 RETURN_IF_HWC_ERROR(error, displayId, UNKNOWN_ERROR);
824 return NO_ERROR;
825}
826
827status_t HWComposer::getSupportedContentTypes(
Peiyong Line9d809e2020-04-14 13:10:48 -0700828 DisplayId displayId, std::vector<hal::ContentType>* outSupportedContentTypes) {
Galia Peycheva5492cb52019-10-30 14:13:16 +0100829 RETURN_IF_INVALID_DISPLAY(displayId, BAD_INDEX);
830 const auto error =
831 mDisplayData[displayId].hwcDisplay->getSupportedContentTypes(outSupportedContentTypes);
832
833 RETURN_IF_HWC_ERROR(error, displayId, UNKNOWN_ERROR);
834
835 return NO_ERROR;
836}
837
Peiyong Line9d809e2020-04-14 13:10:48 -0700838status_t HWComposer::setContentType(DisplayId displayId, hal::ContentType contentType) {
Galia Peycheva5492cb52019-10-30 14:13:16 +0100839 RETURN_IF_INVALID_DISPLAY(displayId, BAD_INDEX);
840 const auto error = mDisplayData[displayId].hwcDisplay->setContentType(contentType);
Peiyong Line9d809e2020-04-14 13:10:48 -0700841 if (error == hal::Error::UNSUPPORTED) {
Galia Peycheva5492cb52019-10-30 14:13:16 +0100842 RETURN_IF_HWC_ERROR(error, displayId, INVALID_OPERATION);
843 }
Peiyong Line9d809e2020-04-14 13:10:48 -0700844 if (error == hal::Error::BAD_PARAMETER) {
Galia Peycheva5492cb52019-10-30 14:13:16 +0100845 RETURN_IF_HWC_ERROR(error, displayId, BAD_VALUE);
846 }
847 RETURN_IF_HWC_ERROR(error, displayId, UNKNOWN_ERROR);
848
849 return NO_ERROR;
850}
851
Lloyd Pique4603f3c2020-02-11 12:06:56 -0800852const std::unordered_map<std::string, bool>& HWComposer::getSupportedLayerGenericMetadata() const {
853 return mSupportedLayerGenericMetadata;
854}
855
Yiwei Zhang5434a782018-12-05 18:06:32 -0800856void HWComposer::dump(std::string& result) const {
Peiyong Linbdd08cc2019-12-17 21:35:14 -0800857 result.append(mComposer->dumpDebugInfo());
Mathias Agopian83727852010-09-23 18:13:21 -0700858}
859
Peiyong Line9d809e2020-04-14 13:10:48 -0700860std::optional<DisplayId> HWComposer::toPhysicalDisplayId(hal::HWDisplayId hwcDisplayId) const {
Dominik Laskowski075d3172018-05-24 15:50:06 -0700861 if (const auto it = mPhysicalDisplayIdMap.find(hwcDisplayId);
862 it != mPhysicalDisplayIdMap.end()) {
863 return it->second;
864 }
865 return {};
866}
867
Peiyong Line9d809e2020-04-14 13:10:48 -0700868std::optional<hal::HWDisplayId> HWComposer::fromPhysicalDisplayId(DisplayId displayId) const {
Dominik Laskowski075d3172018-05-24 15:50:06 -0700869 if (const auto it = mDisplayData.find(displayId);
870 it != mDisplayData.end() && !it->second.isVirtual) {
871 return it->second.hwcDisplay->getId();
872 }
873 return {};
874}
875
Peiyong Line9d809e2020-04-14 13:10:48 -0700876bool HWComposer::shouldIgnoreHotplugConnect(hal::HWDisplayId hwcDisplayId,
Marin Shalamanovbdd59152020-02-14 15:30:06 +0100877 bool hasDisplayIdentificationData) const {
Dominik Laskowski075d3172018-05-24 15:50:06 -0700878 if (isUsingVrComposer() && mInternalHwcDisplayId) {
879 ALOGE("Ignoring connection of external display %" PRIu64 " in VR mode", hwcDisplayId);
Marin Shalamanovbdd59152020-02-14 15:30:06 +0100880 return true;
Steven Thomas6e8f7062017-11-22 14:15:29 -0800881 }
Dominik Laskowski075d3172018-05-24 15:50:06 -0700882
Marin Shalamanovbdd59152020-02-14 15:30:06 +0100883 if (mHasMultiDisplaySupport && !hasDisplayIdentificationData) {
Dominik Laskowski075d3172018-05-24 15:50:06 -0700884 ALOGE("Ignoring connection of display %" PRIu64 " without identification data",
885 hwcDisplayId);
Marin Shalamanovbdd59152020-02-14 15:30:06 +0100886 return true;
Dominik Laskowski075d3172018-05-24 15:50:06 -0700887 }
888
Marin Shalamanovbdd59152020-02-14 15:30:06 +0100889 if (!mHasMultiDisplaySupport && mInternalHwcDisplayId && mExternalHwcDisplayId) {
Dominik Laskowski075d3172018-05-24 15:50:06 -0700890 ALOGE("Ignoring connection of tertiary display %" PRIu64, hwcDisplayId);
Marin Shalamanovbdd59152020-02-14 15:30:06 +0100891 return true;
892 }
893
894 return false;
895}
896
Peiyong Line9d809e2020-04-14 13:10:48 -0700897std::optional<DisplayIdentificationInfo> HWComposer::onHotplugConnect(
898 hal::HWDisplayId hwcDisplayId) {
Marin Shalamanovbdd59152020-02-14 15:30:06 +0100899 std::optional<DisplayIdentificationInfo> info;
900 if (const auto displayId = toPhysicalDisplayId(hwcDisplayId)) {
901 info = DisplayIdentificationInfo{.id = *displayId,
902 .name = std::string(),
903 .deviceProductInfo = std::nullopt};
Dominik Laskowski075d3172018-05-24 15:50:06 -0700904 } else {
Marin Shalamanovbdd59152020-02-14 15:30:06 +0100905 uint8_t port;
906 DisplayIdentificationData data;
907 const bool hasDisplayIdentificationData =
908 getDisplayIdentificationData(hwcDisplayId, &port, &data);
909 if (mPhysicalDisplayIdMap.empty()) {
910 mHasMultiDisplaySupport = hasDisplayIdentificationData;
911 ALOGI("Switching to %s multi-display mode",
912 mHasMultiDisplaySupport ? "generalized" : "legacy");
913 }
914
915 if (shouldIgnoreHotplugConnect(hwcDisplayId, hasDisplayIdentificationData)) {
916 return {};
917 }
918
919 info = [this, hwcDisplayId, &port, &data, hasDisplayIdentificationData] {
920 const bool isPrimary = !mInternalHwcDisplayId;
921 if (mHasMultiDisplaySupport) {
922 if (const auto info = parseDisplayIdentificationData(port, data)) {
923 return *info;
924 }
925 ALOGE("Failed to parse identification data for display %" PRIu64, hwcDisplayId);
926 } else {
927 ALOGW_IF(hasDisplayIdentificationData,
928 "Ignoring identification data for display %" PRIu64, hwcDisplayId);
Peiyong Lin65248e02020-04-18 21:15:07 -0700929 port = isPrimary ? LEGACY_DISPLAY_TYPE_PRIMARY : LEGACY_DISPLAY_TYPE_EXTERNAL;
Marin Shalamanovbdd59152020-02-14 15:30:06 +0100930 }
931
932 return DisplayIdentificationInfo{.id = getFallbackDisplayId(port),
933 .name = isPrimary ? "Internal display"
934 : "External display",
935 .deviceProductInfo = std::nullopt};
936 }();
Dominik Laskowski075d3172018-05-24 15:50:06 -0700937 }
938
Marin Shalamanovbdd59152020-02-14 15:30:06 +0100939 if (!isConnected(info->id)) {
940 allocatePhysicalDisplay(hwcDisplayId, info->id);
941 }
942 return info;
943}
944
945std::optional<DisplayIdentificationInfo> HWComposer::onHotplugDisconnect(
Peiyong Line9d809e2020-04-14 13:10:48 -0700946 hal::HWDisplayId hwcDisplayId) {
Marin Shalamanovbdd59152020-02-14 15:30:06 +0100947 const auto displayId = toPhysicalDisplayId(hwcDisplayId);
948 if (!displayId) {
949 ALOGE("Ignoring disconnection of invalid HWC display %" PRIu64, hwcDisplayId);
950 return {};
Dominik Laskowski075d3172018-05-24 15:50:06 -0700951 }
952
Marin Shalamanovbdd59152020-02-14 15:30:06 +0100953 // The display will later be destroyed by a call to
954 // destroyDisplay(). For now we just mark it disconnected.
955 if (isConnected(*displayId)) {
956 mDisplayData[*displayId].hwcDisplay->setConnected(false);
957 } else {
958 ALOGW("Attempted to disconnect unknown display %" PRIu64, hwcDisplayId);
959 }
960 // The cleanup of Disconnect is handled through HWComposer::disconnectDisplay
961 // via SurfaceFlinger's onHotplugReceived callback handling
962 return DisplayIdentificationInfo{.id = *displayId,
963 .name = std::string(),
Marin Shalamanovf5de90d2019-10-08 10:57:25 +0200964 .deviceProductInfo = std::nullopt};
Steven Thomas6e8f7062017-11-22 14:15:29 -0800965}
966
Peiyong Linbdd08cc2019-12-17 21:35:14 -0800967void HWComposer::loadCapabilities() {
Peiyong Line9d809e2020-04-14 13:10:48 -0700968 static_assert(sizeof(hal::Capability) == sizeof(int32_t), "Capability size has changed");
Peiyong Linbdd08cc2019-12-17 21:35:14 -0800969 auto capabilities = mComposer->getCapabilities();
970 for (auto capability : capabilities) {
Peiyong Line9d809e2020-04-14 13:10:48 -0700971 mCapabilities.emplace(static_cast<hal::Capability>(capability));
Peiyong Linbdd08cc2019-12-17 21:35:14 -0800972 }
973}
974
Lloyd Pique4603f3c2020-02-11 12:06:56 -0800975void HWComposer::loadLayerMetadataSupport() {
976 mSupportedLayerGenericMetadata.clear();
977
978 std::vector<Hwc2::IComposerClient::LayerGenericMetadataKey> supportedMetadataKeyInfo;
979 const auto error = mComposer->getLayerGenericMetadataKeys(&supportedMetadataKeyInfo);
980 if (error != hardware::graphics::composer::V2_4::Error::NONE) {
981 ALOGE("%s: %s failed: %s (%d)", __FUNCTION__, "getLayerGenericMetadataKeys",
982 toString(error).c_str(), static_cast<int32_t>(error));
983 return;
984 }
985
986 for (const auto& [name, mandatory] : supportedMetadataKeyInfo) {
987 mSupportedLayerGenericMetadata.emplace(name, mandatory);
988 }
989}
990
Peiyong Linbdd08cc2019-12-17 21:35:14 -0800991uint32_t HWComposer::getMaxVirtualDisplayCount() const {
992 return mComposer->getMaxVirtualDisplayCount();
993}
994
Lloyd Pique441d5042018-10-18 16:49:51 -0700995} // namespace impl
Dominik Laskowskif9750f22018-06-06 12:24:53 -0700996} // namespace android
Ady Abrahamb0dbdaa2020-01-06 16:19:42 -0800997
998// TODO(b/129481165): remove the #pragma below and fix conversion issues
999#pragma clang diagnostic pop // ignored "-Wconversion"