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