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 | |
Dan Stoza | 09e7a27 | 2016-04-14 12:31:01 -0700 | [diff] [blame] | 33 | #include <algorithm> |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 34 | #include <inttypes.h> |
| 35 | |
| 36 | extern "C" { |
| 37 | static void hotplug_hook(hwc2_callback_data_t callbackData, |
| 38 | hwc2_display_t displayId, int32_t intConnected) { |
| 39 | auto device = static_cast<HWC2::Device*>(callbackData); |
| 40 | auto display = device->getDisplayById(displayId); |
| 41 | if (display) { |
| 42 | auto connected = static_cast<HWC2::Connection>(intConnected); |
| 43 | device->callHotplug(std::move(display), connected); |
| 44 | } else { |
| 45 | ALOGE("Hotplug callback called with unknown display %" PRIu64, |
| 46 | displayId); |
| 47 | } |
| 48 | } |
| 49 | |
| 50 | static void refresh_hook(hwc2_callback_data_t callbackData, |
| 51 | hwc2_display_t displayId) { |
| 52 | auto device = static_cast<HWC2::Device*>(callbackData); |
| 53 | auto display = device->getDisplayById(displayId); |
| 54 | if (display) { |
| 55 | device->callRefresh(std::move(display)); |
| 56 | } else { |
| 57 | ALOGE("Refresh callback called with unknown display %" PRIu64, |
| 58 | displayId); |
| 59 | } |
| 60 | } |
| 61 | |
| 62 | static void vsync_hook(hwc2_callback_data_t callbackData, |
| 63 | hwc2_display_t displayId, int64_t timestamp) { |
| 64 | auto device = static_cast<HWC2::Device*>(callbackData); |
| 65 | auto display = device->getDisplayById(displayId); |
| 66 | if (display) { |
| 67 | device->callVsync(std::move(display), timestamp); |
| 68 | } else { |
| 69 | ALOGE("Vsync callback called with unknown display %" PRIu64, |
| 70 | displayId); |
| 71 | } |
| 72 | } |
| 73 | } |
| 74 | |
| 75 | using android::Fence; |
Dan Stoza | 5a423ea | 2017-02-16 14:10:39 -0800 | [diff] [blame] | 76 | using android::FloatRect; |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 77 | using android::GraphicBuffer; |
Dan Stoza | 7d7ae73 | 2016-03-16 12:23:40 -0700 | [diff] [blame] | 78 | using android::HdrCapabilities; |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 79 | using android::Rect; |
| 80 | using android::Region; |
| 81 | using android::sp; |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 82 | using android::hardware::Return; |
| 83 | using android::hardware::Void; |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 84 | |
| 85 | namespace HWC2 { |
| 86 | |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 87 | namespace Hwc2 = android::Hwc2; |
| 88 | |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 89 | // Device methods |
| 90 | |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 91 | #ifdef BYPASS_IHWC |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 92 | Device::Device(hwc2_device_t* device) |
| 93 | : mHwcDevice(device), |
| 94 | mCreateVirtualDisplay(nullptr), |
| 95 | mDestroyVirtualDisplay(nullptr), |
| 96 | mDump(nullptr), |
| 97 | mGetMaxVirtualDisplayCount(nullptr), |
| 98 | mRegisterCallback(nullptr), |
| 99 | mAcceptDisplayChanges(nullptr), |
| 100 | mCreateLayer(nullptr), |
| 101 | mDestroyLayer(nullptr), |
| 102 | mGetActiveConfig(nullptr), |
| 103 | mGetChangedCompositionTypes(nullptr), |
Dan Stoza | 076ac67 | 2016-03-14 10:47:53 -0700 | [diff] [blame] | 104 | mGetColorModes(nullptr), |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 105 | mGetDisplayAttribute(nullptr), |
| 106 | mGetDisplayConfigs(nullptr), |
| 107 | mGetDisplayName(nullptr), |
| 108 | mGetDisplayRequests(nullptr), |
| 109 | mGetDisplayType(nullptr), |
| 110 | mGetDozeSupport(nullptr), |
Dan Stoza | 7d7ae73 | 2016-03-16 12:23:40 -0700 | [diff] [blame] | 111 | mGetHdrCapabilities(nullptr), |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 112 | mGetReleaseFences(nullptr), |
| 113 | mPresentDisplay(nullptr), |
| 114 | mSetActiveConfig(nullptr), |
| 115 | mSetClientTarget(nullptr), |
Dan Stoza | 076ac67 | 2016-03-14 10:47:53 -0700 | [diff] [blame] | 116 | mSetColorMode(nullptr), |
Dan Stoza | 5df2a86 | 2016-03-24 16:19:37 -0700 | [diff] [blame] | 117 | mSetColorTransform(nullptr), |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 118 | mSetOutputBuffer(nullptr), |
| 119 | mSetPowerMode(nullptr), |
| 120 | mSetVsyncEnabled(nullptr), |
| 121 | mValidateDisplay(nullptr), |
| 122 | mSetCursorPosition(nullptr), |
| 123 | mSetLayerBuffer(nullptr), |
| 124 | mSetLayerSurfaceDamage(nullptr), |
| 125 | mSetLayerBlendMode(nullptr), |
| 126 | mSetLayerColor(nullptr), |
| 127 | mSetLayerCompositionType(nullptr), |
Dan Stoza | 5df2a86 | 2016-03-24 16:19:37 -0700 | [diff] [blame] | 128 | mSetLayerDataspace(nullptr), |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 129 | mSetLayerDisplayFrame(nullptr), |
| 130 | mSetLayerPlaneAlpha(nullptr), |
| 131 | mSetLayerSidebandStream(nullptr), |
| 132 | mSetLayerSourceCrop(nullptr), |
| 133 | mSetLayerTransform(nullptr), |
| 134 | mSetLayerVisibleRegion(nullptr), |
| 135 | mSetLayerZOrder(nullptr), |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 136 | #else |
Hendrik Wagenaar | 87670ff | 2017-02-01 12:10:46 -0800 | [diff] [blame] | 137 | Device::Device(bool useVrComposer) |
| 138 | : mComposer(std::make_unique<Hwc2::Composer>(useVrComposer)), |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 139 | #endif // BYPASS_IHWC |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 140 | mCapabilities(), |
| 141 | mDisplays(), |
| 142 | mHotplug(), |
| 143 | mPendingHotplugs(), |
| 144 | mRefresh(), |
| 145 | mPendingRefreshes(), |
| 146 | mVsync(), |
| 147 | mPendingVsyncs() |
| 148 | { |
| 149 | loadCapabilities(); |
| 150 | loadFunctionPointers(); |
| 151 | registerCallbacks(); |
| 152 | } |
| 153 | |
| 154 | Device::~Device() |
| 155 | { |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 156 | #ifdef BYPASS_IHWC |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 157 | if (mHwcDevice == nullptr) { |
| 158 | return; |
| 159 | } |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 160 | #endif |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 161 | |
| 162 | for (auto element : mDisplays) { |
Dan Stoza | 3862898 | 2016-07-13 15:48:58 -0700 | [diff] [blame] | 163 | auto display = element.second.lock(); |
| 164 | if (!display) { |
| 165 | ALOGE("~Device: Found a display (%" PRId64 " that has already been" |
| 166 | " destroyed", element.first); |
| 167 | continue; |
| 168 | } |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 169 | |
| 170 | DisplayType displayType = HWC2::DisplayType::Invalid; |
| 171 | auto error = display->getType(&displayType); |
| 172 | if (error != Error::None) { |
| 173 | ALOGE("~Device: Failed to determine type of display %" PRIu64 |
| 174 | ": %s (%d)", display->getId(), to_string(error).c_str(), |
| 175 | static_cast<int32_t>(error)); |
| 176 | continue; |
| 177 | } |
| 178 | |
| 179 | if (displayType == HWC2::DisplayType::Physical) { |
| 180 | error = display->setVsyncEnabled(HWC2::Vsync::Disable); |
| 181 | if (error != Error::None) { |
| 182 | ALOGE("~Device: Failed to disable vsync for display %" PRIu64 |
| 183 | ": %s (%d)", display->getId(), to_string(error).c_str(), |
| 184 | static_cast<int32_t>(error)); |
| 185 | } |
| 186 | } |
| 187 | } |
| 188 | |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 189 | #ifdef BYPASS_IHWC |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 190 | hwc2_close(mHwcDevice); |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 191 | #endif |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 192 | } |
| 193 | |
| 194 | // Required by HWC2 device |
| 195 | |
| 196 | std::string Device::dump() const |
| 197 | { |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 198 | #ifdef BYPASS_IHWC |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 199 | uint32_t numBytes = 0; |
| 200 | mDump(mHwcDevice, &numBytes, nullptr); |
| 201 | |
| 202 | std::vector<char> buffer(numBytes); |
| 203 | mDump(mHwcDevice, &numBytes, buffer.data()); |
| 204 | |
| 205 | return std::string(buffer.data(), buffer.size()); |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 206 | #else |
| 207 | return mComposer->dumpDebugInfo(); |
| 208 | #endif |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 209 | } |
| 210 | |
| 211 | uint32_t Device::getMaxVirtualDisplayCount() const |
| 212 | { |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 213 | #ifdef BYPASS_IHWC |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 214 | return mGetMaxVirtualDisplayCount(mHwcDevice); |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 215 | #else |
| 216 | return mComposer->getMaxVirtualDisplayCount(); |
| 217 | #endif |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 218 | } |
| 219 | |
| 220 | Error Device::createVirtualDisplay(uint32_t width, uint32_t height, |
Dan Stoza | 5cf424b | 2016-05-20 14:02:39 -0700 | [diff] [blame] | 221 | android_pixel_format_t* format, std::shared_ptr<Display>* outDisplay) |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 222 | { |
| 223 | ALOGI("Creating virtual display"); |
| 224 | |
| 225 | hwc2_display_t displayId = 0; |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 226 | #ifdef BYPASS_IHWC |
Dan Stoza | 5cf424b | 2016-05-20 14:02:39 -0700 | [diff] [blame] | 227 | int32_t intFormat = static_cast<int32_t>(*format); |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 228 | int32_t intError = mCreateVirtualDisplay(mHwcDevice, width, height, |
Dan Stoza | 5cf424b | 2016-05-20 14:02:39 -0700 | [diff] [blame] | 229 | &intFormat, &displayId); |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 230 | #else |
| 231 | auto intFormat = static_cast<Hwc2::PixelFormat>(*format); |
| 232 | auto intError = mComposer->createVirtualDisplay(width, height, |
Chia-I Wu | 67e376d | 2016-12-19 11:36:22 +0800 | [diff] [blame] | 233 | &intFormat, &displayId); |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 234 | #endif |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 235 | auto error = static_cast<Error>(intError); |
| 236 | if (error != Error::None) { |
| 237 | return error; |
| 238 | } |
| 239 | |
| 240 | ALOGI("Created virtual display"); |
Dan Stoza | 5cf424b | 2016-05-20 14:02:39 -0700 | [diff] [blame] | 241 | *format = static_cast<android_pixel_format_t>(intFormat); |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 242 | *outDisplay = getDisplayById(displayId); |
Dan Stoza | 3862898 | 2016-07-13 15:48:58 -0700 | [diff] [blame] | 243 | if (!*outDisplay) { |
| 244 | ALOGE("Failed to get display by id"); |
| 245 | return Error::BadDisplay; |
| 246 | } |
Chris Forbes | ceb67d1 | 2017-04-11 12:20:00 -0700 | [diff] [blame] | 247 | (*outDisplay)->setConnected(true); |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 248 | return Error::None; |
| 249 | } |
| 250 | |
| 251 | void Device::registerHotplugCallback(HotplugCallback hotplug) |
| 252 | { |
| 253 | ALOGV("registerHotplugCallback"); |
| 254 | mHotplug = hotplug; |
| 255 | for (auto& pending : mPendingHotplugs) { |
| 256 | auto& display = pending.first; |
| 257 | auto connected = pending.second; |
| 258 | ALOGV("Sending pending hotplug(%" PRIu64 ", %s)", display->getId(), |
| 259 | to_string(connected).c_str()); |
| 260 | mHotplug(std::move(display), connected); |
| 261 | } |
| 262 | } |
| 263 | |
| 264 | void Device::registerRefreshCallback(RefreshCallback refresh) |
| 265 | { |
| 266 | mRefresh = refresh; |
| 267 | for (auto& pending : mPendingRefreshes) { |
| 268 | mRefresh(std::move(pending)); |
| 269 | } |
| 270 | } |
| 271 | |
| 272 | void Device::registerVsyncCallback(VsyncCallback vsync) |
| 273 | { |
| 274 | mVsync = vsync; |
| 275 | for (auto& pending : mPendingVsyncs) { |
| 276 | auto& display = pending.first; |
| 277 | auto timestamp = pending.second; |
| 278 | mVsync(std::move(display), timestamp); |
| 279 | } |
| 280 | } |
| 281 | |
| 282 | // For use by Device callbacks |
| 283 | |
| 284 | void Device::callHotplug(std::shared_ptr<Display> display, Connection connected) |
| 285 | { |
| 286 | if (connected == Connection::Connected) { |
| 287 | if (!display->isConnected()) { |
Chia-I Wu | cd8d7f0 | 2016-11-16 11:02:31 +0800 | [diff] [blame] | 288 | #ifndef BYPASS_IHWC |
| 289 | mComposer->setClientTargetSlotCount(display->getId()); |
| 290 | #endif |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 291 | display->loadConfigs(); |
| 292 | display->setConnected(true); |
| 293 | } |
| 294 | } else { |
| 295 | display->setConnected(false); |
| 296 | mDisplays.erase(display->getId()); |
| 297 | } |
| 298 | |
| 299 | if (mHotplug) { |
| 300 | mHotplug(std::move(display), connected); |
| 301 | } else { |
| 302 | ALOGV("callHotplug called, but no valid callback registered, storing"); |
| 303 | mPendingHotplugs.emplace_back(std::move(display), connected); |
| 304 | } |
| 305 | } |
| 306 | |
| 307 | void Device::callRefresh(std::shared_ptr<Display> display) |
| 308 | { |
| 309 | if (mRefresh) { |
| 310 | mRefresh(std::move(display)); |
| 311 | } else { |
| 312 | ALOGV("callRefresh called, but no valid callback registered, storing"); |
| 313 | mPendingRefreshes.emplace_back(std::move(display)); |
| 314 | } |
| 315 | } |
| 316 | |
| 317 | void Device::callVsync(std::shared_ptr<Display> display, nsecs_t timestamp) |
| 318 | { |
| 319 | if (mVsync) { |
| 320 | mVsync(std::move(display), timestamp); |
| 321 | } else { |
| 322 | ALOGV("callVsync called, but no valid callback registered, storing"); |
| 323 | mPendingVsyncs.emplace_back(std::move(display), timestamp); |
| 324 | } |
| 325 | } |
| 326 | |
| 327 | // Other Device methods |
| 328 | |
| 329 | std::shared_ptr<Display> Device::getDisplayById(hwc2_display_t id) { |
| 330 | if (mDisplays.count(id) != 0) { |
Dan Stoza | 3862898 | 2016-07-13 15:48:58 -0700 | [diff] [blame] | 331 | auto strongDisplay = mDisplays[id].lock(); |
| 332 | ALOGE_IF(!strongDisplay, "Display %" PRId64 " is in mDisplays but is no" |
| 333 | " longer alive", id); |
| 334 | return strongDisplay; |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 335 | } |
| 336 | |
| 337 | auto display = std::make_shared<Display>(*this, id); |
| 338 | mDisplays.emplace(id, display); |
| 339 | return display; |
| 340 | } |
| 341 | |
| 342 | // Device initialization methods |
| 343 | |
| 344 | void Device::loadCapabilities() |
| 345 | { |
| 346 | static_assert(sizeof(Capability) == sizeof(int32_t), |
| 347 | "Capability size has changed"); |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 348 | #ifdef BYPASS_IHWC |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 349 | uint32_t numCapabilities = 0; |
| 350 | mHwcDevice->getCapabilities(mHwcDevice, &numCapabilities, nullptr); |
Dan Stoza | 9f26a9c | 2016-06-22 14:51:09 -0700 | [diff] [blame] | 351 | std::vector<Capability> capabilities(numCapabilities); |
| 352 | auto asInt = reinterpret_cast<int32_t*>(capabilities.data()); |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 353 | mHwcDevice->getCapabilities(mHwcDevice, &numCapabilities, asInt); |
Dan Stoza | 9f26a9c | 2016-06-22 14:51:09 -0700 | [diff] [blame] | 354 | for (auto capability : capabilities) { |
| 355 | mCapabilities.emplace(capability); |
| 356 | } |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 357 | #else |
| 358 | auto capabilities = mComposer->getCapabilities(); |
| 359 | for (auto capability : capabilities) { |
| 360 | mCapabilities.emplace(static_cast<Capability>(capability)); |
| 361 | } |
| 362 | #endif |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 363 | } |
| 364 | |
Dan Stoza | 09e7a27 | 2016-04-14 12:31:01 -0700 | [diff] [blame] | 365 | bool Device::hasCapability(HWC2::Capability capability) const |
| 366 | { |
| 367 | return std::find(mCapabilities.cbegin(), mCapabilities.cend(), |
| 368 | capability) != mCapabilities.cend(); |
| 369 | } |
| 370 | |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 371 | void Device::loadFunctionPointers() |
| 372 | { |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 373 | #ifdef BYPASS_IHWC |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 374 | // For all of these early returns, we log an error message inside |
| 375 | // loadFunctionPointer specifying which function failed to load |
| 376 | |
| 377 | // Display function pointers |
Dan Stoza | 7d7ae73 | 2016-03-16 12:23:40 -0700 | [diff] [blame] | 378 | if (!loadFunctionPointer(FunctionDescriptor::CreateVirtualDisplay, |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 379 | mCreateVirtualDisplay)) return; |
Dan Stoza | 7d7ae73 | 2016-03-16 12:23:40 -0700 | [diff] [blame] | 380 | if (!loadFunctionPointer(FunctionDescriptor::DestroyVirtualDisplay, |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 381 | mDestroyVirtualDisplay)) return; |
Dan Stoza | 7d7ae73 | 2016-03-16 12:23:40 -0700 | [diff] [blame] | 382 | if (!loadFunctionPointer(FunctionDescriptor::Dump, mDump)) return; |
| 383 | if (!loadFunctionPointer(FunctionDescriptor::GetMaxVirtualDisplayCount, |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 384 | mGetMaxVirtualDisplayCount)) return; |
Dan Stoza | 7d7ae73 | 2016-03-16 12:23:40 -0700 | [diff] [blame] | 385 | if (!loadFunctionPointer(FunctionDescriptor::RegisterCallback, |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 386 | mRegisterCallback)) return; |
| 387 | |
| 388 | // Device function pointers |
Dan Stoza | 7d7ae73 | 2016-03-16 12:23:40 -0700 | [diff] [blame] | 389 | if (!loadFunctionPointer(FunctionDescriptor::AcceptDisplayChanges, |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 390 | mAcceptDisplayChanges)) return; |
Dan Stoza | 7d7ae73 | 2016-03-16 12:23:40 -0700 | [diff] [blame] | 391 | if (!loadFunctionPointer(FunctionDescriptor::CreateLayer, |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 392 | mCreateLayer)) return; |
Dan Stoza | 7d7ae73 | 2016-03-16 12:23:40 -0700 | [diff] [blame] | 393 | if (!loadFunctionPointer(FunctionDescriptor::DestroyLayer, |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 394 | mDestroyLayer)) return; |
Dan Stoza | 7d7ae73 | 2016-03-16 12:23:40 -0700 | [diff] [blame] | 395 | if (!loadFunctionPointer(FunctionDescriptor::GetActiveConfig, |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 396 | mGetActiveConfig)) return; |
Dan Stoza | 7d7ae73 | 2016-03-16 12:23:40 -0700 | [diff] [blame] | 397 | if (!loadFunctionPointer(FunctionDescriptor::GetChangedCompositionTypes, |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 398 | mGetChangedCompositionTypes)) return; |
Dan Stoza | 076ac67 | 2016-03-14 10:47:53 -0700 | [diff] [blame] | 399 | if (!loadFunctionPointer(FunctionDescriptor::GetColorModes, |
| 400 | mGetColorModes)) return; |
Dan Stoza | 7d7ae73 | 2016-03-16 12:23:40 -0700 | [diff] [blame] | 401 | if (!loadFunctionPointer(FunctionDescriptor::GetDisplayAttribute, |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 402 | mGetDisplayAttribute)) return; |
Dan Stoza | 7d7ae73 | 2016-03-16 12:23:40 -0700 | [diff] [blame] | 403 | if (!loadFunctionPointer(FunctionDescriptor::GetDisplayConfigs, |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 404 | mGetDisplayConfigs)) return; |
Dan Stoza | 7d7ae73 | 2016-03-16 12:23:40 -0700 | [diff] [blame] | 405 | if (!loadFunctionPointer(FunctionDescriptor::GetDisplayName, |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 406 | mGetDisplayName)) return; |
Dan Stoza | 7d7ae73 | 2016-03-16 12:23:40 -0700 | [diff] [blame] | 407 | if (!loadFunctionPointer(FunctionDescriptor::GetDisplayRequests, |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 408 | mGetDisplayRequests)) return; |
Dan Stoza | 7d7ae73 | 2016-03-16 12:23:40 -0700 | [diff] [blame] | 409 | if (!loadFunctionPointer(FunctionDescriptor::GetDisplayType, |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 410 | mGetDisplayType)) return; |
Dan Stoza | 7d7ae73 | 2016-03-16 12:23:40 -0700 | [diff] [blame] | 411 | if (!loadFunctionPointer(FunctionDescriptor::GetDozeSupport, |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 412 | mGetDozeSupport)) return; |
Dan Stoza | 7d7ae73 | 2016-03-16 12:23:40 -0700 | [diff] [blame] | 413 | if (!loadFunctionPointer(FunctionDescriptor::GetHdrCapabilities, |
| 414 | mGetHdrCapabilities)) return; |
| 415 | if (!loadFunctionPointer(FunctionDescriptor::GetReleaseFences, |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 416 | mGetReleaseFences)) return; |
Dan Stoza | 7d7ae73 | 2016-03-16 12:23:40 -0700 | [diff] [blame] | 417 | if (!loadFunctionPointer(FunctionDescriptor::PresentDisplay, |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 418 | mPresentDisplay)) return; |
Dan Stoza | 7d7ae73 | 2016-03-16 12:23:40 -0700 | [diff] [blame] | 419 | if (!loadFunctionPointer(FunctionDescriptor::SetActiveConfig, |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 420 | mSetActiveConfig)) return; |
Dan Stoza | 7d7ae73 | 2016-03-16 12:23:40 -0700 | [diff] [blame] | 421 | if (!loadFunctionPointer(FunctionDescriptor::SetClientTarget, |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 422 | mSetClientTarget)) return; |
Dan Stoza | 076ac67 | 2016-03-14 10:47:53 -0700 | [diff] [blame] | 423 | if (!loadFunctionPointer(FunctionDescriptor::SetColorMode, |
| 424 | mSetColorMode)) return; |
Dan Stoza | 5df2a86 | 2016-03-24 16:19:37 -0700 | [diff] [blame] | 425 | if (!loadFunctionPointer(FunctionDescriptor::SetColorTransform, |
| 426 | mSetColorTransform)) return; |
Dan Stoza | 7d7ae73 | 2016-03-16 12:23:40 -0700 | [diff] [blame] | 427 | if (!loadFunctionPointer(FunctionDescriptor::SetOutputBuffer, |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 428 | mSetOutputBuffer)) return; |
Dan Stoza | 7d7ae73 | 2016-03-16 12:23:40 -0700 | [diff] [blame] | 429 | if (!loadFunctionPointer(FunctionDescriptor::SetPowerMode, |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 430 | mSetPowerMode)) return; |
Dan Stoza | 7d7ae73 | 2016-03-16 12:23:40 -0700 | [diff] [blame] | 431 | if (!loadFunctionPointer(FunctionDescriptor::SetVsyncEnabled, |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 432 | mSetVsyncEnabled)) return; |
Dan Stoza | 7d7ae73 | 2016-03-16 12:23:40 -0700 | [diff] [blame] | 433 | if (!loadFunctionPointer(FunctionDescriptor::ValidateDisplay, |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 434 | mValidateDisplay)) return; |
| 435 | |
| 436 | // Layer function pointers |
Dan Stoza | 7d7ae73 | 2016-03-16 12:23:40 -0700 | [diff] [blame] | 437 | if (!loadFunctionPointer(FunctionDescriptor::SetCursorPosition, |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 438 | mSetCursorPosition)) return; |
Dan Stoza | 7d7ae73 | 2016-03-16 12:23:40 -0700 | [diff] [blame] | 439 | if (!loadFunctionPointer(FunctionDescriptor::SetLayerBuffer, |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 440 | mSetLayerBuffer)) return; |
Dan Stoza | 7d7ae73 | 2016-03-16 12:23:40 -0700 | [diff] [blame] | 441 | if (!loadFunctionPointer(FunctionDescriptor::SetLayerSurfaceDamage, |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 442 | mSetLayerSurfaceDamage)) return; |
Dan Stoza | 7d7ae73 | 2016-03-16 12:23:40 -0700 | [diff] [blame] | 443 | if (!loadFunctionPointer(FunctionDescriptor::SetLayerBlendMode, |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 444 | mSetLayerBlendMode)) return; |
Dan Stoza | 7d7ae73 | 2016-03-16 12:23:40 -0700 | [diff] [blame] | 445 | if (!loadFunctionPointer(FunctionDescriptor::SetLayerColor, |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 446 | mSetLayerColor)) return; |
Dan Stoza | 7d7ae73 | 2016-03-16 12:23:40 -0700 | [diff] [blame] | 447 | if (!loadFunctionPointer(FunctionDescriptor::SetLayerCompositionType, |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 448 | mSetLayerCompositionType)) return; |
Dan Stoza | 5df2a86 | 2016-03-24 16:19:37 -0700 | [diff] [blame] | 449 | if (!loadFunctionPointer(FunctionDescriptor::SetLayerDataspace, |
| 450 | mSetLayerDataspace)) return; |
Dan Stoza | 7d7ae73 | 2016-03-16 12:23:40 -0700 | [diff] [blame] | 451 | if (!loadFunctionPointer(FunctionDescriptor::SetLayerDisplayFrame, |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 452 | mSetLayerDisplayFrame)) return; |
Dan Stoza | 7d7ae73 | 2016-03-16 12:23:40 -0700 | [diff] [blame] | 453 | if (!loadFunctionPointer(FunctionDescriptor::SetLayerPlaneAlpha, |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 454 | mSetLayerPlaneAlpha)) return; |
Dan Stoza | 09e7a27 | 2016-04-14 12:31:01 -0700 | [diff] [blame] | 455 | if (hasCapability(Capability::SidebandStream)) { |
| 456 | if (!loadFunctionPointer(FunctionDescriptor::SetLayerSidebandStream, |
| 457 | mSetLayerSidebandStream)) return; |
| 458 | } |
Dan Stoza | 7d7ae73 | 2016-03-16 12:23:40 -0700 | [diff] [blame] | 459 | if (!loadFunctionPointer(FunctionDescriptor::SetLayerSourceCrop, |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 460 | mSetLayerSourceCrop)) return; |
Dan Stoza | 7d7ae73 | 2016-03-16 12:23:40 -0700 | [diff] [blame] | 461 | if (!loadFunctionPointer(FunctionDescriptor::SetLayerTransform, |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 462 | mSetLayerTransform)) return; |
Dan Stoza | 7d7ae73 | 2016-03-16 12:23:40 -0700 | [diff] [blame] | 463 | if (!loadFunctionPointer(FunctionDescriptor::SetLayerVisibleRegion, |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 464 | mSetLayerVisibleRegion)) return; |
Dan Stoza | 7d7ae73 | 2016-03-16 12:23:40 -0700 | [diff] [blame] | 465 | if (!loadFunctionPointer(FunctionDescriptor::SetLayerZOrder, |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 466 | mSetLayerZOrder)) return; |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 467 | #endif // BYPASS_IHWC |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 468 | } |
| 469 | |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 470 | namespace { |
| 471 | class ComposerCallback : public Hwc2::IComposerCallback { |
| 472 | public: |
| 473 | ComposerCallback(Device* device) : mDevice(device) {} |
| 474 | |
| 475 | Return<void> onHotplug(Hwc2::Display display, |
| 476 | Connection connected) override |
| 477 | { |
| 478 | hotplug_hook(mDevice, display, static_cast<int32_t>(connected)); |
| 479 | return Void(); |
| 480 | } |
| 481 | |
| 482 | Return<void> onRefresh(Hwc2::Display display) override |
| 483 | { |
| 484 | refresh_hook(mDevice, display); |
| 485 | return Void(); |
| 486 | } |
| 487 | |
| 488 | Return<void> onVsync(Hwc2::Display display, int64_t timestamp) override |
| 489 | { |
| 490 | vsync_hook(mDevice, display, timestamp); |
| 491 | return Void(); |
| 492 | } |
| 493 | |
| 494 | private: |
| 495 | Device* mDevice; |
| 496 | }; |
| 497 | } // namespace anonymous |
| 498 | |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 499 | void Device::registerCallbacks() |
| 500 | { |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 501 | #ifdef BYPASS_IHWC |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 502 | registerCallback<HWC2_PFN_HOTPLUG>(Callback::Hotplug, hotplug_hook); |
| 503 | registerCallback<HWC2_PFN_REFRESH>(Callback::Refresh, refresh_hook); |
| 504 | registerCallback<HWC2_PFN_VSYNC>(Callback::Vsync, vsync_hook); |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 505 | #else |
| 506 | sp<ComposerCallback> callback = new ComposerCallback(this); |
| 507 | mComposer->registerCallback(callback); |
| 508 | #endif |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 509 | } |
| 510 | |
| 511 | |
| 512 | // For use by Display |
| 513 | |
| 514 | void Device::destroyVirtualDisplay(hwc2_display_t display) |
| 515 | { |
| 516 | ALOGI("Destroying virtual display"); |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 517 | #ifdef BYPASS_IHWC |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 518 | int32_t intError = mDestroyVirtualDisplay(mHwcDevice, display); |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 519 | #else |
| 520 | auto intError = mComposer->destroyVirtualDisplay(display); |
| 521 | #endif |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 522 | auto error = static_cast<Error>(intError); |
| 523 | ALOGE_IF(error != Error::None, "destroyVirtualDisplay(%" PRIu64 ") failed:" |
| 524 | " %s (%d)", display, to_string(error).c_str(), intError); |
Dan Stoza | 3862898 | 2016-07-13 15:48:58 -0700 | [diff] [blame] | 525 | mDisplays.erase(display); |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 526 | } |
| 527 | |
| 528 | // Display methods |
| 529 | |
| 530 | Display::Display(Device& device, hwc2_display_t id) |
| 531 | : mDevice(device), |
| 532 | mId(id), |
| 533 | mIsConnected(false), |
Chris Forbes | 016d73c | 2017-04-11 10:04:31 -0700 | [diff] [blame] | 534 | mType(DisplayType::Invalid) |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 535 | { |
| 536 | ALOGV("Created display %" PRIu64, id); |
Chris Forbes | 016d73c | 2017-04-11 10:04:31 -0700 | [diff] [blame] | 537 | |
| 538 | #ifdef BYPASS_IHWC |
| 539 | int32_t intError = mDevice.mGetDisplayType(mDevice.mHwcDevice, mId, |
| 540 | reinterpret_cast<int32_t *>(&mType)); |
| 541 | #else |
| 542 | auto intError = mDevice.mComposer->getDisplayType(mId, |
| 543 | reinterpret_cast<Hwc2::IComposerClient::DisplayType *>(&mType)); |
| 544 | #endif |
| 545 | auto error = static_cast<Error>(intError); |
| 546 | if (error != Error::None) { |
| 547 | ALOGE("getDisplayType(%" PRIu64 ") failed: %s (%d)", |
| 548 | id, to_string(error).c_str(), intError); |
| 549 | } |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 550 | } |
| 551 | |
| 552 | Display::~Display() |
| 553 | { |
| 554 | ALOGV("Destroyed display %" PRIu64, mId); |
Chris Forbes | ceb67d1 | 2017-04-11 12:20:00 -0700 | [diff] [blame] | 555 | if (mType == DisplayType::Virtual) { |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 556 | mDevice.destroyVirtualDisplay(mId); |
| 557 | } |
| 558 | } |
| 559 | |
| 560 | Display::Config::Config(Display& display, hwc2_config_t id) |
| 561 | : mDisplay(display), |
| 562 | mId(id), |
| 563 | mWidth(-1), |
| 564 | mHeight(-1), |
| 565 | mVsyncPeriod(-1), |
| 566 | mDpiX(-1), |
| 567 | mDpiY(-1) {} |
| 568 | |
| 569 | Display::Config::Builder::Builder(Display& display, hwc2_config_t id) |
| 570 | : mConfig(new Config(display, id)) {} |
| 571 | |
| 572 | float Display::Config::Builder::getDefaultDensity() { |
| 573 | // Default density is based on TVs: 1080p displays get XHIGH density, lower- |
| 574 | // resolution displays get TV density. Maybe eventually we'll need to update |
| 575 | // it for 4k displays, though hopefully those will just report accurate DPI |
| 576 | // information to begin with. This is also used for virtual displays and |
| 577 | // older HWC implementations, so be careful about orientation. |
| 578 | |
| 579 | auto longDimension = std::max(mConfig->mWidth, mConfig->mHeight); |
| 580 | if (longDimension >= 1080) { |
| 581 | return ACONFIGURATION_DENSITY_XHIGH; |
| 582 | } else { |
| 583 | return ACONFIGURATION_DENSITY_TV; |
| 584 | } |
| 585 | } |
| 586 | |
| 587 | // Required by HWC2 display |
| 588 | |
| 589 | Error Display::acceptChanges() |
| 590 | { |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 591 | #ifdef BYPASS_IHWC |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 592 | int32_t intError = mDevice.mAcceptDisplayChanges(mDevice.mHwcDevice, mId); |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 593 | #else |
| 594 | auto intError = mDevice.mComposer->acceptDisplayChanges(mId); |
| 595 | #endif |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 596 | return static_cast<Error>(intError); |
| 597 | } |
| 598 | |
| 599 | Error Display::createLayer(std::shared_ptr<Layer>* outLayer) |
| 600 | { |
| 601 | hwc2_layer_t layerId = 0; |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 602 | #ifdef BYPASS_IHWC |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 603 | int32_t intError = mDevice.mCreateLayer(mDevice.mHwcDevice, mId, &layerId); |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 604 | #else |
Chia-I Wu | 67e376d | 2016-12-19 11:36:22 +0800 | [diff] [blame] | 605 | auto intError = mDevice.mComposer->createLayer(mId, &layerId); |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 606 | #endif |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 607 | auto error = static_cast<Error>(intError); |
| 608 | if (error != Error::None) { |
| 609 | return error; |
| 610 | } |
| 611 | |
| 612 | auto layer = std::make_shared<Layer>(shared_from_this(), layerId); |
| 613 | mLayers.emplace(layerId, layer); |
| 614 | *outLayer = std::move(layer); |
| 615 | return Error::None; |
| 616 | } |
| 617 | |
| 618 | Error Display::getActiveConfig( |
| 619 | std::shared_ptr<const Display::Config>* outConfig) const |
| 620 | { |
| 621 | ALOGV("[%" PRIu64 "] getActiveConfig", mId); |
| 622 | hwc2_config_t configId = 0; |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 623 | #ifdef BYPASS_IHWC |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 624 | int32_t intError = mDevice.mGetActiveConfig(mDevice.mHwcDevice, mId, |
| 625 | &configId); |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 626 | #else |
Chia-I Wu | 67e376d | 2016-12-19 11:36:22 +0800 | [diff] [blame] | 627 | auto intError = mDevice.mComposer->getActiveConfig(mId, &configId); |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 628 | #endif |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 629 | auto error = static_cast<Error>(intError); |
| 630 | |
| 631 | if (error != Error::None) { |
Fabien Sanglard | b7432cc | 2016-11-11 09:40:27 -0800 | [diff] [blame] | 632 | ALOGE("Unable to get active config for mId:[%" PRIu64 "]", mId); |
| 633 | *outConfig = nullptr; |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 634 | return error; |
| 635 | } |
| 636 | |
| 637 | if (mConfigs.count(configId) != 0) { |
| 638 | *outConfig = mConfigs.at(configId); |
| 639 | } else { |
| 640 | ALOGE("[%" PRIu64 "] getActiveConfig returned unknown config %u", mId, |
| 641 | configId); |
| 642 | // Return no error, but the caller needs to check for a null pointer to |
| 643 | // detect this case |
| 644 | *outConfig = nullptr; |
| 645 | } |
| 646 | |
| 647 | return Error::None; |
| 648 | } |
| 649 | |
| 650 | Error Display::getChangedCompositionTypes( |
| 651 | std::unordered_map<std::shared_ptr<Layer>, Composition>* outTypes) |
| 652 | { |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 653 | #ifdef BYPASS_IHWC |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 654 | uint32_t numElements = 0; |
| 655 | int32_t intError = mDevice.mGetChangedCompositionTypes(mDevice.mHwcDevice, |
| 656 | mId, &numElements, nullptr, nullptr); |
| 657 | auto error = static_cast<Error>(intError); |
| 658 | if (error != Error::None) { |
| 659 | return error; |
| 660 | } |
| 661 | |
| 662 | std::vector<hwc2_layer_t> layerIds(numElements); |
| 663 | std::vector<int32_t> types(numElements); |
| 664 | intError = mDevice.mGetChangedCompositionTypes(mDevice.mHwcDevice, mId, |
| 665 | &numElements, layerIds.data(), types.data()); |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 666 | #else |
| 667 | std::vector<Hwc2::Layer> layerIds; |
Chia-I Wu | cd8d7f0 | 2016-11-16 11:02:31 +0800 | [diff] [blame] | 668 | std::vector<Hwc2::IComposerClient::Composition> types; |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 669 | auto intError = mDevice.mComposer->getChangedCompositionTypes(mId, |
Chia-I Wu | 67e376d | 2016-12-19 11:36:22 +0800 | [diff] [blame] | 670 | &layerIds, &types); |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 671 | uint32_t numElements = layerIds.size(); |
| 672 | auto error = static_cast<Error>(intError); |
| 673 | #endif |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 674 | error = static_cast<Error>(intError); |
| 675 | if (error != Error::None) { |
| 676 | return error; |
| 677 | } |
| 678 | |
| 679 | outTypes->clear(); |
| 680 | outTypes->reserve(numElements); |
| 681 | for (uint32_t element = 0; element < numElements; ++element) { |
| 682 | auto layer = getLayerById(layerIds[element]); |
| 683 | if (layer) { |
| 684 | auto type = static_cast<Composition>(types[element]); |
| 685 | ALOGV("getChangedCompositionTypes: adding %" PRIu64 " %s", |
| 686 | layer->getId(), to_string(type).c_str()); |
| 687 | outTypes->emplace(layer, type); |
| 688 | } else { |
| 689 | ALOGE("getChangedCompositionTypes: invalid layer %" PRIu64 " found" |
| 690 | " on display %" PRIu64, layerIds[element], mId); |
| 691 | } |
| 692 | } |
| 693 | |
| 694 | return Error::None; |
| 695 | } |
| 696 | |
Michael Wright | 28f24d0 | 2016-07-12 13:30:53 -0700 | [diff] [blame] | 697 | Error Display::getColorModes(std::vector<android_color_mode_t>* outModes) const |
Dan Stoza | 076ac67 | 2016-03-14 10:47:53 -0700 | [diff] [blame] | 698 | { |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 699 | #ifdef BYPASS_IHWC |
Dan Stoza | 076ac67 | 2016-03-14 10:47:53 -0700 | [diff] [blame] | 700 | uint32_t numModes = 0; |
| 701 | int32_t intError = mDevice.mGetColorModes(mDevice.mHwcDevice, mId, |
| 702 | &numModes, nullptr); |
| 703 | auto error = static_cast<Error>(intError); |
| 704 | if (error != Error::None) { |
| 705 | return error; |
| 706 | } |
| 707 | |
| 708 | std::vector<int32_t> modes(numModes); |
| 709 | intError = mDevice.mGetColorModes(mDevice.mHwcDevice, mId, &numModes, |
| 710 | modes.data()); |
| 711 | error = static_cast<Error>(intError); |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 712 | #else |
| 713 | std::vector<Hwc2::ColorMode> modes; |
Chia-I Wu | 67e376d | 2016-12-19 11:36:22 +0800 | [diff] [blame] | 714 | auto intError = mDevice.mComposer->getColorModes(mId, &modes); |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 715 | uint32_t numModes = modes.size(); |
| 716 | auto error = static_cast<Error>(intError); |
| 717 | #endif |
Dan Stoza | 076ac67 | 2016-03-14 10:47:53 -0700 | [diff] [blame] | 718 | if (error != Error::None) { |
| 719 | return error; |
| 720 | } |
| 721 | |
Michael Wright | 28f24d0 | 2016-07-12 13:30:53 -0700 | [diff] [blame] | 722 | outModes->resize(numModes); |
| 723 | for (size_t i = 0; i < numModes; i++) { |
| 724 | (*outModes)[i] = static_cast<android_color_mode_t>(modes[i]); |
| 725 | } |
Dan Stoza | 076ac67 | 2016-03-14 10:47:53 -0700 | [diff] [blame] | 726 | return Error::None; |
| 727 | } |
| 728 | |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 729 | std::vector<std::shared_ptr<const Display::Config>> Display::getConfigs() const |
| 730 | { |
| 731 | std::vector<std::shared_ptr<const Config>> configs; |
| 732 | for (const auto& element : mConfigs) { |
| 733 | configs.emplace_back(element.second); |
| 734 | } |
| 735 | return configs; |
| 736 | } |
| 737 | |
| 738 | Error Display::getName(std::string* outName) const |
| 739 | { |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 740 | #ifdef BYPASS_IHWC |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 741 | uint32_t size; |
| 742 | int32_t intError = mDevice.mGetDisplayName(mDevice.mHwcDevice, mId, &size, |
| 743 | nullptr); |
| 744 | auto error = static_cast<Error>(intError); |
| 745 | if (error != Error::None) { |
| 746 | return error; |
| 747 | } |
| 748 | |
| 749 | std::vector<char> rawName(size); |
| 750 | intError = mDevice.mGetDisplayName(mDevice.mHwcDevice, mId, &size, |
| 751 | rawName.data()); |
| 752 | error = static_cast<Error>(intError); |
| 753 | if (error != Error::None) { |
| 754 | return error; |
| 755 | } |
| 756 | |
| 757 | *outName = std::string(rawName.cbegin(), rawName.cend()); |
| 758 | return Error::None; |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 759 | #else |
Chia-I Wu | 67e376d | 2016-12-19 11:36:22 +0800 | [diff] [blame] | 760 | auto intError = mDevice.mComposer->getDisplayName(mId, outName); |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 761 | return static_cast<Error>(intError); |
| 762 | #endif |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 763 | } |
| 764 | |
| 765 | Error Display::getRequests(HWC2::DisplayRequest* outDisplayRequests, |
| 766 | std::unordered_map<std::shared_ptr<Layer>, LayerRequest>* |
| 767 | outLayerRequests) |
| 768 | { |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 769 | #ifdef BYPASS_IHWC |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 770 | int32_t intDisplayRequests = 0; |
| 771 | uint32_t numElements = 0; |
| 772 | int32_t intError = mDevice.mGetDisplayRequests(mDevice.mHwcDevice, mId, |
| 773 | &intDisplayRequests, &numElements, nullptr, nullptr); |
| 774 | auto error = static_cast<Error>(intError); |
| 775 | if (error != Error::None) { |
| 776 | return error; |
| 777 | } |
| 778 | |
| 779 | std::vector<hwc2_layer_t> layerIds(numElements); |
| 780 | std::vector<int32_t> layerRequests(numElements); |
| 781 | intError = mDevice.mGetDisplayRequests(mDevice.mHwcDevice, mId, |
| 782 | &intDisplayRequests, &numElements, layerIds.data(), |
| 783 | layerRequests.data()); |
| 784 | error = static_cast<Error>(intError); |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 785 | #else |
| 786 | uint32_t intDisplayRequests; |
| 787 | std::vector<Hwc2::Layer> layerIds; |
| 788 | std::vector<uint32_t> layerRequests; |
| 789 | auto intError = mDevice.mComposer->getDisplayRequests(mId, |
Chia-I Wu | 67e376d | 2016-12-19 11:36:22 +0800 | [diff] [blame] | 790 | &intDisplayRequests, &layerIds, &layerRequests); |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 791 | uint32_t numElements = layerIds.size(); |
| 792 | auto error = static_cast<Error>(intError); |
| 793 | #endif |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 794 | if (error != Error::None) { |
| 795 | return error; |
| 796 | } |
| 797 | |
| 798 | *outDisplayRequests = static_cast<DisplayRequest>(intDisplayRequests); |
| 799 | outLayerRequests->clear(); |
| 800 | outLayerRequests->reserve(numElements); |
| 801 | for (uint32_t element = 0; element < numElements; ++element) { |
| 802 | auto layer = getLayerById(layerIds[element]); |
| 803 | if (layer) { |
| 804 | auto layerRequest = |
| 805 | static_cast<LayerRequest>(layerRequests[element]); |
| 806 | outLayerRequests->emplace(layer, layerRequest); |
| 807 | } else { |
| 808 | ALOGE("getRequests: invalid layer %" PRIu64 " found on display %" |
| 809 | PRIu64, layerIds[element], mId); |
| 810 | } |
| 811 | } |
| 812 | |
| 813 | return Error::None; |
| 814 | } |
| 815 | |
| 816 | Error Display::getType(DisplayType* outType) const |
| 817 | { |
Chris Forbes | 016d73c | 2017-04-11 10:04:31 -0700 | [diff] [blame] | 818 | *outType = mType; |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 819 | return Error::None; |
| 820 | } |
| 821 | |
| 822 | Error Display::supportsDoze(bool* outSupport) const |
| 823 | { |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 824 | #ifdef BYPASS_IHWC |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 825 | int32_t intSupport = 0; |
| 826 | int32_t intError = mDevice.mGetDozeSupport(mDevice.mHwcDevice, mId, |
| 827 | &intSupport); |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 828 | #else |
| 829 | bool intSupport = false; |
Chia-I Wu | 67e376d | 2016-12-19 11:36:22 +0800 | [diff] [blame] | 830 | auto intError = mDevice.mComposer->getDozeSupport(mId, &intSupport); |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 831 | #endif |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 832 | auto error = static_cast<Error>(intError); |
| 833 | if (error != Error::None) { |
| 834 | return error; |
| 835 | } |
| 836 | *outSupport = static_cast<bool>(intSupport); |
| 837 | return Error::None; |
| 838 | } |
| 839 | |
Dan Stoza | 7d7ae73 | 2016-03-16 12:23:40 -0700 | [diff] [blame] | 840 | Error Display::getHdrCapabilities( |
| 841 | std::unique_ptr<HdrCapabilities>* outCapabilities) const |
| 842 | { |
| 843 | uint32_t numTypes = 0; |
| 844 | float maxLuminance = -1.0f; |
| 845 | float maxAverageLuminance = -1.0f; |
| 846 | float minLuminance = -1.0f; |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 847 | #ifdef BYPASS_IHWC |
Dan Stoza | 7d7ae73 | 2016-03-16 12:23:40 -0700 | [diff] [blame] | 848 | int32_t intError = mDevice.mGetHdrCapabilities(mDevice.mHwcDevice, mId, |
| 849 | &numTypes, nullptr, &maxLuminance, &maxAverageLuminance, |
| 850 | &minLuminance); |
| 851 | auto error = static_cast<HWC2::Error>(intError); |
| 852 | if (error != Error::None) { |
| 853 | return error; |
| 854 | } |
| 855 | |
| 856 | std::vector<int32_t> types(numTypes); |
| 857 | intError = mDevice.mGetHdrCapabilities(mDevice.mHwcDevice, mId, &numTypes, |
| 858 | types.data(), &maxLuminance, &maxAverageLuminance, &minLuminance); |
| 859 | error = static_cast<HWC2::Error>(intError); |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 860 | #else |
| 861 | std::vector<Hwc2::Hdr> intTypes; |
Chia-I Wu | 67e376d | 2016-12-19 11:36:22 +0800 | [diff] [blame] | 862 | auto intError = mDevice.mComposer->getHdrCapabilities(mId, &intTypes, |
| 863 | &maxLuminance, &maxAverageLuminance, &minLuminance); |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 864 | auto error = static_cast<HWC2::Error>(intError); |
| 865 | |
| 866 | std::vector<int32_t> types; |
| 867 | for (auto type : intTypes) { |
| 868 | types.push_back(static_cast<int32_t>(type)); |
| 869 | } |
| 870 | numTypes = types.size(); |
| 871 | #endif |
Dan Stoza | 7d7ae73 | 2016-03-16 12:23:40 -0700 | [diff] [blame] | 872 | if (error != Error::None) { |
| 873 | return error; |
| 874 | } |
| 875 | |
| 876 | *outCapabilities = std::make_unique<HdrCapabilities>(std::move(types), |
| 877 | maxLuminance, maxAverageLuminance, minLuminance); |
| 878 | return Error::None; |
| 879 | } |
| 880 | |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 881 | Error Display::getReleaseFences( |
| 882 | std::unordered_map<std::shared_ptr<Layer>, sp<Fence>>* outFences) const |
| 883 | { |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 884 | #ifdef BYPASS_IHWC |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 885 | uint32_t numElements = 0; |
| 886 | int32_t intError = mDevice.mGetReleaseFences(mDevice.mHwcDevice, mId, |
| 887 | &numElements, nullptr, nullptr); |
| 888 | auto error = static_cast<Error>(intError); |
| 889 | if (error != Error::None) { |
| 890 | return error; |
| 891 | } |
| 892 | |
| 893 | std::vector<hwc2_layer_t> layerIds(numElements); |
| 894 | std::vector<int32_t> fenceFds(numElements); |
| 895 | intError = mDevice.mGetReleaseFences(mDevice.mHwcDevice, mId, &numElements, |
| 896 | layerIds.data(), fenceFds.data()); |
| 897 | error = static_cast<Error>(intError); |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 898 | #else |
| 899 | std::vector<Hwc2::Layer> layerIds; |
| 900 | std::vector<int> fenceFds; |
| 901 | auto intError = mDevice.mComposer->getReleaseFences(mId, |
Chia-I Wu | 67e376d | 2016-12-19 11:36:22 +0800 | [diff] [blame] | 902 | &layerIds, &fenceFds); |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 903 | auto error = static_cast<Error>(intError); |
| 904 | uint32_t numElements = layerIds.size(); |
| 905 | #endif |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 906 | if (error != Error::None) { |
| 907 | return error; |
| 908 | } |
| 909 | |
| 910 | std::unordered_map<std::shared_ptr<Layer>, sp<Fence>> releaseFences; |
| 911 | releaseFences.reserve(numElements); |
| 912 | for (uint32_t element = 0; element < numElements; ++element) { |
| 913 | auto layer = getLayerById(layerIds[element]); |
| 914 | if (layer) { |
| 915 | sp<Fence> fence(new Fence(fenceFds[element])); |
| 916 | releaseFences.emplace(std::move(layer), fence); |
| 917 | } else { |
| 918 | ALOGE("getReleaseFences: invalid layer %" PRIu64 |
| 919 | " found on display %" PRIu64, layerIds[element], mId); |
Chia-I Wu | 5e74c65 | 2017-05-17 13:43:16 -0700 | [diff] [blame^] | 920 | for (; element < numElements; ++element) { |
| 921 | close(fenceFds[element]); |
| 922 | } |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 923 | return Error::BadLayer; |
| 924 | } |
| 925 | } |
| 926 | |
| 927 | *outFences = std::move(releaseFences); |
| 928 | return Error::None; |
| 929 | } |
| 930 | |
Fabien Sanglard | 11d0fc3 | 2016-12-01 15:43:01 -0800 | [diff] [blame] | 931 | Error Display::present(sp<Fence>* outPresentFence) |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 932 | { |
Naseer Ahmed | 847650b | 2016-06-17 11:14:25 -0400 | [diff] [blame] | 933 | int32_t presentFenceFd = -1; |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 934 | #ifdef BYPASS_IHWC |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 935 | int32_t intError = mDevice.mPresentDisplay(mDevice.mHwcDevice, mId, |
Fabien Sanglard | 11d0fc3 | 2016-12-01 15:43:01 -0800 | [diff] [blame] | 936 | &presentFenceFd); |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 937 | #else |
Chia-I Wu | 67e376d | 2016-12-19 11:36:22 +0800 | [diff] [blame] | 938 | auto intError = mDevice.mComposer->presentDisplay(mId, &presentFenceFd); |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 939 | #endif |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 940 | auto error = static_cast<Error>(intError); |
| 941 | if (error != Error::None) { |
| 942 | return error; |
| 943 | } |
| 944 | |
Fabien Sanglard | 11d0fc3 | 2016-12-01 15:43:01 -0800 | [diff] [blame] | 945 | *outPresentFence = new Fence(presentFenceFd); |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 946 | return Error::None; |
| 947 | } |
| 948 | |
| 949 | Error Display::setActiveConfig(const std::shared_ptr<const Config>& config) |
| 950 | { |
| 951 | if (config->getDisplayId() != mId) { |
| 952 | ALOGE("setActiveConfig received config %u for the wrong display %" |
| 953 | PRIu64 " (expected %" PRIu64 ")", config->getId(), |
| 954 | config->getDisplayId(), mId); |
| 955 | return Error::BadConfig; |
| 956 | } |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 957 | #ifdef BYPASS_IHWC |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 958 | int32_t intError = mDevice.mSetActiveConfig(mDevice.mHwcDevice, mId, |
| 959 | config->getId()); |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 960 | #else |
| 961 | auto intError = mDevice.mComposer->setActiveConfig(mId, config->getId()); |
| 962 | #endif |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 963 | return static_cast<Error>(intError); |
| 964 | } |
| 965 | |
Daniel Nicoara | 1f42e3a | 2017-04-10 13:27:32 -0400 | [diff] [blame] | 966 | Error Display::setClientTarget(uint32_t slot, const sp<GraphicBuffer>& target, |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 967 | const sp<Fence>& acquireFence, android_dataspace_t dataspace) |
| 968 | { |
Dan Stoza | 5cf424b | 2016-05-20 14:02:39 -0700 | [diff] [blame] | 969 | // TODO: Properly encode client target surface damage |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 970 | int32_t fenceFd = acquireFence->dup(); |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 971 | #ifdef BYPASS_IHWC |
Chia-I Wu | 06d63de | 2017-01-04 14:58:51 +0800 | [diff] [blame] | 972 | (void) slot; |
Daniel Nicoara | 1f42e3a | 2017-04-10 13:27:32 -0400 | [diff] [blame] | 973 | buffer_handle_t handle = nullptr; |
| 974 | if (target.get() && target->getNativeBuffer()) { |
| 975 | handle = target->getNativeBuffer()->handle; |
| 976 | } |
| 977 | |
| 978 | int32_t intError = mDevice.mSetClientTarget(mDevice.mHwcDevice, mId, handle, |
Dan Stoza | 5cf424b | 2016-05-20 14:02:39 -0700 | [diff] [blame] | 979 | fenceFd, static_cast<int32_t>(dataspace), {0, nullptr}); |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 980 | #else |
Chia-I Wu | 06d63de | 2017-01-04 14:58:51 +0800 | [diff] [blame] | 981 | auto intError = mDevice.mComposer->setClientTarget(mId, slot, target, |
| 982 | fenceFd, static_cast<Hwc2::Dataspace>(dataspace), |
Chia-I Wu | cd8d7f0 | 2016-11-16 11:02:31 +0800 | [diff] [blame] | 983 | std::vector<Hwc2::IComposerClient::Rect>()); |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 984 | #endif |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 985 | return static_cast<Error>(intError); |
| 986 | } |
| 987 | |
Michael Wright | 28f24d0 | 2016-07-12 13:30:53 -0700 | [diff] [blame] | 988 | Error Display::setColorMode(android_color_mode_t mode) |
Dan Stoza | 076ac67 | 2016-03-14 10:47:53 -0700 | [diff] [blame] | 989 | { |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 990 | #ifdef BYPASS_IHWC |
Dan Stoza | 076ac67 | 2016-03-14 10:47:53 -0700 | [diff] [blame] | 991 | int32_t intError = mDevice.mSetColorMode(mDevice.mHwcDevice, mId, mode); |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 992 | #else |
| 993 | auto intError = mDevice.mComposer->setColorMode(mId, |
| 994 | static_cast<Hwc2::ColorMode>(mode)); |
| 995 | #endif |
Dan Stoza | 076ac67 | 2016-03-14 10:47:53 -0700 | [diff] [blame] | 996 | return static_cast<Error>(intError); |
| 997 | } |
| 998 | |
Dan Stoza | 5df2a86 | 2016-03-24 16:19:37 -0700 | [diff] [blame] | 999 | Error Display::setColorTransform(const android::mat4& matrix, |
| 1000 | android_color_transform_t hint) |
| 1001 | { |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 1002 | #ifdef BYPASS_IHWC |
Dan Stoza | 5df2a86 | 2016-03-24 16:19:37 -0700 | [diff] [blame] | 1003 | int32_t intError = mDevice.mSetColorTransform(mDevice.mHwcDevice, mId, |
| 1004 | matrix.asArray(), static_cast<int32_t>(hint)); |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 1005 | #else |
| 1006 | auto intError = mDevice.mComposer->setColorTransform(mId, |
| 1007 | matrix.asArray(), static_cast<Hwc2::ColorTransform>(hint)); |
| 1008 | #endif |
Dan Stoza | 5df2a86 | 2016-03-24 16:19:37 -0700 | [diff] [blame] | 1009 | return static_cast<Error>(intError); |
| 1010 | } |
| 1011 | |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 1012 | Error Display::setOutputBuffer(const sp<GraphicBuffer>& buffer, |
| 1013 | const sp<Fence>& releaseFence) |
| 1014 | { |
| 1015 | int32_t fenceFd = releaseFence->dup(); |
| 1016 | auto handle = buffer->getNativeBuffer()->handle; |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 1017 | #ifdef BYPASS_IHWC |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 1018 | int32_t intError = mDevice.mSetOutputBuffer(mDevice.mHwcDevice, mId, handle, |
| 1019 | fenceFd); |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 1020 | #else |
| 1021 | auto intError = mDevice.mComposer->setOutputBuffer(mId, handle, fenceFd); |
| 1022 | #endif |
Dan Stoza | 3862898 | 2016-07-13 15:48:58 -0700 | [diff] [blame] | 1023 | close(fenceFd); |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 1024 | return static_cast<Error>(intError); |
| 1025 | } |
| 1026 | |
| 1027 | Error Display::setPowerMode(PowerMode mode) |
| 1028 | { |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 1029 | #ifdef BYPASS_IHWC |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 1030 | auto intMode = static_cast<int32_t>(mode); |
| 1031 | int32_t intError = mDevice.mSetPowerMode(mDevice.mHwcDevice, mId, intMode); |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 1032 | #else |
Chia-I Wu | cd8d7f0 | 2016-11-16 11:02:31 +0800 | [diff] [blame] | 1033 | auto intMode = static_cast<Hwc2::IComposerClient::PowerMode>(mode); |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 1034 | auto intError = mDevice.mComposer->setPowerMode(mId, intMode); |
| 1035 | #endif |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 1036 | return static_cast<Error>(intError); |
| 1037 | } |
| 1038 | |
| 1039 | Error Display::setVsyncEnabled(Vsync enabled) |
| 1040 | { |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 1041 | #ifdef BYPASS_IHWC |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 1042 | auto intEnabled = static_cast<int32_t>(enabled); |
| 1043 | int32_t intError = mDevice.mSetVsyncEnabled(mDevice.mHwcDevice, mId, |
| 1044 | intEnabled); |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 1045 | #else |
Chia-I Wu | cd8d7f0 | 2016-11-16 11:02:31 +0800 | [diff] [blame] | 1046 | auto intEnabled = static_cast<Hwc2::IComposerClient::Vsync>(enabled); |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 1047 | auto intError = mDevice.mComposer->setVsyncEnabled(mId, intEnabled); |
| 1048 | #endif |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 1049 | return static_cast<Error>(intError); |
| 1050 | } |
| 1051 | |
| 1052 | Error Display::validate(uint32_t* outNumTypes, uint32_t* outNumRequests) |
| 1053 | { |
| 1054 | uint32_t numTypes = 0; |
| 1055 | uint32_t numRequests = 0; |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 1056 | #ifdef BYPASS_IHWC |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 1057 | int32_t intError = mDevice.mValidateDisplay(mDevice.mHwcDevice, mId, |
| 1058 | &numTypes, &numRequests); |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 1059 | #else |
| 1060 | auto intError = mDevice.mComposer->validateDisplay(mId, |
Chia-I Wu | 67e376d | 2016-12-19 11:36:22 +0800 | [diff] [blame] | 1061 | &numTypes, &numRequests); |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 1062 | #endif |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 1063 | auto error = static_cast<Error>(intError); |
| 1064 | if (error != Error::None && error != Error::HasChanges) { |
| 1065 | return error; |
| 1066 | } |
| 1067 | |
| 1068 | *outNumTypes = numTypes; |
| 1069 | *outNumRequests = numRequests; |
| 1070 | return error; |
| 1071 | } |
| 1072 | |
| 1073 | // For use by Device |
| 1074 | |
| 1075 | int32_t Display::getAttribute(hwc2_config_t configId, Attribute attribute) |
| 1076 | { |
| 1077 | int32_t value = 0; |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 1078 | #ifdef BYPASS_IHWC |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 1079 | int32_t intError = mDevice.mGetDisplayAttribute(mDevice.mHwcDevice, mId, |
| 1080 | configId, static_cast<int32_t>(attribute), &value); |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 1081 | #else |
Chia-I Wu | 67e376d | 2016-12-19 11:36:22 +0800 | [diff] [blame] | 1082 | auto intError = mDevice.mComposer->getDisplayAttribute(mId, configId, |
| 1083 | static_cast<Hwc2::IComposerClient::Attribute>(attribute), |
| 1084 | &value); |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 1085 | #endif |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 1086 | auto error = static_cast<Error>(intError); |
| 1087 | if (error != Error::None) { |
| 1088 | ALOGE("getDisplayAttribute(%" PRIu64 ", %u, %s) failed: %s (%d)", mId, |
| 1089 | configId, to_string(attribute).c_str(), |
| 1090 | to_string(error).c_str(), intError); |
| 1091 | return -1; |
| 1092 | } |
| 1093 | return value; |
| 1094 | } |
| 1095 | |
| 1096 | void Display::loadConfig(hwc2_config_t configId) |
| 1097 | { |
| 1098 | ALOGV("[%" PRIu64 "] loadConfig(%u)", mId, configId); |
| 1099 | |
| 1100 | auto config = Config::Builder(*this, configId) |
| 1101 | .setWidth(getAttribute(configId, Attribute::Width)) |
| 1102 | .setHeight(getAttribute(configId, Attribute::Height)) |
| 1103 | .setVsyncPeriod(getAttribute(configId, Attribute::VsyncPeriod)) |
| 1104 | .setDpiX(getAttribute(configId, Attribute::DpiX)) |
| 1105 | .setDpiY(getAttribute(configId, Attribute::DpiY)) |
| 1106 | .build(); |
| 1107 | mConfigs.emplace(configId, std::move(config)); |
| 1108 | } |
| 1109 | |
| 1110 | void Display::loadConfigs() |
| 1111 | { |
| 1112 | ALOGV("[%" PRIu64 "] loadConfigs", mId); |
| 1113 | |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 1114 | #ifdef BYPASS_IHWC |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 1115 | uint32_t numConfigs = 0; |
| 1116 | int32_t intError = mDevice.mGetDisplayConfigs(mDevice.mHwcDevice, mId, |
| 1117 | &numConfigs, nullptr); |
| 1118 | auto error = static_cast<Error>(intError); |
| 1119 | if (error != Error::None) { |
| 1120 | ALOGE("[%" PRIu64 "] getDisplayConfigs [1] failed: %s (%d)", mId, |
| 1121 | to_string(error).c_str(), intError); |
| 1122 | return; |
| 1123 | } |
| 1124 | |
| 1125 | std::vector<hwc2_config_t> configIds(numConfigs); |
| 1126 | intError = mDevice.mGetDisplayConfigs(mDevice.mHwcDevice, mId, &numConfigs, |
| 1127 | configIds.data()); |
| 1128 | error = static_cast<Error>(intError); |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 1129 | #else |
| 1130 | std::vector<Hwc2::Config> configIds; |
Chia-I Wu | 67e376d | 2016-12-19 11:36:22 +0800 | [diff] [blame] | 1131 | auto intError = mDevice.mComposer->getDisplayConfigs(mId, &configIds); |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 1132 | auto error = static_cast<Error>(intError); |
| 1133 | #endif |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 1134 | if (error != Error::None) { |
| 1135 | ALOGE("[%" PRIu64 "] getDisplayConfigs [2] failed: %s (%d)", mId, |
| 1136 | to_string(error).c_str(), intError); |
| 1137 | return; |
| 1138 | } |
| 1139 | |
| 1140 | for (auto configId : configIds) { |
| 1141 | loadConfig(configId); |
| 1142 | } |
| 1143 | } |
| 1144 | |
| 1145 | // For use by Layer |
| 1146 | |
| 1147 | void Display::destroyLayer(hwc2_layer_t layerId) |
| 1148 | { |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 1149 | #ifdef BYPASS_IHWC |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 1150 | int32_t intError = mDevice.mDestroyLayer(mDevice.mHwcDevice, mId, layerId); |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 1151 | #else |
| 1152 | auto intError =mDevice.mComposer->destroyLayer(mId, layerId); |
| 1153 | #endif |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 1154 | auto error = static_cast<Error>(intError); |
| 1155 | ALOGE_IF(error != Error::None, "destroyLayer(%" PRIu64 ", %" PRIu64 ")" |
| 1156 | " failed: %s (%d)", mId, layerId, to_string(error).c_str(), |
| 1157 | intError); |
| 1158 | mLayers.erase(layerId); |
| 1159 | } |
| 1160 | |
| 1161 | // Other Display methods |
| 1162 | |
| 1163 | std::shared_ptr<Layer> Display::getLayerById(hwc2_layer_t id) const |
| 1164 | { |
| 1165 | if (mLayers.count(id) == 0) { |
| 1166 | return nullptr; |
| 1167 | } |
| 1168 | |
| 1169 | auto layer = mLayers.at(id).lock(); |
| 1170 | return layer; |
| 1171 | } |
| 1172 | |
| 1173 | // Layer methods |
| 1174 | |
| 1175 | Layer::Layer(const std::shared_ptr<Display>& display, hwc2_layer_t id) |
| 1176 | : mDisplay(display), |
| 1177 | mDisplayId(display->getId()), |
| 1178 | mDevice(display->getDevice()), |
| 1179 | mId(id) |
| 1180 | { |
| 1181 | ALOGV("Created layer %" PRIu64 " on display %" PRIu64, id, |
| 1182 | display->getId()); |
| 1183 | } |
| 1184 | |
| 1185 | Layer::~Layer() |
| 1186 | { |
| 1187 | auto display = mDisplay.lock(); |
| 1188 | if (display) { |
| 1189 | display->destroyLayer(mId); |
| 1190 | } |
| 1191 | } |
| 1192 | |
| 1193 | Error Layer::setCursorPosition(int32_t x, int32_t y) |
| 1194 | { |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 1195 | #ifdef BYPASS_IHWC |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 1196 | int32_t intError = mDevice.mSetCursorPosition(mDevice.mHwcDevice, |
| 1197 | mDisplayId, mId, x, y); |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 1198 | #else |
| 1199 | auto intError = mDevice.mComposer->setCursorPosition(mDisplayId, |
| 1200 | mId, x, y); |
| 1201 | #endif |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 1202 | return static_cast<Error>(intError); |
| 1203 | } |
| 1204 | |
Daniel Nicoara | 1f42e3a | 2017-04-10 13:27:32 -0400 | [diff] [blame] | 1205 | Error Layer::setBuffer(uint32_t slot, const sp<GraphicBuffer>& buffer, |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 1206 | const sp<Fence>& acquireFence) |
| 1207 | { |
| 1208 | int32_t fenceFd = acquireFence->dup(); |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 1209 | #ifdef BYPASS_IHWC |
Chia-I Wu | 06d63de | 2017-01-04 14:58:51 +0800 | [diff] [blame] | 1210 | (void) slot; |
Daniel Nicoara | 1f42e3a | 2017-04-10 13:27:32 -0400 | [diff] [blame] | 1211 | buffer_handle_t handle = nullptr; |
| 1212 | if (buffer.get() && buffer->getNativeBuffer()) { |
| 1213 | handle = buffer->getNativeBuffer()->handle; |
| 1214 | } |
| 1215 | |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 1216 | int32_t intError = mDevice.mSetLayerBuffer(mDevice.mHwcDevice, mDisplayId, |
Daniel Nicoara | 1f42e3a | 2017-04-10 13:27:32 -0400 | [diff] [blame] | 1217 | mId, handle, fenceFd); |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 1218 | #else |
| 1219 | auto intError = mDevice.mComposer->setLayerBuffer(mDisplayId, |
Chia-I Wu | 06d63de | 2017-01-04 14:58:51 +0800 | [diff] [blame] | 1220 | mId, slot, buffer, fenceFd); |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 1221 | #endif |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 1222 | return static_cast<Error>(intError); |
| 1223 | } |
| 1224 | |
| 1225 | Error Layer::setSurfaceDamage(const Region& damage) |
| 1226 | { |
| 1227 | // We encode default full-screen damage as INVALID_RECT upstream, but as 0 |
| 1228 | // rects for HWC |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 1229 | #ifdef BYPASS_IHWC |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 1230 | int32_t intError = 0; |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 1231 | #else |
| 1232 | Hwc2::Error intError = Hwc2::Error::NONE; |
| 1233 | #endif |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 1234 | if (damage.isRect() && damage.getBounds() == Rect::INVALID_RECT) { |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 1235 | #ifdef BYPASS_IHWC |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 1236 | intError = mDevice.mSetLayerSurfaceDamage(mDevice.mHwcDevice, |
| 1237 | mDisplayId, mId, {0, nullptr}); |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 1238 | #else |
| 1239 | intError = mDevice.mComposer->setLayerSurfaceDamage(mDisplayId, |
Chia-I Wu | cd8d7f0 | 2016-11-16 11:02:31 +0800 | [diff] [blame] | 1240 | mId, std::vector<Hwc2::IComposerClient::Rect>()); |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 1241 | #endif |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 1242 | } else { |
| 1243 | size_t rectCount = 0; |
| 1244 | auto rectArray = damage.getArray(&rectCount); |
| 1245 | |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 1246 | #ifdef BYPASS_IHWC |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 1247 | std::vector<hwc_rect_t> hwcRects; |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 1248 | #else |
Chia-I Wu | cd8d7f0 | 2016-11-16 11:02:31 +0800 | [diff] [blame] | 1249 | std::vector<Hwc2::IComposerClient::Rect> hwcRects; |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 1250 | #endif |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 1251 | for (size_t rect = 0; rect < rectCount; ++rect) { |
| 1252 | hwcRects.push_back({rectArray[rect].left, rectArray[rect].top, |
| 1253 | rectArray[rect].right, rectArray[rect].bottom}); |
| 1254 | } |
| 1255 | |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 1256 | #ifdef BYPASS_IHWC |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 1257 | hwc_region_t hwcRegion = {}; |
| 1258 | hwcRegion.numRects = rectCount; |
| 1259 | hwcRegion.rects = hwcRects.data(); |
| 1260 | |
| 1261 | intError = mDevice.mSetLayerSurfaceDamage(mDevice.mHwcDevice, |
| 1262 | mDisplayId, mId, hwcRegion); |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 1263 | #else |
| 1264 | intError = mDevice.mComposer->setLayerSurfaceDamage(mDisplayId, |
| 1265 | mId, hwcRects); |
| 1266 | #endif |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 1267 | } |
| 1268 | |
| 1269 | return static_cast<Error>(intError); |
| 1270 | } |
| 1271 | |
| 1272 | Error Layer::setBlendMode(BlendMode mode) |
| 1273 | { |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 1274 | #ifdef BYPASS_IHWC |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 1275 | auto intMode = static_cast<int32_t>(mode); |
| 1276 | int32_t intError = mDevice.mSetLayerBlendMode(mDevice.mHwcDevice, |
| 1277 | mDisplayId, mId, intMode); |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 1278 | #else |
Chia-I Wu | cd8d7f0 | 2016-11-16 11:02:31 +0800 | [diff] [blame] | 1279 | auto intMode = static_cast<Hwc2::IComposerClient::BlendMode>(mode); |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 1280 | auto intError = mDevice.mComposer->setLayerBlendMode(mDisplayId, |
| 1281 | mId, intMode); |
| 1282 | #endif |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 1283 | return static_cast<Error>(intError); |
| 1284 | } |
| 1285 | |
| 1286 | Error Layer::setColor(hwc_color_t color) |
| 1287 | { |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 1288 | #ifdef BYPASS_IHWC |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 1289 | int32_t intError = mDevice.mSetLayerColor(mDevice.mHwcDevice, mDisplayId, |
| 1290 | mId, color); |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 1291 | #else |
Chia-I Wu | cd8d7f0 | 2016-11-16 11:02:31 +0800 | [diff] [blame] | 1292 | Hwc2::IComposerClient::Color hwcColor{color.r, color.g, color.b, color.a}; |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 1293 | auto intError = mDevice.mComposer->setLayerColor(mDisplayId, |
| 1294 | mId, hwcColor); |
| 1295 | #endif |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 1296 | return static_cast<Error>(intError); |
| 1297 | } |
| 1298 | |
| 1299 | Error Layer::setCompositionType(Composition type) |
| 1300 | { |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 1301 | #ifdef BYPASS_IHWC |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 1302 | auto intType = static_cast<int32_t>(type); |
| 1303 | int32_t intError = mDevice.mSetLayerCompositionType(mDevice.mHwcDevice, |
| 1304 | mDisplayId, mId, intType); |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 1305 | #else |
Chia-I Wu | cd8d7f0 | 2016-11-16 11:02:31 +0800 | [diff] [blame] | 1306 | auto intType = static_cast<Hwc2::IComposerClient::Composition>(type); |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 1307 | auto intError = mDevice.mComposer->setLayerCompositionType(mDisplayId, |
| 1308 | mId, intType); |
| 1309 | #endif |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 1310 | return static_cast<Error>(intError); |
| 1311 | } |
| 1312 | |
Dan Stoza | 5df2a86 | 2016-03-24 16:19:37 -0700 | [diff] [blame] | 1313 | Error Layer::setDataspace(android_dataspace_t dataspace) |
| 1314 | { |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 1315 | #ifdef BYPASS_IHWC |
Dan Stoza | 5df2a86 | 2016-03-24 16:19:37 -0700 | [diff] [blame] | 1316 | auto intDataspace = static_cast<int32_t>(dataspace); |
| 1317 | int32_t intError = mDevice.mSetLayerDataspace(mDevice.mHwcDevice, |
| 1318 | mDisplayId, mId, intDataspace); |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 1319 | #else |
| 1320 | auto intDataspace = static_cast<Hwc2::Dataspace>(dataspace); |
| 1321 | auto intError = mDevice.mComposer->setLayerDataspace(mDisplayId, |
| 1322 | mId, intDataspace); |
| 1323 | #endif |
Dan Stoza | 5df2a86 | 2016-03-24 16:19:37 -0700 | [diff] [blame] | 1324 | return static_cast<Error>(intError); |
| 1325 | } |
| 1326 | |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 1327 | Error Layer::setDisplayFrame(const Rect& frame) |
| 1328 | { |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 1329 | #ifdef BYPASS_IHWC |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 1330 | hwc_rect_t hwcRect{frame.left, frame.top, frame.right, frame.bottom}; |
| 1331 | int32_t intError = mDevice.mSetLayerDisplayFrame(mDevice.mHwcDevice, |
| 1332 | mDisplayId, mId, hwcRect); |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 1333 | #else |
Chia-I Wu | cd8d7f0 | 2016-11-16 11:02:31 +0800 | [diff] [blame] | 1334 | Hwc2::IComposerClient::Rect hwcRect{frame.left, frame.top, |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 1335 | frame.right, frame.bottom}; |
| 1336 | auto intError = mDevice.mComposer->setLayerDisplayFrame(mDisplayId, |
| 1337 | mId, hwcRect); |
| 1338 | #endif |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 1339 | return static_cast<Error>(intError); |
| 1340 | } |
| 1341 | |
| 1342 | Error Layer::setPlaneAlpha(float alpha) |
| 1343 | { |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 1344 | #ifdef BYPASS_IHWC |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 1345 | int32_t intError = mDevice.mSetLayerPlaneAlpha(mDevice.mHwcDevice, |
| 1346 | mDisplayId, mId, alpha); |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 1347 | #else |
| 1348 | auto intError = mDevice.mComposer->setLayerPlaneAlpha(mDisplayId, |
| 1349 | mId, alpha); |
| 1350 | #endif |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 1351 | return static_cast<Error>(intError); |
| 1352 | } |
| 1353 | |
| 1354 | Error Layer::setSidebandStream(const native_handle_t* stream) |
| 1355 | { |
Dan Stoza | 09e7a27 | 2016-04-14 12:31:01 -0700 | [diff] [blame] | 1356 | if (!mDevice.hasCapability(Capability::SidebandStream)) { |
| 1357 | ALOGE("Attempted to call setSidebandStream without checking that the " |
| 1358 | "device supports sideband streams"); |
| 1359 | return Error::Unsupported; |
| 1360 | } |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 1361 | #ifdef BYPASS_IHWC |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 1362 | int32_t intError = mDevice.mSetLayerSidebandStream(mDevice.mHwcDevice, |
| 1363 | mDisplayId, mId, stream); |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 1364 | #else |
| 1365 | auto intError = mDevice.mComposer->setLayerSidebandStream(mDisplayId, |
| 1366 | mId, stream); |
| 1367 | #endif |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 1368 | return static_cast<Error>(intError); |
| 1369 | } |
| 1370 | |
| 1371 | Error Layer::setSourceCrop(const FloatRect& crop) |
| 1372 | { |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 1373 | #ifdef BYPASS_IHWC |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 1374 | hwc_frect_t hwcRect{crop.left, crop.top, crop.right, crop.bottom}; |
| 1375 | int32_t intError = mDevice.mSetLayerSourceCrop(mDevice.mHwcDevice, |
| 1376 | mDisplayId, mId, hwcRect); |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 1377 | #else |
Chia-I Wu | cd8d7f0 | 2016-11-16 11:02:31 +0800 | [diff] [blame] | 1378 | Hwc2::IComposerClient::FRect hwcRect{ |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 1379 | crop.left, crop.top, crop.right, crop.bottom}; |
| 1380 | auto intError = mDevice.mComposer->setLayerSourceCrop(mDisplayId, |
| 1381 | mId, hwcRect); |
| 1382 | #endif |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 1383 | return static_cast<Error>(intError); |
| 1384 | } |
| 1385 | |
| 1386 | Error Layer::setTransform(Transform transform) |
| 1387 | { |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 1388 | #ifdef BYPASS_IHWC |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 1389 | auto intTransform = static_cast<int32_t>(transform); |
| 1390 | int32_t intError = mDevice.mSetLayerTransform(mDevice.mHwcDevice, |
| 1391 | mDisplayId, mId, intTransform); |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 1392 | #else |
| 1393 | auto intTransform = static_cast<Hwc2::Transform>(transform); |
| 1394 | auto intError = mDevice.mComposer->setLayerTransform(mDisplayId, |
| 1395 | mId, intTransform); |
| 1396 | #endif |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 1397 | return static_cast<Error>(intError); |
| 1398 | } |
| 1399 | |
| 1400 | Error Layer::setVisibleRegion(const Region& region) |
| 1401 | { |
| 1402 | size_t rectCount = 0; |
| 1403 | auto rectArray = region.getArray(&rectCount); |
| 1404 | |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 1405 | #ifdef BYPASS_IHWC |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 1406 | std::vector<hwc_rect_t> hwcRects; |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 1407 | #else |
Chia-I Wu | cd8d7f0 | 2016-11-16 11:02:31 +0800 | [diff] [blame] | 1408 | std::vector<Hwc2::IComposerClient::Rect> hwcRects; |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 1409 | #endif |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 1410 | for (size_t rect = 0; rect < rectCount; ++rect) { |
| 1411 | hwcRects.push_back({rectArray[rect].left, rectArray[rect].top, |
| 1412 | rectArray[rect].right, rectArray[rect].bottom}); |
| 1413 | } |
| 1414 | |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 1415 | #ifdef BYPASS_IHWC |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 1416 | hwc_region_t hwcRegion = {}; |
| 1417 | hwcRegion.numRects = rectCount; |
| 1418 | hwcRegion.rects = hwcRects.data(); |
| 1419 | |
| 1420 | int32_t intError = mDevice.mSetLayerVisibleRegion(mDevice.mHwcDevice, |
| 1421 | mDisplayId, mId, hwcRegion); |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 1422 | #else |
| 1423 | auto intError = mDevice.mComposer->setLayerVisibleRegion(mDisplayId, |
| 1424 | mId, hwcRects); |
| 1425 | #endif |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 1426 | return static_cast<Error>(intError); |
| 1427 | } |
| 1428 | |
| 1429 | Error Layer::setZOrder(uint32_t z) |
| 1430 | { |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 1431 | #ifdef BYPASS_IHWC |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 1432 | int32_t intError = mDevice.mSetLayerZOrder(mDevice.mHwcDevice, mDisplayId, |
| 1433 | mId, z); |
Chia-I Wu | aab99f5 | 2016-10-05 12:59:58 +0800 | [diff] [blame] | 1434 | #else |
| 1435 | auto intError = mDevice.mComposer->setLayerZOrder(mDisplayId, mId, z); |
| 1436 | #endif |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 1437 | return static_cast<Error>(intError); |
| 1438 | } |
| 1439 | |
Daniel Nicoara | 2f5f8a5 | 2016-12-20 16:11:58 -0500 | [diff] [blame] | 1440 | Error Layer::setInfo(uint32_t type, uint32_t appId) |
| 1441 | { |
| 1442 | #ifdef BYPASS_IHWC |
| 1443 | (void)type; |
| 1444 | (void)appId; |
| 1445 | int32_t intError = 0; |
| 1446 | #else |
| 1447 | auto intError = mDevice.mComposer->setLayerInfo(mDisplayId, mId, type, appId); |
| 1448 | #endif |
| 1449 | return static_cast<Error>(intError); |
| 1450 | } |
| 1451 | |
Dan Stoza | 651bf31 | 2015-10-23 17:03:17 -0700 | [diff] [blame] | 1452 | } // namespace HWC2 |