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