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