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