blob: 36876dc7f19f176c9576f79ab5937b9a6718c6a5 [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
Marin Shalamanovf8c63722020-10-06 13:11:21 +020029#include <android-base/properties.h>
Lloyd Pique37c2c9b2018-12-04 17:25:10 -080030#include <compositionengine/Output.h>
31#include <compositionengine/OutputLayer.h>
32#include <compositionengine/impl/OutputLayerCompositionState.h>
Dominik Laskowski4e2b71f2020-11-10 15:05:32 -080033#include <ftl/future.h>
Lloyd Pique37c2c9b2018-12-04 17:25:10 -080034#include <log/log.h>
Dominik Laskowskifc2c0322018-04-19 14:47:33 -070035#include <ui/DebugUtils.h>
Mathias Agopian921e6ac2012-07-23 23:11:29 -070036#include <ui/GraphicBuffer.h>
Lloyd Pique37c2c9b2018-12-04 17:25:10 -080037#include <utils/Errors.h>
38#include <utils/Trace.h>
Mathias Agopiana350ff92010-08-10 17:14:02 -070039
Lloyd Pique66d68602019-02-13 14:23:31 -080040#include "../Layer.h" // needed only for debugging
Mathias Agopian33ceeb32013-04-01 16:54:58 -070041#include "../SurfaceFlinger.h"
Marin Shalamanovf8c63722020-10-06 13:11:21 +020042#include "../SurfaceFlingerProperties.h"
Lloyd Pique66d68602019-02-13 14:23:31 -080043#include "ComposerHal.h"
44#include "HWC2.h"
Mathias Agopiana350ff92010-08-10 17:14:02 -070045
Dominik Laskowskic1f18f62018-06-13 15:17:55 -070046#define LOG_HWC_DISPLAY_ERROR(hwcDisplayId, msg) \
47 ALOGE("%s failed for HWC display %" PRIu64 ": %s", __FUNCTION__, hwcDisplayId, msg)
48
Dominik Laskowskifc2c0322018-04-19 14:47:33 -070049#define LOG_DISPLAY_ERROR(displayId, msg) \
Dominik Laskowski34157762018-10-31 13:07:19 -070050 ALOGE("%s failed for display %s: %s", __FUNCTION__, to_string(displayId).c_str(), msg)
Dominik Laskowskifc2c0322018-04-19 14:47:33 -070051
Dominik Laskowski34157762018-10-31 13:07:19 -070052#define LOG_HWC_ERROR(what, error, displayId) \
53 ALOGE("%s: %s failed for display %s: %s (%d)", __FUNCTION__, what, \
54 to_string(displayId).c_str(), to_string(error).c_str(), static_cast<int32_t>(error))
Dominik Laskowskifc2c0322018-04-19 14:47:33 -070055
56#define RETURN_IF_INVALID_DISPLAY(displayId, ...) \
57 do { \
Dominik Laskowski075d3172018-05-24 15:50:06 -070058 if (mDisplayData.count(displayId) == 0) { \
Dominik Laskowskifc2c0322018-04-19 14:47:33 -070059 LOG_DISPLAY_ERROR(displayId, "Invalid display"); \
60 return __VA_ARGS__; \
61 } \
62 } while (false)
63
64#define RETURN_IF_HWC_ERROR_FOR(what, error, displayId, ...) \
65 do { \
Peiyong Line9d809e2020-04-14 13:10:48 -070066 if (error != hal::Error::NONE) { \
Dominik Laskowskifc2c0322018-04-19 14:47:33 -070067 LOG_HWC_ERROR(what, error, displayId); \
68 return __VA_ARGS__; \
69 } \
70 } while (false)
71
72#define RETURN_IF_HWC_ERROR(error, displayId, ...) \
73 RETURN_IF_HWC_ERROR_FOR(__FUNCTION__, error, displayId, __VA_ARGS__)
74
Peiyong Line9d809e2020-04-14 13:10:48 -070075namespace hal = android::hardware::graphics::composer::hal;
76
Marin Shalamanov6e840172020-12-14 22:13:28 +010077namespace android {
Peiyong Linbdd08cc2019-12-17 21:35:14 -080078namespace {
79
80using android::hardware::Return;
81using android::hardware::Void;
Peiyong Line9d809e2020-04-14 13:10:48 -070082using android::HWC2::ComposerCallback;
Peiyong Linbdd08cc2019-12-17 21:35:14 -080083
Peiyong Line9d809e2020-04-14 13:10:48 -070084class ComposerCallbackBridge : public hal::IComposerCallback {
Peiyong Linbdd08cc2019-12-17 21:35:14 -080085public:
Peiyong Line9d809e2020-04-14 13:10:48 -070086 ComposerCallbackBridge(ComposerCallback* callback, int32_t sequenceId,
Peiyong Linbdd08cc2019-12-17 21:35:14 -080087 bool vsyncSwitchingSupported)
88 : mCallback(callback),
89 mSequenceId(sequenceId),
90 mVsyncSwitchingSupported(vsyncSwitchingSupported) {}
91
Marin Shalamanov6e840172020-12-14 22:13:28 +010092 Return<void> onHotplug(hal::HWDisplayId display, hal::Connection conn) override {
Peiyong Line9d809e2020-04-14 13:10:48 -070093 mCallback->onHotplugReceived(mSequenceId, display, conn);
Marin Shalamanov6e840172020-12-14 22:13:28 +010094 return Void();
Peiyong Linbdd08cc2019-12-17 21:35:14 -080095 }
96
Marin Shalamanov6e840172020-12-14 22:13:28 +010097 Return<void> onRefresh(hal::HWDisplayId display) override {
Peiyong Linbdd08cc2019-12-17 21:35:14 -080098 mCallback->onRefreshReceived(mSequenceId, display);
Marin Shalamanov6e840172020-12-14 22:13:28 +010099 return Void();
Peiyong Linbdd08cc2019-12-17 21:35:14 -0800100 }
101
Marin Shalamanov6e840172020-12-14 22:13:28 +0100102 Return<void> onVsync(hal::HWDisplayId display, int64_t timestamp) override {
Peiyong Linbdd08cc2019-12-17 21:35:14 -0800103 if (!mVsyncSwitchingSupported) {
104 mCallback->onVsyncReceived(mSequenceId, display, timestamp, std::nullopt);
105 } else {
106 ALOGW("Unexpected onVsync callback on composer >= 2.4, ignoring.");
107 }
Marin Shalamanov6e840172020-12-14 22:13:28 +0100108 return Void();
Peiyong Linbdd08cc2019-12-17 21:35:14 -0800109 }
110
Marin Shalamanov6e840172020-12-14 22:13:28 +0100111 Return<void> onVsync_2_4(hal::HWDisplayId display, int64_t timestamp,
112 hal::VsyncPeriodNanos vsyncPeriodNanos) override {
Peiyong Linbdd08cc2019-12-17 21:35:14 -0800113 if (mVsyncSwitchingSupported) {
Peiyong Linbdd08cc2019-12-17 21:35:14 -0800114 mCallback->onVsyncReceived(mSequenceId, display, timestamp,
115 std::make_optional(vsyncPeriodNanos));
116 } else {
117 ALOGW("Unexpected onVsync_2_4 callback on composer <= 2.3, ignoring.");
118 }
Marin Shalamanov6e840172020-12-14 22:13:28 +0100119 return Void();
Peiyong Linbdd08cc2019-12-17 21:35:14 -0800120 }
121
Marin Shalamanov6e840172020-12-14 22:13:28 +0100122 Return<void> onVsyncPeriodTimingChanged(
Peiyong Line9d809e2020-04-14 13:10:48 -0700123 hal::HWDisplayId display,
124 const hal::VsyncPeriodChangeTimeline& updatedTimeline) override {
125 mCallback->onVsyncPeriodTimingChangedReceived(mSequenceId, display, updatedTimeline);
Marin Shalamanov6e840172020-12-14 22:13:28 +0100126 return Void();
Peiyong Linbdd08cc2019-12-17 21:35:14 -0800127 }
128
Marin Shalamanov6e840172020-12-14 22:13:28 +0100129 Return<void> onSeamlessPossible(hal::HWDisplayId display) override {
Ady Abrahamb0433bc2020-01-08 17:31:06 -0800130 mCallback->onSeamlessPossible(mSequenceId, display);
Marin Shalamanov6e840172020-12-14 22:13:28 +0100131 return Void();
Ady Abrahamb0433bc2020-01-08 17:31:06 -0800132 }
133
Peiyong Linbdd08cc2019-12-17 21:35:14 -0800134private:
Peiyong Line9d809e2020-04-14 13:10:48 -0700135 ComposerCallback* mCallback;
Peiyong Linbdd08cc2019-12-17 21:35:14 -0800136 const int32_t mSequenceId;
137 const bool mVsyncSwitchingSupported;
138};
139
140} // namespace
141
Lloyd Pique441d5042018-10-18 16:49:51 -0700142HWComposer::~HWComposer() = default;
143
144namespace impl {
145
Marin Shalamanovf8c63722020-10-06 13:11:21 +0200146HWComposer::HWComposer(std::unique_ptr<Hwc2::Composer> composer)
147 : mComposer(std::move(composer)),
148 mUpdateDeviceProductInfoOnHotplugReconnect(
149 android::sysprop::update_device_product_info_on_hotplug_reconnect(false)) {}
Peiyong Linbdd08cc2019-12-17 21:35:14 -0800150
151HWComposer::HWComposer(const std::string& composerServiceName)
Marin Shalamanovf8c63722020-10-06 13:11:21 +0200152 : HWComposer(std::make_unique<Hwc2::impl::Composer>(composerServiceName)) {}
Mathias Agopianbef42c52013-08-21 17:45:46 -0700153
Dominik Laskowskib04f98a2018-11-07 21:07:16 -0800154HWComposer::~HWComposer() {
155 mDisplayData.clear();
156}
Dan Stoza9e56aa02015-11-02 13:00:03 -0800157
Lloyd Pique4603f3c2020-02-11 12:06:56 -0800158void HWComposer::setConfiguration(HWC2::ComposerCallback* callback, int32_t sequenceId) {
159 loadCapabilities();
160 loadLayerMetadataSupport();
161
Peiyong Linbdd08cc2019-12-17 21:35:14 -0800162 if (mRegisteredCallback) {
163 ALOGW("Callback already registered. Ignored extra registration attempt.");
164 return;
165 }
166 mRegisteredCallback = true;
167 sp<ComposerCallbackBridge> callbackBridge(
168 new ComposerCallbackBridge(callback, sequenceId,
169 mComposer->isVsyncPeriodSwitchSupported()));
170 mComposer->registerCallback(callbackBridge);
Dan Stoza9e56aa02015-11-02 13:00:03 -0800171}
172
Peiyong Line9d809e2020-04-14 13:10:48 -0700173bool HWComposer::getDisplayIdentificationData(hal::HWDisplayId hwcDisplayId, uint8_t* outPort,
Dominik Laskowskie9ef7c42018-03-12 19:34:30 -0700174 DisplayIdentificationData* outData) const {
Peiyong Line9d809e2020-04-14 13:10:48 -0700175 const auto error = static_cast<hal::Error>(
Peiyong Linbdd08cc2019-12-17 21:35:14 -0800176 mComposer->getDisplayIdentificationData(hwcDisplayId, outPort, outData));
Peiyong Line9d809e2020-04-14 13:10:48 -0700177 if (error != hal::Error::NONE) {
178 if (error != hal::Error::UNSUPPORTED) {
Chia-I Wud0aff9d2018-06-21 13:39:09 +0800179 LOG_HWC_DISPLAY_ERROR(hwcDisplayId, to_string(error).c_str());
180 }
Dominik Laskowskie9ef7c42018-03-12 19:34:30 -0700181 return false;
182 }
183 return true;
184}
185
Peiyong Line9d809e2020-04-14 13:10:48 -0700186bool HWComposer::hasCapability(hal::Capability capability) const {
Peiyong Linbdd08cc2019-12-17 21:35:14 -0800187 return mCapabilities.count(capability) > 0;
Dan Stoza9f26a9c2016-06-22 14:51:09 -0700188}
189
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200190bool HWComposer::hasDisplayCapability(HalDisplayId displayId,
Peiyong Line9d809e2020-04-14 13:10:48 -0700191 hal::DisplayCapability capability) const {
Dominik Laskowski1162e472020-04-02 19:02:47 -0700192 RETURN_IF_INVALID_DISPLAY(displayId, false);
193 return mDisplayData.at(displayId).hwcDisplay->getCapabilities().count(capability) > 0;
Peiyong Lined531a32018-10-26 18:27:56 -0700194}
195
Peiyong Line9d809e2020-04-14 13:10:48 -0700196std::optional<DisplayIdentificationInfo> HWComposer::onHotplug(hal::HWDisplayId hwcDisplayId,
197 hal::Connection connection) {
Marin Shalamanovbdd59152020-02-14 15:30:06 +0100198 switch (connection) {
Peiyong Line9d809e2020-04-14 13:10:48 -0700199 case hal::Connection::CONNECTED:
Marin Shalamanovbdd59152020-02-14 15:30:06 +0100200 return onHotplugConnect(hwcDisplayId);
Peiyong Line9d809e2020-04-14 13:10:48 -0700201 case hal::Connection::DISCONNECTED:
Marin Shalamanovbdd59152020-02-14 15:30:06 +0100202 return onHotplugDisconnect(hwcDisplayId);
Peiyong Line9d809e2020-04-14 13:10:48 -0700203 case hal::Connection::INVALID:
Dominik Laskowski075d3172018-05-24 15:50:06 -0700204 return {};
Dominik Laskowskie9ef7c42018-03-12 19:34:30 -0700205 }
Andy McFaddenb0d1dd32012-09-10 14:08:09 -0700206}
207
Marin Shalamanovf8c63722020-10-06 13:11:21 +0200208bool HWComposer::updatesDeviceProductInfoOnHotplugReconnect() const {
209 return mUpdateDeviceProductInfoOnHotplugReconnect;
210}
211
Peiyong Line9d809e2020-04-14 13:10:48 -0700212bool HWComposer::onVsync(hal::HWDisplayId hwcDisplayId, int64_t timestamp) {
Dominik Laskowski075d3172018-05-24 15:50:06 -0700213 const auto displayId = toPhysicalDisplayId(hwcDisplayId);
214 if (!displayId) {
215 LOG_HWC_DISPLAY_ERROR(hwcDisplayId, "Invalid HWC display");
Steven Thomas94e35b92017-07-26 18:48:28 -0700216 return false;
Jesse Hall1bd20e02012-08-29 10:47:52 -0700217 }
Jesse Hall1bd20e02012-08-29 10:47:52 -0700218
Dominik Laskowski075d3172018-05-24 15:50:06 -0700219 RETURN_IF_INVALID_DISPLAY(*displayId, false);
Dominik Laskowskic1f18f62018-06-13 15:17:55 -0700220
Dominik Laskowski1af47932018-11-12 10:20:46 -0800221 auto& displayData = mDisplayData[*displayId];
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200222 LOG_FATAL_IF(displayData.isVirtual, "%s: Invalid operation on virtual display with ID %s",
223 __FUNCTION__, to_string(*displayId).c_str());
Jesse Hall1bd20e02012-08-29 10:47:52 -0700224
Dan Stoza9e56aa02015-11-02 13:00:03 -0800225 {
Dan Stoza9e56aa02015-11-02 13:00:03 -0800226 // There have been reports of HWCs that signal several vsync events
227 // with the same timestamp when turning the display off and on. This
228 // is a bug in the HWC implementation, but filter the extra events
229 // out here so they don't cause havoc downstream.
Dominik Laskowski1af47932018-11-12 10:20:46 -0800230 if (timestamp == displayData.lastHwVsync) {
Dominik Laskowski34157762018-10-31 13:07:19 -0700231 ALOGW("Ignoring duplicate VSYNC event from HWC for display %s (t=%" PRId64 ")",
232 to_string(*displayId).c_str(), timestamp);
Steven Thomas94e35b92017-07-26 18:48:28 -0700233 return false;
Dan Stoza9e56aa02015-11-02 13:00:03 -0800234 }
235
Dominik Laskowski1af47932018-11-12 10:20:46 -0800236 displayData.lastHwVsync = timestamp;
Jesse Hall1c569c42013-04-05 13:44:52 -0700237 }
Dan Stoza9e56aa02015-11-02 13:00:03 -0800238
Dominik Laskowski34157762018-10-31 13:07:19 -0700239 const auto tag = "HW_VSYNC_" + to_string(*displayId);
Dominik Laskowski1af47932018-11-12 10:20:46 -0800240 ATRACE_INT(tag.c_str(), displayData.vsyncTraceToggle);
241 displayData.vsyncTraceToggle = !displayData.vsyncTraceToggle;
Dan Stoza9e56aa02015-11-02 13:00:03 -0800242
Steven Thomas94e35b92017-07-26 18:48:28 -0700243 return true;
Jesse Hall1c569c42013-04-05 13:44:52 -0700244}
245
Dominik Laskowski075d3172018-05-24 15:50:06 -0700246std::optional<DisplayId> HWComposer::allocateVirtualDisplay(uint32_t width, uint32_t height,
247 ui::PixelFormat* format) {
Fabien Sanglardc8e387e2017-03-10 10:30:28 -0800248 if (SurfaceFlinger::maxVirtualDisplaySize != 0 &&
249 (width > SurfaceFlinger::maxVirtualDisplaySize ||
250 height > SurfaceFlinger::maxVirtualDisplaySize)) {
Dominik Laskowskif3749f82018-06-13 15:49:25 -0700251 ALOGE("%s: Display size %ux%u exceeds maximum dimension of %" PRIu64, __FUNCTION__, width,
252 height, SurfaceFlinger::maxVirtualDisplaySize);
Dominik Laskowski075d3172018-05-24 15:50:06 -0700253 return {};
Fabien Sanglarde29055f2017-03-08 11:36:46 -0800254 }
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200255
256 const auto displayId = mVirtualIdGenerator.nextId();
257 if (!displayId) {
258 ALOGE("%s: No remaining virtual displays", __FUNCTION__);
259 return {};
260 }
261
Peiyong Line9d809e2020-04-14 13:10:48 -0700262 hal::HWDisplayId hwcDisplayId = 0;
263 const auto error = static_cast<hal::Error>(
Peiyong Linbdd08cc2019-12-17 21:35:14 -0800264 mComposer->createVirtualDisplay(width, height, format, &hwcDisplayId));
Peiyong Line9d809e2020-04-14 13:10:48 -0700265 if (error != hal::Error::NONE) {
Dominik Laskowskif3749f82018-06-13 15:49:25 -0700266 ALOGE("%s: Failed to create HWC virtual display", __FUNCTION__);
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200267 mVirtualIdGenerator.markUnused(*displayId);
Dominik Laskowski075d3172018-05-24 15:50:06 -0700268 return {};
Mathias Agopiane60b0682012-08-21 23:34:09 -0700269 }
Dan Stoza9e56aa02015-11-02 13:00:03 -0800270
Peiyong Linbdd08cc2019-12-17 21:35:14 -0800271 auto display = std::make_unique<HWC2::impl::Display>(*mComposer.get(), mCapabilities,
Peiyong Line9d809e2020-04-14 13:10:48 -0700272 hwcDisplayId, hal::DisplayType::VIRTUAL);
Peiyong Linbdd08cc2019-12-17 21:35:14 -0800273 display->setConnected(true);
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200274 auto& displayData = mDisplayData[*displayId];
Peiyong Linbdd08cc2019-12-17 21:35:14 -0800275 displayData.hwcDisplay = std::move(display);
Dominik Laskowskic1f18f62018-06-13 15:17:55 -0700276 displayData.isVirtual = true;
Dominik Laskowski075d3172018-05-24 15:50:06 -0700277 return displayId;
Mathias Agopiane60b0682012-08-21 23:34:09 -0700278}
279
Marin Shalamanova524a092020-07-27 21:39:55 +0200280void HWComposer::allocatePhysicalDisplay(hal::HWDisplayId hwcDisplayId,
281 PhysicalDisplayId displayId) {
Marin Shalamanov3ea1d602020-12-16 19:59:39 +0100282 mPhysicalDisplayIdMap[hwcDisplayId] = displayId;
283
Marin Shalamanovbdd59152020-02-14 15:30:06 +0100284 if (!mInternalHwcDisplayId) {
285 mInternalHwcDisplayId = hwcDisplayId;
286 } else if (mInternalHwcDisplayId != hwcDisplayId && !mExternalHwcDisplayId) {
287 mExternalHwcDisplayId = hwcDisplayId;
288 }
289
290 auto& displayData = mDisplayData[displayId];
291 auto newDisplay =
292 std::make_unique<HWC2::impl::Display>(*mComposer.get(), mCapabilities, hwcDisplayId,
Peiyong Line9d809e2020-04-14 13:10:48 -0700293 hal::DisplayType::PHYSICAL);
Marin Shalamanovbdd59152020-02-14 15:30:06 +0100294 newDisplay->setConnected(true);
295 displayData.hwcDisplay = std::move(newDisplay);
Marin Shalamanov3ea1d602020-12-16 19:59:39 +0100296}
297
298int32_t HWComposer::getAttribute(hal::HWDisplayId hwcDisplayId, hal::HWConfigId configId,
Marin Shalamanov045b7002021-01-07 16:56:24 +0100299 hal::Attribute attribute) const {
Marin Shalamanov3ea1d602020-12-16 19:59:39 +0100300 int32_t value = 0;
301 auto error = static_cast<hal::Error>(
302 mComposer->getDisplayAttribute(hwcDisplayId, configId, attribute, &value));
303
304 RETURN_IF_HWC_ERROR_FOR("getDisplayAttribute", error, *toPhysicalDisplayId(hwcDisplayId), -1);
305 return value;
306}
307
Lloyd Pique1b33fc32021-05-07 14:36:58 -0700308std::shared_ptr<HWC2::Layer> HWComposer::createLayer(HalDisplayId displayId) {
Dominik Laskowskifc2c0322018-04-19 14:47:33 -0700309 RETURN_IF_INVALID_DISPLAY(displayId, nullptr);
310
Lloyd Pique1b33fc32021-05-07 14:36:58 -0700311 auto expected = mDisplayData[displayId].hwcDisplay->createLayer();
312 if (!expected.has_value()) {
313 auto error = std::move(expected).error();
314 RETURN_IF_HWC_ERROR(error, displayId, nullptr);
315 }
316 return std::move(expected).value();
Steven Thomas94e35b92017-07-26 18:48:28 -0700317}
318
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200319bool HWComposer::isConnected(PhysicalDisplayId displayId) const {
Ady Abraham2e9c7032021-03-29 14:01:56 -0700320 if (mDisplayData.count(displayId)) {
321 return mDisplayData.at(displayId).hwcDisplay->isConnected();
322 }
323
324 return false;
Mathias Agopian9c6e2972011-09-20 17:21:56 -0700325}
326
Marin Shalamanov045b7002021-01-07 16:56:24 +0100327std::vector<HWComposer::HWCDisplayMode> HWComposer::getModes(PhysicalDisplayId displayId) const {
Dominik Laskowskifc2c0322018-04-19 14:47:33 -0700328 RETURN_IF_INVALID_DISPLAY(displayId, {});
329
Marin Shalamanov045b7002021-01-07 16:56:24 +0100330 const auto hwcDisplayId = mDisplayData.at(displayId).hwcDisplay->getId();
331 std::vector<hal::HWConfigId> configIds;
332 auto error = static_cast<hal::Error>(mComposer->getDisplayConfigs(hwcDisplayId, &configIds));
333 RETURN_IF_HWC_ERROR_FOR("getDisplayConfigs", error, *toPhysicalDisplayId(hwcDisplayId), {});
334
335 std::vector<HWCDisplayMode> modes;
336 modes.reserve(configIds.size());
337 for (auto configId : configIds) {
338 modes.push_back(HWCDisplayMode{
339 .hwcId = configId,
340 .width = getAttribute(hwcDisplayId, configId, hal::Attribute::WIDTH),
341 .height = getAttribute(hwcDisplayId, configId, hal::Attribute::HEIGHT),
342 .vsyncPeriod = getAttribute(hwcDisplayId, configId, hal::Attribute::VSYNC_PERIOD),
343 .dpiX = getAttribute(hwcDisplayId, configId, hal::Attribute::DPI_X),
344 .dpiY = getAttribute(hwcDisplayId, configId, hal::Attribute::DPI_Y),
345 .configGroup = getAttribute(hwcDisplayId, configId, hal::Attribute::CONFIG_GROUP),
346 });
347 }
348
349 return modes;
Mathias Agopianda27af92012-09-13 18:17:13 -0700350}
351
Marin Shalamanov045b7002021-01-07 16:56:24 +0100352std::optional<hal::HWConfigId> HWComposer::getActiveMode(PhysicalDisplayId displayId) const {
353 RETURN_IF_INVALID_DISPLAY(displayId, std::nullopt);
Dominik Laskowskifc2c0322018-04-19 14:47:33 -0700354
Marin Shalamanov3ea1d602020-12-16 19:59:39 +0100355 const auto hwcId = *fromPhysicalDisplayId(displayId);
356 ALOGV("[%" PRIu64 "] getActiveMode", hwcId);
357 hal::HWConfigId configId;
358 auto error = static_cast<hal::Error>(mComposer->getActiveConfig(hwcId, &configId));
359
Peiyong Line9d809e2020-04-14 13:10:48 -0700360 if (error == hal::Error::BAD_CONFIG) {
Marin Shalamanov3ea1d602020-12-16 19:59:39 +0100361 LOG_DISPLAY_ERROR(displayId, "No active mode");
Marin Shalamanov045b7002021-01-07 16:56:24 +0100362 return std::nullopt;
Dominik Laskowskifc2c0322018-04-19 14:47:33 -0700363 }
364
Marin Shalamanov045b7002021-01-07 16:56:24 +0100365 return configId;
Mathias Agopiana350ff92010-08-10 17:14:02 -0700366}
367
Ady Abraham3a77a7b2019-12-02 18:46:59 -0800368// Composer 2.4
369
Marin Shalamanov228f46b2021-01-28 21:11:45 +0100370ui::DisplayConnectionType HWComposer::getDisplayConnectionType(PhysicalDisplayId displayId) const {
371 RETURN_IF_INVALID_DISPLAY(displayId, ui::DisplayConnectionType::Internal);
Dominik Laskowski55c85402020-01-21 16:25:47 -0800372 const auto& hwcDisplay = mDisplayData.at(displayId).hwcDisplay;
373
Marin Shalamanov228f46b2021-01-28 21:11:45 +0100374 ui::DisplayConnectionType type;
Dominik Laskowski55c85402020-01-21 16:25:47 -0800375 const auto error = hwcDisplay->getConnectionType(&type);
376
377 const auto FALLBACK_TYPE = hwcDisplay->getId() == mInternalHwcDisplayId
Marin Shalamanov228f46b2021-01-28 21:11:45 +0100378 ? ui::DisplayConnectionType::Internal
379 : ui::DisplayConnectionType::External;
Dominik Laskowski55c85402020-01-21 16:25:47 -0800380
381 RETURN_IF_HWC_ERROR(error, displayId, FALLBACK_TYPE);
382 return type;
383}
384
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200385bool HWComposer::isVsyncPeriodSwitchSupported(PhysicalDisplayId displayId) const {
Dominik Laskowski55c85402020-01-21 16:25:47 -0800386 RETURN_IF_INVALID_DISPLAY(displayId, false);
Ady Abraham3a77a7b2019-12-02 18:46:59 -0800387 return mDisplayData.at(displayId).hwcDisplay->isVsyncPeriodSwitchSupported();
388}
389
Marin Shalamanov045b7002021-01-07 16:56:24 +0100390status_t HWComposer::getDisplayVsyncPeriod(PhysicalDisplayId displayId,
391 nsecs_t* outVsyncPeriod) const {
Dominik Laskowski55c85402020-01-21 16:25:47 -0800392 RETURN_IF_INVALID_DISPLAY(displayId, 0);
393
Marin Shalamanov045b7002021-01-07 16:56:24 +0100394 if (!isVsyncPeriodSwitchSupported(displayId)) {
395 return INVALID_OPERATION;
Dominik Laskowskif3749f82018-06-13 15:49:25 -0700396 }
Marin Shalamanov045b7002021-01-07 16:56:24 +0100397 const auto hwcId = *fromPhysicalDisplayId(displayId);
398 Hwc2::VsyncPeriodNanos vsyncPeriodNanos = 0;
399 auto error =
400 static_cast<hal::Error>(mComposer->getDisplayVsyncPeriod(hwcId, &vsyncPeriodNanos));
401 RETURN_IF_HWC_ERROR(error, displayId, 0);
402 *outVsyncPeriod = static_cast<nsecs_t>(vsyncPeriodNanos);
403 return NO_ERROR;
Lloyd Pique3c085a02018-05-09 19:38:32 -0700404}
405
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200406std::vector<ui::ColorMode> HWComposer::getColorModes(PhysicalDisplayId displayId) const {
Dominik Laskowskifc2c0322018-04-19 14:47:33 -0700407 RETURN_IF_INVALID_DISPLAY(displayId, {});
408
Peiyong Linfd997e02018-03-28 15:29:00 -0700409 std::vector<ui::ColorMode> modes;
Dominik Laskowski075d3172018-05-24 15:50:06 -0700410 auto error = mDisplayData.at(displayId).hwcDisplay->getColorModes(&modes);
Dominik Laskowskifc2c0322018-04-19 14:47:33 -0700411 RETURN_IF_HWC_ERROR(error, displayId, {});
Courtney Goeltzenleuchterfad9d8c2016-06-23 11:49:50 -0600412 return modes;
413}
414
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200415status_t HWComposer::setActiveColorMode(PhysicalDisplayId displayId, ui::ColorMode mode,
Dominik Laskowski075d3172018-05-24 15:50:06 -0700416 ui::RenderIntent renderIntent) {
Dominik Laskowskifc2c0322018-04-19 14:47:33 -0700417 RETURN_IF_INVALID_DISPLAY(displayId, BAD_INDEX);
Michael Wright28f24d02016-07-12 13:30:53 -0700418
419 auto& displayData = mDisplayData[displayId];
Peiyong Lin0e7a7912018-04-05 14:36:36 -0700420 auto error = displayData.hwcDisplay->setColorMode(mode, renderIntent);
Dominik Laskowskifc2c0322018-04-19 14:47:33 -0700421 RETURN_IF_HWC_ERROR_FOR(("setColorMode(" + decodeColorMode(mode) + ", " +
422 decodeRenderIntent(renderIntent) + ")")
423 .c_str(),
424 error, displayId, UNKNOWN_ERROR);
Michael Wright28f24d02016-07-12 13:30:53 -0700425
426 return NO_ERROR;
427}
428
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200429void HWComposer::setVsyncEnabled(PhysicalDisplayId displayId, hal::Vsync enabled) {
Dominik Laskowskic1f18f62018-06-13 15:17:55 -0700430 RETURN_IF_INVALID_DISPLAY(displayId);
431 auto& displayData = mDisplayData[displayId];
432
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200433 LOG_FATAL_IF(displayData.isVirtual, "%s: Invalid operation on virtual display with ID %s",
434 __FUNCTION__, to_string(displayId).c_str());
Dan Stoza9e56aa02015-11-02 13:00:03 -0800435
Dan Stoza9e56aa02015-11-02 13:00:03 -0800436 // NOTE: we use our own internal lock here because we have to call
437 // into the HWC with the lock held, and we want to make sure
438 // that even if HWC blocks (which it shouldn't), it won't
439 // affect other threads.
Dominik Laskowski1af47932018-11-12 10:20:46 -0800440 std::lock_guard lock(displayData.vsyncEnabledLock);
441 if (enabled == displayData.vsyncEnabled) {
442 return;
Colin Cross10fbdb62012-07-12 17:56:34 -0700443 }
Dominik Laskowski1af47932018-11-12 10:20:46 -0800444
445 ATRACE_CALL();
446 auto error = displayData.hwcDisplay->setVsyncEnabled(enabled);
447 RETURN_IF_HWC_ERROR(error, displayId);
448
449 displayData.vsyncEnabled = enabled;
450
451 const auto tag = "HW_VSYNC_ON_" + to_string(displayId);
Peiyong Line9d809e2020-04-14 13:10:48 -0700452 ATRACE_INT(tag.c_str(), enabled == hal::Vsync::ENABLE ? 1 : 0);
Colin Cross10fbdb62012-07-12 17:56:34 -0700453}
454
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200455status_t HWComposer::setClientTarget(HalDisplayId displayId, uint32_t slot,
Dominik Laskowski075d3172018-05-24 15:50:06 -0700456 const sp<Fence>& acquireFence, const sp<GraphicBuffer>& target,
457 ui::Dataspace dataspace) {
Dominik Laskowskifc2c0322018-04-19 14:47:33 -0700458 RETURN_IF_INVALID_DISPLAY(displayId, BAD_INDEX);
Jesse Hall851cfe82013-03-20 13:44:00 -0700459
Dominik Laskowski34157762018-10-31 13:07:19 -0700460 ALOGV("%s for display %s", __FUNCTION__, to_string(displayId).c_str());
Dan Stoza9e56aa02015-11-02 13:00:03 -0800461 auto& hwcDisplay = mDisplayData[displayId].hwcDisplay;
Daniel Nicoara1f42e3a2017-04-10 13:27:32 -0400462 auto error = hwcDisplay->setClientTarget(slot, target, acquireFence, dataspace);
Dominik Laskowskifc2c0322018-04-19 14:47:33 -0700463 RETURN_IF_HWC_ERROR(error, displayId, BAD_VALUE);
Jesse Hall851cfe82013-03-20 13:44:00 -0700464 return NO_ERROR;
465}
466
Lloyd Pique66d68602019-02-13 14:23:31 -0800467status_t HWComposer::getDeviceCompositionChanges(
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200468 HalDisplayId displayId, bool frameUsesClientComposition,
Ady Abrahamb42cdc12021-05-11 14:31:26 -0700469 std::chrono::steady_clock::time_point earliestPresentTime,
Lloyd Pique66d68602019-02-13 14:23:31 -0800470 std::optional<android::HWComposer::DeviceRequestedChanges>* outChanges) {
Dan Stoza9e56aa02015-11-02 13:00:03 -0800471 ATRACE_CALL();
472
Dominik Laskowskifc2c0322018-04-19 14:47:33 -0700473 RETURN_IF_INVALID_DISPLAY(displayId, BAD_INDEX);
Dan Stoza9e56aa02015-11-02 13:00:03 -0800474
475 auto& displayData = mDisplayData[displayId];
476 auto& hwcDisplay = displayData.hwcDisplay;
477 if (!hwcDisplay->isConnected()) {
478 return NO_ERROR;
479 }
480
481 uint32_t numTypes = 0;
482 uint32_t numRequests = 0;
Fabien Sanglard249c0ae2017-06-19 19:22:36 -0700483
Peiyong Line9d809e2020-04-14 13:10:48 -0700484 hal::Error error = hal::Error::NONE;
Fabien Sanglard249c0ae2017-06-19 19:22:36 -0700485
Ady Abrahamb42cdc12021-05-11 14:31:26 -0700486 // First try to skip validate altogether when we passed the earliest time
487 // to present and there is no client. Otherwise, we may present a frame too
488 // early or in case of client composition we first need to render the
489 // client target buffer.
490 const bool canSkipValidate =
491 std::chrono::steady_clock::now() >= earliestPresentTime && !frameUsesClientComposition;
Fabien Sanglard249c0ae2017-06-19 19:22:36 -0700492 displayData.validateWasSkipped = false;
Ady Abrahamb42cdc12021-05-11 14:31:26 -0700493 if (canSkipValidate) {
Dominik Laskowski1af47932018-11-12 10:20:46 -0800494 sp<Fence> outPresentFence;
Fabien Sanglard249c0ae2017-06-19 19:22:36 -0700495 uint32_t state = UINT32_MAX;
496 error = hwcDisplay->presentOrValidate(&numTypes, &numRequests, &outPresentFence , &state);
Peiyong Line9d809e2020-04-14 13:10:48 -0700497 if (!hasChangesError(error)) {
Dominik Laskowskifc2c0322018-04-19 14:47:33 -0700498 RETURN_IF_HWC_ERROR_FOR("presentOrValidate", error, displayId, UNKNOWN_ERROR);
Fabien Sanglard249c0ae2017-06-19 19:22:36 -0700499 }
500 if (state == 1) { //Present Succeeded.
Steven Thomas94e35b92017-07-26 18:48:28 -0700501 std::unordered_map<HWC2::Layer*, sp<Fence>> releaseFences;
Fabien Sanglard249c0ae2017-06-19 19:22:36 -0700502 error = hwcDisplay->getReleaseFences(&releaseFences);
503 displayData.releaseFences = std::move(releaseFences);
504 displayData.lastPresentFence = outPresentFence;
505 displayData.validateWasSkipped = true;
506 displayData.presentError = error;
507 return NO_ERROR;
508 }
509 // Present failed but Validate ran.
510 } else {
511 error = hwcDisplay->validate(&numTypes, &numRequests);
512 }
513 ALOGV("SkipValidate failed, Falling back to SLOW validate/present");
Peiyong Line9d809e2020-04-14 13:10:48 -0700514 if (!hasChangesError(error)) {
Dominik Laskowskifc2c0322018-04-19 14:47:33 -0700515 RETURN_IF_HWC_ERROR_FOR("validate", error, displayId, BAD_INDEX);
Dan Stoza9e56aa02015-11-02 13:00:03 -0800516 }
517
Lloyd Pique66d68602019-02-13 14:23:31 -0800518 android::HWComposer::DeviceRequestedChanges::ChangedTypes changedTypes;
Dan Stoza9e56aa02015-11-02 13:00:03 -0800519 changedTypes.reserve(numTypes);
520 error = hwcDisplay->getChangedCompositionTypes(&changedTypes);
Dominik Laskowskifc2c0322018-04-19 14:47:33 -0700521 RETURN_IF_HWC_ERROR_FOR("getChangedCompositionTypes", error, displayId, BAD_INDEX);
Dan Stoza9e56aa02015-11-02 13:00:03 -0800522
Peiyong Line9d809e2020-04-14 13:10:48 -0700523 auto displayRequests = static_cast<hal::DisplayRequest>(0);
Lloyd Pique66d68602019-02-13 14:23:31 -0800524 android::HWComposer::DeviceRequestedChanges::LayerRequests layerRequests;
Dan Stoza9e56aa02015-11-02 13:00:03 -0800525 layerRequests.reserve(numRequests);
Lloyd Pique66d68602019-02-13 14:23:31 -0800526 error = hwcDisplay->getRequests(&displayRequests, &layerRequests);
Dominik Laskowskifc2c0322018-04-19 14:47:33 -0700527 RETURN_IF_HWC_ERROR_FOR("getRequests", error, displayId, BAD_INDEX);
Dan Stoza9e56aa02015-11-02 13:00:03 -0800528
Peiyong Lindfc3f7c2020-05-07 20:15:50 -0700529 DeviceRequestedChanges::ClientTargetProperty clientTargetProperty;
530 error = hwcDisplay->getClientTargetProperty(&clientTargetProperty);
Dan Stoza9e56aa02015-11-02 13:00:03 -0800531
Peiyong Lindfc3f7c2020-05-07 20:15:50 -0700532 outChanges->emplace(DeviceRequestedChanges{std::move(changedTypes), std::move(displayRequests),
533 std::move(layerRequests),
534 std::move(clientTargetProperty)});
Dan Stoza9e56aa02015-11-02 13:00:03 -0800535 error = hwcDisplay->acceptChanges();
Dominik Laskowskifc2c0322018-04-19 14:47:33 -0700536 RETURN_IF_HWC_ERROR_FOR("acceptChanges", error, displayId, BAD_INDEX);
Dan Stoza9e56aa02015-11-02 13:00:03 -0800537
538 return NO_ERROR;
539}
540
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200541sp<Fence> HWComposer::getPresentFence(HalDisplayId displayId) const {
Dominik Laskowskifc2c0322018-04-19 14:47:33 -0700542 RETURN_IF_INVALID_DISPLAY(displayId, Fence::NO_FENCE);
Dominik Laskowski075d3172018-05-24 15:50:06 -0700543 return mDisplayData.at(displayId).lastPresentFence;
Jesse Hall851cfe82013-03-20 13:44:00 -0700544}
545
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200546sp<Fence> HWComposer::getLayerReleaseFence(HalDisplayId displayId, HWC2::Layer* layer) const {
Dominik Laskowskifc2c0322018-04-19 14:47:33 -0700547 RETURN_IF_INVALID_DISPLAY(displayId, Fence::NO_FENCE);
Tim Murray2d3f8b82019-12-04 16:24:17 -0800548 const auto& displayFences = mDisplayData.at(displayId).releaseFences;
549 auto fence = displayFences.find(layer);
550 if (fence == displayFences.end()) {
Dan Stoza9e56aa02015-11-02 13:00:03 -0800551 ALOGV("getLayerReleaseFence: Release fence not found");
552 return Fence::NO_FENCE;
Riley Andrews03414a12014-07-01 14:22:59 -0700553 }
Tim Murray2d3f8b82019-12-04 16:24:17 -0800554 return fence->second;
Riley Andrews03414a12014-07-01 14:22:59 -0700555}
556
Ady Abrahamb42cdc12021-05-11 14:31:26 -0700557status_t HWComposer::presentAndGetReleaseFences(
558 HalDisplayId displayId, std::chrono::steady_clock::time_point earliestPresentTime) {
Dan Stoza9e56aa02015-11-02 13:00:03 -0800559 ATRACE_CALL();
Mathias Agopian3e8b8532012-05-13 20:42:01 -0700560
Dominik Laskowskifc2c0322018-04-19 14:47:33 -0700561 RETURN_IF_INVALID_DISPLAY(displayId, BAD_INDEX);
Pablo Ceballosd814cf22015-09-11 14:37:39 -0700562
Dan Stoza9e56aa02015-11-02 13:00:03 -0800563 auto& displayData = mDisplayData[displayId];
564 auto& hwcDisplay = displayData.hwcDisplay;
Fabien Sanglard249c0ae2017-06-19 19:22:36 -0700565
566 if (displayData.validateWasSkipped) {
Chia-I Wuae5a6b82017-10-10 09:09:22 -0700567 // explicitly flush all pending commands
Peiyong Line9d809e2020-04-14 13:10:48 -0700568 auto error = static_cast<hal::Error>(mComposer->executeCommands());
Peiyong Linbdd08cc2019-12-17 21:35:14 -0800569 RETURN_IF_HWC_ERROR_FOR("executeCommands", error, displayId, UNKNOWN_ERROR);
Dominik Laskowskifc2c0322018-04-19 14:47:33 -0700570 RETURN_IF_HWC_ERROR_FOR("present", displayData.presentError, displayId, UNKNOWN_ERROR);
Fabien Sanglard249c0ae2017-06-19 19:22:36 -0700571 return NO_ERROR;
572 }
573
Ady Abrahamb42cdc12021-05-11 14:31:26 -0700574 {
575 ATRACE_NAME("wait for earliest present time");
576 std::this_thread::sleep_until(earliestPresentTime);
577 }
578
Fabien Sanglard11d0fc32016-12-01 15:43:01 -0800579 auto error = hwcDisplay->present(&displayData.lastPresentFence);
Dominik Laskowskifc2c0322018-04-19 14:47:33 -0700580 RETURN_IF_HWC_ERROR_FOR("present", error, displayId, UNKNOWN_ERROR);
Mathias Agopian3e8b8532012-05-13 20:42:01 -0700581
Steven Thomas94e35b92017-07-26 18:48:28 -0700582 std::unordered_map<HWC2::Layer*, sp<Fence>> releaseFences;
Dan Stoza9e56aa02015-11-02 13:00:03 -0800583 error = hwcDisplay->getReleaseFences(&releaseFences);
Dominik Laskowskifc2c0322018-04-19 14:47:33 -0700584 RETURN_IF_HWC_ERROR_FOR("getReleaseFences", error, displayId, UNKNOWN_ERROR);
Dan Stoza9e56aa02015-11-02 13:00:03 -0800585
586 displayData.releaseFences = std::move(releaseFences);
587
588 return NO_ERROR;
Mathias Agopiana350ff92010-08-10 17:14:02 -0700589}
590
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200591status_t HWComposer::setPowerMode(PhysicalDisplayId displayId, hal::PowerMode mode) {
Dominik Laskowskifc2c0322018-04-19 14:47:33 -0700592 RETURN_IF_INVALID_DISPLAY(displayId, BAD_INDEX);
593
Dominik Laskowskic1f18f62018-06-13 15:17:55 -0700594 const auto& displayData = mDisplayData[displayId];
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200595 LOG_FATAL_IF(displayData.isVirtual, "%s: Invalid operation on virtual display with ID %s",
596 __FUNCTION__, to_string(displayId).c_str());
Mathias Agopian3e8b8532012-05-13 20:42:01 -0700597
Peiyong Line9d809e2020-04-14 13:10:48 -0700598 if (mode == hal::PowerMode::OFF) {
599 setVsyncEnabled(displayId, hal::Vsync::DISABLE);
Dan Stoza9e56aa02015-11-02 13:00:03 -0800600 }
601
Dominik Laskowskic1f18f62018-06-13 15:17:55 -0700602 auto& hwcDisplay = displayData.hwcDisplay;
Dan Stoza9e56aa02015-11-02 13:00:03 -0800603 switch (mode) {
Peiyong Line9d809e2020-04-14 13:10:48 -0700604 case hal::PowerMode::OFF:
605 case hal::PowerMode::ON:
Dan Stoza9e56aa02015-11-02 13:00:03 -0800606 ALOGV("setPowerMode: Calling HWC %s", to_string(mode).c_str());
607 {
608 auto error = hwcDisplay->setPowerMode(mode);
Peiyong Line9d809e2020-04-14 13:10:48 -0700609 if (error != hal::Error::NONE) {
610 LOG_HWC_ERROR(("setPowerMode(" + to_string(mode) + ")").c_str(), error,
611 displayId);
Peiyong Lin306e4992018-05-07 16:18:22 -0700612 }
Mathias Agopianda27af92012-09-13 18:17:13 -0700613 }
Dan Stoza9e56aa02015-11-02 13:00:03 -0800614 break;
Peiyong Line9d809e2020-04-14 13:10:48 -0700615 case hal::PowerMode::DOZE:
616 case hal::PowerMode::DOZE_SUSPEND:
Dan Stoza9e56aa02015-11-02 13:00:03 -0800617 ALOGV("setPowerMode: Calling HWC %s", to_string(mode).c_str());
618 {
619 bool supportsDoze = false;
620 auto error = hwcDisplay->supportsDoze(&supportsDoze);
Peiyong Line9d809e2020-04-14 13:10:48 -0700621 if (error != hal::Error::NONE) {
Peiyong Lin306e4992018-05-07 16:18:22 -0700622 LOG_HWC_ERROR("supportsDoze", error, displayId);
623 }
Dominik Laskowskifc2c0322018-04-19 14:47:33 -0700624
Dan Stoza9e56aa02015-11-02 13:00:03 -0800625 if (!supportsDoze) {
Peiyong Line9d809e2020-04-14 13:10:48 -0700626 mode = hal::PowerMode::ON;
Dan Stoza9e56aa02015-11-02 13:00:03 -0800627 }
628
629 error = hwcDisplay->setPowerMode(mode);
Peiyong Line9d809e2020-04-14 13:10:48 -0700630 if (error != hal::Error::NONE) {
631 LOG_HWC_ERROR(("setPowerMode(" + to_string(mode) + ")").c_str(), error,
632 displayId);
Peiyong Lin306e4992018-05-07 16:18:22 -0700633 }
Dan Stoza9e56aa02015-11-02 13:00:03 -0800634 }
635 break;
636 default:
637 ALOGV("setPowerMode: Not calling HWC");
638 break;
Mathias Agopianda27af92012-09-13 18:17:13 -0700639 }
Dan Stoza9e56aa02015-11-02 13:00:03 -0800640
641 return NO_ERROR;
642}
643
Marin Shalamanov3ea1d602020-12-16 19:59:39 +0100644status_t HWComposer::setActiveModeWithConstraints(
Marin Shalamanov12c9e5a2021-01-07 00:25:35 +0100645 PhysicalDisplayId displayId, hal::HWConfigId hwcModeId,
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200646 const hal::VsyncPeriodChangeConstraints& constraints,
Peiyong Line9d809e2020-04-14 13:10:48 -0700647 hal::VsyncPeriodChangeTimeline* outTimeline) {
Dominik Laskowskifc2c0322018-04-19 14:47:33 -0700648 RETURN_IF_INVALID_DISPLAY(displayId, BAD_INDEX);
Dan Stoza9e56aa02015-11-02 13:00:03 -0800649
Marin Shalamanov12c9e5a2021-01-07 00:25:35 +0100650 auto error = mDisplayData[displayId].hwcDisplay->setActiveConfigWithConstraints(hwcModeId,
651 constraints,
652 outTimeline);
Dominik Laskowskifc2c0322018-04-19 14:47:33 -0700653 RETURN_IF_HWC_ERROR(error, displayId, UNKNOWN_ERROR);
Dan Stoza9e56aa02015-11-02 13:00:03 -0800654 return NO_ERROR;
655}
656
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200657status_t HWComposer::setColorTransform(HalDisplayId displayId, const mat4& transform) {
Dominik Laskowskifc2c0322018-04-19 14:47:33 -0700658 RETURN_IF_INVALID_DISPLAY(displayId, BAD_INDEX);
Dan Stoza9f26a9c2016-06-22 14:51:09 -0700659
660 auto& displayData = mDisplayData[displayId];
661 bool isIdentity = transform == mat4();
Peiyong Line9d809e2020-04-14 13:10:48 -0700662 auto error = displayData.hwcDisplay
663 ->setColorTransform(transform,
664 isIdentity ? hal::ColorTransform::IDENTITY
665 : hal::ColorTransform::ARBITRARY_MATRIX);
Dominik Laskowskifc2c0322018-04-19 14:47:33 -0700666 RETURN_IF_HWC_ERROR(error, displayId, UNKNOWN_ERROR);
Dan Stoza9f26a9c2016-06-22 14:51:09 -0700667 return NO_ERROR;
668}
669
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200670void HWComposer::disconnectDisplay(HalDisplayId displayId) {
Dominik Laskowskic1f18f62018-06-13 15:17:55 -0700671 RETURN_IF_INVALID_DISPLAY(displayId);
Dan Stoza9e56aa02015-11-02 13:00:03 -0800672 auto& displayData = mDisplayData[displayId];
673
Dan Stoza9e56aa02015-11-02 13:00:03 -0800674 // If this was a virtual display, add its slot back for reuse by future
675 // virtual displays
Dominik Laskowskic1f18f62018-06-13 15:17:55 -0700676 if (displayData.isVirtual) {
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200677 mVirtualIdGenerator.markUnused(*HalVirtualDisplayId::tryCast(displayId));
Dan Stoza9e56aa02015-11-02 13:00:03 -0800678 }
679
Dominik Laskowski7e045462018-05-30 13:02:02 -0700680 const auto hwcDisplayId = displayData.hwcDisplay->getId();
Dominik Laskowski075d3172018-05-24 15:50:06 -0700681
682 // TODO(b/74619554): Select internal/external display from remaining displays.
683 if (hwcDisplayId == mInternalHwcDisplayId) {
684 mInternalHwcDisplayId.reset();
685 } else if (hwcDisplayId == mExternalHwcDisplayId) {
686 mExternalHwcDisplayId.reset();
687 }
Peiyong Linbdd08cc2019-12-17 21:35:14 -0800688 mPhysicalDisplayIdMap.erase(hwcDisplayId);
689 mDisplayData.erase(displayId);
Dan Stoza9e56aa02015-11-02 13:00:03 -0800690}
691
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200692status_t HWComposer::setOutputBuffer(HalVirtualDisplayId displayId, const sp<Fence>& acquireFence,
Dominik Laskowski075d3172018-05-24 15:50:06 -0700693 const sp<GraphicBuffer>& buffer) {
Dominik Laskowskifc2c0322018-04-19 14:47:33 -0700694 RETURN_IF_INVALID_DISPLAY(displayId, BAD_INDEX);
Dominik Laskowskic1f18f62018-06-13 15:17:55 -0700695 const auto& displayData = mDisplayData[displayId];
Dan Stoza9e56aa02015-11-02 13:00:03 -0800696
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200697 LOG_FATAL_IF(!displayData.isVirtual, "%s: Invalid operation on physical display with ID %s",
698 __FUNCTION__, to_string(displayId).c_str());
Dan Stoza9e56aa02015-11-02 13:00:03 -0800699
Dominik Laskowskic1f18f62018-06-13 15:17:55 -0700700 auto error = displayData.hwcDisplay->setOutputBuffer(buffer, acquireFence);
Dominik Laskowskifc2c0322018-04-19 14:47:33 -0700701 RETURN_IF_HWC_ERROR(error, displayId, UNKNOWN_ERROR);
Dan Stoza9e56aa02015-11-02 13:00:03 -0800702 return NO_ERROR;
703}
704
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200705void HWComposer::clearReleaseFences(HalDisplayId displayId) {
Dominik Laskowskifc2c0322018-04-19 14:47:33 -0700706 RETURN_IF_INVALID_DISPLAY(displayId);
Dan Stoza9e56aa02015-11-02 13:00:03 -0800707 mDisplayData[displayId].releaseFences.clear();
Mathias Agopian3e8b8532012-05-13 20:42:01 -0700708}
709
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200710status_t HWComposer::getHdrCapabilities(HalDisplayId displayId, HdrCapabilities* outCapabilities) {
Dominik Laskowskifc2c0322018-04-19 14:47:33 -0700711 RETURN_IF_INVALID_DISPLAY(displayId, BAD_INDEX);
Dan Stozac4f471e2016-03-24 09:31:08 -0700712
713 auto& hwcDisplay = mDisplayData[displayId].hwcDisplay;
Peiyong Lin62665892018-04-16 11:07:44 -0700714 auto error = hwcDisplay->getHdrCapabilities(outCapabilities);
Dominik Laskowskifc2c0322018-04-19 14:47:33 -0700715 RETURN_IF_HWC_ERROR(error, displayId, UNKNOWN_ERROR);
Peiyong Lin62665892018-04-16 11:07:44 -0700716 return NO_ERROR;
Dan Stozac4f471e2016-03-24 09:31:08 -0700717}
718
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200719int32_t HWComposer::getSupportedPerFrameMetadata(HalDisplayId displayId) const {
Dominik Laskowskifc2c0322018-04-19 14:47:33 -0700720 RETURN_IF_INVALID_DISPLAY(displayId, 0);
Dominik Laskowski075d3172018-05-24 15:50:06 -0700721 return mDisplayData.at(displayId).hwcDisplay->getSupportedPerFrameMetadata();
Peiyong Lin0ac5f4e2018-04-19 22:06:34 -0700722}
723
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200724std::vector<ui::RenderIntent> HWComposer::getRenderIntents(HalDisplayId displayId,
Dominik Laskowski075d3172018-05-24 15:50:06 -0700725 ui::ColorMode colorMode) const {
Dominik Laskowskifc2c0322018-04-19 14:47:33 -0700726 RETURN_IF_INVALID_DISPLAY(displayId, {});
Peiyong Lin0e7a7912018-04-05 14:36:36 -0700727
728 std::vector<ui::RenderIntent> renderIntents;
Dominik Laskowski075d3172018-05-24 15:50:06 -0700729 auto error = mDisplayData.at(displayId).hwcDisplay->getRenderIntents(colorMode, &renderIntents);
Dominik Laskowskifc2c0322018-04-19 14:47:33 -0700730 RETURN_IF_HWC_ERROR(error, displayId, {});
Peiyong Lin0e7a7912018-04-05 14:36:36 -0700731 return renderIntents;
732}
733
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200734mat4 HWComposer::getDataspaceSaturationMatrix(HalDisplayId displayId, ui::Dataspace dataspace) {
Dominik Laskowskifc2c0322018-04-19 14:47:33 -0700735 RETURN_IF_INVALID_DISPLAY(displayId, {});
Peiyong Lin0e7a7912018-04-05 14:36:36 -0700736
737 mat4 matrix;
738 auto error = mDisplayData[displayId].hwcDisplay->getDataspaceSaturationMatrix(dataspace,
739 &matrix);
Dominik Laskowskifc2c0322018-04-19 14:47:33 -0700740 RETURN_IF_HWC_ERROR(error, displayId, {});
Peiyong Lin0e7a7912018-04-05 14:36:36 -0700741 return matrix;
742}
743
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200744status_t HWComposer::getDisplayedContentSamplingAttributes(HalDisplayId displayId,
Kevin DuBois9c0a1762018-10-16 13:32:31 -0700745 ui::PixelFormat* outFormat,
746 ui::Dataspace* outDataspace,
747 uint8_t* outComponentMask) {
748 RETURN_IF_INVALID_DISPLAY(displayId, BAD_INDEX);
749 const auto error =
750 mDisplayData[displayId]
751 .hwcDisplay->getDisplayedContentSamplingAttributes(outFormat, outDataspace,
752 outComponentMask);
Peiyong Line9d809e2020-04-14 13:10:48 -0700753 if (error == hal::Error::UNSUPPORTED) RETURN_IF_HWC_ERROR(error, displayId, INVALID_OPERATION);
Kevin DuBois9c0a1762018-10-16 13:32:31 -0700754 RETURN_IF_HWC_ERROR(error, displayId, UNKNOWN_ERROR);
755 return NO_ERROR;
756}
757
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200758status_t HWComposer::setDisplayContentSamplingEnabled(HalDisplayId displayId, bool enabled,
Kevin DuBois74e53772018-11-19 10:52:38 -0800759 uint8_t componentMask, uint64_t maxFrames) {
760 RETURN_IF_INVALID_DISPLAY(displayId, BAD_INDEX);
761 const auto error =
762 mDisplayData[displayId].hwcDisplay->setDisplayContentSamplingEnabled(enabled,
763 componentMask,
764 maxFrames);
765
Peiyong Line9d809e2020-04-14 13:10:48 -0700766 if (error == hal::Error::UNSUPPORTED) RETURN_IF_HWC_ERROR(error, displayId, INVALID_OPERATION);
767 if (error == hal::Error::BAD_PARAMETER) RETURN_IF_HWC_ERROR(error, displayId, BAD_VALUE);
Kevin DuBois74e53772018-11-19 10:52:38 -0800768 RETURN_IF_HWC_ERROR(error, displayId, UNKNOWN_ERROR);
769 return NO_ERROR;
770}
771
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200772status_t HWComposer::getDisplayedContentSample(HalDisplayId displayId, uint64_t maxFrames,
Kevin DuBois1d4249a2018-08-29 10:45:14 -0700773 uint64_t timestamp, DisplayedFrameStats* outStats) {
774 RETURN_IF_INVALID_DISPLAY(displayId, BAD_INDEX);
775 const auto error =
776 mDisplayData[displayId].hwcDisplay->getDisplayedContentSample(maxFrames, timestamp,
777 outStats);
778 RETURN_IF_HWC_ERROR(error, displayId, UNKNOWN_ERROR);
779 return NO_ERROR;
780}
781
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200782std::future<status_t> HWComposer::setDisplayBrightness(PhysicalDisplayId displayId,
783 float brightness) {
Dominik Laskowski4e2b71f2020-11-10 15:05:32 -0800784 RETURN_IF_INVALID_DISPLAY(displayId, ftl::yield<status_t>(BAD_INDEX));
Dominik Laskowski5690bde2020-04-23 19:04:22 -0700785 auto& display = mDisplayData[displayId].hwcDisplay;
786
Dominik Laskowski4e2b71f2020-11-10 15:05:32 -0800787 return ftl::chain(display->setDisplayBrightness(brightness))
Dominik Laskowski5690bde2020-04-23 19:04:22 -0700788 .then([displayId](hal::Error error) -> status_t {
789 if (error == hal::Error::UNSUPPORTED) {
790 RETURN_IF_HWC_ERROR(error, displayId, INVALID_OPERATION);
791 }
792 if (error == hal::Error::BAD_PARAMETER) {
793 RETURN_IF_HWC_ERROR(error, displayId, BAD_VALUE);
794 }
795 RETURN_IF_HWC_ERROR(error, displayId, UNKNOWN_ERROR);
796 return NO_ERROR;
797 });
Dan Gittik57e63c52019-01-18 16:37:54 +0000798}
799
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200800status_t HWComposer::setAutoLowLatencyMode(PhysicalDisplayId displayId, bool on) {
Galia Peycheva5492cb52019-10-30 14:13:16 +0100801 RETURN_IF_INVALID_DISPLAY(displayId, BAD_INDEX);
802 const auto error = mDisplayData[displayId].hwcDisplay->setAutoLowLatencyMode(on);
Peiyong Line9d809e2020-04-14 13:10:48 -0700803 if (error == hal::Error::UNSUPPORTED) {
Galia Peycheva5492cb52019-10-30 14:13:16 +0100804 RETURN_IF_HWC_ERROR(error, displayId, INVALID_OPERATION);
805 }
Peiyong Line9d809e2020-04-14 13:10:48 -0700806 if (error == hal::Error::BAD_PARAMETER) {
Galia Peycheva5492cb52019-10-30 14:13:16 +0100807 RETURN_IF_HWC_ERROR(error, displayId, BAD_VALUE);
808 }
809 RETURN_IF_HWC_ERROR(error, displayId, UNKNOWN_ERROR);
810 return NO_ERROR;
811}
812
813status_t HWComposer::getSupportedContentTypes(
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200814 PhysicalDisplayId displayId, std::vector<hal::ContentType>* outSupportedContentTypes) {
Galia Peycheva5492cb52019-10-30 14:13:16 +0100815 RETURN_IF_INVALID_DISPLAY(displayId, BAD_INDEX);
816 const auto error =
817 mDisplayData[displayId].hwcDisplay->getSupportedContentTypes(outSupportedContentTypes);
818
819 RETURN_IF_HWC_ERROR(error, displayId, UNKNOWN_ERROR);
820
821 return NO_ERROR;
822}
823
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200824status_t HWComposer::setContentType(PhysicalDisplayId displayId, hal::ContentType contentType) {
Galia Peycheva5492cb52019-10-30 14:13:16 +0100825 RETURN_IF_INVALID_DISPLAY(displayId, BAD_INDEX);
826 const auto error = mDisplayData[displayId].hwcDisplay->setContentType(contentType);
Peiyong Line9d809e2020-04-14 13:10:48 -0700827 if (error == hal::Error::UNSUPPORTED) {
Galia Peycheva5492cb52019-10-30 14:13:16 +0100828 RETURN_IF_HWC_ERROR(error, displayId, INVALID_OPERATION);
829 }
Peiyong Line9d809e2020-04-14 13:10:48 -0700830 if (error == hal::Error::BAD_PARAMETER) {
Galia Peycheva5492cb52019-10-30 14:13:16 +0100831 RETURN_IF_HWC_ERROR(error, displayId, BAD_VALUE);
832 }
833 RETURN_IF_HWC_ERROR(error, displayId, UNKNOWN_ERROR);
834
835 return NO_ERROR;
836}
837
Lloyd Pique4603f3c2020-02-11 12:06:56 -0800838const std::unordered_map<std::string, bool>& HWComposer::getSupportedLayerGenericMetadata() const {
839 return mSupportedLayerGenericMetadata;
840}
841
Yiwei Zhang5434a782018-12-05 18:06:32 -0800842void HWComposer::dump(std::string& result) const {
Peiyong Linbdd08cc2019-12-17 21:35:14 -0800843 result.append(mComposer->dumpDebugInfo());
Mathias Agopian83727852010-09-23 18:13:21 -0700844}
845
Marin Shalamanova524a092020-07-27 21:39:55 +0200846std::optional<PhysicalDisplayId> HWComposer::toPhysicalDisplayId(
847 hal::HWDisplayId hwcDisplayId) const {
Dominik Laskowski075d3172018-05-24 15:50:06 -0700848 if (const auto it = mPhysicalDisplayIdMap.find(hwcDisplayId);
849 it != mPhysicalDisplayIdMap.end()) {
850 return it->second;
851 }
852 return {};
853}
854
Marin Shalamanova524a092020-07-27 21:39:55 +0200855std::optional<hal::HWDisplayId> HWComposer::fromPhysicalDisplayId(
856 PhysicalDisplayId displayId) const {
Dominik Laskowski075d3172018-05-24 15:50:06 -0700857 if (const auto it = mDisplayData.find(displayId);
858 it != mDisplayData.end() && !it->second.isVirtual) {
859 return it->second.hwcDisplay->getId();
860 }
861 return {};
862}
863
Peiyong Line9d809e2020-04-14 13:10:48 -0700864bool HWComposer::shouldIgnoreHotplugConnect(hal::HWDisplayId hwcDisplayId,
Marin Shalamanovbdd59152020-02-14 15:30:06 +0100865 bool hasDisplayIdentificationData) const {
Marin Shalamanovbdd59152020-02-14 15:30:06 +0100866 if (mHasMultiDisplaySupport && !hasDisplayIdentificationData) {
Dominik Laskowski075d3172018-05-24 15:50:06 -0700867 ALOGE("Ignoring connection of display %" PRIu64 " without identification data",
868 hwcDisplayId);
Marin Shalamanovbdd59152020-02-14 15:30:06 +0100869 return true;
Dominik Laskowski075d3172018-05-24 15:50:06 -0700870 }
871
Marin Shalamanovbdd59152020-02-14 15:30:06 +0100872 if (!mHasMultiDisplaySupport && mInternalHwcDisplayId && mExternalHwcDisplayId) {
Dominik Laskowski075d3172018-05-24 15:50:06 -0700873 ALOGE("Ignoring connection of tertiary display %" PRIu64, hwcDisplayId);
Marin Shalamanovbdd59152020-02-14 15:30:06 +0100874 return true;
875 }
876
877 return false;
878}
879
Peiyong Line9d809e2020-04-14 13:10:48 -0700880std::optional<DisplayIdentificationInfo> HWComposer::onHotplugConnect(
881 hal::HWDisplayId hwcDisplayId) {
Marin Shalamanovbdd59152020-02-14 15:30:06 +0100882 std::optional<DisplayIdentificationInfo> info;
883 if (const auto displayId = toPhysicalDisplayId(hwcDisplayId)) {
884 info = DisplayIdentificationInfo{.id = *displayId,
885 .name = std::string(),
886 .deviceProductInfo = std::nullopt};
Marin Shalamanovf8c63722020-10-06 13:11:21 +0200887 if (mUpdateDeviceProductInfoOnHotplugReconnect) {
888 uint8_t port;
889 DisplayIdentificationData data;
890 getDisplayIdentificationData(hwcDisplayId, &port, &data);
891 if (auto newInfo = parseDisplayIdentificationData(port, data)) {
892 info->deviceProductInfo = std::move(newInfo->deviceProductInfo);
893 } else {
894 ALOGE("Failed to parse identification data for display %" PRIu64, hwcDisplayId);
895 }
896 }
Dominik Laskowski075d3172018-05-24 15:50:06 -0700897 } else {
Marin Shalamanovbdd59152020-02-14 15:30:06 +0100898 uint8_t port;
899 DisplayIdentificationData data;
900 const bool hasDisplayIdentificationData =
901 getDisplayIdentificationData(hwcDisplayId, &port, &data);
902 if (mPhysicalDisplayIdMap.empty()) {
903 mHasMultiDisplaySupport = hasDisplayIdentificationData;
904 ALOGI("Switching to %s multi-display mode",
905 mHasMultiDisplaySupport ? "generalized" : "legacy");
906 }
907
908 if (shouldIgnoreHotplugConnect(hwcDisplayId, hasDisplayIdentificationData)) {
909 return {};
910 }
911
912 info = [this, hwcDisplayId, &port, &data, hasDisplayIdentificationData] {
913 const bool isPrimary = !mInternalHwcDisplayId;
914 if (mHasMultiDisplaySupport) {
915 if (const auto info = parseDisplayIdentificationData(port, data)) {
916 return *info;
917 }
918 ALOGE("Failed to parse identification data for display %" PRIu64, hwcDisplayId);
919 } else {
920 ALOGW_IF(hasDisplayIdentificationData,
921 "Ignoring identification data for display %" PRIu64, hwcDisplayId);
Peiyong Lin65248e02020-04-18 21:15:07 -0700922 port = isPrimary ? LEGACY_DISPLAY_TYPE_PRIMARY : LEGACY_DISPLAY_TYPE_EXTERNAL;
Marin Shalamanovbdd59152020-02-14 15:30:06 +0100923 }
924
Marin Shalamanova524a092020-07-27 21:39:55 +0200925 return DisplayIdentificationInfo{.id = PhysicalDisplayId::fromPort(port),
Marin Shalamanovbdd59152020-02-14 15:30:06 +0100926 .name = isPrimary ? "Internal display"
927 : "External display",
928 .deviceProductInfo = std::nullopt};
929 }();
Dominik Laskowski075d3172018-05-24 15:50:06 -0700930 }
931
Marin Shalamanovbdd59152020-02-14 15:30:06 +0100932 if (!isConnected(info->id)) {
933 allocatePhysicalDisplay(hwcDisplayId, info->id);
934 }
935 return info;
936}
937
938std::optional<DisplayIdentificationInfo> HWComposer::onHotplugDisconnect(
Peiyong Line9d809e2020-04-14 13:10:48 -0700939 hal::HWDisplayId hwcDisplayId) {
Marin Shalamanovbdd59152020-02-14 15:30:06 +0100940 const auto displayId = toPhysicalDisplayId(hwcDisplayId);
941 if (!displayId) {
942 ALOGE("Ignoring disconnection of invalid HWC display %" PRIu64, hwcDisplayId);
943 return {};
Dominik Laskowski075d3172018-05-24 15:50:06 -0700944 }
945
Marin Shalamanovbdd59152020-02-14 15:30:06 +0100946 // The display will later be destroyed by a call to
947 // destroyDisplay(). For now we just mark it disconnected.
948 if (isConnected(*displayId)) {
949 mDisplayData[*displayId].hwcDisplay->setConnected(false);
950 } else {
951 ALOGW("Attempted to disconnect unknown display %" PRIu64, hwcDisplayId);
952 }
953 // The cleanup of Disconnect is handled through HWComposer::disconnectDisplay
954 // via SurfaceFlinger's onHotplugReceived callback handling
955 return DisplayIdentificationInfo{.id = *displayId,
956 .name = std::string(),
Marin Shalamanovf5de90d2019-10-08 10:57:25 +0200957 .deviceProductInfo = std::nullopt};
Steven Thomas6e8f7062017-11-22 14:15:29 -0800958}
959
Peiyong Linbdd08cc2019-12-17 21:35:14 -0800960void HWComposer::loadCapabilities() {
Peiyong Line9d809e2020-04-14 13:10:48 -0700961 static_assert(sizeof(hal::Capability) == sizeof(int32_t), "Capability size has changed");
Peiyong Linbdd08cc2019-12-17 21:35:14 -0800962 auto capabilities = mComposer->getCapabilities();
963 for (auto capability : capabilities) {
Peiyong Line9d809e2020-04-14 13:10:48 -0700964 mCapabilities.emplace(static_cast<hal::Capability>(capability));
Peiyong Linbdd08cc2019-12-17 21:35:14 -0800965 }
966}
967
Lloyd Pique4603f3c2020-02-11 12:06:56 -0800968void HWComposer::loadLayerMetadataSupport() {
969 mSupportedLayerGenericMetadata.clear();
970
971 std::vector<Hwc2::IComposerClient::LayerGenericMetadataKey> supportedMetadataKeyInfo;
972 const auto error = mComposer->getLayerGenericMetadataKeys(&supportedMetadataKeyInfo);
973 if (error != hardware::graphics::composer::V2_4::Error::NONE) {
Ady Abraham3891cbe2021-03-29 11:29:31 -0700974 if (error != hardware::graphics::composer::V2_4::Error::UNSUPPORTED) {
975 ALOGE("%s: %s failed: %s (%d)", __FUNCTION__, "getLayerGenericMetadataKeys",
976 toString(error).c_str(), static_cast<int32_t>(error));
977 }
Lloyd Pique4603f3c2020-02-11 12:06:56 -0800978 return;
979 }
980
981 for (const auto& [name, mandatory] : supportedMetadataKeyInfo) {
982 mSupportedLayerGenericMetadata.emplace(name, mandatory);
983 }
984}
985
Peiyong Linbdd08cc2019-12-17 21:35:14 -0800986uint32_t HWComposer::getMaxVirtualDisplayCount() const {
987 return mComposer->getMaxVirtualDisplayCount();
988}
989
Lloyd Pique441d5042018-10-18 16:49:51 -0700990} // namespace impl
Dominik Laskowskif9750f22018-06-06 12:24:53 -0700991} // namespace android
Ady Abrahamb0dbdaa2020-01-06 16:19:42 -0800992
993// TODO(b/129481165): remove the #pragma below and fix conversion issues
994#pragma clang diagnostic pop // ignored "-Wconversion"