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