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