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