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 | 95f669a | 2024-08-27 11:31:42 -0700 | [diff] [blame^] | 612 | Error Display::getRequestedLuts(LayerLuts* outLuts, |
| 613 | LutFileDescriptorMapper& lutFileDescriptorMapper) { |
| 614 | std::vector<Hwc2::Layer> layerIds; |
| 615 | std::vector<DisplayLuts::LayerLut> tmpLuts; |
| 616 | const auto error = static_cast<Error>(mComposer.getRequestedLuts(mId, &layerIds, &tmpLuts)); |
| 617 | if (error != Error::NONE) { |
| 618 | return error; |
| 619 | } |
| 620 | |
| 621 | uint32_t numElements = layerIds.size(); |
| 622 | outLuts->clear(); |
| 623 | for (uint32_t i = 0; i < numElements; ++i) { |
| 624 | auto layer = getLayerById(layerIds[i]); |
| 625 | if (layer) { |
| 626 | auto& layerLut = tmpLuts[i]; |
| 627 | outLuts->emplace_or_replace(layer.get(), layerLut.lut.lutProperties); |
| 628 | lutFileDescriptorMapper.emplace_or_replace(layer.get(), |
| 629 | ndk::ScopedFileDescriptor( |
| 630 | layerLut.lut.pfd.release())); |
Sally Qi | 492cec3 | 2024-06-28 14:34:47 -0700 | [diff] [blame] | 631 | } |
| 632 | } |
Sally Qi | 95f669a | 2024-08-27 11:31:42 -0700 | [diff] [blame^] | 633 | |
| 634 | return Error::NONE; |
Sally Qi | 492cec3 | 2024-06-28 14:34:47 -0700 | [diff] [blame] | 635 | } |
| 636 | |
Leon Scroggins III | e7c51c6 | 2022-02-01 15:53:54 -0500 | [diff] [blame] | 637 | Error Display::getDisplayDecorationSupport( |
| 638 | std::optional<aidl::android::hardware::graphics::common::DisplayDecorationSupport>* |
| 639 | support) { |
| 640 | const auto error = mComposer.getDisplayDecorationSupport(mId, support); |
| 641 | return static_cast<Error>(error); |
| 642 | } |
| 643 | |
ramindani | 32cf060 | 2022-03-02 02:30:29 +0000 | [diff] [blame] | 644 | Error Display::setIdleTimerEnabled(std::chrono::milliseconds timeout) { |
| 645 | const auto error = mComposer.setIdleTimerEnabled(mId, timeout); |
| 646 | return static_cast<Error>(error); |
| 647 | } |
| 648 | |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 649 | // For use by Device |
| 650 | |
Steven Thomas | 94e35b9 | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 651 | void Display::setConnected(bool connected) { |
Steven Thomas | b6c6ad4 | 2018-01-29 12:22:00 -0800 | [diff] [blame] | 652 | if (!mIsConnected && connected) { |
Steven Thomas | 94e35b9 | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 653 | mComposer.setClientTargetSlotCount(mId); |
Steven Thomas | 94e35b9 | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 654 | } |
| 655 | mIsConnected = connected; |
| 656 | } |
| 657 | |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 658 | // Other Display methods |
| 659 | |
Lloyd Pique | a516c00 | 2021-05-07 14:36:58 -0700 | [diff] [blame] | 660 | std::shared_ptr<HWC2::Layer> Display::getLayerById(HWLayerId id) const { |
| 661 | auto it = mLayers.find(id); |
| 662 | return it != mLayers.end() ? it->second.lock() : nullptr; |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 663 | } |
HyunKyoung | a264a35 | 2024-04-24 18:51:33 +0900 | [diff] [blame] | 664 | |
| 665 | void Display::loadDisplayCapabilities() { |
| 666 | std::call_once(mDisplayCapabilityQueryFlag, [this]() { |
| 667 | std::vector<DisplayCapability> tmpCapabilities; |
| 668 | auto error = |
| 669 | static_cast<Error>(mComposer.getDisplayCapabilities(mId, &tmpCapabilities)); |
| 670 | if (error == Error::NONE) { |
| 671 | std::scoped_lock lock(mDisplayCapabilitiesMutex); |
| 672 | mDisplayCapabilities.emplace(); |
| 673 | for (auto capability : tmpCapabilities) { |
| 674 | mDisplayCapabilities->emplace(capability); |
| 675 | } |
| 676 | } else if (error == Error::UNSUPPORTED) { |
| 677 | std::scoped_lock lock(mDisplayCapabilitiesMutex); |
| 678 | mDisplayCapabilities.emplace(); |
| 679 | if (mCapabilities.count(AidlCapability::SKIP_CLIENT_COLOR_TRANSFORM)) { |
| 680 | mDisplayCapabilities->emplace(DisplayCapability::SKIP_CLIENT_COLOR_TRANSFORM); |
| 681 | } |
| 682 | bool dozeSupport = false; |
| 683 | error = static_cast<Error>(mComposer.getDozeSupport(mId, &dozeSupport)); |
| 684 | if (error == Error::NONE && dozeSupport) { |
| 685 | mDisplayCapabilities->emplace(DisplayCapability::DOZE); |
| 686 | } |
| 687 | } |
| 688 | }); |
| 689 | } |
Lucas Berthou | 8d0a0c4 | 2024-08-27 14:32:31 +0000 | [diff] [blame] | 690 | |
| 691 | void Display::setPhysicalSizeInMm(std::optional<ui::Size> size) { |
| 692 | mPhysicalSize = size; |
| 693 | } |
| 694 | |
Ana Krulec | 4593b69 | 2019-01-11 22:07:25 -0800 | [diff] [blame] | 695 | } // namespace impl |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 696 | |
| 697 | // Layer methods |
| 698 | |
Leon Scroggins III | 4459bf4 | 2022-01-04 13:58:26 -0500 | [diff] [blame] | 699 | namespace { |
| 700 | std::vector<Hwc2::IComposerClient::Rect> convertRegionToHwcRects(const Region& region) { |
| 701 | size_t rectCount = 0; |
| 702 | Rect const* rectArray = region.getArray(&rectCount); |
| 703 | |
| 704 | std::vector<Hwc2::IComposerClient::Rect> hwcRects; |
| 705 | hwcRects.reserve(rectCount); |
| 706 | for (size_t rect = 0; rect < rectCount; ++rect) { |
| 707 | hwcRects.push_back({rectArray[rect].left, rectArray[rect].top, rectArray[rect].right, |
| 708 | rectArray[rect].bottom}); |
| 709 | } |
| 710 | return hwcRects; |
| 711 | } |
| 712 | } // namespace |
| 713 | |
Lloyd Pique | 35d5824 | 2018-12-18 16:33:25 -0800 | [diff] [blame] | 714 | Layer::~Layer() = default; |
| 715 | |
| 716 | namespace impl { |
| 717 | |
Ady Abraham | de549d4 | 2022-01-26 19:19:17 -0800 | [diff] [blame] | 718 | Layer::Layer(android::Hwc2::Composer& composer, |
| 719 | const std::unordered_set<AidlCapability>& capabilities, HWC2::Display& display, |
| 720 | HWLayerId layerId) |
Lloyd Pique | 4603f3c | 2020-02-11 12:06:56 -0800 | [diff] [blame] | 721 | : mComposer(composer), |
| 722 | mCapabilities(capabilities), |
Lloyd Pique | a516c00 | 2021-05-07 14:36:58 -0700 | [diff] [blame] | 723 | mDisplay(&display), |
Lloyd Pique | 4603f3c | 2020-02-11 12:06:56 -0800 | [diff] [blame] | 724 | mId(layerId), |
| 725 | mColorMatrix(android::mat4()) { |
Lloyd Pique | a516c00 | 2021-05-07 14:36:58 -0700 | [diff] [blame] | 726 | ALOGV("Created layer %" PRIu64 " on display %" PRIu64, layerId, display.getId()); |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 727 | } |
| 728 | |
| 729 | Layer::~Layer() |
| 730 | { |
Lloyd Pique | a516c00 | 2021-05-07 14:36:58 -0700 | [diff] [blame] | 731 | onOwningDisplayDestroyed(); |
| 732 | } |
| 733 | |
| 734 | void Layer::onOwningDisplayDestroyed() { |
| 735 | // Note: onOwningDisplayDestroyed() may be called to perform cleanup by |
| 736 | // either the Layer dtor or by the Display dtor and must be safe to call |
| 737 | // from either path. In particular, the call to Display::onLayerDestroyed() |
| 738 | // is expected to be safe to do, |
| 739 | |
| 740 | if (CC_UNLIKELY(!mDisplay)) { |
| 741 | return; |
| 742 | } |
| 743 | |
| 744 | mDisplay->onLayerDestroyed(mId); |
| 745 | |
| 746 | // Note: If the HWC display was actually disconnected, these calls are will |
| 747 | // return an error. We always make them as there may be other reasons for |
| 748 | // the HWC2::Display to be destroyed. |
| 749 | auto intError = mComposer.destroyLayer(mDisplay->getId(), mId); |
Steven Thomas | 94e35b9 | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 750 | auto error = static_cast<Error>(intError); |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 751 | ALOGE_IF(error != Error::NONE, |
| 752 | "destroyLayer(%" PRIu64 ", %" PRIu64 ")" |
| 753 | " failed: %s (%d)", |
Lloyd Pique | a516c00 | 2021-05-07 14:36:58 -0700 | [diff] [blame] | 754 | mDisplay->getId(), mId, to_string(error).c_str(), intError); |
| 755 | |
| 756 | mDisplay = nullptr; |
Steven Thomas | 94e35b9 | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 757 | } |
| 758 | |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 759 | Error Layer::setCursorPosition(int32_t x, int32_t y) |
| 760 | { |
Lloyd Pique | a516c00 | 2021-05-07 14:36:58 -0700 | [diff] [blame] | 761 | if (CC_UNLIKELY(!mDisplay)) { |
| 762 | return Error::BAD_DISPLAY; |
| 763 | } |
| 764 | |
| 765 | auto intError = mComposer.setCursorPosition(mDisplay->getId(), mId, x, y); |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 766 | return static_cast<Error>(intError); |
| 767 | } |
| 768 | |
Daniel Nicoara | 1f42e3a | 2017-04-10 13:27:32 -0400 | [diff] [blame] | 769 | Error Layer::setBuffer(uint32_t slot, const sp<GraphicBuffer>& buffer, |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 770 | const sp<Fence>& acquireFence) |
| 771 | { |
Lloyd Pique | a516c00 | 2021-05-07 14:36:58 -0700 | [diff] [blame] | 772 | if (CC_UNLIKELY(!mDisplay)) { |
| 773 | return Error::BAD_DISPLAY; |
| 774 | } |
| 775 | |
Yichi Chen | 8366f56 | 2019-03-25 19:44:06 +0800 | [diff] [blame] | 776 | if (buffer == nullptr && mBufferSlot == slot) { |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 777 | return Error::NONE; |
Yichi Chen | 8366f56 | 2019-03-25 19:44:06 +0800 | [diff] [blame] | 778 | } |
| 779 | mBufferSlot = slot; |
| 780 | |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 781 | int32_t fenceFd = acquireFence->dup(); |
Lloyd Pique | a516c00 | 2021-05-07 14:36:58 -0700 | [diff] [blame] | 782 | auto intError = mComposer.setLayerBuffer(mDisplay->getId(), mId, slot, buffer, fenceFd); |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 783 | return static_cast<Error>(intError); |
| 784 | } |
| 785 | |
Brian Lindahl | b158a5c | 2022-12-15 15:21:13 -0700 | [diff] [blame] | 786 | Error Layer::setBufferSlotsToClear(const std::vector<uint32_t>& slotsToClear, |
| 787 | uint32_t activeBufferSlot) { |
Brian Lindahl | 90553da | 2022-12-06 13:36:30 -0700 | [diff] [blame] | 788 | if (CC_UNLIKELY(!mDisplay)) { |
| 789 | return Error::BAD_DISPLAY; |
| 790 | } |
Brian Lindahl | b158a5c | 2022-12-15 15:21:13 -0700 | [diff] [blame] | 791 | auto intError = mComposer.setLayerBufferSlotsToClear(mDisplay->getId(), mId, slotsToClear, |
| 792 | activeBufferSlot); |
Brian Lindahl | 90553da | 2022-12-06 13:36:30 -0700 | [diff] [blame] | 793 | return static_cast<Error>(intError); |
| 794 | } |
| 795 | |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 796 | Error Layer::setSurfaceDamage(const Region& damage) |
| 797 | { |
Lloyd Pique | a516c00 | 2021-05-07 14:36:58 -0700 | [diff] [blame] | 798 | if (CC_UNLIKELY(!mDisplay)) { |
| 799 | return Error::BAD_DISPLAY; |
| 800 | } |
| 801 | |
Yichi Chen | 8366f56 | 2019-03-25 19:44:06 +0800 | [diff] [blame] | 802 | if (damage.isRect() && mDamageRegion.isRect() && |
| 803 | (damage.getBounds() == mDamageRegion.getBounds())) { |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 804 | return Error::NONE; |
Yichi Chen | 8366f56 | 2019-03-25 19:44:06 +0800 | [diff] [blame] | 805 | } |
| 806 | mDamageRegion = damage; |
| 807 | |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 808 | // We encode default full-screen damage as INVALID_RECT upstream, but as 0 |
| 809 | // rects for HWC |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 810 | Hwc2::Error intError = Hwc2::Error::NONE; |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 811 | if (damage.isRect() && damage.getBounds() == Rect::INVALID_RECT) { |
Lloyd Pique | a516c00 | 2021-05-07 14:36:58 -0700 | [diff] [blame] | 812 | intError = mComposer.setLayerSurfaceDamage(mDisplay->getId(), mId, |
| 813 | std::vector<Hwc2::IComposerClient::Rect>()); |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 814 | } else { |
Leon Scroggins III | 4459bf4 | 2022-01-04 13:58:26 -0500 | [diff] [blame] | 815 | const auto hwcRects = convertRegionToHwcRects(damage); |
Lloyd Pique | a516c00 | 2021-05-07 14:36:58 -0700 | [diff] [blame] | 816 | intError = mComposer.setLayerSurfaceDamage(mDisplay->getId(), mId, hwcRects); |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 817 | } |
| 818 | |
| 819 | return static_cast<Error>(intError); |
| 820 | } |
| 821 | |
| 822 | Error Layer::setBlendMode(BlendMode mode) |
| 823 | { |
Lloyd Pique | a516c00 | 2021-05-07 14:36:58 -0700 | [diff] [blame] | 824 | if (CC_UNLIKELY(!mDisplay)) { |
| 825 | return Error::BAD_DISPLAY; |
| 826 | } |
| 827 | |
| 828 | auto intError = mComposer.setLayerBlendMode(mDisplay->getId(), mId, mode); |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 829 | return static_cast<Error>(intError); |
| 830 | } |
| 831 | |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 832 | Error Layer::setColor(Color color) { |
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.setLayerColor(mDisplay->getId(), mId, color); |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 838 | return static_cast<Error>(intError); |
| 839 | } |
| 840 | |
| 841 | Error Layer::setCompositionType(Composition type) |
| 842 | { |
Lloyd Pique | a516c00 | 2021-05-07 14:36:58 -0700 | [diff] [blame] | 843 | if (CC_UNLIKELY(!mDisplay)) { |
| 844 | return Error::BAD_DISPLAY; |
| 845 | } |
| 846 | |
| 847 | auto intError = mComposer.setLayerCompositionType(mDisplay->getId(), mId, type); |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 848 | return static_cast<Error>(intError); |
| 849 | } |
| 850 | |
Peiyong Lin | 34beb7a | 2018-03-28 11:57:12 -0700 | [diff] [blame] | 851 | Error Layer::setDataspace(Dataspace dataspace) |
Dan Stoza | 5df2a86 | 2016-03-24 16:19:37 -0700 | [diff] [blame] | 852 | { |
Lloyd Pique | a516c00 | 2021-05-07 14:36:58 -0700 | [diff] [blame] | 853 | if (CC_UNLIKELY(!mDisplay)) { |
| 854 | return Error::BAD_DISPLAY; |
| 855 | } |
| 856 | |
Courtney Goeltzenleuchter | c988ee4 | 2017-05-31 17:56:46 -0600 | [diff] [blame] | 857 | if (dataspace == mDataSpace) { |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 858 | return Error::NONE; |
Courtney Goeltzenleuchter | c988ee4 | 2017-05-31 17:56:46 -0600 | [diff] [blame] | 859 | } |
| 860 | mDataSpace = dataspace; |
Lloyd Pique | a516c00 | 2021-05-07 14:36:58 -0700 | [diff] [blame] | 861 | auto intError = mComposer.setLayerDataspace(mDisplay->getId(), mId, mDataSpace); |
Dan Stoza | 5df2a86 | 2016-03-24 16:19:37 -0700 | [diff] [blame] | 862 | return static_cast<Error>(intError); |
| 863 | } |
| 864 | |
Peiyong Lin | 0ac5f4e | 2018-04-19 22:06:34 -0700 | [diff] [blame] | 865 | Error Layer::setPerFrameMetadata(const int32_t supportedPerFrameMetadata, |
| 866 | const android::HdrMetadata& metadata) |
| 867 | { |
Lloyd Pique | a516c00 | 2021-05-07 14:36:58 -0700 | [diff] [blame] | 868 | if (CC_UNLIKELY(!mDisplay)) { |
| 869 | return Error::BAD_DISPLAY; |
| 870 | } |
| 871 | |
Courtney Goeltzenleuchter | f9c98e5 | 2018-02-12 07:23:17 -0700 | [diff] [blame] | 872 | if (metadata == mHdrMetadata) { |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 873 | return Error::NONE; |
Courtney Goeltzenleuchter | f9c98e5 | 2018-02-12 07:23:17 -0700 | [diff] [blame] | 874 | } |
| 875 | |
| 876 | mHdrMetadata = metadata; |
Peiyong Lin | 0ac5f4e | 2018-04-19 22:06:34 -0700 | [diff] [blame] | 877 | int validTypes = mHdrMetadata.validTypes & supportedPerFrameMetadata; |
| 878 | std::vector<Hwc2::PerFrameMetadata> perFrameMetadatas; |
| 879 | if (validTypes & HdrMetadata::SMPTE2086) { |
| 880 | perFrameMetadatas.insert(perFrameMetadatas.end(), |
| 881 | {{Hwc2::PerFrameMetadataKey::DISPLAY_RED_PRIMARY_X, |
Valerie Hau | e9e843a | 2018-12-18 13:39:23 -0800 | [diff] [blame] | 882 | mHdrMetadata.smpte2086.displayPrimaryRed.x}, |
| 883 | {Hwc2::PerFrameMetadataKey::DISPLAY_RED_PRIMARY_Y, |
| 884 | mHdrMetadata.smpte2086.displayPrimaryRed.y}, |
| 885 | {Hwc2::PerFrameMetadataKey::DISPLAY_GREEN_PRIMARY_X, |
| 886 | mHdrMetadata.smpte2086.displayPrimaryGreen.x}, |
| 887 | {Hwc2::PerFrameMetadataKey::DISPLAY_GREEN_PRIMARY_Y, |
| 888 | mHdrMetadata.smpte2086.displayPrimaryGreen.y}, |
| 889 | {Hwc2::PerFrameMetadataKey::DISPLAY_BLUE_PRIMARY_X, |
| 890 | mHdrMetadata.smpte2086.displayPrimaryBlue.x}, |
| 891 | {Hwc2::PerFrameMetadataKey::DISPLAY_BLUE_PRIMARY_Y, |
| 892 | mHdrMetadata.smpte2086.displayPrimaryBlue.y}, |
| 893 | {Hwc2::PerFrameMetadataKey::WHITE_POINT_X, |
| 894 | mHdrMetadata.smpte2086.whitePoint.x}, |
| 895 | {Hwc2::PerFrameMetadataKey::WHITE_POINT_Y, |
| 896 | mHdrMetadata.smpte2086.whitePoint.y}, |
| 897 | {Hwc2::PerFrameMetadataKey::MAX_LUMINANCE, |
| 898 | mHdrMetadata.smpte2086.maxLuminance}, |
| 899 | {Hwc2::PerFrameMetadataKey::MIN_LUMINANCE, |
| 900 | mHdrMetadata.smpte2086.minLuminance}}); |
Peiyong Lin | 0ac5f4e | 2018-04-19 22:06:34 -0700 | [diff] [blame] | 901 | } |
| 902 | |
| 903 | if (validTypes & HdrMetadata::CTA861_3) { |
| 904 | perFrameMetadatas.insert(perFrameMetadatas.end(), |
| 905 | {{Hwc2::PerFrameMetadataKey::MAX_CONTENT_LIGHT_LEVEL, |
Valerie Hau | e9e843a | 2018-12-18 13:39:23 -0800 | [diff] [blame] | 906 | mHdrMetadata.cta8613.maxContentLightLevel}, |
| 907 | {Hwc2::PerFrameMetadataKey::MAX_FRAME_AVERAGE_LIGHT_LEVEL, |
| 908 | mHdrMetadata.cta8613.maxFrameAverageLightLevel}}); |
Peiyong Lin | 0ac5f4e | 2018-04-19 22:06:34 -0700 | [diff] [blame] | 909 | } |
| 910 | |
Alec Mouri | 66d8348 | 2022-01-11 11:14:44 -0800 | [diff] [blame] | 911 | const Error error = static_cast<Error>( |
| 912 | mComposer.setLayerPerFrameMetadata(mDisplay->getId(), mId, perFrameMetadatas)); |
| 913 | if (error != Error::NONE) { |
| 914 | return error; |
| 915 | } |
Valerie Hau | e9e843a | 2018-12-18 13:39:23 -0800 | [diff] [blame] | 916 | |
Alec Mouri | 66d8348 | 2022-01-11 11:14:44 -0800 | [diff] [blame] | 917 | std::vector<Hwc2::PerFrameMetadataBlob> perFrameMetadataBlobs; |
Valerie Hau | e9e843a | 2018-12-18 13:39:23 -0800 | [diff] [blame] | 918 | if (validTypes & HdrMetadata::HDR10PLUS) { |
Yichi Chen | 1d5146d | 2020-06-12 18:50:11 +0800 | [diff] [blame] | 919 | if (CC_UNLIKELY(mHdrMetadata.hdr10plus.size() == 0)) { |
| 920 | return Error::BAD_PARAMETER; |
| 921 | } |
| 922 | |
Valerie Hau | e9e843a | 2018-12-18 13:39:23 -0800 | [diff] [blame] | 923 | perFrameMetadataBlobs.push_back( |
| 924 | {Hwc2::PerFrameMetadataKey::HDR10_PLUS_SEI, mHdrMetadata.hdr10plus}); |
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 | |
| 927 | return static_cast<Error>( |
| 928 | mComposer.setLayerPerFrameMetadataBlobs(mDisplay->getId(), mId, perFrameMetadataBlobs)); |
Courtney Goeltzenleuchter | f9c98e5 | 2018-02-12 07:23:17 -0700 | [diff] [blame] | 929 | } |
| 930 | |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 931 | Error Layer::setDisplayFrame(const Rect& frame) |
| 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 | |
Chia-I Wu | cd8d7f0 | 2016-11-16 11:02:31 +0800 | [diff] [blame] | 937 | Hwc2::IComposerClient::Rect hwcRect{frame.left, frame.top, |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 938 | frame.right, frame.bottom}; |
Lloyd Pique | a516c00 | 2021-05-07 14:36:58 -0700 | [diff] [blame] | 939 | auto intError = mComposer.setLayerDisplayFrame(mDisplay->getId(), mId, hwcRect); |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 940 | return static_cast<Error>(intError); |
| 941 | } |
| 942 | |
| 943 | Error Layer::setPlaneAlpha(float alpha) |
| 944 | { |
Lloyd Pique | a516c00 | 2021-05-07 14:36:58 -0700 | [diff] [blame] | 945 | if (CC_UNLIKELY(!mDisplay)) { |
| 946 | return Error::BAD_DISPLAY; |
| 947 | } |
| 948 | |
| 949 | auto intError = mComposer.setLayerPlaneAlpha(mDisplay->getId(), mId, alpha); |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 950 | return static_cast<Error>(intError); |
| 951 | } |
| 952 | |
| 953 | Error Layer::setSidebandStream(const native_handle_t* stream) |
| 954 | { |
Lloyd Pique | a516c00 | 2021-05-07 14:36:58 -0700 | [diff] [blame] | 955 | if (CC_UNLIKELY(!mDisplay)) { |
| 956 | return Error::BAD_DISPLAY; |
| 957 | } |
| 958 | |
Ady Abraham | de549d4 | 2022-01-26 19:19:17 -0800 | [diff] [blame] | 959 | if (mCapabilities.count(AidlCapability::SIDEBAND_STREAM) == 0) { |
Dan Stoza | 09e7a27 | 2016-04-14 12:31:01 -0700 | [diff] [blame] | 960 | ALOGE("Attempted to call setSidebandStream without checking that the " |
| 961 | "device supports sideband streams"); |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 962 | return Error::UNSUPPORTED; |
Dan Stoza | 09e7a27 | 2016-04-14 12:31:01 -0700 | [diff] [blame] | 963 | } |
Lloyd Pique | a516c00 | 2021-05-07 14:36:58 -0700 | [diff] [blame] | 964 | auto intError = mComposer.setLayerSidebandStream(mDisplay->getId(), mId, stream); |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 965 | return static_cast<Error>(intError); |
| 966 | } |
| 967 | |
| 968 | Error Layer::setSourceCrop(const FloatRect& crop) |
| 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 | cd8d7f0 | 2016-11-16 11:02:31 +0800 | [diff] [blame] | 974 | Hwc2::IComposerClient::FRect hwcRect{ |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 975 | crop.left, crop.top, crop.right, crop.bottom}; |
Lloyd Pique | a516c00 | 2021-05-07 14:36:58 -0700 | [diff] [blame] | 976 | auto intError = mComposer.setLayerSourceCrop(mDisplay->getId(), mId, hwcRect); |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 977 | return static_cast<Error>(intError); |
| 978 | } |
| 979 | |
| 980 | Error Layer::setTransform(Transform transform) |
| 981 | { |
Lloyd Pique | a516c00 | 2021-05-07 14:36:58 -0700 | [diff] [blame] | 982 | if (CC_UNLIKELY(!mDisplay)) { |
| 983 | return Error::BAD_DISPLAY; |
| 984 | } |
| 985 | |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 986 | auto intTransform = static_cast<Hwc2::Transform>(transform); |
Lloyd Pique | a516c00 | 2021-05-07 14:36:58 -0700 | [diff] [blame] | 987 | auto intError = mComposer.setLayerTransform(mDisplay->getId(), mId, intTransform); |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 988 | return static_cast<Error>(intError); |
| 989 | } |
| 990 | |
| 991 | Error Layer::setVisibleRegion(const Region& region) |
| 992 | { |
Lloyd Pique | a516c00 | 2021-05-07 14:36:58 -0700 | [diff] [blame] | 993 | if (CC_UNLIKELY(!mDisplay)) { |
| 994 | return Error::BAD_DISPLAY; |
| 995 | } |
| 996 | |
Yichi Chen | 8366f56 | 2019-03-25 19:44:06 +0800 | [diff] [blame] | 997 | if (region.isRect() && mVisibleRegion.isRect() && |
| 998 | (region.getBounds() == mVisibleRegion.getBounds())) { |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 999 | return Error::NONE; |
Yichi Chen | 8366f56 | 2019-03-25 19:44:06 +0800 | [diff] [blame] | 1000 | } |
| 1001 | mVisibleRegion = region; |
Leon Scroggins III | 4459bf4 | 2022-01-04 13:58:26 -0500 | [diff] [blame] | 1002 | const auto hwcRects = convertRegionToHwcRects(region); |
Lloyd Pique | a516c00 | 2021-05-07 14:36:58 -0700 | [diff] [blame] | 1003 | auto intError = mComposer.setLayerVisibleRegion(mDisplay->getId(), mId, hwcRects); |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 1004 | return static_cast<Error>(intError); |
| 1005 | } |
| 1006 | |
| 1007 | Error Layer::setZOrder(uint32_t z) |
| 1008 | { |
Lloyd Pique | a516c00 | 2021-05-07 14:36:58 -0700 | [diff] [blame] | 1009 | if (CC_UNLIKELY(!mDisplay)) { |
| 1010 | return Error::BAD_DISPLAY; |
| 1011 | } |
| 1012 | |
| 1013 | auto intError = mComposer.setLayerZOrder(mDisplay->getId(), mId, z); |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 1014 | return static_cast<Error>(intError); |
| 1015 | } |
| 1016 | |
Peiyong Lin | 698147a | 2018-09-14 13:27:18 -0700 | [diff] [blame] | 1017 | // Composer HAL 2.3 |
| 1018 | Error Layer::setColorTransform(const android::mat4& matrix) { |
Lloyd Pique | a516c00 | 2021-05-07 14:36:58 -0700 | [diff] [blame] | 1019 | if (CC_UNLIKELY(!mDisplay)) { |
| 1020 | return Error::BAD_DISPLAY; |
| 1021 | } |
| 1022 | |
Peiyong Lin | 698147a | 2018-09-14 13:27:18 -0700 | [diff] [blame] | 1023 | if (matrix == mColorMatrix) { |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 1024 | return Error::NONE; |
Peiyong Lin | 698147a | 2018-09-14 13:27:18 -0700 | [diff] [blame] | 1025 | } |
Lloyd Pique | a516c00 | 2021-05-07 14:36:58 -0700 | [diff] [blame] | 1026 | auto intError = mComposer.setLayerColorTransform(mDisplay->getId(), mId, matrix.asArray()); |
Peiyong Lin | 04d2587 | 2019-04-18 10:26:19 -0700 | [diff] [blame] | 1027 | Error error = static_cast<Error>(intError); |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 1028 | if (error != Error::NONE) { |
Peiyong Lin | 04d2587 | 2019-04-18 10:26:19 -0700 | [diff] [blame] | 1029 | return error; |
| 1030 | } |
| 1031 | mColorMatrix = matrix; |
| 1032 | return error; |
Peiyong Lin | 698147a | 2018-09-14 13:27:18 -0700 | [diff] [blame] | 1033 | } |
Lloyd Pique | 35d5824 | 2018-12-18 16:33:25 -0800 | [diff] [blame] | 1034 | |
Lloyd Pique | 4603f3c | 2020-02-11 12:06:56 -0800 | [diff] [blame] | 1035 | // Composer HAL 2.4 |
| 1036 | Error Layer::setLayerGenericMetadata(const std::string& name, bool mandatory, |
| 1037 | const std::vector<uint8_t>& value) { |
Lloyd Pique | a516c00 | 2021-05-07 14:36:58 -0700 | [diff] [blame] | 1038 | if (CC_UNLIKELY(!mDisplay)) { |
| 1039 | return Error::BAD_DISPLAY; |
| 1040 | } |
| 1041 | |
| 1042 | auto intError = |
| 1043 | mComposer.setLayerGenericMetadata(mDisplay->getId(), mId, name, mandatory, value); |
Lloyd Pique | 4603f3c | 2020-02-11 12:06:56 -0800 | [diff] [blame] | 1044 | return static_cast<Error>(intError); |
| 1045 | } |
| 1046 | |
Alec Mouri | cdf6cbc | 2021-11-01 17:21:15 -0700 | [diff] [blame] | 1047 | // AIDL HAL |
Alec Mouri | 6da0e27 | 2022-02-07 12:45:57 -0800 | [diff] [blame] | 1048 | Error Layer::setBrightness(float brightness) { |
Alec Mouri | cdf6cbc | 2021-11-01 17:21:15 -0700 | [diff] [blame] | 1049 | if (CC_UNLIKELY(!mDisplay)) { |
| 1050 | return Error::BAD_DISPLAY; |
| 1051 | } |
| 1052 | |
Alec Mouri | 6da0e27 | 2022-02-07 12:45:57 -0800 | [diff] [blame] | 1053 | auto intError = mComposer.setLayerBrightness(mDisplay->getId(), mId, brightness); |
Alec Mouri | cdf6cbc | 2021-11-01 17:21:15 -0700 | [diff] [blame] | 1054 | return static_cast<Error>(intError); |
| 1055 | } |
| 1056 | |
Leon Scroggins III | d77d316 | 2022-01-05 10:42:28 -0500 | [diff] [blame] | 1057 | Error Layer::setBlockingRegion(const Region& region) { |
| 1058 | if (CC_UNLIKELY(!mDisplay)) { |
| 1059 | return Error::BAD_DISPLAY; |
| 1060 | } |
| 1061 | |
| 1062 | if (region.isRect() && mBlockingRegion.isRect() && |
| 1063 | (region.getBounds() == mBlockingRegion.getBounds())) { |
| 1064 | return Error::NONE; |
| 1065 | } |
| 1066 | mBlockingRegion = region; |
| 1067 | const auto hwcRects = convertRegionToHwcRects(region); |
| 1068 | const auto intError = mComposer.setLayerBlockingRegion(mDisplay->getId(), mId, hwcRects); |
| 1069 | return static_cast<Error>(intError); |
| 1070 | } |
| 1071 | |
Sally Qi | 11dcd58 | 2024-08-16 18:11:27 -0700 | [diff] [blame] | 1072 | Error Layer::setLuts(std::vector<Lut>& luts) { |
| 1073 | if (CC_UNLIKELY(!mDisplay)) { |
| 1074 | return Error::BAD_DISPLAY; |
| 1075 | } |
| 1076 | const auto intError = mComposer.setLayerLuts(mDisplay->getId(), mId, luts); |
| 1077 | return static_cast<Error>(intError); |
| 1078 | } |
| 1079 | |
Lloyd Pique | 35d5824 | 2018-12-18 16:33:25 -0800 | [diff] [blame] | 1080 | } // namespace impl |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 1081 | } // namespace HWC2 |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 1082 | } // namespace android |
Ady Abraham | b0dbdaa | 2020-01-06 16:19:42 -0800 | [diff] [blame] | 1083 | |
| 1084 | // TODO(b/129481165): remove the #pragma below and fix conversion issues |
| 1085 | #pragma clang diagnostic pop // ignored "-Wconversion" |