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