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