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