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