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