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