blob: b73d0320c3dfbc74f94c6fe74d97c868006b1518 [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
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200308HWC2::Layer* HWComposer::createLayer(HalDisplayId displayId) {
Dominik Laskowskifc2c0322018-04-19 14:47:33 -0700309 RETURN_IF_INVALID_DISPLAY(displayId, nullptr);
310
Steven Thomas94e35b92017-07-26 18:48:28 -0700311 HWC2::Layer* layer;
Peiyong Linbdd08cc2019-12-17 21:35:14 -0800312 auto error = mDisplayData[displayId].hwcDisplay->createLayer(&layer);
Dominik Laskowskifc2c0322018-04-19 14:47:33 -0700313 RETURN_IF_HWC_ERROR(error, displayId, nullptr);
Dan Stoza9e56aa02015-11-02 13:00:03 -0800314 return layer;
315}
316
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200317void HWComposer::destroyLayer(HalDisplayId displayId, HWC2::Layer* layer) {
Dominik Laskowskifc2c0322018-04-19 14:47:33 -0700318 RETURN_IF_INVALID_DISPLAY(displayId);
319
Peiyong Linbdd08cc2019-12-17 21:35:14 -0800320 auto error = mDisplayData[displayId].hwcDisplay->destroyLayer(layer);
Dominik Laskowskifc2c0322018-04-19 14:47:33 -0700321 RETURN_IF_HWC_ERROR(error, displayId);
Steven Thomas94e35b92017-07-26 18:48:28 -0700322}
323
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200324bool HWComposer::isConnected(PhysicalDisplayId displayId) const {
Ady Abraham2e9c7032021-03-29 14:01:56 -0700325 if (mDisplayData.count(displayId)) {
326 return mDisplayData.at(displayId).hwcDisplay->isConnected();
327 }
328
329 return false;
Mathias Agopian9c6e2972011-09-20 17:21:56 -0700330}
331
Marin Shalamanov045b7002021-01-07 16:56:24 +0100332std::vector<HWComposer::HWCDisplayMode> HWComposer::getModes(PhysicalDisplayId displayId) const {
Dominik Laskowskifc2c0322018-04-19 14:47:33 -0700333 RETURN_IF_INVALID_DISPLAY(displayId, {});
334
Marin Shalamanov045b7002021-01-07 16:56:24 +0100335 const auto hwcDisplayId = mDisplayData.at(displayId).hwcDisplay->getId();
336 std::vector<hal::HWConfigId> configIds;
337 auto error = static_cast<hal::Error>(mComposer->getDisplayConfigs(hwcDisplayId, &configIds));
338 RETURN_IF_HWC_ERROR_FOR("getDisplayConfigs", error, *toPhysicalDisplayId(hwcDisplayId), {});
339
340 std::vector<HWCDisplayMode> modes;
341 modes.reserve(configIds.size());
342 for (auto configId : configIds) {
343 modes.push_back(HWCDisplayMode{
344 .hwcId = configId,
345 .width = getAttribute(hwcDisplayId, configId, hal::Attribute::WIDTH),
346 .height = getAttribute(hwcDisplayId, configId, hal::Attribute::HEIGHT),
347 .vsyncPeriod = getAttribute(hwcDisplayId, configId, hal::Attribute::VSYNC_PERIOD),
348 .dpiX = getAttribute(hwcDisplayId, configId, hal::Attribute::DPI_X),
349 .dpiY = getAttribute(hwcDisplayId, configId, hal::Attribute::DPI_Y),
350 .configGroup = getAttribute(hwcDisplayId, configId, hal::Attribute::CONFIG_GROUP),
351 });
352 }
353
354 return modes;
Mathias Agopianda27af92012-09-13 18:17:13 -0700355}
356
Marin Shalamanov045b7002021-01-07 16:56:24 +0100357std::optional<hal::HWConfigId> HWComposer::getActiveMode(PhysicalDisplayId displayId) const {
358 RETURN_IF_INVALID_DISPLAY(displayId, std::nullopt);
Dominik Laskowskifc2c0322018-04-19 14:47:33 -0700359
Marin Shalamanov3ea1d602020-12-16 19:59:39 +0100360 const auto hwcId = *fromPhysicalDisplayId(displayId);
361 ALOGV("[%" PRIu64 "] getActiveMode", hwcId);
362 hal::HWConfigId configId;
363 auto error = static_cast<hal::Error>(mComposer->getActiveConfig(hwcId, &configId));
364
Peiyong Line9d809e2020-04-14 13:10:48 -0700365 if (error == hal::Error::BAD_CONFIG) {
Marin Shalamanov3ea1d602020-12-16 19:59:39 +0100366 LOG_DISPLAY_ERROR(displayId, "No active mode");
Marin Shalamanov045b7002021-01-07 16:56:24 +0100367 return std::nullopt;
Dominik Laskowskifc2c0322018-04-19 14:47:33 -0700368 }
369
Marin Shalamanov045b7002021-01-07 16:56:24 +0100370 return configId;
Mathias Agopiana350ff92010-08-10 17:14:02 -0700371}
372
Ady Abraham3a77a7b2019-12-02 18:46:59 -0800373// Composer 2.4
374
Marin Shalamanov228f46b2021-01-28 21:11:45 +0100375ui::DisplayConnectionType HWComposer::getDisplayConnectionType(PhysicalDisplayId displayId) const {
376 RETURN_IF_INVALID_DISPLAY(displayId, ui::DisplayConnectionType::Internal);
Dominik Laskowski55c85402020-01-21 16:25:47 -0800377 const auto& hwcDisplay = mDisplayData.at(displayId).hwcDisplay;
378
Marin Shalamanov228f46b2021-01-28 21:11:45 +0100379 ui::DisplayConnectionType type;
Dominik Laskowski55c85402020-01-21 16:25:47 -0800380 const auto error = hwcDisplay->getConnectionType(&type);
381
382 const auto FALLBACK_TYPE = hwcDisplay->getId() == mInternalHwcDisplayId
Marin Shalamanov228f46b2021-01-28 21:11:45 +0100383 ? ui::DisplayConnectionType::Internal
384 : ui::DisplayConnectionType::External;
Dominik Laskowski55c85402020-01-21 16:25:47 -0800385
386 RETURN_IF_HWC_ERROR(error, displayId, FALLBACK_TYPE);
387 return type;
388}
389
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200390bool HWComposer::isVsyncPeriodSwitchSupported(PhysicalDisplayId displayId) const {
Dominik Laskowski55c85402020-01-21 16:25:47 -0800391 RETURN_IF_INVALID_DISPLAY(displayId, false);
Ady Abraham3a77a7b2019-12-02 18:46:59 -0800392 return mDisplayData.at(displayId).hwcDisplay->isVsyncPeriodSwitchSupported();
393}
394
Marin Shalamanov045b7002021-01-07 16:56:24 +0100395status_t HWComposer::getDisplayVsyncPeriod(PhysicalDisplayId displayId,
396 nsecs_t* outVsyncPeriod) const {
Dominik Laskowski55c85402020-01-21 16:25:47 -0800397 RETURN_IF_INVALID_DISPLAY(displayId, 0);
398
Marin Shalamanov045b7002021-01-07 16:56:24 +0100399 if (!isVsyncPeriodSwitchSupported(displayId)) {
400 return INVALID_OPERATION;
Dominik Laskowskif3749f82018-06-13 15:49:25 -0700401 }
Marin Shalamanov045b7002021-01-07 16:56:24 +0100402 const auto hwcId = *fromPhysicalDisplayId(displayId);
403 Hwc2::VsyncPeriodNanos vsyncPeriodNanos = 0;
404 auto error =
405 static_cast<hal::Error>(mComposer->getDisplayVsyncPeriod(hwcId, &vsyncPeriodNanos));
406 RETURN_IF_HWC_ERROR(error, displayId, 0);
407 *outVsyncPeriod = static_cast<nsecs_t>(vsyncPeriodNanos);
408 return NO_ERROR;
Lloyd Pique3c085a02018-05-09 19:38:32 -0700409}
410
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200411std::vector<ui::ColorMode> HWComposer::getColorModes(PhysicalDisplayId displayId) const {
Dominik Laskowskifc2c0322018-04-19 14:47:33 -0700412 RETURN_IF_INVALID_DISPLAY(displayId, {});
413
Peiyong Linfd997e02018-03-28 15:29:00 -0700414 std::vector<ui::ColorMode> modes;
Dominik Laskowski075d3172018-05-24 15:50:06 -0700415 auto error = mDisplayData.at(displayId).hwcDisplay->getColorModes(&modes);
Dominik Laskowskifc2c0322018-04-19 14:47:33 -0700416 RETURN_IF_HWC_ERROR(error, displayId, {});
Courtney Goeltzenleuchterfad9d8c2016-06-23 11:49:50 -0600417 return modes;
418}
419
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200420status_t HWComposer::setActiveColorMode(PhysicalDisplayId displayId, ui::ColorMode mode,
Dominik Laskowski075d3172018-05-24 15:50:06 -0700421 ui::RenderIntent renderIntent) {
Dominik Laskowskifc2c0322018-04-19 14:47:33 -0700422 RETURN_IF_INVALID_DISPLAY(displayId, BAD_INDEX);
Michael Wright28f24d02016-07-12 13:30:53 -0700423
424 auto& displayData = mDisplayData[displayId];
Peiyong Lin0e7a7912018-04-05 14:36:36 -0700425 auto error = displayData.hwcDisplay->setColorMode(mode, renderIntent);
Dominik Laskowskifc2c0322018-04-19 14:47:33 -0700426 RETURN_IF_HWC_ERROR_FOR(("setColorMode(" + decodeColorMode(mode) + ", " +
427 decodeRenderIntent(renderIntent) + ")")
428 .c_str(),
429 error, displayId, UNKNOWN_ERROR);
Michael Wright28f24d02016-07-12 13:30:53 -0700430
431 return NO_ERROR;
432}
433
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200434void HWComposer::setVsyncEnabled(PhysicalDisplayId displayId, hal::Vsync enabled) {
Dominik Laskowskic1f18f62018-06-13 15:17:55 -0700435 RETURN_IF_INVALID_DISPLAY(displayId);
436 auto& displayData = mDisplayData[displayId];
437
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200438 LOG_FATAL_IF(displayData.isVirtual, "%s: Invalid operation on virtual display with ID %s",
439 __FUNCTION__, to_string(displayId).c_str());
Dan Stoza9e56aa02015-11-02 13:00:03 -0800440
Dan Stoza9e56aa02015-11-02 13:00:03 -0800441 // NOTE: we use our own internal lock here because we have to call
442 // into the HWC with the lock held, and we want to make sure
443 // that even if HWC blocks (which it shouldn't), it won't
444 // affect other threads.
Dominik Laskowski1af47932018-11-12 10:20:46 -0800445 std::lock_guard lock(displayData.vsyncEnabledLock);
446 if (enabled == displayData.vsyncEnabled) {
447 return;
Colin Cross10fbdb62012-07-12 17:56:34 -0700448 }
Dominik Laskowski1af47932018-11-12 10:20:46 -0800449
450 ATRACE_CALL();
451 auto error = displayData.hwcDisplay->setVsyncEnabled(enabled);
452 RETURN_IF_HWC_ERROR(error, displayId);
453
454 displayData.vsyncEnabled = enabled;
455
456 const auto tag = "HW_VSYNC_ON_" + to_string(displayId);
Peiyong Line9d809e2020-04-14 13:10:48 -0700457 ATRACE_INT(tag.c_str(), enabled == hal::Vsync::ENABLE ? 1 : 0);
Colin Cross10fbdb62012-07-12 17:56:34 -0700458}
459
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200460status_t HWComposer::setClientTarget(HalDisplayId displayId, uint32_t slot,
Dominik Laskowski075d3172018-05-24 15:50:06 -0700461 const sp<Fence>& acquireFence, const sp<GraphicBuffer>& target,
462 ui::Dataspace dataspace) {
Dominik Laskowskifc2c0322018-04-19 14:47:33 -0700463 RETURN_IF_INVALID_DISPLAY(displayId, BAD_INDEX);
Jesse Hall851cfe82013-03-20 13:44:00 -0700464
Dominik Laskowski34157762018-10-31 13:07:19 -0700465 ALOGV("%s for display %s", __FUNCTION__, to_string(displayId).c_str());
Dan Stoza9e56aa02015-11-02 13:00:03 -0800466 auto& hwcDisplay = mDisplayData[displayId].hwcDisplay;
Daniel Nicoara1f42e3a2017-04-10 13:27:32 -0400467 auto error = hwcDisplay->setClientTarget(slot, target, acquireFence, dataspace);
Dominik Laskowskifc2c0322018-04-19 14:47:33 -0700468 RETURN_IF_HWC_ERROR(error, displayId, BAD_VALUE);
Jesse Hall851cfe82013-03-20 13:44:00 -0700469 return NO_ERROR;
470}
471
Lloyd Pique66d68602019-02-13 14:23:31 -0800472status_t HWComposer::getDeviceCompositionChanges(
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200473 HalDisplayId displayId, bool frameUsesClientComposition,
Lloyd Pique66d68602019-02-13 14:23:31 -0800474 std::optional<android::HWComposer::DeviceRequestedChanges>* outChanges) {
Dan Stoza9e56aa02015-11-02 13:00:03 -0800475 ATRACE_CALL();
476
Dominik Laskowskifc2c0322018-04-19 14:47:33 -0700477 RETURN_IF_INVALID_DISPLAY(displayId, BAD_INDEX);
Dan Stoza9e56aa02015-11-02 13:00:03 -0800478
479 auto& displayData = mDisplayData[displayId];
480 auto& hwcDisplay = displayData.hwcDisplay;
481 if (!hwcDisplay->isConnected()) {
482 return NO_ERROR;
483 }
484
485 uint32_t numTypes = 0;
486 uint32_t numRequests = 0;
Fabien Sanglard249c0ae2017-06-19 19:22:36 -0700487
Peiyong Line9d809e2020-04-14 13:10:48 -0700488 hal::Error error = hal::Error::NONE;
Fabien Sanglard249c0ae2017-06-19 19:22:36 -0700489
Chia-I Wu41b98d42017-12-11 11:04:36 -0800490 // First try to skip validate altogether when there is no client
491 // composition. When there is client composition, since we haven't
492 // rendered to the client target yet, we should not attempt to skip
493 // validate.
Fabien Sanglard249c0ae2017-06-19 19:22:36 -0700494 displayData.validateWasSkipped = false;
Lloyd Pique66d68602019-02-13 14:23:31 -0800495 if (!frameUsesClientComposition) {
Dominik Laskowski1af47932018-11-12 10:20:46 -0800496 sp<Fence> outPresentFence;
Fabien Sanglard249c0ae2017-06-19 19:22:36 -0700497 uint32_t state = UINT32_MAX;
498 error = hwcDisplay->presentOrValidate(&numTypes, &numRequests, &outPresentFence , &state);
Peiyong Line9d809e2020-04-14 13:10:48 -0700499 if (!hasChangesError(error)) {
Dominik Laskowskifc2c0322018-04-19 14:47:33 -0700500 RETURN_IF_HWC_ERROR_FOR("presentOrValidate", error, displayId, UNKNOWN_ERROR);
Fabien Sanglard249c0ae2017-06-19 19:22:36 -0700501 }
502 if (state == 1) { //Present Succeeded.
Steven Thomas94e35b92017-07-26 18:48:28 -0700503 std::unordered_map<HWC2::Layer*, sp<Fence>> releaseFences;
Fabien Sanglard249c0ae2017-06-19 19:22:36 -0700504 error = hwcDisplay->getReleaseFences(&releaseFences);
505 displayData.releaseFences = std::move(releaseFences);
506 displayData.lastPresentFence = outPresentFence;
507 displayData.validateWasSkipped = true;
508 displayData.presentError = error;
509 return NO_ERROR;
510 }
511 // Present failed but Validate ran.
512 } else {
513 error = hwcDisplay->validate(&numTypes, &numRequests);
514 }
515 ALOGV("SkipValidate failed, Falling back to SLOW validate/present");
Peiyong Line9d809e2020-04-14 13:10:48 -0700516 if (!hasChangesError(error)) {
Dominik Laskowskifc2c0322018-04-19 14:47:33 -0700517 RETURN_IF_HWC_ERROR_FOR("validate", error, displayId, BAD_INDEX);
Dan Stoza9e56aa02015-11-02 13:00:03 -0800518 }
519
Lloyd Pique66d68602019-02-13 14:23:31 -0800520 android::HWComposer::DeviceRequestedChanges::ChangedTypes changedTypes;
Dan Stoza9e56aa02015-11-02 13:00:03 -0800521 changedTypes.reserve(numTypes);
522 error = hwcDisplay->getChangedCompositionTypes(&changedTypes);
Dominik Laskowskifc2c0322018-04-19 14:47:33 -0700523 RETURN_IF_HWC_ERROR_FOR("getChangedCompositionTypes", error, displayId, BAD_INDEX);
Dan Stoza9e56aa02015-11-02 13:00:03 -0800524
Peiyong Line9d809e2020-04-14 13:10:48 -0700525 auto displayRequests = static_cast<hal::DisplayRequest>(0);
Lloyd Pique66d68602019-02-13 14:23:31 -0800526 android::HWComposer::DeviceRequestedChanges::LayerRequests layerRequests;
Dan Stoza9e56aa02015-11-02 13:00:03 -0800527 layerRequests.reserve(numRequests);
Lloyd Pique66d68602019-02-13 14:23:31 -0800528 error = hwcDisplay->getRequests(&displayRequests, &layerRequests);
Dominik Laskowskifc2c0322018-04-19 14:47:33 -0700529 RETURN_IF_HWC_ERROR_FOR("getRequests", error, displayId, BAD_INDEX);
Dan Stoza9e56aa02015-11-02 13:00:03 -0800530
Peiyong Lindfc3f7c2020-05-07 20:15:50 -0700531 DeviceRequestedChanges::ClientTargetProperty clientTargetProperty;
532 error = hwcDisplay->getClientTargetProperty(&clientTargetProperty);
Dan Stoza9e56aa02015-11-02 13:00:03 -0800533
Peiyong Lindfc3f7c2020-05-07 20:15:50 -0700534 outChanges->emplace(DeviceRequestedChanges{std::move(changedTypes), std::move(displayRequests),
535 std::move(layerRequests),
536 std::move(clientTargetProperty)});
Dan Stoza9e56aa02015-11-02 13:00:03 -0800537 error = hwcDisplay->acceptChanges();
Dominik Laskowskifc2c0322018-04-19 14:47:33 -0700538 RETURN_IF_HWC_ERROR_FOR("acceptChanges", error, displayId, BAD_INDEX);
Dan Stoza9e56aa02015-11-02 13:00:03 -0800539
540 return NO_ERROR;
541}
542
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200543sp<Fence> HWComposer::getPresentFence(HalDisplayId displayId) const {
Dominik Laskowskifc2c0322018-04-19 14:47:33 -0700544 RETURN_IF_INVALID_DISPLAY(displayId, Fence::NO_FENCE);
Dominik Laskowski075d3172018-05-24 15:50:06 -0700545 return mDisplayData.at(displayId).lastPresentFence;
Jesse Hall851cfe82013-03-20 13:44:00 -0700546}
547
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200548sp<Fence> HWComposer::getLayerReleaseFence(HalDisplayId displayId, HWC2::Layer* layer) const {
Dominik Laskowskifc2c0322018-04-19 14:47:33 -0700549 RETURN_IF_INVALID_DISPLAY(displayId, Fence::NO_FENCE);
Tim Murray2d3f8b82019-12-04 16:24:17 -0800550 const auto& displayFences = mDisplayData.at(displayId).releaseFences;
551 auto fence = displayFences.find(layer);
552 if (fence == displayFences.end()) {
Dan Stoza9e56aa02015-11-02 13:00:03 -0800553 ALOGV("getLayerReleaseFence: Release fence not found");
554 return Fence::NO_FENCE;
Riley Andrews03414a12014-07-01 14:22:59 -0700555 }
Tim Murray2d3f8b82019-12-04 16:24:17 -0800556 return fence->second;
Riley Andrews03414a12014-07-01 14:22:59 -0700557}
558
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200559status_t HWComposer::presentAndGetReleaseFences(HalDisplayId displayId) {
Dan Stoza9e56aa02015-11-02 13:00:03 -0800560 ATRACE_CALL();
Mathias Agopian3e8b8532012-05-13 20:42:01 -0700561
Dominik Laskowskifc2c0322018-04-19 14:47:33 -0700562 RETURN_IF_INVALID_DISPLAY(displayId, BAD_INDEX);
Pablo Ceballosd814cf22015-09-11 14:37:39 -0700563
Dan Stoza9e56aa02015-11-02 13:00:03 -0800564 auto& displayData = mDisplayData[displayId];
565 auto& hwcDisplay = displayData.hwcDisplay;
Fabien Sanglard249c0ae2017-06-19 19:22:36 -0700566
567 if (displayData.validateWasSkipped) {
Chia-I Wuae5a6b82017-10-10 09:09:22 -0700568 // explicitly flush all pending commands
Peiyong Line9d809e2020-04-14 13:10:48 -0700569 auto error = static_cast<hal::Error>(mComposer->executeCommands());
Peiyong Linbdd08cc2019-12-17 21:35:14 -0800570 RETURN_IF_HWC_ERROR_FOR("executeCommands", error, displayId, UNKNOWN_ERROR);
Dominik Laskowskifc2c0322018-04-19 14:47:33 -0700571 RETURN_IF_HWC_ERROR_FOR("present", displayData.presentError, displayId, UNKNOWN_ERROR);
Fabien Sanglard249c0ae2017-06-19 19:22:36 -0700572 return NO_ERROR;
573 }
574
Fabien Sanglard11d0fc32016-12-01 15:43:01 -0800575 auto error = hwcDisplay->present(&displayData.lastPresentFence);
Dominik Laskowskifc2c0322018-04-19 14:47:33 -0700576 RETURN_IF_HWC_ERROR_FOR("present", error, displayId, UNKNOWN_ERROR);
Mathias Agopian3e8b8532012-05-13 20:42:01 -0700577
Steven Thomas94e35b92017-07-26 18:48:28 -0700578 std::unordered_map<HWC2::Layer*, sp<Fence>> releaseFences;
Dan Stoza9e56aa02015-11-02 13:00:03 -0800579 error = hwcDisplay->getReleaseFences(&releaseFences);
Dominik Laskowskifc2c0322018-04-19 14:47:33 -0700580 RETURN_IF_HWC_ERROR_FOR("getReleaseFences", error, displayId, UNKNOWN_ERROR);
Dan Stoza9e56aa02015-11-02 13:00:03 -0800581
582 displayData.releaseFences = std::move(releaseFences);
583
584 return NO_ERROR;
Mathias Agopiana350ff92010-08-10 17:14:02 -0700585}
586
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200587status_t HWComposer::setPowerMode(PhysicalDisplayId displayId, hal::PowerMode mode) {
Dominik Laskowskifc2c0322018-04-19 14:47:33 -0700588 RETURN_IF_INVALID_DISPLAY(displayId, BAD_INDEX);
589
Dominik Laskowskic1f18f62018-06-13 15:17:55 -0700590 const auto& displayData = mDisplayData[displayId];
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200591 LOG_FATAL_IF(displayData.isVirtual, "%s: Invalid operation on virtual display with ID %s",
592 __FUNCTION__, to_string(displayId).c_str());
Mathias Agopian3e8b8532012-05-13 20:42:01 -0700593
Peiyong Line9d809e2020-04-14 13:10:48 -0700594 if (mode == hal::PowerMode::OFF) {
595 setVsyncEnabled(displayId, hal::Vsync::DISABLE);
Dan Stoza9e56aa02015-11-02 13:00:03 -0800596 }
597
Dominik Laskowskic1f18f62018-06-13 15:17:55 -0700598 auto& hwcDisplay = displayData.hwcDisplay;
Dan Stoza9e56aa02015-11-02 13:00:03 -0800599 switch (mode) {
Peiyong Line9d809e2020-04-14 13:10:48 -0700600 case hal::PowerMode::OFF:
601 case hal::PowerMode::ON:
Dan Stoza9e56aa02015-11-02 13:00:03 -0800602 ALOGV("setPowerMode: Calling HWC %s", to_string(mode).c_str());
603 {
604 auto error = hwcDisplay->setPowerMode(mode);
Peiyong Line9d809e2020-04-14 13:10:48 -0700605 if (error != hal::Error::NONE) {
606 LOG_HWC_ERROR(("setPowerMode(" + to_string(mode) + ")").c_str(), error,
607 displayId);
Peiyong Lin306e4992018-05-07 16:18:22 -0700608 }
Mathias Agopianda27af92012-09-13 18:17:13 -0700609 }
Dan Stoza9e56aa02015-11-02 13:00:03 -0800610 break;
Peiyong Line9d809e2020-04-14 13:10:48 -0700611 case hal::PowerMode::DOZE:
612 case hal::PowerMode::DOZE_SUSPEND:
Dan Stoza9e56aa02015-11-02 13:00:03 -0800613 ALOGV("setPowerMode: Calling HWC %s", to_string(mode).c_str());
614 {
615 bool supportsDoze = false;
616 auto error = hwcDisplay->supportsDoze(&supportsDoze);
Peiyong Line9d809e2020-04-14 13:10:48 -0700617 if (error != hal::Error::NONE) {
Peiyong Lin306e4992018-05-07 16:18:22 -0700618 LOG_HWC_ERROR("supportsDoze", error, displayId);
619 }
Dominik Laskowskifc2c0322018-04-19 14:47:33 -0700620
Dan Stoza9e56aa02015-11-02 13:00:03 -0800621 if (!supportsDoze) {
Peiyong Line9d809e2020-04-14 13:10:48 -0700622 mode = hal::PowerMode::ON;
Dan Stoza9e56aa02015-11-02 13:00:03 -0800623 }
624
625 error = hwcDisplay->setPowerMode(mode);
Peiyong Line9d809e2020-04-14 13:10:48 -0700626 if (error != hal::Error::NONE) {
627 LOG_HWC_ERROR(("setPowerMode(" + to_string(mode) + ")").c_str(), error,
628 displayId);
Peiyong Lin306e4992018-05-07 16:18:22 -0700629 }
Dan Stoza9e56aa02015-11-02 13:00:03 -0800630 }
631 break;
632 default:
633 ALOGV("setPowerMode: Not calling HWC");
634 break;
Mathias Agopianda27af92012-09-13 18:17:13 -0700635 }
Dan Stoza9e56aa02015-11-02 13:00:03 -0800636
637 return NO_ERROR;
638}
639
Marin Shalamanov3ea1d602020-12-16 19:59:39 +0100640status_t HWComposer::setActiveModeWithConstraints(
Marin Shalamanov12c9e5a2021-01-07 00:25:35 +0100641 PhysicalDisplayId displayId, hal::HWConfigId hwcModeId,
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200642 const hal::VsyncPeriodChangeConstraints& constraints,
Peiyong Line9d809e2020-04-14 13:10:48 -0700643 hal::VsyncPeriodChangeTimeline* outTimeline) {
Dominik Laskowskifc2c0322018-04-19 14:47:33 -0700644 RETURN_IF_INVALID_DISPLAY(displayId, BAD_INDEX);
Dan Stoza9e56aa02015-11-02 13:00:03 -0800645
Marin Shalamanov12c9e5a2021-01-07 00:25:35 +0100646 auto error = mDisplayData[displayId].hwcDisplay->setActiveConfigWithConstraints(hwcModeId,
647 constraints,
648 outTimeline);
Dominik Laskowskifc2c0322018-04-19 14:47:33 -0700649 RETURN_IF_HWC_ERROR(error, displayId, UNKNOWN_ERROR);
Dan Stoza9e56aa02015-11-02 13:00:03 -0800650 return NO_ERROR;
651}
652
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200653status_t HWComposer::setColorTransform(HalDisplayId displayId, const mat4& transform) {
Dominik Laskowskifc2c0322018-04-19 14:47:33 -0700654 RETURN_IF_INVALID_DISPLAY(displayId, BAD_INDEX);
Dan Stoza9f26a9c2016-06-22 14:51:09 -0700655
656 auto& displayData = mDisplayData[displayId];
657 bool isIdentity = transform == mat4();
Peiyong Line9d809e2020-04-14 13:10:48 -0700658 auto error = displayData.hwcDisplay
659 ->setColorTransform(transform,
660 isIdentity ? hal::ColorTransform::IDENTITY
661 : hal::ColorTransform::ARBITRARY_MATRIX);
Dominik Laskowskifc2c0322018-04-19 14:47:33 -0700662 RETURN_IF_HWC_ERROR(error, displayId, UNKNOWN_ERROR);
Dan Stoza9f26a9c2016-06-22 14:51:09 -0700663 return NO_ERROR;
664}
665
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200666void HWComposer::disconnectDisplay(HalDisplayId displayId) {
Dominik Laskowskic1f18f62018-06-13 15:17:55 -0700667 RETURN_IF_INVALID_DISPLAY(displayId);
Dan Stoza9e56aa02015-11-02 13:00:03 -0800668 auto& displayData = mDisplayData[displayId];
669
Dan Stoza9e56aa02015-11-02 13:00:03 -0800670 // If this was a virtual display, add its slot back for reuse by future
671 // virtual displays
Dominik Laskowskic1f18f62018-06-13 15:17:55 -0700672 if (displayData.isVirtual) {
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200673 mVirtualIdGenerator.markUnused(*HalVirtualDisplayId::tryCast(displayId));
Dan Stoza9e56aa02015-11-02 13:00:03 -0800674 }
675
Dominik Laskowski7e045462018-05-30 13:02:02 -0700676 const auto hwcDisplayId = displayData.hwcDisplay->getId();
Dominik Laskowski075d3172018-05-24 15:50:06 -0700677
678 // TODO(b/74619554): Select internal/external display from remaining displays.
679 if (hwcDisplayId == mInternalHwcDisplayId) {
680 mInternalHwcDisplayId.reset();
681 } else if (hwcDisplayId == mExternalHwcDisplayId) {
682 mExternalHwcDisplayId.reset();
683 }
Peiyong Linbdd08cc2019-12-17 21:35:14 -0800684 mPhysicalDisplayIdMap.erase(hwcDisplayId);
685 mDisplayData.erase(displayId);
Dan Stoza9e56aa02015-11-02 13:00:03 -0800686}
687
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200688status_t HWComposer::setOutputBuffer(HalVirtualDisplayId displayId, const sp<Fence>& acquireFence,
Dominik Laskowski075d3172018-05-24 15:50:06 -0700689 const sp<GraphicBuffer>& buffer) {
Dominik Laskowskifc2c0322018-04-19 14:47:33 -0700690 RETURN_IF_INVALID_DISPLAY(displayId, BAD_INDEX);
Dominik Laskowskic1f18f62018-06-13 15:17:55 -0700691 const auto& displayData = mDisplayData[displayId];
Dan Stoza9e56aa02015-11-02 13:00:03 -0800692
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200693 LOG_FATAL_IF(!displayData.isVirtual, "%s: Invalid operation on physical display with ID %s",
694 __FUNCTION__, to_string(displayId).c_str());
Dan Stoza9e56aa02015-11-02 13:00:03 -0800695
Dominik Laskowskic1f18f62018-06-13 15:17:55 -0700696 auto error = displayData.hwcDisplay->setOutputBuffer(buffer, acquireFence);
Dominik Laskowskifc2c0322018-04-19 14:47:33 -0700697 RETURN_IF_HWC_ERROR(error, displayId, UNKNOWN_ERROR);
Dan Stoza9e56aa02015-11-02 13:00:03 -0800698 return NO_ERROR;
699}
700
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200701void HWComposer::clearReleaseFences(HalDisplayId displayId) {
Dominik Laskowskifc2c0322018-04-19 14:47:33 -0700702 RETURN_IF_INVALID_DISPLAY(displayId);
Dan Stoza9e56aa02015-11-02 13:00:03 -0800703 mDisplayData[displayId].releaseFences.clear();
Mathias Agopian3e8b8532012-05-13 20:42:01 -0700704}
705
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200706status_t HWComposer::getHdrCapabilities(HalDisplayId displayId, HdrCapabilities* outCapabilities) {
Dominik Laskowskifc2c0322018-04-19 14:47:33 -0700707 RETURN_IF_INVALID_DISPLAY(displayId, BAD_INDEX);
Dan Stozac4f471e2016-03-24 09:31:08 -0700708
709 auto& hwcDisplay = mDisplayData[displayId].hwcDisplay;
Peiyong Lin62665892018-04-16 11:07:44 -0700710 auto error = hwcDisplay->getHdrCapabilities(outCapabilities);
Dominik Laskowskifc2c0322018-04-19 14:47:33 -0700711 RETURN_IF_HWC_ERROR(error, displayId, UNKNOWN_ERROR);
Peiyong Lin62665892018-04-16 11:07:44 -0700712 return NO_ERROR;
Dan Stozac4f471e2016-03-24 09:31:08 -0700713}
714
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200715int32_t HWComposer::getSupportedPerFrameMetadata(HalDisplayId displayId) const {
Dominik Laskowskifc2c0322018-04-19 14:47:33 -0700716 RETURN_IF_INVALID_DISPLAY(displayId, 0);
Dominik Laskowski075d3172018-05-24 15:50:06 -0700717 return mDisplayData.at(displayId).hwcDisplay->getSupportedPerFrameMetadata();
Peiyong Lin0ac5f4e2018-04-19 22:06:34 -0700718}
719
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200720std::vector<ui::RenderIntent> HWComposer::getRenderIntents(HalDisplayId displayId,
Dominik Laskowski075d3172018-05-24 15:50:06 -0700721 ui::ColorMode colorMode) const {
Dominik Laskowskifc2c0322018-04-19 14:47:33 -0700722 RETURN_IF_INVALID_DISPLAY(displayId, {});
Peiyong Lin0e7a7912018-04-05 14:36:36 -0700723
724 std::vector<ui::RenderIntent> renderIntents;
Dominik Laskowski075d3172018-05-24 15:50:06 -0700725 auto error = mDisplayData.at(displayId).hwcDisplay->getRenderIntents(colorMode, &renderIntents);
Dominik Laskowskifc2c0322018-04-19 14:47:33 -0700726 RETURN_IF_HWC_ERROR(error, displayId, {});
Peiyong Lin0e7a7912018-04-05 14:36:36 -0700727 return renderIntents;
728}
729
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200730mat4 HWComposer::getDataspaceSaturationMatrix(HalDisplayId displayId, ui::Dataspace dataspace) {
Dominik Laskowskifc2c0322018-04-19 14:47:33 -0700731 RETURN_IF_INVALID_DISPLAY(displayId, {});
Peiyong Lin0e7a7912018-04-05 14:36:36 -0700732
733 mat4 matrix;
734 auto error = mDisplayData[displayId].hwcDisplay->getDataspaceSaturationMatrix(dataspace,
735 &matrix);
Dominik Laskowskifc2c0322018-04-19 14:47:33 -0700736 RETURN_IF_HWC_ERROR(error, displayId, {});
Peiyong Lin0e7a7912018-04-05 14:36:36 -0700737 return matrix;
738}
739
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200740status_t HWComposer::getDisplayedContentSamplingAttributes(HalDisplayId displayId,
Kevin DuBois9c0a1762018-10-16 13:32:31 -0700741 ui::PixelFormat* outFormat,
742 ui::Dataspace* outDataspace,
743 uint8_t* outComponentMask) {
744 RETURN_IF_INVALID_DISPLAY(displayId, BAD_INDEX);
745 const auto error =
746 mDisplayData[displayId]
747 .hwcDisplay->getDisplayedContentSamplingAttributes(outFormat, outDataspace,
748 outComponentMask);
Peiyong Line9d809e2020-04-14 13:10:48 -0700749 if (error == hal::Error::UNSUPPORTED) RETURN_IF_HWC_ERROR(error, displayId, INVALID_OPERATION);
Kevin DuBois9c0a1762018-10-16 13:32:31 -0700750 RETURN_IF_HWC_ERROR(error, displayId, UNKNOWN_ERROR);
751 return NO_ERROR;
752}
753
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200754status_t HWComposer::setDisplayContentSamplingEnabled(HalDisplayId displayId, bool enabled,
Kevin DuBois74e53772018-11-19 10:52:38 -0800755 uint8_t componentMask, uint64_t maxFrames) {
756 RETURN_IF_INVALID_DISPLAY(displayId, BAD_INDEX);
757 const auto error =
758 mDisplayData[displayId].hwcDisplay->setDisplayContentSamplingEnabled(enabled,
759 componentMask,
760 maxFrames);
761
Peiyong Line9d809e2020-04-14 13:10:48 -0700762 if (error == hal::Error::UNSUPPORTED) RETURN_IF_HWC_ERROR(error, displayId, INVALID_OPERATION);
763 if (error == hal::Error::BAD_PARAMETER) RETURN_IF_HWC_ERROR(error, displayId, BAD_VALUE);
Kevin DuBois74e53772018-11-19 10:52:38 -0800764 RETURN_IF_HWC_ERROR(error, displayId, UNKNOWN_ERROR);
765 return NO_ERROR;
766}
767
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200768status_t HWComposer::getDisplayedContentSample(HalDisplayId displayId, uint64_t maxFrames,
Kevin DuBois1d4249a2018-08-29 10:45:14 -0700769 uint64_t timestamp, DisplayedFrameStats* outStats) {
770 RETURN_IF_INVALID_DISPLAY(displayId, BAD_INDEX);
771 const auto error =
772 mDisplayData[displayId].hwcDisplay->getDisplayedContentSample(maxFrames, timestamp,
773 outStats);
774 RETURN_IF_HWC_ERROR(error, displayId, UNKNOWN_ERROR);
775 return NO_ERROR;
776}
777
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200778std::future<status_t> HWComposer::setDisplayBrightness(PhysicalDisplayId displayId,
779 float brightness) {
Dominik Laskowski4e2b71f2020-11-10 15:05:32 -0800780 RETURN_IF_INVALID_DISPLAY(displayId, ftl::yield<status_t>(BAD_INDEX));
Dominik Laskowski5690bde2020-04-23 19:04:22 -0700781 auto& display = mDisplayData[displayId].hwcDisplay;
782
Dominik Laskowski4e2b71f2020-11-10 15:05:32 -0800783 return ftl::chain(display->setDisplayBrightness(brightness))
Dominik Laskowski5690bde2020-04-23 19:04:22 -0700784 .then([displayId](hal::Error error) -> status_t {
785 if (error == hal::Error::UNSUPPORTED) {
786 RETURN_IF_HWC_ERROR(error, displayId, INVALID_OPERATION);
787 }
788 if (error == hal::Error::BAD_PARAMETER) {
789 RETURN_IF_HWC_ERROR(error, displayId, BAD_VALUE);
790 }
791 RETURN_IF_HWC_ERROR(error, displayId, UNKNOWN_ERROR);
792 return NO_ERROR;
793 });
Dan Gittik57e63c52019-01-18 16:37:54 +0000794}
795
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200796status_t HWComposer::setAutoLowLatencyMode(PhysicalDisplayId displayId, bool on) {
Galia Peycheva5492cb52019-10-30 14:13:16 +0100797 RETURN_IF_INVALID_DISPLAY(displayId, BAD_INDEX);
798 const auto error = mDisplayData[displayId].hwcDisplay->setAutoLowLatencyMode(on);
Peiyong Line9d809e2020-04-14 13:10:48 -0700799 if (error == hal::Error::UNSUPPORTED) {
Galia Peycheva5492cb52019-10-30 14:13:16 +0100800 RETURN_IF_HWC_ERROR(error, displayId, INVALID_OPERATION);
801 }
Peiyong Line9d809e2020-04-14 13:10:48 -0700802 if (error == hal::Error::BAD_PARAMETER) {
Galia Peycheva5492cb52019-10-30 14:13:16 +0100803 RETURN_IF_HWC_ERROR(error, displayId, BAD_VALUE);
804 }
805 RETURN_IF_HWC_ERROR(error, displayId, UNKNOWN_ERROR);
806 return NO_ERROR;
807}
808
809status_t HWComposer::getSupportedContentTypes(
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200810 PhysicalDisplayId displayId, std::vector<hal::ContentType>* outSupportedContentTypes) {
Galia Peycheva5492cb52019-10-30 14:13:16 +0100811 RETURN_IF_INVALID_DISPLAY(displayId, BAD_INDEX);
812 const auto error =
813 mDisplayData[displayId].hwcDisplay->getSupportedContentTypes(outSupportedContentTypes);
814
815 RETURN_IF_HWC_ERROR(error, displayId, UNKNOWN_ERROR);
816
817 return NO_ERROR;
818}
819
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200820status_t HWComposer::setContentType(PhysicalDisplayId displayId, hal::ContentType contentType) {
Galia Peycheva5492cb52019-10-30 14:13:16 +0100821 RETURN_IF_INVALID_DISPLAY(displayId, BAD_INDEX);
822 const auto error = mDisplayData[displayId].hwcDisplay->setContentType(contentType);
Peiyong Line9d809e2020-04-14 13:10:48 -0700823 if (error == hal::Error::UNSUPPORTED) {
Galia Peycheva5492cb52019-10-30 14:13:16 +0100824 RETURN_IF_HWC_ERROR(error, displayId, INVALID_OPERATION);
825 }
Peiyong Line9d809e2020-04-14 13:10:48 -0700826 if (error == hal::Error::BAD_PARAMETER) {
Galia Peycheva5492cb52019-10-30 14:13:16 +0100827 RETURN_IF_HWC_ERROR(error, displayId, BAD_VALUE);
828 }
829 RETURN_IF_HWC_ERROR(error, displayId, UNKNOWN_ERROR);
830
831 return NO_ERROR;
832}
833
Lloyd Pique4603f3c2020-02-11 12:06:56 -0800834const std::unordered_map<std::string, bool>& HWComposer::getSupportedLayerGenericMetadata() const {
835 return mSupportedLayerGenericMetadata;
836}
837
Yiwei Zhang5434a782018-12-05 18:06:32 -0800838void HWComposer::dump(std::string& result) const {
Peiyong Linbdd08cc2019-12-17 21:35:14 -0800839 result.append(mComposer->dumpDebugInfo());
Mathias Agopian83727852010-09-23 18:13:21 -0700840}
841
Marin Shalamanova524a092020-07-27 21:39:55 +0200842std::optional<PhysicalDisplayId> HWComposer::toPhysicalDisplayId(
843 hal::HWDisplayId hwcDisplayId) const {
Dominik Laskowski075d3172018-05-24 15:50:06 -0700844 if (const auto it = mPhysicalDisplayIdMap.find(hwcDisplayId);
845 it != mPhysicalDisplayIdMap.end()) {
846 return it->second;
847 }
848 return {};
849}
850
Marin Shalamanova524a092020-07-27 21:39:55 +0200851std::optional<hal::HWDisplayId> HWComposer::fromPhysicalDisplayId(
852 PhysicalDisplayId displayId) const {
Dominik Laskowski075d3172018-05-24 15:50:06 -0700853 if (const auto it = mDisplayData.find(displayId);
854 it != mDisplayData.end() && !it->second.isVirtual) {
855 return it->second.hwcDisplay->getId();
856 }
857 return {};
858}
859
Peiyong Line9d809e2020-04-14 13:10:48 -0700860bool HWComposer::shouldIgnoreHotplugConnect(hal::HWDisplayId hwcDisplayId,
Marin Shalamanovbdd59152020-02-14 15:30:06 +0100861 bool hasDisplayIdentificationData) const {
Marin Shalamanovbdd59152020-02-14 15:30:06 +0100862 if (mHasMultiDisplaySupport && !hasDisplayIdentificationData) {
Dominik Laskowski075d3172018-05-24 15:50:06 -0700863 ALOGE("Ignoring connection of display %" PRIu64 " without identification data",
864 hwcDisplayId);
Marin Shalamanovbdd59152020-02-14 15:30:06 +0100865 return true;
Dominik Laskowski075d3172018-05-24 15:50:06 -0700866 }
867
Marin Shalamanovbdd59152020-02-14 15:30:06 +0100868 if (!mHasMultiDisplaySupport && mInternalHwcDisplayId && mExternalHwcDisplayId) {
Dominik Laskowski075d3172018-05-24 15:50:06 -0700869 ALOGE("Ignoring connection of tertiary display %" PRIu64, hwcDisplayId);
Marin Shalamanovbdd59152020-02-14 15:30:06 +0100870 return true;
871 }
872
873 return false;
874}
875
Peiyong Line9d809e2020-04-14 13:10:48 -0700876std::optional<DisplayIdentificationInfo> HWComposer::onHotplugConnect(
877 hal::HWDisplayId hwcDisplayId) {
Marin Shalamanovbdd59152020-02-14 15:30:06 +0100878 std::optional<DisplayIdentificationInfo> info;
879 if (const auto displayId = toPhysicalDisplayId(hwcDisplayId)) {
880 info = DisplayIdentificationInfo{.id = *displayId,
881 .name = std::string(),
882 .deviceProductInfo = std::nullopt};
Marin Shalamanovf8c63722020-10-06 13:11:21 +0200883 if (mUpdateDeviceProductInfoOnHotplugReconnect) {
884 uint8_t port;
885 DisplayIdentificationData data;
886 getDisplayIdentificationData(hwcDisplayId, &port, &data);
887 if (auto newInfo = parseDisplayIdentificationData(port, data)) {
888 info->deviceProductInfo = std::move(newInfo->deviceProductInfo);
889 } else {
890 ALOGE("Failed to parse identification data for display %" PRIu64, hwcDisplayId);
891 }
892 }
Dominik Laskowski075d3172018-05-24 15:50:06 -0700893 } else {
Marin Shalamanovbdd59152020-02-14 15:30:06 +0100894 uint8_t port;
895 DisplayIdentificationData data;
896 const bool hasDisplayIdentificationData =
897 getDisplayIdentificationData(hwcDisplayId, &port, &data);
898 if (mPhysicalDisplayIdMap.empty()) {
899 mHasMultiDisplaySupport = hasDisplayIdentificationData;
900 ALOGI("Switching to %s multi-display mode",
901 mHasMultiDisplaySupport ? "generalized" : "legacy");
902 }
903
904 if (shouldIgnoreHotplugConnect(hwcDisplayId, hasDisplayIdentificationData)) {
905 return {};
906 }
907
908 info = [this, hwcDisplayId, &port, &data, hasDisplayIdentificationData] {
909 const bool isPrimary = !mInternalHwcDisplayId;
910 if (mHasMultiDisplaySupport) {
911 if (const auto info = parseDisplayIdentificationData(port, data)) {
912 return *info;
913 }
914 ALOGE("Failed to parse identification data for display %" PRIu64, hwcDisplayId);
915 } else {
916 ALOGW_IF(hasDisplayIdentificationData,
917 "Ignoring identification data for display %" PRIu64, hwcDisplayId);
Peiyong Lin65248e02020-04-18 21:15:07 -0700918 port = isPrimary ? LEGACY_DISPLAY_TYPE_PRIMARY : LEGACY_DISPLAY_TYPE_EXTERNAL;
Marin Shalamanovbdd59152020-02-14 15:30:06 +0100919 }
920
Marin Shalamanova524a092020-07-27 21:39:55 +0200921 return DisplayIdentificationInfo{.id = PhysicalDisplayId::fromPort(port),
Marin Shalamanovbdd59152020-02-14 15:30:06 +0100922 .name = isPrimary ? "Internal display"
923 : "External display",
924 .deviceProductInfo = std::nullopt};
925 }();
Dominik Laskowski075d3172018-05-24 15:50:06 -0700926 }
927
Marin Shalamanovbdd59152020-02-14 15:30:06 +0100928 if (!isConnected(info->id)) {
929 allocatePhysicalDisplay(hwcDisplayId, info->id);
930 }
931 return info;
932}
933
934std::optional<DisplayIdentificationInfo> HWComposer::onHotplugDisconnect(
Peiyong Line9d809e2020-04-14 13:10:48 -0700935 hal::HWDisplayId hwcDisplayId) {
Marin Shalamanovbdd59152020-02-14 15:30:06 +0100936 const auto displayId = toPhysicalDisplayId(hwcDisplayId);
937 if (!displayId) {
938 ALOGE("Ignoring disconnection of invalid HWC display %" PRIu64, hwcDisplayId);
939 return {};
Dominik Laskowski075d3172018-05-24 15:50:06 -0700940 }
941
Marin Shalamanovbdd59152020-02-14 15:30:06 +0100942 // The display will later be destroyed by a call to
943 // destroyDisplay(). For now we just mark it disconnected.
944 if (isConnected(*displayId)) {
945 mDisplayData[*displayId].hwcDisplay->setConnected(false);
946 } else {
947 ALOGW("Attempted to disconnect unknown display %" PRIu64, hwcDisplayId);
948 }
949 // The cleanup of Disconnect is handled through HWComposer::disconnectDisplay
950 // via SurfaceFlinger's onHotplugReceived callback handling
951 return DisplayIdentificationInfo{.id = *displayId,
952 .name = std::string(),
Marin Shalamanovf5de90d2019-10-08 10:57:25 +0200953 .deviceProductInfo = std::nullopt};
Steven Thomas6e8f7062017-11-22 14:15:29 -0800954}
955
Peiyong Linbdd08cc2019-12-17 21:35:14 -0800956void HWComposer::loadCapabilities() {
Peiyong Line9d809e2020-04-14 13:10:48 -0700957 static_assert(sizeof(hal::Capability) == sizeof(int32_t), "Capability size has changed");
Peiyong Linbdd08cc2019-12-17 21:35:14 -0800958 auto capabilities = mComposer->getCapabilities();
959 for (auto capability : capabilities) {
Peiyong Line9d809e2020-04-14 13:10:48 -0700960 mCapabilities.emplace(static_cast<hal::Capability>(capability));
Peiyong Linbdd08cc2019-12-17 21:35:14 -0800961 }
962}
963
Lloyd Pique4603f3c2020-02-11 12:06:56 -0800964void HWComposer::loadLayerMetadataSupport() {
965 mSupportedLayerGenericMetadata.clear();
966
967 std::vector<Hwc2::IComposerClient::LayerGenericMetadataKey> supportedMetadataKeyInfo;
968 const auto error = mComposer->getLayerGenericMetadataKeys(&supportedMetadataKeyInfo);
969 if (error != hardware::graphics::composer::V2_4::Error::NONE) {
Ady Abraham3891cbe2021-03-29 11:29:31 -0700970 if (error != hardware::graphics::composer::V2_4::Error::UNSUPPORTED) {
971 ALOGE("%s: %s failed: %s (%d)", __FUNCTION__, "getLayerGenericMetadataKeys",
972 toString(error).c_str(), static_cast<int32_t>(error));
973 }
Lloyd Pique4603f3c2020-02-11 12:06:56 -0800974 return;
975 }
976
977 for (const auto& [name, mandatory] : supportedMetadataKeyInfo) {
978 mSupportedLayerGenericMetadata.emplace(name, mandatory);
979 }
980}
981
Peiyong Linbdd08cc2019-12-17 21:35:14 -0800982uint32_t HWComposer::getMaxVirtualDisplayCount() const {
983 return mComposer->getMaxVirtualDisplayCount();
984}
985
Lloyd Pique441d5042018-10-18 16:49:51 -0700986} // namespace impl
Dominik Laskowskif9750f22018-06-06 12:24:53 -0700987} // namespace android
Ady Abrahamb0dbdaa2020-01-06 16:19:42 -0800988
989// TODO(b/129481165): remove the #pragma below and fix conversion issues
990#pragma clang diagnostic pop // ignored "-Wconversion"