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