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