Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 1 | /* |
Rajavenu Kyatham | 7338b9e | 2019-12-30 19:52:16 +0530 | [diff] [blame] | 2 | * Copyright (c) 2014-2020, The Linux Foundation. All rights reserved. |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 3 | * Not a Contribution. |
| 4 | * |
| 5 | * Copyright 2015 The Android Open Source Project |
| 6 | * |
| 7 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 8 | * you may not use this file except in compliance with the License. |
| 9 | * You may obtain a copy of the License at |
| 10 | * |
| 11 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 12 | * |
| 13 | * Unless required by applicable law or agreed to in writing, software |
| 14 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 16 | * See the License for the specific language governing permissions and |
| 17 | * limitations under the License. |
| 18 | */ |
| 19 | |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 20 | #include <QService.h> |
Naseer Ahmed | e7a7798 | 2018-06-04 10:56:04 -0400 | [diff] [blame] | 21 | #include <binder/Parcel.h> |
| 22 | #include <core/buffer_allocator.h> |
| 23 | #include <cutils/properties.h> |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 24 | #include <display_config.h> |
Naseer Ahmed | e7a7798 | 2018-06-04 10:56:04 -0400 | [diff] [blame] | 25 | #include <hardware_legacy/uevent.h> |
| 26 | #include <private/color_params.h> |
Ramakant Singh | fae5989 | 2017-09-13 10:40:22 +0530 | [diff] [blame] | 27 | #include <qd_utils.h> |
Naseer Ahmed | e7a7798 | 2018-06-04 10:56:04 -0400 | [diff] [blame] | 28 | #include <sync/sync.h> |
| 29 | #include <sys/prctl.h> |
| 30 | #include <sys/resource.h> |
| 31 | #include <utils/String16.h> |
| 32 | #include <utils/constants.h> |
| 33 | #include <utils/debug.h> |
Dileep Marchya | f3ce11f | 2018-04-30 23:35:46 +0530 | [diff] [blame] | 34 | #include <QService.h> |
Ramakant Singh | fae5989 | 2017-09-13 10:40:22 +0530 | [diff] [blame] | 35 | #include <utils/utils.h> |
Naseer Ahmed | 66d5b49 | 2017-02-23 20:30:17 -0500 | [diff] [blame] | 36 | #include <algorithm> |
Mahesh Aia | f3a1f99 | 2019-01-16 13:07:42 -0800 | [diff] [blame] | 37 | #include <utility> |
Dileep Marchya | 7290bd2 | 2016-06-09 11:37:20 +0530 | [diff] [blame] | 38 | #include <bitset> |
Mathew Joseph Karimpanal | 8abb6e0 | 2018-11-20 09:52:49 +0530 | [diff] [blame] | 39 | #include <iterator> |
Dileep Marchya | 550967a | 2017-05-24 17:03:30 +0530 | [diff] [blame] | 40 | #include <memory> |
Naseer Ahmed | e7a7798 | 2018-06-04 10:56:04 -0400 | [diff] [blame] | 41 | #include <string> |
| 42 | #include <thread> |
| 43 | #include <vector> |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 44 | |
| 45 | #include "hwc_buffer_allocator.h" |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 46 | #include "hwc_session.h" |
| 47 | #include "hwc_debugger.h" |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 48 | |
| 49 | #define __CLASS__ "HWCSession" |
| 50 | |
| 51 | #define HWC_UEVENT_SWITCH_HDMI "change@/devices/virtual/switch/hdmi" |
Prabhanjan Kandula | 34ffec0 | 2017-04-25 11:56:39 -0700 | [diff] [blame] | 52 | #define HWC_UEVENT_DRM_EXT_HOTPLUG "mdss_mdp/drm/card" |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 53 | |
Naseer Ahmed | 8584a0f | 2020-02-19 22:23:30 -0500 | [diff] [blame] | 54 | using HwcAttribute = composer_V2_4::IComposerClient::Attribute; |
| 55 | |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 56 | namespace sdm { |
Dileep Marchya | 550967a | 2017-05-24 17:03:30 +0530 | [diff] [blame] | 57 | |
| 58 | static HWCUEvent g_hwc_uevent_; |
Padmanabhan Komanduru | e74cf4f | 2019-04-25 17:38:43 -0700 | [diff] [blame] | 59 | Locker HWCSession::locker_[HWCCallbacks::kNumDisplays]; |
Mathew Joseph Karimpanal | b1c1586 | 2019-07-04 11:14:24 +0530 | [diff] [blame] | 60 | bool HWCSession::pending_power_mode_[HWCCallbacks::kNumDisplays]; |
Srinivas Pullakavi | 3c4337f | 2019-07-03 11:24:31 +0530 | [diff] [blame] | 61 | Locker HWCSession::power_state_[HWCCallbacks::kNumDisplays]; |
Pullakavi Srinivas | 1ae4acb | 2019-11-18 19:33:45 +0530 | [diff] [blame] | 62 | Locker HWCSession::hdr_locker_[HWCCallbacks::kNumDisplays]; |
Srinivas Pullakavi | 3c4337f | 2019-07-03 11:24:31 +0530 | [diff] [blame] | 63 | Locker HWCSession::display_config_locker_; |
Gopikrishnaiah Anandan | a340b70 | 2018-01-16 15:37:15 -0800 | [diff] [blame] | 64 | static const int kSolidFillDelay = 100 * 1000; |
Varun Arora | ad2719a | 2018-10-25 10:13:53 -0700 | [diff] [blame] | 65 | int HWCSession::null_display_mode_ = 0; |
Xu Yang | 45d0abf | 2019-07-05 11:34:06 +0800 | [diff] [blame] | 66 | static const uint32_t kBrightnessScaleMax = 100; |
| 67 | static const uint32_t kSvBlScaleMax = 65535; |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 68 | |
Sushil Chauhan | fea3e90 | 2018-07-31 15:34:48 -0700 | [diff] [blame] | 69 | // Map the known color modes to dataspace. |
Arun Kumar K.R | 5b82155 | 2018-12-07 08:00:15 +0530 | [diff] [blame] | 70 | int32_t GetDataspaceFromColorMode(ColorMode mode) { |
Sushil Chauhan | fea3e90 | 2018-07-31 15:34:48 -0700 | [diff] [blame] | 71 | switch (mode) { |
| 72 | case ColorMode::SRGB: |
| 73 | case ColorMode::NATIVE: |
| 74 | return HAL_DATASPACE_V0_SRGB; |
| 75 | case ColorMode::DCI_P3: |
| 76 | return HAL_DATASPACE_DCI_P3; |
| 77 | case ColorMode::DISPLAY_P3: |
| 78 | return HAL_DATASPACE_DISPLAY_P3; |
| 79 | case ColorMode::BT2100_PQ: |
| 80 | return HAL_DATASPACE_BT2020_PQ; |
| 81 | case ColorMode::BT2100_HLG: |
| 82 | return HAL_DATASPACE_BT2020_HLG; |
Gousemoodhin Nadaf | 0e56687 | 2019-05-13 16:14:54 +0530 | [diff] [blame] | 83 | case ColorMode::DISPLAY_BT2020: |
| 84 | return HAL_DATASPACE_DISPLAY_BT2020; |
Sushil Chauhan | fea3e90 | 2018-07-31 15:34:48 -0700 | [diff] [blame] | 85 | default: |
| 86 | return HAL_DATASPACE_UNKNOWN; |
| 87 | } |
| 88 | } |
| 89 | |
Ramkumar Radhakrishnan | 048dcc4 | 2017-06-09 16:20:56 -0700 | [diff] [blame] | 90 | void HWCUEvent::UEventThread(HWCUEvent *hwc_uevent) { |
Dileep Marchya | 550967a | 2017-05-24 17:03:30 +0530 | [diff] [blame] | 91 | const char *uevent_thread_name = "HWC_UeventThread"; |
| 92 | |
| 93 | prctl(PR_SET_NAME, uevent_thread_name, 0, 0, 0); |
| 94 | setpriority(PRIO_PROCESS, 0, HAL_PRIORITY_URGENT_DISPLAY); |
| 95 | |
Ramkumar Radhakrishnan | 048dcc4 | 2017-06-09 16:20:56 -0700 | [diff] [blame] | 96 | int status = uevent_init(); |
| 97 | if (!status) { |
| 98 | std::unique_lock<std::mutex> caller_lock(hwc_uevent->mutex_); |
| 99 | hwc_uevent->caller_cv_.notify_one(); |
| 100 | DLOGE("Failed to init uevent with err %d", status); |
| 101 | return; |
| 102 | } |
| 103 | |
| 104 | { |
| 105 | // Signal caller thread that worker thread is ready to listen to events. |
| 106 | std::unique_lock<std::mutex> caller_lock(hwc_uevent->mutex_); |
| 107 | hwc_uevent->init_done_ = true; |
| 108 | hwc_uevent->caller_cv_.notify_one(); |
Dileep Marchya | 550967a | 2017-05-24 17:03:30 +0530 | [diff] [blame] | 109 | } |
| 110 | |
| 111 | while (1) { |
| 112 | char uevent_data[PAGE_SIZE] = {}; |
| 113 | |
Dileep Marchya | f3ce11f | 2018-04-30 23:35:46 +0530 | [diff] [blame] | 114 | // keep last 2 zeros to ensure double 0 termination |
Dileep Marchya | 550967a | 2017-05-24 17:03:30 +0530 | [diff] [blame] | 115 | int length = uevent_next_event(uevent_data, INT32(sizeof(uevent_data)) - 2); |
| 116 | |
| 117 | // scope of lock to this block only, so that caller is free to set event handler to nullptr; |
| 118 | { |
Ramkumar Radhakrishnan | 048dcc4 | 2017-06-09 16:20:56 -0700 | [diff] [blame] | 119 | std::lock_guard<std::mutex> guard(hwc_uevent->mutex_); |
| 120 | if (hwc_uevent->uevent_listener_) { |
| 121 | hwc_uevent->uevent_listener_->UEventHandler(uevent_data, length); |
Dileep Marchya | 550967a | 2017-05-24 17:03:30 +0530 | [diff] [blame] | 122 | } else { |
| 123 | DLOGW("UEvent dropped. No uevent listener."); |
| 124 | } |
| 125 | } |
| 126 | } |
Dileep Marchya | 550967a | 2017-05-24 17:03:30 +0530 | [diff] [blame] | 127 | } |
| 128 | |
| 129 | HWCUEvent::HWCUEvent() { |
Ramkumar Radhakrishnan | 048dcc4 | 2017-06-09 16:20:56 -0700 | [diff] [blame] | 130 | std::unique_lock<std::mutex> caller_lock(mutex_); |
Dileep Marchya | 550967a | 2017-05-24 17:03:30 +0530 | [diff] [blame] | 131 | std::thread thread(HWCUEvent::UEventThread, this); |
| 132 | thread.detach(); |
Ramkumar Radhakrishnan | 048dcc4 | 2017-06-09 16:20:56 -0700 | [diff] [blame] | 133 | caller_cv_.wait(caller_lock); |
Dileep Marchya | 550967a | 2017-05-24 17:03:30 +0530 | [diff] [blame] | 134 | } |
| 135 | |
Ramkumar Radhakrishnan | 048dcc4 | 2017-06-09 16:20:56 -0700 | [diff] [blame] | 136 | void HWCUEvent::Register(HWCUEventListener *uevent_listener) { |
| 137 | DLOGI("Set uevent listener = %p", uevent_listener); |
Dileep Marchya | 550967a | 2017-05-24 17:03:30 +0530 | [diff] [blame] | 138 | |
| 139 | std::lock_guard<std::mutex> obj(mutex_); |
Ramkumar Radhakrishnan | 048dcc4 | 2017-06-09 16:20:56 -0700 | [diff] [blame] | 140 | uevent_listener_ = uevent_listener; |
Dileep Marchya | 550967a | 2017-05-24 17:03:30 +0530 | [diff] [blame] | 141 | } |
| 142 | |
Dileep Marchya | cb2a3a9 | 2019-06-21 17:30:50 +0530 | [diff] [blame] | 143 | HWCSession::HWCSession() : cwb_(this) {} |
Rajavenu Kyatham | 42d11cb | 2019-04-16 13:03:29 +0530 | [diff] [blame] | 144 | |
| 145 | HWCSession *HWCSession::GetInstance() { |
| 146 | // executed only once for the very first call. |
| 147 | // GetInstance called multiple times from Composer and ComposerClient |
| 148 | static HWCSession *hwc_session = new HWCSession(); |
| 149 | return hwc_session; |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 150 | } |
| 151 | |
| 152 | int HWCSession::Init() { |
Saurabh Shah | c5c687a | 2017-08-24 16:30:14 -0700 | [diff] [blame] | 153 | SCOPE_LOCK(locker_[HWC_DISPLAY_PRIMARY]); |
| 154 | |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 155 | int status = -EINVAL; |
| 156 | const char *qservice_name = "display.qservice"; |
| 157 | |
Ramkumar Radhakrishnan | 048dcc4 | 2017-06-09 16:20:56 -0700 | [diff] [blame] | 158 | if (!g_hwc_uevent_.InitDone()) { |
| 159 | return status; |
| 160 | } |
| 161 | |
Dileep Marchya | f3ce11f | 2018-04-30 23:35:46 +0530 | [diff] [blame] | 162 | |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 163 | // Start QService and connect to it. |
| 164 | qService::QService::init(); |
| 165 | android::sp<qService::IQService> iqservice = android::interface_cast<qService::IQService>( |
| 166 | android::defaultServiceManager()->getService(android::String16(qservice_name))); |
| 167 | |
| 168 | if (iqservice.get()) { |
| 169 | iqservice->connect(android::sp<qClient::IQClient>(this)); |
| 170 | qservice_ = reinterpret_cast<qService::QService *>(iqservice.get()); |
| 171 | } else { |
Dileep Marchya | 4cb86b4 | 2018-05-01 19:34:51 +0530 | [diff] [blame] | 172 | DLOGE("Failed to acquire %s", qservice_name); |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 173 | return -EINVAL; |
| 174 | } |
| 175 | |
Uday Kiran Pichika | 5e656b2 | 2018-05-15 18:48:24 +0530 | [diff] [blame] | 176 | HWCDebugHandler::Get()->GetProperty(ENABLE_NULL_DISPLAY_PROP, &null_display_mode_); |
Mathew Joseph Karimpanal | abe3b3d | 2018-11-27 17:25:40 +0530 | [diff] [blame] | 177 | HWCDebugHandler::Get()->GetProperty(DISABLE_HOTPLUG_BWCHECK, &disable_hotplug_bwcheck_); |
Pullakavi Srinivas | 2fbff8d | 2019-04-22 18:32:52 -0700 | [diff] [blame] | 178 | HWCDebugHandler::Get()->GetProperty(DISABLE_MASK_LAYER_HINT, &disable_mask_layer_hint_); |
Ramkumar Radhakrishnan | ddbf83c | 2017-06-28 20:01:59 -0700 | [diff] [blame] | 179 | |
Pullakavi Srinivas | f2a3185 | 2019-04-23 14:32:08 -0700 | [diff] [blame] | 180 | if (!null_display_mode_) { |
Varun Arora | 429bf40 | 2018-10-01 13:32:33 -0700 | [diff] [blame] | 181 | g_hwc_uevent_.Register(this); |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 182 | } |
| 183 | |
Mathew Joseph Karimpanal | b1c1586 | 2019-07-04 11:14:24 +0530 | [diff] [blame] | 184 | int value = 1; // Default value when property is not present. |
Srinivas Pullakavi | 3c4337f | 2019-07-03 11:24:31 +0530 | [diff] [blame] | 185 | Debug::Get()->GetProperty(ENABLE_ASYNC_POWERMODE, &value); |
| 186 | async_powermode_ = (value == 1); |
| 187 | DLOGI("builtin_powermode_override: %d", async_powermode_); |
| 188 | |
Padmanabhan Komanduru | f5b7f99 | 2019-07-08 13:33:44 +0530 | [diff] [blame] | 189 | value = 0; |
| 190 | Debug::Get()->GetProperty(ENABLE_ASYNC_VDS_CREATION, &value); |
| 191 | async_vds_creation_ = (value == 1); |
| 192 | DLOGI("async_vds_creation: %d", async_vds_creation_); |
| 193 | |
Pullakavi Srinivas | f2a3185 | 2019-04-23 14:32:08 -0700 | [diff] [blame] | 194 | InitSupportedDisplaySlots(); |
Dileep Marchya | f3ce11f | 2018-04-30 23:35:46 +0530 | [diff] [blame] | 195 | // Create primary display here. Remaining builtin displays will be created after client has set |
| 196 | // display indexes which may happen sometime before callback is registered. |
| 197 | status = CreatePrimaryDisplay(); |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 198 | if (status) { |
Dileep Marchya | f3ce11f | 2018-04-30 23:35:46 +0530 | [diff] [blame] | 199 | Deinit(); |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 200 | return status; |
| 201 | } |
| 202 | |
Prabhanjan Kandula | 63a613f | 2017-09-14 19:29:46 -0700 | [diff] [blame] | 203 | is_composer_up_ = true; |
Ramakant Singh | 2b8f5ec | 2019-09-20 09:43:29 +0530 | [diff] [blame] | 204 | StartServices(); |
Dileep Marchya | d16da3e | 2017-05-20 01:56:21 +0530 | [diff] [blame] | 205 | |
Pullakavi Srinivas | db2b84a | 2019-11-21 14:47:35 +0530 | [diff] [blame] | 206 | PostInit(); |
| 207 | |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 208 | return 0; |
| 209 | } |
| 210 | |
Pullakavi Srinivas | db2b84a | 2019-11-21 14:47:35 +0530 | [diff] [blame] | 211 | void HWCSession::PostInit() { |
| 212 | if (null_display_mode_) { |
| 213 | return; |
| 214 | } |
| 215 | |
| 216 | // Start services which need IDisplayConfig to be up. |
| 217 | // This avoids deadlock between composer and its clients. |
| 218 | auto hwc_display = hwc_display_[HWC_DISPLAY_PRIMARY]; |
| 219 | hwc_display->PostInit(); |
| 220 | } |
| 221 | |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 222 | int HWCSession::Deinit() { |
Dileep Marchya | f3ce11f | 2018-04-30 23:35:46 +0530 | [diff] [blame] | 223 | // Destroy all connected displays |
| 224 | DestroyDisplay(&map_info_primary_); |
Saurabh Shah | c5c687a | 2017-08-24 16:30:14 -0700 | [diff] [blame] | 225 | |
Dileep Marchya | f3ce11f | 2018-04-30 23:35:46 +0530 | [diff] [blame] | 226 | for (auto &map_info : map_info_builtin_) { |
| 227 | DestroyDisplay(&map_info); |
Dileep Marchya | d16da3e | 2017-05-20 01:56:21 +0530 | [diff] [blame] | 228 | } |
Dileep Marchya | f3ce11f | 2018-04-30 23:35:46 +0530 | [diff] [blame] | 229 | |
| 230 | for (auto &map_info : map_info_pluggable_) { |
| 231 | DestroyDisplay(&map_info); |
| 232 | } |
| 233 | |
| 234 | for (auto &map_info : map_info_virtual_) { |
| 235 | DestroyDisplay(&map_info); |
| 236 | } |
Dileep Marchya | d16da3e | 2017-05-20 01:56:21 +0530 | [diff] [blame] | 237 | |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 238 | if (color_mgr_) { |
| 239 | color_mgr_->DestroyColorManager(); |
| 240 | } |
Dileep Marchya | d16da3e | 2017-05-20 01:56:21 +0530 | [diff] [blame] | 241 | |
Varun Arora | 465c1f7 | 2018-02-08 16:18:50 -0800 | [diff] [blame] | 242 | if (!null_display_mode_) { |
| 243 | g_hwc_uevent_.Register(nullptr); |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 244 | |
Varun Arora | 465c1f7 | 2018-02-08 16:18:50 -0800 | [diff] [blame] | 245 | DisplayError error = CoreInterface::DestroyCore(); |
| 246 | if (error != kErrorNone) { |
Dileep Marchya | 4cb86b4 | 2018-05-01 19:34:51 +0530 | [diff] [blame] | 247 | DLOGE("Display core de-initialization failed. Error = %d", error); |
Varun Arora | 465c1f7 | 2018-02-08 16:18:50 -0800 | [diff] [blame] | 248 | } |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 249 | } |
| 250 | |
| 251 | return 0; |
| 252 | } |
| 253 | |
Pullakavi Srinivas | f2a3185 | 2019-04-23 14:32:08 -0700 | [diff] [blame] | 254 | void HWCSession::InitSupportedDisplaySlots() { |
Dileep Marchya | f3ce11f | 2018-04-30 23:35:46 +0530 | [diff] [blame] | 255 | // Default slots: |
Pullakavi Srinivas | f2a3185 | 2019-04-23 14:32:08 -0700 | [diff] [blame] | 256 | // Primary = 0, External = 1 |
| 257 | // Additional external displays 2,3,...max_pluggable_count. |
| 258 | // Additional builtin displays max_pluggable_count + 1, max_pluggable_count + 2,... |
| 259 | // Last slots for virtual displays. |
| 260 | // Virtual display id is only for SF <--> HWC communication. |
| 261 | // It need not align with hwccomposer_defs |
Dileep Marchya | f3ce11f | 2018-04-30 23:35:46 +0530 | [diff] [blame] | 262 | |
| 263 | map_info_primary_.client_id = qdutils::DISPLAY_PRIMARY; |
| 264 | |
Pullakavi Srinivas | f2a3185 | 2019-04-23 14:32:08 -0700 | [diff] [blame] | 265 | if (null_display_mode_) { |
Varun Arora | d7d8c91 | 2019-08-16 11:45:19 -0700 | [diff] [blame] | 266 | InitSupportedNullDisplaySlots(); |
Pullakavi Srinivas | f2a3185 | 2019-04-23 14:32:08 -0700 | [diff] [blame] | 267 | return; |
Dileep Marchya | f3ce11f | 2018-04-30 23:35:46 +0530 | [diff] [blame] | 268 | } |
| 269 | |
Dileep Marchya | 1b37f8c | 2020-01-20 19:14:12 +0530 | [diff] [blame] | 270 | DisplayError error = CoreInterface::CreateCore(&buffer_allocator_, nullptr, |
Pullakavi Srinivas | f2a3185 | 2019-04-23 14:32:08 -0700 | [diff] [blame] | 271 | &socket_handler_, &core_intf_); |
| 272 | if (error != kErrorNone) { |
| 273 | DLOGE("Failed to create CoreInterface"); |
| 274 | return; |
Dileep Marchya | f3ce11f | 2018-04-30 23:35:46 +0530 | [diff] [blame] | 275 | } |
| 276 | |
Pullakavi Srinivas | f2a3185 | 2019-04-23 14:32:08 -0700 | [diff] [blame] | 277 | HWDisplayInterfaceInfo hw_disp_info = {}; |
| 278 | error = core_intf_->GetFirstDisplayInterfaceType(&hw_disp_info); |
| 279 | if (error != kErrorNone) { |
| 280 | CoreInterface::DestroyCore(); |
| 281 | DLOGE("Primary display type not recognized. Error = %d", error); |
| 282 | return; |
| 283 | } |
| 284 | |
| 285 | int max_builtin = 0; |
| 286 | int max_pluggable = 0; |
| 287 | int max_virtual = 0; |
| 288 | |
| 289 | error = core_intf_->GetMaxDisplaysSupported(kBuiltIn, &max_builtin); |
| 290 | if (error != kErrorNone) { |
| 291 | CoreInterface::DestroyCore(); |
| 292 | DLOGE("Could not find maximum built-in displays supported. Error = %d", error); |
| 293 | return; |
| 294 | } |
| 295 | |
| 296 | error = core_intf_->GetMaxDisplaysSupported(kPluggable, &max_pluggable); |
| 297 | if (error != kErrorNone) { |
| 298 | CoreInterface::DestroyCore(); |
| 299 | DLOGE("Could not find maximum pluggable displays supported. Error = %d", error); |
| 300 | return; |
| 301 | } |
| 302 | |
| 303 | error = core_intf_->GetMaxDisplaysSupported(kVirtual, &max_virtual); |
| 304 | if (error != kErrorNone) { |
| 305 | CoreInterface::DestroyCore(); |
| 306 | DLOGE("Could not find maximum virtual displays supported. Error = %d", error); |
| 307 | return; |
| 308 | } |
| 309 | |
Pullakavi Srinivas | 17495f1 | 2019-09-16 20:25:20 +0530 | [diff] [blame] | 310 | if (max_virtual == 0) { |
| 311 | // Check if WB using GPU is supported. |
| 312 | max_virtual += virtual_display_factory_.IsGPUColorConvertSupported() ? 1 : 0; |
| 313 | } |
| 314 | |
Pullakavi Srinivas | f2a3185 | 2019-04-23 14:32:08 -0700 | [diff] [blame] | 315 | if (kPluggable == hw_disp_info.type) { |
| 316 | // If primary is a pluggable display, we have already used one pluggable display interface. |
| 317 | max_pluggable--; |
| 318 | } else { |
| 319 | max_builtin--; |
| 320 | } |
| 321 | |
| 322 | // Init slots in accordance to h/w capability. |
| 323 | uint32_t disp_count = UINT32(std::min(max_pluggable, HWCCallbacks::kNumPluggable)); |
| 324 | hwc2_display_t base_id = qdutils::DISPLAY_EXTERNAL; |
| 325 | map_info_pluggable_.resize(disp_count); |
| 326 | for (auto &map_info : map_info_pluggable_) { |
| 327 | map_info.client_id = base_id++; |
| 328 | } |
| 329 | |
| 330 | disp_count = UINT32(std::min(max_builtin, HWCCallbacks::kNumBuiltIn)); |
| 331 | map_info_builtin_.resize(disp_count); |
| 332 | for (auto &map_info : map_info_builtin_) { |
| 333 | map_info.client_id = base_id++; |
| 334 | } |
| 335 | |
| 336 | disp_count = UINT32(std::min(max_virtual, HWCCallbacks::kNumVirtual)); |
| 337 | map_info_virtual_.resize(disp_count); |
| 338 | for (auto &map_info : map_info_virtual_) { |
| 339 | map_info.client_id = base_id++; |
Dileep Marchya | f3ce11f | 2018-04-30 23:35:46 +0530 | [diff] [blame] | 340 | } |
Archit Srivastava | fe060f7 | 2019-05-27 15:51:58 +0530 | [diff] [blame] | 341 | |
| 342 | // resize HDR supported map to total number of displays. |
| 343 | is_hdr_display_.resize(UINT32(base_id)); |
Srinivas Pullakavi | 3c4337f | 2019-07-03 11:24:31 +0530 | [diff] [blame] | 344 | |
| 345 | if (!async_powermode_) { |
| 346 | return; |
| 347 | } |
| 348 | |
| 349 | int start_index = HWCCallbacks::kNumRealDisplays; |
| 350 | std::vector<DisplayMapInfo> map_info = {map_info_primary_}; |
| 351 | std::copy(map_info_builtin_.begin(), map_info_builtin_.end(), std::back_inserter(map_info)); |
| 352 | std::copy(map_info_pluggable_.begin(), map_info_pluggable_.end(), std::back_inserter(map_info)); |
| 353 | for (auto &map : map_info) { |
| 354 | DLOGI("Display Pairs: map.client_id: %d, start_index: %d", map.client_id, start_index); |
| 355 | map_hwc_display_.insert(std::make_pair(map.client_id, start_index++)); |
| 356 | } |
Dileep Marchya | f3ce11f | 2018-04-30 23:35:46 +0530 | [diff] [blame] | 357 | } |
| 358 | |
Varun Arora | d7d8c91 | 2019-08-16 11:45:19 -0700 | [diff] [blame] | 359 | void HWCSession::InitSupportedNullDisplaySlots() { |
| 360 | if (!null_display_mode_) { |
| 361 | DLOGE("Should only be invoked during null display"); |
| 362 | return; |
| 363 | } |
| 364 | |
| 365 | map_info_primary_.client_id = 0; |
| 366 | // Resize HDR supported map to total number of displays |
| 367 | is_hdr_display_.resize(1); |
| 368 | |
| 369 | if (!async_powermode_) { |
| 370 | return; |
| 371 | } |
| 372 | |
| 373 | DLOGI("Display Pairs: map.client_id: %d, start_index: %d", map_info_primary_.client_id, |
| 374 | HWCCallbacks::kNumRealDisplays); |
| 375 | map_hwc_display_.insert(std::make_pair(map_info_primary_.client_id, |
| 376 | HWCCallbacks::kNumRealDisplays)); |
| 377 | } |
| 378 | |
Dileep Marchya | f3ce11f | 2018-04-30 23:35:46 +0530 | [diff] [blame] | 379 | int HWCSession::GetDisplayIndex(int dpy) { |
| 380 | DisplayMapInfo *map_info = nullptr; |
| 381 | switch (dpy) { |
| 382 | case qdutils::DISPLAY_PRIMARY: |
| 383 | map_info = &map_info_primary_; |
| 384 | break; |
| 385 | case qdutils::DISPLAY_EXTERNAL: |
| 386 | map_info = map_info_pluggable_.size() ? &map_info_pluggable_[0] : nullptr; |
| 387 | break; |
Mathew Joseph Karimpanal | 71ac8a7 | 2018-09-25 22:27:22 +0530 | [diff] [blame] | 388 | case qdutils::DISPLAY_EXTERNAL_2: |
| 389 | map_info = (map_info_pluggable_.size() > 1) ? &map_info_pluggable_[1] : nullptr; |
| 390 | break; |
Dileep Marchya | f3ce11f | 2018-04-30 23:35:46 +0530 | [diff] [blame] | 391 | case qdutils::DISPLAY_VIRTUAL: |
| 392 | map_info = map_info_virtual_.size() ? &map_info_virtual_[0] : nullptr; |
| 393 | break; |
Dileep Marchya | 35e2753 | 2018-06-29 10:50:16 +0530 | [diff] [blame] | 394 | case qdutils::DISPLAY_BUILTIN_2: |
| 395 | map_info = map_info_builtin_.size() ? &map_info_builtin_[0] : nullptr; |
| 396 | break; |
Mathew Joseph Karimpanal | 71ac8a7 | 2018-09-25 22:27:22 +0530 | [diff] [blame] | 397 | default: |
| 398 | DLOGW("Unknown display %d.", dpy); |
| 399 | break; |
Dileep Marchya | f3ce11f | 2018-04-30 23:35:46 +0530 | [diff] [blame] | 400 | } |
| 401 | |
| 402 | if (!map_info) { |
Mathew Joseph Karimpanal | 71ac8a7 | 2018-09-25 22:27:22 +0530 | [diff] [blame] | 403 | DLOGE("Display index not found for display %d.", dpy); |
Dileep Marchya | f3ce11f | 2018-04-30 23:35:46 +0530 | [diff] [blame] | 404 | return -1; |
| 405 | } |
| 406 | |
| 407 | return INT(map_info->client_id); |
| 408 | } |
| 409 | |
Rajavenu Kyatham | 42d11cb | 2019-04-16 13:03:29 +0530 | [diff] [blame] | 410 | void HWCSession::GetCapabilities(uint32_t *outCount, int32_t *outCapabilities) { |
Ramkumar Radhakrishnan | 82af7e9 | 2017-09-21 14:29:42 -0700 | [diff] [blame] | 411 | if (!outCount) { |
| 412 | return; |
| 413 | } |
| 414 | |
Sushil Chauhan | 409e844 | 2017-06-12 17:43:25 -0700 | [diff] [blame] | 415 | int value = 0; |
| 416 | bool disable_skip_validate = false; |
Uday Kiran Pichika | 5e656b2 | 2018-05-15 18:48:24 +0530 | [diff] [blame] | 417 | if (Debug::Get()->GetProperty(DISABLE_SKIP_VALIDATE_PROP, &value) == kErrorNone) { |
Sushil Chauhan | 409e844 | 2017-06-12 17:43:25 -0700 | [diff] [blame] | 418 | disable_skip_validate = (value == 1); |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 419 | } |
Sushil Chauhan | 409e844 | 2017-06-12 17:43:25 -0700 | [diff] [blame] | 420 | uint32_t count = 1 + (disable_skip_validate ? 0 : 1); |
| 421 | |
| 422 | if (outCapabilities != nullptr && (*outCount >= count)) { |
| 423 | outCapabilities[0] = HWC2_CAPABILITY_SKIP_CLIENT_COLOR_TRANSFORM; |
| 424 | if (!disable_skip_validate) { |
| 425 | outCapabilities[1] = HWC2_CAPABILITY_SKIP_VALIDATE; |
| 426 | } |
| 427 | } |
| 428 | *outCount = count; |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 429 | } |
| 430 | |
| 431 | template <typename PFN, typename T> |
| 432 | static hwc2_function_pointer_t AsFP(T function) { |
| 433 | static_assert(std::is_same<PFN, T>::value, "Incompatible function pointer"); |
| 434 | return reinterpret_cast<hwc2_function_pointer_t>(function); |
| 435 | } |
| 436 | |
| 437 | // HWC2 functions returned in GetFunction |
| 438 | // Defined in the same order as in the HWC2 header |
| 439 | |
Rajavenu Kyatham | 42d11cb | 2019-04-16 13:03:29 +0530 | [diff] [blame] | 440 | int32_t HWCSession::AcceptDisplayChanges(hwc2_display_t display) { |
| 441 | return CallDisplayFunction(display, &HWCDisplay::AcceptDisplayChanges); |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 442 | } |
| 443 | |
Rajavenu Kyatham | 42d11cb | 2019-04-16 13:03:29 +0530 | [diff] [blame] | 444 | int32_t HWCSession::CreateLayer(hwc2_display_t display, |
Naseer Ahmed | addcabf | 2016-05-04 15:49:29 -0400 | [diff] [blame] | 445 | hwc2_layer_t *out_layer_id) { |
Ramkumar Radhakrishnan | 82af7e9 | 2017-09-21 14:29:42 -0700 | [diff] [blame] | 446 | if (!out_layer_id) { |
| 447 | return HWC2_ERROR_BAD_PARAMETER; |
| 448 | } |
Saurabh Shah | 04f932b | 2017-10-12 18:47:45 -0700 | [diff] [blame] | 449 | |
Rajavenu Kyatham | 42d11cb | 2019-04-16 13:03:29 +0530 | [diff] [blame] | 450 | return CallDisplayFunction(display, &HWCDisplay::CreateLayer, out_layer_id); |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 451 | } |
| 452 | |
Rajavenu Kyatham | 42d11cb | 2019-04-16 13:03:29 +0530 | [diff] [blame] | 453 | int32_t HWCSession::CreateVirtualDisplay(uint32_t width, uint32_t height, int32_t *format, |
| 454 | hwc2_display_t *out_display_id) { |
Naseer Ahmed | 42fc8d1 | 2016-05-11 18:33:57 -0400 | [diff] [blame] | 455 | // TODO(user): Handle concurrency with HDMI |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 456 | |
Ramkumar Radhakrishnan | 82af7e9 | 2017-09-21 14:29:42 -0700 | [diff] [blame] | 457 | if (!out_display_id || !width || !height || !format) { |
| 458 | return HWC2_ERROR_BAD_PARAMETER; |
| 459 | } |
| 460 | |
Varun Arora | d7d8c91 | 2019-08-16 11:45:19 -0700 | [diff] [blame] | 461 | if (null_display_mode_) { |
| 462 | return 0; |
| 463 | } |
| 464 | |
Padmanabhan Komanduru | f5b7f99 | 2019-07-08 13:33:44 +0530 | [diff] [blame] | 465 | if (async_vds_creation_ && virtual_id_ != HWCCallbacks::kNumDisplays) { |
| 466 | *out_display_id = virtual_id_; |
| 467 | return HWC2_ERROR_NONE; |
| 468 | } |
| 469 | |
Rajavenu Kyatham | 42d11cb | 2019-04-16 13:03:29 +0530 | [diff] [blame] | 470 | auto status = CreateVirtualDisplayObj(width, height, format, out_display_id); |
Naseer Ahmed | 2363394 | 2016-07-13 19:46:56 -0400 | [diff] [blame] | 471 | if (status == HWC2::Error::None) { |
Dileep Marchya | f3ce11f | 2018-04-30 23:35:46 +0530 | [diff] [blame] | 472 | DLOGI("Created virtual display id:% " PRIu64 ", res: %dx%d", *out_display_id, width, height); |
Naseer Ahmed | 2363394 | 2016-07-13 19:46:56 -0400 | [diff] [blame] | 473 | } else { |
| 474 | DLOGE("Failed to create virtual display: %s", to_string(status).c_str()); |
| 475 | } |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 476 | return INT32(status); |
| 477 | } |
| 478 | |
Rajavenu Kyatham | 42d11cb | 2019-04-16 13:03:29 +0530 | [diff] [blame] | 479 | int32_t HWCSession::DestroyLayer(hwc2_display_t display, hwc2_layer_t layer) { |
| 480 | return CallDisplayFunction(display, &HWCDisplay::DestroyLayer, layer); |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 481 | } |
| 482 | |
Rajavenu Kyatham | 42d11cb | 2019-04-16 13:03:29 +0530 | [diff] [blame] | 483 | int32_t HWCSession::DestroyVirtualDisplay(hwc2_display_t display) { |
| 484 | if (display >= HWCCallbacks::kNumDisplays) { |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 485 | return HWC2_ERROR_BAD_DISPLAY; |
| 486 | } |
| 487 | |
Rajavenu Kyatham | 42d11cb | 2019-04-16 13:03:29 +0530 | [diff] [blame] | 488 | hwc2_display_t active_builtin_disp_id = GetActiveBuiltinDisplay(); |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 489 | |
Padmanabhan Komanduru | e74cf4f | 2019-04-25 17:38:43 -0700 | [diff] [blame] | 490 | if (active_builtin_disp_id < HWCCallbacks::kNumDisplays) { |
Ramkumar Radhakrishnan | 44c6436 | 2018-12-12 13:03:59 -0800 | [diff] [blame] | 491 | Locker::ScopeLock lock_a(locker_[active_builtin_disp_id]); |
Mathew Joseph Karimpanal | 71ac8a7 | 2018-09-25 22:27:22 +0530 | [diff] [blame] | 492 | std::bitset<kSecureMax> secure_sessions = 0; |
Rajavenu Kyatham | 42d11cb | 2019-04-16 13:03:29 +0530 | [diff] [blame] | 493 | hwc_display_[active_builtin_disp_id]->GetActiveSecureSession(&secure_sessions); |
Ramkumar Radhakrishnan | a38b760 | 2018-03-15 14:49:52 -0700 | [diff] [blame] | 494 | if (secure_sessions.any()) { |
Ramkumar Radhakrishnan | 44c6436 | 2018-12-12 13:03:59 -0800 | [diff] [blame] | 495 | DLOGW("Secure session is active, defer destruction of virtual display id:%" PRIu64, display); |
Rajavenu Kyatham | 42d11cb | 2019-04-16 13:03:29 +0530 | [diff] [blame] | 496 | destroy_virtual_disp_pending_ = true; |
Ramkumar Radhakrishnan | a38b760 | 2018-03-15 14:49:52 -0700 | [diff] [blame] | 497 | return HWC2_ERROR_NONE; |
| 498 | } |
| 499 | } |
| 500 | |
Rajavenu Kyatham | 42d11cb | 2019-04-16 13:03:29 +0530 | [diff] [blame] | 501 | for (auto &map_info : map_info_virtual_) { |
Dileep Marchya | f3ce11f | 2018-04-30 23:35:46 +0530 | [diff] [blame] | 502 | if (map_info.client_id == display) { |
| 503 | DLOGI("Destroying virtual display id:%" PRIu64, display); |
Rajavenu Kyatham | 42d11cb | 2019-04-16 13:03:29 +0530 | [diff] [blame] | 504 | DestroyDisplay(&map_info); |
Dileep Marchya | f3ce11f | 2018-04-30 23:35:46 +0530 | [diff] [blame] | 505 | break; |
| 506 | } |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 507 | } |
Padmanabhan Komanduru | f5b7f99 | 2019-07-08 13:33:44 +0530 | [diff] [blame] | 508 | virtual_id_ = HWCCallbacks::kNumDisplays; |
Dileep Marchya | f3ce11f | 2018-04-30 23:35:46 +0530 | [diff] [blame] | 509 | |
| 510 | return HWC2_ERROR_NONE; |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 511 | } |
| 512 | |
Pullakavi Srinivas | a3c292c | 2019-12-01 13:27:50 +0530 | [diff] [blame] | 513 | int32_t HWCSession::GetVirtualDisplayId() { |
| 514 | HWDisplaysInfo hw_displays_info = {}; |
| 515 | core_intf_->GetDisplaysStatus(&hw_displays_info); |
| 516 | for (auto &iter : hw_displays_info) { |
| 517 | auto &info = iter.second; |
| 518 | if (info.display_type != kVirtual) { |
| 519 | continue; |
| 520 | } |
| 521 | |
| 522 | return info.display_id; |
| 523 | } |
| 524 | |
| 525 | return -1; |
| 526 | } |
| 527 | |
Rajavenu Kyatham | 42d11cb | 2019-04-16 13:03:29 +0530 | [diff] [blame] | 528 | void HWCSession::Dump(uint32_t *out_size, char *out_buffer) { |
| 529 | if (!out_size) { |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 530 | return; |
| 531 | } |
Saurabh Shah | 9c224a3 | 2017-11-09 12:17:44 -0800 | [diff] [blame] | 532 | |
Mathew Joseph Karimpanal | 50dfb99 | 2019-09-30 12:04:11 +0530 | [diff] [blame] | 533 | const size_t max_dump_size = 16384; // 16 kB |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 534 | |
| 535 | if (out_buffer == nullptr) { |
Naseer Ahmed | 66d5b49 | 2017-02-23 20:30:17 -0500 | [diff] [blame] | 536 | *out_size = max_dump_size; |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 537 | } else { |
Dileep Marchya | 5892812 | 2020-01-28 12:16:51 +0530 | [diff] [blame] | 538 | std::ostringstream os; |
Srinivas Pullakavi | 3c4337f | 2019-07-03 11:24:31 +0530 | [diff] [blame] | 539 | for (int id = 0; id < HWCCallbacks::kNumRealDisplays; id++) { |
Saurabh Shah | 04f932b | 2017-10-12 18:47:45 -0700 | [diff] [blame] | 540 | SCOPE_LOCK(locker_[id]); |
Rajavenu Kyatham | 42d11cb | 2019-04-16 13:03:29 +0530 | [diff] [blame] | 541 | if (hwc_display_[id]) { |
Dileep Marchya | 5892812 | 2020-01-28 12:16:51 +0530 | [diff] [blame] | 542 | hwc_display_[id]->Dump(&os); |
Naseer Ahmed | 0f5b51c | 2016-06-22 19:39:38 -0400 | [diff] [blame] | 543 | } |
| 544 | } |
Dileep Marchya | 5892812 | 2020-01-28 12:16:51 +0530 | [diff] [blame] | 545 | Fence::Dump(&os); |
| 546 | |
| 547 | std::string s = os.str(); |
Naseer Ahmed | 66d5b49 | 2017-02-23 20:30:17 -0500 | [diff] [blame] | 548 | auto copied = s.copy(out_buffer, std::min(s.size(), max_dump_size), 0); |
| 549 | *out_size = UINT32(copied); |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 550 | } |
| 551 | } |
| 552 | |
Rajavenu Kyatham | 42d11cb | 2019-04-16 13:03:29 +0530 | [diff] [blame] | 553 | uint32_t HWCSession::GetMaxVirtualDisplayCount() { |
Pullakavi Srinivas | a3c292c | 2019-12-01 13:27:50 +0530 | [diff] [blame] | 554 | return map_info_virtual_.size(); |
Varun Arora | ad2719a | 2018-10-25 10:13:53 -0700 | [diff] [blame] | 555 | } |
| 556 | |
Rajavenu Kyatham | 42d11cb | 2019-04-16 13:03:29 +0530 | [diff] [blame] | 557 | int32_t HWCSession::GetActiveConfig(hwc2_display_t display, hwc2_config_t *out_config) { |
| 558 | return CallDisplayFunction(display, &HWCDisplay::GetActiveConfig, out_config); |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 559 | } |
| 560 | |
Rajavenu Kyatham | 42d11cb | 2019-04-16 13:03:29 +0530 | [diff] [blame] | 561 | int32_t HWCSession::GetChangedCompositionTypes(hwc2_display_t display, uint32_t *out_num_elements, |
| 562 | hwc2_layer_t *out_layers, int32_t *out_types) { |
Ramkumar Radhakrishnan | 82af7e9 | 2017-09-21 14:29:42 -0700 | [diff] [blame] | 563 | // null_ptr check only for out_num_elements, as out_layers and out_types can be null. |
| 564 | if (!out_num_elements) { |
| 565 | return HWC2_ERROR_BAD_PARAMETER; |
| 566 | } |
Rajavenu Kyatham | 42d11cb | 2019-04-16 13:03:29 +0530 | [diff] [blame] | 567 | return CallDisplayFunction(display, &HWCDisplay::GetChangedCompositionTypes, out_num_elements, |
| 568 | out_layers, out_types); |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 569 | } |
| 570 | |
Rajavenu Kyatham | 42d11cb | 2019-04-16 13:03:29 +0530 | [diff] [blame] | 571 | int32_t HWCSession::GetClientTargetSupport(hwc2_display_t display, uint32_t width, uint32_t height, |
| 572 | int32_t format, int32_t dataspace) { |
| 573 | return CallDisplayFunction(display, &HWCDisplay::GetClientTargetSupport, width, height, format, |
| 574 | dataspace); |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 575 | } |
| 576 | |
Rajavenu Kyatham | 42d11cb | 2019-04-16 13:03:29 +0530 | [diff] [blame] | 577 | int32_t HWCSession::GetColorModes(hwc2_display_t display, uint32_t *out_num_modes, |
| 578 | int32_t /*ColorMode*/ *int_out_modes) { |
Naseer Ahmed | e7a7798 | 2018-06-04 10:56:04 -0400 | [diff] [blame] | 579 | auto out_modes = reinterpret_cast<ColorMode *>(int_out_modes); |
Arun Kumar K.R | 0e10fd2 | 2017-10-11 14:42:11 +0530 | [diff] [blame] | 580 | if (out_num_modes == nullptr) { |
| 581 | return HWC2_ERROR_BAD_PARAMETER; |
| 582 | } |
Rajavenu Kyatham | 42d11cb | 2019-04-16 13:03:29 +0530 | [diff] [blame] | 583 | return CallDisplayFunction(display, &HWCDisplay::GetColorModes, out_num_modes, out_modes); |
Arun Kumar K.R | 29cd658 | 2016-05-10 19:12:45 -0700 | [diff] [blame] | 584 | } |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 585 | |
Rajavenu Kyatham | 42d11cb | 2019-04-16 13:03:29 +0530 | [diff] [blame] | 586 | int32_t HWCSession::GetRenderIntents(hwc2_display_t display, int32_t /*ColorMode*/ int_mode, |
| 587 | uint32_t *out_num_intents, |
| 588 | int32_t /*RenderIntent*/ *int_out_intents) { |
Naseer Ahmed | e7a7798 | 2018-06-04 10:56:04 -0400 | [diff] [blame] | 589 | auto mode = static_cast<ColorMode>(int_mode); |
| 590 | auto out_intents = reinterpret_cast<RenderIntent *>(int_out_intents); |
| 591 | if (out_num_intents == nullptr) { |
| 592 | return HWC2_ERROR_BAD_PARAMETER; |
| 593 | } |
Gurpreet Singh Dhami | ec0fa51 | 2018-08-29 16:51:26 -0400 | [diff] [blame] | 594 | |
Gousemoodhin Nadaf | 0e56687 | 2019-05-13 16:14:54 +0530 | [diff] [blame] | 595 | if (mode < ColorMode::NATIVE || mode > ColorMode::DISPLAY_BT2020) { |
Gurpreet Singh Dhami | ec0fa51 | 2018-08-29 16:51:26 -0400 | [diff] [blame] | 596 | DLOGE("Invalid ColorMode: %d", mode); |
| 597 | return HWC2_ERROR_BAD_PARAMETER; |
| 598 | } |
Rajavenu Kyatham | 42d11cb | 2019-04-16 13:03:29 +0530 | [diff] [blame] | 599 | return CallDisplayFunction(display, &HWCDisplay::GetRenderIntents, mode, out_num_intents, |
| 600 | out_intents); |
Naseer Ahmed | e7a7798 | 2018-06-04 10:56:04 -0400 | [diff] [blame] | 601 | } |
| 602 | |
Rajavenu Kyatham | 42d11cb | 2019-04-16 13:03:29 +0530 | [diff] [blame] | 603 | int32_t HWCSession::GetDataspaceSaturationMatrix(int32_t /*Dataspace*/ int_dataspace, |
| 604 | float *out_matrix) { |
Naseer Ahmed | e7a7798 | 2018-06-04 10:56:04 -0400 | [diff] [blame] | 605 | auto dataspace = static_cast<Dataspace>(int_dataspace); |
Rajavenu Kyatham | 42d11cb | 2019-04-16 13:03:29 +0530 | [diff] [blame] | 606 | if (out_matrix == nullptr || dataspace != Dataspace::SRGB_LINEAR) { |
Naseer Ahmed | e7a7798 | 2018-06-04 10:56:04 -0400 | [diff] [blame] | 607 | return HWC2_ERROR_BAD_PARAMETER; |
| 608 | } |
| 609 | // We only have the matrix for sRGB |
| 610 | float saturation_matrix[kDataspaceSaturationMatrixCount] = { 1.0, 0.0, 0.0, 0.0, \ |
| 611 | 0.0, 1.0, 0.0, 0.0, \ |
| 612 | 0.0, 0.0, 1.0, 0.0, \ |
| 613 | 0.0, 0.0, 0.0, 1.0 }; |
| 614 | |
Naseer Ahmed | e7a7798 | 2018-06-04 10:56:04 -0400 | [diff] [blame] | 615 | for (int32_t i = 0; i < kDataspaceSaturationMatrixCount; i += 4) { |
| 616 | DLOGD("%f %f %f %f", saturation_matrix[i], saturation_matrix[i + 1], saturation_matrix[i + 2], |
| 617 | saturation_matrix[i + 3]); |
| 618 | } |
| 619 | for (uint32_t i = 0; i < kDataspaceSaturationMatrixCount; i++) { |
| 620 | out_matrix[i] = saturation_matrix[i]; |
| 621 | } |
| 622 | return HWC2_ERROR_NONE; |
| 623 | } |
| 624 | |
Rajavenu Kyatham | 42d11cb | 2019-04-16 13:03:29 +0530 | [diff] [blame] | 625 | int32_t HWCSession::GetPerFrameMetadataKeys(hwc2_display_t display, uint32_t *out_num_keys, |
| 626 | int32_t *int_out_keys) { |
Naseer Ahmed | a6782e4 | 2018-06-04 10:56:04 -0400 | [diff] [blame] | 627 | auto out_keys = reinterpret_cast<PerFrameMetadataKey *>(int_out_keys); |
Rajavenu Kyatham | 42d11cb | 2019-04-16 13:03:29 +0530 | [diff] [blame] | 628 | return CallDisplayFunction(display, &HWCDisplay::GetPerFrameMetadataKeys, out_num_keys, |
| 629 | out_keys); |
Naseer Ahmed | a6782e4 | 2018-06-04 10:56:04 -0400 | [diff] [blame] | 630 | } |
| 631 | |
Rajavenu Kyatham | 42d11cb | 2019-04-16 13:03:29 +0530 | [diff] [blame] | 632 | int32_t HWCSession::SetLayerPerFrameMetadata(hwc2_display_t display, hwc2_layer_t layer, |
| 633 | uint32_t num_elements, const int32_t *int_keys, |
| 634 | const float *metadata) { |
Naseer Ahmed | a6782e4 | 2018-06-04 10:56:04 -0400 | [diff] [blame] | 635 | auto keys = reinterpret_cast<const PerFrameMetadataKey *>(int_keys); |
Rajavenu Kyatham | 42d11cb | 2019-04-16 13:03:29 +0530 | [diff] [blame] | 636 | return CallLayerFunction(display, layer, &HWCLayer::SetLayerPerFrameMetadata, num_elements, |
| 637 | keys, metadata); |
Naseer Ahmed | a6782e4 | 2018-06-04 10:56:04 -0400 | [diff] [blame] | 638 | } |
| 639 | |
Gousemoodhin Nadaf | 4b096d0 | 2019-10-24 15:39:59 +0530 | [diff] [blame] | 640 | int32_t HWCSession:: SetLayerPerFrameMetadataBlobs(hwc2_display_t display, |
| 641 | hwc2_layer_t layer, uint32_t num_elements, |
| 642 | const int32_t *int_keys, const uint32_t *sizes, |
| 643 | const uint8_t *metadata) { |
| 644 | auto keys = reinterpret_cast<const PerFrameMetadataKey *>(int_keys); |
| 645 | return CallLayerFunction(display, layer, &HWCLayer::SetLayerPerFrameMetadataBlobs, |
| 646 | num_elements, keys, sizes, metadata); |
| 647 | } |
| 648 | |
Lakshmi Narayana Kalavala | 25fe12c | 2019-12-11 20:44:55 -0800 | [diff] [blame] | 649 | int32_t HWCSession::SetDisplayedContentSamplingEnabled(hwc2_display_t display, int32_t enabled, |
| 650 | uint8_t component_mask, |
| 651 | uint64_t max_frames) { |
| 652 | static constexpr int32_t validComponentMask = HWC2_FORMAT_COMPONENT_0 | HWC2_FORMAT_COMPONENT_1 | |
| 653 | HWC2_FORMAT_COMPONENT_2 | HWC2_FORMAT_COMPONENT_3; |
| 654 | if (component_mask & ~validComponentMask) |
| 655 | return HWC2_ERROR_BAD_PARAMETER; |
| 656 | return CallDisplayFunction(display, &HWCDisplay::SetDisplayedContentSamplingEnabled, enabled, |
| 657 | component_mask, max_frames); |
| 658 | } |
| 659 | |
| 660 | int32_t HWCSession::GetDisplayedContentSamplingAttributes(hwc2_display_t display, int32_t *format, |
| 661 | int32_t *dataspace, |
| 662 | uint8_t *supported_components) { |
| 663 | return CallDisplayFunction(display, &HWCDisplay::GetDisplayedContentSamplingAttributes, format, |
| 664 | dataspace, supported_components); |
| 665 | } |
| 666 | |
| 667 | int32_t HWCSession::GetDisplayedContentSample(hwc2_display_t display, uint64_t max_frames, |
| 668 | uint64_t timestamp, uint64_t *numFrames, |
| 669 | int32_t samples_size[NUM_HISTOGRAM_COLOR_COMPONENTS], |
| 670 | uint64_t *samples[NUM_HISTOGRAM_COLOR_COMPONENTS]) { |
| 671 | return CallDisplayFunction(display, &HWCDisplay::GetDisplayedContentSample, max_frames, timestamp, |
| 672 | numFrames, samples_size, samples); |
| 673 | } |
| 674 | |
Rajavenu Kyatham | 42d11cb | 2019-04-16 13:03:29 +0530 | [diff] [blame] | 675 | int32_t HWCSession::GetDisplayAttribute(hwc2_display_t display, hwc2_config_t config, |
Naseer Ahmed | 8584a0f | 2020-02-19 22:23:30 -0500 | [diff] [blame] | 676 | HwcAttribute attribute, int32_t *out_value) { |
| 677 | if (out_value == nullptr) { |
Arun Kumar K.R | 0e10fd2 | 2017-10-11 14:42:11 +0530 | [diff] [blame] | 678 | return HWC2_ERROR_BAD_PARAMETER; |
| 679 | } |
Rajavenu Kyatham | 42d11cb | 2019-04-16 13:03:29 +0530 | [diff] [blame] | 680 | return CallDisplayFunction(display, &HWCDisplay::GetDisplayAttribute, config, attribute, |
| 681 | out_value); |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 682 | } |
| 683 | |
Rajavenu Kyatham | 42d11cb | 2019-04-16 13:03:29 +0530 | [diff] [blame] | 684 | int32_t HWCSession::GetDisplayConfigs(hwc2_display_t display, uint32_t *out_num_configs, |
| 685 | hwc2_config_t *out_configs) { |
| 686 | return CallDisplayFunction(display, &HWCDisplay::GetDisplayConfigs, out_num_configs, |
| 687 | out_configs); |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 688 | } |
| 689 | |
Rajavenu Kyatham | 42d11cb | 2019-04-16 13:03:29 +0530 | [diff] [blame] | 690 | int32_t HWCSession::GetDisplayName(hwc2_display_t display, uint32_t *out_size, char *out_name) { |
| 691 | return CallDisplayFunction(display, &HWCDisplay::GetDisplayName, out_size, out_name); |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 692 | } |
| 693 | |
Rajavenu Kyatham | 42d11cb | 2019-04-16 13:03:29 +0530 | [diff] [blame] | 694 | int32_t HWCSession::GetDisplayRequests(hwc2_display_t display, int32_t *out_display_requests, |
| 695 | uint32_t *out_num_elements, hwc2_layer_t *out_layers, |
| 696 | int32_t *out_layer_requests) { |
| 697 | return CallDisplayFunction(display, &HWCDisplay::GetDisplayRequests, out_display_requests, |
| 698 | out_num_elements, out_layers, out_layer_requests); |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 699 | } |
| 700 | |
Rajavenu Kyatham | 42d11cb | 2019-04-16 13:03:29 +0530 | [diff] [blame] | 701 | int32_t HWCSession::GetDisplayType(hwc2_display_t display, int32_t *out_type) { |
| 702 | return CallDisplayFunction(display, &HWCDisplay::GetDisplayType, out_type); |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 703 | } |
| 704 | |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 705 | |
Rajavenu Kyatham | 42d11cb | 2019-04-16 13:03:29 +0530 | [diff] [blame] | 706 | int32_t HWCSession::GetHdrCapabilities(hwc2_display_t display, uint32_t* out_num_types, |
| 707 | int32_t* out_types, float* out_max_luminance, |
| 708 | float* out_max_average_luminance, |
| 709 | float* out_min_luminance) { |
| 710 | return CallDisplayFunction(display, &HWCDisplay::GetHdrCapabilities, out_num_types, out_types, |
| 711 | out_max_luminance, out_max_average_luminance, out_min_luminance); |
Naseer Ahmed | 7790772 | 2016-05-03 18:27:54 -0400 | [diff] [blame] | 712 | } |
| 713 | |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 714 | |
Rajavenu Kyatham | 42d11cb | 2019-04-16 13:03:29 +0530 | [diff] [blame] | 715 | int32_t HWCSession::GetReleaseFences(hwc2_display_t display, uint32_t *out_num_elements, |
Rajavenu Kyatham | 7338b9e | 2019-12-30 19:52:16 +0530 | [diff] [blame] | 716 | hwc2_layer_t *out_layers, |
| 717 | std::vector<shared_ptr<Fence>> *out_fences) { |
Rajavenu Kyatham | 42d11cb | 2019-04-16 13:03:29 +0530 | [diff] [blame] | 718 | return CallDisplayFunction(display, &HWCDisplay::GetReleaseFences, out_num_elements, out_layers, |
| 719 | out_fences); |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 720 | } |
| 721 | |
Padmanabhan Komanduru | 6693fcb | 2019-11-22 21:06:52 +0530 | [diff] [blame] | 722 | void HWCSession::PerformQsyncCallback(hwc2_display_t display) { |
Padmanabhan Komanduru | 9e97162 | 2020-02-10 13:09:34 +0530 | [diff] [blame] | 723 | std::shared_ptr<DisplayConfig::ConfigCallback> callback = qsync_callback_.lock(); |
| 724 | if (!callback) { |
Padmanabhan Komanduru | 6693fcb | 2019-11-22 21:06:52 +0530 | [diff] [blame] | 725 | return; |
| 726 | } |
| 727 | |
| 728 | bool qsync_enabled = 0; |
| 729 | int32_t refresh_rate = 0, qsync_refresh_rate = 0; |
| 730 | if (hwc_display_[display]->IsQsyncCallbackNeeded(&qsync_enabled, |
| 731 | &refresh_rate, &qsync_refresh_rate)) { |
Padmanabhan Komanduru | 9e97162 | 2020-02-10 13:09:34 +0530 | [diff] [blame] | 732 | callback->NotifyQsyncChange(qsync_enabled, refresh_rate, qsync_refresh_rate); |
Padmanabhan Komanduru | 6693fcb | 2019-11-22 21:06:52 +0530 | [diff] [blame] | 733 | } |
| 734 | } |
| 735 | |
Dileep Marchya | ad66843 | 2019-12-02 10:44:52 +0530 | [diff] [blame] | 736 | int32_t HWCSession::PresentDisplay(hwc2_display_t display, shared_ptr<Fence> *out_retire_fence) { |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 737 | auto status = HWC2::Error::BadDisplay; |
Baldev Sahu | a5e4836 | 2017-08-31 15:36:44 +0530 | [diff] [blame] | 738 | DTRACE_SCOPED(); |
Saurabh Shah | 04f932b | 2017-10-12 18:47:45 -0700 | [diff] [blame] | 739 | |
Rajavenu Kyatham | 42d11cb | 2019-04-16 13:03:29 +0530 | [diff] [blame] | 740 | if (display >= HWCCallbacks::kNumDisplays) { |
| 741 | DLOGW("Invalid Display : display = %" PRIu64, display); |
Saurabh Shah | 04f932b | 2017-10-12 18:47:45 -0700 | [diff] [blame] | 742 | return HWC2_ERROR_BAD_DISPLAY; |
| 743 | } |
| 744 | |
Rajavenu Kyatham | 42d11cb | 2019-04-16 13:03:29 +0530 | [diff] [blame] | 745 | HandleSecureSession(); |
Mathew Joseph Karimpanal | b1c1586 | 2019-07-04 11:14:24 +0530 | [diff] [blame] | 746 | |
| 747 | |
| 748 | hwc2_display_t target_display = display; |
| 749 | |
Baldev Sahu | a5e4836 | 2017-08-31 15:36:44 +0530 | [diff] [blame] | 750 | { |
Srinivas Pullakavi | 3c4337f | 2019-07-03 11:24:31 +0530 | [diff] [blame] | 751 | SCOPE_LOCK(power_state_[display]); |
| 752 | if (power_state_transition_[display]) { |
| 753 | // Route all interactions with client to dummy display. |
Mathew Joseph Karimpanal | b1c1586 | 2019-07-04 11:14:24 +0530 | [diff] [blame] | 754 | target_display = map_hwc_display_.find(display)->second; |
Srinivas Pullakavi | 3c4337f | 2019-07-03 11:24:31 +0530 | [diff] [blame] | 755 | } |
| 756 | } |
| 757 | |
| 758 | { |
Mathew Joseph Karimpanal | b1c1586 | 2019-07-04 11:14:24 +0530 | [diff] [blame] | 759 | SEQUENCE_EXIT_SCOPE_LOCK(locker_[target_display]); |
| 760 | if (!hwc_display_[target_display]) { |
| 761 | DLOGW("Removed Display : display = %" PRIu64, target_display); |
Baldev Sahu | a5e4836 | 2017-08-31 15:36:44 +0530 | [diff] [blame] | 762 | return HWC2_ERROR_BAD_DISPLAY; |
| 763 | } |
| 764 | |
| 765 | if (out_retire_fence == nullptr) { |
| 766 | return HWC2_ERROR_BAD_PARAMETER; |
| 767 | } |
| 768 | |
Mathew Joseph Karimpanal | b1c1586 | 2019-07-04 11:14:24 +0530 | [diff] [blame] | 769 | if (pending_power_mode_[display]) { |
Mathew Joseph Karimpanal | 71ac8a7 | 2018-09-25 22:27:22 +0530 | [diff] [blame] | 770 | status = HWC2::Error::None; |
Gurpreet Singh Dhami | a947823 | 2018-08-21 12:19:47 -0400 | [diff] [blame] | 771 | } else { |
Sushil Chauhan | dbd8db4 | 2020-02-28 13:07:48 -0800 | [diff] [blame] | 772 | hwc_display_[target_display]->ProcessActiveConfigChange(); |
Dileep Marchya | ad66843 | 2019-12-02 10:44:52 +0530 | [diff] [blame] | 773 | status = PresentDisplayInternal(target_display); |
Padmanabhan Komanduru | e74cf4f | 2019-04-25 17:38:43 -0700 | [diff] [blame] | 774 | if (status == HWC2::Error::None) { |
| 775 | // Check if hwc's refresh trigger is getting exercised. |
Rajavenu Kyatham | 42d11cb | 2019-04-16 13:03:29 +0530 | [diff] [blame] | 776 | if (callbacks_.NeedsRefresh(display)) { |
Mathew Joseph Karimpanal | b1c1586 | 2019-07-04 11:14:24 +0530 | [diff] [blame] | 777 | hwc_display_[target_display]->SetPendingRefresh(); |
Rajavenu Kyatham | 42d11cb | 2019-04-16 13:03:29 +0530 | [diff] [blame] | 778 | callbacks_.ResetRefresh(display); |
Padmanabhan Komanduru | e74cf4f | 2019-04-25 17:38:43 -0700 | [diff] [blame] | 779 | } |
Mathew Joseph Karimpanal | b1c1586 | 2019-07-04 11:14:24 +0530 | [diff] [blame] | 780 | status = hwc_display_[target_display]->Present(out_retire_fence); |
Padmanabhan Komanduru | 6693fcb | 2019-11-22 21:06:52 +0530 | [diff] [blame] | 781 | if (status == HWC2::Error::None) { |
| 782 | PerformQsyncCallback(target_display); |
| 783 | } |
Padmanabhan Komanduru | e74cf4f | 2019-04-25 17:38:43 -0700 | [diff] [blame] | 784 | } |
Baldev Sahu | a5e4836 | 2017-08-31 15:36:44 +0530 | [diff] [blame] | 785 | } |
| 786 | } |
| 787 | |
Saurabh Shah | 04f932b | 2017-10-12 18:47:45 -0700 | [diff] [blame] | 788 | if (status != HWC2::Error::None && status != HWC2::Error::NotValidated) { |
Mathew Joseph Karimpanal | b1c1586 | 2019-07-04 11:14:24 +0530 | [diff] [blame] | 789 | SEQUENCE_CANCEL_SCOPE_LOCK(locker_[target_display]); |
Saurabh Shah | 04f932b | 2017-10-12 18:47:45 -0700 | [diff] [blame] | 790 | } |
| 791 | |
Mathew Joseph Karimpanal | b1c1586 | 2019-07-04 11:14:24 +0530 | [diff] [blame] | 792 | HandlePendingPowerMode(display, *out_retire_fence); |
| 793 | HandlePendingHotplug(display, *out_retire_fence); |
Rajavenu Kyatham | 42d11cb | 2019-04-16 13:03:29 +0530 | [diff] [blame] | 794 | HandlePendingRefresh(); |
Dileep Marchya | cb2a3a9 | 2019-06-21 17:30:50 +0530 | [diff] [blame] | 795 | cwb_.PresentDisplayDone(display); |
Srinivas Pullakavi | 3c4337f | 2019-07-03 11:24:31 +0530 | [diff] [blame] | 796 | display_ready_.set(UINT32(display)); |
Padmanabhan Komanduru | f5b7f99 | 2019-07-08 13:33:44 +0530 | [diff] [blame] | 797 | { |
| 798 | std::unique_lock<std::mutex> caller_lock(hotplug_mutex_); |
| 799 | hotplug_cv_.notify_one(); |
| 800 | } |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 801 | |
| 802 | return INT32(status); |
| 803 | } |
| 804 | |
Padmanabhan Komanduru | 1649f22 | 2019-03-05 11:25:00 +0530 | [diff] [blame] | 805 | void HWCSession::HandlePendingRefresh() { |
| 806 | if (pending_refresh_.none()) { |
| 807 | return; |
| 808 | } |
| 809 | |
| 810 | for (size_t i = 0; i < pending_refresh_.size(); i++) { |
| 811 | if (pending_refresh_.test(i)) { |
Varun Arora | dff7d8d | 2019-08-05 18:12:43 -0700 | [diff] [blame] | 812 | callbacks_.Refresh(i); |
Padmanabhan Komanduru | 1649f22 | 2019-03-05 11:25:00 +0530 | [diff] [blame] | 813 | } |
| 814 | break; |
| 815 | } |
| 816 | |
| 817 | pending_refresh_.reset(); |
| 818 | } |
| 819 | |
Rajavenu Kyatham | 42d11cb | 2019-04-16 13:03:29 +0530 | [diff] [blame] | 820 | void HWCSession::RegisterCallback(int32_t descriptor, hwc2_callback_data_t callback_data, |
| 821 | hwc2_function_pointer_t pointer) { |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 822 | auto desc = static_cast<HWC2::Callback>(descriptor); |
Varun Arora | 2daeb07 | 2019-08-06 15:09:28 -0700 | [diff] [blame] | 823 | |
| 824 | // Detect if client died and now is back |
| 825 | bool already_connected = false; |
| 826 | vector<hwc2_display_t> pending_hotplugs; |
Gousemoodhin Nadaf | 0db182e | 2019-09-05 23:02:31 +0530 | [diff] [blame] | 827 | if (descriptor == HWC2_CALLBACK_HOTPLUG && pointer) { |
Varun Arora | 2daeb07 | 2019-08-06 15:09:28 -0700 | [diff] [blame] | 828 | already_connected = callbacks_.IsClientConnected(); |
| 829 | if (already_connected) { |
| 830 | for (auto& map_info : map_info_builtin_) { |
| 831 | SCOPE_LOCK(locker_[map_info.client_id]); |
| 832 | if (hwc_display_[map_info.client_id]) { |
| 833 | pending_hotplugs.push_back(static_cast<hwc2_display_t>(map_info.client_id)); |
| 834 | } |
| 835 | } |
| 836 | for (auto& map_info : map_info_pluggable_) { |
| 837 | SCOPE_LOCK(locker_[map_info.client_id]); |
| 838 | if (hwc_display_[map_info.client_id]) { |
| 839 | pending_hotplugs.push_back(static_cast<hwc2_display_t>(map_info.client_id)); |
| 840 | } |
| 841 | } |
| 842 | } |
| 843 | } |
| 844 | |
Rajavenu Kyatham | 42d11cb | 2019-04-16 13:03:29 +0530 | [diff] [blame] | 845 | auto error = callbacks_.Register(desc, callback_data, pointer); |
Dileep Marchya | f3ce11f | 2018-04-30 23:35:46 +0530 | [diff] [blame] | 846 | if (error != HWC2::Error::None) { |
Rajavenu Kyatham | 42d11cb | 2019-04-16 13:03:29 +0530 | [diff] [blame] | 847 | return; |
Dileep Marchya | f3ce11f | 2018-04-30 23:35:46 +0530 | [diff] [blame] | 848 | } |
| 849 | |
Varun Arora | dff7d8d | 2019-08-05 18:12:43 -0700 | [diff] [blame] | 850 | DLOGI("%s callback: %s", pointer ? "Registering" : "Deregistering", to_string(desc).c_str()); |
Gousemoodhin Nadaf | 0db182e | 2019-09-05 23:02:31 +0530 | [diff] [blame] | 851 | if (descriptor == HWC2_CALLBACK_HOTPLUG && pointer) { |
Rajavenu Kyatham | 42d11cb | 2019-04-16 13:03:29 +0530 | [diff] [blame] | 852 | if (hwc_display_[HWC_DISPLAY_PRIMARY]) { |
Mathew Joseph Karimpanal | 8abb6e0 | 2018-11-20 09:52:49 +0530 | [diff] [blame] | 853 | DLOGI("Hotplugging primary..."); |
Rajavenu Kyatham | 42d11cb | 2019-04-16 13:03:29 +0530 | [diff] [blame] | 854 | callbacks_.Hotplug(HWC_DISPLAY_PRIMARY, HWC2::Connection::Connected); |
Dileep Marchya | d16da3e | 2017-05-20 01:56:21 +0530 | [diff] [blame] | 855 | } |
Mathew Joseph Karimpanal | 8abb6e0 | 2018-11-20 09:52:49 +0530 | [diff] [blame] | 856 | // Create displays since they should now have their final display indices set. |
| 857 | DLOGI("Handling built-in displays..."); |
Rajavenu Kyatham | 42d11cb | 2019-04-16 13:03:29 +0530 | [diff] [blame] | 858 | if (HandleBuiltInDisplays()) { |
Mathew Joseph Karimpanal | 8abb6e0 | 2018-11-20 09:52:49 +0530 | [diff] [blame] | 859 | DLOGW("Failed handling built-in displays."); |
| 860 | } |
| 861 | DLOGI("Handling pluggable displays..."); |
Rajavenu Kyatham | 42d11cb | 2019-04-16 13:03:29 +0530 | [diff] [blame] | 862 | int32_t err = HandlePluggableDisplays(false); |
Mathew Joseph Karimpanal | abe3b3d | 2018-11-27 17:25:40 +0530 | [diff] [blame] | 863 | if (err) { |
| 864 | DLOGW("All displays could not be created. Error %d '%s'. Hotplug handling %s.", err, |
Mathew Joseph Karimpanal | b1c1586 | 2019-07-04 11:14:24 +0530 | [diff] [blame] | 865 | strerror(abs(err)), pending_hotplug_event_ == kHotPlugEvent ? "deferred" : |
Mathew Joseph Karimpanal | abe3b3d | 2018-11-27 17:25:40 +0530 | [diff] [blame] | 866 | "dropped"); |
Mathew Joseph Karimpanal | 8abb6e0 | 2018-11-20 09:52:49 +0530 | [diff] [blame] | 867 | } |
Varun Arora | 2daeb07 | 2019-08-06 15:09:28 -0700 | [diff] [blame] | 868 | |
| 869 | // If previously registered, call hotplug for all connected displays to refresh |
| 870 | if (already_connected) { |
Gousemoodhin Nadaf | 0db182e | 2019-09-05 23:02:31 +0530 | [diff] [blame] | 871 | std::vector<hwc2_display_t> updated_pending_hotplugs; |
Varun Arora | 2daeb07 | 2019-08-06 15:09:28 -0700 | [diff] [blame] | 872 | for (auto client_id : pending_hotplugs) { |
| 873 | SCOPE_LOCK(locker_[client_id]); |
Gousemoodhin Nadaf | 0db182e | 2019-09-05 23:02:31 +0530 | [diff] [blame] | 874 | // check if the display is unregistered |
Varun Arora | 2daeb07 | 2019-08-06 15:09:28 -0700 | [diff] [blame] | 875 | if (hwc_display_[client_id]) { |
Gousemoodhin Nadaf | 0db182e | 2019-09-05 23:02:31 +0530 | [diff] [blame] | 876 | updated_pending_hotplugs.push_back(client_id); |
Varun Arora | 2daeb07 | 2019-08-06 15:09:28 -0700 | [diff] [blame] | 877 | } |
| 878 | } |
Gousemoodhin Nadaf | 0db182e | 2019-09-05 23:02:31 +0530 | [diff] [blame] | 879 | for (auto client_id : updated_pending_hotplugs) { |
| 880 | DLOGI("Re-hotplug display connected: client id = %d", client_id); |
| 881 | callbacks_.Hotplug(client_id, HWC2::Connection::Connected); |
| 882 | } |
Varun Arora | 2daeb07 | 2019-08-06 15:09:28 -0700 | [diff] [blame] | 883 | } |
Rajavenu Kyatham | 59b6786 | 2019-11-26 21:02:56 +0530 | [diff] [blame] | 884 | } |
| 885 | |
| 886 | if (descriptor == HWC2_CALLBACK_HOTPLUG) { |
Pullakavi Srinivas | 2d55f3a | 2019-07-16 14:49:06 +0530 | [diff] [blame] | 887 | client_connected_ = !!pointer; |
| 888 | // Notfify all displays. |
| 889 | NotifyClientStatus(client_connected_); |
Dileep Marchya | d16da3e | 2017-05-20 01:56:21 +0530 | [diff] [blame] | 890 | } |
Rajavenu Kyatham | 42d11cb | 2019-04-16 13:03:29 +0530 | [diff] [blame] | 891 | need_invalidate_ = false; |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 892 | } |
| 893 | |
Rajavenu Kyatham | 42d11cb | 2019-04-16 13:03:29 +0530 | [diff] [blame] | 894 | int32_t HWCSession::SetActiveConfig(hwc2_display_t display, hwc2_config_t config) { |
| 895 | return CallDisplayFunction(display, &HWCDisplay::SetActiveConfig, config); |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 896 | } |
| 897 | |
Rajavenu Kyatham | 42d11cb | 2019-04-16 13:03:29 +0530 | [diff] [blame] | 898 | int32_t HWCSession::SetClientTarget(hwc2_display_t display, buffer_handle_t target, |
Rajavenu Kyatham | 7338b9e | 2019-12-30 19:52:16 +0530 | [diff] [blame] | 899 | const shared_ptr<Fence> acquire_fence, int32_t dataspace, |
Rajavenu Kyatham | 42d11cb | 2019-04-16 13:03:29 +0530 | [diff] [blame] | 900 | hwc_region_t damage) { |
| 901 | return CallDisplayFunction(display, &HWCDisplay::SetClientTarget, target, acquire_fence, |
| 902 | dataspace, damage); |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 903 | } |
| 904 | |
Rajavenu Kyatham | 42d11cb | 2019-04-16 13:03:29 +0530 | [diff] [blame] | 905 | int32_t HWCSession::SetColorMode(hwc2_display_t display, int32_t /*ColorMode*/ int_mode) { |
Naseer Ahmed | e7a7798 | 2018-06-04 10:56:04 -0400 | [diff] [blame] | 906 | auto mode = static_cast<ColorMode>(int_mode); |
Gousemoodhin Nadaf | 0e56687 | 2019-05-13 16:14:54 +0530 | [diff] [blame] | 907 | if (mode < ColorMode::NATIVE || mode > ColorMode::DISPLAY_BT2020) { |
Saurabh Dubey | 2506937 | 2017-10-10 14:21:22 +0530 | [diff] [blame] | 908 | return HWC2_ERROR_BAD_PARAMETER; |
| 909 | } |
Rajavenu Kyatham | 42d11cb | 2019-04-16 13:03:29 +0530 | [diff] [blame] | 910 | return CallDisplayFunction(display, &HWCDisplay::SetColorMode, mode); |
Arun Kumar K.R | 29cd658 | 2016-05-10 19:12:45 -0700 | [diff] [blame] | 911 | } |
| 912 | |
Rajavenu Kyatham | 42d11cb | 2019-04-16 13:03:29 +0530 | [diff] [blame] | 913 | int32_t HWCSession::SetColorModeWithRenderIntent(hwc2_display_t display, |
Naseer Ahmed | e7a7798 | 2018-06-04 10:56:04 -0400 | [diff] [blame] | 914 | int32_t /*ColorMode*/ int_mode, |
| 915 | int32_t /*RenderIntent*/ int_render_intent) { |
| 916 | auto mode = static_cast<ColorMode>(int_mode); |
Gousemoodhin Nadaf | 0e56687 | 2019-05-13 16:14:54 +0530 | [diff] [blame] | 917 | if (mode < ColorMode::NATIVE || mode > ColorMode::DISPLAY_BT2020) { |
Naseer Ahmed | e7a7798 | 2018-06-04 10:56:04 -0400 | [diff] [blame] | 918 | return HWC2_ERROR_BAD_PARAMETER; |
| 919 | } |
Xu Yang | 47f4409 | 2019-02-13 14:09:53 +0800 | [diff] [blame] | 920 | |
| 921 | if ((int_render_intent < 0) || (int_render_intent > MAX_EXTENDED_RENDER_INTENT)) { |
| 922 | DLOGE("Invalid RenderIntent: %d", int_render_intent); |
Gurpreet Singh Dhami | ec0fa51 | 2018-08-29 16:51:26 -0400 | [diff] [blame] | 923 | return HWC2_ERROR_BAD_PARAMETER; |
| 924 | } |
Xu Yang | 47f4409 | 2019-02-13 14:09:53 +0800 | [diff] [blame] | 925 | |
| 926 | auto render_intent = static_cast<RenderIntent>(int_render_intent); |
Rajavenu Kyatham | 42d11cb | 2019-04-16 13:03:29 +0530 | [diff] [blame] | 927 | return CallDisplayFunction(display, &HWCDisplay::SetColorModeWithRenderIntent, mode, |
| 928 | render_intent); |
Naseer Ahmed | e7a7798 | 2018-06-04 10:56:04 -0400 | [diff] [blame] | 929 | } |
| 930 | |
Rajavenu Kyatham | 42d11cb | 2019-04-16 13:03:29 +0530 | [diff] [blame] | 931 | int32_t HWCSession::SetColorTransform(hwc2_display_t display, const float *matrix, |
Arun Kumar K.R | 29cd658 | 2016-05-10 19:12:45 -0700 | [diff] [blame] | 932 | int32_t /*android_color_transform_t*/ hint) { |
Saurabh Dubey | 2506937 | 2017-10-10 14:21:22 +0530 | [diff] [blame] | 933 | if (!matrix || hint < HAL_COLOR_TRANSFORM_IDENTITY || |
| 934 | hint > HAL_COLOR_TRANSFORM_CORRECT_TRITANOPIA) { |
| 935 | return HWC2_ERROR_BAD_PARAMETER; |
| 936 | } |
Arun Kumar K.R | 29cd658 | 2016-05-10 19:12:45 -0700 | [diff] [blame] | 937 | android_color_transform_t transform_hint = static_cast<android_color_transform_t>(hint); |
Rajavenu Kyatham | 42d11cb | 2019-04-16 13:03:29 +0530 | [diff] [blame] | 938 | return CallDisplayFunction(display, &HWCDisplay::SetColorTransform, matrix, transform_hint); |
Arun Kumar K.R | 29cd658 | 2016-05-10 19:12:45 -0700 | [diff] [blame] | 939 | } |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 940 | |
Rajavenu Kyatham | 42d11cb | 2019-04-16 13:03:29 +0530 | [diff] [blame] | 941 | int32_t HWCSession::SetCursorPosition(hwc2_display_t display, hwc2_layer_t layer, int32_t x, |
| 942 | int32_t y) { |
Pullakavi Srinivas | 68a166c | 2017-05-24 12:17:07 +0530 | [diff] [blame] | 943 | auto status = INT32(HWC2::Error::None); |
Rajavenu Kyatham | 42d11cb | 2019-04-16 13:03:29 +0530 | [diff] [blame] | 944 | status = CallDisplayFunction(display, &HWCDisplay::SetCursorPosition, layer, x, y); |
Pullakavi Srinivas | 68a166c | 2017-05-24 12:17:07 +0530 | [diff] [blame] | 945 | if (status == INT32(HWC2::Error::None)) { |
| 946 | // Update cursor position |
Rajavenu Kyatham | 42d11cb | 2019-04-16 13:03:29 +0530 | [diff] [blame] | 947 | CallLayerFunction(display, layer, &HWCLayer::SetCursorPosition, x, y); |
Pullakavi Srinivas | 68a166c | 2017-05-24 12:17:07 +0530 | [diff] [blame] | 948 | } |
| 949 | return status; |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 950 | } |
| 951 | |
Rajavenu Kyatham | 42d11cb | 2019-04-16 13:03:29 +0530 | [diff] [blame] | 952 | int32_t HWCSession::SetLayerBlendMode(hwc2_display_t display, hwc2_layer_t layer, |
| 953 | int32_t int_mode) { |
Saurabh Dubey | 2506937 | 2017-10-10 14:21:22 +0530 | [diff] [blame] | 954 | if (int_mode < HWC2_BLEND_MODE_INVALID || int_mode > HWC2_BLEND_MODE_COVERAGE) { |
| 955 | return HWC2_ERROR_BAD_PARAMETER; |
| 956 | } |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 957 | auto mode = static_cast<HWC2::BlendMode>(int_mode); |
Rajavenu Kyatham | 42d11cb | 2019-04-16 13:03:29 +0530 | [diff] [blame] | 958 | return CallLayerFunction(display, layer, &HWCLayer::SetLayerBlendMode, mode); |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 959 | } |
| 960 | |
Rajavenu Kyatham | 42d11cb | 2019-04-16 13:03:29 +0530 | [diff] [blame] | 961 | int32_t HWCSession::SetLayerBuffer(hwc2_display_t display, hwc2_layer_t layer, |
Rajavenu Kyatham | 7338b9e | 2019-12-30 19:52:16 +0530 | [diff] [blame] | 962 | buffer_handle_t buffer, |
| 963 | const shared_ptr<Fence> &acquire_fence) { |
Rajavenu Kyatham | 42d11cb | 2019-04-16 13:03:29 +0530 | [diff] [blame] | 964 | return CallLayerFunction(display, layer, &HWCLayer::SetLayerBuffer, buffer, acquire_fence); |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 965 | } |
| 966 | |
Rajavenu Kyatham | 42d11cb | 2019-04-16 13:03:29 +0530 | [diff] [blame] | 967 | int32_t HWCSession::SetLayerColor(hwc2_display_t display, hwc2_layer_t layer, hwc_color_t color) { |
| 968 | return CallLayerFunction(display, layer, &HWCLayer::SetLayerColor, color); |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 969 | } |
| 970 | |
Rajavenu Kyatham | 42d11cb | 2019-04-16 13:03:29 +0530 | [diff] [blame] | 971 | int32_t HWCSession::SetLayerCompositionType(hwc2_display_t display, hwc2_layer_t layer, |
| 972 | int32_t int_type) { |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 973 | auto type = static_cast<HWC2::Composition>(int_type); |
Rajavenu Kyatham | 42d11cb | 2019-04-16 13:03:29 +0530 | [diff] [blame] | 974 | return CallLayerFunction(display, layer, &HWCLayer::SetLayerCompositionType, type); |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 975 | } |
| 976 | |
Rajavenu Kyatham | 42d11cb | 2019-04-16 13:03:29 +0530 | [diff] [blame] | 977 | int32_t HWCSession::SetLayerDataspace(hwc2_display_t display, hwc2_layer_t layer, |
| 978 | int32_t dataspace) { |
| 979 | return CallLayerFunction(display, layer, &HWCLayer::SetLayerDataspace, dataspace); |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 980 | } |
| 981 | |
Rajavenu Kyatham | 42d11cb | 2019-04-16 13:03:29 +0530 | [diff] [blame] | 982 | int32_t HWCSession::SetLayerDisplayFrame(hwc2_display_t display, hwc2_layer_t layer, |
| 983 | hwc_rect_t frame) { |
| 984 | return CallLayerFunction(display, layer, &HWCLayer::SetLayerDisplayFrame, frame); |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 985 | } |
| 986 | |
Rajavenu Kyatham | 42d11cb | 2019-04-16 13:03:29 +0530 | [diff] [blame] | 987 | int32_t HWCSession::SetLayerPlaneAlpha(hwc2_display_t display, hwc2_layer_t layer, float alpha) { |
| 988 | return CallLayerFunction(display, layer, &HWCLayer::SetLayerPlaneAlpha, alpha); |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 989 | } |
| 990 | |
Rajavenu Kyatham | 42d11cb | 2019-04-16 13:03:29 +0530 | [diff] [blame] | 991 | int32_t HWCSession::SetLayerSourceCrop(hwc2_display_t display, hwc2_layer_t layer, |
| 992 | hwc_frect_t crop) { |
| 993 | return HWCSession::CallLayerFunction(display, layer, &HWCLayer::SetLayerSourceCrop, crop); |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 994 | } |
| 995 | |
Rajavenu Kyatham | 42d11cb | 2019-04-16 13:03:29 +0530 | [diff] [blame] | 996 | int32_t HWCSession::SetLayerSurfaceDamage(hwc2_display_t display, hwc2_layer_t layer, |
| 997 | hwc_region_t damage) { |
| 998 | return CallLayerFunction(display, layer, &HWCLayer::SetLayerSurfaceDamage, damage); |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 999 | } |
| 1000 | |
Rajavenu Kyatham | 42d11cb | 2019-04-16 13:03:29 +0530 | [diff] [blame] | 1001 | int32_t HWCSession::SetLayerTransform(hwc2_display_t display, hwc2_layer_t layer, |
| 1002 | int32_t int_transform) { |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 1003 | auto transform = static_cast<HWC2::Transform>(int_transform); |
Rajavenu Kyatham | 42d11cb | 2019-04-16 13:03:29 +0530 | [diff] [blame] | 1004 | return CallLayerFunction(display, layer, &HWCLayer::SetLayerTransform, transform); |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 1005 | } |
| 1006 | |
Rajavenu Kyatham | 42d11cb | 2019-04-16 13:03:29 +0530 | [diff] [blame] | 1007 | int32_t HWCSession::SetLayerVisibleRegion(hwc2_display_t display, hwc2_layer_t layer, |
| 1008 | hwc_region_t visible) { |
| 1009 | return CallLayerFunction(display, layer, &HWCLayer::SetLayerVisibleRegion, visible); |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 1010 | } |
| 1011 | |
Rajavenu Kyatham | 42d11cb | 2019-04-16 13:03:29 +0530 | [diff] [blame] | 1012 | int32_t HWCSession::SetLayerZOrder(hwc2_display_t display, hwc2_layer_t layer, uint32_t z) { |
| 1013 | return CallDisplayFunction(display, &HWCDisplay::SetLayerZOrder, layer, z); |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 1014 | } |
| 1015 | |
Ray Zhang | 2ee8247 | 2019-09-05 02:53:29 +0800 | [diff] [blame] | 1016 | int32_t HWCSession::SetLayerType(hwc2_display_t display, hwc2_layer_t layer, |
| 1017 | IQtiComposerClient::LayerType type) { |
| 1018 | return CallDisplayFunction(display, &HWCDisplay::SetLayerType, layer, type); |
| 1019 | } |
| 1020 | |
Rajavenu Kyatham | 42d11cb | 2019-04-16 13:03:29 +0530 | [diff] [blame] | 1021 | int32_t HWCSession::SetLayerColorTransform(hwc2_display_t display, hwc2_layer_t layer, |
| 1022 | const float *matrix) { |
| 1023 | return CallLayerFunction(display, layer, &HWCLayer::SetLayerColorTransform, matrix); |
Tharaga Balachandran | 209db58 | 2019-03-25 18:56:50 -0400 | [diff] [blame] | 1024 | } |
| 1025 | |
Padmanabhan Komanduru | 13b5e10 | 2019-12-03 12:35:09 +0530 | [diff] [blame] | 1026 | int32_t HWCSession::SetDisplayElapseTime(hwc2_display_t display, uint64_t time) { |
| 1027 | return CallDisplayFunction(display, &HWCDisplay::SetDisplayElapseTime, time); |
| 1028 | } |
| 1029 | |
Rajavenu Kyatham | 42d11cb | 2019-04-16 13:03:29 +0530 | [diff] [blame] | 1030 | int32_t HWCSession::SetOutputBuffer(hwc2_display_t display, buffer_handle_t buffer, |
Rajavenu Kyatham | 7338b9e | 2019-12-30 19:52:16 +0530 | [diff] [blame] | 1031 | const shared_ptr<Fence> &release_fence) { |
Rajavenu Kyatham | 42d11cb | 2019-04-16 13:03:29 +0530 | [diff] [blame] | 1032 | if (INT32(display) != GetDisplayIndex(qdutils::DISPLAY_VIRTUAL)) { |
Arun Kumar K.R | 1018d5b | 2017-06-08 13:51:05 +0530 | [diff] [blame] | 1033 | return HWC2_ERROR_UNSUPPORTED; |
| 1034 | } |
| 1035 | |
Saurabh Shah | c5c687a | 2017-08-24 16:30:14 -0700 | [diff] [blame] | 1036 | SCOPE_LOCK(locker_[display]); |
Rajavenu Kyatham | 42d11cb | 2019-04-16 13:03:29 +0530 | [diff] [blame] | 1037 | if (hwc_display_[display]) { |
| 1038 | auto vds = reinterpret_cast<HWCDisplayVirtual *>(hwc_display_[display]); |
Rajavenu Kyatham | 7338b9e | 2019-12-30 19:52:16 +0530 | [diff] [blame] | 1039 | auto status = vds->SetOutputBuffer(buffer, release_fence); |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 1040 | return INT32(status); |
| 1041 | } else { |
| 1042 | return HWC2_ERROR_BAD_DISPLAY; |
| 1043 | } |
| 1044 | } |
| 1045 | |
Rajavenu Kyatham | 42d11cb | 2019-04-16 13:03:29 +0530 | [diff] [blame] | 1046 | int32_t HWCSession::SetPowerMode(hwc2_display_t display, int32_t int_mode) { |
Padmanabhan Komanduru | e74cf4f | 2019-04-25 17:38:43 -0700 | [diff] [blame] | 1047 | if (display >= HWCCallbacks::kNumDisplays) { |
Varun Arora | 2c23e58 | 2017-10-10 15:07:13 -0700 | [diff] [blame] | 1048 | return HWC2_ERROR_BAD_DISPLAY; |
| 1049 | } |
| 1050 | |
| 1051 | // validate device and also avoid undefined behavior in cast to HWC2::PowerMode |
Rajavenu Kyatham | 42d11cb | 2019-04-16 13:03:29 +0530 | [diff] [blame] | 1052 | if (int_mode < HWC2_POWER_MODE_OFF || int_mode > HWC2_POWER_MODE_DOZE_SUSPEND) { |
Varun Arora | 2c23e58 | 2017-10-10 15:07:13 -0700 | [diff] [blame] | 1053 | return HWC2_ERROR_BAD_PARAMETER; |
| 1054 | } |
| 1055 | |
Mathew Joseph Karimpanal | b1c1586 | 2019-07-04 11:14:24 +0530 | [diff] [blame] | 1056 | if (pending_power_mode_[display]) { |
Ramkumar Radhakrishnan | a38b760 | 2018-03-15 14:49:52 -0700 | [diff] [blame] | 1057 | DLOGW("Set power mode is not allowed during secure display session"); |
| 1058 | return HWC2_ERROR_UNSUPPORTED; |
| 1059 | } |
| 1060 | |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 1061 | auto mode = static_cast<HWC2::PowerMode>(int_mode); |
Varun Arora | 2c23e58 | 2017-10-10 15:07:13 -0700 | [diff] [blame] | 1062 | |
| 1063 | // all displays support on/off. Check for doze modes |
| 1064 | int support = 0; |
Rajavenu Kyatham | 42d11cb | 2019-04-16 13:03:29 +0530 | [diff] [blame] | 1065 | auto status = GetDozeSupport(display, &support); |
Gurpreet Singh Dhami | a947823 | 2018-08-21 12:19:47 -0400 | [diff] [blame] | 1066 | if (status != HWC2_ERROR_NONE) { |
| 1067 | DLOGE("Failed to get doze support Error = %d", status); |
| 1068 | return INT32(status); |
| 1069 | } |
| 1070 | |
Varun Arora | 2c23e58 | 2017-10-10 15:07:13 -0700 | [diff] [blame] | 1071 | if (!support && (mode == HWC2::PowerMode::Doze || mode == HWC2::PowerMode::DozeSuspend)) { |
| 1072 | return HWC2_ERROR_UNSUPPORTED; |
| 1073 | } |
| 1074 | |
Srinivas Pullakavi | 3c4337f | 2019-07-03 11:24:31 +0530 | [diff] [blame] | 1075 | bool override_mode = async_powermode_ && display_ready_.test(UINT32(display)); |
| 1076 | if (!override_mode) { |
| 1077 | auto error = CallDisplayFunction(display, &HWCDisplay::SetPowerMode, mode, |
| 1078 | false /* teardown */); |
| 1079 | if (INT32(error) != HWC2_ERROR_NONE) { |
| 1080 | return INT32(error); |
| 1081 | } |
| 1082 | } else { |
Mathew Joseph Karimpanal | b1c1586 | 2019-07-04 11:14:24 +0530 | [diff] [blame] | 1083 | Locker::ScopeLock lock_disp(locker_[display]); |
Srinivas Pullakavi | 3c4337f | 2019-07-03 11:24:31 +0530 | [diff] [blame] | 1084 | // Update hwc state for now. Actual poweron will handled through DisplayConfig. |
| 1085 | hwc_display_[display]->UpdatePowerMode(mode); |
Srinivas Pullakavi | a747d83 | 2018-05-22 13:52:06 +0530 | [diff] [blame] | 1086 | } |
Ramkumar Radhakrishnan | f985d48 | 2018-07-23 18:10:41 -0700 | [diff] [blame] | 1087 | // Reset idle pc ref count on suspend, as we enable idle pc during suspend. |
| 1088 | if (mode == HWC2::PowerMode::Off) { |
Rajavenu Kyatham | 42d11cb | 2019-04-16 13:03:29 +0530 | [diff] [blame] | 1089 | idle_pc_ref_cnt_ = 0; |
Ramkumar Radhakrishnan | f985d48 | 2018-07-23 18:10:41 -0700 | [diff] [blame] | 1090 | } |
Srinivas Pullakavi | a747d83 | 2018-05-22 13:52:06 +0530 | [diff] [blame] | 1091 | |
Rajavenu Kyatham | 42d11cb | 2019-04-16 13:03:29 +0530 | [diff] [blame] | 1092 | |
| 1093 | UpdateThrottlingRate(); |
Rajavenu Kyatham | 9d50958 | 2019-02-13 15:29:55 +0530 | [diff] [blame] | 1094 | |
Rajavenu Kyatham | 9d50958 | 2019-02-13 15:29:55 +0530 | [diff] [blame] | 1095 | if (mode == HWC2::PowerMode::Doze) { |
Padmanabhan Komanduru | 1649f22 | 2019-03-05 11:25:00 +0530 | [diff] [blame] | 1096 | // Trigger one more refresh for PP features to take effect. |
Rajavenu Kyatham | 42d11cb | 2019-04-16 13:03:29 +0530 | [diff] [blame] | 1097 | pending_refresh_.set(UINT32(display)); |
Rajavenu Kyatham | 9d50958 | 2019-02-13 15:29:55 +0530 | [diff] [blame] | 1098 | } |
| 1099 | |
Srinivas Pullakavi | a747d83 | 2018-05-22 13:52:06 +0530 | [diff] [blame] | 1100 | return HWC2_ERROR_NONE; |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 1101 | } |
| 1102 | |
Rajavenu Kyatham | 42d11cb | 2019-04-16 13:03:29 +0530 | [diff] [blame] | 1103 | int32_t HWCSession::SetVsyncEnabled(hwc2_display_t display, int32_t int_enabled) { |
Varun Arora | 2c23e58 | 2017-10-10 15:07:13 -0700 | [diff] [blame] | 1104 | // avoid undefined behavior in cast to HWC2::Vsync |
| 1105 | if (int_enabled < HWC2_VSYNC_INVALID || int_enabled > HWC2_VSYNC_DISABLE) { |
| 1106 | return HWC2_ERROR_BAD_PARAMETER; |
| 1107 | } |
| 1108 | |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 1109 | auto enabled = static_cast<HWC2::Vsync>(int_enabled); |
Srinivas Pullakavi | a747d83 | 2018-05-22 13:52:06 +0530 | [diff] [blame] | 1110 | |
Padmanabhan Komanduru | f5e6c5d | 2019-04-04 13:56:31 +0530 | [diff] [blame] | 1111 | if (int_enabled == HWC2_VSYNC_ENABLE) { |
Rajavenu Kyatham | 42d11cb | 2019-04-16 13:03:29 +0530 | [diff] [blame] | 1112 | callbacks_.UpdateVsyncSource(display); |
Padmanabhan Komanduru | f5e6c5d | 2019-04-04 13:56:31 +0530 | [diff] [blame] | 1113 | } |
Srinivas Pullakavi | a747d83 | 2018-05-22 13:52:06 +0530 | [diff] [blame] | 1114 | |
Rajavenu Kyatham | 42d11cb | 2019-04-16 13:03:29 +0530 | [diff] [blame] | 1115 | return CallDisplayFunction(display, &HWCDisplay::SetVsyncEnabled, enabled); |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 1116 | } |
| 1117 | |
Rajavenu Kyatham | 42d11cb | 2019-04-16 13:03:29 +0530 | [diff] [blame] | 1118 | int32_t HWCSession::GetDozeSupport(hwc2_display_t display, int32_t *out_support) { |
| 1119 | if (!out_support) { |
Pullakavi Srinivas | 04e5242 | 2018-07-31 15:12:57 +0530 | [diff] [blame] | 1120 | return HWC2_ERROR_BAD_PARAMETER; |
| 1121 | } |
| 1122 | |
Rajavenu Kyatham | 42d11cb | 2019-04-16 13:03:29 +0530 | [diff] [blame] | 1123 | if (display >= HWCCallbacks::kNumDisplays || (hwc_display_[display] == nullptr)) { |
| 1124 | DLOGE("Invalid Display %d Handle %s ", display, hwc_display_[display] ? |
Gurpreet Singh Dhami | a947823 | 2018-08-21 12:19:47 -0400 | [diff] [blame] | 1125 | "Valid" : "NULL"); |
Pullakavi Srinivas | 04e5242 | 2018-07-31 15:12:57 +0530 | [diff] [blame] | 1126 | return HWC2_ERROR_BAD_DISPLAY; |
| 1127 | } |
| 1128 | |
Pullakavi Srinivas | 04e5242 | 2018-07-31 15:12:57 +0530 | [diff] [blame] | 1129 | *out_support = 0; |
Rajavenu Kyatham | 42d11cb | 2019-04-16 13:03:29 +0530 | [diff] [blame] | 1130 | if (hwc_display_[display]->GetDisplayClass() == DISPLAY_CLASS_BUILTIN) { |
Pullakavi Srinivas | 04e5242 | 2018-07-31 15:12:57 +0530 | [diff] [blame] | 1131 | *out_support = 1; |
| 1132 | } |
| 1133 | |
| 1134 | return HWC2_ERROR_NONE; |
| 1135 | } |
| 1136 | |
Rajavenu Kyatham | 42d11cb | 2019-04-16 13:03:29 +0530 | [diff] [blame] | 1137 | int32_t HWCSession::ValidateDisplay(hwc2_display_t display, uint32_t *out_num_types, |
| 1138 | uint32_t *out_num_requests) { |
Varun Arora | 2c23e58 | 2017-10-10 15:07:13 -0700 | [diff] [blame] | 1139 | // out_num_types and out_num_requests will be non-NULL |
Varun Arora | 2c23e58 | 2017-10-10 15:07:13 -0700 | [diff] [blame] | 1140 | |
Padmanabhan Komanduru | e74cf4f | 2019-04-25 17:38:43 -0700 | [diff] [blame] | 1141 | if (display >= HWCCallbacks::kNumDisplays) { |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 1142 | return HWC2_ERROR_BAD_DISPLAY; |
| 1143 | } |
Srinivas Pullakavi | 3c4337f | 2019-07-03 11:24:31 +0530 | [diff] [blame] | 1144 | |
Mathew Joseph Karimpanal | b1c1586 | 2019-07-04 11:14:24 +0530 | [diff] [blame] | 1145 | hwc2_display_t target_display = display; |
| 1146 | |
Srinivas Pullakavi | 3c4337f | 2019-07-03 11:24:31 +0530 | [diff] [blame] | 1147 | { |
| 1148 | SCOPE_LOCK(power_state_[display]); |
| 1149 | if (power_state_transition_[display]) { |
| 1150 | // Route all interactions with client to dummy display. |
Mathew Joseph Karimpanal | b1c1586 | 2019-07-04 11:14:24 +0530 | [diff] [blame] | 1151 | target_display = map_hwc_display_.find(display)->second; |
Srinivas Pullakavi | 3c4337f | 2019-07-03 11:24:31 +0530 | [diff] [blame] | 1152 | } |
| 1153 | } |
Varun Arora | 2c23e58 | 2017-10-10 15:07:13 -0700 | [diff] [blame] | 1154 | DTRACE_SCOPED(); |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 1155 | // TODO(user): Handle secure session, handle QDCM solid fill |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 1156 | auto status = HWC2::Error::BadDisplay; |
Rajavenu Kyatham | 42d11cb | 2019-04-16 13:03:29 +0530 | [diff] [blame] | 1157 | HandleSecureSession(); |
Saurabh Shah | c5c687a | 2017-08-24 16:30:14 -0700 | [diff] [blame] | 1158 | { |
Mathew Joseph Karimpanal | b1c1586 | 2019-07-04 11:14:24 +0530 | [diff] [blame] | 1159 | SEQUENCE_ENTRY_SCOPE_LOCK(locker_[target_display]); |
| 1160 | if (pending_power_mode_[display]) { |
Mathew Joseph Karimpanal | 71ac8a7 | 2018-09-25 22:27:22 +0530 | [diff] [blame] | 1161 | status = HWC2::Error::None; |
Mathew Joseph Karimpanal | b1c1586 | 2019-07-04 11:14:24 +0530 | [diff] [blame] | 1162 | } else if (hwc_display_[target_display]) { |
Sushil Chauhan | ba8e465 | 2020-03-20 10:07:47 -0700 | [diff] [blame^] | 1163 | hwc_display_[target_display]->ProcessActiveConfigChange(); |
Mathew Joseph Karimpanal | b1c1586 | 2019-07-04 11:14:24 +0530 | [diff] [blame] | 1164 | hwc_display_[target_display]->SetFastPathComposition(false); |
| 1165 | status = ValidateDisplayInternal(target_display, out_num_types, out_num_requests); |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 1166 | } |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 1167 | } |
Saurabh Shah | c5c687a | 2017-08-24 16:30:14 -0700 | [diff] [blame] | 1168 | |
Saurabh Shah | 04f932b | 2017-10-12 18:47:45 -0700 | [diff] [blame] | 1169 | // Sequence locking currently begins on Validate, so cancel the sequence lock on failures |
Saurabh Shah | 998ad47 | 2018-01-18 11:44:08 -0800 | [diff] [blame] | 1170 | if (status != HWC2::Error::None && status != HWC2::Error::HasChanges) { |
Mathew Joseph Karimpanal | b1c1586 | 2019-07-04 11:14:24 +0530 | [diff] [blame] | 1171 | SEQUENCE_CANCEL_SCOPE_LOCK(locker_[target_display]); |
| 1172 | } |
| 1173 | |
| 1174 | if (display != target_display) { |
| 1175 | // Validate done on a dummy display. Assume present is complete. |
| 1176 | SEQUENCE_EXIT_SCOPE_LOCK(locker_[target_display]); |
Saurabh Shah | c5c687a | 2017-08-24 16:30:14 -0700 | [diff] [blame] | 1177 | } |
| 1178 | |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 1179 | return INT32(status); |
| 1180 | } |
| 1181 | |
Dileep Marchya | f3ce11f | 2018-04-30 23:35:46 +0530 | [diff] [blame] | 1182 | HWC2::Error HWCSession::CreateVirtualDisplayObj(uint32_t width, uint32_t height, int32_t *format, |
| 1183 | hwc2_display_t *out_display_id) { |
Ramkumar Radhakrishnan | 44c6436 | 2018-12-12 13:03:59 -0800 | [diff] [blame] | 1184 | hwc2_display_t active_builtin_disp_id = GetActiveBuiltinDisplay(); |
Padmanabhan Komanduru | f5b7f99 | 2019-07-08 13:33:44 +0530 | [diff] [blame] | 1185 | hwc2_display_t client_id = HWCCallbacks::kNumDisplays; |
Padmanabhan Komanduru | e74cf4f | 2019-04-25 17:38:43 -0700 | [diff] [blame] | 1186 | if (active_builtin_disp_id < HWCCallbacks::kNumDisplays) { |
Ramkumar Radhakrishnan | 44c6436 | 2018-12-12 13:03:59 -0800 | [diff] [blame] | 1187 | SEQUENCE_WAIT_SCOPE_LOCK(locker_[active_builtin_disp_id]); |
Mathew Joseph Karimpanal | 71ac8a7 | 2018-09-25 22:27:22 +0530 | [diff] [blame] | 1188 | std::bitset<kSecureMax> secure_sessions = 0; |
Ramkumar Radhakrishnan | 44c6436 | 2018-12-12 13:03:59 -0800 | [diff] [blame] | 1189 | if (hwc_display_[active_builtin_disp_id]) { |
| 1190 | hwc_display_[active_builtin_disp_id]->GetActiveSecureSession(&secure_sessions); |
| 1191 | } |
Mathew Joseph Karimpanal | 71ac8a7 | 2018-09-25 22:27:22 +0530 | [diff] [blame] | 1192 | if (secure_sessions.any()) { |
| 1193 | DLOGE("Secure session is active, cannot create virtual display."); |
| 1194 | return HWC2::Error::Unsupported; |
| 1195 | } else if (IsPluggableDisplayConnected()) { |
| 1196 | DLOGE("External session is active, cannot create virtual display."); |
| 1197 | return HWC2::Error::Unsupported; |
| 1198 | } |
| 1199 | } |
| 1200 | |
Pullakavi Srinivas | f2a3185 | 2019-04-23 14:32:08 -0700 | [diff] [blame] | 1201 | if (hwc_display_[HWC_DISPLAY_PRIMARY]) { |
| 1202 | DisplayError error = hwc_display_[HWC_DISPLAY_PRIMARY]->TeardownConcurrentWriteback(); |
| 1203 | if (error) { |
| 1204 | return HWC2::Error::NoResources; |
| 1205 | } |
| 1206 | } |
| 1207 | |
Dileep Marchya | f3ce11f | 2018-04-30 23:35:46 +0530 | [diff] [blame] | 1208 | // Lock confined to this scope |
| 1209 | int status = -EINVAL; |
Pullakavi Srinivas | a3c292c | 2019-12-01 13:27:50 +0530 | [diff] [blame] | 1210 | for (auto &map_info : map_info_virtual_) { |
| 1211 | client_id = map_info.client_id; |
| 1212 | { |
| 1213 | SCOPE_LOCK(locker_[client_id]); |
| 1214 | auto &hwc_display = hwc_display_[client_id]; |
| 1215 | if (hwc_display) { |
| 1216 | continue; |
Dileep Marchya | f3ce11f | 2018-04-30 23:35:46 +0530 | [diff] [blame] | 1217 | } |
Pullakavi Srinivas | a3c292c | 2019-12-01 13:27:50 +0530 | [diff] [blame] | 1218 | |
| 1219 | int32_t display_id = GetVirtualDisplayId(); |
| 1220 | status = virtual_display_factory_.Create(core_intf_, &buffer_allocator_, &callbacks_, |
| 1221 | client_id, display_id, width, height, |
| 1222 | format, set_min_lum_, set_max_lum_, &hwc_display); |
| 1223 | // TODO(user): validate width and height support |
| 1224 | if (status) { |
| 1225 | return HWC2::Error::NoResources; |
| 1226 | } |
| 1227 | |
| 1228 | { |
| 1229 | SCOPE_LOCK(hdr_locker_[client_id]); |
| 1230 | is_hdr_display_[UINT32(client_id)] = HasHDRSupport(hwc_display); |
| 1231 | } |
| 1232 | |
| 1233 | DLOGI("Created virtual display id:% " PRIu64 " with res: %dx%d", client_id, width, height); |
| 1234 | |
| 1235 | *out_display_id = client_id; |
| 1236 | map_info.disp_type = kVirtual; |
| 1237 | map_info.sdm_id = display_id; |
| 1238 | break; |
Saurabh Shah | a307e8c | 2017-09-28 18:05:40 -0700 | [diff] [blame] | 1239 | } |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 1240 | } |
Saurabh Shah | a307e8c | 2017-09-28 18:05:40 -0700 | [diff] [blame] | 1241 | |
Padmanabhan Komanduru | f5b7f99 | 2019-07-08 13:33:44 +0530 | [diff] [blame] | 1242 | // Active builtin display needs revalidation |
| 1243 | if (!async_vds_creation_ && active_builtin_disp_id < HWCCallbacks::kNumRealDisplays) { |
Ramkumar Radhakrishnan | 44c6436 | 2018-12-12 13:03:59 -0800 | [diff] [blame] | 1244 | SEQUENCE_WAIT_SCOPE_LOCK(locker_[active_builtin_disp_id]); |
| 1245 | hwc_display_[active_builtin_disp_id]->ResetValidation(); |
| 1246 | } |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 1247 | |
| 1248 | return HWC2::Error::None; |
| 1249 | } |
| 1250 | |
Mathew Joseph Karimpanal | 71ac8a7 | 2018-09-25 22:27:22 +0530 | [diff] [blame] | 1251 | bool HWCSession::IsPluggableDisplayConnected() { |
| 1252 | for (auto &map_info : map_info_pluggable_) { |
| 1253 | if (hwc_display_[map_info.client_id]) { |
| 1254 | return true; |
| 1255 | } |
| 1256 | } |
| 1257 | return false; |
Pullakavi Srinivas | 04e5242 | 2018-07-31 15:12:57 +0530 | [diff] [blame] | 1258 | } |
| 1259 | |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 1260 | // Qclient methods |
| 1261 | android::status_t HWCSession::notifyCallback(uint32_t command, const android::Parcel *input_parcel, |
| 1262 | android::Parcel *output_parcel) { |
Mathew Joseph Karimpanal | dbd64f8 | 2017-10-06 10:13:38 +0530 | [diff] [blame] | 1263 | android::status_t status = -EINVAL; |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 1264 | |
| 1265 | switch (command) { |
| 1266 | case qService::IQService::DYNAMIC_DEBUG: |
Mathew Joseph Karimpanal | dbd64f8 | 2017-10-06 10:13:38 +0530 | [diff] [blame] | 1267 | if (!input_parcel) { |
| 1268 | DLOGE("QService command = %d: input_parcel needed.", command); |
| 1269 | break; |
| 1270 | } |
| 1271 | status = 0; |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 1272 | DynamicDebug(input_parcel); |
| 1273 | break; |
| 1274 | |
| 1275 | case qService::IQService::SCREEN_REFRESH: |
Dileep Marchya | 35e2753 | 2018-06-29 10:50:16 +0530 | [diff] [blame] | 1276 | if (!input_parcel) { |
| 1277 | DLOGE("QService command = %d: input_parcel needed.", command); |
| 1278 | break; |
| 1279 | } |
| 1280 | status = RefreshScreen(input_parcel); |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 1281 | break; |
| 1282 | |
| 1283 | case qService::IQService::SET_IDLE_TIMEOUT: |
Mathew Joseph Karimpanal | dbd64f8 | 2017-10-06 10:13:38 +0530 | [diff] [blame] | 1284 | if (!input_parcel) { |
| 1285 | DLOGE("QService command = %d: input_parcel needed.", command); |
| 1286 | break; |
| 1287 | } |
Padmanabhan Komanduru | 9e97162 | 2020-02-10 13:09:34 +0530 | [diff] [blame] | 1288 | status = SetIdleTimeout(UINT32(input_parcel->readInt32())); |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 1289 | break; |
| 1290 | |
| 1291 | case qService::IQService::SET_FRAME_DUMP_CONFIG: |
Mathew Joseph Karimpanal | dbd64f8 | 2017-10-06 10:13:38 +0530 | [diff] [blame] | 1292 | if (!input_parcel) { |
| 1293 | DLOGE("QService command = %d: input_parcel needed.", command); |
| 1294 | break; |
| 1295 | } |
| 1296 | status = SetFrameDumpConfig(input_parcel); |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 1297 | break; |
| 1298 | |
| 1299 | case qService::IQService::SET_MAX_PIPES_PER_MIXER: |
Mathew Joseph Karimpanal | dbd64f8 | 2017-10-06 10:13:38 +0530 | [diff] [blame] | 1300 | if (!input_parcel) { |
| 1301 | DLOGE("QService command = %d: input_parcel needed.", command); |
| 1302 | break; |
| 1303 | } |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 1304 | status = SetMaxMixerStages(input_parcel); |
| 1305 | break; |
| 1306 | |
| 1307 | case qService::IQService::SET_DISPLAY_MODE: |
Mathew Joseph Karimpanal | dbd64f8 | 2017-10-06 10:13:38 +0530 | [diff] [blame] | 1308 | if (!input_parcel) { |
| 1309 | DLOGE("QService command = %d: input_parcel needed.", command); |
| 1310 | break; |
| 1311 | } |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 1312 | status = SetDisplayMode(input_parcel); |
| 1313 | break; |
| 1314 | |
Dileep Marchya | 6860b2b | 2017-04-07 15:56:47 +0530 | [diff] [blame] | 1315 | case qService::IQService::SET_SECONDARY_DISPLAY_STATUS: { |
Mathew Joseph Karimpanal | dbd64f8 | 2017-10-06 10:13:38 +0530 | [diff] [blame] | 1316 | if (!input_parcel || !output_parcel) { |
| 1317 | DLOGE("QService command = %d: input_parcel and output_parcel needed.", command); |
| 1318 | break; |
| 1319 | } |
Dileep Marchya | 6860b2b | 2017-04-07 15:56:47 +0530 | [diff] [blame] | 1320 | int disp_id = INT(input_parcel->readInt32()); |
| 1321 | HWCDisplay::DisplayStatus disp_status = |
| 1322 | static_cast<HWCDisplay::DisplayStatus>(input_parcel->readInt32()); |
Padmanabhan Komanduru | 9e97162 | 2020-02-10 13:09:34 +0530 | [diff] [blame] | 1323 | status = SetDisplayStatus(disp_id, disp_status); |
Dileep Marchya | 6860b2b | 2017-04-07 15:56:47 +0530 | [diff] [blame] | 1324 | output_parcel->writeInt32(status); |
| 1325 | } |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 1326 | break; |
| 1327 | |
| 1328 | case qService::IQService::CONFIGURE_DYN_REFRESH_RATE: |
Mathew Joseph Karimpanal | dbd64f8 | 2017-10-06 10:13:38 +0530 | [diff] [blame] | 1329 | if (!input_parcel) { |
| 1330 | DLOGE("QService command = %d: input_parcel needed.", command); |
| 1331 | break; |
| 1332 | } |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 1333 | status = ConfigureRefreshRate(input_parcel); |
| 1334 | break; |
| 1335 | |
Dileep Marchya | 6860b2b | 2017-04-07 15:56:47 +0530 | [diff] [blame] | 1336 | case qService::IQService::TOGGLE_SCREEN_UPDATES: { |
Mathew Joseph Karimpanal | dbd64f8 | 2017-10-06 10:13:38 +0530 | [diff] [blame] | 1337 | if (!input_parcel || !output_parcel) { |
| 1338 | DLOGE("QService command = %d: input_parcel and output_parcel needed.", command); |
| 1339 | break; |
| 1340 | } |
Dileep Marchya | 6860b2b | 2017-04-07 15:56:47 +0530 | [diff] [blame] | 1341 | int32_t input = input_parcel->readInt32(); |
Padmanabhan Komanduru | 9e97162 | 2020-02-10 13:09:34 +0530 | [diff] [blame] | 1342 | status = ToggleScreenUpdate(input == 1); |
Dileep Marchya | 6860b2b | 2017-04-07 15:56:47 +0530 | [diff] [blame] | 1343 | output_parcel->writeInt32(status); |
| 1344 | } |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 1345 | break; |
| 1346 | |
| 1347 | case qService::IQService::QDCM_SVC_CMDS: |
Mathew Joseph Karimpanal | dbd64f8 | 2017-10-06 10:13:38 +0530 | [diff] [blame] | 1348 | if (!input_parcel || !output_parcel) { |
| 1349 | DLOGE("QService command = %d: input_parcel and output_parcel needed.", command); |
| 1350 | break; |
| 1351 | } |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 1352 | status = QdcmCMDHandler(input_parcel, output_parcel); |
| 1353 | break; |
| 1354 | |
Dileep Marchya | 6860b2b | 2017-04-07 15:56:47 +0530 | [diff] [blame] | 1355 | case qService::IQService::MIN_HDCP_ENCRYPTION_LEVEL_CHANGED: { |
Mathew Joseph Karimpanal | dbd64f8 | 2017-10-06 10:13:38 +0530 | [diff] [blame] | 1356 | if (!input_parcel || !output_parcel) { |
| 1357 | DLOGE("QService command = %d: input_parcel and output_parcel needed.", command); |
| 1358 | break; |
| 1359 | } |
Dileep Marchya | 6860b2b | 2017-04-07 15:56:47 +0530 | [diff] [blame] | 1360 | int disp_id = input_parcel->readInt32(); |
| 1361 | uint32_t min_enc_level = UINT32(input_parcel->readInt32()); |
| 1362 | status = MinHdcpEncryptionLevelChanged(disp_id, min_enc_level); |
| 1363 | output_parcel->writeInt32(status); |
| 1364 | } |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 1365 | break; |
| 1366 | |
Dileep Marchya | 6860b2b | 2017-04-07 15:56:47 +0530 | [diff] [blame] | 1367 | case qService::IQService::CONTROL_PARTIAL_UPDATE: { |
Mathew Joseph Karimpanal | dbd64f8 | 2017-10-06 10:13:38 +0530 | [diff] [blame] | 1368 | if (!input_parcel || !output_parcel) { |
| 1369 | DLOGE("QService command = %d: input_parcel and output_parcel needed.", command); |
| 1370 | break; |
| 1371 | } |
Dileep Marchya | 6860b2b | 2017-04-07 15:56:47 +0530 | [diff] [blame] | 1372 | int disp_id = input_parcel->readInt32(); |
| 1373 | uint32_t enable = UINT32(input_parcel->readInt32()); |
| 1374 | status = ControlPartialUpdate(disp_id, enable == 1); |
| 1375 | output_parcel->writeInt32(status); |
| 1376 | } |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 1377 | break; |
| 1378 | |
Dileep Marchya | 6860b2b | 2017-04-07 15:56:47 +0530 | [diff] [blame] | 1379 | case qService::IQService::SET_ACTIVE_CONFIG: { |
Mathew Joseph Karimpanal | dbd64f8 | 2017-10-06 10:13:38 +0530 | [diff] [blame] | 1380 | if (!input_parcel) { |
| 1381 | DLOGE("QService command = %d: input_parcel needed.", command); |
| 1382 | break; |
| 1383 | } |
Dileep Marchya | 6860b2b | 2017-04-07 15:56:47 +0530 | [diff] [blame] | 1384 | uint32_t config = UINT32(input_parcel->readInt32()); |
| 1385 | int disp_id = input_parcel->readInt32(); |
| 1386 | status = SetActiveConfigIndex(disp_id, config); |
| 1387 | } |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 1388 | break; |
| 1389 | |
Dileep Marchya | 6860b2b | 2017-04-07 15:56:47 +0530 | [diff] [blame] | 1390 | case qService::IQService::GET_ACTIVE_CONFIG: { |
Mathew Joseph Karimpanal | dbd64f8 | 2017-10-06 10:13:38 +0530 | [diff] [blame] | 1391 | if (!input_parcel || !output_parcel) { |
| 1392 | DLOGE("QService command = %d: input_parcel and output_parcel needed.", command); |
| 1393 | break; |
| 1394 | } |
Dileep Marchya | 6860b2b | 2017-04-07 15:56:47 +0530 | [diff] [blame] | 1395 | int disp_id = input_parcel->readInt32(); |
| 1396 | uint32_t config = 0; |
| 1397 | status = GetActiveConfigIndex(disp_id, &config); |
| 1398 | output_parcel->writeInt32(INT(config)); |
| 1399 | } |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 1400 | break; |
| 1401 | |
Dileep Marchya | 6860b2b | 2017-04-07 15:56:47 +0530 | [diff] [blame] | 1402 | case qService::IQService::GET_CONFIG_COUNT: { |
Mathew Joseph Karimpanal | dbd64f8 | 2017-10-06 10:13:38 +0530 | [diff] [blame] | 1403 | if (!input_parcel || !output_parcel) { |
| 1404 | DLOGE("QService command = %d: input_parcel and output_parcel needed.", command); |
| 1405 | break; |
| 1406 | } |
Dileep Marchya | 6860b2b | 2017-04-07 15:56:47 +0530 | [diff] [blame] | 1407 | int disp_id = input_parcel->readInt32(); |
| 1408 | uint32_t count = 0; |
| 1409 | status = GetConfigCount(disp_id, &count); |
| 1410 | output_parcel->writeInt32(INT(count)); |
| 1411 | } |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 1412 | break; |
| 1413 | |
| 1414 | case qService::IQService::GET_DISPLAY_ATTRIBUTES_FOR_CONFIG: |
Mathew Joseph Karimpanal | dbd64f8 | 2017-10-06 10:13:38 +0530 | [diff] [blame] | 1415 | if (!input_parcel || !output_parcel) { |
| 1416 | DLOGE("QService command = %d: input_parcel and output_parcel needed.", command); |
| 1417 | break; |
| 1418 | } |
Dileep Marchya | f3ce11f | 2018-04-30 23:35:46 +0530 | [diff] [blame] | 1419 | status = GetDisplayAttributesForConfig(input_parcel, output_parcel); |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 1420 | break; |
| 1421 | |
Dileep Marchya | 6860b2b | 2017-04-07 15:56:47 +0530 | [diff] [blame] | 1422 | case qService::IQService::GET_PANEL_BRIGHTNESS: { |
Mathew Joseph Karimpanal | dbd64f8 | 2017-10-06 10:13:38 +0530 | [diff] [blame] | 1423 | if (!output_parcel) { |
| 1424 | DLOGE("QService command = %d: output_parcel needed.", command); |
| 1425 | break; |
| 1426 | } |
Yuchao Ma | ada1c40 | 2019-11-12 14:47:11 +0800 | [diff] [blame] | 1427 | |
Varun Arora | 75c05f0 | 2019-05-14 14:53:37 -0700 | [diff] [blame] | 1428 | uint32_t display = input_parcel->readUint32(); |
Yuchao Ma | ada1c40 | 2019-11-12 14:47:11 +0800 | [diff] [blame] | 1429 | uint32_t max_brightness_level = 0; |
| 1430 | status = getDisplayMaxBrightness(display, &max_brightness_level); |
| 1431 | if (status || !max_brightness_level) { |
| 1432 | output_parcel->writeInt32(max_brightness_level); |
| 1433 | DLOGE("Failed to get max brightness %u, status %d", max_brightness_level, status); |
| 1434 | break; |
| 1435 | } |
| 1436 | DLOGV("Panel Max brightness is %u", max_brightness_level); |
| 1437 | |
| 1438 | float brightness_precent = -1.0f; |
| 1439 | status = getDisplayBrightness(display, &brightness_precent); |
| 1440 | if (brightness_precent == -1.0f) { |
Varun Arora | 75c05f0 | 2019-05-14 14:53:37 -0700 | [diff] [blame] | 1441 | output_parcel->writeInt32(0); |
| 1442 | } else { |
Yuchao Ma | ada1c40 | 2019-11-12 14:47:11 +0800 | [diff] [blame] | 1443 | output_parcel->writeInt32(INT32(brightness_precent*(max_brightness_level - 1) + 1)); |
Varun Arora | 75c05f0 | 2019-05-14 14:53:37 -0700 | [diff] [blame] | 1444 | } |
Dileep Marchya | 6860b2b | 2017-04-07 15:56:47 +0530 | [diff] [blame] | 1445 | } |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 1446 | break; |
| 1447 | |
Dileep Marchya | 6860b2b | 2017-04-07 15:56:47 +0530 | [diff] [blame] | 1448 | case qService::IQService::SET_PANEL_BRIGHTNESS: { |
Mathew Joseph Karimpanal | dbd64f8 | 2017-10-06 10:13:38 +0530 | [diff] [blame] | 1449 | if (!input_parcel || !output_parcel) { |
| 1450 | DLOGE("QService command = %d: input_parcel and output_parcel needed.", command); |
| 1451 | break; |
| 1452 | } |
Yuchao Ma | ada1c40 | 2019-11-12 14:47:11 +0800 | [diff] [blame] | 1453 | |
| 1454 | uint32_t max_brightness_level = 0; |
| 1455 | uint32_t display = HWC_DISPLAY_PRIMARY; |
| 1456 | status = getDisplayMaxBrightness(display, &max_brightness_level); |
| 1457 | if (status || max_brightness_level <= 1) { |
| 1458 | output_parcel->writeInt32(max_brightness_level); |
| 1459 | DLOGE("Failed to get max brightness %u, status %d", max_brightness_level, status); |
| 1460 | break; |
| 1461 | } |
| 1462 | DLOGV("Panel Max brightness is %u", max_brightness_level); |
| 1463 | |
Varun Arora | 75c05f0 | 2019-05-14 14:53:37 -0700 | [diff] [blame] | 1464 | int level = input_parcel->readInt32(); |
Varun Arora | 75c05f0 | 2019-05-14 14:53:37 -0700 | [diff] [blame] | 1465 | if (level == 0) { |
Yuchao Ma | ada1c40 | 2019-11-12 14:47:11 +0800 | [diff] [blame] | 1466 | status = SetDisplayBrightness(display, -1.0f); |
Varun Arora | 75c05f0 | 2019-05-14 14:53:37 -0700 | [diff] [blame] | 1467 | } else { |
Yuchao Ma | ada1c40 | 2019-11-12 14:47:11 +0800 | [diff] [blame] | 1468 | status = SetDisplayBrightness(display, |
| 1469 | (level - 1)/(static_cast<float>(max_brightness_level - 1))); |
Varun Arora | 75c05f0 | 2019-05-14 14:53:37 -0700 | [diff] [blame] | 1470 | } |
Dileep Marchya | 6860b2b | 2017-04-07 15:56:47 +0530 | [diff] [blame] | 1471 | output_parcel->writeInt32(status); |
| 1472 | } |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 1473 | break; |
| 1474 | |
| 1475 | case qService::IQService::GET_DISPLAY_VISIBLE_REGION: |
Mathew Joseph Karimpanal | dbd64f8 | 2017-10-06 10:13:38 +0530 | [diff] [blame] | 1476 | if (!input_parcel || !output_parcel) { |
| 1477 | DLOGE("QService command = %d: input_parcel and output_parcel needed.", command); |
| 1478 | break; |
| 1479 | } |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 1480 | status = GetVisibleDisplayRect(input_parcel, output_parcel); |
| 1481 | break; |
| 1482 | |
Dileep Marchya | 6860b2b | 2017-04-07 15:56:47 +0530 | [diff] [blame] | 1483 | case qService::IQService::SET_CAMERA_STATUS: { |
Mathew Joseph Karimpanal | dbd64f8 | 2017-10-06 10:13:38 +0530 | [diff] [blame] | 1484 | if (!input_parcel) { |
| 1485 | DLOGE("QService command = %d: input_parcel needed.", command); |
| 1486 | break; |
| 1487 | } |
Dileep Marchya | 6860b2b | 2017-04-07 15:56:47 +0530 | [diff] [blame] | 1488 | uint32_t camera_status = UINT32(input_parcel->readInt32()); |
Padmanabhan Komanduru | 9e97162 | 2020-02-10 13:09:34 +0530 | [diff] [blame] | 1489 | status = SetCameraLaunchStatus(camera_status); |
Dileep Marchya | 6860b2b | 2017-04-07 15:56:47 +0530 | [diff] [blame] | 1490 | } |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 1491 | break; |
| 1492 | |
Dileep Marchya | 6860b2b | 2017-04-07 15:56:47 +0530 | [diff] [blame] | 1493 | case qService::IQService::GET_BW_TRANSACTION_STATUS: { |
Mathew Joseph Karimpanal | dbd64f8 | 2017-10-06 10:13:38 +0530 | [diff] [blame] | 1494 | if (!output_parcel) { |
| 1495 | DLOGE("QService command = %d: output_parcel needed.", command); |
| 1496 | break; |
| 1497 | } |
Dileep Marchya | 6860b2b | 2017-04-07 15:56:47 +0530 | [diff] [blame] | 1498 | bool state = true; |
| 1499 | status = DisplayBWTransactionPending(&state); |
| 1500 | output_parcel->writeInt32(state); |
| 1501 | } |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 1502 | break; |
| 1503 | |
Naseer Ahmed | ad49544 | 2016-06-27 14:59:18 -0400 | [diff] [blame] | 1504 | case qService::IQService::SET_LAYER_MIXER_RESOLUTION: |
Mathew Joseph Karimpanal | dbd64f8 | 2017-10-06 10:13:38 +0530 | [diff] [blame] | 1505 | if (!input_parcel) { |
| 1506 | DLOGE("QService command = %d: input_parcel needed.", command); |
| 1507 | break; |
| 1508 | } |
Naseer Ahmed | ad49544 | 2016-06-27 14:59:18 -0400 | [diff] [blame] | 1509 | status = SetMixerResolution(input_parcel); |
| 1510 | break; |
| 1511 | |
| 1512 | case qService::IQService::SET_COLOR_MODE: |
Mathew Joseph Karimpanal | dbd64f8 | 2017-10-06 10:13:38 +0530 | [diff] [blame] | 1513 | if (!input_parcel) { |
| 1514 | DLOGE("QService command = %d: input_parcel needed.", command); |
| 1515 | break; |
| 1516 | } |
Naseer Ahmed | ad49544 | 2016-06-27 14:59:18 -0400 | [diff] [blame] | 1517 | status = SetColorModeOverride(input_parcel); |
| 1518 | break; |
Arun Kumar K.R | 8da7f50 | 2016-06-07 17:45:50 -0700 | [diff] [blame] | 1519 | |
Naseer Ahmed | e7a7798 | 2018-06-04 10:56:04 -0400 | [diff] [blame] | 1520 | case qService::IQService::SET_COLOR_MODE_WITH_RENDER_INTENT: |
| 1521 | if (!input_parcel) { |
| 1522 | DLOGE("QService command = %d: input_parcel needed.", command); |
| 1523 | break; |
| 1524 | } |
| 1525 | status = SetColorModeWithRenderIntentOverride(input_parcel); |
| 1526 | break; |
| 1527 | |
Naseer Ahmed | 6776dae | 2017-05-09 11:49:41 -0400 | [diff] [blame] | 1528 | case qService::IQService::SET_COLOR_MODE_BY_ID: |
Mathew Joseph Karimpanal | dbd64f8 | 2017-10-06 10:13:38 +0530 | [diff] [blame] | 1529 | if (!input_parcel) { |
| 1530 | DLOGE("QService command = %d: input_parcel needed.", command); |
| 1531 | break; |
| 1532 | } |
Naseer Ahmed | 6776dae | 2017-05-09 11:49:41 -0400 | [diff] [blame] | 1533 | status = SetColorModeById(input_parcel); |
| 1534 | break; |
| 1535 | |
Prabhanjan Kandula | 63a613f | 2017-09-14 19:29:46 -0700 | [diff] [blame] | 1536 | case qService::IQService::GET_COMPOSER_STATUS: |
Mathew Joseph Karimpanal | dbd64f8 | 2017-10-06 10:13:38 +0530 | [diff] [blame] | 1537 | if (!output_parcel) { |
| 1538 | DLOGE("QService command = %d: output_parcel needed.", command); |
| 1539 | break; |
| 1540 | } |
| 1541 | status = 0; |
Prabhanjan Kandula | 63a613f | 2017-09-14 19:29:46 -0700 | [diff] [blame] | 1542 | output_parcel->writeInt32(getComposerStatus()); |
| 1543 | break; |
| 1544 | |
Sushil Chauhan | 380a59d | 2018-03-19 15:47:50 -0700 | [diff] [blame] | 1545 | case qService::IQService::SET_QSYNC_MODE: |
| 1546 | if (!input_parcel) { |
| 1547 | DLOGE("QService command = %d: input_parcel needed.", command); |
| 1548 | break; |
| 1549 | } |
| 1550 | status = SetQSyncMode(input_parcel); |
| 1551 | break; |
| 1552 | |
Lakshmi Narayana Kalavala | 25fe12c | 2019-12-11 20:44:55 -0800 | [diff] [blame] | 1553 | case qService::IQService::SET_COLOR_SAMPLING_ENABLED: |
| 1554 | if (!input_parcel) { |
| 1555 | DLOGE("QService command = %d: input_parcel needed.", command); |
| 1556 | break; |
| 1557 | } |
| 1558 | status = setColorSamplingEnabled(input_parcel); |
| 1559 | break; |
| 1560 | |
Ramkumar Radhakrishnan | f985d48 | 2018-07-23 18:10:41 -0700 | [diff] [blame] | 1561 | case qService::IQService::SET_IDLE_PC: |
| 1562 | if (!input_parcel) { |
| 1563 | DLOGE("QService command = %d: input_parcel needed.", command); |
| 1564 | break; |
| 1565 | } |
| 1566 | status = SetIdlePC(input_parcel); |
| 1567 | break; |
| 1568 | |
Yuchao Ma | 577f0f7 | 2018-07-09 11:20:00 +0800 | [diff] [blame] | 1569 | case qService::IQService::SET_DPPS_AD4_ROI_CONFIG: |
| 1570 | if (!input_parcel) { |
| 1571 | DLOGE("QService command = %d: input_parcel needed.", command); |
| 1572 | break; |
| 1573 | } |
| 1574 | status = SetAd4RoiConfig(input_parcel); |
| 1575 | break; |
| 1576 | |
Pullakavi Srinivas | 9189e60 | 2018-12-19 16:58:07 +0530 | [diff] [blame] | 1577 | case qService::IQService::SET_DSI_CLK: |
| 1578 | if (!input_parcel) { |
| 1579 | DLOGE("QService command = %d: input_parcel needed.", command); |
| 1580 | break; |
| 1581 | } |
| 1582 | status = SetDsiClk(input_parcel); |
| 1583 | break; |
| 1584 | |
| 1585 | case qService::IQService::GET_DSI_CLK: |
| 1586 | if (!input_parcel || !output_parcel) { |
| 1587 | DLOGE("QService command = %d: input_parcel and output_parcel needed.", command); |
| 1588 | break; |
| 1589 | } |
| 1590 | status = GetDsiClk(input_parcel, output_parcel); |
| 1591 | break; |
| 1592 | |
| 1593 | case qService::IQService::GET_SUPPORTED_DSI_CLK: |
| 1594 | if (!input_parcel || !output_parcel) { |
| 1595 | DLOGE("QService command = %d: input_parcel and output_parcel needed.", command); |
| 1596 | break; |
| 1597 | } |
| 1598 | status = GetSupportedDsiClk(input_parcel, output_parcel); |
| 1599 | break; |
| 1600 | |
Archit Srivastava | a59c4ff | 2019-05-20 10:54:22 +0530 | [diff] [blame] | 1601 | case qService::IQService::SET_PANEL_LUMINANCE: |
| 1602 | if (!input_parcel) { |
| 1603 | DLOGE("QService command = %d: input_parcel needed.", command); |
| 1604 | break; |
| 1605 | } |
| 1606 | status = SetPanelLuminanceAttributes(input_parcel); |
| 1607 | break; |
| 1608 | |
Qing Huang | da3a91d | 2019-01-15 14:34:11 +0800 | [diff] [blame] | 1609 | case qService::IQService::SET_COLOR_MODE_FROM_CLIENT: |
| 1610 | if (!input_parcel) { |
| 1611 | DLOGE("QService command = %d: input_parcel needed.", command); |
| 1612 | break; |
| 1613 | } |
| 1614 | status = SetColorModeFromClient(input_parcel); |
| 1615 | break; |
| 1616 | |
Xu Yang | 9dacc87 | 2018-12-25 11:04:28 +0800 | [diff] [blame] | 1617 | case qService::IQService::SET_FRAME_TRIGGER_MODE: |
| 1618 | if (!input_parcel) { |
| 1619 | DLOGE("QService command = %d: input_parcel needed.", command); |
| 1620 | break; |
| 1621 | } |
| 1622 | status = SetFrameTriggerMode(input_parcel); |
| 1623 | break; |
| 1624 | |
Xu Yang | 45d0abf | 2019-07-05 11:34:06 +0800 | [diff] [blame] | 1625 | case qService::IQService::SET_BRIGHTNESS_SCALE: |
| 1626 | if (!input_parcel) { |
| 1627 | DLOGE("QService command = %d: input_parcel needed.", command); |
| 1628 | break; |
| 1629 | } |
| 1630 | status = SetDisplayBrightnessScale(input_parcel); |
| 1631 | break; |
| 1632 | |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 1633 | default: |
Mathew Joseph Karimpanal | dbd64f8 | 2017-10-06 10:13:38 +0530 | [diff] [blame] | 1634 | DLOGW("QService command = %d is not supported.", command); |
| 1635 | break; |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 1636 | } |
| 1637 | |
| 1638 | return status; |
| 1639 | } |
| 1640 | |
Prabhanjan Kandula | 63a613f | 2017-09-14 19:29:46 -0700 | [diff] [blame] | 1641 | android::status_t HWCSession::getComposerStatus() { |
| 1642 | return is_composer_up_; |
| 1643 | } |
| 1644 | |
Dileep Marchya | f3ce11f | 2018-04-30 23:35:46 +0530 | [diff] [blame] | 1645 | android::status_t HWCSession::GetDisplayAttributesForConfig(const android::Parcel *input_parcel, |
| 1646 | android::Parcel *output_parcel) { |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 1647 | int config = input_parcel->readInt32(); |
| 1648 | int dpy = input_parcel->readInt32(); |
| 1649 | int error = android::BAD_VALUE; |
Arun Kumar K.R | 8da7f50 | 2016-06-07 17:45:50 -0700 | [diff] [blame] | 1650 | DisplayConfigVariableInfo display_attributes; |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 1651 | |
Dileep Marchya | f3ce11f | 2018-04-30 23:35:46 +0530 | [diff] [blame] | 1652 | int disp_idx = GetDisplayIndex(dpy); |
| 1653 | if (disp_idx == -1 || config < 0) { |
| 1654 | DLOGE("Invalid display = %d, or config = %d", dpy, config); |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 1655 | return android::BAD_VALUE; |
| 1656 | } |
| 1657 | |
Dileep Marchya | f3ce11f | 2018-04-30 23:35:46 +0530 | [diff] [blame] | 1658 | SEQUENCE_WAIT_SCOPE_LOCK(locker_[disp_idx]); |
| 1659 | if (hwc_display_[disp_idx]) { |
| 1660 | error = hwc_display_[disp_idx]->GetDisplayAttributesForConfig(config, &display_attributes); |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 1661 | if (error == 0) { |
Arun Kumar K.R | 8da7f50 | 2016-06-07 17:45:50 -0700 | [diff] [blame] | 1662 | output_parcel->writeInt32(INT(display_attributes.vsync_period_ns)); |
| 1663 | output_parcel->writeInt32(INT(display_attributes.x_pixels)); |
| 1664 | output_parcel->writeInt32(INT(display_attributes.y_pixels)); |
| 1665 | output_parcel->writeFloat(display_attributes.x_dpi); |
| 1666 | output_parcel->writeFloat(display_attributes.y_dpi); |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 1667 | output_parcel->writeInt32(0); // Panel type, unsupported. |
| 1668 | } |
| 1669 | } |
| 1670 | |
| 1671 | return error; |
| 1672 | } |
| 1673 | |
Lakshmi Narayana Kalavala | 25fe12c | 2019-12-11 20:44:55 -0800 | [diff] [blame] | 1674 | android::status_t HWCSession::setColorSamplingEnabled(const android::Parcel *input_parcel) { |
| 1675 | int dpy = input_parcel->readInt32(); |
| 1676 | int enabled_cmd = input_parcel->readInt32(); |
| 1677 | if (dpy < HWC_DISPLAY_PRIMARY || dpy >= HWC_NUM_DISPLAY_TYPES || enabled_cmd < 0 || |
| 1678 | enabled_cmd > 1) { |
| 1679 | return android::BAD_VALUE; |
| 1680 | } |
| 1681 | |
| 1682 | SEQUENCE_WAIT_SCOPE_LOCK(locker_[dpy]); |
| 1683 | if (!hwc_display_[dpy]) { |
| 1684 | DLOGW("No display id %i active to enable histogram event", dpy); |
| 1685 | return android::BAD_VALUE; |
| 1686 | } |
| 1687 | |
| 1688 | auto error = hwc_display_[dpy]->SetDisplayedContentSamplingEnabledVndService(enabled_cmd); |
| 1689 | return (error == HWC2::Error::None) ? android::OK : android::BAD_VALUE; |
| 1690 | } |
| 1691 | |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 1692 | android::status_t HWCSession::ConfigureRefreshRate(const android::Parcel *input_parcel) { |
Saurabh Shah | c5c687a | 2017-08-24 16:30:14 -0700 | [diff] [blame] | 1693 | SEQUENCE_WAIT_SCOPE_LOCK(locker_[HWC_DISPLAY_PRIMARY]); |
Dileep Marchya | 6860b2b | 2017-04-07 15:56:47 +0530 | [diff] [blame] | 1694 | |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 1695 | uint32_t operation = UINT32(input_parcel->readInt32()); |
Dileep Marchya | 6860b2b | 2017-04-07 15:56:47 +0530 | [diff] [blame] | 1696 | HWCDisplay *hwc_display = hwc_display_[HWC_DISPLAY_PRIMARY]; |
| 1697 | |
Mathew Joseph Karimpanal | dbd64f8 | 2017-10-06 10:13:38 +0530 | [diff] [blame] | 1698 | if (!hwc_display) { |
| 1699 | DLOGW("Display = %d is not connected.", HWC_DISPLAY_PRIMARY); |
| 1700 | return -ENODEV; |
| 1701 | } |
| 1702 | |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 1703 | switch (operation) { |
| 1704 | case qdutils::DISABLE_METADATA_DYN_REFRESH_RATE: |
Dileep Marchya | f3ce11f | 2018-04-30 23:35:46 +0530 | [diff] [blame] | 1705 | return hwc_display->Perform(HWCDisplayBuiltIn::SET_METADATA_DYN_REFRESH_RATE, false); |
Dileep Marchya | 6860b2b | 2017-04-07 15:56:47 +0530 | [diff] [blame] | 1706 | |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 1707 | case qdutils::ENABLE_METADATA_DYN_REFRESH_RATE: |
Dileep Marchya | f3ce11f | 2018-04-30 23:35:46 +0530 | [diff] [blame] | 1708 | return hwc_display->Perform(HWCDisplayBuiltIn::SET_METADATA_DYN_REFRESH_RATE, true); |
Dileep Marchya | 6860b2b | 2017-04-07 15:56:47 +0530 | [diff] [blame] | 1709 | |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 1710 | case qdutils::SET_BINDER_DYN_REFRESH_RATE: { |
| 1711 | uint32_t refresh_rate = UINT32(input_parcel->readInt32()); |
Dileep Marchya | f3ce11f | 2018-04-30 23:35:46 +0530 | [diff] [blame] | 1712 | return hwc_display->Perform(HWCDisplayBuiltIn::SET_BINDER_DYN_REFRESH_RATE, refresh_rate); |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 1713 | } |
Dileep Marchya | 6860b2b | 2017-04-07 15:56:47 +0530 | [diff] [blame] | 1714 | |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 1715 | default: |
| 1716 | DLOGW("Invalid operation %d", operation); |
| 1717 | return -EINVAL; |
| 1718 | } |
| 1719 | |
| 1720 | return 0; |
| 1721 | } |
| 1722 | |
| 1723 | android::status_t HWCSession::SetDisplayMode(const android::Parcel *input_parcel) { |
Saurabh Shah | c5c687a | 2017-08-24 16:30:14 -0700 | [diff] [blame] | 1724 | SEQUENCE_WAIT_SCOPE_LOCK(locker_[HWC_DISPLAY_PRIMARY]); |
Dileep Marchya | 6860b2b | 2017-04-07 15:56:47 +0530 | [diff] [blame] | 1725 | |
Mathew Joseph Karimpanal | dbd64f8 | 2017-10-06 10:13:38 +0530 | [diff] [blame] | 1726 | if (!hwc_display_[HWC_DISPLAY_PRIMARY]) { |
| 1727 | DLOGW("Display = %d is not connected.", HWC_DISPLAY_PRIMARY); |
| 1728 | return -ENODEV; |
| 1729 | } |
| 1730 | |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 1731 | uint32_t mode = UINT32(input_parcel->readInt32()); |
Dileep Marchya | f3ce11f | 2018-04-30 23:35:46 +0530 | [diff] [blame] | 1732 | return hwc_display_[HWC_DISPLAY_PRIMARY]->Perform(HWCDisplayBuiltIn::SET_DISPLAY_MODE, mode); |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 1733 | } |
| 1734 | |
| 1735 | android::status_t HWCSession::SetMaxMixerStages(const android::Parcel *input_parcel) { |
| 1736 | DisplayError error = kErrorNone; |
Dileep Marchya | 7290bd2 | 2016-06-09 11:37:20 +0530 | [diff] [blame] | 1737 | std::bitset<32> bit_mask_display_type = UINT32(input_parcel->readInt32()); |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 1738 | uint32_t max_mixer_stages = UINT32(input_parcel->readInt32()); |
Mathew Joseph Karimpanal | dbd64f8 | 2017-10-06 10:13:38 +0530 | [diff] [blame] | 1739 | android::status_t status = 0; |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 1740 | |
Dileep Marchya | f3ce11f | 2018-04-30 23:35:46 +0530 | [diff] [blame] | 1741 | for (uint32_t i = 0; i < 32 && bit_mask_display_type[i]; i++) { |
| 1742 | int disp_idx = GetDisplayIndex(INT(i)); |
| 1743 | if (disp_idx == -1) { |
| 1744 | continue; |
| 1745 | } |
| 1746 | SEQUENCE_WAIT_SCOPE_LOCK(locker_[disp_idx]); |
| 1747 | auto &hwc_display = hwc_display_[disp_idx]; |
| 1748 | if (!hwc_display) { |
| 1749 | DLOGW("Display = %d is not connected.", disp_idx); |
| 1750 | status = (status)? status : -ENODEV; // Return higher priority error. |
| 1751 | continue; |
| 1752 | } |
| 1753 | |
| 1754 | error = hwc_display->SetMaxMixerStages(max_mixer_stages); |
| 1755 | if (error != kErrorNone) { |
| 1756 | status = -EINVAL; |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 1757 | } |
| 1758 | } |
| 1759 | |
Mathew Joseph Karimpanal | dbd64f8 | 2017-10-06 10:13:38 +0530 | [diff] [blame] | 1760 | return status; |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 1761 | } |
| 1762 | |
Mathew Joseph Karimpanal | dbd64f8 | 2017-10-06 10:13:38 +0530 | [diff] [blame] | 1763 | android::status_t HWCSession::SetFrameDumpConfig(const android::Parcel *input_parcel) { |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 1764 | uint32_t frame_dump_count = UINT32(input_parcel->readInt32()); |
Dileep Marchya | 7290bd2 | 2016-06-09 11:37:20 +0530 | [diff] [blame] | 1765 | std::bitset<32> bit_mask_display_type = UINT32(input_parcel->readInt32()); |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 1766 | uint32_t bit_mask_layer_type = UINT32(input_parcel->readInt32()); |
Sushil Chauhan | 267a619 | 2018-06-06 18:41:47 -0700 | [diff] [blame] | 1767 | int32_t output_format = HAL_PIXEL_FORMAT_RGB_888; |
| 1768 | bool post_processed = true; |
| 1769 | |
Sushil Chauhan | 0a1b15d | 2019-08-23 12:58:18 -0700 | [diff] [blame] | 1770 | // Output buffer dump is not supported, if External or Virtual display is present. |
| 1771 | bool output_buffer_dump = bit_mask_layer_type & (1 << OUTPUT_LAYER_DUMP); |
| 1772 | if (output_buffer_dump) { |
| 1773 | int external_dpy_index = GetDisplayIndex(qdutils::DISPLAY_EXTERNAL); |
| 1774 | int virtual_dpy_index = GetDisplayIndex(qdutils::DISPLAY_VIRTUAL); |
| 1775 | if (((external_dpy_index != -1) && hwc_display_[external_dpy_index]) || |
| 1776 | ((virtual_dpy_index != -1) && hwc_display_[virtual_dpy_index])) { |
| 1777 | DLOGW("Output buffer dump is not supported with External or Virtual display!"); |
| 1778 | return -EINVAL; |
| 1779 | } |
| 1780 | } |
| 1781 | |
Sushil Chauhan | 267a619 | 2018-06-06 18:41:47 -0700 | [diff] [blame] | 1782 | // Read optional user preferences: output_format and post_processed. |
| 1783 | if (input_parcel->dataPosition() != input_parcel->dataSize()) { |
| 1784 | // HAL Pixel Format for output buffer |
| 1785 | output_format = input_parcel->readInt32(); |
| 1786 | } |
| 1787 | if (input_parcel->dataPosition() != input_parcel->dataSize()) { |
| 1788 | // Option to dump Layer Mixer output (0) or DSPP output (1) |
| 1789 | post_processed = (input_parcel->readInt32() != 0); |
| 1790 | } |
| 1791 | |
Mathew Joseph Karimpanal | dbd64f8 | 2017-10-06 10:13:38 +0530 | [diff] [blame] | 1792 | android::status_t status = 0; |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 1793 | |
Mathew Joseph Karimpanal | 0a2fff5 | 2018-10-17 12:11:07 +0530 | [diff] [blame] | 1794 | for (uint32_t i = 0; i < bit_mask_display_type.size(); i++) { |
| 1795 | if (!bit_mask_display_type[i]) { |
| 1796 | continue; |
| 1797 | } |
Dileep Marchya | f3ce11f | 2018-04-30 23:35:46 +0530 | [diff] [blame] | 1798 | int disp_idx = GetDisplayIndex(INT(i)); |
| 1799 | if (disp_idx == -1) { |
| 1800 | continue; |
| 1801 | } |
| 1802 | SEQUENCE_WAIT_SCOPE_LOCK(locker_[disp_idx]); |
| 1803 | auto &hwc_display = hwc_display_[disp_idx]; |
| 1804 | if (!hwc_display) { |
| 1805 | DLOGW("Display = %d is not connected.", disp_idx); |
| 1806 | status = (status)? status : -ENODEV; // Return higher priority error. |
| 1807 | continue; |
| 1808 | } |
| 1809 | |
Sushil Chauhan | 267a619 | 2018-06-06 18:41:47 -0700 | [diff] [blame] | 1810 | HWC2::Error error = hwc_display->SetFrameDumpConfig(frame_dump_count, bit_mask_layer_type, |
| 1811 | output_format, post_processed); |
Dileep Marchya | f3ce11f | 2018-04-30 23:35:46 +0530 | [diff] [blame] | 1812 | if (error != HWC2::Error::None) { |
| 1813 | status = (HWC2::Error::NoResources == error) ? -ENOMEM : -EINVAL; |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 1814 | } |
| 1815 | } |
| 1816 | |
Mathew Joseph Karimpanal | dbd64f8 | 2017-10-06 10:13:38 +0530 | [diff] [blame] | 1817 | return status; |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 1818 | } |
| 1819 | |
Arun Kumar K.R | 8da7f50 | 2016-06-07 17:45:50 -0700 | [diff] [blame] | 1820 | android::status_t HWCSession::SetMixerResolution(const android::Parcel *input_parcel) { |
| 1821 | DisplayError error = kErrorNone; |
| 1822 | uint32_t dpy = UINT32(input_parcel->readInt32()); |
| 1823 | |
| 1824 | if (dpy != HWC_DISPLAY_PRIMARY) { |
Mathew Joseph Karimpanal | dbd64f8 | 2017-10-06 10:13:38 +0530 | [diff] [blame] | 1825 | DLOGW("Resolution change not supported for this display = %d", dpy); |
Arun Kumar K.R | 8da7f50 | 2016-06-07 17:45:50 -0700 | [diff] [blame] | 1826 | return -EINVAL; |
| 1827 | } |
| 1828 | |
Saurabh Shah | c5c687a | 2017-08-24 16:30:14 -0700 | [diff] [blame] | 1829 | SEQUENCE_WAIT_SCOPE_LOCK(locker_[HWC_DISPLAY_PRIMARY]); |
Arun Kumar K.R | 8da7f50 | 2016-06-07 17:45:50 -0700 | [diff] [blame] | 1830 | if (!hwc_display_[HWC_DISPLAY_PRIMARY]) { |
Mathew Joseph Karimpanal | dbd64f8 | 2017-10-06 10:13:38 +0530 | [diff] [blame] | 1831 | DLOGW("Primary display is not initialized"); |
| 1832 | return -ENODEV; |
Arun Kumar K.R | 8da7f50 | 2016-06-07 17:45:50 -0700 | [diff] [blame] | 1833 | } |
| 1834 | |
| 1835 | uint32_t width = UINT32(input_parcel->readInt32()); |
| 1836 | uint32_t height = UINT32(input_parcel->readInt32()); |
| 1837 | |
| 1838 | error = hwc_display_[HWC_DISPLAY_PRIMARY]->SetMixerResolution(width, height); |
| 1839 | if (error != kErrorNone) { |
| 1840 | return -EINVAL; |
| 1841 | } |
| 1842 | |
| 1843 | return 0; |
| 1844 | } |
| 1845 | |
Naseer Ahmed | ad49544 | 2016-06-27 14:59:18 -0400 | [diff] [blame] | 1846 | android::status_t HWCSession::SetColorModeOverride(const android::Parcel *input_parcel) { |
Dileep Marchya | f3ce11f | 2018-04-30 23:35:46 +0530 | [diff] [blame] | 1847 | int display = static_cast<int>(input_parcel->readInt32()); |
Naseer Ahmed | e7a7798 | 2018-06-04 10:56:04 -0400 | [diff] [blame] | 1848 | auto mode = static_cast<ColorMode>(input_parcel->readInt32()); |
Saurabh Shah | c5c687a | 2017-08-24 16:30:14 -0700 | [diff] [blame] | 1849 | |
Dileep Marchya | f3ce11f | 2018-04-30 23:35:46 +0530 | [diff] [blame] | 1850 | int disp_idx = GetDisplayIndex(display); |
| 1851 | if (disp_idx == -1) { |
| 1852 | DLOGE("Invalid display = %d", display); |
| 1853 | return -EINVAL; |
| 1854 | } |
| 1855 | |
Gousemoodhin Nadaf | 0e56687 | 2019-05-13 16:14:54 +0530 | [diff] [blame] | 1856 | if (mode < ColorMode::NATIVE || mode > ColorMode::DISPLAY_BT2020) { |
Gurpreet Singh Dhami | ec0fa51 | 2018-08-29 16:51:26 -0400 | [diff] [blame] | 1857 | DLOGE("Invalid ColorMode: %d", mode); |
| 1858 | return HWC2_ERROR_BAD_PARAMETER; |
| 1859 | } |
Rajavenu Kyatham | 42d11cb | 2019-04-16 13:03:29 +0530 | [diff] [blame] | 1860 | auto err = CallDisplayFunction(static_cast<hwc2_display_t>(disp_idx), &HWCDisplay::SetColorMode, |
| 1861 | mode); |
Naseer Ahmed | ad49544 | 2016-06-27 14:59:18 -0400 | [diff] [blame] | 1862 | if (err != HWC2_ERROR_NONE) |
| 1863 | return -EINVAL; |
Saurabh Shah | 04f932b | 2017-10-12 18:47:45 -0700 | [diff] [blame] | 1864 | |
Naseer Ahmed | ad49544 | 2016-06-27 14:59:18 -0400 | [diff] [blame] | 1865 | return 0; |
| 1866 | } |
| 1867 | |
Yuchao Ma | 577f0f7 | 2018-07-09 11:20:00 +0800 | [diff] [blame] | 1868 | android::status_t HWCSession::SetAd4RoiConfig(const android::Parcel *input_parcel) { |
| 1869 | auto display_id = static_cast<uint32_t>(input_parcel->readInt32()); |
| 1870 | auto h_s = static_cast<uint32_t>(input_parcel->readInt32()); |
| 1871 | auto h_e = static_cast<uint32_t>(input_parcel->readInt32()); |
| 1872 | auto v_s = static_cast<uint32_t>(input_parcel->readInt32()); |
| 1873 | auto v_e = static_cast<uint32_t>(input_parcel->readInt32()); |
| 1874 | auto f_in = static_cast<uint32_t>(input_parcel->readInt32()); |
| 1875 | auto f_out = static_cast<uint32_t>(input_parcel->readInt32()); |
| 1876 | |
Padmanabhan Komanduru | 9e97162 | 2020-02-10 13:09:34 +0530 | [diff] [blame] | 1877 | return static_cast<android::status_t>(SetDisplayDppsAdROI(display_id, h_s, h_e, v_s, |
| 1878 | v_e, f_in, f_out)); |
Yuchao Ma | 577f0f7 | 2018-07-09 11:20:00 +0800 | [diff] [blame] | 1879 | } |
| 1880 | |
Xu Yang | 9dacc87 | 2018-12-25 11:04:28 +0800 | [diff] [blame] | 1881 | android::status_t HWCSession::SetFrameTriggerMode(const android::Parcel *input_parcel) { |
| 1882 | auto display_id = static_cast<int>(input_parcel->readInt32()); |
| 1883 | auto mode = static_cast<uint32_t>(input_parcel->readInt32()); |
| 1884 | |
| 1885 | int disp_idx = GetDisplayIndex(display_id); |
| 1886 | if (disp_idx == -1) { |
| 1887 | DLOGE("Invalid display = %d", display_id); |
| 1888 | return -EINVAL; |
| 1889 | } |
| 1890 | |
Rajavenu Kyatham | 42d11cb | 2019-04-16 13:03:29 +0530 | [diff] [blame] | 1891 | auto err = CallDisplayFunction(static_cast<hwc2_display_t>(disp_idx), |
Xu Yang | 9dacc87 | 2018-12-25 11:04:28 +0800 | [diff] [blame] | 1892 | &HWCDisplay::SetFrameTriggerMode, mode); |
| 1893 | if (err != HWC2_ERROR_NONE) |
| 1894 | return -EINVAL; |
| 1895 | |
| 1896 | return 0; |
| 1897 | } |
| 1898 | |
Naseer Ahmed | e7a7798 | 2018-06-04 10:56:04 -0400 | [diff] [blame] | 1899 | android::status_t HWCSession::SetColorModeWithRenderIntentOverride( |
| 1900 | const android::Parcel *input_parcel) { |
| 1901 | auto display = static_cast<hwc2_display_t>(input_parcel->readInt32()); |
| 1902 | auto mode = static_cast<ColorMode>(input_parcel->readInt32()); |
Xu Yang | 47f4409 | 2019-02-13 14:09:53 +0800 | [diff] [blame] | 1903 | auto int_intent = static_cast<int>(input_parcel->readInt32()); |
Naseer Ahmed | e7a7798 | 2018-06-04 10:56:04 -0400 | [diff] [blame] | 1904 | |
Gousemoodhin Nadaf | 0e56687 | 2019-05-13 16:14:54 +0530 | [diff] [blame] | 1905 | if (mode < ColorMode::NATIVE || mode > ColorMode::DISPLAY_BT2020) { |
Gurpreet Singh Dhami | ec0fa51 | 2018-08-29 16:51:26 -0400 | [diff] [blame] | 1906 | DLOGE("Invalid ColorMode: %d", mode); |
| 1907 | return HWC2_ERROR_BAD_PARAMETER; |
| 1908 | } |
| 1909 | |
Xu Yang | 47f4409 | 2019-02-13 14:09:53 +0800 | [diff] [blame] | 1910 | if ((int_intent < 0) || (int_intent > MAX_EXTENDED_RENDER_INTENT)) { |
| 1911 | DLOGE("Invalid RenderIntent: %d", int_intent); |
Gurpreet Singh Dhami | ec0fa51 | 2018-08-29 16:51:26 -0400 | [diff] [blame] | 1912 | return HWC2_ERROR_BAD_PARAMETER; |
| 1913 | } |
| 1914 | |
Xu Yang | 47f4409 | 2019-02-13 14:09:53 +0800 | [diff] [blame] | 1915 | auto intent = static_cast<RenderIntent>(int_intent); |
Naseer Ahmed | e7a7798 | 2018-06-04 10:56:04 -0400 | [diff] [blame] | 1916 | auto err = |
Rajavenu Kyatham | 42d11cb | 2019-04-16 13:03:29 +0530 | [diff] [blame] | 1917 | CallDisplayFunction(display, &HWCDisplay::SetColorModeWithRenderIntent, mode, intent); |
Naseer Ahmed | e7a7798 | 2018-06-04 10:56:04 -0400 | [diff] [blame] | 1918 | if (err != HWC2_ERROR_NONE) |
| 1919 | return -EINVAL; |
| 1920 | |
| 1921 | return 0; |
| 1922 | } |
Naseer Ahmed | 6776dae | 2017-05-09 11:49:41 -0400 | [diff] [blame] | 1923 | android::status_t HWCSession::SetColorModeById(const android::Parcel *input_parcel) { |
Dileep Marchya | 35e2753 | 2018-06-29 10:50:16 +0530 | [diff] [blame] | 1924 | int display = input_parcel->readInt32(); |
Naseer Ahmed | 6776dae | 2017-05-09 11:49:41 -0400 | [diff] [blame] | 1925 | auto mode = input_parcel->readInt32(); |
Naseer Ahmed | ab76820 | 2017-07-20 12:20:27 -0400 | [diff] [blame] | 1926 | |
Dileep Marchya | f3ce11f | 2018-04-30 23:35:46 +0530 | [diff] [blame] | 1927 | int disp_idx = GetDisplayIndex(display); |
| 1928 | if (disp_idx == -1) { |
| 1929 | DLOGE("Invalid display = %d", display); |
| 1930 | return -EINVAL; |
| 1931 | } |
| 1932 | |
Rajavenu Kyatham | 42d11cb | 2019-04-16 13:03:29 +0530 | [diff] [blame] | 1933 | auto err = CallDisplayFunction(static_cast<hwc2_display_t>(disp_idx), |
Dileep Marchya | f3ce11f | 2018-04-30 23:35:46 +0530 | [diff] [blame] | 1934 | &HWCDisplay::SetColorModeById, mode); |
Naseer Ahmed | 6776dae | 2017-05-09 11:49:41 -0400 | [diff] [blame] | 1935 | if (err != HWC2_ERROR_NONE) |
| 1936 | return -EINVAL; |
Saurabh Shah | 04f932b | 2017-10-12 18:47:45 -0700 | [diff] [blame] | 1937 | |
Naseer Ahmed | 6776dae | 2017-05-09 11:49:41 -0400 | [diff] [blame] | 1938 | return 0; |
| 1939 | } |
| 1940 | |
Qing Huang | da3a91d | 2019-01-15 14:34:11 +0800 | [diff] [blame] | 1941 | android::status_t HWCSession::SetColorModeFromClient(const android::Parcel *input_parcel) { |
| 1942 | int display = input_parcel->readInt32(); |
| 1943 | auto mode = input_parcel->readInt32(); |
Qing Huang | da3a91d | 2019-01-15 14:34:11 +0800 | [diff] [blame] | 1944 | |
| 1945 | int disp_idx = GetDisplayIndex(display); |
| 1946 | if (disp_idx == -1) { |
| 1947 | DLOGE("Invalid display = %d", display); |
| 1948 | return -EINVAL; |
| 1949 | } |
| 1950 | |
Rajavenu Kyatham | 42d11cb | 2019-04-16 13:03:29 +0530 | [diff] [blame] | 1951 | auto err = CallDisplayFunction(static_cast<hwc2_display_t>(disp_idx), |
Qing Huang | da3a91d | 2019-01-15 14:34:11 +0800 | [diff] [blame] | 1952 | &HWCDisplay::SetColorModeFromClientApi, mode); |
| 1953 | if (err != HWC2_ERROR_NONE) |
| 1954 | return -EINVAL; |
| 1955 | |
Varun Arora | dff7d8d | 2019-08-05 18:12:43 -0700 | [diff] [blame] | 1956 | callbacks_.Refresh(static_cast<hwc2_display_t>(disp_idx)); |
Qing Huang | da3a91d | 2019-01-15 14:34:11 +0800 | [diff] [blame] | 1957 | |
| 1958 | return 0; |
| 1959 | } |
| 1960 | |
Dileep Marchya | 35e2753 | 2018-06-29 10:50:16 +0530 | [diff] [blame] | 1961 | android::status_t HWCSession::RefreshScreen(const android::Parcel *input_parcel) { |
| 1962 | int display = input_parcel->readInt32(); |
| 1963 | |
| 1964 | int disp_idx = GetDisplayIndex(display); |
| 1965 | if (disp_idx == -1) { |
| 1966 | DLOGE("Invalid display = %d", display); |
| 1967 | return -EINVAL; |
| 1968 | } |
| 1969 | |
Varun Arora | dff7d8d | 2019-08-05 18:12:43 -0700 | [diff] [blame] | 1970 | callbacks_.Refresh(static_cast<hwc2_display_t>(disp_idx)); |
Dileep Marchya | 35e2753 | 2018-06-29 10:50:16 +0530 | [diff] [blame] | 1971 | |
| 1972 | return 0; |
| 1973 | } |
| 1974 | |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 1975 | void HWCSession::DynamicDebug(const android::Parcel *input_parcel) { |
| 1976 | int type = input_parcel->readInt32(); |
| 1977 | bool enable = (input_parcel->readInt32() > 0); |
| 1978 | DLOGI("type = %d enable = %d", type, enable); |
| 1979 | int verbose_level = input_parcel->readInt32(); |
| 1980 | |
| 1981 | switch (type) { |
| 1982 | case qService::IQService::DEBUG_ALL: |
| 1983 | HWCDebugHandler::DebugAll(enable, verbose_level); |
| 1984 | break; |
| 1985 | |
| 1986 | case qService::IQService::DEBUG_MDPCOMP: |
| 1987 | HWCDebugHandler::DebugStrategy(enable, verbose_level); |
| 1988 | HWCDebugHandler::DebugCompManager(enable, verbose_level); |
| 1989 | break; |
| 1990 | |
| 1991 | case qService::IQService::DEBUG_PIPE_LIFECYCLE: |
| 1992 | HWCDebugHandler::DebugResources(enable, verbose_level); |
Varun Arora | cc301f1 | 2018-12-13 14:32:24 -0800 | [diff] [blame] | 1993 | HWCDebugHandler::DebugQos(enable, verbose_level); |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 1994 | break; |
| 1995 | |
| 1996 | case qService::IQService::DEBUG_DRIVER_CONFIG: |
| 1997 | HWCDebugHandler::DebugDriverConfig(enable, verbose_level); |
| 1998 | break; |
| 1999 | |
| 2000 | case qService::IQService::DEBUG_ROTATOR: |
| 2001 | HWCDebugHandler::DebugResources(enable, verbose_level); |
| 2002 | HWCDebugHandler::DebugDriverConfig(enable, verbose_level); |
| 2003 | HWCDebugHandler::DebugRotator(enable, verbose_level); |
Varun Arora | cc301f1 | 2018-12-13 14:32:24 -0800 | [diff] [blame] | 2004 | HWCDebugHandler::DebugQos(enable, verbose_level); |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 2005 | break; |
| 2006 | |
| 2007 | case qService::IQService::DEBUG_QDCM: |
| 2008 | HWCDebugHandler::DebugQdcm(enable, verbose_level); |
| 2009 | break; |
| 2010 | |
Rohit Kulkarni | aa5111b | 2017-06-13 10:26:39 -0700 | [diff] [blame] | 2011 | case qService::IQService::DEBUG_SCALAR: |
| 2012 | HWCDebugHandler::DebugScalar(enable, verbose_level); |
| 2013 | break; |
| 2014 | |
Saurabh Dubey | d90a6a4 | 2017-10-24 16:28:01 +0530 | [diff] [blame] | 2015 | case qService::IQService::DEBUG_CLIENT: |
| 2016 | HWCDebugHandler::DebugClient(enable, verbose_level); |
| 2017 | break; |
| 2018 | |
| 2019 | case qService::IQService::DEBUG_DISPLAY: |
| 2020 | HWCDebugHandler::DebugDisplay(enable, verbose_level); |
| 2021 | break; |
| 2022 | |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 2023 | default: |
| 2024 | DLOGW("type = %d is not supported", type); |
| 2025 | } |
| 2026 | } |
| 2027 | |
Xu Yang | 2a979af | 2018-05-07 17:10:49 +0800 | [diff] [blame] | 2028 | android::status_t HWCSession::QdcmCMDDispatch(uint32_t display_id, |
| 2029 | const PPDisplayAPIPayload &req_payload, |
| 2030 | PPDisplayAPIPayload *resp_payload, |
| 2031 | PPPendingParams *pending_action) { |
| 2032 | int ret = 0; |
| 2033 | bool is_physical_display = false; |
| 2034 | |
Padmanabhan Komanduru | e74cf4f | 2019-04-25 17:38:43 -0700 | [diff] [blame] | 2035 | if (display_id >= HWCCallbacks::kNumDisplays || !hwc_display_[display_id]) { |
Xu Yang | 2a979af | 2018-05-07 17:10:49 +0800 | [diff] [blame] | 2036 | DLOGW("Invalid display id or display = %d is not connected.", display_id); |
| 2037 | return -ENODEV; |
| 2038 | } |
| 2039 | |
| 2040 | if (display_id == map_info_primary_.client_id) { |
| 2041 | is_physical_display = true; |
| 2042 | } else { |
| 2043 | for (auto &map_info : map_info_builtin_) { |
| 2044 | if (map_info.client_id == display_id) { |
| 2045 | is_physical_display = true; |
| 2046 | break; |
| 2047 | } |
| 2048 | } |
| 2049 | } |
| 2050 | |
| 2051 | if (!is_physical_display) { |
| 2052 | DLOGW("Skipping QDCM command dispatch on display = %d", display_id); |
| 2053 | return ret; |
| 2054 | } |
| 2055 | |
Rajavenu Kyatham | 42d11cb | 2019-04-16 13:03:29 +0530 | [diff] [blame] | 2056 | ret = hwc_display_[display_id]->ColorSVCRequestRoute(req_payload, resp_payload, pending_action); |
Xu Yang | 2a979af | 2018-05-07 17:10:49 +0800 | [diff] [blame] | 2057 | |
| 2058 | return ret; |
| 2059 | } |
| 2060 | |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 2061 | android::status_t HWCSession::QdcmCMDHandler(const android::Parcel *input_parcel, |
| 2062 | android::Parcel *output_parcel) { |
| 2063 | int ret = 0; |
Varun Arora | 75c05f0 | 2019-05-14 14:53:37 -0700 | [diff] [blame] | 2064 | float *brightness = NULL; |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 2065 | uint32_t display_id(0); |
| 2066 | PPPendingParams pending_action; |
| 2067 | PPDisplayAPIPayload resp_payload, req_payload; |
Xu Yang | 2a979af | 2018-05-07 17:10:49 +0800 | [diff] [blame] | 2068 | uint8_t *disp_id = NULL; |
Qing Huang | 02285c3 | 2018-12-06 16:30:38 +0800 | [diff] [blame] | 2069 | int32_t *mode_id = NULL; |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 2070 | |
| 2071 | if (!color_mgr_) { |
Mathew Joseph Karimpanal | dbd64f8 | 2017-10-06 10:13:38 +0530 | [diff] [blame] | 2072 | DLOGW("color_mgr_ not initialized."); |
| 2073 | return -ENOENT; |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 2074 | } |
| 2075 | |
| 2076 | pending_action.action = kNoAction; |
| 2077 | pending_action.params = NULL; |
| 2078 | |
| 2079 | // Read display_id, payload_size and payload from in_parcel. |
| 2080 | ret = HWCColorManager::CreatePayloadFromParcel(*input_parcel, &display_id, &req_payload); |
| 2081 | if (!ret) { |
Xu Yang | 2a979af | 2018-05-07 17:10:49 +0800 | [diff] [blame] | 2082 | ret = QdcmCMDDispatch(display_id, req_payload, &resp_payload, &pending_action); |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 2083 | } |
| 2084 | |
| 2085 | if (ret) { |
| 2086 | output_parcel->writeInt32(ret); // first field in out parcel indicates return code. |
| 2087 | req_payload.DestroyPayload(); |
| 2088 | resp_payload.DestroyPayload(); |
| 2089 | return ret; |
| 2090 | } |
| 2091 | |
Mathew Joseph Karimpanal | dbd64f8 | 2017-10-06 10:13:38 +0530 | [diff] [blame] | 2092 | if (kNoAction != pending_action.action) { |
Ch Ganesh Kumar | 5d43ff6 | 2017-10-13 19:01:47 +0530 | [diff] [blame] | 2093 | int32_t action = pending_action.action; |
| 2094 | int count = -1; |
| 2095 | while (action > 0) { |
| 2096 | count++; |
| 2097 | int32_t bit = (action & 1); |
| 2098 | action = action >> 1; |
| 2099 | |
| 2100 | if (!bit) |
| 2101 | continue; |
| 2102 | |
Xu Yang | 2a979af | 2018-05-07 17:10:49 +0800 | [diff] [blame] | 2103 | DLOGV_IF(kTagQDCM, "pending action = %d, display_id = %d", BITMAP(count), display_id); |
Ch Ganesh Kumar | 5d43ff6 | 2017-10-13 19:01:47 +0530 | [diff] [blame] | 2104 | switch (BITMAP(count)) { |
| 2105 | case kInvalidating: |
Ray Zhang | 2ee8247 | 2019-09-05 02:53:29 +0800 | [diff] [blame] | 2106 | callbacks_.Refresh(display_id); |
Ch Ganesh Kumar | 5d43ff6 | 2017-10-13 19:01:47 +0530 | [diff] [blame] | 2107 | break; |
| 2108 | case kEnterQDCMMode: |
Xu Yang | 2a979af | 2018-05-07 17:10:49 +0800 | [diff] [blame] | 2109 | ret = color_mgr_->EnableQDCMMode(true, hwc_display_[display_id]); |
Ch Ganesh Kumar | 5d43ff6 | 2017-10-13 19:01:47 +0530 | [diff] [blame] | 2110 | break; |
| 2111 | case kExitQDCMMode: |
Xu Yang | 2a979af | 2018-05-07 17:10:49 +0800 | [diff] [blame] | 2112 | ret = color_mgr_->EnableQDCMMode(false, hwc_display_[display_id]); |
Ch Ganesh Kumar | 5d43ff6 | 2017-10-13 19:01:47 +0530 | [diff] [blame] | 2113 | break; |
| 2114 | case kApplySolidFill: |
Gopikrishnaiah Anandan | a340b70 | 2018-01-16 15:37:15 -0800 | [diff] [blame] | 2115 | { |
Xu Yang | 2a979af | 2018-05-07 17:10:49 +0800 | [diff] [blame] | 2116 | SCOPE_LOCK(locker_[display_id]); |
Gopikrishnaiah Anandan | a340b70 | 2018-01-16 15:37:15 -0800 | [diff] [blame] | 2117 | ret = color_mgr_->SetSolidFill(pending_action.params, |
Xu Yang | 2a979af | 2018-05-07 17:10:49 +0800 | [diff] [blame] | 2118 | true, hwc_display_[display_id]); |
Gopikrishnaiah Anandan | a340b70 | 2018-01-16 15:37:15 -0800 | [diff] [blame] | 2119 | } |
Varun Arora | dff7d8d | 2019-08-05 18:12:43 -0700 | [diff] [blame] | 2120 | callbacks_.Refresh(display_id); |
Gopikrishnaiah Anandan | a340b70 | 2018-01-16 15:37:15 -0800 | [diff] [blame] | 2121 | usleep(kSolidFillDelay); |
Ch Ganesh Kumar | 5d43ff6 | 2017-10-13 19:01:47 +0530 | [diff] [blame] | 2122 | break; |
| 2123 | case kDisableSolidFill: |
Gopikrishnaiah Anandan | a340b70 | 2018-01-16 15:37:15 -0800 | [diff] [blame] | 2124 | { |
Xu Yang | 2a979af | 2018-05-07 17:10:49 +0800 | [diff] [blame] | 2125 | SCOPE_LOCK(locker_[display_id]); |
Gopikrishnaiah Anandan | a340b70 | 2018-01-16 15:37:15 -0800 | [diff] [blame] | 2126 | ret = color_mgr_->SetSolidFill(pending_action.params, |
Xu Yang | 2a979af | 2018-05-07 17:10:49 +0800 | [diff] [blame] | 2127 | false, hwc_display_[display_id]); |
Gopikrishnaiah Anandan | a340b70 | 2018-01-16 15:37:15 -0800 | [diff] [blame] | 2128 | } |
Varun Arora | dff7d8d | 2019-08-05 18:12:43 -0700 | [diff] [blame] | 2129 | callbacks_.Refresh(display_id); |
Gopikrishnaiah Anandan | a340b70 | 2018-01-16 15:37:15 -0800 | [diff] [blame] | 2130 | usleep(kSolidFillDelay); |
Ch Ganesh Kumar | 5d43ff6 | 2017-10-13 19:01:47 +0530 | [diff] [blame] | 2131 | break; |
| 2132 | case kSetPanelBrightness: |
Varun Arora | 75c05f0 | 2019-05-14 14:53:37 -0700 | [diff] [blame] | 2133 | ret = -EINVAL; |
| 2134 | brightness = reinterpret_cast<float *>(resp_payload.payload); |
| 2135 | if (brightness == NULL) { |
| 2136 | DLOGE("Brightness payload is Null"); |
Ch Ganesh Kumar | 5d43ff6 | 2017-10-13 19:01:47 +0530 | [diff] [blame] | 2137 | } else { |
Rajavenu Kyatham | 42d11cb | 2019-04-16 13:03:29 +0530 | [diff] [blame] | 2138 | ret = INT(SetDisplayBrightness(static_cast<hwc2_display_t>(display_id), *brightness)); |
Ch Ganesh Kumar | 5d43ff6 | 2017-10-13 19:01:47 +0530 | [diff] [blame] | 2139 | } |
| 2140 | break; |
| 2141 | case kEnableFrameCapture: |
Rajavenu Kyatham | 42d11cb | 2019-04-16 13:03:29 +0530 | [diff] [blame] | 2142 | ret = color_mgr_->SetFrameCapture(pending_action.params, true, hwc_display_[display_id]); |
Varun Arora | dff7d8d | 2019-08-05 18:12:43 -0700 | [diff] [blame] | 2143 | callbacks_.Refresh(display_id); |
Ch Ganesh Kumar | 5d43ff6 | 2017-10-13 19:01:47 +0530 | [diff] [blame] | 2144 | break; |
| 2145 | case kDisableFrameCapture: |
| 2146 | ret = color_mgr_->SetFrameCapture(pending_action.params, false, |
Xu Yang | 2a979af | 2018-05-07 17:10:49 +0800 | [diff] [blame] | 2147 | hwc_display_[display_id]); |
Ch Ganesh Kumar | 5d43ff6 | 2017-10-13 19:01:47 +0530 | [diff] [blame] | 2148 | break; |
| 2149 | case kConfigureDetailedEnhancer: |
Rajavenu Kyatham | 42d11cb | 2019-04-16 13:03:29 +0530 | [diff] [blame] | 2150 | ret = color_mgr_->SetDetailedEnhancer(pending_action.params, hwc_display_[display_id]); |
Varun Arora | dff7d8d | 2019-08-05 18:12:43 -0700 | [diff] [blame] | 2151 | callbacks_.Refresh(display_id); |
Ch Ganesh Kumar | 5d43ff6 | 2017-10-13 19:01:47 +0530 | [diff] [blame] | 2152 | break; |
| 2153 | case kModeSet: |
| 2154 | ret = static_cast<int> |
Xu Yang | 2a979af | 2018-05-07 17:10:49 +0800 | [diff] [blame] | 2155 | (hwc_display_[display_id]->RestoreColorTransform()); |
Varun Arora | dff7d8d | 2019-08-05 18:12:43 -0700 | [diff] [blame] | 2156 | callbacks_.Refresh(display_id); |
Ch Ganesh Kumar | 5d43ff6 | 2017-10-13 19:01:47 +0530 | [diff] [blame] | 2157 | break; |
| 2158 | case kNoAction: |
| 2159 | break; |
Xu Yang | 2a979af | 2018-05-07 17:10:49 +0800 | [diff] [blame] | 2160 | case kMultiDispProc: |
| 2161 | for (auto &map_info : map_info_builtin_) { |
| 2162 | uint32_t id = UINT32(map_info.client_id); |
Padmanabhan Komanduru | e74cf4f | 2019-04-25 17:38:43 -0700 | [diff] [blame] | 2163 | if (id < HWCCallbacks::kNumDisplays && hwc_display_[id]) { |
Xu Yang | 2a979af | 2018-05-07 17:10:49 +0800 | [diff] [blame] | 2164 | int result = 0; |
| 2165 | resp_payload.DestroyPayload(); |
Rajavenu Kyatham | 42d11cb | 2019-04-16 13:03:29 +0530 | [diff] [blame] | 2166 | result = hwc_display_[id]->ColorSVCRequestRoute(req_payload, &resp_payload, |
Xu Yang | 2a979af | 2018-05-07 17:10:49 +0800 | [diff] [blame] | 2167 | &pending_action); |
| 2168 | if (result) { |
| 2169 | DLOGW("Failed to dispatch action to disp %d ret %d", id, result); |
| 2170 | ret = result; |
| 2171 | } |
| 2172 | } |
| 2173 | } |
| 2174 | break; |
| 2175 | case kMultiDispGetId: |
Padmanabhan Komanduru | e74cf4f | 2019-04-25 17:38:43 -0700 | [diff] [blame] | 2176 | ret = resp_payload.CreatePayloadBytes(HWCCallbacks::kNumDisplays, &disp_id); |
Xu Yang | 2a979af | 2018-05-07 17:10:49 +0800 | [diff] [blame] | 2177 | if (ret) { |
| 2178 | DLOGW("Unable to create response payload!"); |
| 2179 | } else { |
Padmanabhan Komanduru | e74cf4f | 2019-04-25 17:38:43 -0700 | [diff] [blame] | 2180 | for (int i = 0; i < HWCCallbacks::kNumDisplays; i++) { |
| 2181 | disp_id[i] = HWCCallbacks::kNumDisplays; |
Xu Yang | 2a979af | 2018-05-07 17:10:49 +0800 | [diff] [blame] | 2182 | } |
| 2183 | if (hwc_display_[HWC_DISPLAY_PRIMARY]) { |
| 2184 | disp_id[HWC_DISPLAY_PRIMARY] = HWC_DISPLAY_PRIMARY; |
| 2185 | } |
| 2186 | for (auto &map_info : map_info_builtin_) { |
| 2187 | uint64_t id = map_info.client_id; |
Padmanabhan Komanduru | e74cf4f | 2019-04-25 17:38:43 -0700 | [diff] [blame] | 2188 | if (id < HWCCallbacks::kNumDisplays && hwc_display_[id]) { |
Xu Yang | 2a979af | 2018-05-07 17:10:49 +0800 | [diff] [blame] | 2189 | disp_id[id] = (uint8_t)id; |
| 2190 | } |
| 2191 | } |
| 2192 | } |
| 2193 | break; |
Qing Huang | 02285c3 | 2018-12-06 16:30:38 +0800 | [diff] [blame] | 2194 | case kSetModeFromClient: |
| 2195 | { |
| 2196 | SCOPE_LOCK(locker_[display_id]); |
| 2197 | mode_id = reinterpret_cast<int32_t *>(resp_payload.payload); |
| 2198 | if (mode_id) { |
| 2199 | ret = static_cast<int>(hwc_display_[display_id]->SetColorModeFromClientApi(*mode_id)); |
| 2200 | } else { |
| 2201 | DLOGE("mode_id is Null"); |
| 2202 | ret = -EINVAL; |
| 2203 | } |
| 2204 | } |
| 2205 | if (!ret) { |
Varun Arora | dff7d8d | 2019-08-05 18:12:43 -0700 | [diff] [blame] | 2206 | callbacks_.Refresh(display_id); |
Qing Huang | 02285c3 | 2018-12-06 16:30:38 +0800 | [diff] [blame] | 2207 | } |
| 2208 | break; |
Ch Ganesh Kumar | 5d43ff6 | 2017-10-13 19:01:47 +0530 | [diff] [blame] | 2209 | default: |
| 2210 | DLOGW("Invalid pending action = %d!", pending_action.action); |
| 2211 | break; |
| 2212 | } |
Mathew Joseph Karimpanal | dbd64f8 | 2017-10-06 10:13:38 +0530 | [diff] [blame] | 2213 | } |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 2214 | } |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 2215 | // for display API getter case, marshall returned params into out_parcel. |
| 2216 | output_parcel->writeInt32(ret); |
| 2217 | HWCColorManager::MarshallStructIntoParcel(resp_payload, output_parcel); |
| 2218 | req_payload.DestroyPayload(); |
| 2219 | resp_payload.DestroyPayload(); |
Sushil Chauhan | d6429af | 2018-11-15 11:34:27 -0800 | [diff] [blame] | 2220 | |
| 2221 | SEQUENCE_WAIT_SCOPE_LOCK(locker_[display_id]); |
Ray Zhang | 2ee8247 | 2019-09-05 02:53:29 +0800 | [diff] [blame] | 2222 | hwc_display_[display_id]->ResetValidation(); |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 2223 | |
Mathew Joseph Karimpanal | dbd64f8 | 2017-10-06 10:13:38 +0530 | [diff] [blame] | 2224 | return ret; |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 2225 | } |
| 2226 | |
Dileep Marchya | f3ce11f | 2018-04-30 23:35:46 +0530 | [diff] [blame] | 2227 | int GetEventValue(const char *uevent_data, int length, const char *event_info) { |
| 2228 | const char *iterator_str = uevent_data; |
| 2229 | while (((iterator_str - uevent_data) <= length) && (*iterator_str)) { |
| 2230 | const char *pstr = strstr(iterator_str, event_info); |
| 2231 | if (pstr != NULL) { |
| 2232 | return (atoi(iterator_str + strlen(event_info))); |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 2233 | } |
Dileep Marchya | f3ce11f | 2018-04-30 23:35:46 +0530 | [diff] [blame] | 2234 | iterator_str += strlen(iterator_str) + 1; |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 2235 | } |
Dileep Marchya | f3ce11f | 2018-04-30 23:35:46 +0530 | [diff] [blame] | 2236 | |
| 2237 | return -1; |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 2238 | } |
| 2239 | |
Prabhanjan Kandula | 0236771 | 2017-08-10 20:09:25 -0700 | [diff] [blame] | 2240 | const char *GetTokenValue(const char *uevent_data, int length, const char *token) { |
Prabhanjan Kandula | 34ffec0 | 2017-04-25 11:56:39 -0700 | [diff] [blame] | 2241 | const char *iterator_str = uevent_data; |
Prabhanjan Kandula | 34ffec0 | 2017-04-25 11:56:39 -0700 | [diff] [blame] | 2242 | const char *pstr = NULL; |
| 2243 | while (((iterator_str - uevent_data) <= length) && (*iterator_str)) { |
Prabhanjan Kandula | 0236771 | 2017-08-10 20:09:25 -0700 | [diff] [blame] | 2244 | pstr = strstr(iterator_str, token); |
| 2245 | if (pstr) { |
Prabhanjan Kandula | 34ffec0 | 2017-04-25 11:56:39 -0700 | [diff] [blame] | 2246 | break; |
| 2247 | } |
| 2248 | iterator_str += strlen(iterator_str) + 1; |
| 2249 | } |
| 2250 | |
Prabhanjan Kandula | 0236771 | 2017-08-10 20:09:25 -0700 | [diff] [blame] | 2251 | if (pstr) |
| 2252 | pstr = pstr+strlen(token); |
| 2253 | |
| 2254 | return pstr; |
| 2255 | } |
| 2256 | |
Pullakavi Srinivas | 9189e60 | 2018-12-19 16:58:07 +0530 | [diff] [blame] | 2257 | android::status_t HWCSession::SetDsiClk(const android::Parcel *input_parcel) { |
| 2258 | int disp_id = input_parcel->readInt32(); |
| 2259 | uint64_t clk = UINT64(input_parcel->readInt64()); |
Dileep Marchya | afa45bc | 2019-06-21 17:05:31 +0530 | [diff] [blame] | 2260 | if (disp_id < 0) { |
| 2261 | return -EINVAL; |
| 2262 | } |
| 2263 | |
| 2264 | SEQUENCE_WAIT_SCOPE_LOCK(locker_[disp_id]); |
| 2265 | if (!hwc_display_[disp_id]) { |
Pullakavi Srinivas | 9189e60 | 2018-12-19 16:58:07 +0530 | [diff] [blame] | 2266 | return -EINVAL; |
| 2267 | } |
| 2268 | |
| 2269 | return hwc_display_[disp_id]->SetDynamicDSIClock(clk); |
| 2270 | } |
| 2271 | |
| 2272 | android::status_t HWCSession::GetDsiClk(const android::Parcel *input_parcel, |
| 2273 | android::Parcel *output_parcel) { |
| 2274 | int disp_id = input_parcel->readInt32(); |
Dileep Marchya | afa45bc | 2019-06-21 17:05:31 +0530 | [diff] [blame] | 2275 | if (disp_id < 0) { |
| 2276 | return -EINVAL; |
| 2277 | } |
| 2278 | |
| 2279 | SEQUENCE_WAIT_SCOPE_LOCK(locker_[disp_id]); |
| 2280 | if (!hwc_display_[disp_id]) { |
Pullakavi Srinivas | 9189e60 | 2018-12-19 16:58:07 +0530 | [diff] [blame] | 2281 | return -EINVAL; |
| 2282 | } |
| 2283 | |
| 2284 | uint64_t bitrate = 0; |
| 2285 | hwc_display_[disp_id]->GetDynamicDSIClock(&bitrate); |
| 2286 | output_parcel->writeUint64(bitrate); |
| 2287 | |
| 2288 | return 0; |
| 2289 | } |
| 2290 | |
| 2291 | android::status_t HWCSession::GetSupportedDsiClk(const android::Parcel *input_parcel, |
| 2292 | android::Parcel *output_parcel) { |
| 2293 | int disp_id = input_parcel->readInt32(); |
Dileep Marchya | afa45bc | 2019-06-21 17:05:31 +0530 | [diff] [blame] | 2294 | if (disp_id < 0) { |
| 2295 | return -EINVAL; |
| 2296 | } |
| 2297 | |
| 2298 | SCOPE_LOCK(locker_[disp_id]); |
| 2299 | if (!hwc_display_[disp_id]) { |
Pullakavi Srinivas | 9189e60 | 2018-12-19 16:58:07 +0530 | [diff] [blame] | 2300 | return -EINVAL; |
| 2301 | } |
| 2302 | |
| 2303 | std::vector<uint64_t> bit_rates; |
| 2304 | hwc_display_[disp_id]->GetSupportedDSIClock(&bit_rates); |
| 2305 | output_parcel->writeInt32(INT32(bit_rates.size())); |
| 2306 | for (auto &bit_rate : bit_rates) { |
| 2307 | output_parcel->writeUint64(bit_rate); |
| 2308 | } |
| 2309 | |
| 2310 | return 0; |
| 2311 | } |
| 2312 | |
Archit Srivastava | a59c4ff | 2019-05-20 10:54:22 +0530 | [diff] [blame] | 2313 | android::status_t HWCSession::SetPanelLuminanceAttributes(const android::Parcel *input_parcel) { |
| 2314 | int disp_id = input_parcel->readInt32(); |
| 2315 | |
| 2316 | // currently doing only for virtual display |
| 2317 | if (disp_id != qdutils::DISPLAY_VIRTUAL) { |
| 2318 | return -EINVAL; |
| 2319 | } |
| 2320 | |
Padmanabhan Komanduru | e4d31fc | 2019-09-12 19:13:17 +0530 | [diff] [blame] | 2321 | float min_lum = input_parcel->readFloat(); |
| 2322 | float max_lum = input_parcel->readFloat(); |
| 2323 | |
| 2324 | // check for out of range luminance values |
| 2325 | if (min_lum <= 0.0f || min_lum >= 1.0f || max_lum <= 100.0f || max_lum >= 1000.0f) { |
| 2326 | return -EINVAL; |
| 2327 | } |
| 2328 | |
Archit Srivastava | a59c4ff | 2019-05-20 10:54:22 +0530 | [diff] [blame] | 2329 | std::lock_guard<std::mutex> obj(mutex_lum_); |
Padmanabhan Komanduru | e4d31fc | 2019-09-12 19:13:17 +0530 | [diff] [blame] | 2330 | set_min_lum_ = min_lum; |
| 2331 | set_max_lum_ = max_lum; |
Archit Srivastava | a59c4ff | 2019-05-20 10:54:22 +0530 | [diff] [blame] | 2332 | DLOGI("set max_lum %f, min_lum %f", set_max_lum_, set_min_lum_); |
| 2333 | |
| 2334 | return 0; |
| 2335 | } |
| 2336 | |
Dileep Marchya | f3ce11f | 2018-04-30 23:35:46 +0530 | [diff] [blame] | 2337 | void HWCSession::UEventHandler(const char *uevent_data, int length) { |
Mathew Joseph Karimpanal | 1289229 | 2019-03-21 16:07:59 +0530 | [diff] [blame] | 2338 | // Drop hotplug uevents until SurfaceFlinger (the client) is connected. The equivalent of hotplug |
| 2339 | // uevent handling will be done once when SurfaceFlinger connects, at RegisterCallback(). Since |
| 2340 | // HandlePluggableDisplays() reads the latest connection states of all displays, no uevent is |
| 2341 | // lost. |
Varun Arora | dff7d8d | 2019-08-05 18:12:43 -0700 | [diff] [blame] | 2342 | if (callbacks_.IsClientConnected() && strcasestr(uevent_data, HWC_UEVENT_DRM_EXT_HOTPLUG)) { |
Dileep Marchya | f3ce11f | 2018-04-30 23:35:46 +0530 | [diff] [blame] | 2343 | // MST hotplug will not carry connection status/test pattern etc. |
| 2344 | // Pluggable display handler will check all connection status' and take action accordingly. |
| 2345 | const char *str_status = GetTokenValue(uevent_data, length, "status="); |
| 2346 | const char *str_mst = GetTokenValue(uevent_data, length, "MST_HOTPLUG="); |
| 2347 | if (!str_status && !str_mst) { |
| 2348 | return; |
Ramakant Singh | fae5989 | 2017-09-13 10:40:22 +0530 | [diff] [blame] | 2349 | } |
Prabhanjan Kandula | 34ffec0 | 2017-04-25 11:56:39 -0700 | [diff] [blame] | 2350 | |
Dileep Marchya | f3ce11f | 2018-04-30 23:35:46 +0530 | [diff] [blame] | 2351 | hpd_bpp_ = GetEventValue(uevent_data, length, "bpp="); |
| 2352 | hpd_pattern_ = GetEventValue(uevent_data, length, "pattern="); |
Varun Arora | d366c20 | 2018-09-26 14:00:56 -0700 | [diff] [blame] | 2353 | DLOGI("Uevent = %s, status = %s, MST_HOTPLUG = %s, bpp = %d, pattern = %d", uevent_data, |
| 2354 | str_status ? str_status : "NULL", str_mst ? str_mst : "NULL", hpd_bpp_, hpd_pattern_); |
Mathew Joseph Karimpanal | 71ac8a7 | 2018-09-25 22:27:22 +0530 | [diff] [blame] | 2355 | |
| 2356 | hwc2_display_t virtual_display_index = |
| 2357 | (hwc2_display_t)GetDisplayIndex(qdutils::DISPLAY_VIRTUAL); |
| 2358 | |
| 2359 | std::bitset<kSecureMax> secure_sessions = 0; |
Ramkumar Radhakrishnan | 44c6436 | 2018-12-12 13:03:59 -0800 | [diff] [blame] | 2360 | hwc2_display_t active_builtin_disp_id = GetActiveBuiltinDisplay(); |
Padmanabhan Komanduru | e74cf4f | 2019-04-25 17:38:43 -0700 | [diff] [blame] | 2361 | if (active_builtin_disp_id < HWCCallbacks::kNumDisplays) { |
Ramkumar Radhakrishnan | 44c6436 | 2018-12-12 13:03:59 -0800 | [diff] [blame] | 2362 | Locker::ScopeLock lock_a(locker_[active_builtin_disp_id]); |
| 2363 | hwc_display_[active_builtin_disp_id]->GetActiveSecureSession(&secure_sessions); |
Mathew Joseph Karimpanal | 71ac8a7 | 2018-09-25 22:27:22 +0530 | [diff] [blame] | 2364 | } |
| 2365 | if (secure_sessions[kSecureDisplay] || hwc_display_[virtual_display_index]) { |
Mathew Joseph Karimpanal | abe3b3d | 2018-11-27 17:25:40 +0530 | [diff] [blame] | 2366 | // Defer hotplug handling. |
| 2367 | SCOPE_LOCK(pluggable_handler_lock_); |
| 2368 | DLOGI("Marking hotplug pending..."); |
Mathew Joseph Karimpanal | b1c1586 | 2019-07-04 11:14:24 +0530 | [diff] [blame] | 2369 | pending_hotplug_event_ = kHotPlugEvent; |
Mathew Joseph Karimpanal | abe3b3d | 2018-11-27 17:25:40 +0530 | [diff] [blame] | 2370 | } else { |
| 2371 | // Handle hotplug. |
| 2372 | int32_t err = HandlePluggableDisplays(true); |
| 2373 | if (err) { |
| 2374 | DLOGW("Hotplug handling failed. Error %d '%s'. Hotplug handling %s.", err, |
Mathew Joseph Karimpanal | b1c1586 | 2019-07-04 11:14:24 +0530 | [diff] [blame] | 2375 | strerror(abs(err)), (pending_hotplug_event_ == kHotPlugEvent) ? |
Mathew Joseph Karimpanal | abe3b3d | 2018-11-27 17:25:40 +0530 | [diff] [blame] | 2376 | "deferred" : "dropped"); |
| 2377 | } |
Dileep Marchya | f3ce11f | 2018-04-30 23:35:46 +0530 | [diff] [blame] | 2378 | } |
| 2379 | |
| 2380 | if (str_status) { |
| 2381 | bool connected = (strncmp(str_status, "connected", strlen("connected")) == 0); |
| 2382 | DLOGI("Connected = %d", connected); |
Mathew Joseph Karimpanal | 71ac8a7 | 2018-09-25 22:27:22 +0530 | [diff] [blame] | 2383 | // Pass on legacy HDMI hot-plug event. |
Dileep Marchya | f3ce11f | 2018-04-30 23:35:46 +0530 | [diff] [blame] | 2384 | qservice_->onHdmiHotplug(INT(connected)); |
| 2385 | } |
Prabhanjan Kandula | 34ffec0 | 2017-04-25 11:56:39 -0700 | [diff] [blame] | 2386 | } |
| 2387 | } |
| 2388 | |
Naseer Ahmed | 8584a0f | 2020-02-19 22:23:30 -0500 | [diff] [blame] | 2389 | int32_t HWCSession::GetVsyncPeriod(hwc2_display_t disp, uint32_t *vsync_period) { |
| 2390 | if (disp >= HWCCallbacks::kNumDisplays) { |
| 2391 | DLOGW("Invalid Display : display = %" PRIu64, disp); |
| 2392 | return HWC2_ERROR_BAD_DISPLAY; |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 2393 | } |
| 2394 | |
Naseer Ahmed | 8584a0f | 2020-02-19 22:23:30 -0500 | [diff] [blame] | 2395 | SCOPE_LOCK(locker_[(int)disp]); |
| 2396 | // default value |
| 2397 | *vsync_period = 1000000000ul / 60; |
| 2398 | |
| 2399 | if (hwc_display_[disp]) { |
| 2400 | hwc_display_[disp]->GetDisplayAttribute(0, HwcAttribute::VSYNC_PERIOD, (int32_t *)vsync_period); |
| 2401 | } |
| 2402 | |
| 2403 | return HWC2_ERROR_NONE; |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 2404 | } |
| 2405 | |
Mathew Joseph Karimpanal | f929747 | 2019-08-21 15:49:15 +0530 | [diff] [blame] | 2406 | void HWCSession::Refresh(hwc2_display_t display) { |
| 2407 | callbacks_.Refresh(display); |
| 2408 | } |
| 2409 | |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 2410 | android::status_t HWCSession::GetVisibleDisplayRect(const android::Parcel *input_parcel, |
| 2411 | android::Parcel *output_parcel) { |
Dileep Marchya | f3ce11f | 2018-04-30 23:35:46 +0530 | [diff] [blame] | 2412 | int disp_idx = GetDisplayIndex(input_parcel->readInt32()); |
| 2413 | if (disp_idx == -1) { |
| 2414 | DLOGE("Invalid display = %d", disp_idx); |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 2415 | return android::BAD_VALUE; |
| 2416 | } |
| 2417 | |
Dileep Marchya | f3ce11f | 2018-04-30 23:35:46 +0530 | [diff] [blame] | 2418 | SEQUENCE_WAIT_SCOPE_LOCK(locker_[disp_idx]); |
| 2419 | if (!hwc_display_[disp_idx]) { |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 2420 | return android::NO_INIT; |
| 2421 | } |
| 2422 | |
| 2423 | hwc_rect_t visible_rect = {0, 0, 0, 0}; |
Dileep Marchya | f3ce11f | 2018-04-30 23:35:46 +0530 | [diff] [blame] | 2424 | int error = hwc_display_[disp_idx]->GetVisibleDisplayRect(&visible_rect); |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 2425 | if (error < 0) { |
| 2426 | return error; |
| 2427 | } |
| 2428 | |
| 2429 | output_parcel->writeInt32(visible_rect.left); |
| 2430 | output_parcel->writeInt32(visible_rect.top); |
| 2431 | output_parcel->writeInt32(visible_rect.right); |
| 2432 | output_parcel->writeInt32(visible_rect.bottom); |
| 2433 | |
| 2434 | return android::NO_ERROR; |
| 2435 | } |
| 2436 | |
Dileep Marchya | f3ce11f | 2018-04-30 23:35:46 +0530 | [diff] [blame] | 2437 | int HWCSession::CreatePrimaryDisplay() { |
| 2438 | int status = -EINVAL; |
| 2439 | HWDisplaysInfo hw_displays_info = {}; |
Ramakant Singh | fae5989 | 2017-09-13 10:40:22 +0530 | [diff] [blame] | 2440 | |
Varun Arora | ad2719a | 2018-10-25 10:13:53 -0700 | [diff] [blame] | 2441 | if (null_display_mode_) { |
| 2442 | HWDisplayInfo hw_info = {}; |
| 2443 | hw_info.display_type = kBuiltIn; |
| 2444 | hw_info.is_connected = 1; |
| 2445 | hw_info.is_primary = 1; |
| 2446 | hw_info.is_wb_ubwc_supported = 0; |
| 2447 | hw_info.display_id = 1; |
| 2448 | hw_displays_info[hw_info.display_id] = hw_info; |
| 2449 | } else { |
| 2450 | DisplayError error = core_intf_->GetDisplaysStatus(&hw_displays_info); |
| 2451 | if (error != kErrorNone) { |
| 2452 | DLOGE("Failed to get connected display list. Error = %d", error); |
| 2453 | return status; |
| 2454 | } |
Ramakant Singh | fae5989 | 2017-09-13 10:40:22 +0530 | [diff] [blame] | 2455 | } |
| 2456 | |
Dileep Marchya | f3ce11f | 2018-04-30 23:35:46 +0530 | [diff] [blame] | 2457 | for (auto &iter : hw_displays_info) { |
| 2458 | auto &info = iter.second; |
| 2459 | if (!info.is_primary) { |
| 2460 | continue; |
| 2461 | } |
| 2462 | |
| 2463 | // todo (user): If primary display is not connected (e.g. hdmi as primary), a NULL display |
| 2464 | // need to be created. SF expects primary display hotplug during callback registration unlike |
| 2465 | // previous implementation where first hotplug could be notified anytime. |
| 2466 | if (!info.is_connected) { |
| 2467 | DLOGE("Primary display is not connected. Not supported at present."); |
| 2468 | break; |
| 2469 | } |
| 2470 | |
| 2471 | auto hwc_display = &hwc_display_[HWC_DISPLAY_PRIMARY]; |
| 2472 | hwc2_display_t client_id = map_info_primary_.client_id; |
| 2473 | |
Dileep Marchya | f3ce11f | 2018-04-30 23:35:46 +0530 | [diff] [blame] | 2474 | if (info.display_type == kBuiltIn) { |
| 2475 | status = HWCDisplayBuiltIn::Create(core_intf_, &buffer_allocator_, &callbacks_, this, |
| 2476 | qservice_, client_id, info.display_id, hwc_display); |
| 2477 | } else if (info.display_type == kPluggable) { |
| 2478 | status = HWCDisplayPluggable::Create(core_intf_, &buffer_allocator_, &callbacks_, this, |
| 2479 | qservice_, client_id, info.display_id, 0, 0, false, |
| 2480 | hwc_display); |
| 2481 | } else { |
| 2482 | DLOGE("Spurious primary display type = %d", info.display_type); |
| 2483 | break; |
| 2484 | } |
| 2485 | |
| 2486 | if (!status) { |
Varun Arora | d7d8c91 | 2019-08-16 11:45:19 -0700 | [diff] [blame] | 2487 | DLOGI("Created primary display type = %d, sdm id = %d, client id = %d", info.display_type, |
Pullakavi Srinivas | 1ae4acb | 2019-11-18 19:33:45 +0530 | [diff] [blame] | 2488 | info.display_id, client_id); |
| 2489 | { |
| 2490 | SCOPE_LOCK(hdr_locker_[client_id]); |
| 2491 | is_hdr_display_[UINT32(client_id)] = HasHDRSupport(*hwc_display); |
| 2492 | } |
| 2493 | |
Dileep Marchya | f3ce11f | 2018-04-30 23:35:46 +0530 | [diff] [blame] | 2494 | map_info_primary_.disp_type = info.display_type; |
| 2495 | map_info_primary_.sdm_id = info.display_id; |
Srinivas Pullakavi | 3c4337f | 2019-07-03 11:24:31 +0530 | [diff] [blame] | 2496 | CreateDummyDisplay(HWC_DISPLAY_PRIMARY); |
Dileep Marchya | f3ce11f | 2018-04-30 23:35:46 +0530 | [diff] [blame] | 2497 | color_mgr_ = HWCColorManager::CreateColorManager(&buffer_allocator_); |
| 2498 | if (!color_mgr_) { |
| 2499 | DLOGW("Failed to load HWCColorManager."); |
| 2500 | } |
| 2501 | } else { |
Varun Arora | d7d8c91 | 2019-08-16 11:45:19 -0700 | [diff] [blame] | 2502 | DLOGE("Primary display creation has failed! status = %d", status); |
Dileep Marchya | f3ce11f | 2018-04-30 23:35:46 +0530 | [diff] [blame] | 2503 | } |
| 2504 | |
| 2505 | // Primary display is found, no need to parse more. |
| 2506 | break; |
Ramakant Singh | fae5989 | 2017-09-13 10:40:22 +0530 | [diff] [blame] | 2507 | } |
| 2508 | |
Dileep Marchya | f3ce11f | 2018-04-30 23:35:46 +0530 | [diff] [blame] | 2509 | return status; |
Ramakant Singh | fae5989 | 2017-09-13 10:40:22 +0530 | [diff] [blame] | 2510 | } |
| 2511 | |
Srinivas Pullakavi | 3c4337f | 2019-07-03 11:24:31 +0530 | [diff] [blame] | 2512 | void HWCSession::CreateDummyDisplay(hwc2_display_t client_id) { |
| 2513 | if (!async_powermode_) { |
| 2514 | return; |
| 2515 | } |
| 2516 | |
| 2517 | hwc2_display_t dummy_disp_id = map_hwc_display_.find(client_id)->second; |
| 2518 | auto hwc_display_dummy = &hwc_display_[dummy_disp_id]; |
| 2519 | HWCDisplayDummy::Create(core_intf_, &buffer_allocator_, &callbacks_, this, qservice_, |
| 2520 | 0, 0, hwc_display_dummy); |
| 2521 | if (!*hwc_display_dummy) { |
| 2522 | DLOGE("Dummy display creation failed for %d display\n", client_id); |
| 2523 | } |
| 2524 | } |
| 2525 | |
Varun Arora | ad2719a | 2018-10-25 10:13:53 -0700 | [diff] [blame] | 2526 | int HWCSession::HandleBuiltInDisplays() { |
| 2527 | if (null_display_mode_) { |
| 2528 | DLOGW("Skipped BuiltIn display handling in null-display mode"); |
| 2529 | return 0; |
| 2530 | } |
Dileep Marchya | f3ce11f | 2018-04-30 23:35:46 +0530 | [diff] [blame] | 2531 | |
Varun Arora | ad2719a | 2018-10-25 10:13:53 -0700 | [diff] [blame] | 2532 | HWDisplaysInfo hw_displays_info = {}; |
Dileep Marchya | f3ce11f | 2018-04-30 23:35:46 +0530 | [diff] [blame] | 2533 | DisplayError error = core_intf_->GetDisplaysStatus(&hw_displays_info); |
| 2534 | if (error != kErrorNone) { |
| 2535 | DLOGE("Failed to get connected display list. Error = %d", error); |
| 2536 | return -EINVAL; |
| 2537 | } |
| 2538 | |
| 2539 | int status = 0; |
Dileep Marchya | f3ce11f | 2018-04-30 23:35:46 +0530 | [diff] [blame] | 2540 | for (auto &iter : hw_displays_info) { |
| 2541 | auto &info = iter.second; |
| 2542 | |
| 2543 | // Do not recreate primary display. |
| 2544 | if (info.is_primary || info.display_type != kBuiltIn) { |
| 2545 | continue; |
| 2546 | } |
| 2547 | |
Pullakavi Srinivas | f2a3185 | 2019-04-23 14:32:08 -0700 | [diff] [blame] | 2548 | for (auto &map_info : map_info_builtin_) { |
| 2549 | hwc2_display_t client_id = map_info.client_id; |
Mathew Joseph Karimpanal | 8abb6e0 | 2018-11-20 09:52:49 +0530 | [diff] [blame] | 2550 | |
Pullakavi Srinivas | f2a3185 | 2019-04-23 14:32:08 -0700 | [diff] [blame] | 2551 | { |
| 2552 | SCOPE_LOCK(locker_[client_id]); |
| 2553 | // Lock confined to this scope |
| 2554 | if (hwc_display_[client_id]) { |
| 2555 | continue; |
| 2556 | } |
Dileep Marchya | f3ce11f | 2018-04-30 23:35:46 +0530 | [diff] [blame] | 2557 | |
Pullakavi Srinivas | f2a3185 | 2019-04-23 14:32:08 -0700 | [diff] [blame] | 2558 | DLOGI("Create builtin display, sdm id = %d, client id = %d", info.display_id, client_id); |
| 2559 | status = HWCDisplayBuiltIn::Create(core_intf_, &buffer_allocator_, &callbacks_, this, |
| 2560 | qservice_, client_id, info.display_id, |
| 2561 | &hwc_display_[client_id]); |
| 2562 | if (status) { |
| 2563 | DLOGE("Builtin display creation failed."); |
| 2564 | break; |
| 2565 | } |
Pullakavi Srinivas | 1ae4acb | 2019-11-18 19:33:45 +0530 | [diff] [blame] | 2566 | |
| 2567 | { |
| 2568 | SCOPE_LOCK(hdr_locker_[client_id]); |
| 2569 | is_hdr_display_[UINT32(client_id)] = HasHDRSupport(hwc_display_[client_id]); |
| 2570 | } |
| 2571 | |
Mathew Joseph Karimpanal | 8abb6e0 | 2018-11-20 09:52:49 +0530 | [diff] [blame] | 2572 | DLOGI("Builtin display created: sdm id = %d, client id = %d", info.display_id, client_id); |
Dileep Marchya | f3ce11f | 2018-04-30 23:35:46 +0530 | [diff] [blame] | 2573 | map_info.disp_type = info.display_type; |
| 2574 | map_info.sdm_id = info.display_id; |
Srinivas Pullakavi | 3c4337f | 2019-07-03 11:24:31 +0530 | [diff] [blame] | 2575 | CreateDummyDisplay(client_id); |
Dileep Marchya | f3ce11f | 2018-04-30 23:35:46 +0530 | [diff] [blame] | 2576 | } |
Dileep Marchya | f3ce11f | 2018-04-30 23:35:46 +0530 | [diff] [blame] | 2577 | |
Pullakavi Srinivas | f2a3185 | 2019-04-23 14:32:08 -0700 | [diff] [blame] | 2578 | DLOGI("Hotplugging builtin display, sdm id = %d, client id = %d", info.display_id, client_id); |
| 2579 | callbacks_.Hotplug(client_id, HWC2::Connection::Connected); |
| 2580 | break; |
| 2581 | } |
Dileep Marchya | f3ce11f | 2018-04-30 23:35:46 +0530 | [diff] [blame] | 2582 | } |
| 2583 | |
| 2584 | return status; |
Saurabh Shah | 04f932b | 2017-10-12 18:47:45 -0700 | [diff] [blame] | 2585 | } |
Dileep Marchya | f3ce11f | 2018-04-30 23:35:46 +0530 | [diff] [blame] | 2586 | |
Varun Arora | d366c20 | 2018-09-26 14:00:56 -0700 | [diff] [blame] | 2587 | int HWCSession::HandlePluggableDisplays(bool delay_hotplug) { |
Mathew Joseph Karimpanal | abe3b3d | 2018-11-27 17:25:40 +0530 | [diff] [blame] | 2588 | SCOPE_LOCK(pluggable_handler_lock_); |
Varun Arora | ad2719a | 2018-10-25 10:13:53 -0700 | [diff] [blame] | 2589 | if (null_display_mode_) { |
| 2590 | DLOGW("Skipped pluggable display handling in null-display mode"); |
| 2591 | return 0; |
| 2592 | } |
| 2593 | |
Mathew Joseph Karimpanal | abe3b3d | 2018-11-27 17:25:40 +0530 | [diff] [blame] | 2594 | DLOGI("Handling hotplug..."); |
Dileep Marchya | f3ce11f | 2018-04-30 23:35:46 +0530 | [diff] [blame] | 2595 | HWDisplaysInfo hw_displays_info = {}; |
Dileep Marchya | f3ce11f | 2018-04-30 23:35:46 +0530 | [diff] [blame] | 2596 | DisplayError error = core_intf_->GetDisplaysStatus(&hw_displays_info); |
| 2597 | if (error != kErrorNone) { |
| 2598 | DLOGE("Failed to get connected display list. Error = %d", error); |
| 2599 | return -EINVAL; |
| 2600 | } |
| 2601 | |
| 2602 | int status = HandleDisconnectedDisplays(&hw_displays_info); |
| 2603 | if (status) { |
| 2604 | DLOGE("All displays could not be disconnected."); |
| 2605 | return status; |
| 2606 | } |
| 2607 | |
| 2608 | status = HandleConnectedDisplays(&hw_displays_info, delay_hotplug); |
| 2609 | if (status) { |
Mathew Joseph Karimpanal | abe3b3d | 2018-11-27 17:25:40 +0530 | [diff] [blame] | 2610 | switch (status) { |
| 2611 | case -EAGAIN: |
| 2612 | case -ENODEV: |
| 2613 | // Errors like device removal or deferral for which we want to try another hotplug handling. |
Mathew Joseph Karimpanal | b1c1586 | 2019-07-04 11:14:24 +0530 | [diff] [blame] | 2614 | pending_hotplug_event_ = kHotPlugEvent; |
Mathew Joseph Karimpanal | abe3b3d | 2018-11-27 17:25:40 +0530 | [diff] [blame] | 2615 | status = 0; |
| 2616 | break; |
| 2617 | default: |
| 2618 | // Real errors we want to flag and stop hotplug handling. |
Mathew Joseph Karimpanal | b1c1586 | 2019-07-04 11:14:24 +0530 | [diff] [blame] | 2619 | pending_hotplug_event_ = kHotPlugNone; |
Mathew Joseph Karimpanal | abe3b3d | 2018-11-27 17:25:40 +0530 | [diff] [blame] | 2620 | DLOGE("All displays could not be connected. Error %d '%s'.", status, strerror(abs(status))); |
| 2621 | } |
Mathew Joseph Karimpanal | b1c1586 | 2019-07-04 11:14:24 +0530 | [diff] [blame] | 2622 | DLOGI("Handling hotplug... %s", (kHotPlugNone == pending_hotplug_event_) ? |
Mathew Joseph Karimpanal | abe3b3d | 2018-11-27 17:25:40 +0530 | [diff] [blame] | 2623 | "Stopped." : "Done. Hotplug events pending."); |
| 2624 | return status; |
Dileep Marchya | f3ce11f | 2018-04-30 23:35:46 +0530 | [diff] [blame] | 2625 | } |
| 2626 | |
Mathew Joseph Karimpanal | b1c1586 | 2019-07-04 11:14:24 +0530 | [diff] [blame] | 2627 | pending_hotplug_event_ = kHotPlugNone; |
Mathew Joseph Karimpanal | abe3b3d | 2018-11-27 17:25:40 +0530 | [diff] [blame] | 2628 | |
| 2629 | DLOGI("Handling hotplug... Done."); |
Dileep Marchya | f3ce11f | 2018-04-30 23:35:46 +0530 | [diff] [blame] | 2630 | return 0; |
| 2631 | } |
| 2632 | |
| 2633 | int HWCSession::HandleConnectedDisplays(HWDisplaysInfo *hw_displays_info, bool delay_hotplug) { |
| 2634 | int status = 0; |
| 2635 | std::vector<hwc2_display_t> pending_hotplugs = {}; |
Padmanabhan Komanduru | f5b7f99 | 2019-07-08 13:33:44 +0530 | [diff] [blame] | 2636 | hwc2_display_t client_id = 0; |
Dileep Marchya | f3ce11f | 2018-04-30 23:35:46 +0530 | [diff] [blame] | 2637 | |
| 2638 | for (auto &iter : *hw_displays_info) { |
| 2639 | auto &info = iter.second; |
| 2640 | |
| 2641 | // Do not recreate primary display or if display is not connected. |
| 2642 | if (info.is_primary || info.display_type != kPluggable || !info.is_connected) { |
| 2643 | continue; |
| 2644 | } |
| 2645 | |
Mathew Joseph Karimpanal | bbc700b | 2018-07-19 19:54:24 +0530 | [diff] [blame] | 2646 | // Check if we are already using the display. |
| 2647 | auto display_used = std::find_if(map_info_pluggable_.begin(), map_info_pluggable_.end(), |
| 2648 | [&](auto &p) { |
| 2649 | return (p.sdm_id == info.display_id); |
| 2650 | }); |
| 2651 | if (display_used != map_info_pluggable_.end()) { |
| 2652 | // Display is already used in a slot. |
| 2653 | continue; |
| 2654 | } |
| 2655 | |
Mathew Joseph Karimpanal | abe3b3d | 2018-11-27 17:25:40 +0530 | [diff] [blame] | 2656 | // Count active pluggable display slots and slots with no commits. |
Mathew Joseph Karimpanal | abe3b3d | 2018-11-27 17:25:40 +0530 | [diff] [blame] | 2657 | bool first_commit_pending = false; |
Mathew Joseph Karimpanal | 8abb6e0 | 2018-11-20 09:52:49 +0530 | [diff] [blame] | 2658 | std::for_each(map_info_pluggable_.begin(), map_info_pluggable_.end(), |
| 2659 | [&](auto &p) { |
Mathew Joseph Karimpanal | abe3b3d | 2018-11-27 17:25:40 +0530 | [diff] [blame] | 2660 | SCOPE_LOCK(locker_[p.client_id]); |
Mathew Joseph Karimpanal | 8abb6e0 | 2018-11-20 09:52:49 +0530 | [diff] [blame] | 2661 | if (hwc_display_[p.client_id]) { |
Mathew Joseph Karimpanal | abe3b3d | 2018-11-27 17:25:40 +0530 | [diff] [blame] | 2662 | if (!hwc_display_[p.client_id]->IsFirstCommitDone()) { |
| 2663 | DLOGI("Display commit pending on display %d-1", p.sdm_id); |
| 2664 | first_commit_pending = true; |
| 2665 | } |
Mathew Joseph Karimpanal | 8abb6e0 | 2018-11-20 09:52:49 +0530 | [diff] [blame] | 2666 | } |
| 2667 | }); |
| 2668 | |
Mathew Joseph Karimpanal | abe3b3d | 2018-11-27 17:25:40 +0530 | [diff] [blame] | 2669 | if (!disable_hotplug_bwcheck_ && first_commit_pending) { |
| 2670 | // Hotplug bandwidth check is accomplished by creating and hotplugging a new display after |
| 2671 | // a display commit has happened on previous hotplugged displays. This allows the driver to |
| 2672 | // return updated modes for the new display based on available link bandwidth. |
| 2673 | DLOGI("Pending display commit on one of the displays. Deferring display creation."); |
| 2674 | status = -EAGAIN; |
Varun Arora | dff7d8d | 2019-08-05 18:12:43 -0700 | [diff] [blame] | 2675 | if (callbacks_.IsClientConnected()) { |
Mathew Joseph Karimpanal | abe3b3d | 2018-11-27 17:25:40 +0530 | [diff] [blame] | 2676 | // Trigger a display refresh since we depend on PresentDisplay() to handle pending hotplugs. |
| 2677 | hwc2_display_t active_builtin_disp_id = GetActiveBuiltinDisplay(); |
Padmanabhan Komanduru | e74cf4f | 2019-04-25 17:38:43 -0700 | [diff] [blame] | 2678 | if (active_builtin_disp_id >= HWCCallbacks::kNumDisplays) { |
Mathew Joseph Karimpanal | abe3b3d | 2018-11-27 17:25:40 +0530 | [diff] [blame] | 2679 | active_builtin_disp_id = HWC_DISPLAY_PRIMARY; |
| 2680 | } |
Varun Arora | dff7d8d | 2019-08-05 18:12:43 -0700 | [diff] [blame] | 2681 | callbacks_.Refresh(active_builtin_disp_id); |
Mathew Joseph Karimpanal | abe3b3d | 2018-11-27 17:25:40 +0530 | [diff] [blame] | 2682 | } |
| 2683 | break; |
| 2684 | } |
Mathew Joseph Karimpanal | 71ac8a7 | 2018-09-25 22:27:22 +0530 | [diff] [blame] | 2685 | |
Dileep Marchya | f3ce11f | 2018-04-30 23:35:46 +0530 | [diff] [blame] | 2686 | // find an empty slot to create display. |
| 2687 | for (auto &map_info : map_info_pluggable_) { |
Padmanabhan Komanduru | f5b7f99 | 2019-07-08 13:33:44 +0530 | [diff] [blame] | 2688 | client_id = map_info.client_id; |
Dileep Marchya | f3ce11f | 2018-04-30 23:35:46 +0530 | [diff] [blame] | 2689 | |
| 2690 | // Lock confined to this scope |
| 2691 | { |
| 2692 | SCOPE_LOCK(locker_[client_id]); |
| 2693 | auto &hwc_display = hwc_display_[client_id]; |
| 2694 | if (hwc_display) { |
Mathew Joseph Karimpanal | bbc700b | 2018-07-19 19:54:24 +0530 | [diff] [blame] | 2695 | // Display slot is already used. |
Dileep Marchya | f3ce11f | 2018-04-30 23:35:46 +0530 | [diff] [blame] | 2696 | continue; |
| 2697 | } |
| 2698 | |
| 2699 | DLOGI("Create pluggable display, sdm id = %d, client id = %d", info.display_id, client_id); |
| 2700 | |
| 2701 | // Test pattern generation ? |
| 2702 | map_info.test_pattern = (hpd_bpp_ > 0) && (hpd_pattern_ > 0); |
Mathew Joseph Karimpanal | 23e2da0 | 2018-11-13 17:44:43 +0530 | [diff] [blame] | 2703 | int err = 0; |
Dileep Marchya | f3ce11f | 2018-04-30 23:35:46 +0530 | [diff] [blame] | 2704 | if (!map_info.test_pattern) { |
Mathew Joseph Karimpanal | 23e2da0 | 2018-11-13 17:44:43 +0530 | [diff] [blame] | 2705 | err = HWCDisplayPluggable::Create(core_intf_, &buffer_allocator_, |
| 2706 | &callbacks_, this, qservice_, client_id, |
| 2707 | info.display_id, 0, 0, false, &hwc_display); |
Dileep Marchya | f3ce11f | 2018-04-30 23:35:46 +0530 | [diff] [blame] | 2708 | } else { |
Mathew Joseph Karimpanal | 23e2da0 | 2018-11-13 17:44:43 +0530 | [diff] [blame] | 2709 | err = HWCDisplayPluggableTest::Create(core_intf_, &buffer_allocator_, |
| 2710 | &callbacks_, this, qservice_, client_id, |
| 2711 | info.display_id, UINT32(hpd_bpp_), |
| 2712 | UINT32(hpd_pattern_), &hwc_display); |
Dileep Marchya | f3ce11f | 2018-04-30 23:35:46 +0530 | [diff] [blame] | 2713 | } |
| 2714 | |
Mathew Joseph Karimpanal | 23e2da0 | 2018-11-13 17:44:43 +0530 | [diff] [blame] | 2715 | if (err) { |
Mathew Joseph Karimpanal | abe3b3d | 2018-11-27 17:25:40 +0530 | [diff] [blame] | 2716 | DLOGW("Pluggable display creation failed/aborted. Error %d '%s'.", err, |
| 2717 | strerror(abs(err))); |
Mathew Joseph Karimpanal | 23e2da0 | 2018-11-13 17:44:43 +0530 | [diff] [blame] | 2718 | status = err; |
| 2719 | // Attempt creating remaining pluggable displays. |
| 2720 | break; |
Dileep Marchya | f3ce11f | 2018-04-30 23:35:46 +0530 | [diff] [blame] | 2721 | } |
| 2722 | |
Pullakavi Srinivas | 1ae4acb | 2019-11-18 19:33:45 +0530 | [diff] [blame] | 2723 | { |
| 2724 | SCOPE_LOCK(hdr_locker_[client_id]); |
| 2725 | is_hdr_display_[UINT32(client_id)] = HasHDRSupport(hwc_display); |
| 2726 | } |
| 2727 | |
Mathew Joseph Karimpanal | bbc700b | 2018-07-19 19:54:24 +0530 | [diff] [blame] | 2728 | DLOGI("Created pluggable display successfully: sdm id = %d, client id = %d", |
| 2729 | info.display_id, client_id); |
Srinivas Pullakavi | 3c4337f | 2019-07-03 11:24:31 +0530 | [diff] [blame] | 2730 | CreateDummyDisplay(client_id); |
Dileep Marchya | f3ce11f | 2018-04-30 23:35:46 +0530 | [diff] [blame] | 2731 | } |
| 2732 | |
| 2733 | map_info.disp_type = info.display_type; |
| 2734 | map_info.sdm_id = info.display_id; |
| 2735 | |
| 2736 | pending_hotplugs.push_back((hwc2_display_t)client_id); |
| 2737 | |
| 2738 | // Display is created for this sdm id, move to next connected display. |
| 2739 | break; |
| 2740 | } |
| 2741 | } |
| 2742 | |
| 2743 | // No display was created. |
| 2744 | if (!pending_hotplugs.size()) { |
Mathew Joseph Karimpanal | 23e2da0 | 2018-11-13 17:44:43 +0530 | [diff] [blame] | 2745 | return status; |
Dileep Marchya | f3ce11f | 2018-04-30 23:35:46 +0530 | [diff] [blame] | 2746 | } |
| 2747 | |
Ramkumar Radhakrishnan | 44c6436 | 2018-12-12 13:03:59 -0800 | [diff] [blame] | 2748 | // Active builtin display needs revalidation |
| 2749 | hwc2_display_t active_builtin_disp_id = GetActiveBuiltinDisplay(); |
Padmanabhan Komanduru | e74cf4f | 2019-04-25 17:38:43 -0700 | [diff] [blame] | 2750 | if (active_builtin_disp_id < HWCCallbacks::kNumDisplays) { |
Padmanabhan Komanduru | f5b7f99 | 2019-07-08 13:33:44 +0530 | [diff] [blame] | 2751 | WaitForResources(delay_hotplug, active_builtin_disp_id, client_id); |
Dileep Marchya | f3ce11f | 2018-04-30 23:35:46 +0530 | [diff] [blame] | 2752 | } |
| 2753 | |
| 2754 | for (auto client_id : pending_hotplugs) { |
Mathew Joseph Karimpanal | bbc700b | 2018-07-19 19:54:24 +0530 | [diff] [blame] | 2755 | DLOGI("Notify hotplug display connected: client id = %d", client_id); |
Dileep Marchya | f3ce11f | 2018-04-30 23:35:46 +0530 | [diff] [blame] | 2756 | callbacks_.Hotplug(client_id, HWC2::Connection::Connected); |
| 2757 | } |
| 2758 | |
Mathew Joseph Karimpanal | 23e2da0 | 2018-11-13 17:44:43 +0530 | [diff] [blame] | 2759 | return status; |
Dileep Marchya | f3ce11f | 2018-04-30 23:35:46 +0530 | [diff] [blame] | 2760 | } |
| 2761 | |
Archit Srivastava | fe060f7 | 2019-05-27 15:51:58 +0530 | [diff] [blame] | 2762 | bool HWCSession::HasHDRSupport(HWCDisplay *hwc_display) { |
| 2763 | // query number of hdr types |
| 2764 | uint32_t out_num_types = 0; |
| 2765 | float out_max_luminance = 0.0f; |
| 2766 | float out_max_average_luminance = 0.0f; |
| 2767 | float out_min_luminance = 0.0f; |
| 2768 | if (hwc_display->GetHdrCapabilities(&out_num_types, nullptr, &out_max_luminance, |
| 2769 | &out_max_average_luminance, &out_min_luminance) |
| 2770 | != HWC2::Error::None) { |
| 2771 | return false; |
| 2772 | } |
| 2773 | |
| 2774 | return (out_num_types > 0); |
| 2775 | } |
| 2776 | |
Dileep Marchya | f3ce11f | 2018-04-30 23:35:46 +0530 | [diff] [blame] | 2777 | int HWCSession::HandleDisconnectedDisplays(HWDisplaysInfo *hw_displays_info) { |
| 2778 | // Destroy pluggable displays which were connected earlier but got disconnected now. |
| 2779 | for (auto &map_info : map_info_pluggable_) { |
| 2780 | bool disconnect = true; // disconnect in case display id is not found in list. |
| 2781 | |
| 2782 | for (auto &iter : *hw_displays_info) { |
| 2783 | auto &info = iter.second; |
| 2784 | if (info.display_id != map_info.sdm_id) { |
| 2785 | continue; |
| 2786 | } |
| 2787 | if (info.is_connected) { |
| 2788 | disconnect = false; |
| 2789 | } |
Mathew Joseph Karimpanal | bbc700b | 2018-07-19 19:54:24 +0530 | [diff] [blame] | 2790 | break; |
Dileep Marchya | f3ce11f | 2018-04-30 23:35:46 +0530 | [diff] [blame] | 2791 | } |
| 2792 | |
| 2793 | if (disconnect) { |
Mathew Joseph Karimpanal | 71ac8a7 | 2018-09-25 22:27:22 +0530 | [diff] [blame] | 2794 | DestroyDisplay(&map_info); |
Dileep Marchya | f3ce11f | 2018-04-30 23:35:46 +0530 | [diff] [blame] | 2795 | } |
| 2796 | } |
| 2797 | |
| 2798 | return 0; |
| 2799 | } |
| 2800 | |
| 2801 | void HWCSession::DestroyDisplay(DisplayMapInfo *map_info) { |
Ramakant Singh | 07254e0 | 2018-10-31 20:45:01 +0530 | [diff] [blame] | 2802 | switch (map_info->disp_type) { |
| 2803 | case kPluggable: |
| 2804 | DestroyPluggableDisplay(map_info); |
| 2805 | break; |
| 2806 | default: |
| 2807 | DestroyNonPluggableDisplay(map_info); |
| 2808 | break; |
| 2809 | } |
| 2810 | } |
Dileep Marchya | f3ce11f | 2018-04-30 23:35:46 +0530 | [diff] [blame] | 2811 | |
Ramakant Singh | 07254e0 | 2018-10-31 20:45:01 +0530 | [diff] [blame] | 2812 | void HWCSession::DestroyPluggableDisplay(DisplayMapInfo *map_info) { |
| 2813 | hwc2_display_t client_id = map_info->client_id; |
| 2814 | |
| 2815 | DLOGI("Notify hotplug display disconnected: client id = %d", client_id); |
| 2816 | callbacks_.Hotplug(client_id, HWC2::Connection::Disconnected); |
Rajavenu Kyatham | 418acc2 | 2019-02-25 15:36:25 +0530 | [diff] [blame] | 2817 | |
Dileep Marchya | f3ce11f | 2018-04-30 23:35:46 +0530 | [diff] [blame] | 2818 | { |
| 2819 | SCOPE_LOCK(locker_[client_id]); |
Dileep Marchya | f3ce11f | 2018-04-30 23:35:46 +0530 | [diff] [blame] | 2820 | auto &hwc_display = hwc_display_[client_id]; |
| 2821 | if (!hwc_display) { |
| 2822 | return; |
| 2823 | } |
Mathew Joseph Karimpanal | bbc700b | 2018-07-19 19:54:24 +0530 | [diff] [blame] | 2824 | DLOGI("Destroy display %d-%d, client id = %d", map_info->sdm_id, map_info->disp_type, |
Ramakant Singh | 07254e0 | 2018-10-31 20:45:01 +0530 | [diff] [blame] | 2825 | client_id); |
Pullakavi Srinivas | 1ae4acb | 2019-11-18 19:33:45 +0530 | [diff] [blame] | 2826 | { |
| 2827 | SCOPE_LOCK(hdr_locker_[client_id]); |
| 2828 | is_hdr_display_[UINT32(client_id)] = false; |
| 2829 | } |
Dileep Marchya | f3ce11f | 2018-04-30 23:35:46 +0530 | [diff] [blame] | 2830 | |
Ramakant Singh | 07254e0 | 2018-10-31 20:45:01 +0530 | [diff] [blame] | 2831 | if (!map_info->test_pattern) { |
| 2832 | HWCDisplayPluggable::Destroy(hwc_display); |
| 2833 | } else { |
| 2834 | HWCDisplayPluggableTest::Destroy(hwc_display); |
Dileep Marchya | f3ce11f | 2018-04-30 23:35:46 +0530 | [diff] [blame] | 2835 | } |
Ramakant Singh | 07254e0 | 2018-10-31 20:45:01 +0530 | [diff] [blame] | 2836 | |
Srinivas Pullakavi | 3c4337f | 2019-07-03 11:24:31 +0530 | [diff] [blame] | 2837 | if (async_powermode_) { |
| 2838 | hwc2_display_t dummy_disp_id = map_hwc_display_.find(client_id)->second; |
| 2839 | auto &hwc_display_dummy = hwc_display_[dummy_disp_id]; |
| 2840 | display_ready_.reset(UINT32(dummy_disp_id)); |
| 2841 | if (hwc_display_dummy) { |
| 2842 | HWCDisplayDummy::Destroy(hwc_display_dummy); |
| 2843 | hwc_display_dummy = nullptr; |
| 2844 | } |
| 2845 | } |
| 2846 | display_ready_.reset(UINT32(client_id)); |
Rajavenu Kyatham | b035224 | 2019-12-17 12:08:55 +0530 | [diff] [blame] | 2847 | pending_power_mode_[client_id] = false; |
Dileep Marchya | f3ce11f | 2018-04-30 23:35:46 +0530 | [diff] [blame] | 2848 | hwc_display = nullptr; |
| 2849 | map_info->Reset(); |
| 2850 | } |
Ramakant Singh | 07254e0 | 2018-10-31 20:45:01 +0530 | [diff] [blame] | 2851 | } |
Dileep Marchya | f3ce11f | 2018-04-30 23:35:46 +0530 | [diff] [blame] | 2852 | |
Ramakant Singh | 07254e0 | 2018-10-31 20:45:01 +0530 | [diff] [blame] | 2853 | void HWCSession::DestroyNonPluggableDisplay(DisplayMapInfo *map_info) { |
| 2854 | hwc2_display_t client_id = map_info->client_id; |
| 2855 | |
| 2856 | SCOPE_LOCK(locker_[client_id]); |
| 2857 | auto &hwc_display = hwc_display_[client_id]; |
| 2858 | if (!hwc_display) { |
| 2859 | return; |
Dileep Marchya | f3ce11f | 2018-04-30 23:35:46 +0530 | [diff] [blame] | 2860 | } |
Ramakant Singh | 07254e0 | 2018-10-31 20:45:01 +0530 | [diff] [blame] | 2861 | DLOGI("Destroy display %d-%d, client id = %d", map_info->sdm_id, map_info->disp_type, |
| 2862 | client_id); |
Pullakavi Srinivas | 1ae4acb | 2019-11-18 19:33:45 +0530 | [diff] [blame] | 2863 | { |
| 2864 | SCOPE_LOCK(hdr_locker_[client_id]); |
| 2865 | is_hdr_display_[UINT32(client_id)] = false; |
| 2866 | } |
| 2867 | |
Ramakant Singh | 07254e0 | 2018-10-31 20:45:01 +0530 | [diff] [blame] | 2868 | switch (map_info->disp_type) { |
| 2869 | case kBuiltIn: |
| 2870 | HWCDisplayBuiltIn::Destroy(hwc_display); |
| 2871 | break; |
| 2872 | default: |
Pullakavi Srinivas | 17495f1 | 2019-09-16 20:25:20 +0530 | [diff] [blame] | 2873 | virtual_display_factory_.Destroy(hwc_display); |
Ramakant Singh | 07254e0 | 2018-10-31 20:45:01 +0530 | [diff] [blame] | 2874 | break; |
| 2875 | } |
| 2876 | |
Srinivas Pullakavi | 3c4337f | 2019-07-03 11:24:31 +0530 | [diff] [blame] | 2877 | if (async_powermode_ && map_info->disp_type == kBuiltIn) { |
| 2878 | hwc2_display_t dummy_disp_id = map_hwc_display_.find(client_id)->second; |
| 2879 | auto &hwc_display_dummy = hwc_display_[dummy_disp_id]; |
| 2880 | display_ready_.reset(UINT32(dummy_disp_id)); |
| 2881 | if (hwc_display_dummy) { |
| 2882 | HWCDisplayDummy::Destroy(hwc_display_dummy); |
| 2883 | hwc_display_dummy = nullptr; |
| 2884 | } |
| 2885 | } |
Rajavenu Kyatham | b035224 | 2019-12-17 12:08:55 +0530 | [diff] [blame] | 2886 | pending_power_mode_[client_id] = false; |
Ramakant Singh | 07254e0 | 2018-10-31 20:45:01 +0530 | [diff] [blame] | 2887 | hwc_display = nullptr; |
Srinivas Pullakavi | 3c4337f | 2019-07-03 11:24:31 +0530 | [diff] [blame] | 2888 | display_ready_.reset(UINT32(client_id)); |
Ramakant Singh | 07254e0 | 2018-10-31 20:45:01 +0530 | [diff] [blame] | 2889 | map_info->Reset(); |
Dileep Marchya | f3ce11f | 2018-04-30 23:35:46 +0530 | [diff] [blame] | 2890 | } |
Saurabh Shah | 04f932b | 2017-10-12 18:47:45 -0700 | [diff] [blame] | 2891 | |
Sushil Chauhan | e3a9fd0 | 2017-10-12 18:00:05 -0700 | [diff] [blame] | 2892 | HWC2::Error HWCSession::ValidateDisplayInternal(hwc2_display_t display, uint32_t *out_num_types, |
| 2893 | uint32_t *out_num_requests) { |
| 2894 | HWCDisplay *hwc_display = hwc_display_[display]; |
Gurpreet Singh Dhami | a427688 | 2019-04-12 10:30:58 -0700 | [diff] [blame] | 2895 | |
| 2896 | DTRACE_SCOPED(); |
Sushil Chauhan | e3a9fd0 | 2017-10-12 18:00:05 -0700 | [diff] [blame] | 2897 | if (hwc_display->IsInternalValidateState()) { |
| 2898 | // Internal Validation has already been done on display, get the Output params. |
| 2899 | return hwc_display->GetValidateDisplayOutput(out_num_types, out_num_requests); |
| 2900 | } |
| 2901 | |
| 2902 | if (display == HWC_DISPLAY_PRIMARY) { |
| 2903 | // TODO(user): This can be moved to HWCDisplayPrimary |
Sushil Chauhan | e3a9fd0 | 2017-10-12 18:00:05 -0700 | [diff] [blame] | 2904 | if (need_invalidate_) { |
Varun Arora | dff7d8d | 2019-08-05 18:12:43 -0700 | [diff] [blame] | 2905 | callbacks_.Refresh(display); |
Sushil Chauhan | e3a9fd0 | 2017-10-12 18:00:05 -0700 | [diff] [blame] | 2906 | need_invalidate_ = false; |
| 2907 | } |
| 2908 | |
| 2909 | if (color_mgr_) { |
| 2910 | color_mgr_->SetColorModeDetailEnhancer(hwc_display_[display]); |
| 2911 | } |
| 2912 | } |
| 2913 | |
| 2914 | return hwc_display->Validate(out_num_types, out_num_requests); |
| 2915 | } |
| 2916 | |
Dileep Marchya | ad66843 | 2019-12-02 10:44:52 +0530 | [diff] [blame] | 2917 | HWC2::Error HWCSession::PresentDisplayInternal(hwc2_display_t display) { |
Sushil Chauhan | e3a9fd0 | 2017-10-12 18:00:05 -0700 | [diff] [blame] | 2918 | HWCDisplay *hwc_display = hwc_display_[display]; |
Gurpreet Singh Dhami | a427688 | 2019-04-12 10:30:58 -0700 | [diff] [blame] | 2919 | |
| 2920 | DTRACE_SCOPED(); |
Sushil Chauhan | e3a9fd0 | 2017-10-12 18:00:05 -0700 | [diff] [blame] | 2921 | // If display is in Skip-Validate state and Validate cannot be skipped, do Internal |
| 2922 | // Validation to optimize for the frames which don't require the Client composition. |
| 2923 | if (hwc_display->IsSkipValidateState() && !hwc_display->CanSkipValidate()) { |
| 2924 | uint32_t out_num_types = 0, out_num_requests = 0; |
Sushil Chauhan | 7bd2066 | 2018-08-20 17:51:32 -0700 | [diff] [blame] | 2925 | hwc_display->SetFastPathComposition(true); |
Sushil Chauhan | e3a9fd0 | 2017-10-12 18:00:05 -0700 | [diff] [blame] | 2926 | HWC2::Error error = ValidateDisplayInternal(display, &out_num_types, &out_num_requests); |
Sushil Chauhan | 181d950 | 2018-12-13 16:40:58 -0800 | [diff] [blame] | 2927 | if ((error != HWC2::Error::None) || hwc_display->HWCClientNeedsValidate()) { |
Sushil Chauhan | e3a9fd0 | 2017-10-12 18:00:05 -0700 | [diff] [blame] | 2928 | hwc_display->SetValidationState(HWCDisplay::kInternalValidate); |
Sushil Chauhan | 7bd2066 | 2018-08-20 17:51:32 -0700 | [diff] [blame] | 2929 | hwc_display->SetFastPathComposition(false); |
Sushil Chauhan | e3a9fd0 | 2017-10-12 18:00:05 -0700 | [diff] [blame] | 2930 | return HWC2::Error::NotValidated; |
| 2931 | } |
| 2932 | } |
Padmanabhan Komanduru | e74cf4f | 2019-04-25 17:38:43 -0700 | [diff] [blame] | 2933 | return HWC2::Error::None; |
Sushil Chauhan | e3a9fd0 | 2017-10-12 18:00:05 -0700 | [diff] [blame] | 2934 | } |
| 2935 | |
Varun Arora | 7c8ee54 | 2018-05-01 20:58:16 -0700 | [diff] [blame] | 2936 | void HWCSession::DisplayPowerReset() { |
Mathew Joseph Karimpanal | 8abb6e0 | 2018-11-20 09:52:49 +0530 | [diff] [blame] | 2937 | // Acquire lock on all displays. |
Padmanabhan Komanduru | e74cf4f | 2019-04-25 17:38:43 -0700 | [diff] [blame] | 2938 | for (hwc2_display_t display = HWC_DISPLAY_PRIMARY; |
| 2939 | display < HWCCallbacks::kNumDisplays; display++) { |
Mathew Joseph Karimpanal | 8abb6e0 | 2018-11-20 09:52:49 +0530 | [diff] [blame] | 2940 | locker_[display].Lock(); |
| 2941 | } |
Varun Arora | 7c8ee54 | 2018-05-01 20:58:16 -0700 | [diff] [blame] | 2942 | |
Mathew Joseph Karimpanal | 8abb6e0 | 2018-11-20 09:52:49 +0530 | [diff] [blame] | 2943 | HWC2::Error status = HWC2::Error::None; |
Padmanabhan Komanduru | e74cf4f | 2019-04-25 17:38:43 -0700 | [diff] [blame] | 2944 | HWC2::PowerMode last_power_mode[HWCCallbacks::kNumDisplays] = {}; |
Varun Arora | 7c8ee54 | 2018-05-01 20:58:16 -0700 | [diff] [blame] | 2945 | |
Padmanabhan Komanduru | e74cf4f | 2019-04-25 17:38:43 -0700 | [diff] [blame] | 2946 | for (hwc2_display_t display = HWC_DISPLAY_PRIMARY; |
| 2947 | display < HWCCallbacks::kNumDisplays; display++) { |
Mathew Joseph Karimpanal | 8abb6e0 | 2018-11-20 09:52:49 +0530 | [diff] [blame] | 2948 | if (hwc_display_[display] != NULL) { |
| 2949 | last_power_mode[display] = hwc_display_[display]->GetCurrentPowerMode(); |
| 2950 | DLOGI("Powering off display = %d", display); |
| 2951 | status = hwc_display_[display]->SetPowerMode(HWC2::PowerMode::Off, |
| 2952 | true /* teardown */); |
| 2953 | if (status != HWC2::Error::None) { |
| 2954 | DLOGE("Power off for display = %d failed with error = %d", display, status); |
Varun Arora | 7c8ee54 | 2018-05-01 20:58:16 -0700 | [diff] [blame] | 2955 | } |
| 2956 | } |
Mathew Joseph Karimpanal | 8abb6e0 | 2018-11-20 09:52:49 +0530 | [diff] [blame] | 2957 | } |
Padmanabhan Komanduru | e74cf4f | 2019-04-25 17:38:43 -0700 | [diff] [blame] | 2958 | for (hwc2_display_t display = HWC_DISPLAY_PRIMARY; |
| 2959 | display < HWCCallbacks::kNumDisplays; display++) { |
Mathew Joseph Karimpanal | 8abb6e0 | 2018-11-20 09:52:49 +0530 | [diff] [blame] | 2960 | if (hwc_display_[display] != NULL) { |
| 2961 | HWC2::PowerMode mode = last_power_mode[display]; |
| 2962 | DLOGI("Setting display %d to mode = %d", display, mode); |
| 2963 | status = hwc_display_[display]->SetPowerMode(mode, false /* teardown */); |
| 2964 | if (status != HWC2::Error::None) { |
| 2965 | DLOGE("%d mode for display = %d failed with error = %d", mode, display, status); |
| 2966 | } |
| 2967 | ColorMode color_mode = hwc_display_[display]->GetCurrentColorMode(); |
| 2968 | status = hwc_display_[display]->SetColorMode(color_mode); |
| 2969 | if (status != HWC2::Error::None) { |
| 2970 | DLOGE("SetColorMode failed for display = %d error = %d", display, status); |
Varun Arora | 7c8ee54 | 2018-05-01 20:58:16 -0700 | [diff] [blame] | 2971 | } |
| 2972 | } |
Mathew Joseph Karimpanal | 8abb6e0 | 2018-11-20 09:52:49 +0530 | [diff] [blame] | 2973 | } |
Varun Arora | 7c8ee54 | 2018-05-01 20:58:16 -0700 | [diff] [blame] | 2974 | |
Padmanabhan Komanduru | f5e6c5d | 2019-04-04 13:56:31 +0530 | [diff] [blame] | 2975 | hwc2_display_t vsync_source = callbacks_.GetVsyncSource(); |
Pullakavi Srinivas | f2a3185 | 2019-04-23 14:32:08 -0700 | [diff] [blame] | 2976 | status = hwc_display_[vsync_source]->SetVsyncEnabled(HWC2::Vsync::Enable); |
Mathew Joseph Karimpanal | 8abb6e0 | 2018-11-20 09:52:49 +0530 | [diff] [blame] | 2977 | if (status != HWC2::Error::None) { |
Pullakavi Srinivas | f2a3185 | 2019-04-23 14:32:08 -0700 | [diff] [blame] | 2978 | DLOGE("Enabling vsync failed for disp: %" PRIu64 " with error = %d", vsync_source, status); |
Mathew Joseph Karimpanal | 8abb6e0 | 2018-11-20 09:52:49 +0530 | [diff] [blame] | 2979 | } |
| 2980 | |
| 2981 | // Release lock on all displays. |
Padmanabhan Komanduru | e74cf4f | 2019-04-25 17:38:43 -0700 | [diff] [blame] | 2982 | for (hwc2_display_t display = HWC_DISPLAY_PRIMARY; |
| 2983 | display < HWCCallbacks::kNumDisplays; display++) { |
Mathew Joseph Karimpanal | 8abb6e0 | 2018-11-20 09:52:49 +0530 | [diff] [blame] | 2984 | locker_[display].Unlock(); |
Varun Arora | 7c8ee54 | 2018-05-01 20:58:16 -0700 | [diff] [blame] | 2985 | } |
Pullakavi Srinivas | f2a3185 | 2019-04-23 14:32:08 -0700 | [diff] [blame] | 2986 | |
Varun Arora | dff7d8d | 2019-08-05 18:12:43 -0700 | [diff] [blame] | 2987 | callbacks_.Refresh(vsync_source); |
Varun Arora | 7c8ee54 | 2018-05-01 20:58:16 -0700 | [diff] [blame] | 2988 | } |
Ramkumar Radhakrishnan | a38b760 | 2018-03-15 14:49:52 -0700 | [diff] [blame] | 2989 | |
Ramkumar Radhakrishnan | 44c6436 | 2018-12-12 13:03:59 -0800 | [diff] [blame] | 2990 | void HWCSession::HandleSecureSession() { |
Mathew Joseph Karimpanal | 71ac8a7 | 2018-09-25 22:27:22 +0530 | [diff] [blame] | 2991 | std::bitset<kSecureMax> secure_sessions = 0; |
| 2992 | { |
Mathew Joseph Karimpanal | b1c1586 | 2019-07-04 11:14:24 +0530 | [diff] [blame] | 2993 | // TODO(user): Revisit if supporting secure display on non-primary. |
Ramkumar Radhakrishnan | 44c6436 | 2018-12-12 13:03:59 -0800 | [diff] [blame] | 2994 | hwc2_display_t active_builtin_disp_id = GetActiveBuiltinDisplay(); |
Padmanabhan Komanduru | e74cf4f | 2019-04-25 17:38:43 -0700 | [diff] [blame] | 2995 | if (active_builtin_disp_id >= HWCCallbacks::kNumDisplays) { |
Ramkumar Radhakrishnan | 44c6436 | 2018-12-12 13:03:59 -0800 | [diff] [blame] | 2996 | return; |
Mathew Joseph Karimpanal | 71ac8a7 | 2018-09-25 22:27:22 +0530 | [diff] [blame] | 2997 | } |
Mathew Joseph Karimpanal | b1c1586 | 2019-07-04 11:14:24 +0530 | [diff] [blame] | 2998 | Locker::ScopeLock lock_pwr(power_state_[active_builtin_disp_id]); |
| 2999 | if (power_state_transition_[active_builtin_disp_id]) { |
| 3000 | // Route all interactions with client to dummy display. |
| 3001 | active_builtin_disp_id = map_hwc_display_.find(active_builtin_disp_id)->second; |
| 3002 | } |
| 3003 | Locker::ScopeLock lock_d(locker_[active_builtin_disp_id]); |
Ramkumar Radhakrishnan | 44c6436 | 2018-12-12 13:03:59 -0800 | [diff] [blame] | 3004 | hwc_display_[active_builtin_disp_id]->GetActiveSecureSession(&secure_sessions); |
Ramkumar Radhakrishnan | a38b760 | 2018-03-15 14:49:52 -0700 | [diff] [blame] | 3005 | } |
| 3006 | |
Mathew Joseph Karimpanal | b1c1586 | 2019-07-04 11:14:24 +0530 | [diff] [blame] | 3007 | if (secure_sessions.any()) { |
| 3008 | secure_session_active_ = true; |
| 3009 | } else if (!secure_session_active_) { |
| 3010 | // No secure session active. No secure session transition to handle. Skip remaining steps. |
| 3011 | return; |
| 3012 | } |
| 3013 | |
Ramkumar Radhakrishnan | 44c6436 | 2018-12-12 13:03:59 -0800 | [diff] [blame] | 3014 | // If it is called during primary prepare/commit, we need to pause any ongoing commit on |
Ramkumar Radhakrishnan | a38b760 | 2018-03-15 14:49:52 -0700 | [diff] [blame] | 3015 | // external/virtual display. |
Padmanabhan Komanduru | e74cf4f | 2019-04-25 17:38:43 -0700 | [diff] [blame] | 3016 | for (hwc2_display_t display = HWC_DISPLAY_PRIMARY; |
| 3017 | display < HWCCallbacks::kNumDisplays; display++) { |
Mathew Joseph Karimpanal | 8abb6e0 | 2018-11-20 09:52:49 +0530 | [diff] [blame] | 3018 | Locker::ScopeLock lock_d(locker_[display]); |
| 3019 | if (hwc_display_[display]) { |
Mathew Joseph Karimpanal | b1c1586 | 2019-07-04 11:14:24 +0530 | [diff] [blame] | 3020 | hwc_display_[display]->HandleSecureSession(secure_sessions, &pending_power_mode_[display]); |
Ramkumar Radhakrishnan | a38b760 | 2018-03-15 14:49:52 -0700 | [diff] [blame] | 3021 | } |
Ramkumar Radhakrishnan | a38b760 | 2018-03-15 14:49:52 -0700 | [diff] [blame] | 3022 | } |
| 3023 | } |
| 3024 | |
Dileep Marchya | ad66843 | 2019-12-02 10:44:52 +0530 | [diff] [blame] | 3025 | void HWCSession::HandlePendingPowerMode(hwc2_display_t disp_id, |
| 3026 | const shared_ptr<Fence> &retire_fence) { |
Mathew Joseph Karimpanal | b1c1586 | 2019-07-04 11:14:24 +0530 | [diff] [blame] | 3027 | if (!secure_session_active_) { |
| 3028 | // No secure session active. Skip remaining steps. |
| 3029 | return; |
| 3030 | } |
| 3031 | |
Ramkumar Radhakrishnan | 44c6436 | 2018-12-12 13:03:59 -0800 | [diff] [blame] | 3032 | hwc2_display_t active_builtin_disp_id = GetActiveBuiltinDisplay(); |
| 3033 | if (disp_id != active_builtin_disp_id) { |
Ramkumar Radhakrishnan | a38b760 | 2018-03-15 14:49:52 -0700 | [diff] [blame] | 3034 | return; |
| 3035 | } |
Mathew Joseph Karimpanal | 71ac8a7 | 2018-09-25 22:27:22 +0530 | [diff] [blame] | 3036 | |
Mathew Joseph Karimpanal | b1c1586 | 2019-07-04 11:14:24 +0530 | [diff] [blame] | 3037 | Locker::ScopeLock lock_d(locker_[active_builtin_disp_id]); |
| 3038 | bool pending_power_mode = false; |
| 3039 | for (hwc2_display_t display = HWC_DISPLAY_PRIMARY + 1; |
Padmanabhan Komanduru | e74cf4f | 2019-04-25 17:38:43 -0700 | [diff] [blame] | 3040 | display < HWCCallbacks::kNumDisplays; display++) { |
Ramkumar Radhakrishnan | 44c6436 | 2018-12-12 13:03:59 -0800 | [diff] [blame] | 3041 | if (display != active_builtin_disp_id) { |
| 3042 | Locker::ScopeLock lock_d(locker_[display]); |
Mathew Joseph Karimpanal | b1c1586 | 2019-07-04 11:14:24 +0530 | [diff] [blame] | 3043 | if (pending_power_mode_[display]) { |
| 3044 | pending_power_mode = true; |
Ramkumar Radhakrishnan | 44c6436 | 2018-12-12 13:03:59 -0800 | [diff] [blame] | 3045 | break; |
| 3046 | } |
Ramkumar Radhakrishnan | a38b760 | 2018-03-15 14:49:52 -0700 | [diff] [blame] | 3047 | } |
| 3048 | } |
Dileep Marchya | ad66843 | 2019-12-02 10:44:52 +0530 | [diff] [blame] | 3049 | |
| 3050 | if (!pending_power_mode) { |
Mathew Joseph Karimpanal | 71ac8a7 | 2018-09-25 22:27:22 +0530 | [diff] [blame] | 3051 | return; |
Ramkumar Radhakrishnan | a38b760 | 2018-03-15 14:49:52 -0700 | [diff] [blame] | 3052 | } |
| 3053 | |
Dileep Marchya | ad66843 | 2019-12-02 10:44:52 +0530 | [diff] [blame] | 3054 | // retire fence is set only after successful primary commit, So check for retire fence to know |
| 3055 | // non secure commit went through to notify driver to change the CRTC mode to non secure. |
| 3056 | // Otherwise any commit to non-primary display would fail. |
| 3057 | if (retire_fence == nullptr) { |
| 3058 | return; |
| 3059 | } |
| 3060 | |
| 3061 | Fence::Wait(retire_fence); |
| 3062 | |
Mathew Joseph Karimpanal | b1c1586 | 2019-07-04 11:14:24 +0530 | [diff] [blame] | 3063 | for (hwc2_display_t display = HWC_DISPLAY_PRIMARY + 1; |
Padmanabhan Komanduru | e74cf4f | 2019-04-25 17:38:43 -0700 | [diff] [blame] | 3064 | display < HWCCallbacks::kNumDisplays; display++) { |
Ramkumar Radhakrishnan | 44c6436 | 2018-12-12 13:03:59 -0800 | [diff] [blame] | 3065 | if (display != active_builtin_disp_id) { |
| 3066 | Locker::ScopeLock lock_d(locker_[display]); |
Mathew Joseph Karimpanal | b1c1586 | 2019-07-04 11:14:24 +0530 | [diff] [blame] | 3067 | if (pending_power_mode_[display] && hwc_display_[display]) { |
| 3068 | HWC2::Error error = |
| 3069 | hwc_display_[display]->SetPowerMode(hwc_display_[display]->GetPendingPowerMode(), false); |
| 3070 | if (HWC2::Error::None == error) { |
| 3071 | pending_power_mode_[display] = false; |
| 3072 | hwc_display_[display]->ClearPendingPowerMode(); |
| 3073 | pending_refresh_.set(UINT32(HWC_DISPLAY_PRIMARY)); |
| 3074 | } else { |
| 3075 | DLOGE("SetDisplayStatus error = %d (%s)", error, to_string(error).c_str()); |
Ramkumar Radhakrishnan | 44c6436 | 2018-12-12 13:03:59 -0800 | [diff] [blame] | 3076 | } |
Ramkumar Radhakrishnan | a38b760 | 2018-03-15 14:49:52 -0700 | [diff] [blame] | 3077 | } |
| 3078 | } |
| 3079 | } |
Mathew Joseph Karimpanal | b1c1586 | 2019-07-04 11:14:24 +0530 | [diff] [blame] | 3080 | secure_session_active_ = false; |
Ramkumar Radhakrishnan | a38b760 | 2018-03-15 14:49:52 -0700 | [diff] [blame] | 3081 | } |
| 3082 | |
Dileep Marchya | ad66843 | 2019-12-02 10:44:52 +0530 | [diff] [blame] | 3083 | void HWCSession::HandlePendingHotplug(hwc2_display_t disp_id, |
| 3084 | const shared_ptr<Fence> &retire_fence) { |
Ramkumar Radhakrishnan | 44c6436 | 2018-12-12 13:03:59 -0800 | [diff] [blame] | 3085 | hwc2_display_t active_builtin_disp_id = GetActiveBuiltinDisplay(); |
| 3086 | if (disp_id != active_builtin_disp_id || |
Mathew Joseph Karimpanal | b1c1586 | 2019-07-04 11:14:24 +0530 | [diff] [blame] | 3087 | (kHotPlugNone == pending_hotplug_event_ && !destroy_virtual_disp_pending_)) { |
Ramkumar Radhakrishnan | a38b760 | 2018-03-15 14:49:52 -0700 | [diff] [blame] | 3088 | return; |
| 3089 | } |
Rajavenu Kyatham | e45d1b7 | 2018-06-27 14:46:44 +0530 | [diff] [blame] | 3090 | |
Ramkumar Radhakrishnan | a38b760 | 2018-03-15 14:49:52 -0700 | [diff] [blame] | 3091 | std :: bitset < kSecureMax > secure_sessions = 0; |
Padmanabhan Komanduru | e74cf4f | 2019-04-25 17:38:43 -0700 | [diff] [blame] | 3092 | if (active_builtin_disp_id < HWCCallbacks::kNumDisplays) { |
Mathew Joseph Karimpanal | b1c1586 | 2019-07-04 11:14:24 +0530 | [diff] [blame] | 3093 | Locker::ScopeLock lock_d(locker_[active_builtin_disp_id]); |
Ramkumar Radhakrishnan | 44c6436 | 2018-12-12 13:03:59 -0800 | [diff] [blame] | 3094 | hwc_display_[active_builtin_disp_id]->GetActiveSecureSession(&secure_sessions); |
| 3095 | } |
| 3096 | |
Padmanabhan Komanduru | e74cf4f | 2019-04-25 17:38:43 -0700 | [diff] [blame] | 3097 | if (secure_sessions.any() || active_builtin_disp_id >= HWCCallbacks::kNumDisplays) { |
Ramkumar Radhakrishnan | 44c6436 | 2018-12-12 13:03:59 -0800 | [diff] [blame] | 3098 | return; |
| 3099 | } |
| 3100 | |
Mathew Joseph Karimpanal | b1c1586 | 2019-07-04 11:14:24 +0530 | [diff] [blame] | 3101 | if (destroy_virtual_disp_pending_ || kHotPlugEvent == pending_hotplug_event_) { |
Dileep Marchya | ad66843 | 2019-12-02 10:44:52 +0530 | [diff] [blame] | 3102 | Fence::Wait(retire_fence); |
| 3103 | |
Ramkumar Radhakrishnan | 44c6436 | 2018-12-12 13:03:59 -0800 | [diff] [blame] | 3104 | // Destroy the pending virtual display if secure session not present. |
| 3105 | if (destroy_virtual_disp_pending_) { |
| 3106 | for (auto &map_info : map_info_virtual_) { |
| 3107 | DestroyDisplay(&map_info); |
| 3108 | destroy_virtual_disp_pending_ = false; |
Padmanabhan Komanduru | f5b7f99 | 2019-07-08 13:33:44 +0530 | [diff] [blame] | 3109 | virtual_id_ = HWCCallbacks::kNumDisplays; |
Ramkumar Radhakrishnan | 44c6436 | 2018-12-12 13:03:59 -0800 | [diff] [blame] | 3110 | } |
Ramkumar Radhakrishnan | a38b760 | 2018-03-15 14:49:52 -0700 | [diff] [blame] | 3111 | } |
Ramkumar Radhakrishnan | 44c6436 | 2018-12-12 13:03:59 -0800 | [diff] [blame] | 3112 | // Handle connect/disconnect hotplugs if secure session is not present. |
| 3113 | hwc2_display_t virtual_display_idx = (hwc2_display_t)GetDisplayIndex(qdutils::DISPLAY_VIRTUAL); |
Mathew Joseph Karimpanal | b1c1586 | 2019-07-04 11:14:24 +0530 | [diff] [blame] | 3114 | if (!hwc_display_[virtual_display_idx] && kHotPlugEvent == pending_hotplug_event_) { |
Mathew Joseph Karimpanal | abe3b3d | 2018-11-27 17:25:40 +0530 | [diff] [blame] | 3115 | // Handle deferred hotplug event. |
| 3116 | int32_t err = pluggable_handler_lock_.TryLock(); |
| 3117 | if (!err) { |
| 3118 | // Do hotplug handling in a different thread to avoid blocking PresentDisplay. |
| 3119 | std::thread(&HWCSession::HandlePluggableDisplays, this, true).detach(); |
| 3120 | pluggable_handler_lock_.Unlock(); |
| 3121 | } else { |
| 3122 | // EBUSY means another thread is already handling hotplug. Skip deferred hotplug handling. |
| 3123 | if (EBUSY != err) { |
| 3124 | DLOGW("Failed to acquire pluggable display handler lock. Error %d '%s'.", err, |
| 3125 | strerror(abs(err))); |
| 3126 | } |
Ramkumar Radhakrishnan | 44c6436 | 2018-12-12 13:03:59 -0800 | [diff] [blame] | 3127 | } |
Mathew Joseph Karimpanal | 71ac8a7 | 2018-09-25 22:27:22 +0530 | [diff] [blame] | 3128 | } |
Mathew Joseph Karimpanal | 71ac8a7 | 2018-09-25 22:27:22 +0530 | [diff] [blame] | 3129 | } |
Ramkumar Radhakrishnan | a38b760 | 2018-03-15 14:49:52 -0700 | [diff] [blame] | 3130 | } |
| 3131 | |
Rajavenu Kyatham | 42d11cb | 2019-04-16 13:03:29 +0530 | [diff] [blame] | 3132 | int32_t HWCSession::GetReadbackBufferAttributes(hwc2_display_t display, int32_t *format, |
| 3133 | int32_t *dataspace) { |
| 3134 | if (!format || !dataspace) { |
Sushil Chauhan | 0652158 | 2018-03-19 14:00:23 -0700 | [diff] [blame] | 3135 | return HWC2_ERROR_BAD_PARAMETER; |
| 3136 | } |
| 3137 | |
| 3138 | if (display != HWC_DISPLAY_PRIMARY) { |
| 3139 | return HWC2_ERROR_BAD_DISPLAY; |
| 3140 | } |
| 3141 | |
Rajavenu Kyatham | 42d11cb | 2019-04-16 13:03:29 +0530 | [diff] [blame] | 3142 | HWCDisplay *hwc_display = hwc_display_[display]; |
Sushil Chauhan | 0652158 | 2018-03-19 14:00:23 -0700 | [diff] [blame] | 3143 | |
Sushil Chauhan | fea3e90 | 2018-07-31 15:34:48 -0700 | [diff] [blame] | 3144 | if (hwc_display) { |
| 3145 | *format = HAL_PIXEL_FORMAT_RGB_888; |
Arun Kumar K.R | 5b82155 | 2018-12-07 08:00:15 +0530 | [diff] [blame] | 3146 | *dataspace = GetDataspaceFromColorMode(hwc_display->GetCurrentColorMode()); |
Sushil Chauhan | fea3e90 | 2018-07-31 15:34:48 -0700 | [diff] [blame] | 3147 | return HWC2_ERROR_NONE; |
| 3148 | } |
| 3149 | |
| 3150 | return HWC2_ERROR_BAD_DISPLAY; |
Sushil Chauhan | 0652158 | 2018-03-19 14:00:23 -0700 | [diff] [blame] | 3151 | } |
| 3152 | |
Rajavenu Kyatham | 42d11cb | 2019-04-16 13:03:29 +0530 | [diff] [blame] | 3153 | int32_t HWCSession::SetReadbackBuffer(hwc2_display_t display, const native_handle_t *buffer, |
Rajavenu Kyatham | 7338b9e | 2019-12-30 19:52:16 +0530 | [diff] [blame] | 3154 | const shared_ptr<Fence> &acquire_fence) { |
Sushil Chauhan | 0652158 | 2018-03-19 14:00:23 -0700 | [diff] [blame] | 3155 | if (!buffer) { |
| 3156 | return HWC2_ERROR_BAD_PARAMETER; |
| 3157 | } |
| 3158 | |
| 3159 | if (display != HWC_DISPLAY_PRIMARY) { |
| 3160 | return HWC2_ERROR_BAD_DISPLAY; |
| 3161 | } |
| 3162 | |
Sushil Chauhan | 0a1b15d | 2019-08-23 12:58:18 -0700 | [diff] [blame] | 3163 | int external_dpy_index = GetDisplayIndex(qdutils::DISPLAY_EXTERNAL); |
| 3164 | int virtual_dpy_index = GetDisplayIndex(qdutils::DISPLAY_VIRTUAL); |
| 3165 | if (((external_dpy_index != -1) && hwc_display_[external_dpy_index]) || |
| 3166 | ((virtual_dpy_index != -1) && hwc_display_[virtual_dpy_index])) { |
Sushil Chauhan | 062a7a4 | 2018-04-25 22:27:52 -0700 | [diff] [blame] | 3167 | return HWC2_ERROR_UNSUPPORTED; |
| 3168 | } |
| 3169 | |
Rajavenu Kyatham | 42d11cb | 2019-04-16 13:03:29 +0530 | [diff] [blame] | 3170 | return CallDisplayFunction(display, &HWCDisplay::SetReadbackBuffer, buffer, acquire_fence, |
Dileep Marchya | cb2a3a9 | 2019-06-21 17:30:50 +0530 | [diff] [blame] | 3171 | false, kCWBClientComposer); |
Sushil Chauhan | 0652158 | 2018-03-19 14:00:23 -0700 | [diff] [blame] | 3172 | } |
| 3173 | |
Rajavenu Kyatham | 7338b9e | 2019-12-30 19:52:16 +0530 | [diff] [blame] | 3174 | int32_t HWCSession::GetReadbackBufferFence(hwc2_display_t display, |
| 3175 | shared_ptr<Fence> *release_fence) { |
Sushil Chauhan | 0652158 | 2018-03-19 14:00:23 -0700 | [diff] [blame] | 3176 | if (!release_fence) { |
| 3177 | return HWC2_ERROR_BAD_PARAMETER; |
| 3178 | } |
| 3179 | |
| 3180 | if (display != HWC_DISPLAY_PRIMARY) { |
| 3181 | return HWC2_ERROR_BAD_DISPLAY; |
| 3182 | } |
| 3183 | |
Rajavenu Kyatham | 42d11cb | 2019-04-16 13:03:29 +0530 | [diff] [blame] | 3184 | return CallDisplayFunction(display, &HWCDisplay::GetReadbackBufferFence, release_fence); |
Sushil Chauhan | 0652158 | 2018-03-19 14:00:23 -0700 | [diff] [blame] | 3185 | } |
| 3186 | |
Rajavenu Kyatham | 42d11cb | 2019-04-16 13:03:29 +0530 | [diff] [blame] | 3187 | int32_t HWCSession::GetDisplayIdentificationData(hwc2_display_t display, uint8_t *outPort, |
| 3188 | uint32_t *outDataSize, uint8_t *outData) { |
Varun Arora | 6ba9eda | 2019-02-07 17:59:32 -0800 | [diff] [blame] | 3189 | if (!outPort || !outDataSize) { |
| 3190 | return HWC2_ERROR_BAD_PARAMETER; |
| 3191 | } |
| 3192 | |
Padmanabhan Komanduru | e74cf4f | 2019-04-25 17:38:43 -0700 | [diff] [blame] | 3193 | if (display >= HWCCallbacks::kNumDisplays) { |
Varun Arora | 6ba9eda | 2019-02-07 17:59:32 -0800 | [diff] [blame] | 3194 | return HWC2_ERROR_BAD_DISPLAY; |
| 3195 | } |
| 3196 | |
Rajavenu Kyatham | 42d11cb | 2019-04-16 13:03:29 +0530 | [diff] [blame] | 3197 | return CallDisplayFunction(display, &HWCDisplay::GetDisplayIdentificationData, outPort, |
Varun Arora | 6ba9eda | 2019-02-07 17:59:32 -0800 | [diff] [blame] | 3198 | outDataSize, outData); |
| 3199 | } |
| 3200 | |
Naseer Ahmed | 8584a0f | 2020-02-19 22:23:30 -0500 | [diff] [blame] | 3201 | int32_t HWCSession::GetDisplayCapabilities(hwc2_display_t display, |
| 3202 | hidl_vec<HwcDisplayCapability> *capabilities) { |
| 3203 | if (!capabilities) { |
Varun Arora | 9da54ef | 2019-05-03 16:17:22 -0700 | [diff] [blame] | 3204 | return HWC2_ERROR_BAD_PARAMETER; |
| 3205 | } |
| 3206 | |
| 3207 | if (display >= HWCCallbacks::kNumDisplays) { |
| 3208 | return HWC2_ERROR_BAD_DISPLAY; |
| 3209 | } |
| 3210 | |
Rajavenu Kyatham | 42d11cb | 2019-04-16 13:03:29 +0530 | [diff] [blame] | 3211 | if (!hwc_display_[display]) { |
Varun Arora | 9da54ef | 2019-05-03 16:17:22 -0700 | [diff] [blame] | 3212 | DLOGE("Expected valid hwc_display"); |
| 3213 | return HWC2_ERROR_BAD_PARAMETER; |
| 3214 | } |
Naseer Ahmed | 8584a0f | 2020-02-19 22:23:30 -0500 | [diff] [blame] | 3215 | |
Rajavenu Kyatham | 42d11cb | 2019-04-16 13:03:29 +0530 | [diff] [blame] | 3216 | bool isBuiltin = (hwc_display_[display]->GetDisplayClass() == DISPLAY_CLASS_BUILTIN); |
Naseer Ahmed | 8584a0f | 2020-02-19 22:23:30 -0500 | [diff] [blame] | 3217 | if (isBuiltin) { |
| 3218 | capabilities->resize(4); |
| 3219 | // TODO(user): Handle SKIP_CLIENT_COLOR_TRANSFORM based on DSPP availability |
| 3220 | std::vector<HwcDisplayCapability> caps{ |
| 3221 | HwcDisplayCapability::SKIP_CLIENT_COLOR_TRANSFORM, HwcDisplayCapability::DOZE, |
| 3222 | HwcDisplayCapability::BRIGHTNESS, HwcDisplayCapability::PROTECTED_CONTENTS}; |
| 3223 | capabilities->setToExternal(caps.data(), caps.size()); |
Varun Arora | 9da54ef | 2019-05-03 16:17:22 -0700 | [diff] [blame] | 3224 | } |
Naseer Ahmed | 8584a0f | 2020-02-19 22:23:30 -0500 | [diff] [blame] | 3225 | return HWC2_ERROR_NONE; |
| 3226 | } |
| 3227 | |
| 3228 | int32_t HWCSession::GetDisplayConnectionType(hwc2_display_t display, |
| 3229 | HwcDisplayConnectionType *type) { |
| 3230 | if (display >= HWCCallbacks::kNumDisplays) { |
| 3231 | return HWC2_ERROR_BAD_DISPLAY; |
| 3232 | } |
| 3233 | |
| 3234 | if (!type) { |
| 3235 | return HWC2_ERROR_BAD_PARAMETER; |
| 3236 | } |
| 3237 | |
| 3238 | if (!hwc_display_[display]) { |
| 3239 | DLOGE("Expected valid hwc_display"); |
| 3240 | return HWC2_ERROR_BAD_PARAMETER; |
| 3241 | } |
| 3242 | *type = HwcDisplayConnectionType::EXTERNAL; |
| 3243 | if (hwc_display_[display]->GetDisplayClass() == DISPLAY_CLASS_BUILTIN) { |
| 3244 | *type = HwcDisplayConnectionType::INTERNAL; |
| 3245 | } |
| 3246 | |
| 3247 | return HWC2_ERROR_NONE; |
Varun Arora | 9da54ef | 2019-05-03 16:17:22 -0700 | [diff] [blame] | 3248 | } |
| 3249 | |
Rajavenu Kyatham | 42d11cb | 2019-04-16 13:03:29 +0530 | [diff] [blame] | 3250 | int32_t HWCSession::GetDisplayBrightnessSupport(hwc2_display_t display, bool *outSupport) { |
| 3251 | if (!outSupport) { |
Varun Arora | 9da54ef | 2019-05-03 16:17:22 -0700 | [diff] [blame] | 3252 | return HWC2_ERROR_BAD_PARAMETER; |
| 3253 | } |
| 3254 | |
| 3255 | if (display >= HWCCallbacks::kNumDisplays) { |
| 3256 | return HWC2_ERROR_BAD_DISPLAY; |
| 3257 | } |
| 3258 | |
Rajavenu Kyatham | 42d11cb | 2019-04-16 13:03:29 +0530 | [diff] [blame] | 3259 | if (!hwc_display_[display]) { |
Varun Arora | 9da54ef | 2019-05-03 16:17:22 -0700 | [diff] [blame] | 3260 | DLOGE("Expected valid hwc_display"); |
| 3261 | return HWC2_ERROR_BAD_PARAMETER; |
| 3262 | } |
Rajavenu Kyatham | 42d11cb | 2019-04-16 13:03:29 +0530 | [diff] [blame] | 3263 | *outSupport = (hwc_display_[display]->GetDisplayClass() == DISPLAY_CLASS_BUILTIN); |
Varun Arora | 9da54ef | 2019-05-03 16:17:22 -0700 | [diff] [blame] | 3264 | return HWC2_ERROR_NONE; |
| 3265 | } |
| 3266 | |
Rajavenu Kyatham | 42d11cb | 2019-04-16 13:03:29 +0530 | [diff] [blame] | 3267 | int32_t HWCSession::SetDisplayBrightness(hwc2_display_t display, float brightness) { |
Sushil Chauhan | ab3c5c5 | 2019-07-12 14:54:29 -0700 | [diff] [blame] | 3268 | if (display >= HWCCallbacks::kNumDisplays) { |
| 3269 | return HWC2_ERROR_BAD_DISPLAY; |
| 3270 | } |
| 3271 | |
| 3272 | if (!hwc_display_[display]) { |
| 3273 | return HWC2_ERROR_BAD_PARAMETER; |
| 3274 | } |
| 3275 | |
| 3276 | return INT32(hwc_display_[display]->SetPanelBrightness(brightness)); |
Varun Arora | 75c05f0 | 2019-05-14 14:53:37 -0700 | [diff] [blame] | 3277 | } |
| 3278 | |
Sushil Chauhan | 380a59d | 2018-03-19 15:47:50 -0700 | [diff] [blame] | 3279 | android::status_t HWCSession::SetQSyncMode(const android::Parcel *input_parcel) { |
| 3280 | auto mode = input_parcel->readInt32(); |
Sushil Chauhan | 380a59d | 2018-03-19 15:47:50 -0700 | [diff] [blame] | 3281 | |
| 3282 | QSyncMode qsync_mode = kQSyncModeNone; |
| 3283 | switch (mode) { |
| 3284 | case qService::IQService::QSYNC_MODE_NONE: |
| 3285 | qsync_mode = kQSyncModeNone; |
| 3286 | break; |
| 3287 | case qService::IQService::QSYNC_MODE_CONTINUOUS: |
| 3288 | qsync_mode = kQSyncModeContinuous; |
| 3289 | break; |
| 3290 | case qService::IQService::QSYNC_MODE_ONESHOT: |
| 3291 | qsync_mode = kQsyncModeOneShot; |
| 3292 | break; |
| 3293 | default: |
| 3294 | DLOGE("Qsync mode not supported %d", mode); |
| 3295 | return -EINVAL; |
| 3296 | } |
Rajavenu Kyatham | 42d11cb | 2019-04-16 13:03:29 +0530 | [diff] [blame] | 3297 | return CallDisplayFunction(HWC_DISPLAY_PRIMARY, &HWCDisplay::SetQSyncMode, qsync_mode); |
Sushil Chauhan | 380a59d | 2018-03-19 15:47:50 -0700 | [diff] [blame] | 3298 | } |
| 3299 | |
Mahesh Aia | f3a1f99 | 2019-01-16 13:07:42 -0800 | [diff] [blame] | 3300 | void HWCSession::UpdateThrottlingRate() { |
| 3301 | uint32_t new_min = 0; |
| 3302 | |
Padmanabhan Komanduru | e74cf4f | 2019-04-25 17:38:43 -0700 | [diff] [blame] | 3303 | for (int i=0; i < HWCCallbacks::kNumDisplays; i++) { |
Mahesh Aia | f3a1f99 | 2019-01-16 13:07:42 -0800 | [diff] [blame] | 3304 | auto &display = hwc_display_[i]; |
| 3305 | if (!display) |
| 3306 | continue; |
| 3307 | if (display->GetCurrentPowerMode() != HWC2::PowerMode::Off) |
| 3308 | new_min = (new_min == 0) ? display->GetMaxRefreshRate() : |
| 3309 | std::min(new_min, display->GetMaxRefreshRate()); |
| 3310 | } |
| 3311 | |
| 3312 | SetNewThrottlingRate(new_min); |
| 3313 | } |
| 3314 | |
| 3315 | void HWCSession::SetNewThrottlingRate(const uint32_t new_rate) { |
| 3316 | if (new_rate !=0 && throttling_refresh_rate_ != new_rate) { |
| 3317 | HWCDisplay::SetThrottlingRefreshRate(new_rate); |
| 3318 | throttling_refresh_rate_ = new_rate; |
| 3319 | } |
| 3320 | } |
| 3321 | |
Ramkumar Radhakrishnan | f985d48 | 2018-07-23 18:10:41 -0700 | [diff] [blame] | 3322 | android::status_t HWCSession::SetIdlePC(const android::Parcel *input_parcel) { |
| 3323 | auto enable = input_parcel->readInt32(); |
| 3324 | auto synchronous = input_parcel->readInt32(); |
| 3325 | |
Padmanabhan Komanduru | 9e97162 | 2020-02-10 13:09:34 +0530 | [diff] [blame] | 3326 | return static_cast<android::status_t>(ControlIdlePowerCollapse(enable, synchronous)); |
Ramkumar Radhakrishnan | f985d48 | 2018-07-23 18:10:41 -0700 | [diff] [blame] | 3327 | } |
| 3328 | |
Ramkumar Radhakrishnan | 44c6436 | 2018-12-12 13:03:59 -0800 | [diff] [blame] | 3329 | hwc2_display_t HWCSession::GetActiveBuiltinDisplay() { |
Mathew Joseph Karimpanal | b1c1586 | 2019-07-04 11:14:24 +0530 | [diff] [blame] | 3330 | hwc2_display_t active_display = HWCCallbacks::kNumDisplays; |
Mathew Joseph Karimpanal | 1d5a23f | 2019-04-25 15:46:11 -0700 | [diff] [blame] | 3331 | // Get first active display among primary and built-in displays. |
| 3332 | std::vector<DisplayMapInfo> map_info = {map_info_primary_}; |
| 3333 | std::copy(map_info_builtin_.begin(), map_info_builtin_.end(), std::back_inserter(map_info)); |
| 3334 | |
| 3335 | for (auto &info : map_info) { |
Mathew Joseph Karimpanal | b1c1586 | 2019-07-04 11:14:24 +0530 | [diff] [blame] | 3336 | hwc2_display_t target_display = info.client_id; |
| 3337 | SCOPE_LOCK(power_state_[target_display]); |
| 3338 | if (power_state_transition_[target_display]) { |
| 3339 | // Route all interactions with client to dummy display. |
| 3340 | target_display = map_hwc_display_.find(target_display)->second; |
| 3341 | } |
| 3342 | Locker::ScopeLock lock_d(locker_[target_display]); |
| 3343 | auto &hwc_display = hwc_display_[target_display]; |
Mathew Joseph Karimpanal | 1d5a23f | 2019-04-25 15:46:11 -0700 | [diff] [blame] | 3344 | if (hwc_display && hwc_display->GetCurrentPowerMode() != HWC2::PowerMode::Off) { |
Mathew Joseph Karimpanal | b1c1586 | 2019-07-04 11:14:24 +0530 | [diff] [blame] | 3345 | active_display = info.client_id; |
Mathew Joseph Karimpanal | 1d5a23f | 2019-04-25 15:46:11 -0700 | [diff] [blame] | 3346 | break; |
| 3347 | } |
Ramkumar Radhakrishnan | 44c6436 | 2018-12-12 13:03:59 -0800 | [diff] [blame] | 3348 | } |
Mathew Joseph Karimpanal | 1d5a23f | 2019-04-25 15:46:11 -0700 | [diff] [blame] | 3349 | |
Mathew Joseph Karimpanal | b1c1586 | 2019-07-04 11:14:24 +0530 | [diff] [blame] | 3350 | return active_display; |
Ramkumar Radhakrishnan | 44c6436 | 2018-12-12 13:03:59 -0800 | [diff] [blame] | 3351 | } |
| 3352 | |
Xu Yang | 45d0abf | 2019-07-05 11:34:06 +0800 | [diff] [blame] | 3353 | int32_t HWCSession::SetDisplayBrightnessScale(const android::Parcel *input_parcel) { |
| 3354 | auto display = input_parcel->readInt32(); |
| 3355 | auto level = input_parcel->readInt32(); |
| 3356 | if (level < 0 || level > kBrightnessScaleMax) { |
| 3357 | DLOGE("Invalid backlight scale level %d", level); |
| 3358 | return -EINVAL; |
| 3359 | } |
| 3360 | auto bl_scale = level * kSvBlScaleMax / kBrightnessScaleMax; |
| 3361 | auto error = CallDisplayFunction(display, &HWCDisplay::SetBLScale, (uint32_t)bl_scale); |
| 3362 | if (INT32(error) == HWC2_ERROR_NONE) { |
| 3363 | callbacks_.Refresh(display); |
| 3364 | } |
| 3365 | |
| 3366 | return INT32(error); |
| 3367 | } |
| 3368 | |
Pullakavi Srinivas | 2d55f3a | 2019-07-16 14:49:06 +0530 | [diff] [blame] | 3369 | void HWCSession::NotifyClientStatus(bool connected) { |
| 3370 | for (uint32_t i = 0; i < HWCCallbacks::kNumDisplays; i++) { |
| 3371 | if (!hwc_display_[i]) { |
| 3372 | continue; |
| 3373 | } |
| 3374 | SCOPE_LOCK(locker_[i]); |
| 3375 | hwc_display_[i]->NotifyClientStatus(connected); |
| 3376 | } |
| 3377 | } |
| 3378 | |
Padmanabhan Komanduru | f5b7f99 | 2019-07-08 13:33:44 +0530 | [diff] [blame] | 3379 | void HWCSession::WaitForResources(bool wait_for_resources, hwc2_display_t active_builtin_id, |
| 3380 | hwc2_display_t display_id) { |
| 3381 | { |
| 3382 | SEQUENCE_WAIT_SCOPE_LOCK(locker_[active_builtin_id]); |
| 3383 | hwc_display_[active_builtin_id]->ResetValidation(); |
| 3384 | } |
| 3385 | |
| 3386 | if (wait_for_resources) { |
| 3387 | bool res_wait = true; |
| 3388 | do { |
| 3389 | if (client_connected_) { |
| 3390 | Refresh(active_builtin_id); |
| 3391 | } |
| 3392 | { |
| 3393 | std::unique_lock<std::mutex> caller_lock(hotplug_mutex_); |
| 3394 | hotplug_cv_.wait(caller_lock); |
| 3395 | } |
| 3396 | res_wait = hwc_display_[display_id]->CheckResourceState(); |
| 3397 | } while (res_wait); |
| 3398 | } |
| 3399 | } |
Padmanabhan Komanduru | 9e97162 | 2020-02-10 13:09:34 +0530 | [diff] [blame] | 3400 | |
Sushil Chauhan | dbd8db4 | 2020-02-28 13:07:48 -0800 | [diff] [blame] | 3401 | int32_t HWCSession::GetDisplayVsyncPeriod(hwc2_display_t disp, VsyncPeriodNanos *vsync_period) { |
| 3402 | if (vsync_period == nullptr) { |
| 3403 | return HWC2_ERROR_BAD_PARAMETER; |
| 3404 | } |
| 3405 | |
| 3406 | return CallDisplayFunction(disp, &HWCDisplay::GetDisplayVsyncPeriod, vsync_period); |
| 3407 | } |
| 3408 | |
| 3409 | int32_t HWCSession::SetActiveConfigWithConstraints( |
| 3410 | hwc2_display_t display, hwc2_config_t config, |
| 3411 | const VsyncPeriodChangeConstraints *vsync_period_change_constraints, |
| 3412 | VsyncPeriodChangeTimeline *out_timeline) { |
| 3413 | if ((vsync_period_change_constraints == nullptr) || (out_timeline == nullptr)) { |
| 3414 | return HWC2_ERROR_BAD_PARAMETER; |
| 3415 | } |
| 3416 | |
| 3417 | return CallDisplayFunction(display, &HWCDisplay::SetActiveConfigWithConstraints, config, |
| 3418 | vsync_period_change_constraints, out_timeline); |
| 3419 | } |
| 3420 | |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 3421 | } // namespace sdm |