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