Chia-I Wu | 7f8d396 | 2016-09-28 21:04:23 +0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2016 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_TAG "HwcPassthrough" |
| 18 | |
Fabien Sanglard | 9b117a4 | 2017-03-21 09:39:35 -0700 | [diff] [blame] | 19 | #include "Hwc.h" |
Chia-I Wu | 7f8d396 | 2016-09-28 21:04:23 +0800 | [diff] [blame] | 20 | |
Steven Thomas | bc67a6a | 2017-07-07 12:34:20 -0700 | [diff] [blame] | 21 | #include <chrono> |
Fabien Sanglard | 9b117a4 | 2017-03-21 09:39:35 -0700 | [diff] [blame] | 22 | #include <type_traits> |
Chia-I Wu | 7f8d396 | 2016-09-28 21:04:23 +0800 | [diff] [blame] | 23 | #include <log/log.h> |
| 24 | |
Daniel Nicoara | 0a60e4b | 2017-01-09 12:51:06 -0500 | [diff] [blame] | 25 | #include "ComposerClient.h" |
Chia-I Wu | 16e8ed2 | 2017-10-19 09:49:03 -0700 | [diff] [blame] | 26 | #include "hardware/fb.h" |
Fabien Sanglard | 0d55a21 | 2017-03-16 16:56:46 -0700 | [diff] [blame] | 27 | #include "hardware/hwcomposer.h" |
| 28 | #include "hwc2on1adapter/HWC2On1Adapter.h" |
Chia-I Wu | 16e8ed2 | 2017-10-19 09:49:03 -0700 | [diff] [blame] | 29 | #include "hwc2onfbadapter/HWC2OnFbAdapter.h" |
Chia-I Wu | 7f8d396 | 2016-09-28 21:04:23 +0800 | [diff] [blame] | 30 | |
Steven Thomas | bc67a6a | 2017-07-07 12:34:20 -0700 | [diff] [blame] | 31 | using namespace std::chrono_literals; |
| 32 | |
Chia-I Wu | 7f8d396 | 2016-09-28 21:04:23 +0800 | [diff] [blame] | 33 | namespace android { |
| 34 | namespace hardware { |
| 35 | namespace graphics { |
| 36 | namespace composer { |
| 37 | namespace V2_1 { |
| 38 | namespace implementation { |
| 39 | |
Chia-I Wu | 7f8d396 | 2016-09-28 21:04:23 +0800 | [diff] [blame] | 40 | HwcHal::HwcHal(const hw_module_t* module) |
Chia-I Wu | 8101b24 | 2017-10-06 12:29:14 -0700 | [diff] [blame] | 41 | : mDevice(nullptr), mDispatch(), mMustValidateDisplay(true), mAdapter() { |
Chia-I Wu | 16e8ed2 | 2017-10-19 09:49:03 -0700 | [diff] [blame] | 42 | uint32_t majorVersion; |
| 43 | if (module->id && strcmp(module->id, GRALLOC_HARDWARE_MODULE_ID) == 0) { |
| 44 | majorVersion = initWithFb(module); |
| 45 | } else { |
| 46 | majorVersion = initWithHwc(module); |
| 47 | } |
| 48 | |
| 49 | initCapabilities(); |
| 50 | if (majorVersion >= 2 && |
| 51 | hasCapability(Capability::PRESENT_FENCE_IS_NOT_RELIABLE)) { |
| 52 | ALOGE("Present fence must be reliable from HWC2 on."); |
| 53 | abort(); |
| 54 | } |
| 55 | |
| 56 | initDispatch(); |
| 57 | } |
| 58 | |
| 59 | HwcHal::~HwcHal() |
| 60 | { |
| 61 | hwc2_close(mDevice); |
| 62 | } |
| 63 | |
| 64 | uint32_t HwcHal::initWithHwc(const hw_module_t* module) |
| 65 | { |
Fabien Sanglard | 0d55a21 | 2017-03-16 16:56:46 -0700 | [diff] [blame] | 66 | // Determine what kind of module is available (HWC2 vs HWC1.X). |
| 67 | hw_device_t* device = nullptr; |
| 68 | int error = module->methods->open(module, HWC_HARDWARE_COMPOSER, &device); |
| 69 | if (error != 0) { |
| 70 | ALOGE("Failed to open HWC device (%s), aborting", strerror(-error)); |
| 71 | abort(); |
| 72 | } |
| 73 | uint32_t majorVersion = (device->version >> 24) & 0xF; |
| 74 | |
| 75 | // If we don't have a HWC2, we need to wrap whatever we have in an adapter. |
| 76 | if (majorVersion != 2) { |
| 77 | uint32_t minorVersion = device->version & HARDWARE_API_VERSION_2_MAJ_MIN_MASK; |
| 78 | minorVersion = (minorVersion >> 16) & 0xF; |
| 79 | ALOGI("Found HWC implementation v%d.%d", majorVersion, minorVersion); |
| 80 | if (minorVersion < 1) { |
| 81 | ALOGE("Cannot adapt to HWC version %d.%d. Minimum supported is 1.1", |
| 82 | majorVersion, minorVersion); |
| 83 | abort(); |
| 84 | } |
| 85 | mAdapter = std::make_unique<HWC2On1Adapter>( |
| 86 | reinterpret_cast<hwc_composer_device_1*>(device)); |
| 87 | |
| 88 | // Place the adapter in front of the device module. |
| 89 | mDevice = mAdapter.get(); |
| 90 | } else { |
| 91 | mDevice = reinterpret_cast<hwc2_device_t*>(device); |
Chia-I Wu | 7f8d396 | 2016-09-28 21:04:23 +0800 | [diff] [blame] | 92 | } |
| 93 | |
Chia-I Wu | 16e8ed2 | 2017-10-19 09:49:03 -0700 | [diff] [blame] | 94 | return majorVersion; |
| 95 | } |
| 96 | |
| 97 | uint32_t HwcHal::initWithFb(const hw_module_t* module) |
| 98 | { |
| 99 | framebuffer_device_t* fb_device; |
| 100 | int error = framebuffer_open(module, &fb_device); |
| 101 | if (error != 0) { |
| 102 | ALOGE("Failed to open FB device (%s), aborting", strerror(-error)); |
Brian Anderson | 9af5d94 | 2017-04-04 16:16:41 -0700 | [diff] [blame] | 103 | abort(); |
| 104 | } |
| 105 | |
Chia-I Wu | 16e8ed2 | 2017-10-19 09:49:03 -0700 | [diff] [blame] | 106 | mFbAdapter = std::make_unique<HWC2OnFbAdapter>(fb_device); |
| 107 | mDevice = mFbAdapter.get(); |
Chia-I Wu | 7f8d396 | 2016-09-28 21:04:23 +0800 | [diff] [blame] | 108 | |
Chia-I Wu | 16e8ed2 | 2017-10-19 09:49:03 -0700 | [diff] [blame] | 109 | return 0; |
Chia-I Wu | 7f8d396 | 2016-09-28 21:04:23 +0800 | [diff] [blame] | 110 | } |
| 111 | |
| 112 | void HwcHal::initCapabilities() |
| 113 | { |
| 114 | uint32_t count = 0; |
| 115 | mDevice->getCapabilities(mDevice, &count, nullptr); |
| 116 | |
| 117 | std::vector<Capability> caps(count); |
| 118 | mDevice->getCapabilities(mDevice, &count, reinterpret_cast< |
| 119 | std::underlying_type<Capability>::type*>(caps.data())); |
| 120 | caps.resize(count); |
| 121 | |
| 122 | mCapabilities.insert(caps.cbegin(), caps.cend()); |
| 123 | } |
| 124 | |
| 125 | template<typename T> |
Chia-I Wu | e176835 | 2016-12-19 12:56:54 +0800 | [diff] [blame] | 126 | void HwcHal::initDispatch(hwc2_function_descriptor_t desc, T* outPfn) |
Chia-I Wu | 7f8d396 | 2016-09-28 21:04:23 +0800 | [diff] [blame] | 127 | { |
| 128 | auto pfn = mDevice->getFunction(mDevice, desc); |
| 129 | if (!pfn) { |
| 130 | LOG_ALWAYS_FATAL("failed to get hwcomposer2 function %d", desc); |
| 131 | } |
| 132 | |
Chia-I Wu | e176835 | 2016-12-19 12:56:54 +0800 | [diff] [blame] | 133 | *outPfn = reinterpret_cast<T>(pfn); |
Chia-I Wu | 7f8d396 | 2016-09-28 21:04:23 +0800 | [diff] [blame] | 134 | } |
| 135 | |
| 136 | void HwcHal::initDispatch() |
| 137 | { |
Chia-I Wu | e176835 | 2016-12-19 12:56:54 +0800 | [diff] [blame] | 138 | initDispatch(HWC2_FUNCTION_ACCEPT_DISPLAY_CHANGES, |
| 139 | &mDispatch.acceptDisplayChanges); |
| 140 | initDispatch(HWC2_FUNCTION_CREATE_LAYER, &mDispatch.createLayer); |
| 141 | initDispatch(HWC2_FUNCTION_CREATE_VIRTUAL_DISPLAY, |
| 142 | &mDispatch.createVirtualDisplay); |
| 143 | initDispatch(HWC2_FUNCTION_DESTROY_LAYER, &mDispatch.destroyLayer); |
| 144 | initDispatch(HWC2_FUNCTION_DESTROY_VIRTUAL_DISPLAY, |
| 145 | &mDispatch.destroyVirtualDisplay); |
| 146 | initDispatch(HWC2_FUNCTION_DUMP, &mDispatch.dump); |
| 147 | initDispatch(HWC2_FUNCTION_GET_ACTIVE_CONFIG, &mDispatch.getActiveConfig); |
| 148 | initDispatch(HWC2_FUNCTION_GET_CHANGED_COMPOSITION_TYPES, |
| 149 | &mDispatch.getChangedCompositionTypes); |
| 150 | initDispatch(HWC2_FUNCTION_GET_CLIENT_TARGET_SUPPORT, |
| 151 | &mDispatch.getClientTargetSupport); |
| 152 | initDispatch(HWC2_FUNCTION_GET_COLOR_MODES, &mDispatch.getColorModes); |
| 153 | initDispatch(HWC2_FUNCTION_GET_DISPLAY_ATTRIBUTE, |
| 154 | &mDispatch.getDisplayAttribute); |
| 155 | initDispatch(HWC2_FUNCTION_GET_DISPLAY_CONFIGS, |
| 156 | &mDispatch.getDisplayConfigs); |
| 157 | initDispatch(HWC2_FUNCTION_GET_DISPLAY_NAME, &mDispatch.getDisplayName); |
| 158 | initDispatch(HWC2_FUNCTION_GET_DISPLAY_REQUESTS, |
| 159 | &mDispatch.getDisplayRequests); |
| 160 | initDispatch(HWC2_FUNCTION_GET_DISPLAY_TYPE, &mDispatch.getDisplayType); |
| 161 | initDispatch(HWC2_FUNCTION_GET_DOZE_SUPPORT, &mDispatch.getDozeSupport); |
| 162 | initDispatch(HWC2_FUNCTION_GET_HDR_CAPABILITIES, |
| 163 | &mDispatch.getHdrCapabilities); |
| 164 | initDispatch(HWC2_FUNCTION_GET_MAX_VIRTUAL_DISPLAY_COUNT, |
| 165 | &mDispatch.getMaxVirtualDisplayCount); |
| 166 | initDispatch(HWC2_FUNCTION_GET_RELEASE_FENCES, |
| 167 | &mDispatch.getReleaseFences); |
| 168 | initDispatch(HWC2_FUNCTION_PRESENT_DISPLAY, &mDispatch.presentDisplay); |
| 169 | initDispatch(HWC2_FUNCTION_REGISTER_CALLBACK, |
| 170 | &mDispatch.registerCallback); |
| 171 | initDispatch(HWC2_FUNCTION_SET_ACTIVE_CONFIG, &mDispatch.setActiveConfig); |
| 172 | initDispatch(HWC2_FUNCTION_SET_CLIENT_TARGET, &mDispatch.setClientTarget); |
| 173 | initDispatch(HWC2_FUNCTION_SET_COLOR_MODE, &mDispatch.setColorMode); |
| 174 | initDispatch(HWC2_FUNCTION_SET_COLOR_TRANSFORM, |
| 175 | &mDispatch.setColorTransform); |
| 176 | initDispatch(HWC2_FUNCTION_SET_CURSOR_POSITION, |
| 177 | &mDispatch.setCursorPosition); |
| 178 | initDispatch(HWC2_FUNCTION_SET_LAYER_BLEND_MODE, |
| 179 | &mDispatch.setLayerBlendMode); |
| 180 | initDispatch(HWC2_FUNCTION_SET_LAYER_BUFFER, &mDispatch.setLayerBuffer); |
| 181 | initDispatch(HWC2_FUNCTION_SET_LAYER_COLOR, &mDispatch.setLayerColor); |
| 182 | initDispatch(HWC2_FUNCTION_SET_LAYER_COMPOSITION_TYPE, |
| 183 | &mDispatch.setLayerCompositionType); |
| 184 | initDispatch(HWC2_FUNCTION_SET_LAYER_DATASPACE, |
| 185 | &mDispatch.setLayerDataspace); |
| 186 | initDispatch(HWC2_FUNCTION_SET_LAYER_DISPLAY_FRAME, |
| 187 | &mDispatch.setLayerDisplayFrame); |
| 188 | initDispatch(HWC2_FUNCTION_SET_LAYER_PLANE_ALPHA, |
| 189 | &mDispatch.setLayerPlaneAlpha); |
Chia-I Wu | 7f8d396 | 2016-09-28 21:04:23 +0800 | [diff] [blame] | 190 | |
| 191 | if (hasCapability(Capability::SIDEBAND_STREAM)) { |
Chia-I Wu | e176835 | 2016-12-19 12:56:54 +0800 | [diff] [blame] | 192 | initDispatch(HWC2_FUNCTION_SET_LAYER_SIDEBAND_STREAM, |
| 193 | &mDispatch.setLayerSidebandStream); |
Chia-I Wu | 7f8d396 | 2016-09-28 21:04:23 +0800 | [diff] [blame] | 194 | } |
| 195 | |
Chia-I Wu | e176835 | 2016-12-19 12:56:54 +0800 | [diff] [blame] | 196 | initDispatch(HWC2_FUNCTION_SET_LAYER_SOURCE_CROP, |
| 197 | &mDispatch.setLayerSourceCrop); |
| 198 | initDispatch(HWC2_FUNCTION_SET_LAYER_SURFACE_DAMAGE, |
| 199 | &mDispatch.setLayerSurfaceDamage); |
| 200 | initDispatch(HWC2_FUNCTION_SET_LAYER_TRANSFORM, |
| 201 | &mDispatch.setLayerTransform); |
| 202 | initDispatch(HWC2_FUNCTION_SET_LAYER_VISIBLE_REGION, |
| 203 | &mDispatch.setLayerVisibleRegion); |
| 204 | initDispatch(HWC2_FUNCTION_SET_LAYER_Z_ORDER, &mDispatch.setLayerZOrder); |
| 205 | initDispatch(HWC2_FUNCTION_SET_OUTPUT_BUFFER, &mDispatch.setOutputBuffer); |
| 206 | initDispatch(HWC2_FUNCTION_SET_POWER_MODE, &mDispatch.setPowerMode); |
| 207 | initDispatch(HWC2_FUNCTION_SET_VSYNC_ENABLED, &mDispatch.setVsyncEnabled); |
| 208 | initDispatch(HWC2_FUNCTION_VALIDATE_DISPLAY, &mDispatch.validateDisplay); |
Chia-I Wu | 7f8d396 | 2016-09-28 21:04:23 +0800 | [diff] [blame] | 209 | } |
| 210 | |
| 211 | bool HwcHal::hasCapability(Capability capability) const |
| 212 | { |
| 213 | return (mCapabilities.count(capability) > 0); |
| 214 | } |
| 215 | |
| 216 | Return<void> HwcHal::getCapabilities(getCapabilities_cb hidl_cb) |
| 217 | { |
| 218 | std::vector<Capability> caps( |
| 219 | mCapabilities.cbegin(), mCapabilities.cend()); |
| 220 | |
| 221 | hidl_vec<Capability> caps_reply; |
| 222 | caps_reply.setToExternal(caps.data(), caps.size()); |
| 223 | hidl_cb(caps_reply); |
| 224 | |
| 225 | return Void(); |
| 226 | } |
| 227 | |
| 228 | Return<void> HwcHal::dumpDebugInfo(dumpDebugInfo_cb hidl_cb) |
| 229 | { |
Chia-I Wu | e176835 | 2016-12-19 12:56:54 +0800 | [diff] [blame] | 230 | uint32_t len = 0; |
Chia-I Wu | 7f8d396 | 2016-09-28 21:04:23 +0800 | [diff] [blame] | 231 | mDispatch.dump(mDevice, &len, nullptr); |
| 232 | |
| 233 | std::vector<char> buf(len + 1); |
| 234 | mDispatch.dump(mDevice, &len, buf.data()); |
| 235 | buf.resize(len + 1); |
| 236 | buf[len] = '\0'; |
| 237 | |
| 238 | hidl_string buf_reply; |
| 239 | buf_reply.setToExternal(buf.data(), len); |
| 240 | hidl_cb(buf_reply); |
| 241 | |
| 242 | return Void(); |
| 243 | } |
| 244 | |
Chia-I Wu | bb61a72 | 2016-10-24 15:40:20 +0800 | [diff] [blame] | 245 | Return<void> HwcHal::createClient(createClient_cb hidl_cb) |
| 246 | { |
| 247 | Error err = Error::NONE; |
Daniel Nicoara | 0a60e4b | 2017-01-09 12:51:06 -0500 | [diff] [blame] | 248 | sp<ComposerClient> client; |
Chia-I Wu | bb61a72 | 2016-10-24 15:40:20 +0800 | [diff] [blame] | 249 | |
| 250 | { |
Steven Thomas | bc67a6a | 2017-07-07 12:34:20 -0700 | [diff] [blame] | 251 | std::unique_lock<std::mutex> lock(mClientMutex); |
| 252 | |
| 253 | if (mClient != nullptr) { |
| 254 | // In surface flinger we delete a composer client on one thread and |
| 255 | // then create a new client on another thread. Although surface |
| 256 | // flinger ensures the calls are made in that sequence (destroy and |
| 257 | // then create), sometimes the calls land in the composer service |
| 258 | // inverted (create and then destroy). Wait for a brief period to |
| 259 | // see if the existing client is destroyed. |
| 260 | ALOGI("HwcHal::createClient: Client already exists. Waiting for" |
| 261 | " it to be destroyed."); |
| 262 | mClientDestroyedWait.wait_for(lock, 1s, |
| 263 | [this] { return mClient == nullptr; }); |
| 264 | std::string doneMsg = mClient == nullptr ? |
| 265 | "Existing client was destroyed." : |
| 266 | "Existing client was never destroyed!"; |
| 267 | ALOGI("HwcHal::createClient: Done waiting. %s", doneMsg.c_str()); |
| 268 | } |
Chia-I Wu | bb61a72 | 2016-10-24 15:40:20 +0800 | [diff] [blame] | 269 | |
| 270 | // only one client is allowed |
| 271 | if (mClient == nullptr) { |
Daniel Nicoara | 0a60e4b | 2017-01-09 12:51:06 -0500 | [diff] [blame] | 272 | client = new ComposerClient(*this); |
| 273 | client->initialize(); |
Chia-I Wu | bb61a72 | 2016-10-24 15:40:20 +0800 | [diff] [blame] | 274 | mClient = client; |
| 275 | } else { |
| 276 | err = Error::NO_RESOURCES; |
| 277 | } |
| 278 | } |
| 279 | |
| 280 | hidl_cb(err, client); |
| 281 | |
| 282 | return Void(); |
| 283 | } |
| 284 | |
Daniel Nicoara | 0a60e4b | 2017-01-09 12:51:06 -0500 | [diff] [blame] | 285 | sp<ComposerClient> HwcHal::getClient() |
Chia-I Wu | bb61a72 | 2016-10-24 15:40:20 +0800 | [diff] [blame] | 286 | { |
| 287 | std::lock_guard<std::mutex> lock(mClientMutex); |
| 288 | return (mClient != nullptr) ? mClient.promote() : nullptr; |
| 289 | } |
| 290 | |
| 291 | void HwcHal::removeClient() |
| 292 | { |
| 293 | std::lock_guard<std::mutex> lock(mClientMutex); |
| 294 | mClient = nullptr; |
Steven Thomas | bc67a6a | 2017-07-07 12:34:20 -0700 | [diff] [blame] | 295 | mClientDestroyedWait.notify_all(); |
Chia-I Wu | bb61a72 | 2016-10-24 15:40:20 +0800 | [diff] [blame] | 296 | } |
| 297 | |
Chia-I Wu | 7f8d396 | 2016-09-28 21:04:23 +0800 | [diff] [blame] | 298 | void HwcHal::hotplugHook(hwc2_callback_data_t callbackData, |
| 299 | hwc2_display_t display, int32_t connected) |
| 300 | { |
| 301 | auto hal = reinterpret_cast<HwcHal*>(callbackData); |
Chia-I Wu | bb61a72 | 2016-10-24 15:40:20 +0800 | [diff] [blame] | 302 | auto client = hal->getClient(); |
| 303 | if (client != nullptr) { |
| 304 | client->onHotplug(display, |
| 305 | static_cast<IComposerCallback::Connection>(connected)); |
Chia-I Wu | 7f8d396 | 2016-09-28 21:04:23 +0800 | [diff] [blame] | 306 | } |
Chia-I Wu | 7f8d396 | 2016-09-28 21:04:23 +0800 | [diff] [blame] | 307 | } |
| 308 | |
| 309 | void HwcHal::refreshHook(hwc2_callback_data_t callbackData, |
| 310 | hwc2_display_t display) |
| 311 | { |
| 312 | auto hal = reinterpret_cast<HwcHal*>(callbackData); |
Chia-I Wu | 8101b24 | 2017-10-06 12:29:14 -0700 | [diff] [blame] | 313 | hal->mMustValidateDisplay = true; |
| 314 | |
Chia-I Wu | bb61a72 | 2016-10-24 15:40:20 +0800 | [diff] [blame] | 315 | auto client = hal->getClient(); |
| 316 | if (client != nullptr) { |
| 317 | client->onRefresh(display); |
| 318 | } |
Chia-I Wu | 7f8d396 | 2016-09-28 21:04:23 +0800 | [diff] [blame] | 319 | } |
| 320 | |
| 321 | void HwcHal::vsyncHook(hwc2_callback_data_t callbackData, |
| 322 | hwc2_display_t display, int64_t timestamp) |
| 323 | { |
| 324 | auto hal = reinterpret_cast<HwcHal*>(callbackData); |
Chia-I Wu | bb61a72 | 2016-10-24 15:40:20 +0800 | [diff] [blame] | 325 | auto client = hal->getClient(); |
| 326 | if (client != nullptr) { |
| 327 | client->onVsync(display, timestamp); |
| 328 | } |
Chia-I Wu | 7f8d396 | 2016-09-28 21:04:23 +0800 | [diff] [blame] | 329 | } |
| 330 | |
Chia-I Wu | bb61a72 | 2016-10-24 15:40:20 +0800 | [diff] [blame] | 331 | void HwcHal::enableCallback(bool enable) |
Chia-I Wu | 7f8d396 | 2016-09-28 21:04:23 +0800 | [diff] [blame] | 332 | { |
Chia-I Wu | bb61a72 | 2016-10-24 15:40:20 +0800 | [diff] [blame] | 333 | if (enable) { |
Chia-I Wu | 8101b24 | 2017-10-06 12:29:14 -0700 | [diff] [blame] | 334 | mMustValidateDisplay = true; |
| 335 | |
Chia-I Wu | bb61a72 | 2016-10-24 15:40:20 +0800 | [diff] [blame] | 336 | mDispatch.registerCallback(mDevice, HWC2_CALLBACK_HOTPLUG, this, |
| 337 | reinterpret_cast<hwc2_function_pointer_t>(hotplugHook)); |
| 338 | mDispatch.registerCallback(mDevice, HWC2_CALLBACK_REFRESH, this, |
| 339 | reinterpret_cast<hwc2_function_pointer_t>(refreshHook)); |
| 340 | mDispatch.registerCallback(mDevice, HWC2_CALLBACK_VSYNC, this, |
| 341 | reinterpret_cast<hwc2_function_pointer_t>(vsyncHook)); |
| 342 | } else { |
| 343 | mDispatch.registerCallback(mDevice, HWC2_CALLBACK_HOTPLUG, this, |
| 344 | nullptr); |
| 345 | mDispatch.registerCallback(mDevice, HWC2_CALLBACK_REFRESH, this, |
| 346 | nullptr); |
| 347 | mDispatch.registerCallback(mDevice, HWC2_CALLBACK_VSYNC, this, |
| 348 | nullptr); |
| 349 | } |
Chia-I Wu | 7f8d396 | 2016-09-28 21:04:23 +0800 | [diff] [blame] | 350 | } |
| 351 | |
Chia-I Wu | bb61a72 | 2016-10-24 15:40:20 +0800 | [diff] [blame] | 352 | uint32_t HwcHal::getMaxVirtualDisplayCount() |
Chia-I Wu | 7f8d396 | 2016-09-28 21:04:23 +0800 | [diff] [blame] | 353 | { |
| 354 | return mDispatch.getMaxVirtualDisplayCount(mDevice); |
| 355 | } |
| 356 | |
Chia-I Wu | bb61a72 | 2016-10-24 15:40:20 +0800 | [diff] [blame] | 357 | Error HwcHal::createVirtualDisplay(uint32_t width, uint32_t height, |
Chia-I Wu | e176835 | 2016-12-19 12:56:54 +0800 | [diff] [blame] | 358 | PixelFormat* format, Display* outDisplay) |
Chia-I Wu | 7f8d396 | 2016-09-28 21:04:23 +0800 | [diff] [blame] | 359 | { |
Chia-I Wu | e176835 | 2016-12-19 12:56:54 +0800 | [diff] [blame] | 360 | int32_t hwc_format = static_cast<int32_t>(*format); |
Chia-I Wu | bb61a72 | 2016-10-24 15:40:20 +0800 | [diff] [blame] | 361 | int32_t err = mDispatch.createVirtualDisplay(mDevice, width, height, |
Chia-I Wu | e176835 | 2016-12-19 12:56:54 +0800 | [diff] [blame] | 362 | &hwc_format, outDisplay); |
| 363 | *format = static_cast<PixelFormat>(hwc_format); |
Chia-I Wu | 7f8d396 | 2016-09-28 21:04:23 +0800 | [diff] [blame] | 364 | |
Chia-I Wu | bb61a72 | 2016-10-24 15:40:20 +0800 | [diff] [blame] | 365 | return static_cast<Error>(err); |
Chia-I Wu | 7f8d396 | 2016-09-28 21:04:23 +0800 | [diff] [blame] | 366 | } |
| 367 | |
Chia-I Wu | bb61a72 | 2016-10-24 15:40:20 +0800 | [diff] [blame] | 368 | Error HwcHal::destroyVirtualDisplay(Display display) |
Chia-I Wu | 7f8d396 | 2016-09-28 21:04:23 +0800 | [diff] [blame] | 369 | { |
Chia-I Wu | bb61a72 | 2016-10-24 15:40:20 +0800 | [diff] [blame] | 370 | int32_t err = mDispatch.destroyVirtualDisplay(mDevice, display); |
| 371 | return static_cast<Error>(err); |
Chia-I Wu | 7f8d396 | 2016-09-28 21:04:23 +0800 | [diff] [blame] | 372 | } |
| 373 | |
Chia-I Wu | e176835 | 2016-12-19 12:56:54 +0800 | [diff] [blame] | 374 | Error HwcHal::createLayer(Display display, Layer* outLayer) |
Chia-I Wu | 7f8d396 | 2016-09-28 21:04:23 +0800 | [diff] [blame] | 375 | { |
Chia-I Wu | e176835 | 2016-12-19 12:56:54 +0800 | [diff] [blame] | 376 | int32_t err = mDispatch.createLayer(mDevice, display, outLayer); |
Chia-I Wu | bb61a72 | 2016-10-24 15:40:20 +0800 | [diff] [blame] | 377 | return static_cast<Error>(err); |
Chia-I Wu | 7f8d396 | 2016-09-28 21:04:23 +0800 | [diff] [blame] | 378 | } |
| 379 | |
Chia-I Wu | bb61a72 | 2016-10-24 15:40:20 +0800 | [diff] [blame] | 380 | Error HwcHal::destroyLayer(Display display, Layer layer) |
Chia-I Wu | 7f8d396 | 2016-09-28 21:04:23 +0800 | [diff] [blame] | 381 | { |
Chia-I Wu | bb61a72 | 2016-10-24 15:40:20 +0800 | [diff] [blame] | 382 | int32_t err = mDispatch.destroyLayer(mDevice, display, layer); |
| 383 | return static_cast<Error>(err); |
Chia-I Wu | 7f8d396 | 2016-09-28 21:04:23 +0800 | [diff] [blame] | 384 | } |
| 385 | |
Chia-I Wu | e176835 | 2016-12-19 12:56:54 +0800 | [diff] [blame] | 386 | Error HwcHal::getActiveConfig(Display display, Config* outConfig) |
Chia-I Wu | 7f8d396 | 2016-09-28 21:04:23 +0800 | [diff] [blame] | 387 | { |
Chia-I Wu | e176835 | 2016-12-19 12:56:54 +0800 | [diff] [blame] | 388 | int32_t err = mDispatch.getActiveConfig(mDevice, display, outConfig); |
Chia-I Wu | bb61a72 | 2016-10-24 15:40:20 +0800 | [diff] [blame] | 389 | return static_cast<Error>(err); |
Chia-I Wu | 7f8d396 | 2016-09-28 21:04:23 +0800 | [diff] [blame] | 390 | } |
| 391 | |
Chia-I Wu | bb61a72 | 2016-10-24 15:40:20 +0800 | [diff] [blame] | 392 | Error HwcHal::getClientTargetSupport(Display display, |
Chia-I Wu | 7f8d396 | 2016-09-28 21:04:23 +0800 | [diff] [blame] | 393 | uint32_t width, uint32_t height, |
| 394 | PixelFormat format, Dataspace dataspace) |
| 395 | { |
Chia-I Wu | bb61a72 | 2016-10-24 15:40:20 +0800 | [diff] [blame] | 396 | int32_t err = mDispatch.getClientTargetSupport(mDevice, display, |
Chia-I Wu | 7f8d396 | 2016-09-28 21:04:23 +0800 | [diff] [blame] | 397 | width, height, static_cast<int32_t>(format), |
| 398 | static_cast<int32_t>(dataspace)); |
Chia-I Wu | bb61a72 | 2016-10-24 15:40:20 +0800 | [diff] [blame] | 399 | return static_cast<Error>(err); |
Chia-I Wu | 7f8d396 | 2016-09-28 21:04:23 +0800 | [diff] [blame] | 400 | } |
| 401 | |
Chia-I Wu | e176835 | 2016-12-19 12:56:54 +0800 | [diff] [blame] | 402 | Error HwcHal::getColorModes(Display display, hidl_vec<ColorMode>* outModes) |
Chia-I Wu | 7f8d396 | 2016-09-28 21:04:23 +0800 | [diff] [blame] | 403 | { |
| 404 | uint32_t count = 0; |
Chia-I Wu | bb61a72 | 2016-10-24 15:40:20 +0800 | [diff] [blame] | 405 | int32_t err = mDispatch.getColorModes(mDevice, display, &count, nullptr); |
| 406 | if (err != HWC2_ERROR_NONE) { |
| 407 | return static_cast<Error>(err); |
Chia-I Wu | 7f8d396 | 2016-09-28 21:04:23 +0800 | [diff] [blame] | 408 | } |
| 409 | |
Chia-I Wu | e176835 | 2016-12-19 12:56:54 +0800 | [diff] [blame] | 410 | outModes->resize(count); |
Chia-I Wu | bb61a72 | 2016-10-24 15:40:20 +0800 | [diff] [blame] | 411 | err = mDispatch.getColorModes(mDevice, display, &count, |
Chia-I Wu | 7f8d396 | 2016-09-28 21:04:23 +0800 | [diff] [blame] | 412 | reinterpret_cast<std::underlying_type<ColorMode>::type*>( |
Chia-I Wu | e176835 | 2016-12-19 12:56:54 +0800 | [diff] [blame] | 413 | outModes->data())); |
Chia-I Wu | bb61a72 | 2016-10-24 15:40:20 +0800 | [diff] [blame] | 414 | if (err != HWC2_ERROR_NONE) { |
Chia-I Wu | e176835 | 2016-12-19 12:56:54 +0800 | [diff] [blame] | 415 | *outModes = hidl_vec<ColorMode>(); |
Chia-I Wu | bb61a72 | 2016-10-24 15:40:20 +0800 | [diff] [blame] | 416 | return static_cast<Error>(err); |
Chia-I Wu | 7f8d396 | 2016-09-28 21:04:23 +0800 | [diff] [blame] | 417 | } |
Chia-I Wu | 7f8d396 | 2016-09-28 21:04:23 +0800 | [diff] [blame] | 418 | |
Chia-I Wu | bb61a72 | 2016-10-24 15:40:20 +0800 | [diff] [blame] | 419 | return Error::NONE; |
Chia-I Wu | 7f8d396 | 2016-09-28 21:04:23 +0800 | [diff] [blame] | 420 | } |
| 421 | |
Chia-I Wu | bb61a72 | 2016-10-24 15:40:20 +0800 | [diff] [blame] | 422 | Error HwcHal::getDisplayAttribute(Display display, Config config, |
Chia-I Wu | e176835 | 2016-12-19 12:56:54 +0800 | [diff] [blame] | 423 | IComposerClient::Attribute attribute, int32_t* outValue) |
Chia-I Wu | 7f8d396 | 2016-09-28 21:04:23 +0800 | [diff] [blame] | 424 | { |
Chia-I Wu | bb61a72 | 2016-10-24 15:40:20 +0800 | [diff] [blame] | 425 | int32_t err = mDispatch.getDisplayAttribute(mDevice, display, config, |
Chia-I Wu | e176835 | 2016-12-19 12:56:54 +0800 | [diff] [blame] | 426 | static_cast<int32_t>(attribute), outValue); |
Chia-I Wu | bb61a72 | 2016-10-24 15:40:20 +0800 | [diff] [blame] | 427 | return static_cast<Error>(err); |
Chia-I Wu | 7f8d396 | 2016-09-28 21:04:23 +0800 | [diff] [blame] | 428 | } |
| 429 | |
Chia-I Wu | e176835 | 2016-12-19 12:56:54 +0800 | [diff] [blame] | 430 | Error HwcHal::getDisplayConfigs(Display display, hidl_vec<Config>* outConfigs) |
Chia-I Wu | 7f8d396 | 2016-09-28 21:04:23 +0800 | [diff] [blame] | 431 | { |
| 432 | uint32_t count = 0; |
Chia-I Wu | bb61a72 | 2016-10-24 15:40:20 +0800 | [diff] [blame] | 433 | int32_t err = mDispatch.getDisplayConfigs(mDevice, display, |
Chia-I Wu | 7f8d396 | 2016-09-28 21:04:23 +0800 | [diff] [blame] | 434 | &count, nullptr); |
Chia-I Wu | bb61a72 | 2016-10-24 15:40:20 +0800 | [diff] [blame] | 435 | if (err != HWC2_ERROR_NONE) { |
| 436 | return static_cast<Error>(err); |
Chia-I Wu | 7f8d396 | 2016-09-28 21:04:23 +0800 | [diff] [blame] | 437 | } |
| 438 | |
Chia-I Wu | e176835 | 2016-12-19 12:56:54 +0800 | [diff] [blame] | 439 | outConfigs->resize(count); |
Chia-I Wu | bb61a72 | 2016-10-24 15:40:20 +0800 | [diff] [blame] | 440 | err = mDispatch.getDisplayConfigs(mDevice, display, |
Chia-I Wu | e176835 | 2016-12-19 12:56:54 +0800 | [diff] [blame] | 441 | &count, outConfigs->data()); |
Chia-I Wu | bb61a72 | 2016-10-24 15:40:20 +0800 | [diff] [blame] | 442 | if (err != HWC2_ERROR_NONE) { |
Chia-I Wu | e176835 | 2016-12-19 12:56:54 +0800 | [diff] [blame] | 443 | *outConfigs = hidl_vec<Config>(); |
Chia-I Wu | bb61a72 | 2016-10-24 15:40:20 +0800 | [diff] [blame] | 444 | return static_cast<Error>(err); |
| 445 | } |
Chia-I Wu | 7f8d396 | 2016-09-28 21:04:23 +0800 | [diff] [blame] | 446 | |
Chia-I Wu | bb61a72 | 2016-10-24 15:40:20 +0800 | [diff] [blame] | 447 | return Error::NONE; |
Chia-I Wu | 7f8d396 | 2016-09-28 21:04:23 +0800 | [diff] [blame] | 448 | } |
| 449 | |
Chia-I Wu | e176835 | 2016-12-19 12:56:54 +0800 | [diff] [blame] | 450 | Error HwcHal::getDisplayName(Display display, hidl_string* outName) |
Chia-I Wu | 7f8d396 | 2016-09-28 21:04:23 +0800 | [diff] [blame] | 451 | { |
| 452 | uint32_t count = 0; |
Chia-I Wu | bb61a72 | 2016-10-24 15:40:20 +0800 | [diff] [blame] | 453 | int32_t err = mDispatch.getDisplayName(mDevice, display, &count, nullptr); |
| 454 | if (err != HWC2_ERROR_NONE) { |
| 455 | return static_cast<Error>(err); |
Chia-I Wu | 7f8d396 | 2016-09-28 21:04:23 +0800 | [diff] [blame] | 456 | } |
| 457 | |
Chia-I Wu | bb61a72 | 2016-10-24 15:40:20 +0800 | [diff] [blame] | 458 | std::vector<char> buf(count + 1); |
| 459 | err = mDispatch.getDisplayName(mDevice, display, &count, buf.data()); |
| 460 | if (err != HWC2_ERROR_NONE) { |
| 461 | return static_cast<Error>(err); |
Chia-I Wu | 7f8d396 | 2016-09-28 21:04:23 +0800 | [diff] [blame] | 462 | } |
Chia-I Wu | bb61a72 | 2016-10-24 15:40:20 +0800 | [diff] [blame] | 463 | buf.resize(count + 1); |
| 464 | buf[count] = '\0'; |
Chia-I Wu | 7f8d396 | 2016-09-28 21:04:23 +0800 | [diff] [blame] | 465 | |
Chia-I Wu | e176835 | 2016-12-19 12:56:54 +0800 | [diff] [blame] | 466 | *outName = buf.data(); |
Chia-I Wu | 7f8d396 | 2016-09-28 21:04:23 +0800 | [diff] [blame] | 467 | |
Chia-I Wu | bb61a72 | 2016-10-24 15:40:20 +0800 | [diff] [blame] | 468 | return Error::NONE; |
Chia-I Wu | 7f8d396 | 2016-09-28 21:04:23 +0800 | [diff] [blame] | 469 | } |
| 470 | |
Chia-I Wu | e176835 | 2016-12-19 12:56:54 +0800 | [diff] [blame] | 471 | Error HwcHal::getDisplayType(Display display, |
| 472 | IComposerClient::DisplayType* outType) |
Chia-I Wu | 7f8d396 | 2016-09-28 21:04:23 +0800 | [diff] [blame] | 473 | { |
Chia-I Wu | bb61a72 | 2016-10-24 15:40:20 +0800 | [diff] [blame] | 474 | int32_t hwc_type = HWC2_DISPLAY_TYPE_INVALID; |
| 475 | int32_t err = mDispatch.getDisplayType(mDevice, display, &hwc_type); |
Chia-I Wu | e176835 | 2016-12-19 12:56:54 +0800 | [diff] [blame] | 476 | *outType = static_cast<IComposerClient::DisplayType>(hwc_type); |
Chia-I Wu | bb61a72 | 2016-10-24 15:40:20 +0800 | [diff] [blame] | 477 | |
| 478 | return static_cast<Error>(err); |
| 479 | } |
| 480 | |
Chia-I Wu | e176835 | 2016-12-19 12:56:54 +0800 | [diff] [blame] | 481 | Error HwcHal::getDozeSupport(Display display, bool* outSupport) |
Chia-I Wu | bb61a72 | 2016-10-24 15:40:20 +0800 | [diff] [blame] | 482 | { |
| 483 | int32_t hwc_support = 0; |
| 484 | int32_t err = mDispatch.getDozeSupport(mDevice, display, &hwc_support); |
Chia-I Wu | e176835 | 2016-12-19 12:56:54 +0800 | [diff] [blame] | 485 | *outSupport = hwc_support; |
Chia-I Wu | bb61a72 | 2016-10-24 15:40:20 +0800 | [diff] [blame] | 486 | |
| 487 | return static_cast<Error>(err); |
| 488 | } |
| 489 | |
Chia-I Wu | e176835 | 2016-12-19 12:56:54 +0800 | [diff] [blame] | 490 | Error HwcHal::getHdrCapabilities(Display display, hidl_vec<Hdr>* outTypes, |
| 491 | float* outMaxLuminance, float* outMaxAverageLuminance, |
| 492 | float* outMinLuminance) |
Chia-I Wu | bb61a72 | 2016-10-24 15:40:20 +0800 | [diff] [blame] | 493 | { |
Chia-I Wu | 7f8d396 | 2016-09-28 21:04:23 +0800 | [diff] [blame] | 494 | uint32_t count = 0; |
Chia-I Wu | bb61a72 | 2016-10-24 15:40:20 +0800 | [diff] [blame] | 495 | int32_t err = mDispatch.getHdrCapabilities(mDevice, display, &count, |
Chia-I Wu | e176835 | 2016-12-19 12:56:54 +0800 | [diff] [blame] | 496 | nullptr, outMaxLuminance, outMaxAverageLuminance, |
| 497 | outMinLuminance); |
Chia-I Wu | bb61a72 | 2016-10-24 15:40:20 +0800 | [diff] [blame] | 498 | if (err != HWC2_ERROR_NONE) { |
| 499 | return static_cast<Error>(err); |
Chia-I Wu | 7f8d396 | 2016-09-28 21:04:23 +0800 | [diff] [blame] | 500 | } |
| 501 | |
Chia-I Wu | e176835 | 2016-12-19 12:56:54 +0800 | [diff] [blame] | 502 | outTypes->resize(count); |
Chia-I Wu | bb61a72 | 2016-10-24 15:40:20 +0800 | [diff] [blame] | 503 | err = mDispatch.getHdrCapabilities(mDevice, display, &count, |
Chia-I Wu | e176835 | 2016-12-19 12:56:54 +0800 | [diff] [blame] | 504 | reinterpret_cast<std::underlying_type<Hdr>::type*>( |
| 505 | outTypes->data()), outMaxLuminance, |
| 506 | outMaxAverageLuminance, outMinLuminance); |
Chia-I Wu | bb61a72 | 2016-10-24 15:40:20 +0800 | [diff] [blame] | 507 | if (err != HWC2_ERROR_NONE) { |
Chia-I Wu | e176835 | 2016-12-19 12:56:54 +0800 | [diff] [blame] | 508 | *outTypes = hidl_vec<Hdr>(); |
Chia-I Wu | bb61a72 | 2016-10-24 15:40:20 +0800 | [diff] [blame] | 509 | return static_cast<Error>(err); |
| 510 | } |
Chia-I Wu | 7f8d396 | 2016-09-28 21:04:23 +0800 | [diff] [blame] | 511 | |
Chia-I Wu | bb61a72 | 2016-10-24 15:40:20 +0800 | [diff] [blame] | 512 | return Error::NONE; |
Chia-I Wu | 7f8d396 | 2016-09-28 21:04:23 +0800 | [diff] [blame] | 513 | } |
| 514 | |
Chia-I Wu | bb61a72 | 2016-10-24 15:40:20 +0800 | [diff] [blame] | 515 | Error HwcHal::setActiveConfig(Display display, Config config) |
Chia-I Wu | 7f8d396 | 2016-09-28 21:04:23 +0800 | [diff] [blame] | 516 | { |
Chia-I Wu | bb61a72 | 2016-10-24 15:40:20 +0800 | [diff] [blame] | 517 | int32_t err = mDispatch.setActiveConfig(mDevice, display, config); |
| 518 | return static_cast<Error>(err); |
Chia-I Wu | 7f8d396 | 2016-09-28 21:04:23 +0800 | [diff] [blame] | 519 | } |
| 520 | |
Chia-I Wu | bb61a72 | 2016-10-24 15:40:20 +0800 | [diff] [blame] | 521 | Error HwcHal::setColorMode(Display display, ColorMode mode) |
Chia-I Wu | 7f8d396 | 2016-09-28 21:04:23 +0800 | [diff] [blame] | 522 | { |
Chia-I Wu | bb61a72 | 2016-10-24 15:40:20 +0800 | [diff] [blame] | 523 | int32_t err = mDispatch.setColorMode(mDevice, display, |
Chia-I Wu | 7f8d396 | 2016-09-28 21:04:23 +0800 | [diff] [blame] | 524 | static_cast<int32_t>(mode)); |
Chia-I Wu | bb61a72 | 2016-10-24 15:40:20 +0800 | [diff] [blame] | 525 | return static_cast<Error>(err); |
Chia-I Wu | 7f8d396 | 2016-09-28 21:04:23 +0800 | [diff] [blame] | 526 | } |
| 527 | |
Chia-I Wu | bb61a72 | 2016-10-24 15:40:20 +0800 | [diff] [blame] | 528 | Error HwcHal::setPowerMode(Display display, IComposerClient::PowerMode mode) |
Chia-I Wu | 7f8d396 | 2016-09-28 21:04:23 +0800 | [diff] [blame] | 529 | { |
Chia-I Wu | bb61a72 | 2016-10-24 15:40:20 +0800 | [diff] [blame] | 530 | int32_t err = mDispatch.setPowerMode(mDevice, display, |
Chia-I Wu | 7f8d396 | 2016-09-28 21:04:23 +0800 | [diff] [blame] | 531 | static_cast<int32_t>(mode)); |
Chia-I Wu | bb61a72 | 2016-10-24 15:40:20 +0800 | [diff] [blame] | 532 | return static_cast<Error>(err); |
Chia-I Wu | 7f8d396 | 2016-09-28 21:04:23 +0800 | [diff] [blame] | 533 | } |
| 534 | |
Chia-I Wu | bb61a72 | 2016-10-24 15:40:20 +0800 | [diff] [blame] | 535 | Error HwcHal::setVsyncEnabled(Display display, IComposerClient::Vsync enabled) |
Chia-I Wu | 7f8d396 | 2016-09-28 21:04:23 +0800 | [diff] [blame] | 536 | { |
Chia-I Wu | bb61a72 | 2016-10-24 15:40:20 +0800 | [diff] [blame] | 537 | int32_t err = mDispatch.setVsyncEnabled(mDevice, display, |
Chia-I Wu | 7f8d396 | 2016-09-28 21:04:23 +0800 | [diff] [blame] | 538 | static_cast<int32_t>(enabled)); |
Chia-I Wu | bb61a72 | 2016-10-24 15:40:20 +0800 | [diff] [blame] | 539 | return static_cast<Error>(err); |
Chia-I Wu | 7f8d396 | 2016-09-28 21:04:23 +0800 | [diff] [blame] | 540 | } |
| 541 | |
Chia-I Wu | bb61a72 | 2016-10-24 15:40:20 +0800 | [diff] [blame] | 542 | Error HwcHal::setColorTransform(Display display, const float* matrix, |
| 543 | int32_t hint) |
| 544 | { |
| 545 | int32_t err = mDispatch.setColorTransform(mDevice, display, matrix, hint); |
| 546 | return static_cast<Error>(err); |
| 547 | } |
| 548 | |
| 549 | Error HwcHal::setClientTarget(Display display, buffer_handle_t target, |
| 550 | int32_t acquireFence, int32_t dataspace, |
| 551 | const std::vector<hwc_rect_t>& damage) |
| 552 | { |
| 553 | hwc_region region = { damage.size(), damage.data() }; |
| 554 | int32_t err = mDispatch.setClientTarget(mDevice, display, target, |
| 555 | acquireFence, dataspace, region); |
| 556 | return static_cast<Error>(err); |
| 557 | } |
| 558 | |
| 559 | Error HwcHal::setOutputBuffer(Display display, buffer_handle_t buffer, |
| 560 | int32_t releaseFence) |
| 561 | { |
| 562 | int32_t err = mDispatch.setOutputBuffer(mDevice, display, buffer, |
| 563 | releaseFence); |
| 564 | // unlike in setClientTarget, releaseFence is owned by us |
| 565 | if (err == HWC2_ERROR_NONE && releaseFence >= 0) { |
| 566 | close(releaseFence); |
| 567 | } |
| 568 | |
| 569 | return static_cast<Error>(err); |
| 570 | } |
| 571 | |
| 572 | Error HwcHal::validateDisplay(Display display, |
Chia-I Wu | e176835 | 2016-12-19 12:56:54 +0800 | [diff] [blame] | 573 | std::vector<Layer>* outChangedLayers, |
| 574 | std::vector<IComposerClient::Composition>* outCompositionTypes, |
| 575 | uint32_t* outDisplayRequestMask, |
| 576 | std::vector<Layer>* outRequestedLayers, |
| 577 | std::vector<uint32_t>* outRequestMasks) |
Chia-I Wu | 7f8d396 | 2016-09-28 21:04:23 +0800 | [diff] [blame] | 578 | { |
| 579 | uint32_t types_count = 0; |
| 580 | uint32_t reqs_count = 0; |
Chia-I Wu | bb61a72 | 2016-10-24 15:40:20 +0800 | [diff] [blame] | 581 | int32_t err = mDispatch.validateDisplay(mDevice, display, |
Chia-I Wu | 7f8d396 | 2016-09-28 21:04:23 +0800 | [diff] [blame] | 582 | &types_count, &reqs_count); |
Chia-I Wu | 8101b24 | 2017-10-06 12:29:14 -0700 | [diff] [blame] | 583 | mMustValidateDisplay = false; |
| 584 | |
Chia-I Wu | bb61a72 | 2016-10-24 15:40:20 +0800 | [diff] [blame] | 585 | if (err != HWC2_ERROR_NONE && err != HWC2_ERROR_HAS_CHANGES) { |
| 586 | return static_cast<Error>(err); |
Chia-I Wu | 7f8d396 | 2016-09-28 21:04:23 +0800 | [diff] [blame] | 587 | } |
| 588 | |
Chia-I Wu | bb61a72 | 2016-10-24 15:40:20 +0800 | [diff] [blame] | 589 | err = mDispatch.getChangedCompositionTypes(mDevice, display, |
| 590 | &types_count, nullptr, nullptr); |
| 591 | if (err != HWC2_ERROR_NONE) { |
| 592 | return static_cast<Error>(err); |
Chia-I Wu | 7f8d396 | 2016-09-28 21:04:23 +0800 | [diff] [blame] | 593 | } |
| 594 | |
Chia-I Wu | e176835 | 2016-12-19 12:56:54 +0800 | [diff] [blame] | 595 | outChangedLayers->resize(types_count); |
| 596 | outCompositionTypes->resize(types_count); |
Chia-I Wu | bb61a72 | 2016-10-24 15:40:20 +0800 | [diff] [blame] | 597 | err = mDispatch.getChangedCompositionTypes(mDevice, display, |
Chia-I Wu | e176835 | 2016-12-19 12:56:54 +0800 | [diff] [blame] | 598 | &types_count, outChangedLayers->data(), |
Chia-I Wu | bb61a72 | 2016-10-24 15:40:20 +0800 | [diff] [blame] | 599 | reinterpret_cast< |
| 600 | std::underlying_type<IComposerClient::Composition>::type*>( |
Chia-I Wu | e176835 | 2016-12-19 12:56:54 +0800 | [diff] [blame] | 601 | outCompositionTypes->data())); |
Chia-I Wu | bb61a72 | 2016-10-24 15:40:20 +0800 | [diff] [blame] | 602 | if (err != HWC2_ERROR_NONE) { |
Chia-I Wu | e176835 | 2016-12-19 12:56:54 +0800 | [diff] [blame] | 603 | outChangedLayers->clear(); |
| 604 | outCompositionTypes->clear(); |
Chia-I Wu | bb61a72 | 2016-10-24 15:40:20 +0800 | [diff] [blame] | 605 | return static_cast<Error>(err); |
Chia-I Wu | 7f8d396 | 2016-09-28 21:04:23 +0800 | [diff] [blame] | 606 | } |
| 607 | |
Chia-I Wu | bb61a72 | 2016-10-24 15:40:20 +0800 | [diff] [blame] | 608 | int32_t display_reqs = 0; |
| 609 | err = mDispatch.getDisplayRequests(mDevice, display, &display_reqs, |
| 610 | &reqs_count, nullptr, nullptr); |
| 611 | if (err != HWC2_ERROR_NONE) { |
Chia-I Wu | e176835 | 2016-12-19 12:56:54 +0800 | [diff] [blame] | 612 | outChangedLayers->clear(); |
| 613 | outCompositionTypes->clear(); |
Chia-I Wu | bb61a72 | 2016-10-24 15:40:20 +0800 | [diff] [blame] | 614 | return static_cast<Error>(err); |
| 615 | } |
| 616 | |
Chia-I Wu | e176835 | 2016-12-19 12:56:54 +0800 | [diff] [blame] | 617 | outRequestedLayers->resize(reqs_count); |
| 618 | outRequestMasks->resize(reqs_count); |
Chia-I Wu | bb61a72 | 2016-10-24 15:40:20 +0800 | [diff] [blame] | 619 | err = mDispatch.getDisplayRequests(mDevice, display, &display_reqs, |
Chia-I Wu | e176835 | 2016-12-19 12:56:54 +0800 | [diff] [blame] | 620 | &reqs_count, outRequestedLayers->data(), |
| 621 | reinterpret_cast<int32_t*>(outRequestMasks->data())); |
Chia-I Wu | bb61a72 | 2016-10-24 15:40:20 +0800 | [diff] [blame] | 622 | if (err != HWC2_ERROR_NONE) { |
Chia-I Wu | e176835 | 2016-12-19 12:56:54 +0800 | [diff] [blame] | 623 | outChangedLayers->clear(); |
| 624 | outCompositionTypes->clear(); |
Chia-I Wu | bb61a72 | 2016-10-24 15:40:20 +0800 | [diff] [blame] | 625 | |
Chia-I Wu | e176835 | 2016-12-19 12:56:54 +0800 | [diff] [blame] | 626 | outRequestedLayers->clear(); |
| 627 | outRequestMasks->clear(); |
Chia-I Wu | bb61a72 | 2016-10-24 15:40:20 +0800 | [diff] [blame] | 628 | return static_cast<Error>(err); |
| 629 | } |
| 630 | |
Chia-I Wu | e176835 | 2016-12-19 12:56:54 +0800 | [diff] [blame] | 631 | *outDisplayRequestMask = display_reqs; |
Chia-I Wu | bb61a72 | 2016-10-24 15:40:20 +0800 | [diff] [blame] | 632 | |
| 633 | return static_cast<Error>(err); |
Chia-I Wu | 7f8d396 | 2016-09-28 21:04:23 +0800 | [diff] [blame] | 634 | } |
| 635 | |
Chia-I Wu | bb61a72 | 2016-10-24 15:40:20 +0800 | [diff] [blame] | 636 | Error HwcHal::acceptDisplayChanges(Display display) |
Chia-I Wu | 7f8d396 | 2016-09-28 21:04:23 +0800 | [diff] [blame] | 637 | { |
Chia-I Wu | bb61a72 | 2016-10-24 15:40:20 +0800 | [diff] [blame] | 638 | int32_t err = mDispatch.acceptDisplayChanges(mDevice, display); |
| 639 | return static_cast<Error>(err); |
Chia-I Wu | 7f8d396 | 2016-09-28 21:04:23 +0800 | [diff] [blame] | 640 | } |
| 641 | |
Chia-I Wu | e176835 | 2016-12-19 12:56:54 +0800 | [diff] [blame] | 642 | Error HwcHal::presentDisplay(Display display, int32_t* outPresentFence, |
| 643 | std::vector<Layer>* outLayers, std::vector<int32_t>* outReleaseFences) |
Chia-I Wu | 7f8d396 | 2016-09-28 21:04:23 +0800 | [diff] [blame] | 644 | { |
Chia-I Wu | 8101b24 | 2017-10-06 12:29:14 -0700 | [diff] [blame] | 645 | if (mMustValidateDisplay) { |
| 646 | return Error::NOT_VALIDATED; |
| 647 | } |
| 648 | |
Chia-I Wu | e176835 | 2016-12-19 12:56:54 +0800 | [diff] [blame] | 649 | *outPresentFence = -1; |
| 650 | int32_t err = mDispatch.presentDisplay(mDevice, display, outPresentFence); |
Chia-I Wu | bb61a72 | 2016-10-24 15:40:20 +0800 | [diff] [blame] | 651 | if (err != HWC2_ERROR_NONE) { |
| 652 | return static_cast<Error>(err); |
| 653 | } |
| 654 | |
| 655 | uint32_t count = 0; |
| 656 | err = mDispatch.getReleaseFences(mDevice, display, &count, |
| 657 | nullptr, nullptr); |
| 658 | if (err != HWC2_ERROR_NONE) { |
| 659 | ALOGW("failed to get release fences"); |
| 660 | return Error::NONE; |
| 661 | } |
| 662 | |
Chia-I Wu | e176835 | 2016-12-19 12:56:54 +0800 | [diff] [blame] | 663 | outLayers->resize(count); |
| 664 | outReleaseFences->resize(count); |
Chia-I Wu | bb61a72 | 2016-10-24 15:40:20 +0800 | [diff] [blame] | 665 | err = mDispatch.getReleaseFences(mDevice, display, &count, |
Chia-I Wu | e176835 | 2016-12-19 12:56:54 +0800 | [diff] [blame] | 666 | outLayers->data(), outReleaseFences->data()); |
Chia-I Wu | bb61a72 | 2016-10-24 15:40:20 +0800 | [diff] [blame] | 667 | if (err != HWC2_ERROR_NONE) { |
| 668 | ALOGW("failed to get release fences"); |
Chia-I Wu | e176835 | 2016-12-19 12:56:54 +0800 | [diff] [blame] | 669 | outLayers->clear(); |
| 670 | outReleaseFences->clear(); |
Chia-I Wu | bb61a72 | 2016-10-24 15:40:20 +0800 | [diff] [blame] | 671 | return Error::NONE; |
| 672 | } |
| 673 | |
| 674 | return static_cast<Error>(err); |
Chia-I Wu | 7f8d396 | 2016-09-28 21:04:23 +0800 | [diff] [blame] | 675 | } |
| 676 | |
Chia-I Wu | bb61a72 | 2016-10-24 15:40:20 +0800 | [diff] [blame] | 677 | Error HwcHal::setLayerCursorPosition(Display display, Layer layer, |
| 678 | int32_t x, int32_t y) |
| 679 | { |
| 680 | int32_t err = mDispatch.setCursorPosition(mDevice, display, layer, x, y); |
| 681 | return static_cast<Error>(err); |
| 682 | } |
| 683 | |
| 684 | Error HwcHal::setLayerBuffer(Display display, Layer layer, |
| 685 | buffer_handle_t buffer, int32_t acquireFence) |
| 686 | { |
| 687 | int32_t err = mDispatch.setLayerBuffer(mDevice, display, layer, |
| 688 | buffer, acquireFence); |
| 689 | return static_cast<Error>(err); |
| 690 | } |
| 691 | |
| 692 | Error HwcHal::setLayerSurfaceDamage(Display display, Layer layer, |
| 693 | const std::vector<hwc_rect_t>& damage) |
| 694 | { |
| 695 | hwc_region region = { damage.size(), damage.data() }; |
| 696 | int32_t err = mDispatch.setLayerSurfaceDamage(mDevice, display, layer, |
| 697 | region); |
| 698 | return static_cast<Error>(err); |
| 699 | } |
| 700 | |
| 701 | Error HwcHal::setLayerBlendMode(Display display, Layer layer, int32_t mode) |
| 702 | { |
| 703 | int32_t err = mDispatch.setLayerBlendMode(mDevice, display, layer, mode); |
| 704 | return static_cast<Error>(err); |
| 705 | } |
| 706 | |
| 707 | Error HwcHal::setLayerColor(Display display, Layer layer, |
| 708 | IComposerClient::Color color) |
Chia-I Wu | 7f8d396 | 2016-09-28 21:04:23 +0800 | [diff] [blame] | 709 | { |
| 710 | hwc_color_t hwc_color{color.r, color.g, color.b, color.a}; |
Chia-I Wu | bb61a72 | 2016-10-24 15:40:20 +0800 | [diff] [blame] | 711 | int32_t err = mDispatch.setLayerColor(mDevice, display, layer, hwc_color); |
| 712 | return static_cast<Error>(err); |
Chia-I Wu | 7f8d396 | 2016-09-28 21:04:23 +0800 | [diff] [blame] | 713 | } |
| 714 | |
Chia-I Wu | bb61a72 | 2016-10-24 15:40:20 +0800 | [diff] [blame] | 715 | Error HwcHal::setLayerCompositionType(Display display, Layer layer, |
| 716 | int32_t type) |
Chia-I Wu | 7f8d396 | 2016-09-28 21:04:23 +0800 | [diff] [blame] | 717 | { |
Chia-I Wu | bb61a72 | 2016-10-24 15:40:20 +0800 | [diff] [blame] | 718 | int32_t err = mDispatch.setLayerCompositionType(mDevice, display, layer, |
| 719 | type); |
| 720 | return static_cast<Error>(err); |
Chia-I Wu | 7f8d396 | 2016-09-28 21:04:23 +0800 | [diff] [blame] | 721 | } |
| 722 | |
Chia-I Wu | bb61a72 | 2016-10-24 15:40:20 +0800 | [diff] [blame] | 723 | Error HwcHal::setLayerDataspace(Display display, Layer layer, |
| 724 | int32_t dataspace) |
Chia-I Wu | 7f8d396 | 2016-09-28 21:04:23 +0800 | [diff] [blame] | 725 | { |
Chia-I Wu | bb61a72 | 2016-10-24 15:40:20 +0800 | [diff] [blame] | 726 | int32_t err = mDispatch.setLayerDataspace(mDevice, display, layer, |
| 727 | dataspace); |
| 728 | return static_cast<Error>(err); |
Chia-I Wu | 7f8d396 | 2016-09-28 21:04:23 +0800 | [diff] [blame] | 729 | } |
| 730 | |
Chia-I Wu | bb61a72 | 2016-10-24 15:40:20 +0800 | [diff] [blame] | 731 | Error HwcHal::setLayerDisplayFrame(Display display, Layer layer, |
| 732 | const hwc_rect_t& frame) |
Chia-I Wu | 7f8d396 | 2016-09-28 21:04:23 +0800 | [diff] [blame] | 733 | { |
Chia-I Wu | bb61a72 | 2016-10-24 15:40:20 +0800 | [diff] [blame] | 734 | int32_t err = mDispatch.setLayerDisplayFrame(mDevice, display, layer, |
| 735 | frame); |
| 736 | return static_cast<Error>(err); |
Chia-I Wu | 7f8d396 | 2016-09-28 21:04:23 +0800 | [diff] [blame] | 737 | } |
| 738 | |
Chia-I Wu | bb61a72 | 2016-10-24 15:40:20 +0800 | [diff] [blame] | 739 | Error HwcHal::setLayerPlaneAlpha(Display display, Layer layer, float alpha) |
Chia-I Wu | 7f8d396 | 2016-09-28 21:04:23 +0800 | [diff] [blame] | 740 | { |
Chia-I Wu | bb61a72 | 2016-10-24 15:40:20 +0800 | [diff] [blame] | 741 | int32_t err = mDispatch.setLayerPlaneAlpha(mDevice, display, layer, |
| 742 | alpha); |
| 743 | return static_cast<Error>(err); |
Chia-I Wu | 7f8d396 | 2016-09-28 21:04:23 +0800 | [diff] [blame] | 744 | } |
| 745 | |
Chia-I Wu | bb61a72 | 2016-10-24 15:40:20 +0800 | [diff] [blame] | 746 | Error HwcHal::setLayerSidebandStream(Display display, Layer layer, |
| 747 | buffer_handle_t stream) |
Chia-I Wu | 7f8d396 | 2016-09-28 21:04:23 +0800 | [diff] [blame] | 748 | { |
Chia-I Wu | bb61a72 | 2016-10-24 15:40:20 +0800 | [diff] [blame] | 749 | int32_t err = mDispatch.setLayerSidebandStream(mDevice, display, layer, |
| 750 | stream); |
| 751 | return static_cast<Error>(err); |
Chia-I Wu | 7f8d396 | 2016-09-28 21:04:23 +0800 | [diff] [blame] | 752 | } |
| 753 | |
Chia-I Wu | bb61a72 | 2016-10-24 15:40:20 +0800 | [diff] [blame] | 754 | Error HwcHal::setLayerSourceCrop(Display display, Layer layer, |
| 755 | const hwc_frect_t& crop) |
Chia-I Wu | 7f8d396 | 2016-09-28 21:04:23 +0800 | [diff] [blame] | 756 | { |
Chia-I Wu | bb61a72 | 2016-10-24 15:40:20 +0800 | [diff] [blame] | 757 | int32_t err = mDispatch.setLayerSourceCrop(mDevice, display, layer, crop); |
| 758 | return static_cast<Error>(err); |
Chia-I Wu | 7f8d396 | 2016-09-28 21:04:23 +0800 | [diff] [blame] | 759 | } |
| 760 | |
Chia-I Wu | bb61a72 | 2016-10-24 15:40:20 +0800 | [diff] [blame] | 761 | Error HwcHal::setLayerTransform(Display display, Layer layer, |
| 762 | int32_t transform) |
Chia-I Wu | 7f8d396 | 2016-09-28 21:04:23 +0800 | [diff] [blame] | 763 | { |
Chia-I Wu | bb61a72 | 2016-10-24 15:40:20 +0800 | [diff] [blame] | 764 | int32_t err = mDispatch.setLayerTransform(mDevice, display, layer, |
| 765 | transform); |
| 766 | return static_cast<Error>(err); |
Chia-I Wu | 7f8d396 | 2016-09-28 21:04:23 +0800 | [diff] [blame] | 767 | } |
| 768 | |
Chia-I Wu | bb61a72 | 2016-10-24 15:40:20 +0800 | [diff] [blame] | 769 | Error HwcHal::setLayerVisibleRegion(Display display, Layer layer, |
| 770 | const std::vector<hwc_rect_t>& visible) |
Chia-I Wu | 7f8d396 | 2016-09-28 21:04:23 +0800 | [diff] [blame] | 771 | { |
Chia-I Wu | bb61a72 | 2016-10-24 15:40:20 +0800 | [diff] [blame] | 772 | hwc_region_t region = { visible.size(), visible.data() }; |
| 773 | int32_t err = mDispatch.setLayerVisibleRegion(mDevice, display, layer, |
| 774 | region); |
| 775 | return static_cast<Error>(err); |
Chia-I Wu | 7f8d396 | 2016-09-28 21:04:23 +0800 | [diff] [blame] | 776 | } |
| 777 | |
Chia-I Wu | bb61a72 | 2016-10-24 15:40:20 +0800 | [diff] [blame] | 778 | Error HwcHal::setLayerZOrder(Display display, Layer layer, uint32_t z) |
Chia-I Wu | 7f8d396 | 2016-09-28 21:04:23 +0800 | [diff] [blame] | 779 | { |
Chia-I Wu | bb61a72 | 2016-10-24 15:40:20 +0800 | [diff] [blame] | 780 | int32_t err = mDispatch.setLayerZOrder(mDevice, display, layer, z); |
| 781 | return static_cast<Error>(err); |
Chia-I Wu | 7f8d396 | 2016-09-28 21:04:23 +0800 | [diff] [blame] | 782 | } |
| 783 | |
| 784 | IComposer* HIDL_FETCH_IComposer(const char*) |
| 785 | { |
Chia-I Wu | e176835 | 2016-12-19 12:56:54 +0800 | [diff] [blame] | 786 | const hw_module_t* module = nullptr; |
Chia-I Wu | 7f8d396 | 2016-09-28 21:04:23 +0800 | [diff] [blame] | 787 | int err = hw_get_module(HWC_HARDWARE_MODULE_ID, &module); |
| 788 | if (err) { |
Chia-I Wu | 16e8ed2 | 2017-10-19 09:49:03 -0700 | [diff] [blame] | 789 | ALOGI("falling back to FB HAL"); |
| 790 | err = hw_get_module(GRALLOC_HARDWARE_MODULE_ID, &module); |
| 791 | } |
| 792 | if (err) { |
| 793 | ALOGE("failed to get hwcomposer or fb module"); |
Chia-I Wu | 7f8d396 | 2016-09-28 21:04:23 +0800 | [diff] [blame] | 794 | return nullptr; |
| 795 | } |
| 796 | |
| 797 | return new HwcHal(module); |
| 798 | } |
| 799 | |
| 800 | } // namespace implementation |
| 801 | } // namespace V2_1 |
| 802 | } // namespace composer |
| 803 | } // namespace graphics |
| 804 | } // namespace hardware |
| 805 | } // namespace android |