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