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