blob: 038cec4aa5bc46a92c77f119fa6f1ba5e285d3cf [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
Dominik Laskowski5690bde2020-04-23 19:04:22 -070039#include "../Promise.h"
Mathias Agopian33ceeb32013-04-01 16:54:58 -070040#include "../SurfaceFlinger.h"
Lloyd Pique66d68602019-02-13 14:23:31 -080041#include "ComposerHal.h"
42#include "HWC2.h"
Mathias Agopiana350ff92010-08-10 17:14:02 -070043
Dominik Laskowskic1f18f62018-06-13 15:17:55 -070044#define LOG_HWC_DISPLAY_ERROR(hwcDisplayId, msg) \
45 ALOGE("%s failed for HWC display %" PRIu64 ": %s", __FUNCTION__, hwcDisplayId, msg)
46
Dominik Laskowskifc2c0322018-04-19 14:47:33 -070047#define LOG_DISPLAY_ERROR(displayId, msg) \
Dominik Laskowski34157762018-10-31 13:07:19 -070048 ALOGE("%s failed for display %s: %s", __FUNCTION__, to_string(displayId).c_str(), msg)
Dominik Laskowskifc2c0322018-04-19 14:47:33 -070049
Dominik Laskowski34157762018-10-31 13:07:19 -070050#define LOG_HWC_ERROR(what, error, displayId) \
51 ALOGE("%s: %s failed for display %s: %s (%d)", __FUNCTION__, what, \
52 to_string(displayId).c_str(), to_string(error).c_str(), static_cast<int32_t>(error))
Dominik Laskowskifc2c0322018-04-19 14:47:33 -070053
54#define RETURN_IF_INVALID_DISPLAY(displayId, ...) \
55 do { \
Dominik Laskowski075d3172018-05-24 15:50:06 -070056 if (mDisplayData.count(displayId) == 0) { \
Dominik Laskowskifc2c0322018-04-19 14:47:33 -070057 LOG_DISPLAY_ERROR(displayId, "Invalid display"); \
58 return __VA_ARGS__; \
59 } \
60 } while (false)
61
62#define RETURN_IF_HWC_ERROR_FOR(what, error, displayId, ...) \
63 do { \
Peiyong Line9d809e2020-04-14 13:10:48 -070064 if (error != hal::Error::NONE) { \
Dominik Laskowskifc2c0322018-04-19 14:47:33 -070065 LOG_HWC_ERROR(what, error, displayId); \
66 return __VA_ARGS__; \
67 } \
68 } while (false)
69
70#define RETURN_IF_HWC_ERROR(error, displayId, ...) \
71 RETURN_IF_HWC_ERROR_FOR(__FUNCTION__, error, displayId, __VA_ARGS__)
72
Peiyong Line9d809e2020-04-14 13:10:48 -070073namespace hal = android::hardware::graphics::composer::hal;
74
Peiyong Linbdd08cc2019-12-17 21:35:14 -080075namespace {
76
77using android::hardware::Return;
78using android::hardware::Void;
Peiyong Line9d809e2020-04-14 13:10:48 -070079using android::HWC2::ComposerCallback;
Peiyong Linbdd08cc2019-12-17 21:35:14 -080080
Peiyong Line9d809e2020-04-14 13:10:48 -070081class ComposerCallbackBridge : public hal::IComposerCallback {
Peiyong Linbdd08cc2019-12-17 21:35:14 -080082public:
Peiyong Line9d809e2020-04-14 13:10:48 -070083 ComposerCallbackBridge(ComposerCallback* callback, int32_t sequenceId,
Peiyong Linbdd08cc2019-12-17 21:35:14 -080084 bool vsyncSwitchingSupported)
85 : mCallback(callback),
86 mSequenceId(sequenceId),
87 mVsyncSwitchingSupported(vsyncSwitchingSupported) {}
88
Peiyong Line9d809e2020-04-14 13:10:48 -070089 android::hardware::Return<void> onHotplug(hal::HWDisplayId display,
90 hal::Connection conn) override {
91 mCallback->onHotplugReceived(mSequenceId, display, conn);
Peiyong Linbdd08cc2019-12-17 21:35:14 -080092 return android::hardware::Void();
93 }
94
Peiyong Line9d809e2020-04-14 13:10:48 -070095 android::hardware::Return<void> onRefresh(hal::HWDisplayId display) override {
Peiyong Linbdd08cc2019-12-17 21:35:14 -080096 mCallback->onRefreshReceived(mSequenceId, display);
97 return android::hardware::Void();
98 }
99
Peiyong Line9d809e2020-04-14 13:10:48 -0700100 android::hardware::Return<void> onVsync(hal::HWDisplayId display, int64_t timestamp) override {
Peiyong Linbdd08cc2019-12-17 21:35:14 -0800101 if (!mVsyncSwitchingSupported) {
102 mCallback->onVsyncReceived(mSequenceId, display, timestamp, std::nullopt);
103 } else {
104 ALOGW("Unexpected onVsync callback on composer >= 2.4, ignoring.");
105 }
106 return android::hardware::Void();
107 }
108
Peiyong Line9d809e2020-04-14 13:10:48 -0700109 android::hardware::Return<void> onVsync_2_4(hal::HWDisplayId display, int64_t timestamp,
110 hal::VsyncPeriodNanos vsyncPeriodNanos) override {
Peiyong Linbdd08cc2019-12-17 21:35:14 -0800111 if (mVsyncSwitchingSupported) {
Peiyong Linbdd08cc2019-12-17 21:35:14 -0800112 mCallback->onVsyncReceived(mSequenceId, display, timestamp,
113 std::make_optional(vsyncPeriodNanos));
114 } else {
115 ALOGW("Unexpected onVsync_2_4 callback on composer <= 2.3, ignoring.");
116 }
117 return android::hardware::Void();
118 }
119
120 android::hardware::Return<void> onVsyncPeriodTimingChanged(
Peiyong Line9d809e2020-04-14 13:10:48 -0700121 hal::HWDisplayId display,
122 const hal::VsyncPeriodChangeTimeline& updatedTimeline) override {
123 mCallback->onVsyncPeriodTimingChangedReceived(mSequenceId, display, updatedTimeline);
Peiyong Linbdd08cc2019-12-17 21:35:14 -0800124 return android::hardware::Void();
125 }
126
Peiyong Line9d809e2020-04-14 13:10:48 -0700127 android::hardware::Return<void> onSeamlessPossible(hal::HWDisplayId display) override {
Ady Abrahamb0433bc2020-01-08 17:31:06 -0800128 mCallback->onSeamlessPossible(mSequenceId, display);
129 return android::hardware::Void();
130 }
131
Peiyong Linbdd08cc2019-12-17 21:35:14 -0800132private:
Peiyong Line9d809e2020-04-14 13:10:48 -0700133 ComposerCallback* mCallback;
Peiyong Linbdd08cc2019-12-17 21:35:14 -0800134 const int32_t mSequenceId;
135 const bool mVsyncSwitchingSupported;
136};
137
138} // namespace
139
Mathias Agopiana350ff92010-08-10 17:14:02 -0700140namespace android {
Jesse Hall5880cc52012-06-05 23:40:32 -0700141
Lloyd Pique441d5042018-10-18 16:49:51 -0700142HWComposer::~HWComposer() = default;
143
144namespace impl {
145
Peiyong Linbdd08cc2019-12-17 21:35:14 -0800146HWComposer::HWComposer(std::unique_ptr<Hwc2::Composer> composer) : mComposer(std::move(composer)) {
Peiyong Linbdd08cc2019-12-17 21:35:14 -0800147}
148
149HWComposer::HWComposer(const std::string& composerServiceName)
150 : mComposer(std::make_unique<Hwc2::impl::Composer>(composerServiceName)) {
Peiyong Linbdd08cc2019-12-17 21:35:14 -0800151}
Mathias Agopianbef42c52013-08-21 17:45:46 -0700152
Dominik Laskowskib04f98a2018-11-07 21:07:16 -0800153HWComposer::~HWComposer() {
154 mDisplayData.clear();
155}
Dan Stoza9e56aa02015-11-02 13:00:03 -0800156
Lloyd Pique4603f3c2020-02-11 12:06:56 -0800157void HWComposer::setConfiguration(HWC2::ComposerCallback* callback, int32_t sequenceId) {
158 loadCapabilities();
159 loadLayerMetadataSupport();
160
Peiyong Linbdd08cc2019-12-17 21:35:14 -0800161 if (mRegisteredCallback) {
162 ALOGW("Callback already registered. Ignored extra registration attempt.");
163 return;
164 }
165 mRegisteredCallback = true;
166 sp<ComposerCallbackBridge> callbackBridge(
167 new ComposerCallbackBridge(callback, sequenceId,
168 mComposer->isVsyncPeriodSwitchSupported()));
169 mComposer->registerCallback(callbackBridge);
Dan Stoza9e56aa02015-11-02 13:00:03 -0800170}
171
Peiyong Line9d809e2020-04-14 13:10:48 -0700172bool HWComposer::getDisplayIdentificationData(hal::HWDisplayId hwcDisplayId, uint8_t* outPort,
Dominik Laskowskie9ef7c42018-03-12 19:34:30 -0700173 DisplayIdentificationData* outData) const {
Peiyong Line9d809e2020-04-14 13:10:48 -0700174 const auto error = static_cast<hal::Error>(
Peiyong Linbdd08cc2019-12-17 21:35:14 -0800175 mComposer->getDisplayIdentificationData(hwcDisplayId, outPort, outData));
Peiyong Line9d809e2020-04-14 13:10:48 -0700176 if (error != hal::Error::NONE) {
177 if (error != hal::Error::UNSUPPORTED) {
Chia-I Wud0aff9d2018-06-21 13:39:09 +0800178 LOG_HWC_DISPLAY_ERROR(hwcDisplayId, to_string(error).c_str());
179 }
Dominik Laskowskie9ef7c42018-03-12 19:34:30 -0700180 return false;
181 }
182 return true;
183}
184
Peiyong Line9d809e2020-04-14 13:10:48 -0700185bool HWComposer::hasCapability(hal::Capability capability) const {
Peiyong Linbdd08cc2019-12-17 21:35:14 -0800186 return mCapabilities.count(capability) > 0;
Dan Stoza9f26a9c2016-06-22 14:51:09 -0700187}
188
Dominik Laskowski1162e472020-04-02 19:02:47 -0700189bool HWComposer::hasDisplayCapability(DisplayId displayId,
Peiyong Line9d809e2020-04-14 13:10:48 -0700190 hal::DisplayCapability capability) const {
Dominik Laskowski1162e472020-04-02 19:02:47 -0700191 RETURN_IF_INVALID_DISPLAY(displayId, false);
192 return mDisplayData.at(displayId).hwcDisplay->getCapabilities().count(capability) > 0;
Peiyong Lined531a32018-10-26 18:27:56 -0700193}
194
Peiyong Line9d809e2020-04-14 13:10:48 -0700195std::optional<DisplayIdentificationInfo> HWComposer::onHotplug(hal::HWDisplayId hwcDisplayId,
196 hal::Connection connection) {
Marin Shalamanovbdd59152020-02-14 15:30:06 +0100197 switch (connection) {
Peiyong Line9d809e2020-04-14 13:10:48 -0700198 case hal::Connection::CONNECTED:
Marin Shalamanovbdd59152020-02-14 15:30:06 +0100199 return onHotplugConnect(hwcDisplayId);
Peiyong Line9d809e2020-04-14 13:10:48 -0700200 case hal::Connection::DISCONNECTED:
Marin Shalamanovbdd59152020-02-14 15:30:06 +0100201 return onHotplugDisconnect(hwcDisplayId);
Peiyong Line9d809e2020-04-14 13:10:48 -0700202 case hal::Connection::INVALID:
Dominik Laskowski075d3172018-05-24 15:50:06 -0700203 return {};
Dominik Laskowskie9ef7c42018-03-12 19:34:30 -0700204 }
Andy McFaddenb0d1dd32012-09-10 14:08:09 -0700205}
206
Peiyong Line9d809e2020-04-14 13:10:48 -0700207bool HWComposer::onVsync(hal::HWDisplayId hwcDisplayId, int64_t timestamp) {
Dominik Laskowski075d3172018-05-24 15:50:06 -0700208 const auto displayId = toPhysicalDisplayId(hwcDisplayId);
209 if (!displayId) {
210 LOG_HWC_DISPLAY_ERROR(hwcDisplayId, "Invalid HWC display");
Steven Thomas94e35b92017-07-26 18:48:28 -0700211 return false;
Jesse Hall1bd20e02012-08-29 10:47:52 -0700212 }
Jesse Hall1bd20e02012-08-29 10:47:52 -0700213
Dominik Laskowski075d3172018-05-24 15:50:06 -0700214 RETURN_IF_INVALID_DISPLAY(*displayId, false);
Dominik Laskowskic1f18f62018-06-13 15:17:55 -0700215
Dominik Laskowski1af47932018-11-12 10:20:46 -0800216 auto& displayData = mDisplayData[*displayId];
Dominik Laskowskic1f18f62018-06-13 15:17:55 -0700217 if (displayData.isVirtual) {
Dominik Laskowski075d3172018-05-24 15:50:06 -0700218 LOG_DISPLAY_ERROR(*displayId, "Invalid operation on virtual display");
Steven Thomas94e35b92017-07-26 18:48:28 -0700219 return false;
Jesse Hall1bd20e02012-08-29 10:47:52 -0700220 }
221
Dan Stoza9e56aa02015-11-02 13:00:03 -0800222 {
Dominik Laskowski1af47932018-11-12 10:20:46 -0800223 std::lock_guard lock(displayData.lastHwVsyncLock);
Jesse Hall1bd20e02012-08-29 10:47:52 -0700224
Dan Stoza9e56aa02015-11-02 13:00:03 -0800225 // There have been reports of HWCs that signal several vsync events
226 // with the same timestamp when turning the display off and on. This
227 // is a bug in the HWC implementation, but filter the extra events
228 // out here so they don't cause havoc downstream.
Dominik Laskowski1af47932018-11-12 10:20:46 -0800229 if (timestamp == displayData.lastHwVsync) {
Dominik Laskowski34157762018-10-31 13:07:19 -0700230 ALOGW("Ignoring duplicate VSYNC event from HWC for display %s (t=%" PRId64 ")",
231 to_string(*displayId).c_str(), timestamp);
Steven Thomas94e35b92017-07-26 18:48:28 -0700232 return false;
Dan Stoza9e56aa02015-11-02 13:00:03 -0800233 }
234
Dominik Laskowski1af47932018-11-12 10:20:46 -0800235 displayData.lastHwVsync = timestamp;
Jesse Hall1c569c42013-04-05 13:44:52 -0700236 }
Dan Stoza9e56aa02015-11-02 13:00:03 -0800237
Dominik Laskowski34157762018-10-31 13:07:19 -0700238 const auto tag = "HW_VSYNC_" + to_string(*displayId);
Dominik Laskowski1af47932018-11-12 10:20:46 -0800239 ATRACE_INT(tag.c_str(), displayData.vsyncTraceToggle);
240 displayData.vsyncTraceToggle = !displayData.vsyncTraceToggle;
Dan Stoza9e56aa02015-11-02 13:00:03 -0800241
Steven Thomas94e35b92017-07-26 18:48:28 -0700242 return true;
Jesse Hall1c569c42013-04-05 13:44:52 -0700243}
244
Dominik Laskowski075d3172018-05-24 15:50:06 -0700245std::optional<DisplayId> HWComposer::allocateVirtualDisplay(uint32_t width, uint32_t height,
246 ui::PixelFormat* format) {
Dan Stoza9e56aa02015-11-02 13:00:03 -0800247 if (mRemainingHwcVirtualDisplays == 0) {
Dominik Laskowskif3749f82018-06-13 15:49:25 -0700248 ALOGE("%s: No remaining virtual displays", __FUNCTION__);
Dominik Laskowski075d3172018-05-24 15:50:06 -0700249 return {};
Mathias Agopiane60b0682012-08-21 23:34:09 -0700250 }
Mathias Agopiane60b0682012-08-21 23:34:09 -0700251
Fabien Sanglardc8e387e2017-03-10 10:30:28 -0800252 if (SurfaceFlinger::maxVirtualDisplaySize != 0 &&
253 (width > SurfaceFlinger::maxVirtualDisplaySize ||
254 height > SurfaceFlinger::maxVirtualDisplaySize)) {
Dominik Laskowskif3749f82018-06-13 15:49:25 -0700255 ALOGE("%s: Display size %ux%u exceeds maximum dimension of %" PRIu64, __FUNCTION__, width,
256 height, SurfaceFlinger::maxVirtualDisplaySize);
Dominik Laskowski075d3172018-05-24 15:50:06 -0700257 return {};
Fabien Sanglarde29055f2017-03-08 11:36:46 -0800258 }
Peiyong Line9d809e2020-04-14 13:10:48 -0700259 hal::HWDisplayId hwcDisplayId = 0;
260 const auto error = static_cast<hal::Error>(
Peiyong Linbdd08cc2019-12-17 21:35:14 -0800261 mComposer->createVirtualDisplay(width, height, format, &hwcDisplayId));
Peiyong Line9d809e2020-04-14 13:10:48 -0700262 if (error != hal::Error::NONE) {
Dominik Laskowskif3749f82018-06-13 15:49:25 -0700263 ALOGE("%s: Failed to create HWC virtual display", __FUNCTION__);
Dominik Laskowski075d3172018-05-24 15:50:06 -0700264 return {};
Mathias Agopiane60b0682012-08-21 23:34:09 -0700265 }
Dan Stoza9e56aa02015-11-02 13:00:03 -0800266
Peiyong Linbdd08cc2019-12-17 21:35:14 -0800267 auto display = std::make_unique<HWC2::impl::Display>(*mComposer.get(), mCapabilities,
Peiyong Line9d809e2020-04-14 13:10:48 -0700268 hwcDisplayId, hal::DisplayType::VIRTUAL);
Peiyong Linbdd08cc2019-12-17 21:35:14 -0800269 display->setConnected(true);
270
Dominik Laskowski075d3172018-05-24 15:50:06 -0700271 DisplayId displayId;
272 if (mFreeVirtualDisplayIds.empty()) {
273 displayId = getVirtualDisplayId(mNextVirtualDisplayId++);
Dan Stoza9e56aa02015-11-02 13:00:03 -0800274 } else {
Dominik Laskowski075d3172018-05-24 15:50:06 -0700275 displayId = *mFreeVirtualDisplayIds.begin();
276 mFreeVirtualDisplayIds.erase(displayId);
Mathias Agopiane60b0682012-08-21 23:34:09 -0700277 }
Dan Stoza9e56aa02015-11-02 13:00:03 -0800278
Dominik Laskowski075d3172018-05-24 15:50:06 -0700279 auto& displayData = mDisplayData[displayId];
Peiyong Linbdd08cc2019-12-17 21:35:14 -0800280 displayData.hwcDisplay = std::move(display);
Dominik Laskowskic1f18f62018-06-13 15:17:55 -0700281 displayData.isVirtual = true;
Dan Stoza9e56aa02015-11-02 13:00:03 -0800282
283 --mRemainingHwcVirtualDisplays;
Dominik Laskowski075d3172018-05-24 15:50:06 -0700284 return displayId;
Mathias Agopiane60b0682012-08-21 23:34:09 -0700285}
286
Peiyong Line9d809e2020-04-14 13:10:48 -0700287void HWComposer::allocatePhysicalDisplay(hal::HWDisplayId hwcDisplayId, DisplayId displayId) {
Marin Shalamanovbdd59152020-02-14 15:30:06 +0100288 if (!mInternalHwcDisplayId) {
289 mInternalHwcDisplayId = hwcDisplayId;
290 } else if (mInternalHwcDisplayId != hwcDisplayId && !mExternalHwcDisplayId) {
291 mExternalHwcDisplayId = hwcDisplayId;
292 }
293
294 auto& displayData = mDisplayData[displayId];
295 auto newDisplay =
296 std::make_unique<HWC2::impl::Display>(*mComposer.get(), mCapabilities, hwcDisplayId,
Peiyong Line9d809e2020-04-14 13:10:48 -0700297 hal::DisplayType::PHYSICAL);
Marin Shalamanovbdd59152020-02-14 15:30:06 +0100298 newDisplay->setConnected(true);
299 displayData.hwcDisplay = std::move(newDisplay);
300 mPhysicalDisplayIdMap[hwcDisplayId] = displayId;
301}
302
Dominik Laskowski075d3172018-05-24 15:50:06 -0700303HWC2::Layer* HWComposer::createLayer(DisplayId displayId) {
Dominik Laskowskifc2c0322018-04-19 14:47:33 -0700304 RETURN_IF_INVALID_DISPLAY(displayId, nullptr);
305
Steven Thomas94e35b92017-07-26 18:48:28 -0700306 HWC2::Layer* layer;
Peiyong Linbdd08cc2019-12-17 21:35:14 -0800307 auto error = mDisplayData[displayId].hwcDisplay->createLayer(&layer);
Dominik Laskowskifc2c0322018-04-19 14:47:33 -0700308 RETURN_IF_HWC_ERROR(error, displayId, nullptr);
Dan Stoza9e56aa02015-11-02 13:00:03 -0800309 return layer;
310}
311
Dominik Laskowski075d3172018-05-24 15:50:06 -0700312void HWComposer::destroyLayer(DisplayId displayId, HWC2::Layer* layer) {
Dominik Laskowskifc2c0322018-04-19 14:47:33 -0700313 RETURN_IF_INVALID_DISPLAY(displayId);
314
Peiyong Linbdd08cc2019-12-17 21:35:14 -0800315 auto error = mDisplayData[displayId].hwcDisplay->destroyLayer(layer);
Dominik Laskowskifc2c0322018-04-19 14:47:33 -0700316 RETURN_IF_HWC_ERROR(error, displayId);
Steven Thomas94e35b92017-07-26 18:48:28 -0700317}
318
Dominik Laskowski075d3172018-05-24 15:50:06 -0700319nsecs_t HWComposer::getRefreshTimestamp(DisplayId displayId) const {
320 RETURN_IF_INVALID_DISPLAY(displayId, 0);
Dominik Laskowski1af47932018-11-12 10:20:46 -0800321 const auto& displayData = mDisplayData.at(displayId);
Mathias Agopiand3ee2312012-08-02 14:01:42 -0700322 // this returns the last refresh timestamp.
323 // if the last one is not available, we estimate it based on
324 // the refresh period and whatever closest timestamp we have.
Dominik Laskowski1af47932018-11-12 10:20:46 -0800325 std::lock_guard lock(displayData.lastHwVsyncLock);
Mathias Agopiand3ee2312012-08-02 14:01:42 -0700326 nsecs_t now = systemTime(CLOCK_MONOTONIC);
Ady Abraham3a77a7b2019-12-02 18:46:59 -0800327 auto vsyncPeriodNanos = getDisplayVsyncPeriod(displayId);
328 return now - ((now - displayData.lastHwVsync) % vsyncPeriodNanos);
Mathias Agopian3eb38cb2012-04-03 22:09:52 -0700329}
330
Dominik Laskowski075d3172018-05-24 15:50:06 -0700331bool HWComposer::isConnected(DisplayId displayId) const {
Dominik Laskowskifc2c0322018-04-19 14:47:33 -0700332 RETURN_IF_INVALID_DISPLAY(displayId, false);
Dominik Laskowski075d3172018-05-24 15:50:06 -0700333 return mDisplayData.at(displayId).hwcDisplay->isConnected();
Mathias Agopian9c6e2972011-09-20 17:21:56 -0700334}
335
Dominik Laskowski075d3172018-05-24 15:50:06 -0700336std::vector<std::shared_ptr<const HWC2::Display::Config>> HWComposer::getConfigs(
337 DisplayId displayId) const {
Dominik Laskowskifc2c0322018-04-19 14:47:33 -0700338 RETURN_IF_INVALID_DISPLAY(displayId, {});
339
Dominik Laskowski075d3172018-05-24 15:50:06 -0700340 const auto& displayData = mDisplayData.at(displayId);
341 auto configs = displayData.hwcDisplay->getConfigs();
Dan Stoza9e56aa02015-11-02 13:00:03 -0800342 if (displayData.configMap.empty()) {
343 for (size_t i = 0; i < configs.size(); ++i) {
344 displayData.configMap[i] = configs[i];
Mathias Agopianda27af92012-09-13 18:17:13 -0700345 }
346 }
Dan Stoza9e56aa02015-11-02 13:00:03 -0800347 return configs;
Mathias Agopianda27af92012-09-13 18:17:13 -0700348}
349
Dominik Laskowski075d3172018-05-24 15:50:06 -0700350std::shared_ptr<const HWC2::Display::Config> HWComposer::getActiveConfig(
351 DisplayId displayId) const {
Dominik Laskowskifc2c0322018-04-19 14:47:33 -0700352 RETURN_IF_INVALID_DISPLAY(displayId, nullptr);
353
Dan Stoza9e56aa02015-11-02 13:00:03 -0800354 std::shared_ptr<const HWC2::Display::Config> config;
Dominik Laskowski075d3172018-05-24 15:50:06 -0700355 auto error = mDisplayData.at(displayId).hwcDisplay->getActiveConfig(&config);
Peiyong Line9d809e2020-04-14 13:10:48 -0700356 if (error == hal::Error::BAD_CONFIG) {
Dominik Laskowskifc2c0322018-04-19 14:47:33 -0700357 LOG_DISPLAY_ERROR(displayId, "No active config");
Dan Stoza9e56aa02015-11-02 13:00:03 -0800358 return nullptr;
Dominik Laskowskifc2c0322018-04-19 14:47:33 -0700359 }
360
361 RETURN_IF_HWC_ERROR(error, displayId, nullptr);
362
363 if (!config) {
364 LOG_DISPLAY_ERROR(displayId, "Unknown config");
Dan Stoza9e56aa02015-11-02 13:00:03 -0800365 return nullptr;
366 }
367
368 return config;
Mathias Agopiana350ff92010-08-10 17:14:02 -0700369}
370
Ady Abraham3a77a7b2019-12-02 18:46:59 -0800371// Composer 2.4
372
Dominik Laskowski55c85402020-01-21 16:25:47 -0800373DisplayConnectionType HWComposer::getDisplayConnectionType(DisplayId displayId) const {
374 RETURN_IF_INVALID_DISPLAY(displayId, DisplayConnectionType::Internal);
375 const auto& hwcDisplay = mDisplayData.at(displayId).hwcDisplay;
376
377 DisplayConnectionType type;
378 const auto error = hwcDisplay->getConnectionType(&type);
379
380 const auto FALLBACK_TYPE = hwcDisplay->getId() == mInternalHwcDisplayId
381 ? DisplayConnectionType::Internal
382 : DisplayConnectionType::External;
383
384 RETURN_IF_HWC_ERROR(error, displayId, FALLBACK_TYPE);
385 return type;
386}
387
Ady Abraham3a77a7b2019-12-02 18:46:59 -0800388bool HWComposer::isVsyncPeriodSwitchSupported(DisplayId displayId) const {
Dominik Laskowski55c85402020-01-21 16:25:47 -0800389 RETURN_IF_INVALID_DISPLAY(displayId, false);
Ady Abraham3a77a7b2019-12-02 18:46:59 -0800390 return mDisplayData.at(displayId).hwcDisplay->isVsyncPeriodSwitchSupported();
391}
392
393nsecs_t HWComposer::getDisplayVsyncPeriod(DisplayId displayId) const {
Dominik Laskowski55c85402020-01-21 16:25:47 -0800394 RETURN_IF_INVALID_DISPLAY(displayId, 0);
395
Ady Abraham3a77a7b2019-12-02 18:46:59 -0800396 nsecs_t vsyncPeriodNanos;
397 auto error = mDisplayData.at(displayId).hwcDisplay->getDisplayVsyncPeriod(&vsyncPeriodNanos);
Dominik Laskowski55c85402020-01-21 16:25:47 -0800398 RETURN_IF_HWC_ERROR(error, displayId, 0);
Ady Abraham3a77a7b2019-12-02 18:46:59 -0800399 return vsyncPeriodNanos;
400}
401
Dominik Laskowski075d3172018-05-24 15:50:06 -0700402int HWComposer::getActiveConfigIndex(DisplayId displayId) const {
Dominik Laskowskif3749f82018-06-13 15:49:25 -0700403 RETURN_IF_INVALID_DISPLAY(displayId, -1);
404
Lloyd Pique3c085a02018-05-09 19:38:32 -0700405 int index;
Dominik Laskowski075d3172018-05-24 15:50:06 -0700406 auto error = mDisplayData.at(displayId).hwcDisplay->getActiveConfigIndex(&index);
Peiyong Line9d809e2020-04-14 13:10:48 -0700407 if (error == hal::Error::BAD_CONFIG) {
Dominik Laskowskif3749f82018-06-13 15:49:25 -0700408 LOG_DISPLAY_ERROR(displayId, "No active config");
Lloyd Pique3c085a02018-05-09 19:38:32 -0700409 return -1;
Dominik Laskowskif3749f82018-06-13 15:49:25 -0700410 }
411
412 RETURN_IF_HWC_ERROR(error, displayId, -1);
413
414 if (index < 0) {
415 LOG_DISPLAY_ERROR(displayId, "Unknown config");
Lloyd Pique3c085a02018-05-09 19:38:32 -0700416 return -1;
417 }
418
419 return index;
420}
421
Dominik Laskowski075d3172018-05-24 15:50:06 -0700422std::vector<ui::ColorMode> HWComposer::getColorModes(DisplayId displayId) const {
Dominik Laskowskifc2c0322018-04-19 14:47:33 -0700423 RETURN_IF_INVALID_DISPLAY(displayId, {});
424
Peiyong Linfd997e02018-03-28 15:29:00 -0700425 std::vector<ui::ColorMode> modes;
Dominik Laskowski075d3172018-05-24 15:50:06 -0700426 auto error = mDisplayData.at(displayId).hwcDisplay->getColorModes(&modes);
Dominik Laskowskifc2c0322018-04-19 14:47:33 -0700427 RETURN_IF_HWC_ERROR(error, displayId, {});
Courtney Goeltzenleuchterfad9d8c2016-06-23 11:49:50 -0600428 return modes;
429}
430
Dominik Laskowski075d3172018-05-24 15:50:06 -0700431status_t HWComposer::setActiveColorMode(DisplayId displayId, ui::ColorMode mode,
432 ui::RenderIntent renderIntent) {
Dominik Laskowskifc2c0322018-04-19 14:47:33 -0700433 RETURN_IF_INVALID_DISPLAY(displayId, BAD_INDEX);
Michael Wright28f24d02016-07-12 13:30:53 -0700434
435 auto& displayData = mDisplayData[displayId];
Peiyong Lin0e7a7912018-04-05 14:36:36 -0700436 auto error = displayData.hwcDisplay->setColorMode(mode, renderIntent);
Dominik Laskowskifc2c0322018-04-19 14:47:33 -0700437 RETURN_IF_HWC_ERROR_FOR(("setColorMode(" + decodeColorMode(mode) + ", " +
438 decodeRenderIntent(renderIntent) + ")")
439 .c_str(),
440 error, displayId, UNKNOWN_ERROR);
Michael Wright28f24d02016-07-12 13:30:53 -0700441
442 return NO_ERROR;
443}
444
Peiyong Line9d809e2020-04-14 13:10:48 -0700445void HWComposer::setVsyncEnabled(DisplayId displayId, hal::Vsync enabled) {
Dominik Laskowskic1f18f62018-06-13 15:17:55 -0700446 RETURN_IF_INVALID_DISPLAY(displayId);
447 auto& displayData = mDisplayData[displayId];
448
449 if (displayData.isVirtual) {
450 LOG_DISPLAY_ERROR(displayId, "Invalid operation on virtual display");
Dan Stoza9e56aa02015-11-02 13:00:03 -0800451 return;
452 }
453
Dan Stoza9e56aa02015-11-02 13:00:03 -0800454 // NOTE: we use our own internal lock here because we have to call
455 // into the HWC with the lock held, and we want to make sure
456 // that even if HWC blocks (which it shouldn't), it won't
457 // affect other threads.
Dominik Laskowski1af47932018-11-12 10:20:46 -0800458 std::lock_guard lock(displayData.vsyncEnabledLock);
459 if (enabled == displayData.vsyncEnabled) {
460 return;
Colin Cross10fbdb62012-07-12 17:56:34 -0700461 }
Dominik Laskowski1af47932018-11-12 10:20:46 -0800462
463 ATRACE_CALL();
464 auto error = displayData.hwcDisplay->setVsyncEnabled(enabled);
465 RETURN_IF_HWC_ERROR(error, displayId);
466
467 displayData.vsyncEnabled = enabled;
468
469 const auto tag = "HW_VSYNC_ON_" + to_string(displayId);
Peiyong Line9d809e2020-04-14 13:10:48 -0700470 ATRACE_INT(tag.c_str(), enabled == hal::Vsync::ENABLE ? 1 : 0);
Colin Cross10fbdb62012-07-12 17:56:34 -0700471}
472
Dominik Laskowski075d3172018-05-24 15:50:06 -0700473status_t HWComposer::setClientTarget(DisplayId displayId, uint32_t slot,
474 const sp<Fence>& acquireFence, const sp<GraphicBuffer>& target,
475 ui::Dataspace dataspace) {
Dominik Laskowskifc2c0322018-04-19 14:47:33 -0700476 RETURN_IF_INVALID_DISPLAY(displayId, BAD_INDEX);
Jesse Hall851cfe82013-03-20 13:44:00 -0700477
Dominik Laskowski34157762018-10-31 13:07:19 -0700478 ALOGV("%s for display %s", __FUNCTION__, to_string(displayId).c_str());
Dan Stoza9e56aa02015-11-02 13:00:03 -0800479 auto& hwcDisplay = mDisplayData[displayId].hwcDisplay;
Daniel Nicoara1f42e3a2017-04-10 13:27:32 -0400480 auto error = hwcDisplay->setClientTarget(slot, target, acquireFence, dataspace);
Dominik Laskowskifc2c0322018-04-19 14:47:33 -0700481 RETURN_IF_HWC_ERROR(error, displayId, BAD_VALUE);
Jesse Hall851cfe82013-03-20 13:44:00 -0700482 return NO_ERROR;
483}
484
Lloyd Pique66d68602019-02-13 14:23:31 -0800485status_t HWComposer::getDeviceCompositionChanges(
486 DisplayId displayId, bool frameUsesClientComposition,
487 std::optional<android::HWComposer::DeviceRequestedChanges>* outChanges) {
Dan Stoza9e56aa02015-11-02 13:00:03 -0800488 ATRACE_CALL();
489
Dominik Laskowskifc2c0322018-04-19 14:47:33 -0700490 RETURN_IF_INVALID_DISPLAY(displayId, BAD_INDEX);
Dan Stoza9e56aa02015-11-02 13:00:03 -0800491
492 auto& displayData = mDisplayData[displayId];
493 auto& hwcDisplay = displayData.hwcDisplay;
494 if (!hwcDisplay->isConnected()) {
495 return NO_ERROR;
496 }
497
498 uint32_t numTypes = 0;
499 uint32_t numRequests = 0;
Fabien Sanglard249c0ae2017-06-19 19:22:36 -0700500
Peiyong Line9d809e2020-04-14 13:10:48 -0700501 hal::Error error = hal::Error::NONE;
Fabien Sanglard249c0ae2017-06-19 19:22:36 -0700502
Chia-I Wu41b98d42017-12-11 11:04:36 -0800503 // First try to skip validate altogether when there is no client
504 // composition. When there is client composition, since we haven't
505 // rendered to the client target yet, we should not attempt to skip
506 // validate.
Fabien Sanglard249c0ae2017-06-19 19:22:36 -0700507 displayData.validateWasSkipped = false;
Lloyd Pique66d68602019-02-13 14:23:31 -0800508 if (!frameUsesClientComposition) {
Dominik Laskowski1af47932018-11-12 10:20:46 -0800509 sp<Fence> outPresentFence;
Fabien Sanglard249c0ae2017-06-19 19:22:36 -0700510 uint32_t state = UINT32_MAX;
511 error = hwcDisplay->presentOrValidate(&numTypes, &numRequests, &outPresentFence , &state);
Peiyong Line9d809e2020-04-14 13:10:48 -0700512 if (!hasChangesError(error)) {
Dominik Laskowskifc2c0322018-04-19 14:47:33 -0700513 RETURN_IF_HWC_ERROR_FOR("presentOrValidate", error, displayId, UNKNOWN_ERROR);
Fabien Sanglard249c0ae2017-06-19 19:22:36 -0700514 }
515 if (state == 1) { //Present Succeeded.
Steven Thomas94e35b92017-07-26 18:48:28 -0700516 std::unordered_map<HWC2::Layer*, sp<Fence>> releaseFences;
Fabien Sanglard249c0ae2017-06-19 19:22:36 -0700517 error = hwcDisplay->getReleaseFences(&releaseFences);
518 displayData.releaseFences = std::move(releaseFences);
519 displayData.lastPresentFence = outPresentFence;
520 displayData.validateWasSkipped = true;
521 displayData.presentError = error;
522 return NO_ERROR;
523 }
524 // Present failed but Validate ran.
525 } else {
526 error = hwcDisplay->validate(&numTypes, &numRequests);
527 }
528 ALOGV("SkipValidate failed, Falling back to SLOW validate/present");
Peiyong Line9d809e2020-04-14 13:10:48 -0700529 if (!hasChangesError(error)) {
Dominik Laskowskifc2c0322018-04-19 14:47:33 -0700530 RETURN_IF_HWC_ERROR_FOR("validate", error, displayId, BAD_INDEX);
Dan Stoza9e56aa02015-11-02 13:00:03 -0800531 }
532
Lloyd Pique66d68602019-02-13 14:23:31 -0800533 android::HWComposer::DeviceRequestedChanges::ChangedTypes changedTypes;
Dan Stoza9e56aa02015-11-02 13:00:03 -0800534 changedTypes.reserve(numTypes);
535 error = hwcDisplay->getChangedCompositionTypes(&changedTypes);
Dominik Laskowskifc2c0322018-04-19 14:47:33 -0700536 RETURN_IF_HWC_ERROR_FOR("getChangedCompositionTypes", error, displayId, BAD_INDEX);
Dan Stoza9e56aa02015-11-02 13:00:03 -0800537
Peiyong Line9d809e2020-04-14 13:10:48 -0700538 auto displayRequests = static_cast<hal::DisplayRequest>(0);
Lloyd Pique66d68602019-02-13 14:23:31 -0800539 android::HWComposer::DeviceRequestedChanges::LayerRequests layerRequests;
Dan Stoza9e56aa02015-11-02 13:00:03 -0800540 layerRequests.reserve(numRequests);
Lloyd Pique66d68602019-02-13 14:23:31 -0800541 error = hwcDisplay->getRequests(&displayRequests, &layerRequests);
Dominik Laskowskifc2c0322018-04-19 14:47:33 -0700542 RETURN_IF_HWC_ERROR_FOR("getRequests", error, displayId, BAD_INDEX);
Dan Stoza9e56aa02015-11-02 13:00:03 -0800543
Lloyd Pique66d68602019-02-13 14:23:31 -0800544 outChanges->emplace(DeviceRequestedChanges{std::move(changedTypes), std::move(displayRequests),
545 std::move(layerRequests)});
Dan Stoza9e56aa02015-11-02 13:00:03 -0800546
547 error = hwcDisplay->acceptChanges();
Dominik Laskowskifc2c0322018-04-19 14:47:33 -0700548 RETURN_IF_HWC_ERROR_FOR("acceptChanges", error, displayId, BAD_INDEX);
Dan Stoza9e56aa02015-11-02 13:00:03 -0800549
550 return NO_ERROR;
551}
552
Dominik Laskowski075d3172018-05-24 15:50:06 -0700553sp<Fence> HWComposer::getPresentFence(DisplayId displayId) const {
Dominik Laskowskifc2c0322018-04-19 14:47:33 -0700554 RETURN_IF_INVALID_DISPLAY(displayId, Fence::NO_FENCE);
Dominik Laskowski075d3172018-05-24 15:50:06 -0700555 return mDisplayData.at(displayId).lastPresentFence;
Jesse Hall851cfe82013-03-20 13:44:00 -0700556}
557
Dominik Laskowski075d3172018-05-24 15:50:06 -0700558sp<Fence> HWComposer::getLayerReleaseFence(DisplayId displayId, HWC2::Layer* layer) const {
Dominik Laskowskifc2c0322018-04-19 14:47:33 -0700559 RETURN_IF_INVALID_DISPLAY(displayId, Fence::NO_FENCE);
Tim Murray2d3f8b82019-12-04 16:24:17 -0800560 const auto& displayFences = mDisplayData.at(displayId).releaseFences;
561 auto fence = displayFences.find(layer);
562 if (fence == displayFences.end()) {
Dan Stoza9e56aa02015-11-02 13:00:03 -0800563 ALOGV("getLayerReleaseFence: Release fence not found");
564 return Fence::NO_FENCE;
Riley Andrews03414a12014-07-01 14:22:59 -0700565 }
Tim Murray2d3f8b82019-12-04 16:24:17 -0800566 return fence->second;
Riley Andrews03414a12014-07-01 14:22:59 -0700567}
568
Dominik Laskowski075d3172018-05-24 15:50:06 -0700569status_t HWComposer::presentAndGetReleaseFences(DisplayId displayId) {
Dan Stoza9e56aa02015-11-02 13:00:03 -0800570 ATRACE_CALL();
Mathias Agopian3e8b8532012-05-13 20:42:01 -0700571
Dominik Laskowskifc2c0322018-04-19 14:47:33 -0700572 RETURN_IF_INVALID_DISPLAY(displayId, BAD_INDEX);
Pablo Ceballosd814cf22015-09-11 14:37:39 -0700573
Dan Stoza9e56aa02015-11-02 13:00:03 -0800574 auto& displayData = mDisplayData[displayId];
575 auto& hwcDisplay = displayData.hwcDisplay;
Fabien Sanglard249c0ae2017-06-19 19:22:36 -0700576
577 if (displayData.validateWasSkipped) {
Chia-I Wuae5a6b82017-10-10 09:09:22 -0700578 // explicitly flush all pending commands
Peiyong Line9d809e2020-04-14 13:10:48 -0700579 auto error = static_cast<hal::Error>(mComposer->executeCommands());
Peiyong Linbdd08cc2019-12-17 21:35:14 -0800580 RETURN_IF_HWC_ERROR_FOR("executeCommands", error, displayId, UNKNOWN_ERROR);
Dominik Laskowskifc2c0322018-04-19 14:47:33 -0700581 RETURN_IF_HWC_ERROR_FOR("present", displayData.presentError, displayId, UNKNOWN_ERROR);
Fabien Sanglard249c0ae2017-06-19 19:22:36 -0700582 return NO_ERROR;
583 }
584
Fabien Sanglard11d0fc32016-12-01 15:43:01 -0800585 auto error = hwcDisplay->present(&displayData.lastPresentFence);
Dominik Laskowskifc2c0322018-04-19 14:47:33 -0700586 RETURN_IF_HWC_ERROR_FOR("present", error, displayId, UNKNOWN_ERROR);
Mathias Agopian3e8b8532012-05-13 20:42:01 -0700587
Steven Thomas94e35b92017-07-26 18:48:28 -0700588 std::unordered_map<HWC2::Layer*, sp<Fence>> releaseFences;
Dan Stoza9e56aa02015-11-02 13:00:03 -0800589 error = hwcDisplay->getReleaseFences(&releaseFences);
Dominik Laskowskifc2c0322018-04-19 14:47:33 -0700590 RETURN_IF_HWC_ERROR_FOR("getReleaseFences", error, displayId, UNKNOWN_ERROR);
Dan Stoza9e56aa02015-11-02 13:00:03 -0800591
592 displayData.releaseFences = std::move(releaseFences);
593
594 return NO_ERROR;
Mathias Agopiana350ff92010-08-10 17:14:02 -0700595}
596
Peiyong Lin65248e02020-04-18 21:15:07 -0700597status_t HWComposer::setPowerMode(DisplayId displayId, hal::PowerMode mode) {
Dominik Laskowskifc2c0322018-04-19 14:47:33 -0700598 RETURN_IF_INVALID_DISPLAY(displayId, BAD_INDEX);
599
Dominik Laskowskic1f18f62018-06-13 15:17:55 -0700600 const auto& displayData = mDisplayData[displayId];
601 if (displayData.isVirtual) {
Dominik Laskowskifc2c0322018-04-19 14:47:33 -0700602 LOG_DISPLAY_ERROR(displayId, "Invalid operation on virtual display");
603 return INVALID_OPERATION;
Dan Stoza9e56aa02015-11-02 13:00:03 -0800604 }
Mathias Agopian3e8b8532012-05-13 20:42:01 -0700605
Peiyong Line9d809e2020-04-14 13:10:48 -0700606 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
Dominik Laskowski5690bde2020-04-23 19:04:22 -0700798std::future<status_t> HWComposer::setDisplayBrightness(DisplayId displayId, float brightness) {
799 RETURN_IF_INVALID_DISPLAY(displayId, promise::yield<status_t>(BAD_INDEX));
800 auto& display = mDisplayData[displayId].hwcDisplay;
801
802 return promise::chain(display->setDisplayBrightness(brightness))
803 .then([displayId](hal::Error error) -> status_t {
804 if (error == hal::Error::UNSUPPORTED) {
805 RETURN_IF_HWC_ERROR(error, displayId, INVALID_OPERATION);
806 }
807 if (error == hal::Error::BAD_PARAMETER) {
808 RETURN_IF_HWC_ERROR(error, displayId, BAD_VALUE);
809 }
810 RETURN_IF_HWC_ERROR(error, displayId, UNKNOWN_ERROR);
811 return NO_ERROR;
812 });
Dan Gittik57e63c52019-01-18 16:37:54 +0000813}
814
Hendrik Wagenaar87670ff2017-02-01 12:10:46 -0800815bool HWComposer::isUsingVrComposer() const {
Hendrik Wagenaar87670ff2017-02-01 12:10:46 -0800816 return getComposer()->isUsingVrComposer();
Hendrik Wagenaar87670ff2017-02-01 12:10:46 -0800817}
818
Galia Peycheva5492cb52019-10-30 14:13:16 +0100819status_t HWComposer::setAutoLowLatencyMode(DisplayId displayId, bool on) {
820 RETURN_IF_INVALID_DISPLAY(displayId, BAD_INDEX);
821 const auto error = mDisplayData[displayId].hwcDisplay->setAutoLowLatencyMode(on);
Peiyong Line9d809e2020-04-14 13:10:48 -0700822 if (error == hal::Error::UNSUPPORTED) {
Galia Peycheva5492cb52019-10-30 14:13:16 +0100823 RETURN_IF_HWC_ERROR(error, displayId, INVALID_OPERATION);
824 }
Peiyong Line9d809e2020-04-14 13:10:48 -0700825 if (error == hal::Error::BAD_PARAMETER) {
Galia Peycheva5492cb52019-10-30 14:13:16 +0100826 RETURN_IF_HWC_ERROR(error, displayId, BAD_VALUE);
827 }
828 RETURN_IF_HWC_ERROR(error, displayId, UNKNOWN_ERROR);
829 return NO_ERROR;
830}
831
832status_t HWComposer::getSupportedContentTypes(
Peiyong Line9d809e2020-04-14 13:10:48 -0700833 DisplayId displayId, std::vector<hal::ContentType>* outSupportedContentTypes) {
Galia Peycheva5492cb52019-10-30 14:13:16 +0100834 RETURN_IF_INVALID_DISPLAY(displayId, BAD_INDEX);
835 const auto error =
836 mDisplayData[displayId].hwcDisplay->getSupportedContentTypes(outSupportedContentTypes);
837
838 RETURN_IF_HWC_ERROR(error, displayId, UNKNOWN_ERROR);
839
840 return NO_ERROR;
841}
842
Peiyong Line9d809e2020-04-14 13:10:48 -0700843status_t HWComposer::setContentType(DisplayId displayId, hal::ContentType contentType) {
Galia Peycheva5492cb52019-10-30 14:13:16 +0100844 RETURN_IF_INVALID_DISPLAY(displayId, BAD_INDEX);
845 const auto error = mDisplayData[displayId].hwcDisplay->setContentType(contentType);
Peiyong Line9d809e2020-04-14 13:10:48 -0700846 if (error == hal::Error::UNSUPPORTED) {
Galia Peycheva5492cb52019-10-30 14:13:16 +0100847 RETURN_IF_HWC_ERROR(error, displayId, INVALID_OPERATION);
848 }
Peiyong Line9d809e2020-04-14 13:10:48 -0700849 if (error == hal::Error::BAD_PARAMETER) {
Galia Peycheva5492cb52019-10-30 14:13:16 +0100850 RETURN_IF_HWC_ERROR(error, displayId, BAD_VALUE);
851 }
852 RETURN_IF_HWC_ERROR(error, displayId, UNKNOWN_ERROR);
853
854 return NO_ERROR;
855}
856
Lloyd Pique4603f3c2020-02-11 12:06:56 -0800857const std::unordered_map<std::string, bool>& HWComposer::getSupportedLayerGenericMetadata() const {
858 return mSupportedLayerGenericMetadata;
859}
860
Yiwei Zhang5434a782018-12-05 18:06:32 -0800861void HWComposer::dump(std::string& result) const {
Peiyong Linbdd08cc2019-12-17 21:35:14 -0800862 result.append(mComposer->dumpDebugInfo());
Mathias Agopian83727852010-09-23 18:13:21 -0700863}
864
Peiyong Line9d809e2020-04-14 13:10:48 -0700865std::optional<DisplayId> HWComposer::toPhysicalDisplayId(hal::HWDisplayId hwcDisplayId) const {
Dominik Laskowski075d3172018-05-24 15:50:06 -0700866 if (const auto it = mPhysicalDisplayIdMap.find(hwcDisplayId);
867 it != mPhysicalDisplayIdMap.end()) {
868 return it->second;
869 }
870 return {};
871}
872
Peiyong Line9d809e2020-04-14 13:10:48 -0700873std::optional<hal::HWDisplayId> HWComposer::fromPhysicalDisplayId(DisplayId displayId) const {
Dominik Laskowski075d3172018-05-24 15:50:06 -0700874 if (const auto it = mDisplayData.find(displayId);
875 it != mDisplayData.end() && !it->second.isVirtual) {
876 return it->second.hwcDisplay->getId();
877 }
878 return {};
879}
880
Peiyong Line9d809e2020-04-14 13:10:48 -0700881bool HWComposer::shouldIgnoreHotplugConnect(hal::HWDisplayId hwcDisplayId,
Marin Shalamanovbdd59152020-02-14 15:30:06 +0100882 bool hasDisplayIdentificationData) const {
Dominik Laskowski075d3172018-05-24 15:50:06 -0700883 if (isUsingVrComposer() && mInternalHwcDisplayId) {
884 ALOGE("Ignoring connection of external display %" PRIu64 " in VR mode", hwcDisplayId);
Marin Shalamanovbdd59152020-02-14 15:30:06 +0100885 return true;
Steven Thomas6e8f7062017-11-22 14:15:29 -0800886 }
Dominik Laskowski075d3172018-05-24 15:50:06 -0700887
Marin Shalamanovbdd59152020-02-14 15:30:06 +0100888 if (mHasMultiDisplaySupport && !hasDisplayIdentificationData) {
Dominik Laskowski075d3172018-05-24 15:50:06 -0700889 ALOGE("Ignoring connection of display %" PRIu64 " without identification data",
890 hwcDisplayId);
Marin Shalamanovbdd59152020-02-14 15:30:06 +0100891 return true;
Dominik Laskowski075d3172018-05-24 15:50:06 -0700892 }
893
Marin Shalamanovbdd59152020-02-14 15:30:06 +0100894 if (!mHasMultiDisplaySupport && mInternalHwcDisplayId && mExternalHwcDisplayId) {
Dominik Laskowski075d3172018-05-24 15:50:06 -0700895 ALOGE("Ignoring connection of tertiary display %" PRIu64, hwcDisplayId);
Marin Shalamanovbdd59152020-02-14 15:30:06 +0100896 return true;
897 }
898
899 return false;
900}
901
Peiyong Line9d809e2020-04-14 13:10:48 -0700902std::optional<DisplayIdentificationInfo> HWComposer::onHotplugConnect(
903 hal::HWDisplayId hwcDisplayId) {
Marin Shalamanovbdd59152020-02-14 15:30:06 +0100904 std::optional<DisplayIdentificationInfo> info;
905 if (const auto displayId = toPhysicalDisplayId(hwcDisplayId)) {
906 info = DisplayIdentificationInfo{.id = *displayId,
907 .name = std::string(),
908 .deviceProductInfo = std::nullopt};
Dominik Laskowski075d3172018-05-24 15:50:06 -0700909 } else {
Marin Shalamanovbdd59152020-02-14 15:30:06 +0100910 uint8_t port;
911 DisplayIdentificationData data;
912 const bool hasDisplayIdentificationData =
913 getDisplayIdentificationData(hwcDisplayId, &port, &data);
914 if (mPhysicalDisplayIdMap.empty()) {
915 mHasMultiDisplaySupport = hasDisplayIdentificationData;
916 ALOGI("Switching to %s multi-display mode",
917 mHasMultiDisplaySupport ? "generalized" : "legacy");
918 }
919
920 if (shouldIgnoreHotplugConnect(hwcDisplayId, hasDisplayIdentificationData)) {
921 return {};
922 }
923
924 info = [this, hwcDisplayId, &port, &data, hasDisplayIdentificationData] {
925 const bool isPrimary = !mInternalHwcDisplayId;
926 if (mHasMultiDisplaySupport) {
927 if (const auto info = parseDisplayIdentificationData(port, data)) {
928 return *info;
929 }
930 ALOGE("Failed to parse identification data for display %" PRIu64, hwcDisplayId);
931 } else {
932 ALOGW_IF(hasDisplayIdentificationData,
933 "Ignoring identification data for display %" PRIu64, hwcDisplayId);
Peiyong Lin65248e02020-04-18 21:15:07 -0700934 port = isPrimary ? LEGACY_DISPLAY_TYPE_PRIMARY : LEGACY_DISPLAY_TYPE_EXTERNAL;
Marin Shalamanovbdd59152020-02-14 15:30:06 +0100935 }
936
937 return DisplayIdentificationInfo{.id = getFallbackDisplayId(port),
938 .name = isPrimary ? "Internal display"
939 : "External display",
940 .deviceProductInfo = std::nullopt};
941 }();
Dominik Laskowski075d3172018-05-24 15:50:06 -0700942 }
943
Marin Shalamanovbdd59152020-02-14 15:30:06 +0100944 if (!isConnected(info->id)) {
945 allocatePhysicalDisplay(hwcDisplayId, info->id);
946 }
947 return info;
948}
949
950std::optional<DisplayIdentificationInfo> HWComposer::onHotplugDisconnect(
Peiyong Line9d809e2020-04-14 13:10:48 -0700951 hal::HWDisplayId hwcDisplayId) {
Marin Shalamanovbdd59152020-02-14 15:30:06 +0100952 const auto displayId = toPhysicalDisplayId(hwcDisplayId);
953 if (!displayId) {
954 ALOGE("Ignoring disconnection of invalid HWC display %" PRIu64, hwcDisplayId);
955 return {};
Dominik Laskowski075d3172018-05-24 15:50:06 -0700956 }
957
Marin Shalamanovbdd59152020-02-14 15:30:06 +0100958 // The display will later be destroyed by a call to
959 // destroyDisplay(). For now we just mark it disconnected.
960 if (isConnected(*displayId)) {
961 mDisplayData[*displayId].hwcDisplay->setConnected(false);
962 } else {
963 ALOGW("Attempted to disconnect unknown display %" PRIu64, hwcDisplayId);
964 }
965 // The cleanup of Disconnect is handled through HWComposer::disconnectDisplay
966 // via SurfaceFlinger's onHotplugReceived callback handling
967 return DisplayIdentificationInfo{.id = *displayId,
968 .name = std::string(),
Marin Shalamanovf5de90d2019-10-08 10:57:25 +0200969 .deviceProductInfo = std::nullopt};
Steven Thomas6e8f7062017-11-22 14:15:29 -0800970}
971
Peiyong Linbdd08cc2019-12-17 21:35:14 -0800972void HWComposer::loadCapabilities() {
Peiyong Line9d809e2020-04-14 13:10:48 -0700973 static_assert(sizeof(hal::Capability) == sizeof(int32_t), "Capability size has changed");
Peiyong Linbdd08cc2019-12-17 21:35:14 -0800974 auto capabilities = mComposer->getCapabilities();
975 for (auto capability : capabilities) {
Peiyong Line9d809e2020-04-14 13:10:48 -0700976 mCapabilities.emplace(static_cast<hal::Capability>(capability));
Peiyong Linbdd08cc2019-12-17 21:35:14 -0800977 }
978}
979
Lloyd Pique4603f3c2020-02-11 12:06:56 -0800980void HWComposer::loadLayerMetadataSupport() {
981 mSupportedLayerGenericMetadata.clear();
982
983 std::vector<Hwc2::IComposerClient::LayerGenericMetadataKey> supportedMetadataKeyInfo;
984 const auto error = mComposer->getLayerGenericMetadataKeys(&supportedMetadataKeyInfo);
985 if (error != hardware::graphics::composer::V2_4::Error::NONE) {
986 ALOGE("%s: %s failed: %s (%d)", __FUNCTION__, "getLayerGenericMetadataKeys",
987 toString(error).c_str(), static_cast<int32_t>(error));
988 return;
989 }
990
991 for (const auto& [name, mandatory] : supportedMetadataKeyInfo) {
992 mSupportedLayerGenericMetadata.emplace(name, mandatory);
993 }
994}
995
Peiyong Linbdd08cc2019-12-17 21:35:14 -0800996uint32_t HWComposer::getMaxVirtualDisplayCount() const {
997 return mComposer->getMaxVirtualDisplayCount();
998}
999
Lloyd Pique441d5042018-10-18 16:49:51 -07001000} // namespace impl
Dominik Laskowskif9750f22018-06-06 12:24:53 -07001001} // namespace android
Ady Abrahamb0dbdaa2020-01-06 16:19:42 -08001002
1003// TODO(b/129481165): remove the #pragma below and fix conversion issues
1004#pragma clang diagnostic pop // ignored "-Wconversion"