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