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