| 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 |  | 
| Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 541 | Error Display::getReleaseFences( | 
| Steven Thomas | 94e35b9 | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 542 | std::unordered_map<Layer*, sp<Fence>>* outFences) const | 
| Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 543 | { | 
| Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 544 | std::vector<Hwc2::Layer> layerIds; | 
|  | 545 | std::vector<int> fenceFds; | 
| Steven Thomas | 94e35b9 | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 546 | auto intError = mComposer.getReleaseFences(mId, &layerIds, &fenceFds); | 
| Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 547 | auto error = static_cast<Error>(intError); | 
|  | 548 | uint32_t numElements = layerIds.size(); | 
| Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 549 | if (error != Error::None) { | 
|  | 550 | return error; | 
|  | 551 | } | 
|  | 552 |  | 
| Steven Thomas | 94e35b9 | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 553 | std::unordered_map<Layer*, sp<Fence>> releaseFences; | 
| Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 554 | releaseFences.reserve(numElements); | 
|  | 555 | for (uint32_t element = 0; element < numElements; ++element) { | 
|  | 556 | auto layer = getLayerById(layerIds[element]); | 
|  | 557 | if (layer) { | 
|  | 558 | sp<Fence> fence(new Fence(fenceFds[element])); | 
| Steven Thomas | 94e35b9 | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 559 | releaseFences.emplace(layer, fence); | 
| Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 560 | } else { | 
|  | 561 | ALOGE("getReleaseFences: invalid layer %" PRIu64 | 
|  | 562 | " found on display %" PRIu64, layerIds[element], mId); | 
| Chia-I Wu | 5e74c65 | 2017-05-17 13:43:16 -0700 | [diff] [blame] | 563 | for (; element < numElements; ++element) { | 
|  | 564 | close(fenceFds[element]); | 
|  | 565 | } | 
| Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 566 | return Error::BadLayer; | 
|  | 567 | } | 
|  | 568 | } | 
|  | 569 |  | 
|  | 570 | *outFences = std::move(releaseFences); | 
|  | 571 | return Error::None; | 
|  | 572 | } | 
|  | 573 |  | 
| Fabien Sanglard | 11d0fc3 | 2016-12-01 15:43:01 -0800 | [diff] [blame] | 574 | Error Display::present(sp<Fence>* outPresentFence) | 
| Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 575 | { | 
| Naseer Ahmed | 847650b | 2016-06-17 11:14:25 -0400 | [diff] [blame] | 576 | int32_t presentFenceFd = -1; | 
| Steven Thomas | 94e35b9 | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 577 | auto intError = mComposer.presentDisplay(mId, &presentFenceFd); | 
| Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 578 | auto error = static_cast<Error>(intError); | 
|  | 579 | if (error != Error::None) { | 
|  | 580 | return error; | 
|  | 581 | } | 
|  | 582 |  | 
| Fabien Sanglard | 11d0fc3 | 2016-12-01 15:43:01 -0800 | [diff] [blame] | 583 | *outPresentFence = new Fence(presentFenceFd); | 
| Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 584 | return Error::None; | 
|  | 585 | } | 
|  | 586 |  | 
|  | 587 | Error Display::setActiveConfig(const std::shared_ptr<const Config>& config) | 
|  | 588 | { | 
|  | 589 | if (config->getDisplayId() != mId) { | 
|  | 590 | ALOGE("setActiveConfig received config %u for the wrong display %" | 
|  | 591 | PRIu64 " (expected %" PRIu64 ")", config->getId(), | 
|  | 592 | config->getDisplayId(), mId); | 
|  | 593 | return Error::BadConfig; | 
|  | 594 | } | 
| Steven Thomas | 94e35b9 | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 595 | auto intError = mComposer.setActiveConfig(mId, config->getId()); | 
| Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 596 | return static_cast<Error>(intError); | 
|  | 597 | } | 
|  | 598 |  | 
| Daniel Nicoara | 1f42e3a | 2017-04-10 13:27:32 -0400 | [diff] [blame] | 599 | Error Display::setClientTarget(uint32_t slot, const sp<GraphicBuffer>& target, | 
| Peiyong Lin | 34beb7a | 2018-03-28 11:57:12 -0700 | [diff] [blame] | 600 | const sp<Fence>& acquireFence, Dataspace dataspace) | 
| Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 601 | { | 
| Dan Stoza | 5cf424b | 2016-05-20 14:02:39 -0700 | [diff] [blame] | 602 | // TODO: Properly encode client target surface damage | 
| Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 603 | int32_t fenceFd = acquireFence->dup(); | 
| Steven Thomas | 94e35b9 | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 604 | auto intError = mComposer.setClientTarget(mId, slot, target, | 
| Peiyong Lin | 34beb7a | 2018-03-28 11:57:12 -0700 | [diff] [blame] | 605 | fenceFd, dataspace, std::vector<Hwc2::IComposerClient::Rect>()); | 
| Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 606 | return static_cast<Error>(intError); | 
|  | 607 | } | 
|  | 608 |  | 
| Peiyong Lin | 0e7a791 | 2018-04-05 14:36:36 -0700 | [diff] [blame] | 609 | Error Display::setColorMode(ColorMode mode, RenderIntent renderIntent) | 
| Dan Stoza | 076ac67 | 2016-03-14 10:47:53 -0700 | [diff] [blame] | 610 | { | 
| Michael Wright | 5d22d4f | 2018-06-21 02:50:34 +0100 | [diff] [blame] | 611 | // When the color mode is switched to DISPLAY_P3, we want to boost the GPU frequency | 
|  | 612 | // so that GPU composition can finish in time. When color mode is switched from | 
|  | 613 | // DISPLAY_P3, we want to reset GPU frequency. | 
|  | 614 | const bool expensiveRenderingExpected = (mode == ColorMode::DISPLAY_P3); | 
|  | 615 | mPowerAdvisor.setExpensiveRenderingExpected(mId, expensiveRenderingExpected); | 
|  | 616 |  | 
| Peiyong Lin | 0e7a791 | 2018-04-05 14:36:36 -0700 | [diff] [blame] | 617 | auto intError = mComposer.setColorMode(mId, mode, renderIntent); | 
| Dan Stoza | 076ac67 | 2016-03-14 10:47:53 -0700 | [diff] [blame] | 618 | return static_cast<Error>(intError); | 
|  | 619 | } | 
|  | 620 |  | 
| Dan Stoza | 5df2a86 | 2016-03-24 16:19:37 -0700 | [diff] [blame] | 621 | Error Display::setColorTransform(const android::mat4& matrix, | 
|  | 622 | android_color_transform_t hint) | 
|  | 623 | { | 
| Steven Thomas | 94e35b9 | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 624 | auto intError = mComposer.setColorTransform(mId, | 
| Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 625 | matrix.asArray(), static_cast<Hwc2::ColorTransform>(hint)); | 
| Dan Stoza | 5df2a86 | 2016-03-24 16:19:37 -0700 | [diff] [blame] | 626 | return static_cast<Error>(intError); | 
|  | 627 | } | 
|  | 628 |  | 
| Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 629 | Error Display::setOutputBuffer(const sp<GraphicBuffer>& buffer, | 
|  | 630 | const sp<Fence>& releaseFence) | 
|  | 631 | { | 
|  | 632 | int32_t fenceFd = releaseFence->dup(); | 
|  | 633 | auto handle = buffer->getNativeBuffer()->handle; | 
| Steven Thomas | 94e35b9 | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 634 | auto intError = mComposer.setOutputBuffer(mId, handle, fenceFd); | 
| Dan Stoza | 3862898 | 2016-07-13 15:48:58 -0700 | [diff] [blame] | 635 | close(fenceFd); | 
| Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 636 | return static_cast<Error>(intError); | 
|  | 637 | } | 
|  | 638 |  | 
|  | 639 | Error Display::setPowerMode(PowerMode mode) | 
|  | 640 | { | 
| Chia-I Wu | cd8d7f0 | 2016-11-16 11:02:31 +0800 | [diff] [blame] | 641 | auto intMode = static_cast<Hwc2::IComposerClient::PowerMode>(mode); | 
| Steven Thomas | 94e35b9 | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 642 | auto intError = mComposer.setPowerMode(mId, intMode); | 
| Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 643 | return static_cast<Error>(intError); | 
|  | 644 | } | 
|  | 645 |  | 
|  | 646 | Error Display::setVsyncEnabled(Vsync enabled) | 
|  | 647 | { | 
| Chia-I Wu | cd8d7f0 | 2016-11-16 11:02:31 +0800 | [diff] [blame] | 648 | auto intEnabled = static_cast<Hwc2::IComposerClient::Vsync>(enabled); | 
| Steven Thomas | 94e35b9 | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 649 | auto intError = mComposer.setVsyncEnabled(mId, intEnabled); | 
| Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 650 | return static_cast<Error>(intError); | 
|  | 651 | } | 
|  | 652 |  | 
|  | 653 | Error Display::validate(uint32_t* outNumTypes, uint32_t* outNumRequests) | 
|  | 654 | { | 
|  | 655 | uint32_t numTypes = 0; | 
|  | 656 | uint32_t numRequests = 0; | 
| Steven Thomas | 94e35b9 | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 657 | auto intError = mComposer.validateDisplay(mId, &numTypes, &numRequests); | 
| Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 658 | auto error = static_cast<Error>(intError); | 
|  | 659 | if (error != Error::None && error != Error::HasChanges) { | 
|  | 660 | return error; | 
|  | 661 | } | 
|  | 662 |  | 
|  | 663 | *outNumTypes = numTypes; | 
|  | 664 | *outNumRequests = numRequests; | 
|  | 665 | return error; | 
|  | 666 | } | 
|  | 667 |  | 
| Fabien Sanglard | 249c0ae | 2017-06-19 19:22:36 -0700 | [diff] [blame] | 668 | Error Display::presentOrValidate(uint32_t* outNumTypes, uint32_t* outNumRequests, | 
|  | 669 | sp<android::Fence>* outPresentFence, uint32_t* state) { | 
|  | 670 |  | 
|  | 671 | uint32_t numTypes = 0; | 
|  | 672 | uint32_t numRequests = 0; | 
|  | 673 | int32_t presentFenceFd = -1; | 
| Steven Thomas | 94e35b9 | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 674 | auto intError = mComposer.presentOrValidateDisplay( | 
|  | 675 | mId, &numTypes, &numRequests, &presentFenceFd, state); | 
| Fabien Sanglard | 249c0ae | 2017-06-19 19:22:36 -0700 | [diff] [blame] | 676 | auto error = static_cast<Error>(intError); | 
|  | 677 | if (error != Error::None && error != Error::HasChanges) { | 
|  | 678 | return error; | 
|  | 679 | } | 
|  | 680 |  | 
|  | 681 | if (*state == 1) { | 
|  | 682 | *outPresentFence = new Fence(presentFenceFd); | 
|  | 683 | } | 
|  | 684 |  | 
|  | 685 | if (*state == 0) { | 
|  | 686 | *outNumTypes = numTypes; | 
|  | 687 | *outNumRequests = numRequests; | 
|  | 688 | } | 
|  | 689 | return error; | 
|  | 690 | } | 
| Chia-I Wu | 0c6ce46 | 2017-06-22 10:48:28 -0700 | [diff] [blame] | 691 |  | 
| Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 692 | // For use by Device | 
|  | 693 |  | 
| Steven Thomas | 94e35b9 | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 694 | void Display::setConnected(bool connected) { | 
| Steven Thomas | b6c6ad4 | 2018-01-29 12:22:00 -0800 | [diff] [blame] | 695 | if (!mIsConnected && connected) { | 
| Steven Thomas | 94e35b9 | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 696 | mComposer.setClientTargetSlotCount(mId); | 
| Steven Thomas | b6c6ad4 | 2018-01-29 12:22:00 -0800 | [diff] [blame] | 697 | if (mType == DisplayType::Physical) { | 
|  | 698 | loadConfigs(); | 
|  | 699 | } | 
| Steven Thomas | 94e35b9 | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 700 | } | 
|  | 701 | mIsConnected = connected; | 
|  | 702 | } | 
|  | 703 |  | 
| Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 704 | int32_t Display::getAttribute(hwc2_config_t configId, Attribute attribute) | 
|  | 705 | { | 
|  | 706 | int32_t value = 0; | 
| Steven Thomas | 94e35b9 | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 707 | auto intError = mComposer.getDisplayAttribute(mId, configId, | 
| Chia-I Wu | 67e376d | 2016-12-19 11:36:22 +0800 | [diff] [blame] | 708 | static_cast<Hwc2::IComposerClient::Attribute>(attribute), | 
|  | 709 | &value); | 
| Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 710 | auto error = static_cast<Error>(intError); | 
|  | 711 | if (error != Error::None) { | 
|  | 712 | ALOGE("getDisplayAttribute(%" PRIu64 ", %u, %s) failed: %s (%d)", mId, | 
|  | 713 | configId, to_string(attribute).c_str(), | 
|  | 714 | to_string(error).c_str(), intError); | 
|  | 715 | return -1; | 
|  | 716 | } | 
|  | 717 | return value; | 
|  | 718 | } | 
|  | 719 |  | 
|  | 720 | void Display::loadConfig(hwc2_config_t configId) | 
|  | 721 | { | 
|  | 722 | ALOGV("[%" PRIu64 "] loadConfig(%u)", mId, configId); | 
|  | 723 |  | 
|  | 724 | auto config = Config::Builder(*this, configId) | 
|  | 725 | .setWidth(getAttribute(configId, Attribute::Width)) | 
|  | 726 | .setHeight(getAttribute(configId, Attribute::Height)) | 
|  | 727 | .setVsyncPeriod(getAttribute(configId, Attribute::VsyncPeriod)) | 
|  | 728 | .setDpiX(getAttribute(configId, Attribute::DpiX)) | 
|  | 729 | .setDpiY(getAttribute(configId, Attribute::DpiY)) | 
|  | 730 | .build(); | 
|  | 731 | mConfigs.emplace(configId, std::move(config)); | 
|  | 732 | } | 
|  | 733 |  | 
|  | 734 | void Display::loadConfigs() | 
|  | 735 | { | 
|  | 736 | ALOGV("[%" PRIu64 "] loadConfigs", mId); | 
|  | 737 |  | 
| Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 738 | std::vector<Hwc2::Config> configIds; | 
| Steven Thomas | 94e35b9 | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 739 | auto intError = mComposer.getDisplayConfigs(mId, &configIds); | 
| Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 740 | auto error = static_cast<Error>(intError); | 
| Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 741 | if (error != Error::None) { | 
|  | 742 | ALOGE("[%" PRIu64 "] getDisplayConfigs [2] failed: %s (%d)", mId, | 
|  | 743 | to_string(error).c_str(), intError); | 
|  | 744 | return; | 
|  | 745 | } | 
|  | 746 |  | 
|  | 747 | for (auto configId : configIds) { | 
|  | 748 | loadConfig(configId); | 
|  | 749 | } | 
|  | 750 | } | 
|  | 751 |  | 
| Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 752 | // Other Display methods | 
|  | 753 |  | 
| Steven Thomas | 94e35b9 | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 754 | Layer* Display::getLayerById(hwc2_layer_t id) const | 
| Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 755 | { | 
|  | 756 | if (mLayers.count(id) == 0) { | 
|  | 757 | return nullptr; | 
|  | 758 | } | 
|  | 759 |  | 
| Steven Thomas | 94e35b9 | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 760 | return mLayers.at(id).get(); | 
| Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 761 | } | 
|  | 762 |  | 
|  | 763 | // Layer methods | 
|  | 764 |  | 
| Courtney Goeltzenleuchter | f9c98e5 | 2018-02-12 07:23:17 -0700 | [diff] [blame] | 765 | Layer::Layer(android::Hwc2::Composer& composer, const std::unordered_set<Capability>& capabilities, | 
| Steven Thomas | 94e35b9 | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 766 | hwc2_display_t displayId, hwc2_layer_t layerId) | 
|  | 767 | : mComposer(composer), | 
|  | 768 | mCapabilities(capabilities), | 
|  | 769 | mDisplayId(displayId), | 
|  | 770 | mId(layerId) | 
| Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 771 | { | 
| Steven Thomas | 94e35b9 | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 772 | ALOGV("Created layer %" PRIu64 " on display %" PRIu64, layerId, displayId); | 
| Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 773 | } | 
|  | 774 |  | 
|  | 775 | Layer::~Layer() | 
|  | 776 | { | 
| Steven Thomas | 94e35b9 | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 777 | auto intError = mComposer.destroyLayer(mDisplayId, mId); | 
|  | 778 | auto error = static_cast<Error>(intError); | 
|  | 779 | ALOGE_IF(error != Error::None, "destroyLayer(%" PRIu64 ", %" PRIu64 ")" | 
|  | 780 | " failed: %s (%d)", mDisplayId, mId, to_string(error).c_str(), | 
|  | 781 | intError); | 
|  | 782 | if (mLayerDestroyedListener) { | 
|  | 783 | mLayerDestroyedListener(this); | 
| Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 784 | } | 
|  | 785 | } | 
|  | 786 |  | 
| Steven Thomas | 94e35b9 | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 787 | void Layer::setLayerDestroyedListener(std::function<void(Layer*)> listener) { | 
|  | 788 | LOG_ALWAYS_FATAL_IF(mLayerDestroyedListener && listener, | 
|  | 789 | "Attempt to set layer destroyed listener multiple times"); | 
|  | 790 | mLayerDestroyedListener = listener; | 
|  | 791 | } | 
|  | 792 |  | 
| Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 793 | Error Layer::setCursorPosition(int32_t x, int32_t y) | 
|  | 794 | { | 
| Steven Thomas | 94e35b9 | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 795 | auto intError = mComposer.setCursorPosition(mDisplayId, mId, x, y); | 
| Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 796 | return static_cast<Error>(intError); | 
|  | 797 | } | 
|  | 798 |  | 
| Daniel Nicoara | 1f42e3a | 2017-04-10 13:27:32 -0400 | [diff] [blame] | 799 | Error Layer::setBuffer(uint32_t slot, const sp<GraphicBuffer>& buffer, | 
| Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 800 | const sp<Fence>& acquireFence) | 
|  | 801 | { | 
|  | 802 | int32_t fenceFd = acquireFence->dup(); | 
| Steven Thomas | 94e35b9 | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 803 | auto intError = mComposer.setLayerBuffer(mDisplayId, mId, slot, buffer, | 
|  | 804 | fenceFd); | 
| Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 805 | return static_cast<Error>(intError); | 
|  | 806 | } | 
|  | 807 |  | 
|  | 808 | Error Layer::setSurfaceDamage(const Region& damage) | 
|  | 809 | { | 
|  | 810 | // We encode default full-screen damage as INVALID_RECT upstream, but as 0 | 
|  | 811 | // rects for HWC | 
| Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 812 | Hwc2::Error intError = Hwc2::Error::NONE; | 
| Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 813 | if (damage.isRect() && damage.getBounds() == Rect::INVALID_RECT) { | 
| Steven Thomas | 94e35b9 | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 814 | intError = mComposer.setLayerSurfaceDamage(mDisplayId, | 
| Chia-I Wu | cd8d7f0 | 2016-11-16 11:02:31 +0800 | [diff] [blame] | 815 | mId, std::vector<Hwc2::IComposerClient::Rect>()); | 
| Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 816 | } else { | 
|  | 817 | size_t rectCount = 0; | 
|  | 818 | auto rectArray = damage.getArray(&rectCount); | 
|  | 819 |  | 
| Chia-I Wu | cd8d7f0 | 2016-11-16 11:02:31 +0800 | [diff] [blame] | 820 | std::vector<Hwc2::IComposerClient::Rect> hwcRects; | 
| Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 821 | for (size_t rect = 0; rect < rectCount; ++rect) { | 
|  | 822 | hwcRects.push_back({rectArray[rect].left, rectArray[rect].top, | 
|  | 823 | rectArray[rect].right, rectArray[rect].bottom}); | 
|  | 824 | } | 
|  | 825 |  | 
| Steven Thomas | 94e35b9 | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 826 | intError = mComposer.setLayerSurfaceDamage(mDisplayId, mId, hwcRects); | 
| Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 827 | } | 
|  | 828 |  | 
|  | 829 | return static_cast<Error>(intError); | 
|  | 830 | } | 
|  | 831 |  | 
|  | 832 | Error Layer::setBlendMode(BlendMode mode) | 
|  | 833 | { | 
| Chia-I Wu | cd8d7f0 | 2016-11-16 11:02:31 +0800 | [diff] [blame] | 834 | auto intMode = static_cast<Hwc2::IComposerClient::BlendMode>(mode); | 
| Steven Thomas | 94e35b9 | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 835 | auto intError = mComposer.setLayerBlendMode(mDisplayId, mId, intMode); | 
| Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 836 | return static_cast<Error>(intError); | 
|  | 837 | } | 
|  | 838 |  | 
|  | 839 | Error Layer::setColor(hwc_color_t color) | 
|  | 840 | { | 
| Chia-I Wu | cd8d7f0 | 2016-11-16 11:02:31 +0800 | [diff] [blame] | 841 | Hwc2::IComposerClient::Color hwcColor{color.r, color.g, color.b, color.a}; | 
| Steven Thomas | 94e35b9 | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 842 | auto intError = mComposer.setLayerColor(mDisplayId, mId, hwcColor); | 
| Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 843 | return static_cast<Error>(intError); | 
|  | 844 | } | 
|  | 845 |  | 
|  | 846 | Error Layer::setCompositionType(Composition type) | 
|  | 847 | { | 
| Chia-I Wu | cd8d7f0 | 2016-11-16 11:02:31 +0800 | [diff] [blame] | 848 | auto intType = static_cast<Hwc2::IComposerClient::Composition>(type); | 
| Steven Thomas | 94e35b9 | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 849 | auto intError = mComposer.setLayerCompositionType( | 
|  | 850 | mDisplayId, mId, intType); | 
| Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 851 | return static_cast<Error>(intError); | 
|  | 852 | } | 
|  | 853 |  | 
| Peiyong Lin | 34beb7a | 2018-03-28 11:57:12 -0700 | [diff] [blame] | 854 | Error Layer::setDataspace(Dataspace dataspace) | 
| Dan Stoza | 5df2a86 | 2016-03-24 16:19:37 -0700 | [diff] [blame] | 855 | { | 
| Courtney Goeltzenleuchter | c988ee4 | 2017-05-31 17:56:46 -0600 | [diff] [blame] | 856 | if (dataspace == mDataSpace) { | 
|  | 857 | return Error::None; | 
|  | 858 | } | 
|  | 859 | mDataSpace = dataspace; | 
| Peiyong Lin | 34beb7a | 2018-03-28 11:57:12 -0700 | [diff] [blame] | 860 | auto intError = mComposer.setLayerDataspace(mDisplayId, mId, mDataSpace); | 
| Dan Stoza | 5df2a86 | 2016-03-24 16:19:37 -0700 | [diff] [blame] | 861 | return static_cast<Error>(intError); | 
|  | 862 | } | 
|  | 863 |  | 
| Peiyong Lin | 0ac5f4e | 2018-04-19 22:06:34 -0700 | [diff] [blame] | 864 | Error Layer::setPerFrameMetadata(const int32_t supportedPerFrameMetadata, | 
|  | 865 | const android::HdrMetadata& metadata) | 
|  | 866 | { | 
| Courtney Goeltzenleuchter | f9c98e5 | 2018-02-12 07:23:17 -0700 | [diff] [blame] | 867 | if (metadata == mHdrMetadata) { | 
|  | 868 | return Error::None; | 
|  | 869 | } | 
|  | 870 |  | 
|  | 871 | mHdrMetadata = metadata; | 
| Peiyong Lin | 0ac5f4e | 2018-04-19 22:06:34 -0700 | [diff] [blame] | 872 | int validTypes = mHdrMetadata.validTypes & supportedPerFrameMetadata; | 
|  | 873 | std::vector<Hwc2::PerFrameMetadata> perFrameMetadatas; | 
|  | 874 | if (validTypes & HdrMetadata::SMPTE2086) { | 
|  | 875 | perFrameMetadatas.insert(perFrameMetadatas.end(), | 
|  | 876 | {{Hwc2::PerFrameMetadataKey::DISPLAY_RED_PRIMARY_X, | 
|  | 877 | mHdrMetadata.smpte2086.displayPrimaryRed.x}, | 
|  | 878 | {Hwc2::PerFrameMetadataKey::DISPLAY_RED_PRIMARY_Y, | 
|  | 879 | mHdrMetadata.smpte2086.displayPrimaryRed.y}, | 
|  | 880 | {Hwc2::PerFrameMetadataKey::DISPLAY_GREEN_PRIMARY_X, | 
|  | 881 | mHdrMetadata.smpte2086.displayPrimaryGreen.x}, | 
|  | 882 | {Hwc2::PerFrameMetadataKey::DISPLAY_GREEN_PRIMARY_Y, | 
|  | 883 | mHdrMetadata.smpte2086.displayPrimaryGreen.y}, | 
|  | 884 | {Hwc2::PerFrameMetadataKey::DISPLAY_BLUE_PRIMARY_X, | 
|  | 885 | mHdrMetadata.smpte2086.displayPrimaryBlue.x}, | 
|  | 886 | {Hwc2::PerFrameMetadataKey::DISPLAY_BLUE_PRIMARY_Y, | 
|  | 887 | mHdrMetadata.smpte2086.displayPrimaryBlue.y}, | 
|  | 888 | {Hwc2::PerFrameMetadataKey::WHITE_POINT_X, | 
|  | 889 | mHdrMetadata.smpte2086.whitePoint.x}, | 
|  | 890 | {Hwc2::PerFrameMetadataKey::WHITE_POINT_Y, | 
|  | 891 | mHdrMetadata.smpte2086.whitePoint.y}, | 
|  | 892 | {Hwc2::PerFrameMetadataKey::MAX_LUMINANCE, | 
|  | 893 | mHdrMetadata.smpte2086.maxLuminance}, | 
|  | 894 | {Hwc2::PerFrameMetadataKey::MIN_LUMINANCE, | 
|  | 895 | mHdrMetadata.smpte2086.minLuminance}}); | 
|  | 896 | } | 
|  | 897 |  | 
|  | 898 | if (validTypes & HdrMetadata::CTA861_3) { | 
|  | 899 | perFrameMetadatas.insert(perFrameMetadatas.end(), | 
|  | 900 | {{Hwc2::PerFrameMetadataKey::MAX_CONTENT_LIGHT_LEVEL, | 
|  | 901 | mHdrMetadata.cta8613.maxContentLightLevel}, | 
|  | 902 | {Hwc2::PerFrameMetadataKey::MAX_FRAME_AVERAGE_LIGHT_LEVEL, | 
|  | 903 | mHdrMetadata.cta8613.maxFrameAverageLightLevel}}); | 
|  | 904 | } | 
|  | 905 |  | 
|  | 906 | auto intError = mComposer.setLayerPerFrameMetadata(mDisplayId, mId, perFrameMetadatas); | 
| Courtney Goeltzenleuchter | f9c98e5 | 2018-02-12 07:23:17 -0700 | [diff] [blame] | 907 | return static_cast<Error>(intError); | 
|  | 908 | } | 
|  | 909 |  | 
| Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 910 | Error Layer::setDisplayFrame(const Rect& frame) | 
|  | 911 | { | 
| Chia-I Wu | cd8d7f0 | 2016-11-16 11:02:31 +0800 | [diff] [blame] | 912 | Hwc2::IComposerClient::Rect hwcRect{frame.left, frame.top, | 
| Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 913 | frame.right, frame.bottom}; | 
| Steven Thomas | 94e35b9 | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 914 | auto intError = mComposer.setLayerDisplayFrame(mDisplayId, mId, hwcRect); | 
| Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 915 | return static_cast<Error>(intError); | 
|  | 916 | } | 
|  | 917 |  | 
|  | 918 | Error Layer::setPlaneAlpha(float alpha) | 
|  | 919 | { | 
| Steven Thomas | 94e35b9 | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 920 | auto intError = mComposer.setLayerPlaneAlpha(mDisplayId, mId, alpha); | 
| Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 921 | return static_cast<Error>(intError); | 
|  | 922 | } | 
|  | 923 |  | 
|  | 924 | Error Layer::setSidebandStream(const native_handle_t* stream) | 
|  | 925 | { | 
| Steven Thomas | 94e35b9 | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 926 | if (mCapabilities.count(Capability::SidebandStream) == 0) { | 
| Dan Stoza | 09e7a27 | 2016-04-14 12:31:01 -0700 | [diff] [blame] | 927 | ALOGE("Attempted to call setSidebandStream without checking that the " | 
|  | 928 | "device supports sideband streams"); | 
|  | 929 | return Error::Unsupported; | 
|  | 930 | } | 
| Steven Thomas | 94e35b9 | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 931 | auto intError = mComposer.setLayerSidebandStream(mDisplayId, mId, stream); | 
| Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 932 | return static_cast<Error>(intError); | 
|  | 933 | } | 
|  | 934 |  | 
|  | 935 | Error Layer::setSourceCrop(const FloatRect& crop) | 
|  | 936 | { | 
| Chia-I Wu | cd8d7f0 | 2016-11-16 11:02:31 +0800 | [diff] [blame] | 937 | Hwc2::IComposerClient::FRect hwcRect{ | 
| Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 938 | crop.left, crop.top, crop.right, crop.bottom}; | 
| Steven Thomas | 94e35b9 | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 939 | auto intError = mComposer.setLayerSourceCrop(mDisplayId, mId, hwcRect); | 
| Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 940 | return static_cast<Error>(intError); | 
|  | 941 | } | 
|  | 942 |  | 
|  | 943 | Error Layer::setTransform(Transform transform) | 
|  | 944 | { | 
| Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 945 | auto intTransform = static_cast<Hwc2::Transform>(transform); | 
| Steven Thomas | 94e35b9 | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 946 | auto intError = mComposer.setLayerTransform(mDisplayId, mId, intTransform); | 
| Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 947 | return static_cast<Error>(intError); | 
|  | 948 | } | 
|  | 949 |  | 
|  | 950 | Error Layer::setVisibleRegion(const Region& region) | 
|  | 951 | { | 
|  | 952 | size_t rectCount = 0; | 
|  | 953 | auto rectArray = region.getArray(&rectCount); | 
|  | 954 |  | 
| Chia-I Wu | cd8d7f0 | 2016-11-16 11:02:31 +0800 | [diff] [blame] | 955 | std::vector<Hwc2::IComposerClient::Rect> hwcRects; | 
| Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 956 | for (size_t rect = 0; rect < rectCount; ++rect) { | 
|  | 957 | hwcRects.push_back({rectArray[rect].left, rectArray[rect].top, | 
|  | 958 | rectArray[rect].right, rectArray[rect].bottom}); | 
|  | 959 | } | 
|  | 960 |  | 
| Steven Thomas | 94e35b9 | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 961 | auto intError = mComposer.setLayerVisibleRegion(mDisplayId, mId, hwcRects); | 
| Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 962 | return static_cast<Error>(intError); | 
|  | 963 | } | 
|  | 964 |  | 
|  | 965 | Error Layer::setZOrder(uint32_t z) | 
|  | 966 | { | 
| Steven Thomas | 94e35b9 | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 967 | auto intError = mComposer.setLayerZOrder(mDisplayId, mId, z); | 
| Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 968 | return static_cast<Error>(intError); | 
|  | 969 | } | 
|  | 970 |  | 
| Daniel Nicoara | 2f5f8a5 | 2016-12-20 16:11:58 -0500 | [diff] [blame] | 971 | Error Layer::setInfo(uint32_t type, uint32_t appId) | 
|  | 972 | { | 
| Steven Thomas | 94e35b9 | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 973 | auto intError = mComposer.setLayerInfo(mDisplayId, mId, type, appId); | 
| Daniel Nicoara | 2f5f8a5 | 2016-12-20 16:11:58 -0500 | [diff] [blame] | 974 | return static_cast<Error>(intError); | 
|  | 975 | } | 
|  | 976 |  | 
| Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 977 | } // namespace HWC2 |