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