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