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