blob: 7a2f0f34eefbce896e3ffa0588f692315c8daa73 [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
Peiyong Lindfc3f7c2020-05-07 20:15:50 -0700544 DeviceRequestedChanges::ClientTargetProperty clientTargetProperty;
545 error = hwcDisplay->getClientTargetProperty(&clientTargetProperty);
Dan Stoza9e56aa02015-11-02 13:00:03 -0800546
Peiyong Lindfc3f7c2020-05-07 20:15:50 -0700547 outChanges->emplace(DeviceRequestedChanges{std::move(changedTypes), std::move(displayRequests),
548 std::move(layerRequests),
549 std::move(clientTargetProperty)});
Dan Stoza9e56aa02015-11-02 13:00:03 -0800550 error = hwcDisplay->acceptChanges();
Dominik Laskowskifc2c0322018-04-19 14:47:33 -0700551 RETURN_IF_HWC_ERROR_FOR("acceptChanges", error, displayId, BAD_INDEX);
Dan Stoza9e56aa02015-11-02 13:00:03 -0800552
553 return NO_ERROR;
554}
555
Dominik Laskowski075d3172018-05-24 15:50:06 -0700556sp<Fence> HWComposer::getPresentFence(DisplayId displayId) const {
Dominik Laskowskifc2c0322018-04-19 14:47:33 -0700557 RETURN_IF_INVALID_DISPLAY(displayId, Fence::NO_FENCE);
Dominik Laskowski075d3172018-05-24 15:50:06 -0700558 return mDisplayData.at(displayId).lastPresentFence;
Jesse Hall851cfe82013-03-20 13:44:00 -0700559}
560
Dominik Laskowski075d3172018-05-24 15:50:06 -0700561sp<Fence> HWComposer::getLayerReleaseFence(DisplayId displayId, HWC2::Layer* layer) const {
Dominik Laskowskifc2c0322018-04-19 14:47:33 -0700562 RETURN_IF_INVALID_DISPLAY(displayId, Fence::NO_FENCE);
Tim Murray2d3f8b82019-12-04 16:24:17 -0800563 const auto& displayFences = mDisplayData.at(displayId).releaseFences;
564 auto fence = displayFences.find(layer);
565 if (fence == displayFences.end()) {
Dan Stoza9e56aa02015-11-02 13:00:03 -0800566 ALOGV("getLayerReleaseFence: Release fence not found");
567 return Fence::NO_FENCE;
Riley Andrews03414a12014-07-01 14:22:59 -0700568 }
Tim Murray2d3f8b82019-12-04 16:24:17 -0800569 return fence->second;
Riley Andrews03414a12014-07-01 14:22:59 -0700570}
571
Dominik Laskowski075d3172018-05-24 15:50:06 -0700572status_t HWComposer::presentAndGetReleaseFences(DisplayId displayId) {
Dan Stoza9e56aa02015-11-02 13:00:03 -0800573 ATRACE_CALL();
Mathias Agopian3e8b8532012-05-13 20:42:01 -0700574
Dominik Laskowskifc2c0322018-04-19 14:47:33 -0700575 RETURN_IF_INVALID_DISPLAY(displayId, BAD_INDEX);
Pablo Ceballosd814cf22015-09-11 14:37:39 -0700576
Dan Stoza9e56aa02015-11-02 13:00:03 -0800577 auto& displayData = mDisplayData[displayId];
578 auto& hwcDisplay = displayData.hwcDisplay;
Fabien Sanglard249c0ae2017-06-19 19:22:36 -0700579
580 if (displayData.validateWasSkipped) {
Chia-I Wuae5a6b82017-10-10 09:09:22 -0700581 // explicitly flush all pending commands
Peiyong Line9d809e2020-04-14 13:10:48 -0700582 auto error = static_cast<hal::Error>(mComposer->executeCommands());
Peiyong Linbdd08cc2019-12-17 21:35:14 -0800583 RETURN_IF_HWC_ERROR_FOR("executeCommands", error, displayId, UNKNOWN_ERROR);
Dominik Laskowskifc2c0322018-04-19 14:47:33 -0700584 RETURN_IF_HWC_ERROR_FOR("present", displayData.presentError, displayId, UNKNOWN_ERROR);
Fabien Sanglard249c0ae2017-06-19 19:22:36 -0700585 return NO_ERROR;
586 }
587
Fabien Sanglard11d0fc32016-12-01 15:43:01 -0800588 auto error = hwcDisplay->present(&displayData.lastPresentFence);
Dominik Laskowskifc2c0322018-04-19 14:47:33 -0700589 RETURN_IF_HWC_ERROR_FOR("present", error, displayId, UNKNOWN_ERROR);
Mathias Agopian3e8b8532012-05-13 20:42:01 -0700590
Steven Thomas94e35b92017-07-26 18:48:28 -0700591 std::unordered_map<HWC2::Layer*, sp<Fence>> releaseFences;
Dan Stoza9e56aa02015-11-02 13:00:03 -0800592 error = hwcDisplay->getReleaseFences(&releaseFences);
Dominik Laskowskifc2c0322018-04-19 14:47:33 -0700593 RETURN_IF_HWC_ERROR_FOR("getReleaseFences", error, displayId, UNKNOWN_ERROR);
Dan Stoza9e56aa02015-11-02 13:00:03 -0800594
595 displayData.releaseFences = std::move(releaseFences);
596
597 return NO_ERROR;
Mathias Agopiana350ff92010-08-10 17:14:02 -0700598}
599
Peiyong Lin65248e02020-04-18 21:15:07 -0700600status_t HWComposer::setPowerMode(DisplayId displayId, hal::PowerMode mode) {
Dominik Laskowskifc2c0322018-04-19 14:47:33 -0700601 RETURN_IF_INVALID_DISPLAY(displayId, BAD_INDEX);
602
Dominik Laskowskic1f18f62018-06-13 15:17:55 -0700603 const auto& displayData = mDisplayData[displayId];
604 if (displayData.isVirtual) {
Dominik Laskowskifc2c0322018-04-19 14:47:33 -0700605 LOG_DISPLAY_ERROR(displayId, "Invalid operation on virtual display");
606 return INVALID_OPERATION;
Dan Stoza9e56aa02015-11-02 13:00:03 -0800607 }
Mathias Agopian3e8b8532012-05-13 20:42:01 -0700608
Peiyong Line9d809e2020-04-14 13:10:48 -0700609 if (mode == hal::PowerMode::OFF) {
610 setVsyncEnabled(displayId, hal::Vsync::DISABLE);
Dan Stoza9e56aa02015-11-02 13:00:03 -0800611 }
612
Dominik Laskowskic1f18f62018-06-13 15:17:55 -0700613 auto& hwcDisplay = displayData.hwcDisplay;
Dan Stoza9e56aa02015-11-02 13:00:03 -0800614 switch (mode) {
Peiyong Line9d809e2020-04-14 13:10:48 -0700615 case hal::PowerMode::OFF:
616 case hal::PowerMode::ON:
Dan Stoza9e56aa02015-11-02 13:00:03 -0800617 ALOGV("setPowerMode: Calling HWC %s", to_string(mode).c_str());
618 {
619 auto error = hwcDisplay->setPowerMode(mode);
Peiyong Line9d809e2020-04-14 13:10:48 -0700620 if (error != hal::Error::NONE) {
621 LOG_HWC_ERROR(("setPowerMode(" + to_string(mode) + ")").c_str(), error,
622 displayId);
Peiyong Lin306e4992018-05-07 16:18:22 -0700623 }
Mathias Agopianda27af92012-09-13 18:17:13 -0700624 }
Dan Stoza9e56aa02015-11-02 13:00:03 -0800625 break;
Peiyong Line9d809e2020-04-14 13:10:48 -0700626 case hal::PowerMode::DOZE:
627 case hal::PowerMode::DOZE_SUSPEND:
Dan Stoza9e56aa02015-11-02 13:00:03 -0800628 ALOGV("setPowerMode: Calling HWC %s", to_string(mode).c_str());
629 {
630 bool supportsDoze = false;
631 auto error = hwcDisplay->supportsDoze(&supportsDoze);
Peiyong Line9d809e2020-04-14 13:10:48 -0700632 if (error != hal::Error::NONE) {
Peiyong Lin306e4992018-05-07 16:18:22 -0700633 LOG_HWC_ERROR("supportsDoze", error, displayId);
634 }
Dominik Laskowskifc2c0322018-04-19 14:47:33 -0700635
Dan Stoza9e56aa02015-11-02 13:00:03 -0800636 if (!supportsDoze) {
Peiyong Line9d809e2020-04-14 13:10:48 -0700637 mode = hal::PowerMode::ON;
Dan Stoza9e56aa02015-11-02 13:00:03 -0800638 }
639
640 error = hwcDisplay->setPowerMode(mode);
Peiyong Line9d809e2020-04-14 13:10:48 -0700641 if (error != hal::Error::NONE) {
642 LOG_HWC_ERROR(("setPowerMode(" + to_string(mode) + ")").c_str(), error,
643 displayId);
Peiyong Lin306e4992018-05-07 16:18:22 -0700644 }
Dan Stoza9e56aa02015-11-02 13:00:03 -0800645 }
646 break;
647 default:
648 ALOGV("setPowerMode: Not calling HWC");
649 break;
Mathias Agopianda27af92012-09-13 18:17:13 -0700650 }
Dan Stoza9e56aa02015-11-02 13:00:03 -0800651
652 return NO_ERROR;
653}
654
Ady Abraham3a77a7b2019-12-02 18:46:59 -0800655status_t HWComposer::setActiveConfigWithConstraints(
Peiyong Line9d809e2020-04-14 13:10:48 -0700656 DisplayId displayId, size_t configId, const hal::VsyncPeriodChangeConstraints& constraints,
657 hal::VsyncPeriodChangeTimeline* outTimeline) {
Dominik Laskowskifc2c0322018-04-19 14:47:33 -0700658 RETURN_IF_INVALID_DISPLAY(displayId, BAD_INDEX);
Dan Stoza9e56aa02015-11-02 13:00:03 -0800659
660 auto& displayData = mDisplayData[displayId];
661 if (displayData.configMap.count(configId) == 0) {
Dominik Laskowskifc2c0322018-04-19 14:47:33 -0700662 LOG_DISPLAY_ERROR(displayId, ("Invalid config " + std::to_string(configId)).c_str());
Dan Stoza9e56aa02015-11-02 13:00:03 -0800663 return BAD_INDEX;
664 }
665
Ady Abraham3a77a7b2019-12-02 18:46:59 -0800666 auto error =
667 displayData.hwcDisplay->setActiveConfigWithConstraints(displayData.configMap[configId],
668 constraints, outTimeline);
Dominik Laskowskifc2c0322018-04-19 14:47:33 -0700669 RETURN_IF_HWC_ERROR(error, displayId, UNKNOWN_ERROR);
Dan Stoza9e56aa02015-11-02 13:00:03 -0800670 return NO_ERROR;
671}
672
Dominik Laskowski075d3172018-05-24 15:50:06 -0700673status_t HWComposer::setColorTransform(DisplayId displayId, const mat4& transform) {
Dominik Laskowskifc2c0322018-04-19 14:47:33 -0700674 RETURN_IF_INVALID_DISPLAY(displayId, BAD_INDEX);
Dan Stoza9f26a9c2016-06-22 14:51:09 -0700675
676 auto& displayData = mDisplayData[displayId];
677 bool isIdentity = transform == mat4();
Peiyong Line9d809e2020-04-14 13:10:48 -0700678 auto error = displayData.hwcDisplay
679 ->setColorTransform(transform,
680 isIdentity ? hal::ColorTransform::IDENTITY
681 : hal::ColorTransform::ARBITRARY_MATRIX);
Dominik Laskowskifc2c0322018-04-19 14:47:33 -0700682 RETURN_IF_HWC_ERROR(error, displayId, UNKNOWN_ERROR);
Dan Stoza9f26a9c2016-06-22 14:51:09 -0700683 return NO_ERROR;
684}
685
Dominik Laskowski075d3172018-05-24 15:50:06 -0700686void HWComposer::disconnectDisplay(DisplayId displayId) {
Dominik Laskowskic1f18f62018-06-13 15:17:55 -0700687 RETURN_IF_INVALID_DISPLAY(displayId);
Dan Stoza9e56aa02015-11-02 13:00:03 -0800688 auto& displayData = mDisplayData[displayId];
689
Dan Stoza9e56aa02015-11-02 13:00:03 -0800690 // If this was a virtual display, add its slot back for reuse by future
691 // virtual displays
Dominik Laskowskic1f18f62018-06-13 15:17:55 -0700692 if (displayData.isVirtual) {
Dominik Laskowski075d3172018-05-24 15:50:06 -0700693 mFreeVirtualDisplayIds.insert(displayId);
Dan Stoza9e56aa02015-11-02 13:00:03 -0800694 ++mRemainingHwcVirtualDisplays;
695 }
696
Dominik Laskowski7e045462018-05-30 13:02:02 -0700697 const auto hwcDisplayId = displayData.hwcDisplay->getId();
Dominik Laskowski075d3172018-05-24 15:50:06 -0700698
699 // TODO(b/74619554): Select internal/external display from remaining displays.
700 if (hwcDisplayId == mInternalHwcDisplayId) {
701 mInternalHwcDisplayId.reset();
702 } else if (hwcDisplayId == mExternalHwcDisplayId) {
703 mExternalHwcDisplayId.reset();
704 }
Peiyong Linbdd08cc2019-12-17 21:35:14 -0800705 mPhysicalDisplayIdMap.erase(hwcDisplayId);
706 mDisplayData.erase(displayId);
Dan Stoza9e56aa02015-11-02 13:00:03 -0800707}
708
Dominik Laskowski075d3172018-05-24 15:50:06 -0700709status_t HWComposer::setOutputBuffer(DisplayId displayId, const sp<Fence>& acquireFence,
710 const sp<GraphicBuffer>& buffer) {
Dominik Laskowskifc2c0322018-04-19 14:47:33 -0700711 RETURN_IF_INVALID_DISPLAY(displayId, BAD_INDEX);
Dominik Laskowskic1f18f62018-06-13 15:17:55 -0700712 const auto& displayData = mDisplayData[displayId];
Dan Stoza9e56aa02015-11-02 13:00:03 -0800713
Dominik Laskowskic1f18f62018-06-13 15:17:55 -0700714 if (!displayData.isVirtual) {
Dominik Laskowskifc2c0322018-04-19 14:47:33 -0700715 LOG_DISPLAY_ERROR(displayId, "Invalid operation on physical display");
Dan Stoza9e56aa02015-11-02 13:00:03 -0800716 return INVALID_OPERATION;
717 }
718
Dominik Laskowskic1f18f62018-06-13 15:17:55 -0700719 auto error = displayData.hwcDisplay->setOutputBuffer(buffer, acquireFence);
Dominik Laskowskifc2c0322018-04-19 14:47:33 -0700720 RETURN_IF_HWC_ERROR(error, displayId, UNKNOWN_ERROR);
Dan Stoza9e56aa02015-11-02 13:00:03 -0800721 return NO_ERROR;
722}
723
Dominik Laskowski075d3172018-05-24 15:50:06 -0700724void HWComposer::clearReleaseFences(DisplayId displayId) {
Dominik Laskowskifc2c0322018-04-19 14:47:33 -0700725 RETURN_IF_INVALID_DISPLAY(displayId);
Dan Stoza9e56aa02015-11-02 13:00:03 -0800726 mDisplayData[displayId].releaseFences.clear();
Mathias Agopian3e8b8532012-05-13 20:42:01 -0700727}
728
Dominik Laskowski075d3172018-05-24 15:50:06 -0700729status_t HWComposer::getHdrCapabilities(DisplayId displayId, HdrCapabilities* outCapabilities) {
Dominik Laskowskifc2c0322018-04-19 14:47:33 -0700730 RETURN_IF_INVALID_DISPLAY(displayId, BAD_INDEX);
Dan Stozac4f471e2016-03-24 09:31:08 -0700731
732 auto& hwcDisplay = mDisplayData[displayId].hwcDisplay;
Peiyong Lin62665892018-04-16 11:07:44 -0700733 auto error = hwcDisplay->getHdrCapabilities(outCapabilities);
Dominik Laskowskifc2c0322018-04-19 14:47:33 -0700734 RETURN_IF_HWC_ERROR(error, displayId, UNKNOWN_ERROR);
Peiyong Lin62665892018-04-16 11:07:44 -0700735 return NO_ERROR;
Dan Stozac4f471e2016-03-24 09:31:08 -0700736}
737
Dominik Laskowski075d3172018-05-24 15:50:06 -0700738int32_t HWComposer::getSupportedPerFrameMetadata(DisplayId displayId) const {
Dominik Laskowskifc2c0322018-04-19 14:47:33 -0700739 RETURN_IF_INVALID_DISPLAY(displayId, 0);
Dominik Laskowski075d3172018-05-24 15:50:06 -0700740 return mDisplayData.at(displayId).hwcDisplay->getSupportedPerFrameMetadata();
Peiyong Lin0ac5f4e2018-04-19 22:06:34 -0700741}
742
Dominik Laskowski075d3172018-05-24 15:50:06 -0700743std::vector<ui::RenderIntent> HWComposer::getRenderIntents(DisplayId displayId,
744 ui::ColorMode colorMode) const {
Dominik Laskowskifc2c0322018-04-19 14:47:33 -0700745 RETURN_IF_INVALID_DISPLAY(displayId, {});
Peiyong Lin0e7a7912018-04-05 14:36:36 -0700746
747 std::vector<ui::RenderIntent> renderIntents;
Dominik Laskowski075d3172018-05-24 15:50:06 -0700748 auto error = mDisplayData.at(displayId).hwcDisplay->getRenderIntents(colorMode, &renderIntents);
Dominik Laskowskifc2c0322018-04-19 14:47:33 -0700749 RETURN_IF_HWC_ERROR(error, displayId, {});
Peiyong Lin0e7a7912018-04-05 14:36:36 -0700750 return renderIntents;
751}
752
Dominik Laskowski075d3172018-05-24 15:50:06 -0700753mat4 HWComposer::getDataspaceSaturationMatrix(DisplayId displayId, ui::Dataspace dataspace) {
Dominik Laskowskifc2c0322018-04-19 14:47:33 -0700754 RETURN_IF_INVALID_DISPLAY(displayId, {});
Peiyong Lin0e7a7912018-04-05 14:36:36 -0700755
756 mat4 matrix;
757 auto error = mDisplayData[displayId].hwcDisplay->getDataspaceSaturationMatrix(dataspace,
758 &matrix);
Dominik Laskowskifc2c0322018-04-19 14:47:33 -0700759 RETURN_IF_HWC_ERROR(error, displayId, {});
Peiyong Lin0e7a7912018-04-05 14:36:36 -0700760 return matrix;
761}
762
Kevin DuBois9c0a1762018-10-16 13:32:31 -0700763status_t HWComposer::getDisplayedContentSamplingAttributes(DisplayId displayId,
764 ui::PixelFormat* outFormat,
765 ui::Dataspace* outDataspace,
766 uint8_t* outComponentMask) {
767 RETURN_IF_INVALID_DISPLAY(displayId, BAD_INDEX);
768 const auto error =
769 mDisplayData[displayId]
770 .hwcDisplay->getDisplayedContentSamplingAttributes(outFormat, outDataspace,
771 outComponentMask);
Peiyong Line9d809e2020-04-14 13:10:48 -0700772 if (error == hal::Error::UNSUPPORTED) RETURN_IF_HWC_ERROR(error, displayId, INVALID_OPERATION);
Kevin DuBois9c0a1762018-10-16 13:32:31 -0700773 RETURN_IF_HWC_ERROR(error, displayId, UNKNOWN_ERROR);
774 return NO_ERROR;
775}
776
Kevin DuBois74e53772018-11-19 10:52:38 -0800777status_t HWComposer::setDisplayContentSamplingEnabled(DisplayId displayId, bool enabled,
778 uint8_t componentMask, uint64_t maxFrames) {
779 RETURN_IF_INVALID_DISPLAY(displayId, BAD_INDEX);
780 const auto error =
781 mDisplayData[displayId].hwcDisplay->setDisplayContentSamplingEnabled(enabled,
782 componentMask,
783 maxFrames);
784
Peiyong Line9d809e2020-04-14 13:10:48 -0700785 if (error == hal::Error::UNSUPPORTED) RETURN_IF_HWC_ERROR(error, displayId, INVALID_OPERATION);
786 if (error == hal::Error::BAD_PARAMETER) RETURN_IF_HWC_ERROR(error, displayId, BAD_VALUE);
Kevin DuBois74e53772018-11-19 10:52:38 -0800787 RETURN_IF_HWC_ERROR(error, displayId, UNKNOWN_ERROR);
788 return NO_ERROR;
789}
790
Kevin DuBois1d4249a2018-08-29 10:45:14 -0700791status_t HWComposer::getDisplayedContentSample(DisplayId displayId, uint64_t maxFrames,
792 uint64_t timestamp, DisplayedFrameStats* outStats) {
793 RETURN_IF_INVALID_DISPLAY(displayId, BAD_INDEX);
794 const auto error =
795 mDisplayData[displayId].hwcDisplay->getDisplayedContentSample(maxFrames, timestamp,
796 outStats);
797 RETURN_IF_HWC_ERROR(error, displayId, UNKNOWN_ERROR);
798 return NO_ERROR;
799}
800
Dominik Laskowski5690bde2020-04-23 19:04:22 -0700801std::future<status_t> HWComposer::setDisplayBrightness(DisplayId displayId, float brightness) {
802 RETURN_IF_INVALID_DISPLAY(displayId, promise::yield<status_t>(BAD_INDEX));
803 auto& display = mDisplayData[displayId].hwcDisplay;
804
805 return promise::chain(display->setDisplayBrightness(brightness))
806 .then([displayId](hal::Error error) -> status_t {
807 if (error == hal::Error::UNSUPPORTED) {
808 RETURN_IF_HWC_ERROR(error, displayId, INVALID_OPERATION);
809 }
810 if (error == hal::Error::BAD_PARAMETER) {
811 RETURN_IF_HWC_ERROR(error, displayId, BAD_VALUE);
812 }
813 RETURN_IF_HWC_ERROR(error, displayId, UNKNOWN_ERROR);
814 return NO_ERROR;
815 });
Dan Gittik57e63c52019-01-18 16:37:54 +0000816}
817
Hendrik Wagenaar87670ff2017-02-01 12:10:46 -0800818bool HWComposer::isUsingVrComposer() const {
Hendrik Wagenaar87670ff2017-02-01 12:10:46 -0800819 return getComposer()->isUsingVrComposer();
Hendrik Wagenaar87670ff2017-02-01 12:10:46 -0800820}
821
Galia Peycheva5492cb52019-10-30 14:13:16 +0100822status_t HWComposer::setAutoLowLatencyMode(DisplayId displayId, bool on) {
823 RETURN_IF_INVALID_DISPLAY(displayId, BAD_INDEX);
824 const auto error = mDisplayData[displayId].hwcDisplay->setAutoLowLatencyMode(on);
Peiyong Line9d809e2020-04-14 13:10:48 -0700825 if (error == hal::Error::UNSUPPORTED) {
Galia Peycheva5492cb52019-10-30 14:13:16 +0100826 RETURN_IF_HWC_ERROR(error, displayId, INVALID_OPERATION);
827 }
Peiyong Line9d809e2020-04-14 13:10:48 -0700828 if (error == hal::Error::BAD_PARAMETER) {
Galia Peycheva5492cb52019-10-30 14:13:16 +0100829 RETURN_IF_HWC_ERROR(error, displayId, BAD_VALUE);
830 }
831 RETURN_IF_HWC_ERROR(error, displayId, UNKNOWN_ERROR);
832 return NO_ERROR;
833}
834
835status_t HWComposer::getSupportedContentTypes(
Peiyong Line9d809e2020-04-14 13:10:48 -0700836 DisplayId displayId, std::vector<hal::ContentType>* outSupportedContentTypes) {
Galia Peycheva5492cb52019-10-30 14:13:16 +0100837 RETURN_IF_INVALID_DISPLAY(displayId, BAD_INDEX);
838 const auto error =
839 mDisplayData[displayId].hwcDisplay->getSupportedContentTypes(outSupportedContentTypes);
840
841 RETURN_IF_HWC_ERROR(error, displayId, UNKNOWN_ERROR);
842
843 return NO_ERROR;
844}
845
Peiyong Line9d809e2020-04-14 13:10:48 -0700846status_t HWComposer::setContentType(DisplayId displayId, hal::ContentType contentType) {
Galia Peycheva5492cb52019-10-30 14:13:16 +0100847 RETURN_IF_INVALID_DISPLAY(displayId, BAD_INDEX);
848 const auto error = mDisplayData[displayId].hwcDisplay->setContentType(contentType);
Peiyong Line9d809e2020-04-14 13:10:48 -0700849 if (error == hal::Error::UNSUPPORTED) {
Galia Peycheva5492cb52019-10-30 14:13:16 +0100850 RETURN_IF_HWC_ERROR(error, displayId, INVALID_OPERATION);
851 }
Peiyong Line9d809e2020-04-14 13:10:48 -0700852 if (error == hal::Error::BAD_PARAMETER) {
Galia Peycheva5492cb52019-10-30 14:13:16 +0100853 RETURN_IF_HWC_ERROR(error, displayId, BAD_VALUE);
854 }
855 RETURN_IF_HWC_ERROR(error, displayId, UNKNOWN_ERROR);
856
857 return NO_ERROR;
858}
859
Lloyd Pique4603f3c2020-02-11 12:06:56 -0800860const std::unordered_map<std::string, bool>& HWComposer::getSupportedLayerGenericMetadata() const {
861 return mSupportedLayerGenericMetadata;
862}
863
Yiwei Zhang5434a782018-12-05 18:06:32 -0800864void HWComposer::dump(std::string& result) const {
Peiyong Linbdd08cc2019-12-17 21:35:14 -0800865 result.append(mComposer->dumpDebugInfo());
Mathias Agopian83727852010-09-23 18:13:21 -0700866}
867
Peiyong Line9d809e2020-04-14 13:10:48 -0700868std::optional<DisplayId> HWComposer::toPhysicalDisplayId(hal::HWDisplayId hwcDisplayId) const {
Dominik Laskowski075d3172018-05-24 15:50:06 -0700869 if (const auto it = mPhysicalDisplayIdMap.find(hwcDisplayId);
870 it != mPhysicalDisplayIdMap.end()) {
871 return it->second;
872 }
873 return {};
874}
875
Peiyong Line9d809e2020-04-14 13:10:48 -0700876std::optional<hal::HWDisplayId> HWComposer::fromPhysicalDisplayId(DisplayId displayId) const {
Dominik Laskowski075d3172018-05-24 15:50:06 -0700877 if (const auto it = mDisplayData.find(displayId);
878 it != mDisplayData.end() && !it->second.isVirtual) {
879 return it->second.hwcDisplay->getId();
880 }
881 return {};
882}
883
Peiyong Line9d809e2020-04-14 13:10:48 -0700884bool HWComposer::shouldIgnoreHotplugConnect(hal::HWDisplayId hwcDisplayId,
Marin Shalamanovbdd59152020-02-14 15:30:06 +0100885 bool hasDisplayIdentificationData) const {
Dominik Laskowski075d3172018-05-24 15:50:06 -0700886 if (isUsingVrComposer() && mInternalHwcDisplayId) {
887 ALOGE("Ignoring connection of external display %" PRIu64 " in VR mode", hwcDisplayId);
Marin Shalamanovbdd59152020-02-14 15:30:06 +0100888 return true;
Steven Thomas6e8f7062017-11-22 14:15:29 -0800889 }
Dominik Laskowski075d3172018-05-24 15:50:06 -0700890
Marin Shalamanovbdd59152020-02-14 15:30:06 +0100891 if (mHasMultiDisplaySupport && !hasDisplayIdentificationData) {
Dominik Laskowski075d3172018-05-24 15:50:06 -0700892 ALOGE("Ignoring connection of display %" PRIu64 " without identification data",
893 hwcDisplayId);
Marin Shalamanovbdd59152020-02-14 15:30:06 +0100894 return true;
Dominik Laskowski075d3172018-05-24 15:50:06 -0700895 }
896
Marin Shalamanovbdd59152020-02-14 15:30:06 +0100897 if (!mHasMultiDisplaySupport && mInternalHwcDisplayId && mExternalHwcDisplayId) {
Dominik Laskowski075d3172018-05-24 15:50:06 -0700898 ALOGE("Ignoring connection of tertiary display %" PRIu64, hwcDisplayId);
Marin Shalamanovbdd59152020-02-14 15:30:06 +0100899 return true;
900 }
901
902 return false;
903}
904
Peiyong Line9d809e2020-04-14 13:10:48 -0700905std::optional<DisplayIdentificationInfo> HWComposer::onHotplugConnect(
906 hal::HWDisplayId hwcDisplayId) {
Marin Shalamanovbdd59152020-02-14 15:30:06 +0100907 std::optional<DisplayIdentificationInfo> info;
908 if (const auto displayId = toPhysicalDisplayId(hwcDisplayId)) {
909 info = DisplayIdentificationInfo{.id = *displayId,
910 .name = std::string(),
911 .deviceProductInfo = std::nullopt};
Dominik Laskowski075d3172018-05-24 15:50:06 -0700912 } else {
Marin Shalamanovbdd59152020-02-14 15:30:06 +0100913 uint8_t port;
914 DisplayIdentificationData data;
915 const bool hasDisplayIdentificationData =
916 getDisplayIdentificationData(hwcDisplayId, &port, &data);
917 if (mPhysicalDisplayIdMap.empty()) {
918 mHasMultiDisplaySupport = hasDisplayIdentificationData;
919 ALOGI("Switching to %s multi-display mode",
920 mHasMultiDisplaySupport ? "generalized" : "legacy");
921 }
922
923 if (shouldIgnoreHotplugConnect(hwcDisplayId, hasDisplayIdentificationData)) {
924 return {};
925 }
926
927 info = [this, hwcDisplayId, &port, &data, hasDisplayIdentificationData] {
928 const bool isPrimary = !mInternalHwcDisplayId;
929 if (mHasMultiDisplaySupport) {
930 if (const auto info = parseDisplayIdentificationData(port, data)) {
931 return *info;
932 }
933 ALOGE("Failed to parse identification data for display %" PRIu64, hwcDisplayId);
934 } else {
935 ALOGW_IF(hasDisplayIdentificationData,
936 "Ignoring identification data for display %" PRIu64, hwcDisplayId);
Peiyong Lin65248e02020-04-18 21:15:07 -0700937 port = isPrimary ? LEGACY_DISPLAY_TYPE_PRIMARY : LEGACY_DISPLAY_TYPE_EXTERNAL;
Marin Shalamanovbdd59152020-02-14 15:30:06 +0100938 }
939
940 return DisplayIdentificationInfo{.id = getFallbackDisplayId(port),
941 .name = isPrimary ? "Internal display"
942 : "External display",
943 .deviceProductInfo = std::nullopt};
944 }();
Dominik Laskowski075d3172018-05-24 15:50:06 -0700945 }
946
Marin Shalamanovbdd59152020-02-14 15:30:06 +0100947 if (!isConnected(info->id)) {
948 allocatePhysicalDisplay(hwcDisplayId, info->id);
949 }
950 return info;
951}
952
953std::optional<DisplayIdentificationInfo> HWComposer::onHotplugDisconnect(
Peiyong Line9d809e2020-04-14 13:10:48 -0700954 hal::HWDisplayId hwcDisplayId) {
Marin Shalamanovbdd59152020-02-14 15:30:06 +0100955 const auto displayId = toPhysicalDisplayId(hwcDisplayId);
956 if (!displayId) {
957 ALOGE("Ignoring disconnection of invalid HWC display %" PRIu64, hwcDisplayId);
958 return {};
Dominik Laskowski075d3172018-05-24 15:50:06 -0700959 }
960
Marin Shalamanovbdd59152020-02-14 15:30:06 +0100961 // The display will later be destroyed by a call to
962 // destroyDisplay(). For now we just mark it disconnected.
963 if (isConnected(*displayId)) {
964 mDisplayData[*displayId].hwcDisplay->setConnected(false);
965 } else {
966 ALOGW("Attempted to disconnect unknown display %" PRIu64, hwcDisplayId);
967 }
968 // The cleanup of Disconnect is handled through HWComposer::disconnectDisplay
969 // via SurfaceFlinger's onHotplugReceived callback handling
970 return DisplayIdentificationInfo{.id = *displayId,
971 .name = std::string(),
Marin Shalamanovf5de90d2019-10-08 10:57:25 +0200972 .deviceProductInfo = std::nullopt};
Steven Thomas6e8f7062017-11-22 14:15:29 -0800973}
974
Peiyong Linbdd08cc2019-12-17 21:35:14 -0800975void HWComposer::loadCapabilities() {
Peiyong Line9d809e2020-04-14 13:10:48 -0700976 static_assert(sizeof(hal::Capability) == sizeof(int32_t), "Capability size has changed");
Peiyong Linbdd08cc2019-12-17 21:35:14 -0800977 auto capabilities = mComposer->getCapabilities();
978 for (auto capability : capabilities) {
Peiyong Line9d809e2020-04-14 13:10:48 -0700979 mCapabilities.emplace(static_cast<hal::Capability>(capability));
Peiyong Linbdd08cc2019-12-17 21:35:14 -0800980 }
981}
982
Lloyd Pique4603f3c2020-02-11 12:06:56 -0800983void HWComposer::loadLayerMetadataSupport() {
984 mSupportedLayerGenericMetadata.clear();
985
986 std::vector<Hwc2::IComposerClient::LayerGenericMetadataKey> supportedMetadataKeyInfo;
987 const auto error = mComposer->getLayerGenericMetadataKeys(&supportedMetadataKeyInfo);
988 if (error != hardware::graphics::composer::V2_4::Error::NONE) {
989 ALOGE("%s: %s failed: %s (%d)", __FUNCTION__, "getLayerGenericMetadataKeys",
990 toString(error).c_str(), static_cast<int32_t>(error));
991 return;
992 }
993
994 for (const auto& [name, mandatory] : supportedMetadataKeyInfo) {
995 mSupportedLayerGenericMetadata.emplace(name, mandatory);
996 }
997}
998
Peiyong Linbdd08cc2019-12-17 21:35:14 -0800999uint32_t HWComposer::getMaxVirtualDisplayCount() const {
1000 return mComposer->getMaxVirtualDisplayCount();
1001}
1002
Lloyd Pique441d5042018-10-18 16:49:51 -07001003} // namespace impl
Dominik Laskowskif9750f22018-06-06 12:24:53 -07001004} // namespace android
Ady Abrahamb0dbdaa2020-01-06 16:19:42 -08001005
1006// TODO(b/129481165): remove the #pragma below and fix conversion issues
1007#pragma clang diagnostic pop // ignored "-Wconversion"