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