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 | a516c00 | 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 | a516c00 | 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 | a516c00 | 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 | a516c00 | 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 | a516c00 | 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 | a516c00 | 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 | a516c00 | 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 | |
Ady Abraham | 27fbcc7 | 2021-09-20 14:54:57 -0700 | [diff] [blame] | 286 | bool Display::hasCapability(hal::DisplayCapability capability) const { |
| 287 | std::scoped_lock lock(mDisplayCapabilitiesMutex); |
| 288 | if (mDisplayCapabilities) { |
| 289 | return mDisplayCapabilities->count(capability) > 0; |
| 290 | } |
| 291 | |
| 292 | ALOGW("Can't query capability %d." |
| 293 | " Display Capabilities were not queried from HWC yet", |
| 294 | static_cast<int>(capability)); |
| 295 | |
| 296 | return false; |
| 297 | } |
| 298 | |
Peiyong Lin | ed531a3 | 2018-10-26 18:27:56 -0700 | [diff] [blame] | 299 | Error Display::supportsDoze(bool* outSupport) const { |
Ady Abraham | 27fbcc7 | 2021-09-20 14:54:57 -0700 | [diff] [blame] | 300 | *outSupport = hasCapability(DisplayCapability::DOZE); |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 301 | return Error::NONE; |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 302 | } |
| 303 | |
Peiyong Lin | 6266589 | 2018-04-16 11:07:44 -0700 | [diff] [blame] | 304 | Error Display::getHdrCapabilities(HdrCapabilities* outCapabilities) const |
Dan Stoza | 7d7ae73 | 2016-03-16 12:23:40 -0700 | [diff] [blame] | 305 | { |
Dan Stoza | 7d7ae73 | 2016-03-16 12:23:40 -0700 | [diff] [blame] | 306 | float maxLuminance = -1.0f; |
| 307 | float maxAverageLuminance = -1.0f; |
| 308 | float minLuminance = -1.0f; |
Peiyong Lin | 6266589 | 2018-04-16 11:07:44 -0700 | [diff] [blame] | 309 | std::vector<Hwc2::Hdr> types; |
| 310 | auto intError = mComposer.getHdrCapabilities(mId, &types, |
Chia-I Wu | 67e376d | 2016-12-19 11:36:22 +0800 | [diff] [blame] | 311 | &maxLuminance, &maxAverageLuminance, &minLuminance); |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 312 | auto error = static_cast<HWC2::Error>(intError); |
| 313 | |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 314 | if (error != Error::NONE) { |
Dan Stoza | 7d7ae73 | 2016-03-16 12:23:40 -0700 | [diff] [blame] | 315 | return error; |
| 316 | } |
| 317 | |
Peiyong Lin | 6266589 | 2018-04-16 11:07:44 -0700 | [diff] [blame] | 318 | *outCapabilities = HdrCapabilities(std::move(types), |
Dan Stoza | 7d7ae73 | 2016-03-16 12:23:40 -0700 | [diff] [blame] | 319 | maxLuminance, maxAverageLuminance, minLuminance); |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 320 | return Error::NONE; |
Dan Stoza | 7d7ae73 | 2016-03-16 12:23:40 -0700 | [diff] [blame] | 321 | } |
| 322 | |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 323 | Error Display::getDisplayedContentSamplingAttributes(hal::PixelFormat* outFormat, |
Kevin DuBois | 9c0a176 | 2018-10-16 13:32:31 -0700 | [diff] [blame] | 324 | Dataspace* outDataspace, |
| 325 | uint8_t* outComponentMask) const { |
| 326 | auto intError = mComposer.getDisplayedContentSamplingAttributes(mId, outFormat, outDataspace, |
| 327 | outComponentMask); |
| 328 | return static_cast<Error>(intError); |
| 329 | } |
| 330 | |
Kevin DuBois | 74e5377 | 2018-11-19 10:52:38 -0800 | [diff] [blame] | 331 | Error Display::setDisplayContentSamplingEnabled(bool enabled, uint8_t componentMask, |
| 332 | uint64_t maxFrames) const { |
| 333 | auto intError = |
| 334 | mComposer.setDisplayContentSamplingEnabled(mId, enabled, componentMask, maxFrames); |
| 335 | return static_cast<Error>(intError); |
| 336 | } |
| 337 | |
Kevin DuBois | 1d4249a | 2018-08-29 10:45:14 -0700 | [diff] [blame] | 338 | Error Display::getDisplayedContentSample(uint64_t maxFrames, uint64_t timestamp, |
| 339 | android::DisplayedFrameStats* outStats) const { |
| 340 | auto intError = mComposer.getDisplayedContentSample(mId, maxFrames, timestamp, outStats); |
| 341 | return static_cast<Error>(intError); |
| 342 | } |
| 343 | |
Lloyd Pique | 35d5824 | 2018-12-18 16:33:25 -0800 | [diff] [blame] | 344 | 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] | 345 | std::vector<Hwc2::Layer> layerIds; |
| 346 | std::vector<int> fenceFds; |
Steven Thomas | 94e35b9 | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 347 | auto intError = mComposer.getReleaseFences(mId, &layerIds, &fenceFds); |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 348 | auto error = static_cast<Error>(intError); |
| 349 | uint32_t numElements = layerIds.size(); |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 350 | if (error != Error::NONE) { |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 351 | return error; |
| 352 | } |
| 353 | |
Lloyd Pique | 35d5824 | 2018-12-18 16:33:25 -0800 | [diff] [blame] | 354 | std::unordered_map<HWC2::Layer*, sp<Fence>> releaseFences; |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 355 | releaseFences.reserve(numElements); |
| 356 | for (uint32_t element = 0; element < numElements; ++element) { |
| 357 | auto layer = getLayerById(layerIds[element]); |
| 358 | if (layer) { |
| 359 | sp<Fence> fence(new Fence(fenceFds[element])); |
Lloyd Pique | a516c00 | 2021-05-07 14:36:58 -0700 | [diff] [blame] | 360 | releaseFences.emplace(layer.get(), fence); |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 361 | } else { |
| 362 | ALOGE("getReleaseFences: invalid layer %" PRIu64 |
| 363 | " found on display %" PRIu64, layerIds[element], mId); |
Chia-I Wu | 5e74c65 | 2017-05-17 13:43:16 -0700 | [diff] [blame] | 364 | for (; element < numElements; ++element) { |
| 365 | close(fenceFds[element]); |
| 366 | } |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 367 | return Error::BAD_LAYER; |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 368 | } |
| 369 | } |
| 370 | |
| 371 | *outFences = std::move(releaseFences); |
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 | |
Fabien Sanglard | 11d0fc3 | 2016-12-01 15:43:01 -0800 | [diff] [blame] | 375 | Error Display::present(sp<Fence>* outPresentFence) |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 376 | { |
Naseer Ahmed | 847650b | 2016-06-17 11:14:25 -0400 | [diff] [blame] | 377 | int32_t presentFenceFd = -1; |
Steven Thomas | 94e35b9 | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 378 | auto intError = mComposer.presentDisplay(mId, &presentFenceFd); |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 379 | auto error = static_cast<Error>(intError); |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 380 | if (error != Error::NONE) { |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 381 | return error; |
| 382 | } |
| 383 | |
Fabien Sanglard | 11d0fc3 | 2016-12-01 15:43:01 -0800 | [diff] [blame] | 384 | *outPresentFence = new Fence(presentFenceFd); |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 385 | return Error::NONE; |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 386 | } |
| 387 | |
Marin Shalamanov | 3ea1d60 | 2020-12-16 19:59:39 +0100 | [diff] [blame] | 388 | Error Display::setActiveConfigWithConstraints(hal::HWConfigId configId, |
| 389 | const VsyncPeriodChangeConstraints& constraints, |
| 390 | VsyncPeriodChangeTimeline* outTimeline) { |
Ady Abraham | 7159f57 | 2019-10-11 11:10:18 -0700 | [diff] [blame] | 391 | ALOGV("[%" PRIu64 "] setActiveConfigWithConstraints", mId); |
Ady Abraham | 7159f57 | 2019-10-11 11:10:18 -0700 | [diff] [blame] | 392 | |
| 393 | if (isVsyncPeriodSwitchSupported()) { |
| 394 | Hwc2::IComposerClient::VsyncPeriodChangeConstraints hwc2Constraints; |
| 395 | hwc2Constraints.desiredTimeNanos = constraints.desiredTimeNanos; |
| 396 | hwc2Constraints.seamlessRequired = constraints.seamlessRequired; |
| 397 | |
| 398 | Hwc2::VsyncPeriodChangeTimeline vsyncPeriodChangeTimeline = {}; |
Marin Shalamanov | 3ea1d60 | 2020-12-16 19:59:39 +0100 | [diff] [blame] | 399 | auto intError = mComposer.setActiveConfigWithConstraints(mId, configId, hwc2Constraints, |
| 400 | &vsyncPeriodChangeTimeline); |
Ady Abraham | 7159f57 | 2019-10-11 11:10:18 -0700 | [diff] [blame] | 401 | outTimeline->newVsyncAppliedTimeNanos = vsyncPeriodChangeTimeline.newVsyncAppliedTimeNanos; |
| 402 | outTimeline->refreshRequired = vsyncPeriodChangeTimeline.refreshRequired; |
| 403 | outTimeline->refreshTimeNanos = vsyncPeriodChangeTimeline.refreshTimeNanos; |
| 404 | return static_cast<Error>(intError); |
| 405 | } |
| 406 | |
| 407 | // Use legacy setActiveConfig instead |
| 408 | ALOGV("fallback to legacy setActiveConfig"); |
| 409 | const auto now = systemTime(); |
| 410 | if (constraints.desiredTimeNanos > now || constraints.seamlessRequired) { |
| 411 | ALOGE("setActiveConfigWithConstraints received constraints that can't be satisfied"); |
| 412 | } |
| 413 | |
Marin Shalamanov | 3ea1d60 | 2020-12-16 19:59:39 +0100 | [diff] [blame] | 414 | auto intError_2_4 = mComposer.setActiveConfig(mId, configId); |
Ady Abraham | 7159f57 | 2019-10-11 11:10:18 -0700 | [diff] [blame] | 415 | outTimeline->newVsyncAppliedTimeNanos = std::max(now, constraints.desiredTimeNanos); |
| 416 | outTimeline->refreshRequired = true; |
| 417 | outTimeline->refreshTimeNanos = now; |
| 418 | return static_cast<Error>(intError_2_4); |
| 419 | } |
| 420 | |
Daniel Nicoara | 1f42e3a | 2017-04-10 13:27:32 -0400 | [diff] [blame] | 421 | Error Display::setClientTarget(uint32_t slot, const sp<GraphicBuffer>& target, |
Peiyong Lin | 34beb7a | 2018-03-28 11:57:12 -0700 | [diff] [blame] | 422 | const sp<Fence>& acquireFence, Dataspace dataspace) |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 423 | { |
Dan Stoza | 5cf424b | 2016-05-20 14:02:39 -0700 | [diff] [blame] | 424 | // TODO: Properly encode client target surface damage |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 425 | int32_t fenceFd = acquireFence->dup(); |
Steven Thomas | 94e35b9 | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 426 | auto intError = mComposer.setClientTarget(mId, slot, target, |
Peiyong Lin | 34beb7a | 2018-03-28 11:57:12 -0700 | [diff] [blame] | 427 | fenceFd, dataspace, std::vector<Hwc2::IComposerClient::Rect>()); |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 428 | return static_cast<Error>(intError); |
| 429 | } |
| 430 | |
Peiyong Lin | 0e7a791 | 2018-04-05 14:36:36 -0700 | [diff] [blame] | 431 | Error Display::setColorMode(ColorMode mode, RenderIntent renderIntent) |
Dan Stoza | 076ac67 | 2016-03-14 10:47:53 -0700 | [diff] [blame] | 432 | { |
Peiyong Lin | 0e7a791 | 2018-04-05 14:36:36 -0700 | [diff] [blame] | 433 | auto intError = mComposer.setColorMode(mId, mode, renderIntent); |
Dan Stoza | 076ac67 | 2016-03-14 10:47:53 -0700 | [diff] [blame] | 434 | return static_cast<Error>(intError); |
| 435 | } |
| 436 | |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 437 | Error Display::setColorTransform(const android::mat4& matrix, ColorTransform hint) { |
| 438 | auto intError = mComposer.setColorTransform(mId, matrix.asArray(), hint); |
Dan Stoza | 5df2a86 | 2016-03-24 16:19:37 -0700 | [diff] [blame] | 439 | return static_cast<Error>(intError); |
| 440 | } |
| 441 | |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 442 | Error Display::setOutputBuffer(const sp<GraphicBuffer>& buffer, |
| 443 | const sp<Fence>& releaseFence) |
| 444 | { |
| 445 | int32_t fenceFd = releaseFence->dup(); |
| 446 | auto handle = buffer->getNativeBuffer()->handle; |
Steven Thomas | 94e35b9 | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 447 | auto intError = mComposer.setOutputBuffer(mId, handle, fenceFd); |
Dan Stoza | 3862898 | 2016-07-13 15:48:58 -0700 | [diff] [blame] | 448 | close(fenceFd); |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 449 | return static_cast<Error>(intError); |
| 450 | } |
| 451 | |
| 452 | Error Display::setPowerMode(PowerMode mode) |
| 453 | { |
Chia-I Wu | cd8d7f0 | 2016-11-16 11:02:31 +0800 | [diff] [blame] | 454 | auto intMode = static_cast<Hwc2::IComposerClient::PowerMode>(mode); |
Steven Thomas | 94e35b9 | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 455 | auto intError = mComposer.setPowerMode(mId, intMode); |
Peiyong Lin | 1336e6e | 2019-05-28 09:23:50 -0700 | [diff] [blame] | 456 | |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 457 | if (mode == PowerMode::ON) { |
Peiyong Lin | 1336e6e | 2019-05-28 09:23:50 -0700 | [diff] [blame] | 458 | std::call_once(mDisplayCapabilityQueryFlag, [this]() { |
| 459 | std::vector<Hwc2::DisplayCapability> tmpCapabilities; |
| 460 | auto error = |
| 461 | static_cast<Error>(mComposer.getDisplayCapabilities(mId, &tmpCapabilities)); |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 462 | if (error == Error::NONE) { |
Ady Abraham | 27fbcc7 | 2021-09-20 14:54:57 -0700 | [diff] [blame] | 463 | std::scoped_lock lock(mDisplayCapabilitiesMutex); |
| 464 | mDisplayCapabilities.emplace(); |
Peiyong Lin | 1336e6e | 2019-05-28 09:23:50 -0700 | [diff] [blame] | 465 | for (auto capability : tmpCapabilities) { |
Ady Abraham | 27fbcc7 | 2021-09-20 14:54:57 -0700 | [diff] [blame] | 466 | mDisplayCapabilities->emplace(static_cast<DisplayCapability>(capability)); |
Peiyong Lin | 1336e6e | 2019-05-28 09:23:50 -0700 | [diff] [blame] | 467 | } |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 468 | } else if (error == Error::UNSUPPORTED) { |
Ady Abraham | 27fbcc7 | 2021-09-20 14:54:57 -0700 | [diff] [blame] | 469 | std::scoped_lock lock(mDisplayCapabilitiesMutex); |
| 470 | mDisplayCapabilities.emplace(); |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 471 | if (mCapabilities.count(Capability::SKIP_CLIENT_COLOR_TRANSFORM)) { |
Ady Abraham | 27fbcc7 | 2021-09-20 14:54:57 -0700 | [diff] [blame] | 472 | mDisplayCapabilities->emplace(DisplayCapability::SKIP_CLIENT_COLOR_TRANSFORM); |
Peiyong Lin | 1336e6e | 2019-05-28 09:23:50 -0700 | [diff] [blame] | 473 | } |
| 474 | bool dozeSupport = false; |
| 475 | error = static_cast<Error>(mComposer.getDozeSupport(mId, &dozeSupport)); |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 476 | if (error == Error::NONE && dozeSupport) { |
Ady Abraham | 27fbcc7 | 2021-09-20 14:54:57 -0700 | [diff] [blame] | 477 | mDisplayCapabilities->emplace(DisplayCapability::DOZE); |
Peiyong Lin | 1336e6e | 2019-05-28 09:23:50 -0700 | [diff] [blame] | 478 | } |
| 479 | } |
| 480 | }); |
| 481 | } |
| 482 | |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 483 | return static_cast<Error>(intError); |
| 484 | } |
| 485 | |
| 486 | Error Display::setVsyncEnabled(Vsync enabled) |
| 487 | { |
Chia-I Wu | cd8d7f0 | 2016-11-16 11:02:31 +0800 | [diff] [blame] | 488 | auto intEnabled = static_cast<Hwc2::IComposerClient::Vsync>(enabled); |
Steven Thomas | 94e35b9 | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 489 | auto intError = mComposer.setVsyncEnabled(mId, intEnabled); |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 490 | return static_cast<Error>(intError); |
| 491 | } |
| 492 | |
| 493 | Error Display::validate(uint32_t* outNumTypes, uint32_t* outNumRequests) |
| 494 | { |
| 495 | uint32_t numTypes = 0; |
| 496 | uint32_t numRequests = 0; |
Steven Thomas | 94e35b9 | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 497 | auto intError = mComposer.validateDisplay(mId, &numTypes, &numRequests); |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 498 | auto error = static_cast<Error>(intError); |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 499 | if (error != Error::NONE && !hasChangesError(error)) { |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 500 | return error; |
| 501 | } |
| 502 | |
| 503 | *outNumTypes = numTypes; |
| 504 | *outNumRequests = numRequests; |
| 505 | return error; |
| 506 | } |
| 507 | |
Fabien Sanglard | 249c0ae | 2017-06-19 19:22:36 -0700 | [diff] [blame] | 508 | Error Display::presentOrValidate(uint32_t* outNumTypes, uint32_t* outNumRequests, |
| 509 | sp<android::Fence>* outPresentFence, uint32_t* state) { |
| 510 | |
| 511 | uint32_t numTypes = 0; |
| 512 | uint32_t numRequests = 0; |
| 513 | int32_t presentFenceFd = -1; |
Steven Thomas | 94e35b9 | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 514 | auto intError = mComposer.presentOrValidateDisplay( |
| 515 | mId, &numTypes, &numRequests, &presentFenceFd, state); |
Fabien Sanglard | 249c0ae | 2017-06-19 19:22:36 -0700 | [diff] [blame] | 516 | auto error = static_cast<Error>(intError); |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 517 | if (error != Error::NONE && !hasChangesError(error)) { |
Fabien Sanglard | 249c0ae | 2017-06-19 19:22:36 -0700 | [diff] [blame] | 518 | return error; |
| 519 | } |
| 520 | |
| 521 | if (*state == 1) { |
| 522 | *outPresentFence = new Fence(presentFenceFd); |
| 523 | } |
| 524 | |
| 525 | if (*state == 0) { |
| 526 | *outNumTypes = numTypes; |
| 527 | *outNumRequests = numRequests; |
| 528 | } |
| 529 | return error; |
| 530 | } |
Chia-I Wu | 0c6ce46 | 2017-06-22 10:48:28 -0700 | [diff] [blame] | 531 | |
Dominik Laskowski | 5690bde | 2020-04-23 19:04:22 -0700 | [diff] [blame] | 532 | std::future<Error> Display::setDisplayBrightness(float brightness) { |
Dominik Laskowski | 4e2b71f | 2020-11-10 15:05:32 -0800 | [diff] [blame] | 533 | return ftl::defer([composer = &mComposer, id = mId, brightness] { |
Dominik Laskowski | 5690bde | 2020-04-23 19:04:22 -0700 | [diff] [blame] | 534 | const auto intError = composer->setDisplayBrightness(id, brightness); |
| 535 | return static_cast<Error>(intError); |
| 536 | }); |
Dan Gittik | 57e63c5 | 2019-01-18 16:37:54 +0000 | [diff] [blame] | 537 | } |
| 538 | |
Dominik Laskowski | 5690bde | 2020-04-23 19:04:22 -0700 | [diff] [blame] | 539 | Error Display::setAutoLowLatencyMode(bool on) { |
Galia Peycheva | 5492cb5 | 2019-10-30 14:13:16 +0100 | [diff] [blame] | 540 | auto intError = mComposer.setAutoLowLatencyMode(mId, on); |
| 541 | return static_cast<Error>(intError); |
| 542 | } |
| 543 | |
| 544 | Error Display::getSupportedContentTypes(std::vector<ContentType>* outSupportedContentTypes) const { |
| 545 | std::vector<Hwc2::IComposerClient::ContentType> tmpSupportedContentTypes; |
| 546 | auto intError = mComposer.getSupportedContentTypes(mId, &tmpSupportedContentTypes); |
| 547 | for (Hwc2::IComposerClient::ContentType contentType : tmpSupportedContentTypes) { |
| 548 | outSupportedContentTypes->push_back(static_cast<ContentType>(contentType)); |
| 549 | } |
| 550 | return static_cast<Error>(intError); |
| 551 | } |
| 552 | |
Dominik Laskowski | 5690bde | 2020-04-23 19:04:22 -0700 | [diff] [blame] | 553 | Error Display::setContentType(ContentType contentType) { |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 554 | auto intError = mComposer.setContentType(mId, contentType); |
Galia Peycheva | 5492cb5 | 2019-10-30 14:13:16 +0100 | [diff] [blame] | 555 | return static_cast<Error>(intError); |
| 556 | } |
| 557 | |
Peiyong Lin | dfc3f7c | 2020-05-07 20:15:50 -0700 | [diff] [blame] | 558 | Error Display::getClientTargetProperty(ClientTargetProperty* outClientTargetProperty) { |
| 559 | const auto error = mComposer.getClientTargetProperty(mId, outClientTargetProperty); |
| 560 | return static_cast<Error>(error); |
| 561 | } |
| 562 | |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 563 | // For use by Device |
| 564 | |
Steven Thomas | 94e35b9 | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 565 | void Display::setConnected(bool connected) { |
Steven Thomas | b6c6ad4 | 2018-01-29 12:22:00 -0800 | [diff] [blame] | 566 | if (!mIsConnected && connected) { |
Steven Thomas | 94e35b9 | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 567 | mComposer.setClientTargetSlotCount(mId); |
Steven Thomas | 94e35b9 | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 568 | } |
| 569 | mIsConnected = connected; |
| 570 | } |
| 571 | |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 572 | // Other Display methods |
| 573 | |
Lloyd Pique | a516c00 | 2021-05-07 14:36:58 -0700 | [diff] [blame] | 574 | std::shared_ptr<HWC2::Layer> Display::getLayerById(HWLayerId id) const { |
| 575 | auto it = mLayers.find(id); |
| 576 | return it != mLayers.end() ? it->second.lock() : nullptr; |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 577 | } |
Ana Krulec | 4593b69 | 2019-01-11 22:07:25 -0800 | [diff] [blame] | 578 | } // namespace impl |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 579 | |
| 580 | // Layer methods |
| 581 | |
Lloyd Pique | 35d5824 | 2018-12-18 16:33:25 -0800 | [diff] [blame] | 582 | Layer::~Layer() = default; |
| 583 | |
| 584 | namespace impl { |
| 585 | |
Courtney Goeltzenleuchter | f9c98e5 | 2018-02-12 07:23:17 -0700 | [diff] [blame] | 586 | Layer::Layer(android::Hwc2::Composer& composer, const std::unordered_set<Capability>& capabilities, |
Lloyd Pique | a516c00 | 2021-05-07 14:36:58 -0700 | [diff] [blame] | 587 | HWC2::Display& display, HWLayerId layerId) |
Lloyd Pique | 4603f3c | 2020-02-11 12:06:56 -0800 | [diff] [blame] | 588 | : mComposer(composer), |
| 589 | mCapabilities(capabilities), |
Lloyd Pique | a516c00 | 2021-05-07 14:36:58 -0700 | [diff] [blame] | 590 | mDisplay(&display), |
Lloyd Pique | 4603f3c | 2020-02-11 12:06:56 -0800 | [diff] [blame] | 591 | mId(layerId), |
| 592 | mColorMatrix(android::mat4()) { |
Lloyd Pique | a516c00 | 2021-05-07 14:36:58 -0700 | [diff] [blame] | 593 | ALOGV("Created layer %" PRIu64 " on display %" PRIu64, layerId, display.getId()); |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 594 | } |
| 595 | |
| 596 | Layer::~Layer() |
| 597 | { |
Lloyd Pique | a516c00 | 2021-05-07 14:36:58 -0700 | [diff] [blame] | 598 | onOwningDisplayDestroyed(); |
| 599 | } |
| 600 | |
| 601 | void Layer::onOwningDisplayDestroyed() { |
| 602 | // Note: onOwningDisplayDestroyed() may be called to perform cleanup by |
| 603 | // either the Layer dtor or by the Display dtor and must be safe to call |
| 604 | // from either path. In particular, the call to Display::onLayerDestroyed() |
| 605 | // is expected to be safe to do, |
| 606 | |
| 607 | if (CC_UNLIKELY(!mDisplay)) { |
| 608 | return; |
| 609 | } |
| 610 | |
| 611 | mDisplay->onLayerDestroyed(mId); |
| 612 | |
| 613 | // Note: If the HWC display was actually disconnected, these calls are will |
| 614 | // return an error. We always make them as there may be other reasons for |
| 615 | // the HWC2::Display to be destroyed. |
| 616 | auto intError = mComposer.destroyLayer(mDisplay->getId(), mId); |
Steven Thomas | 94e35b9 | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 617 | auto error = static_cast<Error>(intError); |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 618 | ALOGE_IF(error != Error::NONE, |
| 619 | "destroyLayer(%" PRIu64 ", %" PRIu64 ")" |
| 620 | " failed: %s (%d)", |
Lloyd Pique | a516c00 | 2021-05-07 14:36:58 -0700 | [diff] [blame] | 621 | mDisplay->getId(), mId, to_string(error).c_str(), intError); |
| 622 | |
| 623 | mDisplay = nullptr; |
Steven Thomas | 94e35b9 | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 624 | } |
| 625 | |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 626 | Error Layer::setCursorPosition(int32_t x, int32_t y) |
| 627 | { |
Lloyd Pique | a516c00 | 2021-05-07 14:36:58 -0700 | [diff] [blame] | 628 | if (CC_UNLIKELY(!mDisplay)) { |
| 629 | return Error::BAD_DISPLAY; |
| 630 | } |
| 631 | |
| 632 | auto intError = mComposer.setCursorPosition(mDisplay->getId(), mId, x, y); |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 633 | return static_cast<Error>(intError); |
| 634 | } |
| 635 | |
Daniel Nicoara | 1f42e3a | 2017-04-10 13:27:32 -0400 | [diff] [blame] | 636 | Error Layer::setBuffer(uint32_t slot, const sp<GraphicBuffer>& buffer, |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 637 | const sp<Fence>& acquireFence) |
| 638 | { |
Lloyd Pique | a516c00 | 2021-05-07 14:36:58 -0700 | [diff] [blame] | 639 | if (CC_UNLIKELY(!mDisplay)) { |
| 640 | return Error::BAD_DISPLAY; |
| 641 | } |
| 642 | |
Yichi Chen | 8366f56 | 2019-03-25 19:44:06 +0800 | [diff] [blame] | 643 | if (buffer == nullptr && mBufferSlot == slot) { |
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 | mBufferSlot = slot; |
| 647 | |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 648 | int32_t fenceFd = acquireFence->dup(); |
Lloyd Pique | a516c00 | 2021-05-07 14:36:58 -0700 | [diff] [blame] | 649 | auto intError = mComposer.setLayerBuffer(mDisplay->getId(), mId, slot, buffer, fenceFd); |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 650 | return static_cast<Error>(intError); |
| 651 | } |
| 652 | |
| 653 | Error Layer::setSurfaceDamage(const Region& damage) |
| 654 | { |
Lloyd Pique | a516c00 | 2021-05-07 14:36:58 -0700 | [diff] [blame] | 655 | if (CC_UNLIKELY(!mDisplay)) { |
| 656 | return Error::BAD_DISPLAY; |
| 657 | } |
| 658 | |
Yichi Chen | 8366f56 | 2019-03-25 19:44:06 +0800 | [diff] [blame] | 659 | if (damage.isRect() && mDamageRegion.isRect() && |
| 660 | (damage.getBounds() == mDamageRegion.getBounds())) { |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 661 | return Error::NONE; |
Yichi Chen | 8366f56 | 2019-03-25 19:44:06 +0800 | [diff] [blame] | 662 | } |
| 663 | mDamageRegion = damage; |
| 664 | |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 665 | // We encode default full-screen damage as INVALID_RECT upstream, but as 0 |
| 666 | // rects for HWC |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 667 | Hwc2::Error intError = Hwc2::Error::NONE; |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 668 | if (damage.isRect() && damage.getBounds() == Rect::INVALID_RECT) { |
Lloyd Pique | a516c00 | 2021-05-07 14:36:58 -0700 | [diff] [blame] | 669 | intError = mComposer.setLayerSurfaceDamage(mDisplay->getId(), mId, |
| 670 | std::vector<Hwc2::IComposerClient::Rect>()); |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 671 | } else { |
| 672 | size_t rectCount = 0; |
| 673 | auto rectArray = damage.getArray(&rectCount); |
| 674 | |
Chia-I Wu | cd8d7f0 | 2016-11-16 11:02:31 +0800 | [diff] [blame] | 675 | std::vector<Hwc2::IComposerClient::Rect> hwcRects; |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 676 | for (size_t rect = 0; rect < rectCount; ++rect) { |
| 677 | hwcRects.push_back({rectArray[rect].left, rectArray[rect].top, |
| 678 | rectArray[rect].right, rectArray[rect].bottom}); |
| 679 | } |
| 680 | |
Lloyd Pique | a516c00 | 2021-05-07 14:36:58 -0700 | [diff] [blame] | 681 | intError = mComposer.setLayerSurfaceDamage(mDisplay->getId(), mId, hwcRects); |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 682 | } |
| 683 | |
| 684 | return static_cast<Error>(intError); |
| 685 | } |
| 686 | |
| 687 | Error Layer::setBlendMode(BlendMode mode) |
| 688 | { |
Lloyd Pique | a516c00 | 2021-05-07 14:36:58 -0700 | [diff] [blame] | 689 | if (CC_UNLIKELY(!mDisplay)) { |
| 690 | return Error::BAD_DISPLAY; |
| 691 | } |
| 692 | |
| 693 | auto intError = mComposer.setLayerBlendMode(mDisplay->getId(), mId, mode); |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 694 | return static_cast<Error>(intError); |
| 695 | } |
| 696 | |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 697 | Error Layer::setColor(Color color) { |
Lloyd Pique | a516c00 | 2021-05-07 14:36:58 -0700 | [diff] [blame] | 698 | if (CC_UNLIKELY(!mDisplay)) { |
| 699 | return Error::BAD_DISPLAY; |
| 700 | } |
| 701 | |
| 702 | auto intError = mComposer.setLayerColor(mDisplay->getId(), mId, color); |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 703 | return static_cast<Error>(intError); |
| 704 | } |
| 705 | |
| 706 | Error Layer::setCompositionType(Composition type) |
| 707 | { |
Lloyd Pique | a516c00 | 2021-05-07 14:36:58 -0700 | [diff] [blame] | 708 | if (CC_UNLIKELY(!mDisplay)) { |
| 709 | return Error::BAD_DISPLAY; |
| 710 | } |
| 711 | |
| 712 | auto intError = mComposer.setLayerCompositionType(mDisplay->getId(), mId, type); |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 713 | return static_cast<Error>(intError); |
| 714 | } |
| 715 | |
Peiyong Lin | 34beb7a | 2018-03-28 11:57:12 -0700 | [diff] [blame] | 716 | Error Layer::setDataspace(Dataspace dataspace) |
Dan Stoza | 5df2a86 | 2016-03-24 16:19:37 -0700 | [diff] [blame] | 717 | { |
Lloyd Pique | a516c00 | 2021-05-07 14:36:58 -0700 | [diff] [blame] | 718 | if (CC_UNLIKELY(!mDisplay)) { |
| 719 | return Error::BAD_DISPLAY; |
| 720 | } |
| 721 | |
Courtney Goeltzenleuchter | c988ee4 | 2017-05-31 17:56:46 -0600 | [diff] [blame] | 722 | if (dataspace == mDataSpace) { |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 723 | return Error::NONE; |
Courtney Goeltzenleuchter | c988ee4 | 2017-05-31 17:56:46 -0600 | [diff] [blame] | 724 | } |
| 725 | mDataSpace = dataspace; |
Lloyd Pique | a516c00 | 2021-05-07 14:36:58 -0700 | [diff] [blame] | 726 | auto intError = mComposer.setLayerDataspace(mDisplay->getId(), mId, mDataSpace); |
Dan Stoza | 5df2a86 | 2016-03-24 16:19:37 -0700 | [diff] [blame] | 727 | return static_cast<Error>(intError); |
| 728 | } |
| 729 | |
Peiyong Lin | 0ac5f4e | 2018-04-19 22:06:34 -0700 | [diff] [blame] | 730 | Error Layer::setPerFrameMetadata(const int32_t supportedPerFrameMetadata, |
| 731 | const android::HdrMetadata& metadata) |
| 732 | { |
Lloyd Pique | a516c00 | 2021-05-07 14:36:58 -0700 | [diff] [blame] | 733 | if (CC_UNLIKELY(!mDisplay)) { |
| 734 | return Error::BAD_DISPLAY; |
| 735 | } |
| 736 | |
Courtney Goeltzenleuchter | f9c98e5 | 2018-02-12 07:23:17 -0700 | [diff] [blame] | 737 | if (metadata == mHdrMetadata) { |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 738 | return Error::NONE; |
Courtney Goeltzenleuchter | f9c98e5 | 2018-02-12 07:23:17 -0700 | [diff] [blame] | 739 | } |
| 740 | |
| 741 | mHdrMetadata = metadata; |
Peiyong Lin | 0ac5f4e | 2018-04-19 22:06:34 -0700 | [diff] [blame] | 742 | int validTypes = mHdrMetadata.validTypes & supportedPerFrameMetadata; |
| 743 | std::vector<Hwc2::PerFrameMetadata> perFrameMetadatas; |
| 744 | if (validTypes & HdrMetadata::SMPTE2086) { |
| 745 | perFrameMetadatas.insert(perFrameMetadatas.end(), |
| 746 | {{Hwc2::PerFrameMetadataKey::DISPLAY_RED_PRIMARY_X, |
Valerie Hau | e9e843a | 2018-12-18 13:39:23 -0800 | [diff] [blame] | 747 | mHdrMetadata.smpte2086.displayPrimaryRed.x}, |
| 748 | {Hwc2::PerFrameMetadataKey::DISPLAY_RED_PRIMARY_Y, |
| 749 | mHdrMetadata.smpte2086.displayPrimaryRed.y}, |
| 750 | {Hwc2::PerFrameMetadataKey::DISPLAY_GREEN_PRIMARY_X, |
| 751 | mHdrMetadata.smpte2086.displayPrimaryGreen.x}, |
| 752 | {Hwc2::PerFrameMetadataKey::DISPLAY_GREEN_PRIMARY_Y, |
| 753 | mHdrMetadata.smpte2086.displayPrimaryGreen.y}, |
| 754 | {Hwc2::PerFrameMetadataKey::DISPLAY_BLUE_PRIMARY_X, |
| 755 | mHdrMetadata.smpte2086.displayPrimaryBlue.x}, |
| 756 | {Hwc2::PerFrameMetadataKey::DISPLAY_BLUE_PRIMARY_Y, |
| 757 | mHdrMetadata.smpte2086.displayPrimaryBlue.y}, |
| 758 | {Hwc2::PerFrameMetadataKey::WHITE_POINT_X, |
| 759 | mHdrMetadata.smpte2086.whitePoint.x}, |
| 760 | {Hwc2::PerFrameMetadataKey::WHITE_POINT_Y, |
| 761 | mHdrMetadata.smpte2086.whitePoint.y}, |
| 762 | {Hwc2::PerFrameMetadataKey::MAX_LUMINANCE, |
| 763 | mHdrMetadata.smpte2086.maxLuminance}, |
| 764 | {Hwc2::PerFrameMetadataKey::MIN_LUMINANCE, |
| 765 | mHdrMetadata.smpte2086.minLuminance}}); |
Peiyong Lin | 0ac5f4e | 2018-04-19 22:06:34 -0700 | [diff] [blame] | 766 | } |
| 767 | |
| 768 | if (validTypes & HdrMetadata::CTA861_3) { |
| 769 | perFrameMetadatas.insert(perFrameMetadatas.end(), |
| 770 | {{Hwc2::PerFrameMetadataKey::MAX_CONTENT_LIGHT_LEVEL, |
Valerie Hau | e9e843a | 2018-12-18 13:39:23 -0800 | [diff] [blame] | 771 | mHdrMetadata.cta8613.maxContentLightLevel}, |
| 772 | {Hwc2::PerFrameMetadataKey::MAX_FRAME_AVERAGE_LIGHT_LEVEL, |
| 773 | mHdrMetadata.cta8613.maxFrameAverageLightLevel}}); |
Peiyong Lin | 0ac5f4e | 2018-04-19 22:06:34 -0700 | [diff] [blame] | 774 | } |
| 775 | |
Valerie Hau | e9e843a | 2018-12-18 13:39:23 -0800 | [diff] [blame] | 776 | Error error = static_cast<Error>( |
Lloyd Pique | a516c00 | 2021-05-07 14:36:58 -0700 | [diff] [blame] | 777 | mComposer.setLayerPerFrameMetadata(mDisplay->getId(), mId, perFrameMetadatas)); |
Valerie Hau | e9e843a | 2018-12-18 13:39:23 -0800 | [diff] [blame] | 778 | |
| 779 | if (validTypes & HdrMetadata::HDR10PLUS) { |
Yichi Chen | 1d5146d | 2020-06-12 18:50:11 +0800 | [diff] [blame] | 780 | if (CC_UNLIKELY(mHdrMetadata.hdr10plus.size() == 0)) { |
| 781 | return Error::BAD_PARAMETER; |
| 782 | } |
| 783 | |
Valerie Hau | e9e843a | 2018-12-18 13:39:23 -0800 | [diff] [blame] | 784 | std::vector<Hwc2::PerFrameMetadataBlob> perFrameMetadataBlobs; |
| 785 | perFrameMetadataBlobs.push_back( |
| 786 | {Hwc2::PerFrameMetadataKey::HDR10_PLUS_SEI, mHdrMetadata.hdr10plus}); |
Lloyd Pique | a516c00 | 2021-05-07 14:36:58 -0700 | [diff] [blame] | 787 | Error setMetadataBlobsError = |
| 788 | static_cast<Error>(mComposer.setLayerPerFrameMetadataBlobs(mDisplay->getId(), mId, |
| 789 | perFrameMetadataBlobs)); |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 790 | if (error == Error::NONE) { |
Valerie Hau | e9e843a | 2018-12-18 13:39:23 -0800 | [diff] [blame] | 791 | return setMetadataBlobsError; |
| 792 | } |
| 793 | } |
| 794 | return error; |
Courtney Goeltzenleuchter | f9c98e5 | 2018-02-12 07:23:17 -0700 | [diff] [blame] | 795 | } |
| 796 | |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 797 | Error Layer::setDisplayFrame(const Rect& frame) |
| 798 | { |
Lloyd Pique | a516c00 | 2021-05-07 14:36:58 -0700 | [diff] [blame] | 799 | if (CC_UNLIKELY(!mDisplay)) { |
| 800 | return Error::BAD_DISPLAY; |
| 801 | } |
| 802 | |
Chia-I Wu | cd8d7f0 | 2016-11-16 11:02:31 +0800 | [diff] [blame] | 803 | Hwc2::IComposerClient::Rect hwcRect{frame.left, frame.top, |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 804 | frame.right, frame.bottom}; |
Lloyd Pique | a516c00 | 2021-05-07 14:36:58 -0700 | [diff] [blame] | 805 | auto intError = mComposer.setLayerDisplayFrame(mDisplay->getId(), mId, hwcRect); |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 806 | return static_cast<Error>(intError); |
| 807 | } |
| 808 | |
| 809 | Error Layer::setPlaneAlpha(float alpha) |
| 810 | { |
Lloyd Pique | a516c00 | 2021-05-07 14:36:58 -0700 | [diff] [blame] | 811 | if (CC_UNLIKELY(!mDisplay)) { |
| 812 | return Error::BAD_DISPLAY; |
| 813 | } |
| 814 | |
| 815 | auto intError = mComposer.setLayerPlaneAlpha(mDisplay->getId(), mId, alpha); |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 816 | return static_cast<Error>(intError); |
| 817 | } |
| 818 | |
| 819 | Error Layer::setSidebandStream(const native_handle_t* stream) |
| 820 | { |
Lloyd Pique | a516c00 | 2021-05-07 14:36:58 -0700 | [diff] [blame] | 821 | if (CC_UNLIKELY(!mDisplay)) { |
| 822 | return Error::BAD_DISPLAY; |
| 823 | } |
| 824 | |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 825 | if (mCapabilities.count(Capability::SIDEBAND_STREAM) == 0) { |
Dan Stoza | 09e7a27 | 2016-04-14 12:31:01 -0700 | [diff] [blame] | 826 | ALOGE("Attempted to call setSidebandStream without checking that the " |
| 827 | "device supports sideband streams"); |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 828 | return Error::UNSUPPORTED; |
Dan Stoza | 09e7a27 | 2016-04-14 12:31:01 -0700 | [diff] [blame] | 829 | } |
Lloyd Pique | a516c00 | 2021-05-07 14:36:58 -0700 | [diff] [blame] | 830 | auto intError = mComposer.setLayerSidebandStream(mDisplay->getId(), mId, stream); |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 831 | return static_cast<Error>(intError); |
| 832 | } |
| 833 | |
| 834 | Error Layer::setSourceCrop(const FloatRect& crop) |
| 835 | { |
Lloyd Pique | a516c00 | 2021-05-07 14:36:58 -0700 | [diff] [blame] | 836 | if (CC_UNLIKELY(!mDisplay)) { |
| 837 | return Error::BAD_DISPLAY; |
| 838 | } |
| 839 | |
Chia-I Wu | cd8d7f0 | 2016-11-16 11:02:31 +0800 | [diff] [blame] | 840 | Hwc2::IComposerClient::FRect hwcRect{ |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 841 | crop.left, crop.top, crop.right, crop.bottom}; |
Lloyd Pique | a516c00 | 2021-05-07 14:36:58 -0700 | [diff] [blame] | 842 | auto intError = mComposer.setLayerSourceCrop(mDisplay->getId(), mId, hwcRect); |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 843 | return static_cast<Error>(intError); |
| 844 | } |
| 845 | |
| 846 | Error Layer::setTransform(Transform transform) |
| 847 | { |
Lloyd Pique | a516c00 | 2021-05-07 14:36:58 -0700 | [diff] [blame] | 848 | if (CC_UNLIKELY(!mDisplay)) { |
| 849 | return Error::BAD_DISPLAY; |
| 850 | } |
| 851 | |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 852 | auto intTransform = static_cast<Hwc2::Transform>(transform); |
Lloyd Pique | a516c00 | 2021-05-07 14:36:58 -0700 | [diff] [blame] | 853 | auto intError = mComposer.setLayerTransform(mDisplay->getId(), mId, intTransform); |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 854 | return static_cast<Error>(intError); |
| 855 | } |
| 856 | |
| 857 | Error Layer::setVisibleRegion(const Region& region) |
| 858 | { |
Lloyd Pique | a516c00 | 2021-05-07 14:36:58 -0700 | [diff] [blame] | 859 | if (CC_UNLIKELY(!mDisplay)) { |
| 860 | return Error::BAD_DISPLAY; |
| 861 | } |
| 862 | |
Yichi Chen | 8366f56 | 2019-03-25 19:44:06 +0800 | [diff] [blame] | 863 | if (region.isRect() && mVisibleRegion.isRect() && |
| 864 | (region.getBounds() == mVisibleRegion.getBounds())) { |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 865 | return Error::NONE; |
Yichi Chen | 8366f56 | 2019-03-25 19:44:06 +0800 | [diff] [blame] | 866 | } |
| 867 | mVisibleRegion = region; |
| 868 | |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 869 | size_t rectCount = 0; |
| 870 | auto rectArray = region.getArray(&rectCount); |
| 871 | |
Chia-I Wu | cd8d7f0 | 2016-11-16 11:02:31 +0800 | [diff] [blame] | 872 | std::vector<Hwc2::IComposerClient::Rect> hwcRects; |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 873 | for (size_t rect = 0; rect < rectCount; ++rect) { |
| 874 | hwcRects.push_back({rectArray[rect].left, rectArray[rect].top, |
| 875 | rectArray[rect].right, rectArray[rect].bottom}); |
| 876 | } |
| 877 | |
Lloyd Pique | a516c00 | 2021-05-07 14:36:58 -0700 | [diff] [blame] | 878 | auto intError = mComposer.setLayerVisibleRegion(mDisplay->getId(), mId, hwcRects); |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 879 | return static_cast<Error>(intError); |
| 880 | } |
| 881 | |
| 882 | Error Layer::setZOrder(uint32_t z) |
| 883 | { |
Lloyd Pique | a516c00 | 2021-05-07 14:36:58 -0700 | [diff] [blame] | 884 | if (CC_UNLIKELY(!mDisplay)) { |
| 885 | return Error::BAD_DISPLAY; |
| 886 | } |
| 887 | |
| 888 | auto intError = mComposer.setLayerZOrder(mDisplay->getId(), mId, z); |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 889 | return static_cast<Error>(intError); |
| 890 | } |
| 891 | |
Peiyong Lin | 698147a | 2018-09-14 13:27:18 -0700 | [diff] [blame] | 892 | // Composer HAL 2.3 |
| 893 | Error Layer::setColorTransform(const android::mat4& matrix) { |
Lloyd Pique | a516c00 | 2021-05-07 14:36:58 -0700 | [diff] [blame] | 894 | if (CC_UNLIKELY(!mDisplay)) { |
| 895 | return Error::BAD_DISPLAY; |
| 896 | } |
| 897 | |
Peiyong Lin | 698147a | 2018-09-14 13:27:18 -0700 | [diff] [blame] | 898 | if (matrix == mColorMatrix) { |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 899 | return Error::NONE; |
Peiyong Lin | 698147a | 2018-09-14 13:27:18 -0700 | [diff] [blame] | 900 | } |
Lloyd Pique | a516c00 | 2021-05-07 14:36:58 -0700 | [diff] [blame] | 901 | auto intError = mComposer.setLayerColorTransform(mDisplay->getId(), mId, matrix.asArray()); |
Peiyong Lin | 04d2587 | 2019-04-18 10:26:19 -0700 | [diff] [blame] | 902 | Error error = static_cast<Error>(intError); |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 903 | if (error != Error::NONE) { |
Peiyong Lin | 04d2587 | 2019-04-18 10:26:19 -0700 | [diff] [blame] | 904 | return error; |
| 905 | } |
| 906 | mColorMatrix = matrix; |
| 907 | return error; |
Peiyong Lin | 698147a | 2018-09-14 13:27:18 -0700 | [diff] [blame] | 908 | } |
Lloyd Pique | 35d5824 | 2018-12-18 16:33:25 -0800 | [diff] [blame] | 909 | |
Lloyd Pique | 4603f3c | 2020-02-11 12:06:56 -0800 | [diff] [blame] | 910 | // Composer HAL 2.4 |
| 911 | Error Layer::setLayerGenericMetadata(const std::string& name, bool mandatory, |
| 912 | const std::vector<uint8_t>& value) { |
Lloyd Pique | a516c00 | 2021-05-07 14:36:58 -0700 | [diff] [blame] | 913 | if (CC_UNLIKELY(!mDisplay)) { |
| 914 | return Error::BAD_DISPLAY; |
| 915 | } |
| 916 | |
| 917 | auto intError = |
| 918 | mComposer.setLayerGenericMetadata(mDisplay->getId(), mId, name, mandatory, value); |
Lloyd Pique | 4603f3c | 2020-02-11 12:06:56 -0800 | [diff] [blame] | 919 | return static_cast<Error>(intError); |
| 920 | } |
| 921 | |
Lloyd Pique | 35d5824 | 2018-12-18 16:33:25 -0800 | [diff] [blame] | 922 | } // namespace impl |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 923 | } // namespace HWC2 |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 924 | } // namespace android |
Ady Abraham | b0dbdaa | 2020-01-06 16:19:42 -0800 | [diff] [blame] | 925 | |
| 926 | // TODO(b/129481165): remove the #pragma below and fix conversion issues |
| 927 | #pragma clang diagnostic pop // ignored "-Wconversion" |