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