Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2015 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 Abraham | b0dbdaa | 2020-01-06 16:19:42 -0800 | [diff] [blame] | 17 | // TODO(b/129481165): remove the #pragma below and fix conversion issues |
| 18 | #pragma clang diagnostic push |
| 19 | #pragma clang diagnostic ignored "-Wconversion" |
| 20 | |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 21 | // #define LOG_NDEBUG 0 |
| 22 | |
| 23 | #undef LOG_TAG |
| 24 | #define LOG_TAG "HWC2" |
| 25 | #define ATRACE_TAG ATRACE_TAG_GRAPHICS |
| 26 | |
| 27 | #include "HWC2.h" |
| 28 | |
Dominik Laskowski | 4e2b71f | 2020-11-10 15:05:32 -0800 | [diff] [blame] | 29 | #include <android/configuration.h> |
Dominik Laskowski | 8809687 | 2023-12-08 15:26:04 -0500 | [diff] [blame] | 30 | #include <common/FlagManager.h> |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 31 | #include <ui/Fence.h> |
Dan Stoza | 5a423ea | 2017-02-16 14:10:39 -0800 | [diff] [blame] | 32 | #include <ui/FloatRect.h> |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 33 | #include <ui/GraphicBuffer.h> |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 34 | |
Lloyd Pique | 3c085a0 | 2018-05-09 19:38:32 -0700 | [diff] [blame] | 35 | #include <algorithm> |
Dominik Laskowski | 4e2b71f | 2020-11-10 15:05:32 -0800 | [diff] [blame] | 36 | #include <cinttypes> |
Lloyd Pique | 3c085a0 | 2018-05-09 19:38:32 -0700 | [diff] [blame] | 37 | #include <iterator> |
Peiyong Lin | 0ac5f4e | 2018-04-19 22:06:34 -0700 | [diff] [blame] | 38 | #include <set> |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 39 | |
Ady Abraham | 6e60b14 | 2022-01-06 18:10:35 -0800 | [diff] [blame] | 40 | using aidl::android::hardware::graphics::composer3::Color; |
Leon Scroggins III | 2e1aa18 | 2021-12-01 17:33:12 -0500 | [diff] [blame] | 41 | using aidl::android::hardware::graphics::composer3::Composition; |
Ady Abraham | de549d4 | 2022-01-26 19:19:17 -0800 | [diff] [blame] | 42 | using AidlCapability = aidl::android::hardware::graphics::composer3::Capability; |
Leon Scroggins III | 5967aec | 2021-12-29 11:14:22 -0500 | [diff] [blame] | 43 | using aidl::android::hardware::graphics::composer3::DisplayCapability; |
Sally Qi | 11dcd58 | 2024-08-16 18:11:27 -0700 | [diff] [blame] | 44 | using aidl::android::hardware::graphics::composer3::DisplayLuts; |
Sally Qi | 0abc4a5 | 2024-09-26 16:13:06 -0700 | [diff] [blame] | 45 | using aidl::android::hardware::graphics::composer3::LutProperties; |
| 46 | using aidl::android::hardware::graphics::composer3::Luts; |
Sally Qi | 0cbd08b | 2022-08-17 12:12:28 -0700 | [diff] [blame] | 47 | using aidl::android::hardware::graphics::composer3::OverlayProperties; |
Leon Scroggins III | 2e1aa18 | 2021-12-01 17:33:12 -0500 | [diff] [blame] | 48 | |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 49 | namespace android { |
| 50 | |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 51 | using android::Fence; |
Dan Stoza | 5a423ea | 2017-02-16 14:10:39 -0800 | [diff] [blame] | 52 | using android::FloatRect; |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 53 | using android::GraphicBuffer; |
Dan Stoza | 7d7ae73 | 2016-03-16 12:23:40 -0700 | [diff] [blame] | 54 | using android::HdrCapabilities; |
Courtney Goeltzenleuchter | f9c98e5 | 2018-02-12 07:23:17 -0700 | [diff] [blame] | 55 | using android::HdrMetadata; |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 56 | using android::Rect; |
| 57 | using android::Region; |
| 58 | using android::sp; |
| 59 | |
| 60 | namespace HWC2 { |
| 61 | |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 62 | using namespace android::hardware::graphics::composer::hal; |
| 63 | |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 64 | namespace Hwc2 = android::Hwc2; |
| 65 | |
Steven Thomas | 94e35b9 | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 66 | namespace { |
| 67 | |
Peiyong Lin | 0ac5f4e | 2018-04-19 22:06:34 -0700 | [diff] [blame] | 68 | inline bool hasMetadataKey(const std::set<Hwc2::PerFrameMetadataKey>& keys, |
| 69 | const Hwc2::PerFrameMetadataKey& key) { |
| 70 | return keys.find(key) != keys.end(); |
| 71 | } |
| 72 | |
Steven Thomas | 94e35b9 | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 73 | } // namespace anonymous |
| 74 | |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 75 | // Display methods |
Ana Krulec | 4593b69 | 2019-01-11 22:07:25 -0800 | [diff] [blame] | 76 | Display::~Display() = default; |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 77 | |
Ana Krulec | 4593b69 | 2019-01-11 22:07:25 -0800 | [diff] [blame] | 78 | namespace impl { |
Dominik Laskowski | 55c8540 | 2020-01-21 16:25:47 -0800 | [diff] [blame] | 79 | |
Peiyong Lin | 74ca2f4 | 2019-01-14 19:36:57 -0800 | [diff] [blame] | 80 | Display::Display(android::Hwc2::Composer& composer, |
Ady Abraham | de549d4 | 2022-01-26 19:19:17 -0800 | [diff] [blame] | 81 | const std::unordered_set<AidlCapability>& capabilities, HWDisplayId id, |
Lloyd Pique | bc79209 | 2018-01-17 11:52:30 -0800 | [diff] [blame] | 82 | DisplayType type) |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 83 | : mComposer(composer), mCapabilities(capabilities), mId(id), mType(type) { |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 84 | ALOGV("Created display %" PRIu64, id); |
HyunKyoung | a264a35 | 2024-04-24 18:51:33 +0900 | [diff] [blame] | 85 | if (mType == hal::DisplayType::VIRTUAL) { |
| 86 | loadDisplayCapabilities(); |
| 87 | } |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 88 | } |
| 89 | |
Steven Thomas | 94e35b9 | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 90 | Display::~Display() { |
Lloyd Pique | a516c00 | 2021-05-07 14:36:58 -0700 | [diff] [blame] | 91 | // Note: The calls to onOwningDisplayDestroyed() are allowed (and expected) |
| 92 | // to call Display::onLayerDestroyed(). As that call removes entries from |
| 93 | // mLayers, we do not want to have a for loop directly over it here. Since |
| 94 | // the end goal is an empty mLayers anyway, we just go ahead and swap an |
| 95 | // initially empty local container with mLayers, and then enumerate |
| 96 | // the contents of the local container. |
| 97 | Layers destroyingLayers; |
| 98 | std::swap(mLayers, destroyingLayers); |
| 99 | for (const auto& [_, weakLayer] : destroyingLayers) { |
| 100 | if (std::shared_ptr layer = weakLayer.lock()) { |
| 101 | layer->onOwningDisplayDestroyed(); |
| 102 | } |
| 103 | } |
Steven Thomas | 94e35b9 | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 104 | |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 105 | Error error = Error::NONE; |
Dominik Laskowski | 55c8540 | 2020-01-21 16:25:47 -0800 | [diff] [blame] | 106 | const char* msg; |
| 107 | switch (mType) { |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 108 | case DisplayType::PHYSICAL: |
| 109 | error = setVsyncEnabled(HWC2::Vsync::DISABLE); |
Dominik Laskowski | 55c8540 | 2020-01-21 16:25:47 -0800 | [diff] [blame] | 110 | msg = "disable VSYNC for"; |
| 111 | break; |
| 112 | |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 113 | case DisplayType::VIRTUAL: |
Dominik Laskowski | 55c8540 | 2020-01-21 16:25:47 -0800 | [diff] [blame] | 114 | error = static_cast<Error>(mComposer.destroyVirtualDisplay(mId)); |
| 115 | msg = "destroy virtual"; |
| 116 | break; |
| 117 | |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 118 | case DisplayType::INVALID: // Used in unit tests. |
Dominik Laskowski | 55c8540 | 2020-01-21 16:25:47 -0800 | [diff] [blame] | 119 | break; |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 120 | } |
Dominik Laskowski | 55c8540 | 2020-01-21 16:25:47 -0800 | [diff] [blame] | 121 | |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 122 | ALOGE_IF(error != Error::NONE, "%s: Failed to %s display %" PRIu64 ": %d", __FUNCTION__, msg, |
| 123 | mId, static_cast<int32_t>(error)); |
Dominik Laskowski | 55c8540 | 2020-01-21 16:25:47 -0800 | [diff] [blame] | 124 | |
| 125 | ALOGV("Destroyed display %" PRIu64, mId); |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 126 | } |
| 127 | |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 128 | // Required by HWC2 display |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 129 | Error Display::acceptChanges() |
| 130 | { |
Steven Thomas | 94e35b9 | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 131 | auto intError = mComposer.acceptDisplayChanges(mId); |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 132 | return static_cast<Error>(intError); |
| 133 | } |
| 134 | |
Lloyd Pique | a516c00 | 2021-05-07 14:36:58 -0700 | [diff] [blame] | 135 | base::expected<std::shared_ptr<HWC2::Layer>, hal::Error> Display::createLayer() { |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 136 | HWLayerId layerId = 0; |
Steven Thomas | 94e35b9 | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 137 | auto intError = mComposer.createLayer(mId, &layerId); |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 138 | auto error = static_cast<Error>(intError); |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 139 | if (error != Error::NONE) { |
Lloyd Pique | a516c00 | 2021-05-07 14:36:58 -0700 | [diff] [blame] | 140 | return base::unexpected(error); |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 141 | } |
| 142 | |
Lloyd Pique | a516c00 | 2021-05-07 14:36:58 -0700 | [diff] [blame] | 143 | auto layer = std::make_shared<impl::Layer>(mComposer, mCapabilities, *this, layerId); |
| 144 | mLayers.emplace(layerId, layer); |
| 145 | return layer; |
Steven Thomas | 94e35b9 | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 146 | } |
| 147 | |
Lloyd Pique | a516c00 | 2021-05-07 14:36:58 -0700 | [diff] [blame] | 148 | void Display::onLayerDestroyed(hal::HWLayerId layerId) { |
| 149 | mLayers.erase(layerId); |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 150 | } |
| 151 | |
Ady Abraham | 7159f57 | 2019-10-11 11:10:18 -0700 | [diff] [blame] | 152 | bool Display::isVsyncPeriodSwitchSupported() const { |
| 153 | ALOGV("[%" PRIu64 "] isVsyncPeriodSwitchSupported()", mId); |
| 154 | |
Ady Abraham | 4d211cf | 2021-12-14 16:19:03 -0800 | [diff] [blame] | 155 | return mComposer.isSupported(android::Hwc2::Composer::OptionalFeature::RefreshRateSwitching); |
Ady Abraham | 7159f57 | 2019-10-11 11:10:18 -0700 | [diff] [blame] | 156 | } |
| 157 | |
ramindani | 32cf060 | 2022-03-02 02:30:29 +0000 | [diff] [blame] | 158 | bool Display::hasDisplayIdleTimerCapability() const { |
| 159 | bool isCapabilitySupported = false; |
| 160 | return mComposer.hasDisplayIdleTimerCapability(mId, &isCapabilitySupported) == Error::NONE && |
| 161 | isCapabilitySupported; |
| 162 | } |
| 163 | |
ramindani | 06e518e | 2022-03-14 18:47:53 +0000 | [diff] [blame] | 164 | Error Display::getPhysicalDisplayOrientation(Hwc2::AidlTransform* outTransform) const { |
| 165 | auto error = mComposer.getPhysicalDisplayOrientation(mId, outTransform); |
| 166 | return static_cast<Error>(error); |
| 167 | } |
| 168 | |
Lloyd Pique | 35d5824 | 2018-12-18 16:33:25 -0800 | [diff] [blame] | 169 | Error Display::getChangedCompositionTypes(std::unordered_map<HWC2::Layer*, Composition>* outTypes) { |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 170 | std::vector<Hwc2::Layer> layerIds; |
Leon Scroggins III | 2e1aa18 | 2021-12-01 17:33:12 -0500 | [diff] [blame] | 171 | std::vector<Composition> types; |
Steven Thomas | 94e35b9 | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 172 | auto intError = mComposer.getChangedCompositionTypes( |
| 173 | mId, &layerIds, &types); |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 174 | uint32_t numElements = layerIds.size(); |
linkai | d1bb314 | 2023-12-20 10:18:16 +0800 | [diff] [blame] | 175 | const auto error = static_cast<Error>(intError); |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 176 | if (error != Error::NONE) { |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 177 | return error; |
| 178 | } |
| 179 | |
| 180 | outTypes->clear(); |
| 181 | outTypes->reserve(numElements); |
| 182 | for (uint32_t element = 0; element < numElements; ++element) { |
| 183 | auto layer = getLayerById(layerIds[element]); |
| 184 | if (layer) { |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 185 | auto type = types[element]; |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 186 | ALOGV("getChangedCompositionTypes: adding %" PRIu64 " %s", |
| 187 | layer->getId(), to_string(type).c_str()); |
Lloyd Pique | a516c00 | 2021-05-07 14:36:58 -0700 | [diff] [blame] | 188 | outTypes->emplace(layer.get(), type); |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 189 | } else { |
| 190 | ALOGE("getChangedCompositionTypes: invalid layer %" PRIu64 " found" |
| 191 | " on display %" PRIu64, layerIds[element], mId); |
| 192 | } |
| 193 | } |
| 194 | |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 195 | return Error::NONE; |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 196 | } |
| 197 | |
Peiyong Lin | 34beb7a | 2018-03-28 11:57:12 -0700 | [diff] [blame] | 198 | Error Display::getColorModes(std::vector<ColorMode>* outModes) const |
Dan Stoza | 076ac67 | 2016-03-14 10:47:53 -0700 | [diff] [blame] | 199 | { |
Peiyong Lin | fd997e0 | 2018-03-28 15:29:00 -0700 | [diff] [blame] | 200 | auto intError = mComposer.getColorModes(mId, outModes); |
| 201 | return static_cast<Error>(intError); |
Dan Stoza | 076ac67 | 2016-03-14 10:47:53 -0700 | [diff] [blame] | 202 | } |
| 203 | |
Chia-I Wu | d7e01d7 | 2018-06-21 13:39:09 +0800 | [diff] [blame] | 204 | int32_t Display::getSupportedPerFrameMetadata() const |
Peiyong Lin | 0ac5f4e | 2018-04-19 22:06:34 -0700 | [diff] [blame] | 205 | { |
Chia-I Wu | d7e01d7 | 2018-06-21 13:39:09 +0800 | [diff] [blame] | 206 | int32_t supportedPerFrameMetadata = 0; |
| 207 | |
| 208 | std::vector<Hwc2::PerFrameMetadataKey> tmpKeys = mComposer.getPerFrameMetadataKeys(mId); |
| 209 | std::set<Hwc2::PerFrameMetadataKey> keys(tmpKeys.begin(), tmpKeys.end()); |
Peiyong Lin | 0ac5f4e | 2018-04-19 22:06:34 -0700 | [diff] [blame] | 210 | |
| 211 | // Check whether a specific metadata type is supported. A metadata type is considered |
| 212 | // supported if and only if all required fields are supported. |
| 213 | |
| 214 | // SMPTE2086 |
Peiyong Lin | 0ac5f4e | 2018-04-19 22:06:34 -0700 | [diff] [blame] | 215 | if (hasMetadataKey(keys, Hwc2::PerFrameMetadataKey::DISPLAY_RED_PRIMARY_X) && |
| 216 | hasMetadataKey(keys, Hwc2::PerFrameMetadataKey::DISPLAY_RED_PRIMARY_Y) && |
| 217 | hasMetadataKey(keys, Hwc2::PerFrameMetadataKey::DISPLAY_GREEN_PRIMARY_X) && |
| 218 | hasMetadataKey(keys, Hwc2::PerFrameMetadataKey::DISPLAY_GREEN_PRIMARY_Y) && |
| 219 | hasMetadataKey(keys, Hwc2::PerFrameMetadataKey::DISPLAY_BLUE_PRIMARY_X) && |
| 220 | hasMetadataKey(keys, Hwc2::PerFrameMetadataKey::DISPLAY_BLUE_PRIMARY_Y) && |
| 221 | hasMetadataKey(keys, Hwc2::PerFrameMetadataKey::WHITE_POINT_X) && |
| 222 | hasMetadataKey(keys, Hwc2::PerFrameMetadataKey::WHITE_POINT_Y) && |
| 223 | hasMetadataKey(keys, Hwc2::PerFrameMetadataKey::MAX_LUMINANCE) && |
| 224 | hasMetadataKey(keys, Hwc2::PerFrameMetadataKey::MIN_LUMINANCE)) { |
Chia-I Wu | d7e01d7 | 2018-06-21 13:39:09 +0800 | [diff] [blame] | 225 | supportedPerFrameMetadata |= HdrMetadata::Type::SMPTE2086; |
Peiyong Lin | 0ac5f4e | 2018-04-19 22:06:34 -0700 | [diff] [blame] | 226 | } |
| 227 | // CTA861_3 |
| 228 | if (hasMetadataKey(keys, Hwc2::PerFrameMetadataKey::MAX_CONTENT_LIGHT_LEVEL) && |
| 229 | hasMetadataKey(keys, Hwc2::PerFrameMetadataKey::MAX_FRAME_AVERAGE_LIGHT_LEVEL)) { |
Chia-I Wu | d7e01d7 | 2018-06-21 13:39:09 +0800 | [diff] [blame] | 230 | supportedPerFrameMetadata |= HdrMetadata::Type::CTA861_3; |
Peiyong Lin | 0ac5f4e | 2018-04-19 22:06:34 -0700 | [diff] [blame] | 231 | } |
| 232 | |
Valerie Hau | e9e843a | 2018-12-18 13:39:23 -0800 | [diff] [blame] | 233 | // HDR10PLUS |
| 234 | if (hasMetadataKey(keys, Hwc2::PerFrameMetadataKey::HDR10_PLUS_SEI)) { |
| 235 | supportedPerFrameMetadata |= HdrMetadata::Type::HDR10PLUS; |
| 236 | } |
| 237 | |
Chia-I Wu | d7e01d7 | 2018-06-21 13:39:09 +0800 | [diff] [blame] | 238 | return supportedPerFrameMetadata; |
Peiyong Lin | 0ac5f4e | 2018-04-19 22:06:34 -0700 | [diff] [blame] | 239 | } |
| 240 | |
Peiyong Lin | 0e7a791 | 2018-04-05 14:36:36 -0700 | [diff] [blame] | 241 | Error Display::getRenderIntents(ColorMode colorMode, |
| 242 | std::vector<RenderIntent>* outRenderIntents) const |
| 243 | { |
| 244 | auto intError = mComposer.getRenderIntents(mId, colorMode, outRenderIntents); |
| 245 | return static_cast<Error>(intError); |
| 246 | } |
| 247 | |
| 248 | Error Display::getDataspaceSaturationMatrix(Dataspace dataspace, android::mat4* outMatrix) |
| 249 | { |
| 250 | auto intError = mComposer.getDataspaceSaturationMatrix(dataspace, outMatrix); |
| 251 | return static_cast<Error>(intError); |
| 252 | } |
| 253 | |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 254 | Error Display::getName(std::string* outName) const |
| 255 | { |
Steven Thomas | 94e35b9 | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 256 | auto intError = mComposer.getDisplayName(mId, outName); |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 257 | return static_cast<Error>(intError); |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 258 | } |
| 259 | |
| 260 | Error Display::getRequests(HWC2::DisplayRequest* outDisplayRequests, |
Lloyd Pique | 35d5824 | 2018-12-18 16:33:25 -0800 | [diff] [blame] | 261 | std::unordered_map<HWC2::Layer*, LayerRequest>* outLayerRequests) { |
Lloyd Pique | e9eff97 | 2020-05-05 12:36:44 -0700 | [diff] [blame] | 262 | uint32_t intDisplayRequests = 0; |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 263 | std::vector<Hwc2::Layer> layerIds; |
| 264 | std::vector<uint32_t> layerRequests; |
Steven Thomas | 94e35b9 | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 265 | auto intError = mComposer.getDisplayRequests( |
| 266 | mId, &intDisplayRequests, &layerIds, &layerRequests); |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 267 | uint32_t numElements = layerIds.size(); |
| 268 | auto error = static_cast<Error>(intError); |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 269 | if (error != Error::NONE) { |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 270 | return error; |
| 271 | } |
| 272 | |
| 273 | *outDisplayRequests = static_cast<DisplayRequest>(intDisplayRequests); |
| 274 | outLayerRequests->clear(); |
| 275 | outLayerRequests->reserve(numElements); |
| 276 | for (uint32_t element = 0; element < numElements; ++element) { |
| 277 | auto layer = getLayerById(layerIds[element]); |
| 278 | if (layer) { |
| 279 | auto layerRequest = |
| 280 | static_cast<LayerRequest>(layerRequests[element]); |
Lloyd Pique | a516c00 | 2021-05-07 14:36:58 -0700 | [diff] [blame] | 281 | outLayerRequests->emplace(layer.get(), layerRequest); |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 282 | } else { |
| 283 | ALOGE("getRequests: invalid layer %" PRIu64 " found on display %" |
| 284 | PRIu64, layerIds[element], mId); |
| 285 | } |
| 286 | } |
| 287 | |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 288 | return Error::NONE; |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 289 | } |
| 290 | |
Dominik Laskowski | 969cdcb | 2024-02-08 16:35:29 -0500 | [diff] [blame] | 291 | ftl::Expected<ui::DisplayConnectionType, hal::Error> Display::getConnectionType() const { |
| 292 | if (!mConnectionType) { |
| 293 | mConnectionType = [this]() -> decltype(mConnectionType) { |
| 294 | if (mType != DisplayType::PHYSICAL) { |
| 295 | return ftl::Unexpected(Error::BAD_DISPLAY); |
| 296 | } |
Dominik Laskowski | 55c8540 | 2020-01-21 16:25:47 -0800 | [diff] [blame] | 297 | |
Dominik Laskowski | 969cdcb | 2024-02-08 16:35:29 -0500 | [diff] [blame] | 298 | using ConnectionType = Hwc2::IComposerClient::DisplayConnectionType; |
| 299 | ConnectionType connectionType; |
| 300 | |
| 301 | if (const auto error = static_cast<Error>( |
| 302 | mComposer.getDisplayConnectionType(mId, &connectionType)); |
| 303 | error != Error::NONE) { |
| 304 | return ftl::Unexpected(error); |
| 305 | } |
| 306 | |
| 307 | return connectionType == ConnectionType::INTERNAL ? ui::DisplayConnectionType::Internal |
| 308 | : ui::DisplayConnectionType::External; |
| 309 | }(); |
Dominik Laskowski | 55c8540 | 2020-01-21 16:25:47 -0800 | [diff] [blame] | 310 | } |
| 311 | |
Dominik Laskowski | 969cdcb | 2024-02-08 16:35:29 -0500 | [diff] [blame] | 312 | return *mConnectionType; |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 313 | } |
| 314 | |
Leon Scroggins III | 5967aec | 2021-12-29 11:14:22 -0500 | [diff] [blame] | 315 | bool Display::hasCapability(DisplayCapability capability) const { |
Ady Abraham | 27fbcc7 | 2021-09-20 14:54:57 -0700 | [diff] [blame] | 316 | std::scoped_lock lock(mDisplayCapabilitiesMutex); |
| 317 | if (mDisplayCapabilities) { |
| 318 | return mDisplayCapabilities->count(capability) > 0; |
| 319 | } |
| 320 | |
Leon Scroggins III | 515f038 | 2021-12-29 11:17:04 -0500 | [diff] [blame] | 321 | ALOGW("Can't query capability %s." |
Ady Abraham | 27fbcc7 | 2021-09-20 14:54:57 -0700 | [diff] [blame] | 322 | " Display Capabilities were not queried from HWC yet", |
Leon Scroggins III | 515f038 | 2021-12-29 11:17:04 -0500 | [diff] [blame] | 323 | to_string(capability).c_str()); |
Ady Abraham | 27fbcc7 | 2021-09-20 14:54:57 -0700 | [diff] [blame] | 324 | |
| 325 | return false; |
| 326 | } |
| 327 | |
Peiyong Lin | ed531a3 | 2018-10-26 18:27:56 -0700 | [diff] [blame] | 328 | Error Display::supportsDoze(bool* outSupport) const { |
Leon Scroggins III | 689c80f | 2023-06-05 17:49:32 -0400 | [diff] [blame] | 329 | { |
| 330 | std::scoped_lock lock(mDisplayCapabilitiesMutex); |
| 331 | if (!mDisplayCapabilities) { |
| 332 | // The display has not turned on since boot, so DOZE support is unknown. |
| 333 | ALOGW("%s: haven't queried capabilities yet!", __func__); |
| 334 | return Error::NO_RESOURCES; |
| 335 | } |
| 336 | } |
Ady Abraham | 27fbcc7 | 2021-09-20 14:54:57 -0700 | [diff] [blame] | 337 | *outSupport = hasCapability(DisplayCapability::DOZE); |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 338 | return Error::NONE; |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 339 | } |
| 340 | |
Peiyong Lin | 6266589 | 2018-04-16 11:07:44 -0700 | [diff] [blame] | 341 | Error Display::getHdrCapabilities(HdrCapabilities* outCapabilities) const |
Dan Stoza | 7d7ae73 | 2016-03-16 12:23:40 -0700 | [diff] [blame] | 342 | { |
Dan Stoza | 7d7ae73 | 2016-03-16 12:23:40 -0700 | [diff] [blame] | 343 | float maxLuminance = -1.0f; |
| 344 | float maxAverageLuminance = -1.0f; |
| 345 | float minLuminance = -1.0f; |
Marc Kassis | bdf7e4b | 2022-11-04 17:26:48 +0100 | [diff] [blame] | 346 | std::vector<Hwc2::Hdr> hdrTypes; |
| 347 | auto intError = mComposer.getHdrCapabilities(mId, &hdrTypes, &maxLuminance, |
| 348 | &maxAverageLuminance, &minLuminance); |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 349 | auto error = static_cast<HWC2::Error>(intError); |
| 350 | |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 351 | if (error != Error::NONE) { |
Dan Stoza | 7d7ae73 | 2016-03-16 12:23:40 -0700 | [diff] [blame] | 352 | return error; |
| 353 | } |
| 354 | |
Marc Kassis | bdf7e4b | 2022-11-04 17:26:48 +0100 | [diff] [blame] | 355 | *outCapabilities = |
| 356 | HdrCapabilities(std::move(hdrTypes), maxLuminance, maxAverageLuminance, minLuminance); |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 357 | return Error::NONE; |
Dan Stoza | 7d7ae73 | 2016-03-16 12:23:40 -0700 | [diff] [blame] | 358 | } |
| 359 | |
Sally Qi | bb866c1 | 2022-10-17 11:31:20 -0700 | [diff] [blame] | 360 | Error Display::getOverlaySupport(OverlayProperties* outProperties) const { |
| 361 | auto intError = mComposer.getOverlaySupport(outProperties); |
| 362 | return static_cast<Error>(intError); |
Sally Qi | 0cbd08b | 2022-08-17 12:12:28 -0700 | [diff] [blame] | 363 | } |
| 364 | |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 365 | Error Display::getDisplayedContentSamplingAttributes(hal::PixelFormat* outFormat, |
Kevin DuBois | 9c0a176 | 2018-10-16 13:32:31 -0700 | [diff] [blame] | 366 | Dataspace* outDataspace, |
| 367 | uint8_t* outComponentMask) const { |
| 368 | auto intError = mComposer.getDisplayedContentSamplingAttributes(mId, outFormat, outDataspace, |
| 369 | outComponentMask); |
| 370 | return static_cast<Error>(intError); |
| 371 | } |
| 372 | |
Kevin DuBois | 74e5377 | 2018-11-19 10:52:38 -0800 | [diff] [blame] | 373 | Error Display::setDisplayContentSamplingEnabled(bool enabled, uint8_t componentMask, |
| 374 | uint64_t maxFrames) const { |
| 375 | auto intError = |
| 376 | mComposer.setDisplayContentSamplingEnabled(mId, enabled, componentMask, maxFrames); |
| 377 | return static_cast<Error>(intError); |
| 378 | } |
| 379 | |
Kevin DuBois | 1d4249a | 2018-08-29 10:45:14 -0700 | [diff] [blame] | 380 | Error Display::getDisplayedContentSample(uint64_t maxFrames, uint64_t timestamp, |
| 381 | android::DisplayedFrameStats* outStats) const { |
| 382 | auto intError = mComposer.getDisplayedContentSample(mId, maxFrames, timestamp, outStats); |
| 383 | return static_cast<Error>(intError); |
| 384 | } |
| 385 | |
Lloyd Pique | 35d5824 | 2018-12-18 16:33:25 -0800 | [diff] [blame] | 386 | Error Display::getReleaseFences(std::unordered_map<HWC2::Layer*, sp<Fence>>* outFences) const { |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 387 | std::vector<Hwc2::Layer> layerIds; |
| 388 | std::vector<int> fenceFds; |
Steven Thomas | 94e35b9 | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 389 | auto intError = mComposer.getReleaseFences(mId, &layerIds, &fenceFds); |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 390 | auto error = static_cast<Error>(intError); |
| 391 | uint32_t numElements = layerIds.size(); |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 392 | if (error != Error::NONE) { |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 393 | return error; |
| 394 | } |
| 395 | |
Lloyd Pique | 35d5824 | 2018-12-18 16:33:25 -0800 | [diff] [blame] | 396 | std::unordered_map<HWC2::Layer*, sp<Fence>> releaseFences; |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 397 | releaseFences.reserve(numElements); |
| 398 | for (uint32_t element = 0; element < numElements; ++element) { |
| 399 | auto layer = getLayerById(layerIds[element]); |
| 400 | if (layer) { |
Ady Abraham | d11bade | 2022-08-01 16:18:03 -0700 | [diff] [blame] | 401 | sp<Fence> fence(sp<Fence>::make(fenceFds[element])); |
Lloyd Pique | a516c00 | 2021-05-07 14:36:58 -0700 | [diff] [blame] | 402 | releaseFences.emplace(layer.get(), fence); |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 403 | } else { |
| 404 | ALOGE("getReleaseFences: invalid layer %" PRIu64 |
| 405 | " found on display %" PRIu64, layerIds[element], mId); |
Chia-I Wu | 5e74c65 | 2017-05-17 13:43:16 -0700 | [diff] [blame] | 406 | for (; element < numElements; ++element) { |
| 407 | close(fenceFds[element]); |
| 408 | } |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 409 | return Error::BAD_LAYER; |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 410 | } |
| 411 | } |
| 412 | |
| 413 | *outFences = std::move(releaseFences); |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 414 | return Error::NONE; |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 415 | } |
| 416 | |
Fabien Sanglard | 11d0fc3 | 2016-12-01 15:43:01 -0800 | [diff] [blame] | 417 | Error Display::present(sp<Fence>* outPresentFence) |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 418 | { |
Naseer Ahmed | 847650b | 2016-06-17 11:14:25 -0400 | [diff] [blame] | 419 | int32_t presentFenceFd = -1; |
Steven Thomas | 94e35b9 | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 420 | auto intError = mComposer.presentDisplay(mId, &presentFenceFd); |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 421 | auto error = static_cast<Error>(intError); |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 422 | if (error != Error::NONE) { |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 423 | return error; |
| 424 | } |
| 425 | |
Ady Abraham | d11bade | 2022-08-01 16:18:03 -0700 | [diff] [blame] | 426 | *outPresentFence = sp<Fence>::make(presentFenceFd); |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 427 | return Error::NONE; |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 428 | } |
| 429 | |
Marin Shalamanov | 3ea1d60 | 2020-12-16 19:59:39 +0100 | [diff] [blame] | 430 | Error Display::setActiveConfigWithConstraints(hal::HWConfigId configId, |
| 431 | const VsyncPeriodChangeConstraints& constraints, |
| 432 | VsyncPeriodChangeTimeline* outTimeline) { |
Ady Abraham | 7159f57 | 2019-10-11 11:10:18 -0700 | [diff] [blame] | 433 | ALOGV("[%" PRIu64 "] setActiveConfigWithConstraints", mId); |
Ady Abraham | 7159f57 | 2019-10-11 11:10:18 -0700 | [diff] [blame] | 434 | |
Dominik Laskowski | 8809687 | 2023-12-08 15:26:04 -0500 | [diff] [blame] | 435 | // FIXME (b/319505580): At least the first config set on an external display must be |
| 436 | // `setActiveConfig`, so skip over the block that calls `setActiveConfigWithConstraints` |
| 437 | // for simplicity. |
Dominik Laskowski | 8809687 | 2023-12-08 15:26:04 -0500 | [diff] [blame] | 438 | const bool connected_display = FlagManager::getInstance().connected_display(); |
Dominik Laskowski | 8809687 | 2023-12-08 15:26:04 -0500 | [diff] [blame] | 439 | |
| 440 | if (isVsyncPeriodSwitchSupported() && |
Dominik Laskowski | 969cdcb | 2024-02-08 16:35:29 -0500 | [diff] [blame] | 441 | (!connected_display || |
| 442 | getConnectionType().value_opt() != ui::DisplayConnectionType::External)) { |
Ady Abraham | 7159f57 | 2019-10-11 11:10:18 -0700 | [diff] [blame] | 443 | Hwc2::IComposerClient::VsyncPeriodChangeConstraints hwc2Constraints; |
| 444 | hwc2Constraints.desiredTimeNanos = constraints.desiredTimeNanos; |
| 445 | hwc2Constraints.seamlessRequired = constraints.seamlessRequired; |
| 446 | |
| 447 | Hwc2::VsyncPeriodChangeTimeline vsyncPeriodChangeTimeline = {}; |
Marin Shalamanov | 3ea1d60 | 2020-12-16 19:59:39 +0100 | [diff] [blame] | 448 | auto intError = mComposer.setActiveConfigWithConstraints(mId, configId, hwc2Constraints, |
| 449 | &vsyncPeriodChangeTimeline); |
Ady Abraham | 7159f57 | 2019-10-11 11:10:18 -0700 | [diff] [blame] | 450 | outTimeline->newVsyncAppliedTimeNanos = vsyncPeriodChangeTimeline.newVsyncAppliedTimeNanos; |
| 451 | outTimeline->refreshRequired = vsyncPeriodChangeTimeline.refreshRequired; |
| 452 | outTimeline->refreshTimeNanos = vsyncPeriodChangeTimeline.refreshTimeNanos; |
| 453 | return static_cast<Error>(intError); |
| 454 | } |
| 455 | |
| 456 | // Use legacy setActiveConfig instead |
| 457 | ALOGV("fallback to legacy setActiveConfig"); |
| 458 | const auto now = systemTime(); |
| 459 | if (constraints.desiredTimeNanos > now || constraints.seamlessRequired) { |
| 460 | ALOGE("setActiveConfigWithConstraints received constraints that can't be satisfied"); |
| 461 | } |
| 462 | |
Marin Shalamanov | 3ea1d60 | 2020-12-16 19:59:39 +0100 | [diff] [blame] | 463 | auto intError_2_4 = mComposer.setActiveConfig(mId, configId); |
Ady Abraham | 7159f57 | 2019-10-11 11:10:18 -0700 | [diff] [blame] | 464 | outTimeline->newVsyncAppliedTimeNanos = std::max(now, constraints.desiredTimeNanos); |
| 465 | outTimeline->refreshRequired = true; |
| 466 | outTimeline->refreshTimeNanos = now; |
| 467 | return static_cast<Error>(intError_2_4); |
| 468 | } |
| 469 | |
Daniel Nicoara | 1f42e3a | 2017-04-10 13:27:32 -0400 | [diff] [blame] | 470 | Error Display::setClientTarget(uint32_t slot, const sp<GraphicBuffer>& target, |
Alec Mouri | f97df4d | 2023-09-06 02:10:05 +0000 | [diff] [blame] | 471 | const sp<Fence>& acquireFence, Dataspace dataspace, |
| 472 | float hdrSdrRatio) { |
Dan Stoza | 5cf424b | 2016-05-20 14:02:39 -0700 | [diff] [blame] | 473 | // TODO: Properly encode client target surface damage |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 474 | int32_t fenceFd = acquireFence->dup(); |
Alec Mouri | f97df4d | 2023-09-06 02:10:05 +0000 | [diff] [blame] | 475 | auto intError = |
| 476 | mComposer.setClientTarget(mId, slot, target, fenceFd, dataspace, |
| 477 | std::vector<Hwc2::IComposerClient::Rect>(), hdrSdrRatio); |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 478 | return static_cast<Error>(intError); |
| 479 | } |
| 480 | |
Peiyong Lin | 0e7a791 | 2018-04-05 14:36:36 -0700 | [diff] [blame] | 481 | Error Display::setColorMode(ColorMode mode, RenderIntent renderIntent) |
Dan Stoza | 076ac67 | 2016-03-14 10:47:53 -0700 | [diff] [blame] | 482 | { |
Peiyong Lin | 0e7a791 | 2018-04-05 14:36:36 -0700 | [diff] [blame] | 483 | auto intError = mComposer.setColorMode(mId, mode, renderIntent); |
Dan Stoza | 076ac67 | 2016-03-14 10:47:53 -0700 | [diff] [blame] | 484 | return static_cast<Error>(intError); |
| 485 | } |
| 486 | |
Ady Abraham | dc011a9 | 2021-12-21 14:06:44 -0800 | [diff] [blame] | 487 | Error Display::setColorTransform(const android::mat4& matrix) { |
| 488 | auto intError = mComposer.setColorTransform(mId, matrix.asArray()); |
Dan Stoza | 5df2a86 | 2016-03-24 16:19:37 -0700 | [diff] [blame] | 489 | return static_cast<Error>(intError); |
| 490 | } |
| 491 | |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 492 | Error Display::setOutputBuffer(const sp<GraphicBuffer>& buffer, |
| 493 | const sp<Fence>& releaseFence) |
| 494 | { |
| 495 | int32_t fenceFd = releaseFence->dup(); |
| 496 | auto handle = buffer->getNativeBuffer()->handle; |
Steven Thomas | 94e35b9 | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 497 | auto intError = mComposer.setOutputBuffer(mId, handle, fenceFd); |
Dan Stoza | 3862898 | 2016-07-13 15:48:58 -0700 | [diff] [blame] | 498 | close(fenceFd); |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 499 | return static_cast<Error>(intError); |
| 500 | } |
| 501 | |
| 502 | Error Display::setPowerMode(PowerMode mode) |
| 503 | { |
Chia-I Wu | cd8d7f0 | 2016-11-16 11:02:31 +0800 | [diff] [blame] | 504 | auto intMode = static_cast<Hwc2::IComposerClient::PowerMode>(mode); |
Steven Thomas | 94e35b9 | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 505 | auto intError = mComposer.setPowerMode(mId, intMode); |
Peiyong Lin | 1336e6e | 2019-05-28 09:23:50 -0700 | [diff] [blame] | 506 | |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 507 | if (mode == PowerMode::ON) { |
HyunKyoung | a264a35 | 2024-04-24 18:51:33 +0900 | [diff] [blame] | 508 | loadDisplayCapabilities(); |
Peiyong Lin | 1336e6e | 2019-05-28 09:23:50 -0700 | [diff] [blame] | 509 | } |
| 510 | |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 511 | return static_cast<Error>(intError); |
| 512 | } |
| 513 | |
| 514 | Error Display::setVsyncEnabled(Vsync enabled) |
| 515 | { |
Chia-I Wu | cd8d7f0 | 2016-11-16 11:02:31 +0800 | [diff] [blame] | 516 | auto intEnabled = static_cast<Hwc2::IComposerClient::Vsync>(enabled); |
Steven Thomas | 94e35b9 | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 517 | auto intError = mComposer.setVsyncEnabled(mId, intEnabled); |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 518 | return static_cast<Error>(intError); |
| 519 | } |
| 520 | |
ramindani | 09acbb8 | 2023-11-03 09:02:38 -0700 | [diff] [blame] | 521 | Error Display::validate(nsecs_t expectedPresentTime, int32_t frameIntervalNs, uint32_t* outNumTypes, |
Ady Abraham | 43065bd | 2021-12-10 17:22:15 -0800 | [diff] [blame] | 522 | uint32_t* outNumRequests) { |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 523 | uint32_t numTypes = 0; |
| 524 | uint32_t numRequests = 0; |
ramindani | 09acbb8 | 2023-11-03 09:02:38 -0700 | [diff] [blame] | 525 | auto intError = mComposer.validateDisplay(mId, expectedPresentTime, frameIntervalNs, &numTypes, |
| 526 | &numRequests); |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 527 | auto error = static_cast<Error>(intError); |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 528 | if (error != Error::NONE && !hasChangesError(error)) { |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 529 | return error; |
| 530 | } |
| 531 | |
| 532 | *outNumTypes = numTypes; |
| 533 | *outNumRequests = numRequests; |
| 534 | return error; |
| 535 | } |
| 536 | |
ramindani | 4aac32c | 2023-10-30 14:13:30 -0700 | [diff] [blame] | 537 | Error Display::presentOrValidate(nsecs_t expectedPresentTime, int32_t frameIntervalNs, |
| 538 | uint32_t* outNumTypes, uint32_t* outNumRequests, |
| 539 | sp<android::Fence>* outPresentFence, uint32_t* state) { |
Fabien Sanglard | 249c0ae | 2017-06-19 19:22:36 -0700 | [diff] [blame] | 540 | uint32_t numTypes = 0; |
| 541 | uint32_t numRequests = 0; |
| 542 | int32_t presentFenceFd = -1; |
ramindani | 4aac32c | 2023-10-30 14:13:30 -0700 | [diff] [blame] | 543 | auto intError = |
| 544 | mComposer.presentOrValidateDisplay(mId, expectedPresentTime, frameIntervalNs, &numTypes, |
| 545 | &numRequests, &presentFenceFd, state); |
Fabien Sanglard | 249c0ae | 2017-06-19 19:22:36 -0700 | [diff] [blame] | 546 | auto error = static_cast<Error>(intError); |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 547 | if (error != Error::NONE && !hasChangesError(error)) { |
Fabien Sanglard | 249c0ae | 2017-06-19 19:22:36 -0700 | [diff] [blame] | 548 | return error; |
| 549 | } |
| 550 | |
| 551 | if (*state == 1) { |
Ady Abraham | d11bade | 2022-08-01 16:18:03 -0700 | [diff] [blame] | 552 | *outPresentFence = sp<Fence>::make(presentFenceFd); |
Fabien Sanglard | 249c0ae | 2017-06-19 19:22:36 -0700 | [diff] [blame] | 553 | } |
| 554 | |
| 555 | if (*state == 0) { |
| 556 | *outNumTypes = numTypes; |
| 557 | *outNumRequests = numRequests; |
| 558 | } |
| 559 | return error; |
| 560 | } |
Chia-I Wu | 0c6ce46 | 2017-06-22 10:48:28 -0700 | [diff] [blame] | 561 | |
Dominik Laskowski | b17c621 | 2022-05-09 09:36:19 -0700 | [diff] [blame] | 562 | ftl::Future<Error> Display::setDisplayBrightness( |
Alec Mouri | 4d8a05d | 2022-03-23 18:14:26 +0000 | [diff] [blame] | 563 | float brightness, float brightnessNits, |
| 564 | const Hwc2::Composer::DisplayBrightnessOptions& options) { |
| 565 | return ftl::defer([composer = &mComposer, id = mId, brightness, brightnessNits, options] { |
| 566 | const auto intError = |
| 567 | composer->setDisplayBrightness(id, brightness, brightnessNits, options); |
Dominik Laskowski | 5690bde | 2020-04-23 19:04:22 -0700 | [diff] [blame] | 568 | return static_cast<Error>(intError); |
| 569 | }); |
Dan Gittik | 57e63c5 | 2019-01-18 16:37:54 +0000 | [diff] [blame] | 570 | } |
| 571 | |
Kriti Dang | 7defaf3 | 2021-11-15 11:55:43 +0100 | [diff] [blame] | 572 | Error Display::setBootDisplayConfig(hal::HWConfigId configId) { |
| 573 | auto intError = mComposer.setBootDisplayConfig(mId, configId); |
| 574 | return static_cast<Error>(intError); |
| 575 | } |
| 576 | |
| 577 | Error Display::clearBootDisplayConfig() { |
| 578 | auto intError = mComposer.clearBootDisplayConfig(mId); |
| 579 | return static_cast<Error>(intError); |
| 580 | } |
| 581 | |
| 582 | Error Display::getPreferredBootDisplayConfig(hal::HWConfigId* configId) const { |
| 583 | auto intError = mComposer.getPreferredBootDisplayConfig(mId, configId); |
| 584 | return static_cast<Error>(intError); |
| 585 | } |
| 586 | |
Dominik Laskowski | 5690bde | 2020-04-23 19:04:22 -0700 | [diff] [blame] | 587 | Error Display::setAutoLowLatencyMode(bool on) { |
Galia Peycheva | 5492cb5 | 2019-10-30 14:13:16 +0100 | [diff] [blame] | 588 | auto intError = mComposer.setAutoLowLatencyMode(mId, on); |
| 589 | return static_cast<Error>(intError); |
| 590 | } |
| 591 | |
| 592 | Error Display::getSupportedContentTypes(std::vector<ContentType>* outSupportedContentTypes) const { |
| 593 | std::vector<Hwc2::IComposerClient::ContentType> tmpSupportedContentTypes; |
| 594 | auto intError = mComposer.getSupportedContentTypes(mId, &tmpSupportedContentTypes); |
| 595 | for (Hwc2::IComposerClient::ContentType contentType : tmpSupportedContentTypes) { |
| 596 | outSupportedContentTypes->push_back(static_cast<ContentType>(contentType)); |
| 597 | } |
| 598 | return static_cast<Error>(intError); |
| 599 | } |
| 600 | |
Dominik Laskowski | 5690bde | 2020-04-23 19:04:22 -0700 | [diff] [blame] | 601 | Error Display::setContentType(ContentType contentType) { |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 602 | auto intError = mComposer.setContentType(mId, contentType); |
Galia Peycheva | 5492cb5 | 2019-10-30 14:13:16 +0100 | [diff] [blame] | 603 | return static_cast<Error>(intError); |
| 604 | } |
| 605 | |
Alec Mouri | 8506569 | 2022-03-18 00:58:26 +0000 | [diff] [blame] | 606 | Error Display::getClientTargetProperty( |
| 607 | aidl::android::hardware::graphics::composer3::ClientTargetPropertyWithBrightness* |
| 608 | outClientTargetProperty) { |
| 609 | const auto error = mComposer.getClientTargetProperty(mId, outClientTargetProperty); |
Peiyong Lin | dfc3f7c | 2020-05-07 20:15:50 -0700 | [diff] [blame] | 610 | return static_cast<Error>(error); |
| 611 | } |
| 612 | |
Sally Qi | 95f669a | 2024-08-27 11:31:42 -0700 | [diff] [blame] | 613 | Error Display::getRequestedLuts(LayerLuts* outLuts, |
| 614 | LutFileDescriptorMapper& lutFileDescriptorMapper) { |
| 615 | std::vector<Hwc2::Layer> layerIds; |
| 616 | std::vector<DisplayLuts::LayerLut> tmpLuts; |
| 617 | const auto error = static_cast<Error>(mComposer.getRequestedLuts(mId, &layerIds, &tmpLuts)); |
| 618 | if (error != Error::NONE) { |
| 619 | return error; |
| 620 | } |
| 621 | |
| 622 | uint32_t numElements = layerIds.size(); |
| 623 | outLuts->clear(); |
| 624 | for (uint32_t i = 0; i < numElements; ++i) { |
| 625 | auto layer = getLayerById(layerIds[i]); |
| 626 | if (layer) { |
| 627 | auto& layerLut = tmpLuts[i]; |
Sally Qi | 0abc4a5 | 2024-09-26 16:13:06 -0700 | [diff] [blame] | 628 | if (layerLut.luts.pfd.get() > 0 && layerLut.luts.offsets.has_value()) { |
| 629 | const auto& offsets = layerLut.luts.offsets.value(); |
| 630 | std::vector<std::pair<int32_t, LutProperties>> lutOffsetsAndProperties; |
| 631 | lutOffsetsAndProperties.reserve(offsets.size()); |
| 632 | std::transform(offsets.begin(), offsets.end(), layerLut.luts.lutProperties.begin(), |
| 633 | std::back_inserter(lutOffsetsAndProperties), |
| 634 | [](int32_t i, LutProperties j) { return std::make_pair(i, j); }); |
| 635 | outLuts->emplace_or_replace(layer.get(), lutOffsetsAndProperties); |
| 636 | lutFileDescriptorMapper.emplace_or_replace(layer.get(), |
| 637 | ndk::ScopedFileDescriptor( |
| 638 | layerLut.luts.pfd.release())); |
| 639 | } |
Sally Qi | 492cec3 | 2024-06-28 14:34:47 -0700 | [diff] [blame] | 640 | } |
| 641 | } |
Sally Qi | 95f669a | 2024-08-27 11:31:42 -0700 | [diff] [blame] | 642 | |
| 643 | return Error::NONE; |
Sally Qi | 492cec3 | 2024-06-28 14:34:47 -0700 | [diff] [blame] | 644 | } |
| 645 | |
Leon Scroggins III | e7c51c6 | 2022-02-01 15:53:54 -0500 | [diff] [blame] | 646 | Error Display::getDisplayDecorationSupport( |
| 647 | std::optional<aidl::android::hardware::graphics::common::DisplayDecorationSupport>* |
| 648 | support) { |
| 649 | const auto error = mComposer.getDisplayDecorationSupport(mId, support); |
| 650 | return static_cast<Error>(error); |
| 651 | } |
| 652 | |
ramindani | 32cf060 | 2022-03-02 02:30:29 +0000 | [diff] [blame] | 653 | Error Display::setIdleTimerEnabled(std::chrono::milliseconds timeout) { |
| 654 | const auto error = mComposer.setIdleTimerEnabled(mId, timeout); |
| 655 | return static_cast<Error>(error); |
| 656 | } |
| 657 | |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 658 | // For use by Device |
| 659 | |
Steven Thomas | 94e35b9 | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 660 | void Display::setConnected(bool connected) { |
Steven Thomas | b6c6ad4 | 2018-01-29 12:22:00 -0800 | [diff] [blame] | 661 | if (!mIsConnected && connected) { |
Steven Thomas | 94e35b9 | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 662 | mComposer.setClientTargetSlotCount(mId); |
Steven Thomas | 94e35b9 | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 663 | } |
| 664 | mIsConnected = connected; |
| 665 | } |
| 666 | |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 667 | // Other Display methods |
| 668 | |
Lloyd Pique | a516c00 | 2021-05-07 14:36:58 -0700 | [diff] [blame] | 669 | std::shared_ptr<HWC2::Layer> Display::getLayerById(HWLayerId id) const { |
| 670 | auto it = mLayers.find(id); |
| 671 | return it != mLayers.end() ? it->second.lock() : nullptr; |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 672 | } |
HyunKyoung | a264a35 | 2024-04-24 18:51:33 +0900 | [diff] [blame] | 673 | |
| 674 | void Display::loadDisplayCapabilities() { |
| 675 | std::call_once(mDisplayCapabilityQueryFlag, [this]() { |
| 676 | std::vector<DisplayCapability> tmpCapabilities; |
| 677 | auto error = |
| 678 | static_cast<Error>(mComposer.getDisplayCapabilities(mId, &tmpCapabilities)); |
| 679 | if (error == Error::NONE) { |
| 680 | std::scoped_lock lock(mDisplayCapabilitiesMutex); |
| 681 | mDisplayCapabilities.emplace(); |
| 682 | for (auto capability : tmpCapabilities) { |
| 683 | mDisplayCapabilities->emplace(capability); |
| 684 | } |
| 685 | } else if (error == Error::UNSUPPORTED) { |
| 686 | std::scoped_lock lock(mDisplayCapabilitiesMutex); |
| 687 | mDisplayCapabilities.emplace(); |
| 688 | if (mCapabilities.count(AidlCapability::SKIP_CLIENT_COLOR_TRANSFORM)) { |
| 689 | mDisplayCapabilities->emplace(DisplayCapability::SKIP_CLIENT_COLOR_TRANSFORM); |
| 690 | } |
| 691 | bool dozeSupport = false; |
| 692 | error = static_cast<Error>(mComposer.getDozeSupport(mId, &dozeSupport)); |
| 693 | if (error == Error::NONE && dozeSupport) { |
| 694 | mDisplayCapabilities->emplace(DisplayCapability::DOZE); |
| 695 | } |
| 696 | } |
| 697 | }); |
| 698 | } |
Lucas Berthou | 8d0a0c4 | 2024-08-27 14:32:31 +0000 | [diff] [blame] | 699 | |
| 700 | void Display::setPhysicalSizeInMm(std::optional<ui::Size> size) { |
| 701 | mPhysicalSize = size; |
| 702 | } |
| 703 | |
Ana Krulec | 4593b69 | 2019-01-11 22:07:25 -0800 | [diff] [blame] | 704 | } // namespace impl |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 705 | |
| 706 | // Layer methods |
| 707 | |
Leon Scroggins III | 4459bf4 | 2022-01-04 13:58:26 -0500 | [diff] [blame] | 708 | namespace { |
| 709 | std::vector<Hwc2::IComposerClient::Rect> convertRegionToHwcRects(const Region& region) { |
| 710 | size_t rectCount = 0; |
| 711 | Rect const* rectArray = region.getArray(&rectCount); |
| 712 | |
| 713 | std::vector<Hwc2::IComposerClient::Rect> hwcRects; |
| 714 | hwcRects.reserve(rectCount); |
| 715 | for (size_t rect = 0; rect < rectCount; ++rect) { |
| 716 | hwcRects.push_back({rectArray[rect].left, rectArray[rect].top, rectArray[rect].right, |
| 717 | rectArray[rect].bottom}); |
| 718 | } |
| 719 | return hwcRects; |
| 720 | } |
| 721 | } // namespace |
| 722 | |
Lloyd Pique | 35d5824 | 2018-12-18 16:33:25 -0800 | [diff] [blame] | 723 | Layer::~Layer() = default; |
| 724 | |
| 725 | namespace impl { |
| 726 | |
Ady Abraham | de549d4 | 2022-01-26 19:19:17 -0800 | [diff] [blame] | 727 | Layer::Layer(android::Hwc2::Composer& composer, |
| 728 | const std::unordered_set<AidlCapability>& capabilities, HWC2::Display& display, |
| 729 | HWLayerId layerId) |
Lloyd Pique | 4603f3c | 2020-02-11 12:06:56 -0800 | [diff] [blame] | 730 | : mComposer(composer), |
| 731 | mCapabilities(capabilities), |
Lloyd Pique | a516c00 | 2021-05-07 14:36:58 -0700 | [diff] [blame] | 732 | mDisplay(&display), |
Lloyd Pique | 4603f3c | 2020-02-11 12:06:56 -0800 | [diff] [blame] | 733 | mId(layerId), |
| 734 | mColorMatrix(android::mat4()) { |
Lloyd Pique | a516c00 | 2021-05-07 14:36:58 -0700 | [diff] [blame] | 735 | ALOGV("Created layer %" PRIu64 " on display %" PRIu64, layerId, display.getId()); |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 736 | } |
| 737 | |
| 738 | Layer::~Layer() |
| 739 | { |
Lloyd Pique | a516c00 | 2021-05-07 14:36:58 -0700 | [diff] [blame] | 740 | onOwningDisplayDestroyed(); |
| 741 | } |
| 742 | |
| 743 | void Layer::onOwningDisplayDestroyed() { |
| 744 | // Note: onOwningDisplayDestroyed() may be called to perform cleanup by |
| 745 | // either the Layer dtor or by the Display dtor and must be safe to call |
| 746 | // from either path. In particular, the call to Display::onLayerDestroyed() |
| 747 | // is expected to be safe to do, |
| 748 | |
| 749 | if (CC_UNLIKELY(!mDisplay)) { |
| 750 | return; |
| 751 | } |
| 752 | |
| 753 | mDisplay->onLayerDestroyed(mId); |
| 754 | |
| 755 | // Note: If the HWC display was actually disconnected, these calls are will |
| 756 | // return an error. We always make them as there may be other reasons for |
| 757 | // the HWC2::Display to be destroyed. |
| 758 | auto intError = mComposer.destroyLayer(mDisplay->getId(), mId); |
Steven Thomas | 94e35b9 | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 759 | auto error = static_cast<Error>(intError); |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 760 | ALOGE_IF(error != Error::NONE, |
| 761 | "destroyLayer(%" PRIu64 ", %" PRIu64 ")" |
| 762 | " failed: %s (%d)", |
Lloyd Pique | a516c00 | 2021-05-07 14:36:58 -0700 | [diff] [blame] | 763 | mDisplay->getId(), mId, to_string(error).c_str(), intError); |
| 764 | |
| 765 | mDisplay = nullptr; |
Steven Thomas | 94e35b9 | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 766 | } |
| 767 | |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 768 | Error Layer::setCursorPosition(int32_t x, int32_t y) |
| 769 | { |
Lloyd Pique | a516c00 | 2021-05-07 14:36:58 -0700 | [diff] [blame] | 770 | if (CC_UNLIKELY(!mDisplay)) { |
| 771 | return Error::BAD_DISPLAY; |
| 772 | } |
| 773 | |
| 774 | auto intError = mComposer.setCursorPosition(mDisplay->getId(), mId, x, y); |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 775 | return static_cast<Error>(intError); |
| 776 | } |
| 777 | |
Daniel Nicoara | 1f42e3a | 2017-04-10 13:27:32 -0400 | [diff] [blame] | 778 | Error Layer::setBuffer(uint32_t slot, const sp<GraphicBuffer>& buffer, |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 779 | const sp<Fence>& acquireFence) |
| 780 | { |
Lloyd Pique | a516c00 | 2021-05-07 14:36:58 -0700 | [diff] [blame] | 781 | if (CC_UNLIKELY(!mDisplay)) { |
| 782 | return Error::BAD_DISPLAY; |
| 783 | } |
| 784 | |
Yichi Chen | 8366f56 | 2019-03-25 19:44:06 +0800 | [diff] [blame] | 785 | if (buffer == nullptr && mBufferSlot == slot) { |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 786 | return Error::NONE; |
Yichi Chen | 8366f56 | 2019-03-25 19:44:06 +0800 | [diff] [blame] | 787 | } |
| 788 | mBufferSlot = slot; |
| 789 | |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 790 | int32_t fenceFd = acquireFence->dup(); |
Lloyd Pique | a516c00 | 2021-05-07 14:36:58 -0700 | [diff] [blame] | 791 | auto intError = mComposer.setLayerBuffer(mDisplay->getId(), mId, slot, buffer, fenceFd); |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 792 | return static_cast<Error>(intError); |
| 793 | } |
| 794 | |
Brian Lindahl | b158a5c | 2022-12-15 15:21:13 -0700 | [diff] [blame] | 795 | Error Layer::setBufferSlotsToClear(const std::vector<uint32_t>& slotsToClear, |
| 796 | uint32_t activeBufferSlot) { |
Brian Lindahl | 90553da | 2022-12-06 13:36:30 -0700 | [diff] [blame] | 797 | if (CC_UNLIKELY(!mDisplay)) { |
| 798 | return Error::BAD_DISPLAY; |
| 799 | } |
Brian Lindahl | b158a5c | 2022-12-15 15:21:13 -0700 | [diff] [blame] | 800 | auto intError = mComposer.setLayerBufferSlotsToClear(mDisplay->getId(), mId, slotsToClear, |
| 801 | activeBufferSlot); |
Brian Lindahl | 90553da | 2022-12-06 13:36:30 -0700 | [diff] [blame] | 802 | return static_cast<Error>(intError); |
| 803 | } |
| 804 | |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 805 | Error Layer::setSurfaceDamage(const Region& damage) |
| 806 | { |
Lloyd Pique | a516c00 | 2021-05-07 14:36:58 -0700 | [diff] [blame] | 807 | if (CC_UNLIKELY(!mDisplay)) { |
| 808 | return Error::BAD_DISPLAY; |
| 809 | } |
| 810 | |
Yichi Chen | 8366f56 | 2019-03-25 19:44:06 +0800 | [diff] [blame] | 811 | if (damage.isRect() && mDamageRegion.isRect() && |
| 812 | (damage.getBounds() == mDamageRegion.getBounds())) { |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 813 | return Error::NONE; |
Yichi Chen | 8366f56 | 2019-03-25 19:44:06 +0800 | [diff] [blame] | 814 | } |
| 815 | mDamageRegion = damage; |
| 816 | |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 817 | // We encode default full-screen damage as INVALID_RECT upstream, but as 0 |
| 818 | // rects for HWC |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 819 | Hwc2::Error intError = Hwc2::Error::NONE; |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 820 | if (damage.isRect() && damage.getBounds() == Rect::INVALID_RECT) { |
Lloyd Pique | a516c00 | 2021-05-07 14:36:58 -0700 | [diff] [blame] | 821 | intError = mComposer.setLayerSurfaceDamage(mDisplay->getId(), mId, |
| 822 | std::vector<Hwc2::IComposerClient::Rect>()); |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 823 | } else { |
Leon Scroggins III | 4459bf4 | 2022-01-04 13:58:26 -0500 | [diff] [blame] | 824 | const auto hwcRects = convertRegionToHwcRects(damage); |
Lloyd Pique | a516c00 | 2021-05-07 14:36:58 -0700 | [diff] [blame] | 825 | intError = mComposer.setLayerSurfaceDamage(mDisplay->getId(), mId, hwcRects); |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 826 | } |
| 827 | |
| 828 | return static_cast<Error>(intError); |
| 829 | } |
| 830 | |
| 831 | Error Layer::setBlendMode(BlendMode mode) |
| 832 | { |
Lloyd Pique | a516c00 | 2021-05-07 14:36:58 -0700 | [diff] [blame] | 833 | if (CC_UNLIKELY(!mDisplay)) { |
| 834 | return Error::BAD_DISPLAY; |
| 835 | } |
| 836 | |
| 837 | auto intError = mComposer.setLayerBlendMode(mDisplay->getId(), mId, mode); |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 838 | return static_cast<Error>(intError); |
| 839 | } |
| 840 | |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 841 | Error Layer::setColor(Color color) { |
Lloyd Pique | a516c00 | 2021-05-07 14:36:58 -0700 | [diff] [blame] | 842 | if (CC_UNLIKELY(!mDisplay)) { |
| 843 | return Error::BAD_DISPLAY; |
| 844 | } |
| 845 | |
| 846 | auto intError = mComposer.setLayerColor(mDisplay->getId(), mId, color); |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 847 | return static_cast<Error>(intError); |
| 848 | } |
| 849 | |
| 850 | Error Layer::setCompositionType(Composition type) |
| 851 | { |
Lloyd Pique | a516c00 | 2021-05-07 14:36:58 -0700 | [diff] [blame] | 852 | if (CC_UNLIKELY(!mDisplay)) { |
| 853 | return Error::BAD_DISPLAY; |
| 854 | } |
| 855 | |
| 856 | auto intError = mComposer.setLayerCompositionType(mDisplay->getId(), mId, type); |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 857 | return static_cast<Error>(intError); |
| 858 | } |
| 859 | |
Peiyong Lin | 34beb7a | 2018-03-28 11:57:12 -0700 | [diff] [blame] | 860 | Error Layer::setDataspace(Dataspace dataspace) |
Dan Stoza | 5df2a86 | 2016-03-24 16:19:37 -0700 | [diff] [blame] | 861 | { |
Lloyd Pique | a516c00 | 2021-05-07 14:36:58 -0700 | [diff] [blame] | 862 | if (CC_UNLIKELY(!mDisplay)) { |
| 863 | return Error::BAD_DISPLAY; |
| 864 | } |
| 865 | |
Courtney Goeltzenleuchter | c988ee4 | 2017-05-31 17:56:46 -0600 | [diff] [blame] | 866 | if (dataspace == mDataSpace) { |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 867 | return Error::NONE; |
Courtney Goeltzenleuchter | c988ee4 | 2017-05-31 17:56:46 -0600 | [diff] [blame] | 868 | } |
| 869 | mDataSpace = dataspace; |
Lloyd Pique | a516c00 | 2021-05-07 14:36:58 -0700 | [diff] [blame] | 870 | auto intError = mComposer.setLayerDataspace(mDisplay->getId(), mId, mDataSpace); |
Dan Stoza | 5df2a86 | 2016-03-24 16:19:37 -0700 | [diff] [blame] | 871 | return static_cast<Error>(intError); |
| 872 | } |
| 873 | |
Peiyong Lin | 0ac5f4e | 2018-04-19 22:06:34 -0700 | [diff] [blame] | 874 | Error Layer::setPerFrameMetadata(const int32_t supportedPerFrameMetadata, |
| 875 | const android::HdrMetadata& metadata) |
| 876 | { |
Lloyd Pique | a516c00 | 2021-05-07 14:36:58 -0700 | [diff] [blame] | 877 | if (CC_UNLIKELY(!mDisplay)) { |
| 878 | return Error::BAD_DISPLAY; |
| 879 | } |
| 880 | |
Courtney Goeltzenleuchter | f9c98e5 | 2018-02-12 07:23:17 -0700 | [diff] [blame] | 881 | if (metadata == mHdrMetadata) { |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 882 | return Error::NONE; |
Courtney Goeltzenleuchter | f9c98e5 | 2018-02-12 07:23:17 -0700 | [diff] [blame] | 883 | } |
| 884 | |
| 885 | mHdrMetadata = metadata; |
Peiyong Lin | 0ac5f4e | 2018-04-19 22:06:34 -0700 | [diff] [blame] | 886 | int validTypes = mHdrMetadata.validTypes & supportedPerFrameMetadata; |
| 887 | std::vector<Hwc2::PerFrameMetadata> perFrameMetadatas; |
| 888 | if (validTypes & HdrMetadata::SMPTE2086) { |
| 889 | perFrameMetadatas.insert(perFrameMetadatas.end(), |
| 890 | {{Hwc2::PerFrameMetadataKey::DISPLAY_RED_PRIMARY_X, |
Valerie Hau | e9e843a | 2018-12-18 13:39:23 -0800 | [diff] [blame] | 891 | mHdrMetadata.smpte2086.displayPrimaryRed.x}, |
| 892 | {Hwc2::PerFrameMetadataKey::DISPLAY_RED_PRIMARY_Y, |
| 893 | mHdrMetadata.smpte2086.displayPrimaryRed.y}, |
| 894 | {Hwc2::PerFrameMetadataKey::DISPLAY_GREEN_PRIMARY_X, |
| 895 | mHdrMetadata.smpte2086.displayPrimaryGreen.x}, |
| 896 | {Hwc2::PerFrameMetadataKey::DISPLAY_GREEN_PRIMARY_Y, |
| 897 | mHdrMetadata.smpte2086.displayPrimaryGreen.y}, |
| 898 | {Hwc2::PerFrameMetadataKey::DISPLAY_BLUE_PRIMARY_X, |
| 899 | mHdrMetadata.smpte2086.displayPrimaryBlue.x}, |
| 900 | {Hwc2::PerFrameMetadataKey::DISPLAY_BLUE_PRIMARY_Y, |
| 901 | mHdrMetadata.smpte2086.displayPrimaryBlue.y}, |
| 902 | {Hwc2::PerFrameMetadataKey::WHITE_POINT_X, |
| 903 | mHdrMetadata.smpte2086.whitePoint.x}, |
| 904 | {Hwc2::PerFrameMetadataKey::WHITE_POINT_Y, |
| 905 | mHdrMetadata.smpte2086.whitePoint.y}, |
| 906 | {Hwc2::PerFrameMetadataKey::MAX_LUMINANCE, |
| 907 | mHdrMetadata.smpte2086.maxLuminance}, |
| 908 | {Hwc2::PerFrameMetadataKey::MIN_LUMINANCE, |
| 909 | mHdrMetadata.smpte2086.minLuminance}}); |
Peiyong Lin | 0ac5f4e | 2018-04-19 22:06:34 -0700 | [diff] [blame] | 910 | } |
| 911 | |
| 912 | if (validTypes & HdrMetadata::CTA861_3) { |
| 913 | perFrameMetadatas.insert(perFrameMetadatas.end(), |
| 914 | {{Hwc2::PerFrameMetadataKey::MAX_CONTENT_LIGHT_LEVEL, |
Valerie Hau | e9e843a | 2018-12-18 13:39:23 -0800 | [diff] [blame] | 915 | mHdrMetadata.cta8613.maxContentLightLevel}, |
| 916 | {Hwc2::PerFrameMetadataKey::MAX_FRAME_AVERAGE_LIGHT_LEVEL, |
| 917 | mHdrMetadata.cta8613.maxFrameAverageLightLevel}}); |
Peiyong Lin | 0ac5f4e | 2018-04-19 22:06:34 -0700 | [diff] [blame] | 918 | } |
| 919 | |
Alec Mouri | 66d8348 | 2022-01-11 11:14:44 -0800 | [diff] [blame] | 920 | const Error error = static_cast<Error>( |
| 921 | mComposer.setLayerPerFrameMetadata(mDisplay->getId(), mId, perFrameMetadatas)); |
| 922 | if (error != Error::NONE) { |
| 923 | return error; |
| 924 | } |
Valerie Hau | e9e843a | 2018-12-18 13:39:23 -0800 | [diff] [blame] | 925 | |
Alec Mouri | 66d8348 | 2022-01-11 11:14:44 -0800 | [diff] [blame] | 926 | std::vector<Hwc2::PerFrameMetadataBlob> perFrameMetadataBlobs; |
Valerie Hau | e9e843a | 2018-12-18 13:39:23 -0800 | [diff] [blame] | 927 | if (validTypes & HdrMetadata::HDR10PLUS) { |
Yichi Chen | 1d5146d | 2020-06-12 18:50:11 +0800 | [diff] [blame] | 928 | if (CC_UNLIKELY(mHdrMetadata.hdr10plus.size() == 0)) { |
| 929 | return Error::BAD_PARAMETER; |
| 930 | } |
| 931 | |
Valerie Hau | e9e843a | 2018-12-18 13:39:23 -0800 | [diff] [blame] | 932 | perFrameMetadataBlobs.push_back( |
| 933 | {Hwc2::PerFrameMetadataKey::HDR10_PLUS_SEI, mHdrMetadata.hdr10plus}); |
Valerie Hau | e9e843a | 2018-12-18 13:39:23 -0800 | [diff] [blame] | 934 | } |
Alec Mouri | 66d8348 | 2022-01-11 11:14:44 -0800 | [diff] [blame] | 935 | |
| 936 | return static_cast<Error>( |
| 937 | mComposer.setLayerPerFrameMetadataBlobs(mDisplay->getId(), mId, perFrameMetadataBlobs)); |
Courtney Goeltzenleuchter | f9c98e5 | 2018-02-12 07:23:17 -0700 | [diff] [blame] | 938 | } |
| 939 | |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 940 | Error Layer::setDisplayFrame(const Rect& frame) |
| 941 | { |
Lloyd Pique | a516c00 | 2021-05-07 14:36:58 -0700 | [diff] [blame] | 942 | if (CC_UNLIKELY(!mDisplay)) { |
| 943 | return Error::BAD_DISPLAY; |
| 944 | } |
| 945 | |
Chia-I Wu | cd8d7f0 | 2016-11-16 11:02:31 +0800 | [diff] [blame] | 946 | Hwc2::IComposerClient::Rect hwcRect{frame.left, frame.top, |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 947 | frame.right, frame.bottom}; |
Lloyd Pique | a516c00 | 2021-05-07 14:36:58 -0700 | [diff] [blame] | 948 | auto intError = mComposer.setLayerDisplayFrame(mDisplay->getId(), mId, hwcRect); |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 949 | return static_cast<Error>(intError); |
| 950 | } |
| 951 | |
| 952 | Error Layer::setPlaneAlpha(float alpha) |
| 953 | { |
Lloyd Pique | a516c00 | 2021-05-07 14:36:58 -0700 | [diff] [blame] | 954 | if (CC_UNLIKELY(!mDisplay)) { |
| 955 | return Error::BAD_DISPLAY; |
| 956 | } |
| 957 | |
| 958 | auto intError = mComposer.setLayerPlaneAlpha(mDisplay->getId(), mId, alpha); |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 959 | return static_cast<Error>(intError); |
| 960 | } |
| 961 | |
| 962 | Error Layer::setSidebandStream(const native_handle_t* stream) |
| 963 | { |
Lloyd Pique | a516c00 | 2021-05-07 14:36:58 -0700 | [diff] [blame] | 964 | if (CC_UNLIKELY(!mDisplay)) { |
| 965 | return Error::BAD_DISPLAY; |
| 966 | } |
| 967 | |
Ady Abraham | de549d4 | 2022-01-26 19:19:17 -0800 | [diff] [blame] | 968 | if (mCapabilities.count(AidlCapability::SIDEBAND_STREAM) == 0) { |
Dan Stoza | 09e7a27 | 2016-04-14 12:31:01 -0700 | [diff] [blame] | 969 | ALOGE("Attempted to call setSidebandStream without checking that the " |
| 970 | "device supports sideband streams"); |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 971 | return Error::UNSUPPORTED; |
Dan Stoza | 09e7a27 | 2016-04-14 12:31:01 -0700 | [diff] [blame] | 972 | } |
Lloyd Pique | a516c00 | 2021-05-07 14:36:58 -0700 | [diff] [blame] | 973 | auto intError = mComposer.setLayerSidebandStream(mDisplay->getId(), mId, stream); |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 974 | return static_cast<Error>(intError); |
| 975 | } |
| 976 | |
| 977 | Error Layer::setSourceCrop(const FloatRect& crop) |
| 978 | { |
Lloyd Pique | a516c00 | 2021-05-07 14:36:58 -0700 | [diff] [blame] | 979 | if (CC_UNLIKELY(!mDisplay)) { |
| 980 | return Error::BAD_DISPLAY; |
| 981 | } |
| 982 | |
Chia-I Wu | cd8d7f0 | 2016-11-16 11:02:31 +0800 | [diff] [blame] | 983 | Hwc2::IComposerClient::FRect hwcRect{ |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 984 | crop.left, crop.top, crop.right, crop.bottom}; |
Lloyd Pique | a516c00 | 2021-05-07 14:36:58 -0700 | [diff] [blame] | 985 | auto intError = mComposer.setLayerSourceCrop(mDisplay->getId(), mId, hwcRect); |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 986 | return static_cast<Error>(intError); |
| 987 | } |
| 988 | |
| 989 | Error Layer::setTransform(Transform transform) |
| 990 | { |
Lloyd Pique | a516c00 | 2021-05-07 14:36:58 -0700 | [diff] [blame] | 991 | if (CC_UNLIKELY(!mDisplay)) { |
| 992 | return Error::BAD_DISPLAY; |
| 993 | } |
| 994 | |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 995 | auto intTransform = static_cast<Hwc2::Transform>(transform); |
Lloyd Pique | a516c00 | 2021-05-07 14:36:58 -0700 | [diff] [blame] | 996 | auto intError = mComposer.setLayerTransform(mDisplay->getId(), mId, intTransform); |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 997 | return static_cast<Error>(intError); |
| 998 | } |
| 999 | |
| 1000 | Error Layer::setVisibleRegion(const Region& region) |
| 1001 | { |
Lloyd Pique | a516c00 | 2021-05-07 14:36:58 -0700 | [diff] [blame] | 1002 | if (CC_UNLIKELY(!mDisplay)) { |
| 1003 | return Error::BAD_DISPLAY; |
| 1004 | } |
| 1005 | |
Yichi Chen | 8366f56 | 2019-03-25 19:44:06 +0800 | [diff] [blame] | 1006 | if (region.isRect() && mVisibleRegion.isRect() && |
| 1007 | (region.getBounds() == mVisibleRegion.getBounds())) { |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 1008 | return Error::NONE; |
Yichi Chen | 8366f56 | 2019-03-25 19:44:06 +0800 | [diff] [blame] | 1009 | } |
| 1010 | mVisibleRegion = region; |
Leon Scroggins III | 4459bf4 | 2022-01-04 13:58:26 -0500 | [diff] [blame] | 1011 | const auto hwcRects = convertRegionToHwcRects(region); |
Lloyd Pique | a516c00 | 2021-05-07 14:36:58 -0700 | [diff] [blame] | 1012 | auto intError = mComposer.setLayerVisibleRegion(mDisplay->getId(), mId, hwcRects); |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 1013 | return static_cast<Error>(intError); |
| 1014 | } |
| 1015 | |
| 1016 | Error Layer::setZOrder(uint32_t z) |
| 1017 | { |
Lloyd Pique | a516c00 | 2021-05-07 14:36:58 -0700 | [diff] [blame] | 1018 | if (CC_UNLIKELY(!mDisplay)) { |
| 1019 | return Error::BAD_DISPLAY; |
| 1020 | } |
| 1021 | |
| 1022 | auto intError = mComposer.setLayerZOrder(mDisplay->getId(), mId, z); |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 1023 | return static_cast<Error>(intError); |
| 1024 | } |
| 1025 | |
Peiyong Lin | 698147a | 2018-09-14 13:27:18 -0700 | [diff] [blame] | 1026 | // Composer HAL 2.3 |
| 1027 | Error Layer::setColorTransform(const android::mat4& matrix) { |
Lloyd Pique | a516c00 | 2021-05-07 14:36:58 -0700 | [diff] [blame] | 1028 | if (CC_UNLIKELY(!mDisplay)) { |
| 1029 | return Error::BAD_DISPLAY; |
| 1030 | } |
| 1031 | |
Peiyong Lin | 698147a | 2018-09-14 13:27:18 -0700 | [diff] [blame] | 1032 | if (matrix == mColorMatrix) { |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 1033 | return Error::NONE; |
Peiyong Lin | 698147a | 2018-09-14 13:27:18 -0700 | [diff] [blame] | 1034 | } |
Lloyd Pique | a516c00 | 2021-05-07 14:36:58 -0700 | [diff] [blame] | 1035 | auto intError = mComposer.setLayerColorTransform(mDisplay->getId(), mId, matrix.asArray()); |
Peiyong Lin | 04d2587 | 2019-04-18 10:26:19 -0700 | [diff] [blame] | 1036 | Error error = static_cast<Error>(intError); |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 1037 | if (error != Error::NONE) { |
Peiyong Lin | 04d2587 | 2019-04-18 10:26:19 -0700 | [diff] [blame] | 1038 | return error; |
| 1039 | } |
| 1040 | mColorMatrix = matrix; |
| 1041 | return error; |
Peiyong Lin | 698147a | 2018-09-14 13:27:18 -0700 | [diff] [blame] | 1042 | } |
Lloyd Pique | 35d5824 | 2018-12-18 16:33:25 -0800 | [diff] [blame] | 1043 | |
Lloyd Pique | 4603f3c | 2020-02-11 12:06:56 -0800 | [diff] [blame] | 1044 | // Composer HAL 2.4 |
| 1045 | Error Layer::setLayerGenericMetadata(const std::string& name, bool mandatory, |
| 1046 | const std::vector<uint8_t>& value) { |
Lloyd Pique | a516c00 | 2021-05-07 14:36:58 -0700 | [diff] [blame] | 1047 | if (CC_UNLIKELY(!mDisplay)) { |
| 1048 | return Error::BAD_DISPLAY; |
| 1049 | } |
| 1050 | |
| 1051 | auto intError = |
| 1052 | mComposer.setLayerGenericMetadata(mDisplay->getId(), mId, name, mandatory, value); |
Lloyd Pique | 4603f3c | 2020-02-11 12:06:56 -0800 | [diff] [blame] | 1053 | return static_cast<Error>(intError); |
| 1054 | } |
| 1055 | |
Alec Mouri | cdf6cbc | 2021-11-01 17:21:15 -0700 | [diff] [blame] | 1056 | // AIDL HAL |
Alec Mouri | 6da0e27 | 2022-02-07 12:45:57 -0800 | [diff] [blame] | 1057 | Error Layer::setBrightness(float brightness) { |
Alec Mouri | cdf6cbc | 2021-11-01 17:21:15 -0700 | [diff] [blame] | 1058 | if (CC_UNLIKELY(!mDisplay)) { |
| 1059 | return Error::BAD_DISPLAY; |
| 1060 | } |
| 1061 | |
Alec Mouri | 6da0e27 | 2022-02-07 12:45:57 -0800 | [diff] [blame] | 1062 | auto intError = mComposer.setLayerBrightness(mDisplay->getId(), mId, brightness); |
Alec Mouri | cdf6cbc | 2021-11-01 17:21:15 -0700 | [diff] [blame] | 1063 | return static_cast<Error>(intError); |
| 1064 | } |
| 1065 | |
Leon Scroggins III | d77d316 | 2022-01-05 10:42:28 -0500 | [diff] [blame] | 1066 | Error Layer::setBlockingRegion(const Region& region) { |
| 1067 | if (CC_UNLIKELY(!mDisplay)) { |
| 1068 | return Error::BAD_DISPLAY; |
| 1069 | } |
| 1070 | |
| 1071 | if (region.isRect() && mBlockingRegion.isRect() && |
| 1072 | (region.getBounds() == mBlockingRegion.getBounds())) { |
| 1073 | return Error::NONE; |
| 1074 | } |
| 1075 | mBlockingRegion = region; |
| 1076 | const auto hwcRects = convertRegionToHwcRects(region); |
| 1077 | const auto intError = mComposer.setLayerBlockingRegion(mDisplay->getId(), mId, hwcRects); |
| 1078 | return static_cast<Error>(intError); |
| 1079 | } |
| 1080 | |
Sally Qi | 0abc4a5 | 2024-09-26 16:13:06 -0700 | [diff] [blame] | 1081 | Error Layer::setLuts(aidl::android::hardware::graphics::composer3::Luts& luts) { |
Sally Qi | 11dcd58 | 2024-08-16 18:11:27 -0700 | [diff] [blame] | 1082 | if (CC_UNLIKELY(!mDisplay)) { |
| 1083 | return Error::BAD_DISPLAY; |
| 1084 | } |
| 1085 | const auto intError = mComposer.setLayerLuts(mDisplay->getId(), mId, luts); |
| 1086 | return static_cast<Error>(intError); |
| 1087 | } |
| 1088 | |
Lloyd Pique | 35d5824 | 2018-12-18 16:33:25 -0800 | [diff] [blame] | 1089 | } // namespace impl |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 1090 | } // namespace HWC2 |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 1091 | } // namespace android |
Ady Abraham | b0dbdaa | 2020-01-06 16:19:42 -0800 | [diff] [blame] | 1092 | |
| 1093 | // TODO(b/129481165): remove the #pragma below and fix conversion issues |
| 1094 | #pragma clang diagnostic pop // ignored "-Wconversion" |