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 | |
Pullakavi Srinivas | 5cb87bd | 2020-04-02 22:30:55 +0530 | [diff] [blame] | 184 | int value = 0; // 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; |
Pullakavi Srinivas | 5cb87bd | 2020-04-02 22:30:55 +0530 | [diff] [blame] | 1130 | uint32_t config = 0; |
| 1131 | GetActiveConfigIndex(display, &config); |
| 1132 | *out_support = isSmartPanelConfig(display, config) ? 1 : 0; |
Pullakavi Srinivas | 04e5242 | 2018-07-31 15:12:57 +0530 | [diff] [blame] | 1133 | |
| 1134 | return HWC2_ERROR_NONE; |
| 1135 | } |
| 1136 | |
Pullakavi Srinivas | 5cb87bd | 2020-04-02 22:30:55 +0530 | [diff] [blame] | 1137 | bool HWCSession::isSmartPanelConfig(uint32_t disp_id, uint32_t config_id) { |
| 1138 | if (disp_id != qdutils::DISPLAY_PRIMARY) { |
| 1139 | return false; |
| 1140 | } |
| 1141 | |
| 1142 | SCOPE_LOCK(locker_[disp_id]); |
| 1143 | if (!hwc_display_[disp_id]) { |
| 1144 | DLOGE("Display %d is not created yet.", disp_id); |
| 1145 | return false; |
| 1146 | } |
| 1147 | |
| 1148 | return hwc_display_[disp_id]->IsSmartPanelConfig(config_id); |
| 1149 | } |
| 1150 | |
Rajavenu Kyatham | 42d11cb | 2019-04-16 13:03:29 +0530 | [diff] [blame] | 1151 | int32_t HWCSession::ValidateDisplay(hwc2_display_t display, uint32_t *out_num_types, |
| 1152 | uint32_t *out_num_requests) { |
Varun Arora | 2c23e58 | 2017-10-10 15:07:13 -0700 | [diff] [blame] | 1153 | // out_num_types and out_num_requests will be non-NULL |
Varun Arora | 2c23e58 | 2017-10-10 15:07:13 -0700 | [diff] [blame] | 1154 | |
Padmanabhan Komanduru | e74cf4f | 2019-04-25 17:38:43 -0700 | [diff] [blame] | 1155 | if (display >= HWCCallbacks::kNumDisplays) { |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 1156 | return HWC2_ERROR_BAD_DISPLAY; |
| 1157 | } |
Srinivas Pullakavi | 3c4337f | 2019-07-03 11:24:31 +0530 | [diff] [blame] | 1158 | |
Mathew Joseph Karimpanal | b1c1586 | 2019-07-04 11:14:24 +0530 | [diff] [blame] | 1159 | hwc2_display_t target_display = display; |
| 1160 | |
Srinivas Pullakavi | 3c4337f | 2019-07-03 11:24:31 +0530 | [diff] [blame] | 1161 | { |
| 1162 | SCOPE_LOCK(power_state_[display]); |
| 1163 | if (power_state_transition_[display]) { |
| 1164 | // Route all interactions with client to dummy display. |
Mathew Joseph Karimpanal | b1c1586 | 2019-07-04 11:14:24 +0530 | [diff] [blame] | 1165 | target_display = map_hwc_display_.find(display)->second; |
Srinivas Pullakavi | 3c4337f | 2019-07-03 11:24:31 +0530 | [diff] [blame] | 1166 | } |
| 1167 | } |
Varun Arora | 2c23e58 | 2017-10-10 15:07:13 -0700 | [diff] [blame] | 1168 | DTRACE_SCOPED(); |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 1169 | // TODO(user): Handle secure session, handle QDCM solid fill |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 1170 | auto status = HWC2::Error::BadDisplay; |
Rajavenu Kyatham | 42d11cb | 2019-04-16 13:03:29 +0530 | [diff] [blame] | 1171 | HandleSecureSession(); |
Saurabh Shah | c5c687a | 2017-08-24 16:30:14 -0700 | [diff] [blame] | 1172 | { |
Mathew Joseph Karimpanal | b1c1586 | 2019-07-04 11:14:24 +0530 | [diff] [blame] | 1173 | SEQUENCE_ENTRY_SCOPE_LOCK(locker_[target_display]); |
| 1174 | if (pending_power_mode_[display]) { |
Mathew Joseph Karimpanal | 71ac8a7 | 2018-09-25 22:27:22 +0530 | [diff] [blame] | 1175 | status = HWC2::Error::None; |
Mathew Joseph Karimpanal | b1c1586 | 2019-07-04 11:14:24 +0530 | [diff] [blame] | 1176 | } else if (hwc_display_[target_display]) { |
Sushil Chauhan | ba8e465 | 2020-03-20 10:07:47 -0700 | [diff] [blame] | 1177 | hwc_display_[target_display]->ProcessActiveConfigChange(); |
Mathew Joseph Karimpanal | b1c1586 | 2019-07-04 11:14:24 +0530 | [diff] [blame] | 1178 | hwc_display_[target_display]->SetFastPathComposition(false); |
| 1179 | status = ValidateDisplayInternal(target_display, out_num_types, out_num_requests); |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 1180 | } |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 1181 | } |
Saurabh Shah | c5c687a | 2017-08-24 16:30:14 -0700 | [diff] [blame] | 1182 | |
Saurabh Shah | 04f932b | 2017-10-12 18:47:45 -0700 | [diff] [blame] | 1183 | // 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] | 1184 | if (status != HWC2::Error::None && status != HWC2::Error::HasChanges) { |
Mathew Joseph Karimpanal | b1c1586 | 2019-07-04 11:14:24 +0530 | [diff] [blame] | 1185 | SEQUENCE_CANCEL_SCOPE_LOCK(locker_[target_display]); |
| 1186 | } |
| 1187 | |
| 1188 | if (display != target_display) { |
| 1189 | // Validate done on a dummy display. Assume present is complete. |
| 1190 | SEQUENCE_EXIT_SCOPE_LOCK(locker_[target_display]); |
Saurabh Shah | c5c687a | 2017-08-24 16:30:14 -0700 | [diff] [blame] | 1191 | } |
| 1192 | |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 1193 | return INT32(status); |
| 1194 | } |
| 1195 | |
Dileep Marchya | f3ce11f | 2018-04-30 23:35:46 +0530 | [diff] [blame] | 1196 | HWC2::Error HWCSession::CreateVirtualDisplayObj(uint32_t width, uint32_t height, int32_t *format, |
| 1197 | hwc2_display_t *out_display_id) { |
Ramkumar Radhakrishnan | 44c6436 | 2018-12-12 13:03:59 -0800 | [diff] [blame] | 1198 | hwc2_display_t active_builtin_disp_id = GetActiveBuiltinDisplay(); |
Padmanabhan Komanduru | f5b7f99 | 2019-07-08 13:33:44 +0530 | [diff] [blame] | 1199 | hwc2_display_t client_id = HWCCallbacks::kNumDisplays; |
Padmanabhan Komanduru | e74cf4f | 2019-04-25 17:38:43 -0700 | [diff] [blame] | 1200 | if (active_builtin_disp_id < HWCCallbacks::kNumDisplays) { |
Ramkumar Radhakrishnan | 44c6436 | 2018-12-12 13:03:59 -0800 | [diff] [blame] | 1201 | SEQUENCE_WAIT_SCOPE_LOCK(locker_[active_builtin_disp_id]); |
Mathew Joseph Karimpanal | 71ac8a7 | 2018-09-25 22:27:22 +0530 | [diff] [blame] | 1202 | std::bitset<kSecureMax> secure_sessions = 0; |
Ramkumar Radhakrishnan | 44c6436 | 2018-12-12 13:03:59 -0800 | [diff] [blame] | 1203 | if (hwc_display_[active_builtin_disp_id]) { |
| 1204 | hwc_display_[active_builtin_disp_id]->GetActiveSecureSession(&secure_sessions); |
| 1205 | } |
Mathew Joseph Karimpanal | 71ac8a7 | 2018-09-25 22:27:22 +0530 | [diff] [blame] | 1206 | if (secure_sessions.any()) { |
| 1207 | DLOGE("Secure session is active, cannot create virtual display."); |
| 1208 | return HWC2::Error::Unsupported; |
| 1209 | } else if (IsPluggableDisplayConnected()) { |
| 1210 | DLOGE("External session is active, cannot create virtual display."); |
| 1211 | return HWC2::Error::Unsupported; |
| 1212 | } |
| 1213 | } |
| 1214 | |
Pullakavi Srinivas | f2a3185 | 2019-04-23 14:32:08 -0700 | [diff] [blame] | 1215 | if (hwc_display_[HWC_DISPLAY_PRIMARY]) { |
| 1216 | DisplayError error = hwc_display_[HWC_DISPLAY_PRIMARY]->TeardownConcurrentWriteback(); |
| 1217 | if (error) { |
| 1218 | return HWC2::Error::NoResources; |
| 1219 | } |
| 1220 | } |
| 1221 | |
Dileep Marchya | f3ce11f | 2018-04-30 23:35:46 +0530 | [diff] [blame] | 1222 | // Lock confined to this scope |
| 1223 | int status = -EINVAL; |
Pullakavi Srinivas | a3c292c | 2019-12-01 13:27:50 +0530 | [diff] [blame] | 1224 | for (auto &map_info : map_info_virtual_) { |
| 1225 | client_id = map_info.client_id; |
| 1226 | { |
| 1227 | SCOPE_LOCK(locker_[client_id]); |
| 1228 | auto &hwc_display = hwc_display_[client_id]; |
| 1229 | if (hwc_display) { |
| 1230 | continue; |
Dileep Marchya | f3ce11f | 2018-04-30 23:35:46 +0530 | [diff] [blame] | 1231 | } |
Pullakavi Srinivas | a3c292c | 2019-12-01 13:27:50 +0530 | [diff] [blame] | 1232 | |
| 1233 | int32_t display_id = GetVirtualDisplayId(); |
| 1234 | status = virtual_display_factory_.Create(core_intf_, &buffer_allocator_, &callbacks_, |
| 1235 | client_id, display_id, width, height, |
| 1236 | format, set_min_lum_, set_max_lum_, &hwc_display); |
| 1237 | // TODO(user): validate width and height support |
| 1238 | if (status) { |
| 1239 | return HWC2::Error::NoResources; |
| 1240 | } |
| 1241 | |
| 1242 | { |
| 1243 | SCOPE_LOCK(hdr_locker_[client_id]); |
| 1244 | is_hdr_display_[UINT32(client_id)] = HasHDRSupport(hwc_display); |
| 1245 | } |
| 1246 | |
| 1247 | DLOGI("Created virtual display id:% " PRIu64 " with res: %dx%d", client_id, width, height); |
| 1248 | |
| 1249 | *out_display_id = client_id; |
| 1250 | map_info.disp_type = kVirtual; |
| 1251 | map_info.sdm_id = display_id; |
| 1252 | break; |
Saurabh Shah | a307e8c | 2017-09-28 18:05:40 -0700 | [diff] [blame] | 1253 | } |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 1254 | } |
Saurabh Shah | a307e8c | 2017-09-28 18:05:40 -0700 | [diff] [blame] | 1255 | |
Padmanabhan Komanduru | f5b7f99 | 2019-07-08 13:33:44 +0530 | [diff] [blame] | 1256 | // Active builtin display needs revalidation |
| 1257 | if (!async_vds_creation_ && active_builtin_disp_id < HWCCallbacks::kNumRealDisplays) { |
Ramkumar Radhakrishnan | 44c6436 | 2018-12-12 13:03:59 -0800 | [diff] [blame] | 1258 | SEQUENCE_WAIT_SCOPE_LOCK(locker_[active_builtin_disp_id]); |
| 1259 | hwc_display_[active_builtin_disp_id]->ResetValidation(); |
| 1260 | } |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 1261 | |
| 1262 | return HWC2::Error::None; |
| 1263 | } |
| 1264 | |
Mathew Joseph Karimpanal | 71ac8a7 | 2018-09-25 22:27:22 +0530 | [diff] [blame] | 1265 | bool HWCSession::IsPluggableDisplayConnected() { |
| 1266 | for (auto &map_info : map_info_pluggable_) { |
| 1267 | if (hwc_display_[map_info.client_id]) { |
| 1268 | return true; |
| 1269 | } |
| 1270 | } |
| 1271 | return false; |
Pullakavi Srinivas | 04e5242 | 2018-07-31 15:12:57 +0530 | [diff] [blame] | 1272 | } |
| 1273 | |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 1274 | // Qclient methods |
| 1275 | android::status_t HWCSession::notifyCallback(uint32_t command, const android::Parcel *input_parcel, |
| 1276 | android::Parcel *output_parcel) { |
Mathew Joseph Karimpanal | dbd64f8 | 2017-10-06 10:13:38 +0530 | [diff] [blame] | 1277 | android::status_t status = -EINVAL; |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 1278 | |
| 1279 | switch (command) { |
| 1280 | case qService::IQService::DYNAMIC_DEBUG: |
Mathew Joseph Karimpanal | dbd64f8 | 2017-10-06 10:13:38 +0530 | [diff] [blame] | 1281 | if (!input_parcel) { |
| 1282 | DLOGE("QService command = %d: input_parcel needed.", command); |
| 1283 | break; |
| 1284 | } |
| 1285 | status = 0; |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 1286 | DynamicDebug(input_parcel); |
| 1287 | break; |
| 1288 | |
| 1289 | case qService::IQService::SCREEN_REFRESH: |
Dileep Marchya | 35e2753 | 2018-06-29 10:50:16 +0530 | [diff] [blame] | 1290 | if (!input_parcel) { |
| 1291 | DLOGE("QService command = %d: input_parcel needed.", command); |
| 1292 | break; |
| 1293 | } |
| 1294 | status = RefreshScreen(input_parcel); |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 1295 | break; |
| 1296 | |
| 1297 | case qService::IQService::SET_IDLE_TIMEOUT: |
Mathew Joseph Karimpanal | dbd64f8 | 2017-10-06 10:13:38 +0530 | [diff] [blame] | 1298 | if (!input_parcel) { |
| 1299 | DLOGE("QService command = %d: input_parcel needed.", command); |
| 1300 | break; |
| 1301 | } |
Padmanabhan Komanduru | 9e97162 | 2020-02-10 13:09:34 +0530 | [diff] [blame] | 1302 | status = SetIdleTimeout(UINT32(input_parcel->readInt32())); |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 1303 | break; |
| 1304 | |
| 1305 | case qService::IQService::SET_FRAME_DUMP_CONFIG: |
Mathew Joseph Karimpanal | dbd64f8 | 2017-10-06 10:13:38 +0530 | [diff] [blame] | 1306 | if (!input_parcel) { |
| 1307 | DLOGE("QService command = %d: input_parcel needed.", command); |
| 1308 | break; |
| 1309 | } |
| 1310 | status = SetFrameDumpConfig(input_parcel); |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 1311 | break; |
| 1312 | |
| 1313 | case qService::IQService::SET_MAX_PIPES_PER_MIXER: |
Mathew Joseph Karimpanal | dbd64f8 | 2017-10-06 10:13:38 +0530 | [diff] [blame] | 1314 | if (!input_parcel) { |
| 1315 | DLOGE("QService command = %d: input_parcel needed.", command); |
| 1316 | break; |
| 1317 | } |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 1318 | status = SetMaxMixerStages(input_parcel); |
| 1319 | break; |
| 1320 | |
| 1321 | case qService::IQService::SET_DISPLAY_MODE: |
Mathew Joseph Karimpanal | dbd64f8 | 2017-10-06 10:13:38 +0530 | [diff] [blame] | 1322 | if (!input_parcel) { |
| 1323 | DLOGE("QService command = %d: input_parcel needed.", command); |
| 1324 | break; |
| 1325 | } |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 1326 | status = SetDisplayMode(input_parcel); |
| 1327 | break; |
| 1328 | |
Dileep Marchya | 6860b2b | 2017-04-07 15:56:47 +0530 | [diff] [blame] | 1329 | case qService::IQService::SET_SECONDARY_DISPLAY_STATUS: { |
Mathew Joseph Karimpanal | dbd64f8 | 2017-10-06 10:13:38 +0530 | [diff] [blame] | 1330 | if (!input_parcel || !output_parcel) { |
| 1331 | DLOGE("QService command = %d: input_parcel and output_parcel needed.", command); |
| 1332 | break; |
| 1333 | } |
Dileep Marchya | 6860b2b | 2017-04-07 15:56:47 +0530 | [diff] [blame] | 1334 | int disp_id = INT(input_parcel->readInt32()); |
| 1335 | HWCDisplay::DisplayStatus disp_status = |
| 1336 | static_cast<HWCDisplay::DisplayStatus>(input_parcel->readInt32()); |
Padmanabhan Komanduru | 9e97162 | 2020-02-10 13:09:34 +0530 | [diff] [blame] | 1337 | status = SetDisplayStatus(disp_id, disp_status); |
Dileep Marchya | 6860b2b | 2017-04-07 15:56:47 +0530 | [diff] [blame] | 1338 | output_parcel->writeInt32(status); |
| 1339 | } |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 1340 | break; |
| 1341 | |
| 1342 | case qService::IQService::CONFIGURE_DYN_REFRESH_RATE: |
Mathew Joseph Karimpanal | dbd64f8 | 2017-10-06 10:13:38 +0530 | [diff] [blame] | 1343 | if (!input_parcel) { |
| 1344 | DLOGE("QService command = %d: input_parcel needed.", command); |
| 1345 | break; |
| 1346 | } |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 1347 | status = ConfigureRefreshRate(input_parcel); |
| 1348 | break; |
| 1349 | |
Dileep Marchya | 6860b2b | 2017-04-07 15:56:47 +0530 | [diff] [blame] | 1350 | case qService::IQService::TOGGLE_SCREEN_UPDATES: { |
Mathew Joseph Karimpanal | dbd64f8 | 2017-10-06 10:13:38 +0530 | [diff] [blame] | 1351 | if (!input_parcel || !output_parcel) { |
| 1352 | DLOGE("QService command = %d: input_parcel and output_parcel needed.", command); |
| 1353 | break; |
| 1354 | } |
Dileep Marchya | 6860b2b | 2017-04-07 15:56:47 +0530 | [diff] [blame] | 1355 | int32_t input = input_parcel->readInt32(); |
Padmanabhan Komanduru | 9e97162 | 2020-02-10 13:09:34 +0530 | [diff] [blame] | 1356 | status = ToggleScreenUpdate(input == 1); |
Dileep Marchya | 6860b2b | 2017-04-07 15:56:47 +0530 | [diff] [blame] | 1357 | output_parcel->writeInt32(status); |
| 1358 | } |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 1359 | break; |
| 1360 | |
| 1361 | case qService::IQService::QDCM_SVC_CMDS: |
Mathew Joseph Karimpanal | dbd64f8 | 2017-10-06 10:13:38 +0530 | [diff] [blame] | 1362 | if (!input_parcel || !output_parcel) { |
| 1363 | DLOGE("QService command = %d: input_parcel and output_parcel needed.", command); |
| 1364 | break; |
| 1365 | } |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 1366 | status = QdcmCMDHandler(input_parcel, output_parcel); |
| 1367 | break; |
| 1368 | |
Dileep Marchya | 6860b2b | 2017-04-07 15:56:47 +0530 | [diff] [blame] | 1369 | case qService::IQService::MIN_HDCP_ENCRYPTION_LEVEL_CHANGED: { |
Mathew Joseph Karimpanal | dbd64f8 | 2017-10-06 10:13:38 +0530 | [diff] [blame] | 1370 | if (!input_parcel || !output_parcel) { |
| 1371 | DLOGE("QService command = %d: input_parcel and output_parcel needed.", command); |
| 1372 | break; |
| 1373 | } |
Dileep Marchya | 6860b2b | 2017-04-07 15:56:47 +0530 | [diff] [blame] | 1374 | int disp_id = input_parcel->readInt32(); |
| 1375 | uint32_t min_enc_level = UINT32(input_parcel->readInt32()); |
| 1376 | status = MinHdcpEncryptionLevelChanged(disp_id, min_enc_level); |
| 1377 | output_parcel->writeInt32(status); |
| 1378 | } |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 1379 | break; |
| 1380 | |
Dileep Marchya | 6860b2b | 2017-04-07 15:56:47 +0530 | [diff] [blame] | 1381 | case qService::IQService::CONTROL_PARTIAL_UPDATE: { |
Mathew Joseph Karimpanal | dbd64f8 | 2017-10-06 10:13:38 +0530 | [diff] [blame] | 1382 | if (!input_parcel || !output_parcel) { |
| 1383 | DLOGE("QService command = %d: input_parcel and output_parcel needed.", command); |
| 1384 | break; |
| 1385 | } |
Dileep Marchya | 6860b2b | 2017-04-07 15:56:47 +0530 | [diff] [blame] | 1386 | int disp_id = input_parcel->readInt32(); |
| 1387 | uint32_t enable = UINT32(input_parcel->readInt32()); |
| 1388 | status = ControlPartialUpdate(disp_id, enable == 1); |
| 1389 | output_parcel->writeInt32(status); |
| 1390 | } |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 1391 | break; |
| 1392 | |
Dileep Marchya | 6860b2b | 2017-04-07 15:56:47 +0530 | [diff] [blame] | 1393 | case qService::IQService::SET_ACTIVE_CONFIG: { |
Mathew Joseph Karimpanal | dbd64f8 | 2017-10-06 10:13:38 +0530 | [diff] [blame] | 1394 | if (!input_parcel) { |
| 1395 | DLOGE("QService command = %d: input_parcel needed.", command); |
| 1396 | break; |
| 1397 | } |
Dileep Marchya | 6860b2b | 2017-04-07 15:56:47 +0530 | [diff] [blame] | 1398 | uint32_t config = UINT32(input_parcel->readInt32()); |
| 1399 | int disp_id = input_parcel->readInt32(); |
| 1400 | status = SetActiveConfigIndex(disp_id, config); |
| 1401 | } |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 1402 | break; |
| 1403 | |
Dileep Marchya | 6860b2b | 2017-04-07 15:56:47 +0530 | [diff] [blame] | 1404 | case qService::IQService::GET_ACTIVE_CONFIG: { |
Mathew Joseph Karimpanal | dbd64f8 | 2017-10-06 10:13:38 +0530 | [diff] [blame] | 1405 | if (!input_parcel || !output_parcel) { |
| 1406 | DLOGE("QService command = %d: input_parcel and output_parcel needed.", command); |
| 1407 | break; |
| 1408 | } |
Dileep Marchya | 6860b2b | 2017-04-07 15:56:47 +0530 | [diff] [blame] | 1409 | int disp_id = input_parcel->readInt32(); |
| 1410 | uint32_t config = 0; |
| 1411 | status = GetActiveConfigIndex(disp_id, &config); |
| 1412 | output_parcel->writeInt32(INT(config)); |
| 1413 | } |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 1414 | break; |
| 1415 | |
Dileep Marchya | 6860b2b | 2017-04-07 15:56:47 +0530 | [diff] [blame] | 1416 | case qService::IQService::GET_CONFIG_COUNT: { |
Mathew Joseph Karimpanal | dbd64f8 | 2017-10-06 10:13:38 +0530 | [diff] [blame] | 1417 | if (!input_parcel || !output_parcel) { |
| 1418 | DLOGE("QService command = %d: input_parcel and output_parcel needed.", command); |
| 1419 | break; |
| 1420 | } |
Dileep Marchya | 6860b2b | 2017-04-07 15:56:47 +0530 | [diff] [blame] | 1421 | int disp_id = input_parcel->readInt32(); |
| 1422 | uint32_t count = 0; |
| 1423 | status = GetConfigCount(disp_id, &count); |
| 1424 | output_parcel->writeInt32(INT(count)); |
| 1425 | } |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 1426 | break; |
| 1427 | |
| 1428 | case qService::IQService::GET_DISPLAY_ATTRIBUTES_FOR_CONFIG: |
Mathew Joseph Karimpanal | dbd64f8 | 2017-10-06 10:13:38 +0530 | [diff] [blame] | 1429 | if (!input_parcel || !output_parcel) { |
| 1430 | DLOGE("QService command = %d: input_parcel and output_parcel needed.", command); |
| 1431 | break; |
| 1432 | } |
Dileep Marchya | f3ce11f | 2018-04-30 23:35:46 +0530 | [diff] [blame] | 1433 | status = GetDisplayAttributesForConfig(input_parcel, output_parcel); |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 1434 | break; |
| 1435 | |
Dileep Marchya | 6860b2b | 2017-04-07 15:56:47 +0530 | [diff] [blame] | 1436 | case qService::IQService::GET_PANEL_BRIGHTNESS: { |
Mathew Joseph Karimpanal | dbd64f8 | 2017-10-06 10:13:38 +0530 | [diff] [blame] | 1437 | if (!output_parcel) { |
| 1438 | DLOGE("QService command = %d: output_parcel needed.", command); |
| 1439 | break; |
| 1440 | } |
Yuchao Ma | ada1c40 | 2019-11-12 14:47:11 +0800 | [diff] [blame] | 1441 | |
Varun Arora | 75c05f0 | 2019-05-14 14:53:37 -0700 | [diff] [blame] | 1442 | uint32_t display = input_parcel->readUint32(); |
Yuchao Ma | ada1c40 | 2019-11-12 14:47:11 +0800 | [diff] [blame] | 1443 | uint32_t max_brightness_level = 0; |
| 1444 | status = getDisplayMaxBrightness(display, &max_brightness_level); |
| 1445 | if (status || !max_brightness_level) { |
| 1446 | output_parcel->writeInt32(max_brightness_level); |
| 1447 | DLOGE("Failed to get max brightness %u, status %d", max_brightness_level, status); |
| 1448 | break; |
| 1449 | } |
| 1450 | DLOGV("Panel Max brightness is %u", max_brightness_level); |
| 1451 | |
| 1452 | float brightness_precent = -1.0f; |
| 1453 | status = getDisplayBrightness(display, &brightness_precent); |
| 1454 | if (brightness_precent == -1.0f) { |
Varun Arora | 75c05f0 | 2019-05-14 14:53:37 -0700 | [diff] [blame] | 1455 | output_parcel->writeInt32(0); |
| 1456 | } else { |
Yuchao Ma | ada1c40 | 2019-11-12 14:47:11 +0800 | [diff] [blame] | 1457 | output_parcel->writeInt32(INT32(brightness_precent*(max_brightness_level - 1) + 1)); |
Varun Arora | 75c05f0 | 2019-05-14 14:53:37 -0700 | [diff] [blame] | 1458 | } |
Dileep Marchya | 6860b2b | 2017-04-07 15:56:47 +0530 | [diff] [blame] | 1459 | } |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 1460 | break; |
| 1461 | |
Dileep Marchya | 6860b2b | 2017-04-07 15:56:47 +0530 | [diff] [blame] | 1462 | case qService::IQService::SET_PANEL_BRIGHTNESS: { |
Mathew Joseph Karimpanal | dbd64f8 | 2017-10-06 10:13:38 +0530 | [diff] [blame] | 1463 | if (!input_parcel || !output_parcel) { |
| 1464 | DLOGE("QService command = %d: input_parcel and output_parcel needed.", command); |
| 1465 | break; |
| 1466 | } |
Yuchao Ma | ada1c40 | 2019-11-12 14:47:11 +0800 | [diff] [blame] | 1467 | |
| 1468 | uint32_t max_brightness_level = 0; |
| 1469 | uint32_t display = HWC_DISPLAY_PRIMARY; |
| 1470 | status = getDisplayMaxBrightness(display, &max_brightness_level); |
| 1471 | if (status || max_brightness_level <= 1) { |
| 1472 | output_parcel->writeInt32(max_brightness_level); |
| 1473 | DLOGE("Failed to get max brightness %u, status %d", max_brightness_level, status); |
| 1474 | break; |
| 1475 | } |
| 1476 | DLOGV("Panel Max brightness is %u", max_brightness_level); |
| 1477 | |
Varun Arora | 75c05f0 | 2019-05-14 14:53:37 -0700 | [diff] [blame] | 1478 | int level = input_parcel->readInt32(); |
Varun Arora | 75c05f0 | 2019-05-14 14:53:37 -0700 | [diff] [blame] | 1479 | if (level == 0) { |
Yuchao Ma | ada1c40 | 2019-11-12 14:47:11 +0800 | [diff] [blame] | 1480 | status = SetDisplayBrightness(display, -1.0f); |
Varun Arora | 75c05f0 | 2019-05-14 14:53:37 -0700 | [diff] [blame] | 1481 | } else { |
Yuchao Ma | ada1c40 | 2019-11-12 14:47:11 +0800 | [diff] [blame] | 1482 | status = SetDisplayBrightness(display, |
| 1483 | (level - 1)/(static_cast<float>(max_brightness_level - 1))); |
Varun Arora | 75c05f0 | 2019-05-14 14:53:37 -0700 | [diff] [blame] | 1484 | } |
Dileep Marchya | 6860b2b | 2017-04-07 15:56:47 +0530 | [diff] [blame] | 1485 | output_parcel->writeInt32(status); |
| 1486 | } |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 1487 | break; |
| 1488 | |
| 1489 | case qService::IQService::GET_DISPLAY_VISIBLE_REGION: |
Mathew Joseph Karimpanal | dbd64f8 | 2017-10-06 10:13:38 +0530 | [diff] [blame] | 1490 | if (!input_parcel || !output_parcel) { |
| 1491 | DLOGE("QService command = %d: input_parcel and output_parcel needed.", command); |
| 1492 | break; |
| 1493 | } |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 1494 | status = GetVisibleDisplayRect(input_parcel, output_parcel); |
| 1495 | break; |
| 1496 | |
Dileep Marchya | 6860b2b | 2017-04-07 15:56:47 +0530 | [diff] [blame] | 1497 | case qService::IQService::SET_CAMERA_STATUS: { |
Mathew Joseph Karimpanal | dbd64f8 | 2017-10-06 10:13:38 +0530 | [diff] [blame] | 1498 | if (!input_parcel) { |
| 1499 | DLOGE("QService command = %d: input_parcel needed.", command); |
| 1500 | break; |
| 1501 | } |
Dileep Marchya | 6860b2b | 2017-04-07 15:56:47 +0530 | [diff] [blame] | 1502 | uint32_t camera_status = UINT32(input_parcel->readInt32()); |
Padmanabhan Komanduru | 9e97162 | 2020-02-10 13:09:34 +0530 | [diff] [blame] | 1503 | status = SetCameraLaunchStatus(camera_status); |
Dileep Marchya | 6860b2b | 2017-04-07 15:56:47 +0530 | [diff] [blame] | 1504 | } |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 1505 | break; |
| 1506 | |
Dileep Marchya | 6860b2b | 2017-04-07 15:56:47 +0530 | [diff] [blame] | 1507 | case qService::IQService::GET_BW_TRANSACTION_STATUS: { |
Mathew Joseph Karimpanal | dbd64f8 | 2017-10-06 10:13:38 +0530 | [diff] [blame] | 1508 | if (!output_parcel) { |
| 1509 | DLOGE("QService command = %d: output_parcel needed.", command); |
| 1510 | break; |
| 1511 | } |
Dileep Marchya | 6860b2b | 2017-04-07 15:56:47 +0530 | [diff] [blame] | 1512 | bool state = true; |
| 1513 | status = DisplayBWTransactionPending(&state); |
| 1514 | output_parcel->writeInt32(state); |
| 1515 | } |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 1516 | break; |
| 1517 | |
Naseer Ahmed | ad49544 | 2016-06-27 14:59:18 -0400 | [diff] [blame] | 1518 | case qService::IQService::SET_LAYER_MIXER_RESOLUTION: |
Mathew Joseph Karimpanal | dbd64f8 | 2017-10-06 10:13:38 +0530 | [diff] [blame] | 1519 | if (!input_parcel) { |
| 1520 | DLOGE("QService command = %d: input_parcel needed.", command); |
| 1521 | break; |
| 1522 | } |
Naseer Ahmed | ad49544 | 2016-06-27 14:59:18 -0400 | [diff] [blame] | 1523 | status = SetMixerResolution(input_parcel); |
| 1524 | break; |
| 1525 | |
| 1526 | case qService::IQService::SET_COLOR_MODE: |
Mathew Joseph Karimpanal | dbd64f8 | 2017-10-06 10:13:38 +0530 | [diff] [blame] | 1527 | if (!input_parcel) { |
| 1528 | DLOGE("QService command = %d: input_parcel needed.", command); |
| 1529 | break; |
| 1530 | } |
Naseer Ahmed | ad49544 | 2016-06-27 14:59:18 -0400 | [diff] [blame] | 1531 | status = SetColorModeOverride(input_parcel); |
| 1532 | break; |
Arun Kumar K.R | 8da7f50 | 2016-06-07 17:45:50 -0700 | [diff] [blame] | 1533 | |
Naseer Ahmed | e7a7798 | 2018-06-04 10:56:04 -0400 | [diff] [blame] | 1534 | case qService::IQService::SET_COLOR_MODE_WITH_RENDER_INTENT: |
| 1535 | if (!input_parcel) { |
| 1536 | DLOGE("QService command = %d: input_parcel needed.", command); |
| 1537 | break; |
| 1538 | } |
| 1539 | status = SetColorModeWithRenderIntentOverride(input_parcel); |
| 1540 | break; |
| 1541 | |
Naseer Ahmed | 6776dae | 2017-05-09 11:49:41 -0400 | [diff] [blame] | 1542 | case qService::IQService::SET_COLOR_MODE_BY_ID: |
Mathew Joseph Karimpanal | dbd64f8 | 2017-10-06 10:13:38 +0530 | [diff] [blame] | 1543 | if (!input_parcel) { |
| 1544 | DLOGE("QService command = %d: input_parcel needed.", command); |
| 1545 | break; |
| 1546 | } |
Naseer Ahmed | 6776dae | 2017-05-09 11:49:41 -0400 | [diff] [blame] | 1547 | status = SetColorModeById(input_parcel); |
| 1548 | break; |
| 1549 | |
Prabhanjan Kandula | 63a613f | 2017-09-14 19:29:46 -0700 | [diff] [blame] | 1550 | case qService::IQService::GET_COMPOSER_STATUS: |
Mathew Joseph Karimpanal | dbd64f8 | 2017-10-06 10:13:38 +0530 | [diff] [blame] | 1551 | if (!output_parcel) { |
| 1552 | DLOGE("QService command = %d: output_parcel needed.", command); |
| 1553 | break; |
| 1554 | } |
| 1555 | status = 0; |
Prabhanjan Kandula | 63a613f | 2017-09-14 19:29:46 -0700 | [diff] [blame] | 1556 | output_parcel->writeInt32(getComposerStatus()); |
| 1557 | break; |
| 1558 | |
Sushil Chauhan | 380a59d | 2018-03-19 15:47:50 -0700 | [diff] [blame] | 1559 | case qService::IQService::SET_QSYNC_MODE: |
| 1560 | if (!input_parcel) { |
| 1561 | DLOGE("QService command = %d: input_parcel needed.", command); |
| 1562 | break; |
| 1563 | } |
| 1564 | status = SetQSyncMode(input_parcel); |
| 1565 | break; |
| 1566 | |
Lakshmi Narayana Kalavala | 25fe12c | 2019-12-11 20:44:55 -0800 | [diff] [blame] | 1567 | case qService::IQService::SET_COLOR_SAMPLING_ENABLED: |
| 1568 | if (!input_parcel) { |
| 1569 | DLOGE("QService command = %d: input_parcel needed.", command); |
| 1570 | break; |
| 1571 | } |
| 1572 | status = setColorSamplingEnabled(input_parcel); |
| 1573 | break; |
| 1574 | |
Ramkumar Radhakrishnan | f985d48 | 2018-07-23 18:10:41 -0700 | [diff] [blame] | 1575 | case qService::IQService::SET_IDLE_PC: |
| 1576 | if (!input_parcel) { |
| 1577 | DLOGE("QService command = %d: input_parcel needed.", command); |
| 1578 | break; |
| 1579 | } |
| 1580 | status = SetIdlePC(input_parcel); |
| 1581 | break; |
| 1582 | |
Yuchao Ma | 577f0f7 | 2018-07-09 11:20:00 +0800 | [diff] [blame] | 1583 | case qService::IQService::SET_DPPS_AD4_ROI_CONFIG: |
| 1584 | if (!input_parcel) { |
| 1585 | DLOGE("QService command = %d: input_parcel needed.", command); |
| 1586 | break; |
| 1587 | } |
| 1588 | status = SetAd4RoiConfig(input_parcel); |
| 1589 | break; |
| 1590 | |
Pullakavi Srinivas | 9189e60 | 2018-12-19 16:58:07 +0530 | [diff] [blame] | 1591 | case qService::IQService::SET_DSI_CLK: |
| 1592 | if (!input_parcel) { |
| 1593 | DLOGE("QService command = %d: input_parcel needed.", command); |
| 1594 | break; |
| 1595 | } |
| 1596 | status = SetDsiClk(input_parcel); |
| 1597 | break; |
| 1598 | |
| 1599 | case qService::IQService::GET_DSI_CLK: |
| 1600 | if (!input_parcel || !output_parcel) { |
| 1601 | DLOGE("QService command = %d: input_parcel and output_parcel needed.", command); |
| 1602 | break; |
| 1603 | } |
| 1604 | status = GetDsiClk(input_parcel, output_parcel); |
| 1605 | break; |
| 1606 | |
| 1607 | case qService::IQService::GET_SUPPORTED_DSI_CLK: |
| 1608 | if (!input_parcel || !output_parcel) { |
| 1609 | DLOGE("QService command = %d: input_parcel and output_parcel needed.", command); |
| 1610 | break; |
| 1611 | } |
| 1612 | status = GetSupportedDsiClk(input_parcel, output_parcel); |
| 1613 | break; |
| 1614 | |
Archit Srivastava | a59c4ff | 2019-05-20 10:54:22 +0530 | [diff] [blame] | 1615 | case qService::IQService::SET_PANEL_LUMINANCE: |
| 1616 | if (!input_parcel) { |
| 1617 | DLOGE("QService command = %d: input_parcel needed.", command); |
| 1618 | break; |
| 1619 | } |
| 1620 | status = SetPanelLuminanceAttributes(input_parcel); |
| 1621 | break; |
| 1622 | |
Qing Huang | da3a91d | 2019-01-15 14:34:11 +0800 | [diff] [blame] | 1623 | case qService::IQService::SET_COLOR_MODE_FROM_CLIENT: |
| 1624 | if (!input_parcel) { |
| 1625 | DLOGE("QService command = %d: input_parcel needed.", command); |
| 1626 | break; |
| 1627 | } |
| 1628 | status = SetColorModeFromClient(input_parcel); |
| 1629 | break; |
| 1630 | |
Xu Yang | 9dacc87 | 2018-12-25 11:04:28 +0800 | [diff] [blame] | 1631 | case qService::IQService::SET_FRAME_TRIGGER_MODE: |
| 1632 | if (!input_parcel) { |
| 1633 | DLOGE("QService command = %d: input_parcel needed.", command); |
| 1634 | break; |
| 1635 | } |
| 1636 | status = SetFrameTriggerMode(input_parcel); |
| 1637 | break; |
| 1638 | |
Xu Yang | 45d0abf | 2019-07-05 11:34:06 +0800 | [diff] [blame] | 1639 | case qService::IQService::SET_BRIGHTNESS_SCALE: |
| 1640 | if (!input_parcel) { |
| 1641 | DLOGE("QService command = %d: input_parcel needed.", command); |
| 1642 | break; |
| 1643 | } |
| 1644 | status = SetDisplayBrightnessScale(input_parcel); |
| 1645 | break; |
| 1646 | |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 1647 | default: |
Mathew Joseph Karimpanal | dbd64f8 | 2017-10-06 10:13:38 +0530 | [diff] [blame] | 1648 | DLOGW("QService command = %d is not supported.", command); |
| 1649 | break; |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 1650 | } |
| 1651 | |
| 1652 | return status; |
| 1653 | } |
| 1654 | |
Prabhanjan Kandula | 63a613f | 2017-09-14 19:29:46 -0700 | [diff] [blame] | 1655 | android::status_t HWCSession::getComposerStatus() { |
| 1656 | return is_composer_up_; |
| 1657 | } |
| 1658 | |
Dileep Marchya | f3ce11f | 2018-04-30 23:35:46 +0530 | [diff] [blame] | 1659 | android::status_t HWCSession::GetDisplayAttributesForConfig(const android::Parcel *input_parcel, |
| 1660 | android::Parcel *output_parcel) { |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 1661 | int config = input_parcel->readInt32(); |
| 1662 | int dpy = input_parcel->readInt32(); |
| 1663 | int error = android::BAD_VALUE; |
Arun Kumar K.R | 8da7f50 | 2016-06-07 17:45:50 -0700 | [diff] [blame] | 1664 | DisplayConfigVariableInfo display_attributes; |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 1665 | |
Dileep Marchya | f3ce11f | 2018-04-30 23:35:46 +0530 | [diff] [blame] | 1666 | int disp_idx = GetDisplayIndex(dpy); |
| 1667 | if (disp_idx == -1 || config < 0) { |
| 1668 | DLOGE("Invalid display = %d, or config = %d", dpy, config); |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 1669 | return android::BAD_VALUE; |
| 1670 | } |
| 1671 | |
Dileep Marchya | f3ce11f | 2018-04-30 23:35:46 +0530 | [diff] [blame] | 1672 | SEQUENCE_WAIT_SCOPE_LOCK(locker_[disp_idx]); |
| 1673 | if (hwc_display_[disp_idx]) { |
| 1674 | error = hwc_display_[disp_idx]->GetDisplayAttributesForConfig(config, &display_attributes); |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 1675 | if (error == 0) { |
Arun Kumar K.R | 8da7f50 | 2016-06-07 17:45:50 -0700 | [diff] [blame] | 1676 | output_parcel->writeInt32(INT(display_attributes.vsync_period_ns)); |
| 1677 | output_parcel->writeInt32(INT(display_attributes.x_pixels)); |
| 1678 | output_parcel->writeInt32(INT(display_attributes.y_pixels)); |
| 1679 | output_parcel->writeFloat(display_attributes.x_dpi); |
| 1680 | output_parcel->writeFloat(display_attributes.y_dpi); |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 1681 | output_parcel->writeInt32(0); // Panel type, unsupported. |
| 1682 | } |
| 1683 | } |
| 1684 | |
| 1685 | return error; |
| 1686 | } |
| 1687 | |
Lakshmi Narayana Kalavala | 25fe12c | 2019-12-11 20:44:55 -0800 | [diff] [blame] | 1688 | android::status_t HWCSession::setColorSamplingEnabled(const android::Parcel *input_parcel) { |
| 1689 | int dpy = input_parcel->readInt32(); |
| 1690 | int enabled_cmd = input_parcel->readInt32(); |
| 1691 | if (dpy < HWC_DISPLAY_PRIMARY || dpy >= HWC_NUM_DISPLAY_TYPES || enabled_cmd < 0 || |
| 1692 | enabled_cmd > 1) { |
| 1693 | return android::BAD_VALUE; |
| 1694 | } |
| 1695 | |
| 1696 | SEQUENCE_WAIT_SCOPE_LOCK(locker_[dpy]); |
| 1697 | if (!hwc_display_[dpy]) { |
| 1698 | DLOGW("No display id %i active to enable histogram event", dpy); |
| 1699 | return android::BAD_VALUE; |
| 1700 | } |
| 1701 | |
| 1702 | auto error = hwc_display_[dpy]->SetDisplayedContentSamplingEnabledVndService(enabled_cmd); |
| 1703 | return (error == HWC2::Error::None) ? android::OK : android::BAD_VALUE; |
| 1704 | } |
| 1705 | |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 1706 | android::status_t HWCSession::ConfigureRefreshRate(const android::Parcel *input_parcel) { |
Saurabh Shah | c5c687a | 2017-08-24 16:30:14 -0700 | [diff] [blame] | 1707 | SEQUENCE_WAIT_SCOPE_LOCK(locker_[HWC_DISPLAY_PRIMARY]); |
Dileep Marchya | 6860b2b | 2017-04-07 15:56:47 +0530 | [diff] [blame] | 1708 | |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 1709 | uint32_t operation = UINT32(input_parcel->readInt32()); |
Dileep Marchya | 6860b2b | 2017-04-07 15:56:47 +0530 | [diff] [blame] | 1710 | HWCDisplay *hwc_display = hwc_display_[HWC_DISPLAY_PRIMARY]; |
| 1711 | |
Mathew Joseph Karimpanal | dbd64f8 | 2017-10-06 10:13:38 +0530 | [diff] [blame] | 1712 | if (!hwc_display) { |
| 1713 | DLOGW("Display = %d is not connected.", HWC_DISPLAY_PRIMARY); |
| 1714 | return -ENODEV; |
| 1715 | } |
| 1716 | |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 1717 | switch (operation) { |
| 1718 | case qdutils::DISABLE_METADATA_DYN_REFRESH_RATE: |
Dileep Marchya | f3ce11f | 2018-04-30 23:35:46 +0530 | [diff] [blame] | 1719 | return hwc_display->Perform(HWCDisplayBuiltIn::SET_METADATA_DYN_REFRESH_RATE, false); |
Dileep Marchya | 6860b2b | 2017-04-07 15:56:47 +0530 | [diff] [blame] | 1720 | |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 1721 | case qdutils::ENABLE_METADATA_DYN_REFRESH_RATE: |
Dileep Marchya | f3ce11f | 2018-04-30 23:35:46 +0530 | [diff] [blame] | 1722 | return hwc_display->Perform(HWCDisplayBuiltIn::SET_METADATA_DYN_REFRESH_RATE, true); |
Dileep Marchya | 6860b2b | 2017-04-07 15:56:47 +0530 | [diff] [blame] | 1723 | |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 1724 | case qdutils::SET_BINDER_DYN_REFRESH_RATE: { |
| 1725 | uint32_t refresh_rate = UINT32(input_parcel->readInt32()); |
Dileep Marchya | f3ce11f | 2018-04-30 23:35:46 +0530 | [diff] [blame] | 1726 | return hwc_display->Perform(HWCDisplayBuiltIn::SET_BINDER_DYN_REFRESH_RATE, refresh_rate); |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 1727 | } |
Dileep Marchya | 6860b2b | 2017-04-07 15:56:47 +0530 | [diff] [blame] | 1728 | |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 1729 | default: |
| 1730 | DLOGW("Invalid operation %d", operation); |
| 1731 | return -EINVAL; |
| 1732 | } |
| 1733 | |
| 1734 | return 0; |
| 1735 | } |
| 1736 | |
| 1737 | android::status_t HWCSession::SetDisplayMode(const android::Parcel *input_parcel) { |
Saurabh Shah | c5c687a | 2017-08-24 16:30:14 -0700 | [diff] [blame] | 1738 | SEQUENCE_WAIT_SCOPE_LOCK(locker_[HWC_DISPLAY_PRIMARY]); |
Dileep Marchya | 6860b2b | 2017-04-07 15:56:47 +0530 | [diff] [blame] | 1739 | |
Mathew Joseph Karimpanal | dbd64f8 | 2017-10-06 10:13:38 +0530 | [diff] [blame] | 1740 | if (!hwc_display_[HWC_DISPLAY_PRIMARY]) { |
| 1741 | DLOGW("Display = %d is not connected.", HWC_DISPLAY_PRIMARY); |
| 1742 | return -ENODEV; |
| 1743 | } |
| 1744 | |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 1745 | uint32_t mode = UINT32(input_parcel->readInt32()); |
Dileep Marchya | f3ce11f | 2018-04-30 23:35:46 +0530 | [diff] [blame] | 1746 | return hwc_display_[HWC_DISPLAY_PRIMARY]->Perform(HWCDisplayBuiltIn::SET_DISPLAY_MODE, mode); |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 1747 | } |
| 1748 | |
| 1749 | android::status_t HWCSession::SetMaxMixerStages(const android::Parcel *input_parcel) { |
| 1750 | DisplayError error = kErrorNone; |
Dileep Marchya | 7290bd2 | 2016-06-09 11:37:20 +0530 | [diff] [blame] | 1751 | std::bitset<32> bit_mask_display_type = UINT32(input_parcel->readInt32()); |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 1752 | uint32_t max_mixer_stages = UINT32(input_parcel->readInt32()); |
Mathew Joseph Karimpanal | dbd64f8 | 2017-10-06 10:13:38 +0530 | [diff] [blame] | 1753 | android::status_t status = 0; |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 1754 | |
Dileep Marchya | f3ce11f | 2018-04-30 23:35:46 +0530 | [diff] [blame] | 1755 | for (uint32_t i = 0; i < 32 && bit_mask_display_type[i]; i++) { |
| 1756 | int disp_idx = GetDisplayIndex(INT(i)); |
| 1757 | if (disp_idx == -1) { |
| 1758 | continue; |
| 1759 | } |
| 1760 | SEQUENCE_WAIT_SCOPE_LOCK(locker_[disp_idx]); |
| 1761 | auto &hwc_display = hwc_display_[disp_idx]; |
| 1762 | if (!hwc_display) { |
| 1763 | DLOGW("Display = %d is not connected.", disp_idx); |
| 1764 | status = (status)? status : -ENODEV; // Return higher priority error. |
| 1765 | continue; |
| 1766 | } |
| 1767 | |
| 1768 | error = hwc_display->SetMaxMixerStages(max_mixer_stages); |
| 1769 | if (error != kErrorNone) { |
| 1770 | status = -EINVAL; |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 1771 | } |
| 1772 | } |
| 1773 | |
Mathew Joseph Karimpanal | dbd64f8 | 2017-10-06 10:13:38 +0530 | [diff] [blame] | 1774 | return status; |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 1775 | } |
| 1776 | |
Mathew Joseph Karimpanal | dbd64f8 | 2017-10-06 10:13:38 +0530 | [diff] [blame] | 1777 | android::status_t HWCSession::SetFrameDumpConfig(const android::Parcel *input_parcel) { |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 1778 | uint32_t frame_dump_count = UINT32(input_parcel->readInt32()); |
Dileep Marchya | 7290bd2 | 2016-06-09 11:37:20 +0530 | [diff] [blame] | 1779 | std::bitset<32> bit_mask_display_type = UINT32(input_parcel->readInt32()); |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 1780 | uint32_t bit_mask_layer_type = UINT32(input_parcel->readInt32()); |
Sushil Chauhan | 267a619 | 2018-06-06 18:41:47 -0700 | [diff] [blame] | 1781 | int32_t output_format = HAL_PIXEL_FORMAT_RGB_888; |
| 1782 | bool post_processed = true; |
| 1783 | |
Sushil Chauhan | 0a1b15d | 2019-08-23 12:58:18 -0700 | [diff] [blame] | 1784 | // Output buffer dump is not supported, if External or Virtual display is present. |
| 1785 | bool output_buffer_dump = bit_mask_layer_type & (1 << OUTPUT_LAYER_DUMP); |
| 1786 | if (output_buffer_dump) { |
| 1787 | int external_dpy_index = GetDisplayIndex(qdutils::DISPLAY_EXTERNAL); |
| 1788 | int virtual_dpy_index = GetDisplayIndex(qdutils::DISPLAY_VIRTUAL); |
| 1789 | if (((external_dpy_index != -1) && hwc_display_[external_dpy_index]) || |
| 1790 | ((virtual_dpy_index != -1) && hwc_display_[virtual_dpy_index])) { |
| 1791 | DLOGW("Output buffer dump is not supported with External or Virtual display!"); |
| 1792 | return -EINVAL; |
| 1793 | } |
| 1794 | } |
| 1795 | |
Sushil Chauhan | 267a619 | 2018-06-06 18:41:47 -0700 | [diff] [blame] | 1796 | // Read optional user preferences: output_format and post_processed. |
| 1797 | if (input_parcel->dataPosition() != input_parcel->dataSize()) { |
| 1798 | // HAL Pixel Format for output buffer |
| 1799 | output_format = input_parcel->readInt32(); |
| 1800 | } |
| 1801 | if (input_parcel->dataPosition() != input_parcel->dataSize()) { |
| 1802 | // Option to dump Layer Mixer output (0) or DSPP output (1) |
| 1803 | post_processed = (input_parcel->readInt32() != 0); |
| 1804 | } |
| 1805 | |
Mathew Joseph Karimpanal | dbd64f8 | 2017-10-06 10:13:38 +0530 | [diff] [blame] | 1806 | android::status_t status = 0; |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 1807 | |
Mathew Joseph Karimpanal | 0a2fff5 | 2018-10-17 12:11:07 +0530 | [diff] [blame] | 1808 | for (uint32_t i = 0; i < bit_mask_display_type.size(); i++) { |
| 1809 | if (!bit_mask_display_type[i]) { |
| 1810 | continue; |
| 1811 | } |
Dileep Marchya | f3ce11f | 2018-04-30 23:35:46 +0530 | [diff] [blame] | 1812 | int disp_idx = GetDisplayIndex(INT(i)); |
| 1813 | if (disp_idx == -1) { |
| 1814 | continue; |
| 1815 | } |
| 1816 | SEQUENCE_WAIT_SCOPE_LOCK(locker_[disp_idx]); |
| 1817 | auto &hwc_display = hwc_display_[disp_idx]; |
| 1818 | if (!hwc_display) { |
| 1819 | DLOGW("Display = %d is not connected.", disp_idx); |
| 1820 | status = (status)? status : -ENODEV; // Return higher priority error. |
| 1821 | continue; |
| 1822 | } |
| 1823 | |
Sushil Chauhan | 267a619 | 2018-06-06 18:41:47 -0700 | [diff] [blame] | 1824 | HWC2::Error error = hwc_display->SetFrameDumpConfig(frame_dump_count, bit_mask_layer_type, |
| 1825 | output_format, post_processed); |
Dileep Marchya | f3ce11f | 2018-04-30 23:35:46 +0530 | [diff] [blame] | 1826 | if (error != HWC2::Error::None) { |
| 1827 | status = (HWC2::Error::NoResources == error) ? -ENOMEM : -EINVAL; |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 1828 | } |
| 1829 | } |
| 1830 | |
Mathew Joseph Karimpanal | dbd64f8 | 2017-10-06 10:13:38 +0530 | [diff] [blame] | 1831 | return status; |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 1832 | } |
| 1833 | |
Arun Kumar K.R | 8da7f50 | 2016-06-07 17:45:50 -0700 | [diff] [blame] | 1834 | android::status_t HWCSession::SetMixerResolution(const android::Parcel *input_parcel) { |
| 1835 | DisplayError error = kErrorNone; |
| 1836 | uint32_t dpy = UINT32(input_parcel->readInt32()); |
| 1837 | |
| 1838 | if (dpy != HWC_DISPLAY_PRIMARY) { |
Mathew Joseph Karimpanal | dbd64f8 | 2017-10-06 10:13:38 +0530 | [diff] [blame] | 1839 | DLOGW("Resolution change not supported for this display = %d", dpy); |
Arun Kumar K.R | 8da7f50 | 2016-06-07 17:45:50 -0700 | [diff] [blame] | 1840 | return -EINVAL; |
| 1841 | } |
| 1842 | |
Saurabh Shah | c5c687a | 2017-08-24 16:30:14 -0700 | [diff] [blame] | 1843 | SEQUENCE_WAIT_SCOPE_LOCK(locker_[HWC_DISPLAY_PRIMARY]); |
Arun Kumar K.R | 8da7f50 | 2016-06-07 17:45:50 -0700 | [diff] [blame] | 1844 | if (!hwc_display_[HWC_DISPLAY_PRIMARY]) { |
Mathew Joseph Karimpanal | dbd64f8 | 2017-10-06 10:13:38 +0530 | [diff] [blame] | 1845 | DLOGW("Primary display is not initialized"); |
| 1846 | return -ENODEV; |
Arun Kumar K.R | 8da7f50 | 2016-06-07 17:45:50 -0700 | [diff] [blame] | 1847 | } |
| 1848 | |
| 1849 | uint32_t width = UINT32(input_parcel->readInt32()); |
| 1850 | uint32_t height = UINT32(input_parcel->readInt32()); |
| 1851 | |
| 1852 | error = hwc_display_[HWC_DISPLAY_PRIMARY]->SetMixerResolution(width, height); |
| 1853 | if (error != kErrorNone) { |
| 1854 | return -EINVAL; |
| 1855 | } |
| 1856 | |
| 1857 | return 0; |
| 1858 | } |
| 1859 | |
Naseer Ahmed | ad49544 | 2016-06-27 14:59:18 -0400 | [diff] [blame] | 1860 | android::status_t HWCSession::SetColorModeOverride(const android::Parcel *input_parcel) { |
Dileep Marchya | f3ce11f | 2018-04-30 23:35:46 +0530 | [diff] [blame] | 1861 | int display = static_cast<int>(input_parcel->readInt32()); |
Naseer Ahmed | e7a7798 | 2018-06-04 10:56:04 -0400 | [diff] [blame] | 1862 | auto mode = static_cast<ColorMode>(input_parcel->readInt32()); |
Saurabh Shah | c5c687a | 2017-08-24 16:30:14 -0700 | [diff] [blame] | 1863 | |
Dileep Marchya | f3ce11f | 2018-04-30 23:35:46 +0530 | [diff] [blame] | 1864 | int disp_idx = GetDisplayIndex(display); |
| 1865 | if (disp_idx == -1) { |
| 1866 | DLOGE("Invalid display = %d", display); |
| 1867 | return -EINVAL; |
| 1868 | } |
| 1869 | |
Gousemoodhin Nadaf | 0e56687 | 2019-05-13 16:14:54 +0530 | [diff] [blame] | 1870 | if (mode < ColorMode::NATIVE || mode > ColorMode::DISPLAY_BT2020) { |
Gurpreet Singh Dhami | ec0fa51 | 2018-08-29 16:51:26 -0400 | [diff] [blame] | 1871 | DLOGE("Invalid ColorMode: %d", mode); |
| 1872 | return HWC2_ERROR_BAD_PARAMETER; |
| 1873 | } |
Rajavenu Kyatham | 42d11cb | 2019-04-16 13:03:29 +0530 | [diff] [blame] | 1874 | auto err = CallDisplayFunction(static_cast<hwc2_display_t>(disp_idx), &HWCDisplay::SetColorMode, |
| 1875 | mode); |
Naseer Ahmed | ad49544 | 2016-06-27 14:59:18 -0400 | [diff] [blame] | 1876 | if (err != HWC2_ERROR_NONE) |
| 1877 | return -EINVAL; |
Saurabh Shah | 04f932b | 2017-10-12 18:47:45 -0700 | [diff] [blame] | 1878 | |
Naseer Ahmed | ad49544 | 2016-06-27 14:59:18 -0400 | [diff] [blame] | 1879 | return 0; |
| 1880 | } |
| 1881 | |
Yuchao Ma | 577f0f7 | 2018-07-09 11:20:00 +0800 | [diff] [blame] | 1882 | android::status_t HWCSession::SetAd4RoiConfig(const android::Parcel *input_parcel) { |
| 1883 | auto display_id = static_cast<uint32_t>(input_parcel->readInt32()); |
| 1884 | auto h_s = static_cast<uint32_t>(input_parcel->readInt32()); |
| 1885 | auto h_e = static_cast<uint32_t>(input_parcel->readInt32()); |
| 1886 | auto v_s = static_cast<uint32_t>(input_parcel->readInt32()); |
| 1887 | auto v_e = static_cast<uint32_t>(input_parcel->readInt32()); |
| 1888 | auto f_in = static_cast<uint32_t>(input_parcel->readInt32()); |
| 1889 | auto f_out = static_cast<uint32_t>(input_parcel->readInt32()); |
| 1890 | |
Padmanabhan Komanduru | 9e97162 | 2020-02-10 13:09:34 +0530 | [diff] [blame] | 1891 | return static_cast<android::status_t>(SetDisplayDppsAdROI(display_id, h_s, h_e, v_s, |
| 1892 | v_e, f_in, f_out)); |
Yuchao Ma | 577f0f7 | 2018-07-09 11:20:00 +0800 | [diff] [blame] | 1893 | } |
| 1894 | |
Xu Yang | 9dacc87 | 2018-12-25 11:04:28 +0800 | [diff] [blame] | 1895 | android::status_t HWCSession::SetFrameTriggerMode(const android::Parcel *input_parcel) { |
| 1896 | auto display_id = static_cast<int>(input_parcel->readInt32()); |
| 1897 | auto mode = static_cast<uint32_t>(input_parcel->readInt32()); |
| 1898 | |
| 1899 | int disp_idx = GetDisplayIndex(display_id); |
| 1900 | if (disp_idx == -1) { |
| 1901 | DLOGE("Invalid display = %d", display_id); |
| 1902 | return -EINVAL; |
| 1903 | } |
| 1904 | |
Rajavenu Kyatham | 42d11cb | 2019-04-16 13:03:29 +0530 | [diff] [blame] | 1905 | auto err = CallDisplayFunction(static_cast<hwc2_display_t>(disp_idx), |
Xu Yang | 9dacc87 | 2018-12-25 11:04:28 +0800 | [diff] [blame] | 1906 | &HWCDisplay::SetFrameTriggerMode, mode); |
| 1907 | if (err != HWC2_ERROR_NONE) |
| 1908 | return -EINVAL; |
| 1909 | |
| 1910 | return 0; |
| 1911 | } |
| 1912 | |
Naseer Ahmed | e7a7798 | 2018-06-04 10:56:04 -0400 | [diff] [blame] | 1913 | android::status_t HWCSession::SetColorModeWithRenderIntentOverride( |
| 1914 | const android::Parcel *input_parcel) { |
| 1915 | auto display = static_cast<hwc2_display_t>(input_parcel->readInt32()); |
| 1916 | auto mode = static_cast<ColorMode>(input_parcel->readInt32()); |
Xu Yang | 47f4409 | 2019-02-13 14:09:53 +0800 | [diff] [blame] | 1917 | auto int_intent = static_cast<int>(input_parcel->readInt32()); |
Naseer Ahmed | e7a7798 | 2018-06-04 10:56:04 -0400 | [diff] [blame] | 1918 | |
Gousemoodhin Nadaf | 0e56687 | 2019-05-13 16:14:54 +0530 | [diff] [blame] | 1919 | if (mode < ColorMode::NATIVE || mode > ColorMode::DISPLAY_BT2020) { |
Gurpreet Singh Dhami | ec0fa51 | 2018-08-29 16:51:26 -0400 | [diff] [blame] | 1920 | DLOGE("Invalid ColorMode: %d", mode); |
| 1921 | return HWC2_ERROR_BAD_PARAMETER; |
| 1922 | } |
| 1923 | |
Xu Yang | 47f4409 | 2019-02-13 14:09:53 +0800 | [diff] [blame] | 1924 | if ((int_intent < 0) || (int_intent > MAX_EXTENDED_RENDER_INTENT)) { |
| 1925 | DLOGE("Invalid RenderIntent: %d", int_intent); |
Gurpreet Singh Dhami | ec0fa51 | 2018-08-29 16:51:26 -0400 | [diff] [blame] | 1926 | return HWC2_ERROR_BAD_PARAMETER; |
| 1927 | } |
| 1928 | |
Xu Yang | 47f4409 | 2019-02-13 14:09:53 +0800 | [diff] [blame] | 1929 | auto intent = static_cast<RenderIntent>(int_intent); |
Naseer Ahmed | e7a7798 | 2018-06-04 10:56:04 -0400 | [diff] [blame] | 1930 | auto err = |
Rajavenu Kyatham | 42d11cb | 2019-04-16 13:03:29 +0530 | [diff] [blame] | 1931 | CallDisplayFunction(display, &HWCDisplay::SetColorModeWithRenderIntent, mode, intent); |
Naseer Ahmed | e7a7798 | 2018-06-04 10:56:04 -0400 | [diff] [blame] | 1932 | if (err != HWC2_ERROR_NONE) |
| 1933 | return -EINVAL; |
| 1934 | |
| 1935 | return 0; |
| 1936 | } |
Naseer Ahmed | 6776dae | 2017-05-09 11:49:41 -0400 | [diff] [blame] | 1937 | android::status_t HWCSession::SetColorModeById(const android::Parcel *input_parcel) { |
Dileep Marchya | 35e2753 | 2018-06-29 10:50:16 +0530 | [diff] [blame] | 1938 | int display = input_parcel->readInt32(); |
Naseer Ahmed | 6776dae | 2017-05-09 11:49:41 -0400 | [diff] [blame] | 1939 | auto mode = input_parcel->readInt32(); |
Naseer Ahmed | ab76820 | 2017-07-20 12:20:27 -0400 | [diff] [blame] | 1940 | |
Dileep Marchya | f3ce11f | 2018-04-30 23:35:46 +0530 | [diff] [blame] | 1941 | int disp_idx = GetDisplayIndex(display); |
| 1942 | if (disp_idx == -1) { |
| 1943 | DLOGE("Invalid display = %d", display); |
| 1944 | return -EINVAL; |
| 1945 | } |
| 1946 | |
Rajavenu Kyatham | 42d11cb | 2019-04-16 13:03:29 +0530 | [diff] [blame] | 1947 | auto err = CallDisplayFunction(static_cast<hwc2_display_t>(disp_idx), |
Dileep Marchya | f3ce11f | 2018-04-30 23:35:46 +0530 | [diff] [blame] | 1948 | &HWCDisplay::SetColorModeById, mode); |
Naseer Ahmed | 6776dae | 2017-05-09 11:49:41 -0400 | [diff] [blame] | 1949 | if (err != HWC2_ERROR_NONE) |
| 1950 | return -EINVAL; |
Saurabh Shah | 04f932b | 2017-10-12 18:47:45 -0700 | [diff] [blame] | 1951 | |
Naseer Ahmed | 6776dae | 2017-05-09 11:49:41 -0400 | [diff] [blame] | 1952 | return 0; |
| 1953 | } |
| 1954 | |
Qing Huang | da3a91d | 2019-01-15 14:34:11 +0800 | [diff] [blame] | 1955 | android::status_t HWCSession::SetColorModeFromClient(const android::Parcel *input_parcel) { |
| 1956 | int display = input_parcel->readInt32(); |
| 1957 | auto mode = input_parcel->readInt32(); |
Qing Huang | da3a91d | 2019-01-15 14:34:11 +0800 | [diff] [blame] | 1958 | |
| 1959 | int disp_idx = GetDisplayIndex(display); |
| 1960 | if (disp_idx == -1) { |
| 1961 | DLOGE("Invalid display = %d", display); |
| 1962 | return -EINVAL; |
| 1963 | } |
| 1964 | |
Rajavenu Kyatham | 42d11cb | 2019-04-16 13:03:29 +0530 | [diff] [blame] | 1965 | auto err = CallDisplayFunction(static_cast<hwc2_display_t>(disp_idx), |
Qing Huang | da3a91d | 2019-01-15 14:34:11 +0800 | [diff] [blame] | 1966 | &HWCDisplay::SetColorModeFromClientApi, mode); |
| 1967 | if (err != HWC2_ERROR_NONE) |
| 1968 | return -EINVAL; |
| 1969 | |
Varun Arora | dff7d8d | 2019-08-05 18:12:43 -0700 | [diff] [blame] | 1970 | callbacks_.Refresh(static_cast<hwc2_display_t>(disp_idx)); |
Qing Huang | da3a91d | 2019-01-15 14:34:11 +0800 | [diff] [blame] | 1971 | |
| 1972 | return 0; |
| 1973 | } |
| 1974 | |
Dileep Marchya | 35e2753 | 2018-06-29 10:50:16 +0530 | [diff] [blame] | 1975 | android::status_t HWCSession::RefreshScreen(const android::Parcel *input_parcel) { |
| 1976 | int display = input_parcel->readInt32(); |
| 1977 | |
| 1978 | int disp_idx = GetDisplayIndex(display); |
| 1979 | if (disp_idx == -1) { |
| 1980 | DLOGE("Invalid display = %d", display); |
| 1981 | return -EINVAL; |
| 1982 | } |
| 1983 | |
Varun Arora | dff7d8d | 2019-08-05 18:12:43 -0700 | [diff] [blame] | 1984 | callbacks_.Refresh(static_cast<hwc2_display_t>(disp_idx)); |
Dileep Marchya | 35e2753 | 2018-06-29 10:50:16 +0530 | [diff] [blame] | 1985 | |
| 1986 | return 0; |
| 1987 | } |
| 1988 | |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 1989 | void HWCSession::DynamicDebug(const android::Parcel *input_parcel) { |
| 1990 | int type = input_parcel->readInt32(); |
| 1991 | bool enable = (input_parcel->readInt32() > 0); |
| 1992 | DLOGI("type = %d enable = %d", type, enable); |
| 1993 | int verbose_level = input_parcel->readInt32(); |
| 1994 | |
| 1995 | switch (type) { |
| 1996 | case qService::IQService::DEBUG_ALL: |
| 1997 | HWCDebugHandler::DebugAll(enable, verbose_level); |
| 1998 | break; |
| 1999 | |
| 2000 | case qService::IQService::DEBUG_MDPCOMP: |
| 2001 | HWCDebugHandler::DebugStrategy(enable, verbose_level); |
| 2002 | HWCDebugHandler::DebugCompManager(enable, verbose_level); |
| 2003 | break; |
| 2004 | |
| 2005 | case qService::IQService::DEBUG_PIPE_LIFECYCLE: |
| 2006 | HWCDebugHandler::DebugResources(enable, verbose_level); |
Varun Arora | cc301f1 | 2018-12-13 14:32:24 -0800 | [diff] [blame] | 2007 | HWCDebugHandler::DebugQos(enable, verbose_level); |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 2008 | break; |
| 2009 | |
| 2010 | case qService::IQService::DEBUG_DRIVER_CONFIG: |
| 2011 | HWCDebugHandler::DebugDriverConfig(enable, verbose_level); |
| 2012 | break; |
| 2013 | |
| 2014 | case qService::IQService::DEBUG_ROTATOR: |
| 2015 | HWCDebugHandler::DebugResources(enable, verbose_level); |
| 2016 | HWCDebugHandler::DebugDriverConfig(enable, verbose_level); |
| 2017 | HWCDebugHandler::DebugRotator(enable, verbose_level); |
Varun Arora | cc301f1 | 2018-12-13 14:32:24 -0800 | [diff] [blame] | 2018 | HWCDebugHandler::DebugQos(enable, verbose_level); |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 2019 | break; |
| 2020 | |
| 2021 | case qService::IQService::DEBUG_QDCM: |
| 2022 | HWCDebugHandler::DebugQdcm(enable, verbose_level); |
| 2023 | break; |
| 2024 | |
Rohit Kulkarni | aa5111b | 2017-06-13 10:26:39 -0700 | [diff] [blame] | 2025 | case qService::IQService::DEBUG_SCALAR: |
| 2026 | HWCDebugHandler::DebugScalar(enable, verbose_level); |
| 2027 | break; |
| 2028 | |
Saurabh Dubey | d90a6a4 | 2017-10-24 16:28:01 +0530 | [diff] [blame] | 2029 | case qService::IQService::DEBUG_CLIENT: |
| 2030 | HWCDebugHandler::DebugClient(enable, verbose_level); |
| 2031 | break; |
| 2032 | |
| 2033 | case qService::IQService::DEBUG_DISPLAY: |
| 2034 | HWCDebugHandler::DebugDisplay(enable, verbose_level); |
| 2035 | break; |
| 2036 | |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 2037 | default: |
| 2038 | DLOGW("type = %d is not supported", type); |
| 2039 | } |
| 2040 | } |
| 2041 | |
Xu Yang | 2a979af | 2018-05-07 17:10:49 +0800 | [diff] [blame] | 2042 | android::status_t HWCSession::QdcmCMDDispatch(uint32_t display_id, |
| 2043 | const PPDisplayAPIPayload &req_payload, |
| 2044 | PPDisplayAPIPayload *resp_payload, |
| 2045 | PPPendingParams *pending_action) { |
| 2046 | int ret = 0; |
| 2047 | bool is_physical_display = false; |
| 2048 | |
Padmanabhan Komanduru | e74cf4f | 2019-04-25 17:38:43 -0700 | [diff] [blame] | 2049 | if (display_id >= HWCCallbacks::kNumDisplays || !hwc_display_[display_id]) { |
Xu Yang | 2a979af | 2018-05-07 17:10:49 +0800 | [diff] [blame] | 2050 | DLOGW("Invalid display id or display = %d is not connected.", display_id); |
| 2051 | return -ENODEV; |
| 2052 | } |
| 2053 | |
| 2054 | if (display_id == map_info_primary_.client_id) { |
| 2055 | is_physical_display = true; |
| 2056 | } else { |
| 2057 | for (auto &map_info : map_info_builtin_) { |
| 2058 | if (map_info.client_id == display_id) { |
| 2059 | is_physical_display = true; |
| 2060 | break; |
| 2061 | } |
| 2062 | } |
| 2063 | } |
| 2064 | |
| 2065 | if (!is_physical_display) { |
| 2066 | DLOGW("Skipping QDCM command dispatch on display = %d", display_id); |
| 2067 | return ret; |
| 2068 | } |
| 2069 | |
Rajavenu Kyatham | 42d11cb | 2019-04-16 13:03:29 +0530 | [diff] [blame] | 2070 | ret = hwc_display_[display_id]->ColorSVCRequestRoute(req_payload, resp_payload, pending_action); |
Xu Yang | 2a979af | 2018-05-07 17:10:49 +0800 | [diff] [blame] | 2071 | |
| 2072 | return ret; |
| 2073 | } |
| 2074 | |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 2075 | android::status_t HWCSession::QdcmCMDHandler(const android::Parcel *input_parcel, |
| 2076 | android::Parcel *output_parcel) { |
| 2077 | int ret = 0; |
Varun Arora | 75c05f0 | 2019-05-14 14:53:37 -0700 | [diff] [blame] | 2078 | float *brightness = NULL; |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 2079 | uint32_t display_id(0); |
| 2080 | PPPendingParams pending_action; |
| 2081 | PPDisplayAPIPayload resp_payload, req_payload; |
Xu Yang | 2a979af | 2018-05-07 17:10:49 +0800 | [diff] [blame] | 2082 | uint8_t *disp_id = NULL; |
Qing Huang | 02285c3 | 2018-12-06 16:30:38 +0800 | [diff] [blame] | 2083 | int32_t *mode_id = NULL; |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 2084 | |
| 2085 | if (!color_mgr_) { |
Mathew Joseph Karimpanal | dbd64f8 | 2017-10-06 10:13:38 +0530 | [diff] [blame] | 2086 | DLOGW("color_mgr_ not initialized."); |
| 2087 | return -ENOENT; |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 2088 | } |
| 2089 | |
| 2090 | pending_action.action = kNoAction; |
| 2091 | pending_action.params = NULL; |
| 2092 | |
| 2093 | // Read display_id, payload_size and payload from in_parcel. |
| 2094 | ret = HWCColorManager::CreatePayloadFromParcel(*input_parcel, &display_id, &req_payload); |
| 2095 | if (!ret) { |
Xu Yang | 2a979af | 2018-05-07 17:10:49 +0800 | [diff] [blame] | 2096 | ret = QdcmCMDDispatch(display_id, req_payload, &resp_payload, &pending_action); |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 2097 | } |
| 2098 | |
| 2099 | if (ret) { |
| 2100 | output_parcel->writeInt32(ret); // first field in out parcel indicates return code. |
| 2101 | req_payload.DestroyPayload(); |
| 2102 | resp_payload.DestroyPayload(); |
| 2103 | return ret; |
| 2104 | } |
| 2105 | |
Mathew Joseph Karimpanal | dbd64f8 | 2017-10-06 10:13:38 +0530 | [diff] [blame] | 2106 | if (kNoAction != pending_action.action) { |
Ch Ganesh Kumar | 5d43ff6 | 2017-10-13 19:01:47 +0530 | [diff] [blame] | 2107 | int32_t action = pending_action.action; |
| 2108 | int count = -1; |
| 2109 | while (action > 0) { |
| 2110 | count++; |
| 2111 | int32_t bit = (action & 1); |
| 2112 | action = action >> 1; |
| 2113 | |
| 2114 | if (!bit) |
| 2115 | continue; |
| 2116 | |
Xu Yang | 2a979af | 2018-05-07 17:10:49 +0800 | [diff] [blame] | 2117 | 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] | 2118 | switch (BITMAP(count)) { |
| 2119 | case kInvalidating: |
Ray Zhang | 2ee8247 | 2019-09-05 02:53:29 +0800 | [diff] [blame] | 2120 | callbacks_.Refresh(display_id); |
Ch Ganesh Kumar | 5d43ff6 | 2017-10-13 19:01:47 +0530 | [diff] [blame] | 2121 | break; |
| 2122 | case kEnterQDCMMode: |
Xu Yang | 2a979af | 2018-05-07 17:10:49 +0800 | [diff] [blame] | 2123 | ret = color_mgr_->EnableQDCMMode(true, hwc_display_[display_id]); |
Ch Ganesh Kumar | 5d43ff6 | 2017-10-13 19:01:47 +0530 | [diff] [blame] | 2124 | break; |
| 2125 | case kExitQDCMMode: |
Xu Yang | 2a979af | 2018-05-07 17:10:49 +0800 | [diff] [blame] | 2126 | ret = color_mgr_->EnableQDCMMode(false, hwc_display_[display_id]); |
Ch Ganesh Kumar | 5d43ff6 | 2017-10-13 19:01:47 +0530 | [diff] [blame] | 2127 | break; |
| 2128 | case kApplySolidFill: |
Gopikrishnaiah Anandan | a340b70 | 2018-01-16 15:37:15 -0800 | [diff] [blame] | 2129 | { |
Xu Yang | 2a979af | 2018-05-07 17:10:49 +0800 | [diff] [blame] | 2130 | SCOPE_LOCK(locker_[display_id]); |
Gopikrishnaiah Anandan | a340b70 | 2018-01-16 15:37:15 -0800 | [diff] [blame] | 2131 | ret = color_mgr_->SetSolidFill(pending_action.params, |
Xu Yang | 2a979af | 2018-05-07 17:10:49 +0800 | [diff] [blame] | 2132 | true, hwc_display_[display_id]); |
Gopikrishnaiah Anandan | a340b70 | 2018-01-16 15:37:15 -0800 | [diff] [blame] | 2133 | } |
Varun Arora | dff7d8d | 2019-08-05 18:12:43 -0700 | [diff] [blame] | 2134 | callbacks_.Refresh(display_id); |
Gopikrishnaiah Anandan | a340b70 | 2018-01-16 15:37:15 -0800 | [diff] [blame] | 2135 | usleep(kSolidFillDelay); |
Ch Ganesh Kumar | 5d43ff6 | 2017-10-13 19:01:47 +0530 | [diff] [blame] | 2136 | break; |
| 2137 | case kDisableSolidFill: |
Gopikrishnaiah Anandan | a340b70 | 2018-01-16 15:37:15 -0800 | [diff] [blame] | 2138 | { |
Xu Yang | 2a979af | 2018-05-07 17:10:49 +0800 | [diff] [blame] | 2139 | SCOPE_LOCK(locker_[display_id]); |
Gopikrishnaiah Anandan | a340b70 | 2018-01-16 15:37:15 -0800 | [diff] [blame] | 2140 | ret = color_mgr_->SetSolidFill(pending_action.params, |
Xu Yang | 2a979af | 2018-05-07 17:10:49 +0800 | [diff] [blame] | 2141 | false, hwc_display_[display_id]); |
Gopikrishnaiah Anandan | a340b70 | 2018-01-16 15:37:15 -0800 | [diff] [blame] | 2142 | } |
Varun Arora | dff7d8d | 2019-08-05 18:12:43 -0700 | [diff] [blame] | 2143 | callbacks_.Refresh(display_id); |
Gopikrishnaiah Anandan | a340b70 | 2018-01-16 15:37:15 -0800 | [diff] [blame] | 2144 | usleep(kSolidFillDelay); |
Ch Ganesh Kumar | 5d43ff6 | 2017-10-13 19:01:47 +0530 | [diff] [blame] | 2145 | break; |
| 2146 | case kSetPanelBrightness: |
Varun Arora | 75c05f0 | 2019-05-14 14:53:37 -0700 | [diff] [blame] | 2147 | ret = -EINVAL; |
| 2148 | brightness = reinterpret_cast<float *>(resp_payload.payload); |
| 2149 | if (brightness == NULL) { |
| 2150 | DLOGE("Brightness payload is Null"); |
Ch Ganesh Kumar | 5d43ff6 | 2017-10-13 19:01:47 +0530 | [diff] [blame] | 2151 | } else { |
Rajavenu Kyatham | 42d11cb | 2019-04-16 13:03:29 +0530 | [diff] [blame] | 2152 | ret = INT(SetDisplayBrightness(static_cast<hwc2_display_t>(display_id), *brightness)); |
Ch Ganesh Kumar | 5d43ff6 | 2017-10-13 19:01:47 +0530 | [diff] [blame] | 2153 | } |
| 2154 | break; |
| 2155 | case kEnableFrameCapture: |
Rajavenu Kyatham | 42d11cb | 2019-04-16 13:03:29 +0530 | [diff] [blame] | 2156 | ret = color_mgr_->SetFrameCapture(pending_action.params, true, hwc_display_[display_id]); |
Varun Arora | dff7d8d | 2019-08-05 18:12:43 -0700 | [diff] [blame] | 2157 | callbacks_.Refresh(display_id); |
Ch Ganesh Kumar | 5d43ff6 | 2017-10-13 19:01:47 +0530 | [diff] [blame] | 2158 | break; |
| 2159 | case kDisableFrameCapture: |
| 2160 | ret = color_mgr_->SetFrameCapture(pending_action.params, false, |
Xu Yang | 2a979af | 2018-05-07 17:10:49 +0800 | [diff] [blame] | 2161 | hwc_display_[display_id]); |
Ch Ganesh Kumar | 5d43ff6 | 2017-10-13 19:01:47 +0530 | [diff] [blame] | 2162 | break; |
| 2163 | case kConfigureDetailedEnhancer: |
Rajavenu Kyatham | 42d11cb | 2019-04-16 13:03:29 +0530 | [diff] [blame] | 2164 | ret = color_mgr_->SetDetailedEnhancer(pending_action.params, hwc_display_[display_id]); |
Varun Arora | dff7d8d | 2019-08-05 18:12:43 -0700 | [diff] [blame] | 2165 | callbacks_.Refresh(display_id); |
Ch Ganesh Kumar | 5d43ff6 | 2017-10-13 19:01:47 +0530 | [diff] [blame] | 2166 | break; |
| 2167 | case kModeSet: |
| 2168 | ret = static_cast<int> |
Xu Yang | 2a979af | 2018-05-07 17:10:49 +0800 | [diff] [blame] | 2169 | (hwc_display_[display_id]->RestoreColorTransform()); |
Varun Arora | dff7d8d | 2019-08-05 18:12:43 -0700 | [diff] [blame] | 2170 | callbacks_.Refresh(display_id); |
Ch Ganesh Kumar | 5d43ff6 | 2017-10-13 19:01:47 +0530 | [diff] [blame] | 2171 | break; |
| 2172 | case kNoAction: |
| 2173 | break; |
Xu Yang | 2a979af | 2018-05-07 17:10:49 +0800 | [diff] [blame] | 2174 | case kMultiDispProc: |
| 2175 | for (auto &map_info : map_info_builtin_) { |
| 2176 | uint32_t id = UINT32(map_info.client_id); |
Padmanabhan Komanduru | e74cf4f | 2019-04-25 17:38:43 -0700 | [diff] [blame] | 2177 | if (id < HWCCallbacks::kNumDisplays && hwc_display_[id]) { |
Xu Yang | 2a979af | 2018-05-07 17:10:49 +0800 | [diff] [blame] | 2178 | int result = 0; |
| 2179 | resp_payload.DestroyPayload(); |
Rajavenu Kyatham | 42d11cb | 2019-04-16 13:03:29 +0530 | [diff] [blame] | 2180 | result = hwc_display_[id]->ColorSVCRequestRoute(req_payload, &resp_payload, |
Xu Yang | 2a979af | 2018-05-07 17:10:49 +0800 | [diff] [blame] | 2181 | &pending_action); |
| 2182 | if (result) { |
| 2183 | DLOGW("Failed to dispatch action to disp %d ret %d", id, result); |
| 2184 | ret = result; |
| 2185 | } |
| 2186 | } |
| 2187 | } |
| 2188 | break; |
| 2189 | case kMultiDispGetId: |
Padmanabhan Komanduru | e74cf4f | 2019-04-25 17:38:43 -0700 | [diff] [blame] | 2190 | ret = resp_payload.CreatePayloadBytes(HWCCallbacks::kNumDisplays, &disp_id); |
Xu Yang | 2a979af | 2018-05-07 17:10:49 +0800 | [diff] [blame] | 2191 | if (ret) { |
| 2192 | DLOGW("Unable to create response payload!"); |
| 2193 | } else { |
Padmanabhan Komanduru | e74cf4f | 2019-04-25 17:38:43 -0700 | [diff] [blame] | 2194 | for (int i = 0; i < HWCCallbacks::kNumDisplays; i++) { |
| 2195 | disp_id[i] = HWCCallbacks::kNumDisplays; |
Xu Yang | 2a979af | 2018-05-07 17:10:49 +0800 | [diff] [blame] | 2196 | } |
| 2197 | if (hwc_display_[HWC_DISPLAY_PRIMARY]) { |
| 2198 | disp_id[HWC_DISPLAY_PRIMARY] = HWC_DISPLAY_PRIMARY; |
| 2199 | } |
| 2200 | for (auto &map_info : map_info_builtin_) { |
| 2201 | uint64_t id = map_info.client_id; |
Padmanabhan Komanduru | e74cf4f | 2019-04-25 17:38:43 -0700 | [diff] [blame] | 2202 | if (id < HWCCallbacks::kNumDisplays && hwc_display_[id]) { |
Xu Yang | 2a979af | 2018-05-07 17:10:49 +0800 | [diff] [blame] | 2203 | disp_id[id] = (uint8_t)id; |
| 2204 | } |
| 2205 | } |
| 2206 | } |
| 2207 | break; |
Qing Huang | 02285c3 | 2018-12-06 16:30:38 +0800 | [diff] [blame] | 2208 | case kSetModeFromClient: |
| 2209 | { |
| 2210 | SCOPE_LOCK(locker_[display_id]); |
| 2211 | mode_id = reinterpret_cast<int32_t *>(resp_payload.payload); |
| 2212 | if (mode_id) { |
| 2213 | ret = static_cast<int>(hwc_display_[display_id]->SetColorModeFromClientApi(*mode_id)); |
| 2214 | } else { |
| 2215 | DLOGE("mode_id is Null"); |
| 2216 | ret = -EINVAL; |
| 2217 | } |
| 2218 | } |
| 2219 | if (!ret) { |
Varun Arora | dff7d8d | 2019-08-05 18:12:43 -0700 | [diff] [blame] | 2220 | callbacks_.Refresh(display_id); |
Qing Huang | 02285c3 | 2018-12-06 16:30:38 +0800 | [diff] [blame] | 2221 | } |
| 2222 | break; |
Ch Ganesh Kumar | 5d43ff6 | 2017-10-13 19:01:47 +0530 | [diff] [blame] | 2223 | default: |
| 2224 | DLOGW("Invalid pending action = %d!", pending_action.action); |
| 2225 | break; |
| 2226 | } |
Mathew Joseph Karimpanal | dbd64f8 | 2017-10-06 10:13:38 +0530 | [diff] [blame] | 2227 | } |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 2228 | } |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 2229 | // for display API getter case, marshall returned params into out_parcel. |
| 2230 | output_parcel->writeInt32(ret); |
| 2231 | HWCColorManager::MarshallStructIntoParcel(resp_payload, output_parcel); |
| 2232 | req_payload.DestroyPayload(); |
| 2233 | resp_payload.DestroyPayload(); |
Sushil Chauhan | d6429af | 2018-11-15 11:34:27 -0800 | [diff] [blame] | 2234 | |
| 2235 | SEQUENCE_WAIT_SCOPE_LOCK(locker_[display_id]); |
Ray Zhang | 2ee8247 | 2019-09-05 02:53:29 +0800 | [diff] [blame] | 2236 | hwc_display_[display_id]->ResetValidation(); |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 2237 | |
Mathew Joseph Karimpanal | dbd64f8 | 2017-10-06 10:13:38 +0530 | [diff] [blame] | 2238 | return ret; |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 2239 | } |
| 2240 | |
Dileep Marchya | f3ce11f | 2018-04-30 23:35:46 +0530 | [diff] [blame] | 2241 | int GetEventValue(const char *uevent_data, int length, const char *event_info) { |
| 2242 | const char *iterator_str = uevent_data; |
| 2243 | while (((iterator_str - uevent_data) <= length) && (*iterator_str)) { |
| 2244 | const char *pstr = strstr(iterator_str, event_info); |
| 2245 | if (pstr != NULL) { |
| 2246 | return (atoi(iterator_str + strlen(event_info))); |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 2247 | } |
Dileep Marchya | f3ce11f | 2018-04-30 23:35:46 +0530 | [diff] [blame] | 2248 | iterator_str += strlen(iterator_str) + 1; |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 2249 | } |
Dileep Marchya | f3ce11f | 2018-04-30 23:35:46 +0530 | [diff] [blame] | 2250 | |
| 2251 | return -1; |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 2252 | } |
| 2253 | |
Prabhanjan Kandula | 0236771 | 2017-08-10 20:09:25 -0700 | [diff] [blame] | 2254 | const char *GetTokenValue(const char *uevent_data, int length, const char *token) { |
Prabhanjan Kandula | 34ffec0 | 2017-04-25 11:56:39 -0700 | [diff] [blame] | 2255 | const char *iterator_str = uevent_data; |
Prabhanjan Kandula | 34ffec0 | 2017-04-25 11:56:39 -0700 | [diff] [blame] | 2256 | const char *pstr = NULL; |
| 2257 | while (((iterator_str - uevent_data) <= length) && (*iterator_str)) { |
Prabhanjan Kandula | 0236771 | 2017-08-10 20:09:25 -0700 | [diff] [blame] | 2258 | pstr = strstr(iterator_str, token); |
| 2259 | if (pstr) { |
Prabhanjan Kandula | 34ffec0 | 2017-04-25 11:56:39 -0700 | [diff] [blame] | 2260 | break; |
| 2261 | } |
| 2262 | iterator_str += strlen(iterator_str) + 1; |
| 2263 | } |
| 2264 | |
Prabhanjan Kandula | 0236771 | 2017-08-10 20:09:25 -0700 | [diff] [blame] | 2265 | if (pstr) |
| 2266 | pstr = pstr+strlen(token); |
| 2267 | |
| 2268 | return pstr; |
| 2269 | } |
| 2270 | |
Pullakavi Srinivas | 9189e60 | 2018-12-19 16:58:07 +0530 | [diff] [blame] | 2271 | android::status_t HWCSession::SetDsiClk(const android::Parcel *input_parcel) { |
| 2272 | int disp_id = input_parcel->readInt32(); |
| 2273 | uint64_t clk = UINT64(input_parcel->readInt64()); |
Dileep Marchya | afa45bc | 2019-06-21 17:05:31 +0530 | [diff] [blame] | 2274 | if (disp_id < 0) { |
| 2275 | return -EINVAL; |
| 2276 | } |
| 2277 | |
| 2278 | SEQUENCE_WAIT_SCOPE_LOCK(locker_[disp_id]); |
| 2279 | if (!hwc_display_[disp_id]) { |
Pullakavi Srinivas | 9189e60 | 2018-12-19 16:58:07 +0530 | [diff] [blame] | 2280 | return -EINVAL; |
| 2281 | } |
| 2282 | |
| 2283 | return hwc_display_[disp_id]->SetDynamicDSIClock(clk); |
| 2284 | } |
| 2285 | |
| 2286 | android::status_t HWCSession::GetDsiClk(const android::Parcel *input_parcel, |
| 2287 | android::Parcel *output_parcel) { |
| 2288 | int disp_id = input_parcel->readInt32(); |
Dileep Marchya | afa45bc | 2019-06-21 17:05:31 +0530 | [diff] [blame] | 2289 | if (disp_id < 0) { |
| 2290 | return -EINVAL; |
| 2291 | } |
| 2292 | |
| 2293 | SEQUENCE_WAIT_SCOPE_LOCK(locker_[disp_id]); |
| 2294 | if (!hwc_display_[disp_id]) { |
Pullakavi Srinivas | 9189e60 | 2018-12-19 16:58:07 +0530 | [diff] [blame] | 2295 | return -EINVAL; |
| 2296 | } |
| 2297 | |
| 2298 | uint64_t bitrate = 0; |
| 2299 | hwc_display_[disp_id]->GetDynamicDSIClock(&bitrate); |
| 2300 | output_parcel->writeUint64(bitrate); |
| 2301 | |
| 2302 | return 0; |
| 2303 | } |
| 2304 | |
| 2305 | android::status_t HWCSession::GetSupportedDsiClk(const android::Parcel *input_parcel, |
| 2306 | android::Parcel *output_parcel) { |
| 2307 | int disp_id = input_parcel->readInt32(); |
Dileep Marchya | afa45bc | 2019-06-21 17:05:31 +0530 | [diff] [blame] | 2308 | if (disp_id < 0) { |
| 2309 | return -EINVAL; |
| 2310 | } |
| 2311 | |
| 2312 | SCOPE_LOCK(locker_[disp_id]); |
| 2313 | if (!hwc_display_[disp_id]) { |
Pullakavi Srinivas | 9189e60 | 2018-12-19 16:58:07 +0530 | [diff] [blame] | 2314 | return -EINVAL; |
| 2315 | } |
| 2316 | |
| 2317 | std::vector<uint64_t> bit_rates; |
| 2318 | hwc_display_[disp_id]->GetSupportedDSIClock(&bit_rates); |
| 2319 | output_parcel->writeInt32(INT32(bit_rates.size())); |
| 2320 | for (auto &bit_rate : bit_rates) { |
| 2321 | output_parcel->writeUint64(bit_rate); |
| 2322 | } |
| 2323 | |
| 2324 | return 0; |
| 2325 | } |
| 2326 | |
Archit Srivastava | a59c4ff | 2019-05-20 10:54:22 +0530 | [diff] [blame] | 2327 | android::status_t HWCSession::SetPanelLuminanceAttributes(const android::Parcel *input_parcel) { |
| 2328 | int disp_id = input_parcel->readInt32(); |
| 2329 | |
| 2330 | // currently doing only for virtual display |
| 2331 | if (disp_id != qdutils::DISPLAY_VIRTUAL) { |
| 2332 | return -EINVAL; |
| 2333 | } |
| 2334 | |
Padmanabhan Komanduru | e4d31fc | 2019-09-12 19:13:17 +0530 | [diff] [blame] | 2335 | float min_lum = input_parcel->readFloat(); |
| 2336 | float max_lum = input_parcel->readFloat(); |
| 2337 | |
| 2338 | // check for out of range luminance values |
| 2339 | if (min_lum <= 0.0f || min_lum >= 1.0f || max_lum <= 100.0f || max_lum >= 1000.0f) { |
| 2340 | return -EINVAL; |
| 2341 | } |
| 2342 | |
Archit Srivastava | a59c4ff | 2019-05-20 10:54:22 +0530 | [diff] [blame] | 2343 | std::lock_guard<std::mutex> obj(mutex_lum_); |
Padmanabhan Komanduru | e4d31fc | 2019-09-12 19:13:17 +0530 | [diff] [blame] | 2344 | set_min_lum_ = min_lum; |
| 2345 | set_max_lum_ = max_lum; |
Archit Srivastava | a59c4ff | 2019-05-20 10:54:22 +0530 | [diff] [blame] | 2346 | DLOGI("set max_lum %f, min_lum %f", set_max_lum_, set_min_lum_); |
| 2347 | |
| 2348 | return 0; |
| 2349 | } |
| 2350 | |
Dileep Marchya | f3ce11f | 2018-04-30 23:35:46 +0530 | [diff] [blame] | 2351 | void HWCSession::UEventHandler(const char *uevent_data, int length) { |
Mathew Joseph Karimpanal | 1289229 | 2019-03-21 16:07:59 +0530 | [diff] [blame] | 2352 | // Drop hotplug uevents until SurfaceFlinger (the client) is connected. The equivalent of hotplug |
| 2353 | // uevent handling will be done once when SurfaceFlinger connects, at RegisterCallback(). Since |
| 2354 | // HandlePluggableDisplays() reads the latest connection states of all displays, no uevent is |
| 2355 | // lost. |
Varun Arora | dff7d8d | 2019-08-05 18:12:43 -0700 | [diff] [blame] | 2356 | if (callbacks_.IsClientConnected() && strcasestr(uevent_data, HWC_UEVENT_DRM_EXT_HOTPLUG)) { |
Dileep Marchya | f3ce11f | 2018-04-30 23:35:46 +0530 | [diff] [blame] | 2357 | // MST hotplug will not carry connection status/test pattern etc. |
| 2358 | // Pluggable display handler will check all connection status' and take action accordingly. |
| 2359 | const char *str_status = GetTokenValue(uevent_data, length, "status="); |
| 2360 | const char *str_mst = GetTokenValue(uevent_data, length, "MST_HOTPLUG="); |
| 2361 | if (!str_status && !str_mst) { |
| 2362 | return; |
Ramakant Singh | fae5989 | 2017-09-13 10:40:22 +0530 | [diff] [blame] | 2363 | } |
Prabhanjan Kandula | 34ffec0 | 2017-04-25 11:56:39 -0700 | [diff] [blame] | 2364 | |
Dileep Marchya | f3ce11f | 2018-04-30 23:35:46 +0530 | [diff] [blame] | 2365 | hpd_bpp_ = GetEventValue(uevent_data, length, "bpp="); |
| 2366 | hpd_pattern_ = GetEventValue(uevent_data, length, "pattern="); |
Varun Arora | d366c20 | 2018-09-26 14:00:56 -0700 | [diff] [blame] | 2367 | DLOGI("Uevent = %s, status = %s, MST_HOTPLUG = %s, bpp = %d, pattern = %d", uevent_data, |
| 2368 | 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] | 2369 | |
| 2370 | hwc2_display_t virtual_display_index = |
| 2371 | (hwc2_display_t)GetDisplayIndex(qdutils::DISPLAY_VIRTUAL); |
| 2372 | |
| 2373 | std::bitset<kSecureMax> secure_sessions = 0; |
Ramkumar Radhakrishnan | 44c6436 | 2018-12-12 13:03:59 -0800 | [diff] [blame] | 2374 | hwc2_display_t active_builtin_disp_id = GetActiveBuiltinDisplay(); |
Padmanabhan Komanduru | e74cf4f | 2019-04-25 17:38:43 -0700 | [diff] [blame] | 2375 | if (active_builtin_disp_id < HWCCallbacks::kNumDisplays) { |
Ramkumar Radhakrishnan | 44c6436 | 2018-12-12 13:03:59 -0800 | [diff] [blame] | 2376 | Locker::ScopeLock lock_a(locker_[active_builtin_disp_id]); |
| 2377 | hwc_display_[active_builtin_disp_id]->GetActiveSecureSession(&secure_sessions); |
Mathew Joseph Karimpanal | 71ac8a7 | 2018-09-25 22:27:22 +0530 | [diff] [blame] | 2378 | } |
| 2379 | if (secure_sessions[kSecureDisplay] || hwc_display_[virtual_display_index]) { |
Mathew Joseph Karimpanal | abe3b3d | 2018-11-27 17:25:40 +0530 | [diff] [blame] | 2380 | // Defer hotplug handling. |
| 2381 | SCOPE_LOCK(pluggable_handler_lock_); |
| 2382 | DLOGI("Marking hotplug pending..."); |
Mathew Joseph Karimpanal | b1c1586 | 2019-07-04 11:14:24 +0530 | [diff] [blame] | 2383 | pending_hotplug_event_ = kHotPlugEvent; |
Mathew Joseph Karimpanal | abe3b3d | 2018-11-27 17:25:40 +0530 | [diff] [blame] | 2384 | } else { |
| 2385 | // Handle hotplug. |
| 2386 | int32_t err = HandlePluggableDisplays(true); |
| 2387 | if (err) { |
| 2388 | DLOGW("Hotplug handling failed. Error %d '%s'. Hotplug handling %s.", err, |
Mathew Joseph Karimpanal | b1c1586 | 2019-07-04 11:14:24 +0530 | [diff] [blame] | 2389 | strerror(abs(err)), (pending_hotplug_event_ == kHotPlugEvent) ? |
Mathew Joseph Karimpanal | abe3b3d | 2018-11-27 17:25:40 +0530 | [diff] [blame] | 2390 | "deferred" : "dropped"); |
| 2391 | } |
Dileep Marchya | f3ce11f | 2018-04-30 23:35:46 +0530 | [diff] [blame] | 2392 | } |
| 2393 | |
| 2394 | if (str_status) { |
| 2395 | bool connected = (strncmp(str_status, "connected", strlen("connected")) == 0); |
| 2396 | DLOGI("Connected = %d", connected); |
Mathew Joseph Karimpanal | 71ac8a7 | 2018-09-25 22:27:22 +0530 | [diff] [blame] | 2397 | // Pass on legacy HDMI hot-plug event. |
Dileep Marchya | f3ce11f | 2018-04-30 23:35:46 +0530 | [diff] [blame] | 2398 | qservice_->onHdmiHotplug(INT(connected)); |
| 2399 | } |
Prabhanjan Kandula | 34ffec0 | 2017-04-25 11:56:39 -0700 | [diff] [blame] | 2400 | } |
| 2401 | } |
| 2402 | |
Naseer Ahmed | 8584a0f | 2020-02-19 22:23:30 -0500 | [diff] [blame] | 2403 | int32_t HWCSession::GetVsyncPeriod(hwc2_display_t disp, uint32_t *vsync_period) { |
| 2404 | if (disp >= HWCCallbacks::kNumDisplays) { |
| 2405 | DLOGW("Invalid Display : display = %" PRIu64, disp); |
| 2406 | return HWC2_ERROR_BAD_DISPLAY; |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 2407 | } |
| 2408 | |
Naseer Ahmed | 8584a0f | 2020-02-19 22:23:30 -0500 | [diff] [blame] | 2409 | SCOPE_LOCK(locker_[(int)disp]); |
| 2410 | // default value |
| 2411 | *vsync_period = 1000000000ul / 60; |
| 2412 | |
| 2413 | if (hwc_display_[disp]) { |
| 2414 | hwc_display_[disp]->GetDisplayAttribute(0, HwcAttribute::VSYNC_PERIOD, (int32_t *)vsync_period); |
| 2415 | } |
| 2416 | |
| 2417 | return HWC2_ERROR_NONE; |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 2418 | } |
| 2419 | |
Mathew Joseph Karimpanal | f929747 | 2019-08-21 15:49:15 +0530 | [diff] [blame] | 2420 | void HWCSession::Refresh(hwc2_display_t display) { |
| 2421 | callbacks_.Refresh(display); |
| 2422 | } |
| 2423 | |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 2424 | android::status_t HWCSession::GetVisibleDisplayRect(const android::Parcel *input_parcel, |
| 2425 | android::Parcel *output_parcel) { |
Dileep Marchya | f3ce11f | 2018-04-30 23:35:46 +0530 | [diff] [blame] | 2426 | int disp_idx = GetDisplayIndex(input_parcel->readInt32()); |
| 2427 | if (disp_idx == -1) { |
| 2428 | DLOGE("Invalid display = %d", disp_idx); |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 2429 | return android::BAD_VALUE; |
| 2430 | } |
| 2431 | |
Dileep Marchya | f3ce11f | 2018-04-30 23:35:46 +0530 | [diff] [blame] | 2432 | SEQUENCE_WAIT_SCOPE_LOCK(locker_[disp_idx]); |
| 2433 | if (!hwc_display_[disp_idx]) { |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 2434 | return android::NO_INIT; |
| 2435 | } |
| 2436 | |
| 2437 | hwc_rect_t visible_rect = {0, 0, 0, 0}; |
Dileep Marchya | f3ce11f | 2018-04-30 23:35:46 +0530 | [diff] [blame] | 2438 | int error = hwc_display_[disp_idx]->GetVisibleDisplayRect(&visible_rect); |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 2439 | if (error < 0) { |
| 2440 | return error; |
| 2441 | } |
| 2442 | |
| 2443 | output_parcel->writeInt32(visible_rect.left); |
| 2444 | output_parcel->writeInt32(visible_rect.top); |
| 2445 | output_parcel->writeInt32(visible_rect.right); |
| 2446 | output_parcel->writeInt32(visible_rect.bottom); |
| 2447 | |
| 2448 | return android::NO_ERROR; |
| 2449 | } |
| 2450 | |
Dileep Marchya | f3ce11f | 2018-04-30 23:35:46 +0530 | [diff] [blame] | 2451 | int HWCSession::CreatePrimaryDisplay() { |
| 2452 | int status = -EINVAL; |
| 2453 | HWDisplaysInfo hw_displays_info = {}; |
Ramakant Singh | fae5989 | 2017-09-13 10:40:22 +0530 | [diff] [blame] | 2454 | |
Varun Arora | ad2719a | 2018-10-25 10:13:53 -0700 | [diff] [blame] | 2455 | if (null_display_mode_) { |
| 2456 | HWDisplayInfo hw_info = {}; |
| 2457 | hw_info.display_type = kBuiltIn; |
| 2458 | hw_info.is_connected = 1; |
| 2459 | hw_info.is_primary = 1; |
| 2460 | hw_info.is_wb_ubwc_supported = 0; |
| 2461 | hw_info.display_id = 1; |
| 2462 | hw_displays_info[hw_info.display_id] = hw_info; |
| 2463 | } else { |
| 2464 | DisplayError error = core_intf_->GetDisplaysStatus(&hw_displays_info); |
| 2465 | if (error != kErrorNone) { |
| 2466 | DLOGE("Failed to get connected display list. Error = %d", error); |
| 2467 | return status; |
| 2468 | } |
Ramakant Singh | fae5989 | 2017-09-13 10:40:22 +0530 | [diff] [blame] | 2469 | } |
| 2470 | |
Dileep Marchya | f3ce11f | 2018-04-30 23:35:46 +0530 | [diff] [blame] | 2471 | for (auto &iter : hw_displays_info) { |
| 2472 | auto &info = iter.second; |
| 2473 | if (!info.is_primary) { |
| 2474 | continue; |
| 2475 | } |
| 2476 | |
| 2477 | // todo (user): If primary display is not connected (e.g. hdmi as primary), a NULL display |
| 2478 | // need to be created. SF expects primary display hotplug during callback registration unlike |
| 2479 | // previous implementation where first hotplug could be notified anytime. |
| 2480 | if (!info.is_connected) { |
| 2481 | DLOGE("Primary display is not connected. Not supported at present."); |
| 2482 | break; |
| 2483 | } |
| 2484 | |
| 2485 | auto hwc_display = &hwc_display_[HWC_DISPLAY_PRIMARY]; |
| 2486 | hwc2_display_t client_id = map_info_primary_.client_id; |
| 2487 | |
Dileep Marchya | f3ce11f | 2018-04-30 23:35:46 +0530 | [diff] [blame] | 2488 | if (info.display_type == kBuiltIn) { |
| 2489 | status = HWCDisplayBuiltIn::Create(core_intf_, &buffer_allocator_, &callbacks_, this, |
| 2490 | qservice_, client_id, info.display_id, hwc_display); |
| 2491 | } else if (info.display_type == kPluggable) { |
| 2492 | status = HWCDisplayPluggable::Create(core_intf_, &buffer_allocator_, &callbacks_, this, |
| 2493 | qservice_, client_id, info.display_id, 0, 0, false, |
| 2494 | hwc_display); |
| 2495 | } else { |
| 2496 | DLOGE("Spurious primary display type = %d", info.display_type); |
| 2497 | break; |
| 2498 | } |
| 2499 | |
| 2500 | if (!status) { |
Varun Arora | d7d8c91 | 2019-08-16 11:45:19 -0700 | [diff] [blame] | 2501 | 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] | 2502 | info.display_id, client_id); |
| 2503 | { |
| 2504 | SCOPE_LOCK(hdr_locker_[client_id]); |
| 2505 | is_hdr_display_[UINT32(client_id)] = HasHDRSupport(*hwc_display); |
| 2506 | } |
| 2507 | |
Dileep Marchya | f3ce11f | 2018-04-30 23:35:46 +0530 | [diff] [blame] | 2508 | map_info_primary_.disp_type = info.display_type; |
| 2509 | map_info_primary_.sdm_id = info.display_id; |
Srinivas Pullakavi | 3c4337f | 2019-07-03 11:24:31 +0530 | [diff] [blame] | 2510 | CreateDummyDisplay(HWC_DISPLAY_PRIMARY); |
Dileep Marchya | f3ce11f | 2018-04-30 23:35:46 +0530 | [diff] [blame] | 2511 | color_mgr_ = HWCColorManager::CreateColorManager(&buffer_allocator_); |
| 2512 | if (!color_mgr_) { |
| 2513 | DLOGW("Failed to load HWCColorManager."); |
| 2514 | } |
| 2515 | } else { |
Varun Arora | d7d8c91 | 2019-08-16 11:45:19 -0700 | [diff] [blame] | 2516 | DLOGE("Primary display creation has failed! status = %d", status); |
Dileep Marchya | f3ce11f | 2018-04-30 23:35:46 +0530 | [diff] [blame] | 2517 | } |
| 2518 | |
| 2519 | // Primary display is found, no need to parse more. |
| 2520 | break; |
Ramakant Singh | fae5989 | 2017-09-13 10:40:22 +0530 | [diff] [blame] | 2521 | } |
| 2522 | |
Dileep Marchya | f3ce11f | 2018-04-30 23:35:46 +0530 | [diff] [blame] | 2523 | return status; |
Ramakant Singh | fae5989 | 2017-09-13 10:40:22 +0530 | [diff] [blame] | 2524 | } |
| 2525 | |
Srinivas Pullakavi | 3c4337f | 2019-07-03 11:24:31 +0530 | [diff] [blame] | 2526 | void HWCSession::CreateDummyDisplay(hwc2_display_t client_id) { |
| 2527 | if (!async_powermode_) { |
| 2528 | return; |
| 2529 | } |
| 2530 | |
| 2531 | hwc2_display_t dummy_disp_id = map_hwc_display_.find(client_id)->second; |
| 2532 | auto hwc_display_dummy = &hwc_display_[dummy_disp_id]; |
| 2533 | HWCDisplayDummy::Create(core_intf_, &buffer_allocator_, &callbacks_, this, qservice_, |
| 2534 | 0, 0, hwc_display_dummy); |
| 2535 | if (!*hwc_display_dummy) { |
| 2536 | DLOGE("Dummy display creation failed for %d display\n", client_id); |
| 2537 | } |
| 2538 | } |
| 2539 | |
Varun Arora | ad2719a | 2018-10-25 10:13:53 -0700 | [diff] [blame] | 2540 | int HWCSession::HandleBuiltInDisplays() { |
| 2541 | if (null_display_mode_) { |
| 2542 | DLOGW("Skipped BuiltIn display handling in null-display mode"); |
| 2543 | return 0; |
| 2544 | } |
Dileep Marchya | f3ce11f | 2018-04-30 23:35:46 +0530 | [diff] [blame] | 2545 | |
Varun Arora | ad2719a | 2018-10-25 10:13:53 -0700 | [diff] [blame] | 2546 | HWDisplaysInfo hw_displays_info = {}; |
Dileep Marchya | f3ce11f | 2018-04-30 23:35:46 +0530 | [diff] [blame] | 2547 | DisplayError error = core_intf_->GetDisplaysStatus(&hw_displays_info); |
| 2548 | if (error != kErrorNone) { |
| 2549 | DLOGE("Failed to get connected display list. Error = %d", error); |
| 2550 | return -EINVAL; |
| 2551 | } |
| 2552 | |
| 2553 | int status = 0; |
Dileep Marchya | f3ce11f | 2018-04-30 23:35:46 +0530 | [diff] [blame] | 2554 | for (auto &iter : hw_displays_info) { |
| 2555 | auto &info = iter.second; |
| 2556 | |
| 2557 | // Do not recreate primary display. |
| 2558 | if (info.is_primary || info.display_type != kBuiltIn) { |
| 2559 | continue; |
| 2560 | } |
| 2561 | |
Pullakavi Srinivas | f2a3185 | 2019-04-23 14:32:08 -0700 | [diff] [blame] | 2562 | for (auto &map_info : map_info_builtin_) { |
| 2563 | hwc2_display_t client_id = map_info.client_id; |
Mathew Joseph Karimpanal | 8abb6e0 | 2018-11-20 09:52:49 +0530 | [diff] [blame] | 2564 | |
Pullakavi Srinivas | f2a3185 | 2019-04-23 14:32:08 -0700 | [diff] [blame] | 2565 | { |
| 2566 | SCOPE_LOCK(locker_[client_id]); |
| 2567 | // Lock confined to this scope |
| 2568 | if (hwc_display_[client_id]) { |
| 2569 | continue; |
| 2570 | } |
Dileep Marchya | f3ce11f | 2018-04-30 23:35:46 +0530 | [diff] [blame] | 2571 | |
Pullakavi Srinivas | f2a3185 | 2019-04-23 14:32:08 -0700 | [diff] [blame] | 2572 | DLOGI("Create builtin display, sdm id = %d, client id = %d", info.display_id, client_id); |
| 2573 | status = HWCDisplayBuiltIn::Create(core_intf_, &buffer_allocator_, &callbacks_, this, |
| 2574 | qservice_, client_id, info.display_id, |
| 2575 | &hwc_display_[client_id]); |
| 2576 | if (status) { |
| 2577 | DLOGE("Builtin display creation failed."); |
| 2578 | break; |
| 2579 | } |
Pullakavi Srinivas | 1ae4acb | 2019-11-18 19:33:45 +0530 | [diff] [blame] | 2580 | |
| 2581 | { |
| 2582 | SCOPE_LOCK(hdr_locker_[client_id]); |
| 2583 | is_hdr_display_[UINT32(client_id)] = HasHDRSupport(hwc_display_[client_id]); |
| 2584 | } |
| 2585 | |
Mathew Joseph Karimpanal | 8abb6e0 | 2018-11-20 09:52:49 +0530 | [diff] [blame] | 2586 | 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] | 2587 | map_info.disp_type = info.display_type; |
| 2588 | map_info.sdm_id = info.display_id; |
Srinivas Pullakavi | 3c4337f | 2019-07-03 11:24:31 +0530 | [diff] [blame] | 2589 | CreateDummyDisplay(client_id); |
Dileep Marchya | f3ce11f | 2018-04-30 23:35:46 +0530 | [diff] [blame] | 2590 | } |
Dileep Marchya | f3ce11f | 2018-04-30 23:35:46 +0530 | [diff] [blame] | 2591 | |
Pullakavi Srinivas | f2a3185 | 2019-04-23 14:32:08 -0700 | [diff] [blame] | 2592 | DLOGI("Hotplugging builtin display, sdm id = %d, client id = %d", info.display_id, client_id); |
| 2593 | callbacks_.Hotplug(client_id, HWC2::Connection::Connected); |
| 2594 | break; |
| 2595 | } |
Dileep Marchya | f3ce11f | 2018-04-30 23:35:46 +0530 | [diff] [blame] | 2596 | } |
| 2597 | |
| 2598 | return status; |
Saurabh Shah | 04f932b | 2017-10-12 18:47:45 -0700 | [diff] [blame] | 2599 | } |
Dileep Marchya | f3ce11f | 2018-04-30 23:35:46 +0530 | [diff] [blame] | 2600 | |
Varun Arora | d366c20 | 2018-09-26 14:00:56 -0700 | [diff] [blame] | 2601 | int HWCSession::HandlePluggableDisplays(bool delay_hotplug) { |
Mathew Joseph Karimpanal | abe3b3d | 2018-11-27 17:25:40 +0530 | [diff] [blame] | 2602 | SCOPE_LOCK(pluggable_handler_lock_); |
Varun Arora | ad2719a | 2018-10-25 10:13:53 -0700 | [diff] [blame] | 2603 | if (null_display_mode_) { |
| 2604 | DLOGW("Skipped pluggable display handling in null-display mode"); |
| 2605 | return 0; |
| 2606 | } |
| 2607 | |
Mathew Joseph Karimpanal | abe3b3d | 2018-11-27 17:25:40 +0530 | [diff] [blame] | 2608 | DLOGI("Handling hotplug..."); |
Dileep Marchya | f3ce11f | 2018-04-30 23:35:46 +0530 | [diff] [blame] | 2609 | HWDisplaysInfo hw_displays_info = {}; |
Dileep Marchya | f3ce11f | 2018-04-30 23:35:46 +0530 | [diff] [blame] | 2610 | DisplayError error = core_intf_->GetDisplaysStatus(&hw_displays_info); |
| 2611 | if (error != kErrorNone) { |
| 2612 | DLOGE("Failed to get connected display list. Error = %d", error); |
| 2613 | return -EINVAL; |
| 2614 | } |
| 2615 | |
| 2616 | int status = HandleDisconnectedDisplays(&hw_displays_info); |
| 2617 | if (status) { |
| 2618 | DLOGE("All displays could not be disconnected."); |
| 2619 | return status; |
| 2620 | } |
| 2621 | |
| 2622 | status = HandleConnectedDisplays(&hw_displays_info, delay_hotplug); |
| 2623 | if (status) { |
Mathew Joseph Karimpanal | abe3b3d | 2018-11-27 17:25:40 +0530 | [diff] [blame] | 2624 | switch (status) { |
| 2625 | case -EAGAIN: |
| 2626 | case -ENODEV: |
| 2627 | // 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] | 2628 | pending_hotplug_event_ = kHotPlugEvent; |
Mathew Joseph Karimpanal | abe3b3d | 2018-11-27 17:25:40 +0530 | [diff] [blame] | 2629 | status = 0; |
| 2630 | break; |
| 2631 | default: |
| 2632 | // Real errors we want to flag and stop hotplug handling. |
Mathew Joseph Karimpanal | b1c1586 | 2019-07-04 11:14:24 +0530 | [diff] [blame] | 2633 | pending_hotplug_event_ = kHotPlugNone; |
Mathew Joseph Karimpanal | abe3b3d | 2018-11-27 17:25:40 +0530 | [diff] [blame] | 2634 | DLOGE("All displays could not be connected. Error %d '%s'.", status, strerror(abs(status))); |
| 2635 | } |
Mathew Joseph Karimpanal | b1c1586 | 2019-07-04 11:14:24 +0530 | [diff] [blame] | 2636 | DLOGI("Handling hotplug... %s", (kHotPlugNone == pending_hotplug_event_) ? |
Mathew Joseph Karimpanal | abe3b3d | 2018-11-27 17:25:40 +0530 | [diff] [blame] | 2637 | "Stopped." : "Done. Hotplug events pending."); |
| 2638 | return status; |
Dileep Marchya | f3ce11f | 2018-04-30 23:35:46 +0530 | [diff] [blame] | 2639 | } |
| 2640 | |
Mathew Joseph Karimpanal | b1c1586 | 2019-07-04 11:14:24 +0530 | [diff] [blame] | 2641 | pending_hotplug_event_ = kHotPlugNone; |
Mathew Joseph Karimpanal | abe3b3d | 2018-11-27 17:25:40 +0530 | [diff] [blame] | 2642 | |
| 2643 | DLOGI("Handling hotplug... Done."); |
Dileep Marchya | f3ce11f | 2018-04-30 23:35:46 +0530 | [diff] [blame] | 2644 | return 0; |
| 2645 | } |
| 2646 | |
| 2647 | int HWCSession::HandleConnectedDisplays(HWDisplaysInfo *hw_displays_info, bool delay_hotplug) { |
| 2648 | int status = 0; |
| 2649 | std::vector<hwc2_display_t> pending_hotplugs = {}; |
Padmanabhan Komanduru | f5b7f99 | 2019-07-08 13:33:44 +0530 | [diff] [blame] | 2650 | hwc2_display_t client_id = 0; |
Dileep Marchya | f3ce11f | 2018-04-30 23:35:46 +0530 | [diff] [blame] | 2651 | |
| 2652 | for (auto &iter : *hw_displays_info) { |
| 2653 | auto &info = iter.second; |
| 2654 | |
| 2655 | // Do not recreate primary display or if display is not connected. |
| 2656 | if (info.is_primary || info.display_type != kPluggable || !info.is_connected) { |
| 2657 | continue; |
| 2658 | } |
| 2659 | |
Mathew Joseph Karimpanal | bbc700b | 2018-07-19 19:54:24 +0530 | [diff] [blame] | 2660 | // Check if we are already using the display. |
| 2661 | auto display_used = std::find_if(map_info_pluggable_.begin(), map_info_pluggable_.end(), |
| 2662 | [&](auto &p) { |
| 2663 | return (p.sdm_id == info.display_id); |
| 2664 | }); |
| 2665 | if (display_used != map_info_pluggable_.end()) { |
| 2666 | // Display is already used in a slot. |
| 2667 | continue; |
| 2668 | } |
| 2669 | |
Mathew Joseph Karimpanal | abe3b3d | 2018-11-27 17:25:40 +0530 | [diff] [blame] | 2670 | // Count active pluggable display slots and slots with no commits. |
Mathew Joseph Karimpanal | abe3b3d | 2018-11-27 17:25:40 +0530 | [diff] [blame] | 2671 | bool first_commit_pending = false; |
Mathew Joseph Karimpanal | 8abb6e0 | 2018-11-20 09:52:49 +0530 | [diff] [blame] | 2672 | std::for_each(map_info_pluggable_.begin(), map_info_pluggable_.end(), |
| 2673 | [&](auto &p) { |
Mathew Joseph Karimpanal | abe3b3d | 2018-11-27 17:25:40 +0530 | [diff] [blame] | 2674 | SCOPE_LOCK(locker_[p.client_id]); |
Mathew Joseph Karimpanal | 8abb6e0 | 2018-11-20 09:52:49 +0530 | [diff] [blame] | 2675 | if (hwc_display_[p.client_id]) { |
Mathew Joseph Karimpanal | abe3b3d | 2018-11-27 17:25:40 +0530 | [diff] [blame] | 2676 | if (!hwc_display_[p.client_id]->IsFirstCommitDone()) { |
| 2677 | DLOGI("Display commit pending on display %d-1", p.sdm_id); |
| 2678 | first_commit_pending = true; |
| 2679 | } |
Mathew Joseph Karimpanal | 8abb6e0 | 2018-11-20 09:52:49 +0530 | [diff] [blame] | 2680 | } |
| 2681 | }); |
| 2682 | |
Mathew Joseph Karimpanal | abe3b3d | 2018-11-27 17:25:40 +0530 | [diff] [blame] | 2683 | if (!disable_hotplug_bwcheck_ && first_commit_pending) { |
| 2684 | // Hotplug bandwidth check is accomplished by creating and hotplugging a new display after |
| 2685 | // a display commit has happened on previous hotplugged displays. This allows the driver to |
| 2686 | // return updated modes for the new display based on available link bandwidth. |
| 2687 | DLOGI("Pending display commit on one of the displays. Deferring display creation."); |
| 2688 | status = -EAGAIN; |
Varun Arora | dff7d8d | 2019-08-05 18:12:43 -0700 | [diff] [blame] | 2689 | if (callbacks_.IsClientConnected()) { |
Mathew Joseph Karimpanal | abe3b3d | 2018-11-27 17:25:40 +0530 | [diff] [blame] | 2690 | // Trigger a display refresh since we depend on PresentDisplay() to handle pending hotplugs. |
| 2691 | hwc2_display_t active_builtin_disp_id = GetActiveBuiltinDisplay(); |
Padmanabhan Komanduru | e74cf4f | 2019-04-25 17:38:43 -0700 | [diff] [blame] | 2692 | if (active_builtin_disp_id >= HWCCallbacks::kNumDisplays) { |
Mathew Joseph Karimpanal | abe3b3d | 2018-11-27 17:25:40 +0530 | [diff] [blame] | 2693 | active_builtin_disp_id = HWC_DISPLAY_PRIMARY; |
| 2694 | } |
Varun Arora | dff7d8d | 2019-08-05 18:12:43 -0700 | [diff] [blame] | 2695 | callbacks_.Refresh(active_builtin_disp_id); |
Mathew Joseph Karimpanal | abe3b3d | 2018-11-27 17:25:40 +0530 | [diff] [blame] | 2696 | } |
| 2697 | break; |
| 2698 | } |
Mathew Joseph Karimpanal | 71ac8a7 | 2018-09-25 22:27:22 +0530 | [diff] [blame] | 2699 | |
Dileep Marchya | f3ce11f | 2018-04-30 23:35:46 +0530 | [diff] [blame] | 2700 | // find an empty slot to create display. |
| 2701 | for (auto &map_info : map_info_pluggable_) { |
Padmanabhan Komanduru | f5b7f99 | 2019-07-08 13:33:44 +0530 | [diff] [blame] | 2702 | client_id = map_info.client_id; |
Dileep Marchya | f3ce11f | 2018-04-30 23:35:46 +0530 | [diff] [blame] | 2703 | |
| 2704 | // Lock confined to this scope |
| 2705 | { |
| 2706 | SCOPE_LOCK(locker_[client_id]); |
| 2707 | auto &hwc_display = hwc_display_[client_id]; |
| 2708 | if (hwc_display) { |
Mathew Joseph Karimpanal | bbc700b | 2018-07-19 19:54:24 +0530 | [diff] [blame] | 2709 | // Display slot is already used. |
Dileep Marchya | f3ce11f | 2018-04-30 23:35:46 +0530 | [diff] [blame] | 2710 | continue; |
| 2711 | } |
| 2712 | |
| 2713 | DLOGI("Create pluggable display, sdm id = %d, client id = %d", info.display_id, client_id); |
| 2714 | |
| 2715 | // Test pattern generation ? |
| 2716 | map_info.test_pattern = (hpd_bpp_ > 0) && (hpd_pattern_ > 0); |
Mathew Joseph Karimpanal | 23e2da0 | 2018-11-13 17:44:43 +0530 | [diff] [blame] | 2717 | int err = 0; |
Dileep Marchya | f3ce11f | 2018-04-30 23:35:46 +0530 | [diff] [blame] | 2718 | if (!map_info.test_pattern) { |
Mathew Joseph Karimpanal | 23e2da0 | 2018-11-13 17:44:43 +0530 | [diff] [blame] | 2719 | err = HWCDisplayPluggable::Create(core_intf_, &buffer_allocator_, |
| 2720 | &callbacks_, this, qservice_, client_id, |
| 2721 | info.display_id, 0, 0, false, &hwc_display); |
Dileep Marchya | f3ce11f | 2018-04-30 23:35:46 +0530 | [diff] [blame] | 2722 | } else { |
Mathew Joseph Karimpanal | 23e2da0 | 2018-11-13 17:44:43 +0530 | [diff] [blame] | 2723 | err = HWCDisplayPluggableTest::Create(core_intf_, &buffer_allocator_, |
| 2724 | &callbacks_, this, qservice_, client_id, |
| 2725 | info.display_id, UINT32(hpd_bpp_), |
| 2726 | UINT32(hpd_pattern_), &hwc_display); |
Dileep Marchya | f3ce11f | 2018-04-30 23:35:46 +0530 | [diff] [blame] | 2727 | } |
| 2728 | |
Mathew Joseph Karimpanal | 23e2da0 | 2018-11-13 17:44:43 +0530 | [diff] [blame] | 2729 | if (err) { |
Mathew Joseph Karimpanal | abe3b3d | 2018-11-27 17:25:40 +0530 | [diff] [blame] | 2730 | DLOGW("Pluggable display creation failed/aborted. Error %d '%s'.", err, |
| 2731 | strerror(abs(err))); |
Mathew Joseph Karimpanal | 23e2da0 | 2018-11-13 17:44:43 +0530 | [diff] [blame] | 2732 | status = err; |
| 2733 | // Attempt creating remaining pluggable displays. |
| 2734 | break; |
Dileep Marchya | f3ce11f | 2018-04-30 23:35:46 +0530 | [diff] [blame] | 2735 | } |
| 2736 | |
Pullakavi Srinivas | 1ae4acb | 2019-11-18 19:33:45 +0530 | [diff] [blame] | 2737 | { |
| 2738 | SCOPE_LOCK(hdr_locker_[client_id]); |
| 2739 | is_hdr_display_[UINT32(client_id)] = HasHDRSupport(hwc_display); |
| 2740 | } |
| 2741 | |
Mathew Joseph Karimpanal | bbc700b | 2018-07-19 19:54:24 +0530 | [diff] [blame] | 2742 | DLOGI("Created pluggable display successfully: sdm id = %d, client id = %d", |
| 2743 | info.display_id, client_id); |
Srinivas Pullakavi | 3c4337f | 2019-07-03 11:24:31 +0530 | [diff] [blame] | 2744 | CreateDummyDisplay(client_id); |
Dileep Marchya | f3ce11f | 2018-04-30 23:35:46 +0530 | [diff] [blame] | 2745 | } |
| 2746 | |
| 2747 | map_info.disp_type = info.display_type; |
| 2748 | map_info.sdm_id = info.display_id; |
| 2749 | |
| 2750 | pending_hotplugs.push_back((hwc2_display_t)client_id); |
| 2751 | |
| 2752 | // Display is created for this sdm id, move to next connected display. |
| 2753 | break; |
| 2754 | } |
| 2755 | } |
| 2756 | |
| 2757 | // No display was created. |
| 2758 | if (!pending_hotplugs.size()) { |
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 | |
Ramkumar Radhakrishnan | 44c6436 | 2018-12-12 13:03:59 -0800 | [diff] [blame] | 2762 | // Active builtin display needs revalidation |
| 2763 | hwc2_display_t active_builtin_disp_id = GetActiveBuiltinDisplay(); |
Padmanabhan Komanduru | e74cf4f | 2019-04-25 17:38:43 -0700 | [diff] [blame] | 2764 | if (active_builtin_disp_id < HWCCallbacks::kNumDisplays) { |
Padmanabhan Komanduru | f5b7f99 | 2019-07-08 13:33:44 +0530 | [diff] [blame] | 2765 | WaitForResources(delay_hotplug, active_builtin_disp_id, client_id); |
Dileep Marchya | f3ce11f | 2018-04-30 23:35:46 +0530 | [diff] [blame] | 2766 | } |
| 2767 | |
| 2768 | for (auto client_id : pending_hotplugs) { |
Mathew Joseph Karimpanal | bbc700b | 2018-07-19 19:54:24 +0530 | [diff] [blame] | 2769 | DLOGI("Notify hotplug display connected: client id = %d", client_id); |
Dileep Marchya | f3ce11f | 2018-04-30 23:35:46 +0530 | [diff] [blame] | 2770 | callbacks_.Hotplug(client_id, HWC2::Connection::Connected); |
| 2771 | } |
| 2772 | |
Mathew Joseph Karimpanal | 23e2da0 | 2018-11-13 17:44:43 +0530 | [diff] [blame] | 2773 | return status; |
Dileep Marchya | f3ce11f | 2018-04-30 23:35:46 +0530 | [diff] [blame] | 2774 | } |
| 2775 | |
Archit Srivastava | fe060f7 | 2019-05-27 15:51:58 +0530 | [diff] [blame] | 2776 | bool HWCSession::HasHDRSupport(HWCDisplay *hwc_display) { |
| 2777 | // query number of hdr types |
| 2778 | uint32_t out_num_types = 0; |
| 2779 | float out_max_luminance = 0.0f; |
| 2780 | float out_max_average_luminance = 0.0f; |
| 2781 | float out_min_luminance = 0.0f; |
| 2782 | if (hwc_display->GetHdrCapabilities(&out_num_types, nullptr, &out_max_luminance, |
| 2783 | &out_max_average_luminance, &out_min_luminance) |
| 2784 | != HWC2::Error::None) { |
| 2785 | return false; |
| 2786 | } |
| 2787 | |
| 2788 | return (out_num_types > 0); |
| 2789 | } |
| 2790 | |
Dileep Marchya | f3ce11f | 2018-04-30 23:35:46 +0530 | [diff] [blame] | 2791 | int HWCSession::HandleDisconnectedDisplays(HWDisplaysInfo *hw_displays_info) { |
| 2792 | // Destroy pluggable displays which were connected earlier but got disconnected now. |
| 2793 | for (auto &map_info : map_info_pluggable_) { |
| 2794 | bool disconnect = true; // disconnect in case display id is not found in list. |
| 2795 | |
| 2796 | for (auto &iter : *hw_displays_info) { |
| 2797 | auto &info = iter.second; |
| 2798 | if (info.display_id != map_info.sdm_id) { |
| 2799 | continue; |
| 2800 | } |
| 2801 | if (info.is_connected) { |
| 2802 | disconnect = false; |
| 2803 | } |
Mathew Joseph Karimpanal | bbc700b | 2018-07-19 19:54:24 +0530 | [diff] [blame] | 2804 | break; |
Dileep Marchya | f3ce11f | 2018-04-30 23:35:46 +0530 | [diff] [blame] | 2805 | } |
| 2806 | |
| 2807 | if (disconnect) { |
Mathew Joseph Karimpanal | 71ac8a7 | 2018-09-25 22:27:22 +0530 | [diff] [blame] | 2808 | DestroyDisplay(&map_info); |
Dileep Marchya | f3ce11f | 2018-04-30 23:35:46 +0530 | [diff] [blame] | 2809 | } |
| 2810 | } |
| 2811 | |
| 2812 | return 0; |
| 2813 | } |
| 2814 | |
| 2815 | void HWCSession::DestroyDisplay(DisplayMapInfo *map_info) { |
Ramakant Singh | 07254e0 | 2018-10-31 20:45:01 +0530 | [diff] [blame] | 2816 | switch (map_info->disp_type) { |
| 2817 | case kPluggable: |
| 2818 | DestroyPluggableDisplay(map_info); |
| 2819 | break; |
| 2820 | default: |
| 2821 | DestroyNonPluggableDisplay(map_info); |
| 2822 | break; |
| 2823 | } |
| 2824 | } |
Dileep Marchya | f3ce11f | 2018-04-30 23:35:46 +0530 | [diff] [blame] | 2825 | |
Ramakant Singh | 07254e0 | 2018-10-31 20:45:01 +0530 | [diff] [blame] | 2826 | void HWCSession::DestroyPluggableDisplay(DisplayMapInfo *map_info) { |
| 2827 | hwc2_display_t client_id = map_info->client_id; |
| 2828 | |
| 2829 | DLOGI("Notify hotplug display disconnected: client id = %d", client_id); |
| 2830 | callbacks_.Hotplug(client_id, HWC2::Connection::Disconnected); |
Rajavenu Kyatham | 418acc2 | 2019-02-25 15:36:25 +0530 | [diff] [blame] | 2831 | |
Dileep Marchya | f3ce11f | 2018-04-30 23:35:46 +0530 | [diff] [blame] | 2832 | { |
| 2833 | SCOPE_LOCK(locker_[client_id]); |
Dileep Marchya | f3ce11f | 2018-04-30 23:35:46 +0530 | [diff] [blame] | 2834 | auto &hwc_display = hwc_display_[client_id]; |
| 2835 | if (!hwc_display) { |
| 2836 | return; |
| 2837 | } |
Mathew Joseph Karimpanal | bbc700b | 2018-07-19 19:54:24 +0530 | [diff] [blame] | 2838 | 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] | 2839 | client_id); |
Pullakavi Srinivas | 1ae4acb | 2019-11-18 19:33:45 +0530 | [diff] [blame] | 2840 | { |
| 2841 | SCOPE_LOCK(hdr_locker_[client_id]); |
| 2842 | is_hdr_display_[UINT32(client_id)] = false; |
| 2843 | } |
Dileep Marchya | f3ce11f | 2018-04-30 23:35:46 +0530 | [diff] [blame] | 2844 | |
Ramakant Singh | 07254e0 | 2018-10-31 20:45:01 +0530 | [diff] [blame] | 2845 | if (!map_info->test_pattern) { |
| 2846 | HWCDisplayPluggable::Destroy(hwc_display); |
| 2847 | } else { |
| 2848 | HWCDisplayPluggableTest::Destroy(hwc_display); |
Dileep Marchya | f3ce11f | 2018-04-30 23:35:46 +0530 | [diff] [blame] | 2849 | } |
Ramakant Singh | 07254e0 | 2018-10-31 20:45:01 +0530 | [diff] [blame] | 2850 | |
Srinivas Pullakavi | 3c4337f | 2019-07-03 11:24:31 +0530 | [diff] [blame] | 2851 | if (async_powermode_) { |
| 2852 | hwc2_display_t dummy_disp_id = map_hwc_display_.find(client_id)->second; |
| 2853 | auto &hwc_display_dummy = hwc_display_[dummy_disp_id]; |
| 2854 | display_ready_.reset(UINT32(dummy_disp_id)); |
| 2855 | if (hwc_display_dummy) { |
| 2856 | HWCDisplayDummy::Destroy(hwc_display_dummy); |
| 2857 | hwc_display_dummy = nullptr; |
| 2858 | } |
| 2859 | } |
| 2860 | display_ready_.reset(UINT32(client_id)); |
Rajavenu Kyatham | b035224 | 2019-12-17 12:08:55 +0530 | [diff] [blame] | 2861 | pending_power_mode_[client_id] = false; |
Dileep Marchya | f3ce11f | 2018-04-30 23:35:46 +0530 | [diff] [blame] | 2862 | hwc_display = nullptr; |
| 2863 | map_info->Reset(); |
| 2864 | } |
Ramakant Singh | 07254e0 | 2018-10-31 20:45:01 +0530 | [diff] [blame] | 2865 | } |
Dileep Marchya | f3ce11f | 2018-04-30 23:35:46 +0530 | [diff] [blame] | 2866 | |
Ramakant Singh | 07254e0 | 2018-10-31 20:45:01 +0530 | [diff] [blame] | 2867 | void HWCSession::DestroyNonPluggableDisplay(DisplayMapInfo *map_info) { |
| 2868 | hwc2_display_t client_id = map_info->client_id; |
| 2869 | |
| 2870 | SCOPE_LOCK(locker_[client_id]); |
| 2871 | auto &hwc_display = hwc_display_[client_id]; |
| 2872 | if (!hwc_display) { |
| 2873 | return; |
Dileep Marchya | f3ce11f | 2018-04-30 23:35:46 +0530 | [diff] [blame] | 2874 | } |
Ramakant Singh | 07254e0 | 2018-10-31 20:45:01 +0530 | [diff] [blame] | 2875 | DLOGI("Destroy display %d-%d, client id = %d", map_info->sdm_id, map_info->disp_type, |
| 2876 | client_id); |
Pullakavi Srinivas | 1ae4acb | 2019-11-18 19:33:45 +0530 | [diff] [blame] | 2877 | { |
| 2878 | SCOPE_LOCK(hdr_locker_[client_id]); |
| 2879 | is_hdr_display_[UINT32(client_id)] = false; |
| 2880 | } |
| 2881 | |
Ramakant Singh | 07254e0 | 2018-10-31 20:45:01 +0530 | [diff] [blame] | 2882 | switch (map_info->disp_type) { |
| 2883 | case kBuiltIn: |
| 2884 | HWCDisplayBuiltIn::Destroy(hwc_display); |
| 2885 | break; |
| 2886 | default: |
Pullakavi Srinivas | 17495f1 | 2019-09-16 20:25:20 +0530 | [diff] [blame] | 2887 | virtual_display_factory_.Destroy(hwc_display); |
Ramakant Singh | 07254e0 | 2018-10-31 20:45:01 +0530 | [diff] [blame] | 2888 | break; |
| 2889 | } |
| 2890 | |
Srinivas Pullakavi | 3c4337f | 2019-07-03 11:24:31 +0530 | [diff] [blame] | 2891 | if (async_powermode_ && map_info->disp_type == kBuiltIn) { |
| 2892 | hwc2_display_t dummy_disp_id = map_hwc_display_.find(client_id)->second; |
| 2893 | auto &hwc_display_dummy = hwc_display_[dummy_disp_id]; |
| 2894 | display_ready_.reset(UINT32(dummy_disp_id)); |
| 2895 | if (hwc_display_dummy) { |
| 2896 | HWCDisplayDummy::Destroy(hwc_display_dummy); |
| 2897 | hwc_display_dummy = nullptr; |
| 2898 | } |
| 2899 | } |
Rajavenu Kyatham | b035224 | 2019-12-17 12:08:55 +0530 | [diff] [blame] | 2900 | pending_power_mode_[client_id] = false; |
Ramakant Singh | 07254e0 | 2018-10-31 20:45:01 +0530 | [diff] [blame] | 2901 | hwc_display = nullptr; |
Srinivas Pullakavi | 3c4337f | 2019-07-03 11:24:31 +0530 | [diff] [blame] | 2902 | display_ready_.reset(UINT32(client_id)); |
Ramakant Singh | 07254e0 | 2018-10-31 20:45:01 +0530 | [diff] [blame] | 2903 | map_info->Reset(); |
Dileep Marchya | f3ce11f | 2018-04-30 23:35:46 +0530 | [diff] [blame] | 2904 | } |
Saurabh Shah | 04f932b | 2017-10-12 18:47:45 -0700 | [diff] [blame] | 2905 | |
Sushil Chauhan | e3a9fd0 | 2017-10-12 18:00:05 -0700 | [diff] [blame] | 2906 | HWC2::Error HWCSession::ValidateDisplayInternal(hwc2_display_t display, uint32_t *out_num_types, |
| 2907 | uint32_t *out_num_requests) { |
| 2908 | HWCDisplay *hwc_display = hwc_display_[display]; |
Gurpreet Singh Dhami | a427688 | 2019-04-12 10:30:58 -0700 | [diff] [blame] | 2909 | |
| 2910 | DTRACE_SCOPED(); |
Sushil Chauhan | e3a9fd0 | 2017-10-12 18:00:05 -0700 | [diff] [blame] | 2911 | if (hwc_display->IsInternalValidateState()) { |
| 2912 | // Internal Validation has already been done on display, get the Output params. |
| 2913 | return hwc_display->GetValidateDisplayOutput(out_num_types, out_num_requests); |
| 2914 | } |
| 2915 | |
| 2916 | if (display == HWC_DISPLAY_PRIMARY) { |
| 2917 | // TODO(user): This can be moved to HWCDisplayPrimary |
Sushil Chauhan | e3a9fd0 | 2017-10-12 18:00:05 -0700 | [diff] [blame] | 2918 | if (need_invalidate_) { |
Varun Arora | dff7d8d | 2019-08-05 18:12:43 -0700 | [diff] [blame] | 2919 | callbacks_.Refresh(display); |
Sushil Chauhan | e3a9fd0 | 2017-10-12 18:00:05 -0700 | [diff] [blame] | 2920 | need_invalidate_ = false; |
| 2921 | } |
| 2922 | |
| 2923 | if (color_mgr_) { |
| 2924 | color_mgr_->SetColorModeDetailEnhancer(hwc_display_[display]); |
| 2925 | } |
| 2926 | } |
| 2927 | |
| 2928 | return hwc_display->Validate(out_num_types, out_num_requests); |
| 2929 | } |
| 2930 | |
Dileep Marchya | ad66843 | 2019-12-02 10:44:52 +0530 | [diff] [blame] | 2931 | HWC2::Error HWCSession::PresentDisplayInternal(hwc2_display_t display) { |
Sushil Chauhan | e3a9fd0 | 2017-10-12 18:00:05 -0700 | [diff] [blame] | 2932 | HWCDisplay *hwc_display = hwc_display_[display]; |
Gurpreet Singh Dhami | a427688 | 2019-04-12 10:30:58 -0700 | [diff] [blame] | 2933 | |
| 2934 | DTRACE_SCOPED(); |
Sushil Chauhan | e3a9fd0 | 2017-10-12 18:00:05 -0700 | [diff] [blame] | 2935 | // If display is in Skip-Validate state and Validate cannot be skipped, do Internal |
| 2936 | // Validation to optimize for the frames which don't require the Client composition. |
| 2937 | if (hwc_display->IsSkipValidateState() && !hwc_display->CanSkipValidate()) { |
| 2938 | uint32_t out_num_types = 0, out_num_requests = 0; |
Sushil Chauhan | 7bd2066 | 2018-08-20 17:51:32 -0700 | [diff] [blame] | 2939 | hwc_display->SetFastPathComposition(true); |
Sushil Chauhan | e3a9fd0 | 2017-10-12 18:00:05 -0700 | [diff] [blame] | 2940 | HWC2::Error error = ValidateDisplayInternal(display, &out_num_types, &out_num_requests); |
Sushil Chauhan | 181d950 | 2018-12-13 16:40:58 -0800 | [diff] [blame] | 2941 | if ((error != HWC2::Error::None) || hwc_display->HWCClientNeedsValidate()) { |
Sushil Chauhan | e3a9fd0 | 2017-10-12 18:00:05 -0700 | [diff] [blame] | 2942 | hwc_display->SetValidationState(HWCDisplay::kInternalValidate); |
Sushil Chauhan | 7bd2066 | 2018-08-20 17:51:32 -0700 | [diff] [blame] | 2943 | hwc_display->SetFastPathComposition(false); |
Sushil Chauhan | e3a9fd0 | 2017-10-12 18:00:05 -0700 | [diff] [blame] | 2944 | return HWC2::Error::NotValidated; |
| 2945 | } |
| 2946 | } |
Padmanabhan Komanduru | e74cf4f | 2019-04-25 17:38:43 -0700 | [diff] [blame] | 2947 | return HWC2::Error::None; |
Sushil Chauhan | e3a9fd0 | 2017-10-12 18:00:05 -0700 | [diff] [blame] | 2948 | } |
| 2949 | |
Varun Arora | 7c8ee54 | 2018-05-01 20:58:16 -0700 | [diff] [blame] | 2950 | void HWCSession::DisplayPowerReset() { |
Mathew Joseph Karimpanal | 8abb6e0 | 2018-11-20 09:52:49 +0530 | [diff] [blame] | 2951 | // Acquire lock on all displays. |
Padmanabhan Komanduru | e74cf4f | 2019-04-25 17:38:43 -0700 | [diff] [blame] | 2952 | for (hwc2_display_t display = HWC_DISPLAY_PRIMARY; |
| 2953 | display < HWCCallbacks::kNumDisplays; display++) { |
Mathew Joseph Karimpanal | 8abb6e0 | 2018-11-20 09:52:49 +0530 | [diff] [blame] | 2954 | locker_[display].Lock(); |
| 2955 | } |
Varun Arora | 7c8ee54 | 2018-05-01 20:58:16 -0700 | [diff] [blame] | 2956 | |
Mathew Joseph Karimpanal | 8abb6e0 | 2018-11-20 09:52:49 +0530 | [diff] [blame] | 2957 | HWC2::Error status = HWC2::Error::None; |
Padmanabhan Komanduru | e74cf4f | 2019-04-25 17:38:43 -0700 | [diff] [blame] | 2958 | HWC2::PowerMode last_power_mode[HWCCallbacks::kNumDisplays] = {}; |
Varun Arora | 7c8ee54 | 2018-05-01 20:58:16 -0700 | [diff] [blame] | 2959 | |
Padmanabhan Komanduru | e74cf4f | 2019-04-25 17:38:43 -0700 | [diff] [blame] | 2960 | for (hwc2_display_t display = HWC_DISPLAY_PRIMARY; |
| 2961 | display < HWCCallbacks::kNumDisplays; display++) { |
Mathew Joseph Karimpanal | 8abb6e0 | 2018-11-20 09:52:49 +0530 | [diff] [blame] | 2962 | if (hwc_display_[display] != NULL) { |
| 2963 | last_power_mode[display] = hwc_display_[display]->GetCurrentPowerMode(); |
| 2964 | DLOGI("Powering off display = %d", display); |
| 2965 | status = hwc_display_[display]->SetPowerMode(HWC2::PowerMode::Off, |
| 2966 | true /* teardown */); |
| 2967 | if (status != HWC2::Error::None) { |
| 2968 | DLOGE("Power off for display = %d failed with error = %d", display, status); |
Varun Arora | 7c8ee54 | 2018-05-01 20:58:16 -0700 | [diff] [blame] | 2969 | } |
| 2970 | } |
Mathew Joseph Karimpanal | 8abb6e0 | 2018-11-20 09:52:49 +0530 | [diff] [blame] | 2971 | } |
Padmanabhan Komanduru | e74cf4f | 2019-04-25 17:38:43 -0700 | [diff] [blame] | 2972 | for (hwc2_display_t display = HWC_DISPLAY_PRIMARY; |
| 2973 | display < HWCCallbacks::kNumDisplays; display++) { |
Mathew Joseph Karimpanal | 8abb6e0 | 2018-11-20 09:52:49 +0530 | [diff] [blame] | 2974 | if (hwc_display_[display] != NULL) { |
| 2975 | HWC2::PowerMode mode = last_power_mode[display]; |
| 2976 | DLOGI("Setting display %d to mode = %d", display, mode); |
| 2977 | status = hwc_display_[display]->SetPowerMode(mode, false /* teardown */); |
| 2978 | if (status != HWC2::Error::None) { |
| 2979 | DLOGE("%d mode for display = %d failed with error = %d", mode, display, status); |
| 2980 | } |
| 2981 | ColorMode color_mode = hwc_display_[display]->GetCurrentColorMode(); |
| 2982 | status = hwc_display_[display]->SetColorMode(color_mode); |
| 2983 | if (status != HWC2::Error::None) { |
| 2984 | DLOGE("SetColorMode failed for display = %d error = %d", display, status); |
Varun Arora | 7c8ee54 | 2018-05-01 20:58:16 -0700 | [diff] [blame] | 2985 | } |
| 2986 | } |
Mathew Joseph Karimpanal | 8abb6e0 | 2018-11-20 09:52:49 +0530 | [diff] [blame] | 2987 | } |
Varun Arora | 7c8ee54 | 2018-05-01 20:58:16 -0700 | [diff] [blame] | 2988 | |
Padmanabhan Komanduru | f5e6c5d | 2019-04-04 13:56:31 +0530 | [diff] [blame] | 2989 | hwc2_display_t vsync_source = callbacks_.GetVsyncSource(); |
Pullakavi Srinivas | f2a3185 | 2019-04-23 14:32:08 -0700 | [diff] [blame] | 2990 | status = hwc_display_[vsync_source]->SetVsyncEnabled(HWC2::Vsync::Enable); |
Mathew Joseph Karimpanal | 8abb6e0 | 2018-11-20 09:52:49 +0530 | [diff] [blame] | 2991 | if (status != HWC2::Error::None) { |
Pullakavi Srinivas | f2a3185 | 2019-04-23 14:32:08 -0700 | [diff] [blame] | 2992 | 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] | 2993 | } |
| 2994 | |
| 2995 | // Release lock on all displays. |
Padmanabhan Komanduru | e74cf4f | 2019-04-25 17:38:43 -0700 | [diff] [blame] | 2996 | for (hwc2_display_t display = HWC_DISPLAY_PRIMARY; |
| 2997 | display < HWCCallbacks::kNumDisplays; display++) { |
Mathew Joseph Karimpanal | 8abb6e0 | 2018-11-20 09:52:49 +0530 | [diff] [blame] | 2998 | locker_[display].Unlock(); |
Varun Arora | 7c8ee54 | 2018-05-01 20:58:16 -0700 | [diff] [blame] | 2999 | } |
Pullakavi Srinivas | f2a3185 | 2019-04-23 14:32:08 -0700 | [diff] [blame] | 3000 | |
Varun Arora | dff7d8d | 2019-08-05 18:12:43 -0700 | [diff] [blame] | 3001 | callbacks_.Refresh(vsync_source); |
Varun Arora | 7c8ee54 | 2018-05-01 20:58:16 -0700 | [diff] [blame] | 3002 | } |
Ramkumar Radhakrishnan | a38b760 | 2018-03-15 14:49:52 -0700 | [diff] [blame] | 3003 | |
Ramkumar Radhakrishnan | 44c6436 | 2018-12-12 13:03:59 -0800 | [diff] [blame] | 3004 | void HWCSession::HandleSecureSession() { |
Mathew Joseph Karimpanal | 71ac8a7 | 2018-09-25 22:27:22 +0530 | [diff] [blame] | 3005 | std::bitset<kSecureMax> secure_sessions = 0; |
| 3006 | { |
Mathew Joseph Karimpanal | b1c1586 | 2019-07-04 11:14:24 +0530 | [diff] [blame] | 3007 | // TODO(user): Revisit if supporting secure display on non-primary. |
Ramkumar Radhakrishnan | 44c6436 | 2018-12-12 13:03:59 -0800 | [diff] [blame] | 3008 | hwc2_display_t active_builtin_disp_id = GetActiveBuiltinDisplay(); |
Padmanabhan Komanduru | e74cf4f | 2019-04-25 17:38:43 -0700 | [diff] [blame] | 3009 | if (active_builtin_disp_id >= HWCCallbacks::kNumDisplays) { |
Ramkumar Radhakrishnan | 44c6436 | 2018-12-12 13:03:59 -0800 | [diff] [blame] | 3010 | return; |
Mathew Joseph Karimpanal | 71ac8a7 | 2018-09-25 22:27:22 +0530 | [diff] [blame] | 3011 | } |
Mathew Joseph Karimpanal | b1c1586 | 2019-07-04 11:14:24 +0530 | [diff] [blame] | 3012 | Locker::ScopeLock lock_pwr(power_state_[active_builtin_disp_id]); |
| 3013 | if (power_state_transition_[active_builtin_disp_id]) { |
| 3014 | // Route all interactions with client to dummy display. |
| 3015 | active_builtin_disp_id = map_hwc_display_.find(active_builtin_disp_id)->second; |
| 3016 | } |
| 3017 | Locker::ScopeLock lock_d(locker_[active_builtin_disp_id]); |
Ramkumar Radhakrishnan | 44c6436 | 2018-12-12 13:03:59 -0800 | [diff] [blame] | 3018 | hwc_display_[active_builtin_disp_id]->GetActiveSecureSession(&secure_sessions); |
Ramkumar Radhakrishnan | a38b760 | 2018-03-15 14:49:52 -0700 | [diff] [blame] | 3019 | } |
| 3020 | |
Mathew Joseph Karimpanal | b1c1586 | 2019-07-04 11:14:24 +0530 | [diff] [blame] | 3021 | if (secure_sessions.any()) { |
| 3022 | secure_session_active_ = true; |
| 3023 | } else if (!secure_session_active_) { |
| 3024 | // No secure session active. No secure session transition to handle. Skip remaining steps. |
| 3025 | return; |
| 3026 | } |
| 3027 | |
Ramkumar Radhakrishnan | 44c6436 | 2018-12-12 13:03:59 -0800 | [diff] [blame] | 3028 | // 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] | 3029 | // external/virtual display. |
Padmanabhan Komanduru | e74cf4f | 2019-04-25 17:38:43 -0700 | [diff] [blame] | 3030 | for (hwc2_display_t display = HWC_DISPLAY_PRIMARY; |
| 3031 | display < HWCCallbacks::kNumDisplays; display++) { |
Mathew Joseph Karimpanal | 8abb6e0 | 2018-11-20 09:52:49 +0530 | [diff] [blame] | 3032 | Locker::ScopeLock lock_d(locker_[display]); |
| 3033 | if (hwc_display_[display]) { |
Mathew Joseph Karimpanal | b1c1586 | 2019-07-04 11:14:24 +0530 | [diff] [blame] | 3034 | hwc_display_[display]->HandleSecureSession(secure_sessions, &pending_power_mode_[display]); |
Ramkumar Radhakrishnan | a38b760 | 2018-03-15 14:49:52 -0700 | [diff] [blame] | 3035 | } |
Ramkumar Radhakrishnan | a38b760 | 2018-03-15 14:49:52 -0700 | [diff] [blame] | 3036 | } |
| 3037 | } |
| 3038 | |
Dileep Marchya | ad66843 | 2019-12-02 10:44:52 +0530 | [diff] [blame] | 3039 | void HWCSession::HandlePendingPowerMode(hwc2_display_t disp_id, |
| 3040 | const shared_ptr<Fence> &retire_fence) { |
Mathew Joseph Karimpanal | b1c1586 | 2019-07-04 11:14:24 +0530 | [diff] [blame] | 3041 | if (!secure_session_active_) { |
| 3042 | // No secure session active. Skip remaining steps. |
| 3043 | return; |
| 3044 | } |
| 3045 | |
Ramkumar Radhakrishnan | 44c6436 | 2018-12-12 13:03:59 -0800 | [diff] [blame] | 3046 | hwc2_display_t active_builtin_disp_id = GetActiveBuiltinDisplay(); |
| 3047 | if (disp_id != active_builtin_disp_id) { |
Ramkumar Radhakrishnan | a38b760 | 2018-03-15 14:49:52 -0700 | [diff] [blame] | 3048 | return; |
| 3049 | } |
Mathew Joseph Karimpanal | 71ac8a7 | 2018-09-25 22:27:22 +0530 | [diff] [blame] | 3050 | |
Mathew Joseph Karimpanal | b1c1586 | 2019-07-04 11:14:24 +0530 | [diff] [blame] | 3051 | Locker::ScopeLock lock_d(locker_[active_builtin_disp_id]); |
| 3052 | bool pending_power_mode = false; |
| 3053 | for (hwc2_display_t display = HWC_DISPLAY_PRIMARY + 1; |
Padmanabhan Komanduru | e74cf4f | 2019-04-25 17:38:43 -0700 | [diff] [blame] | 3054 | display < HWCCallbacks::kNumDisplays; display++) { |
Ramkumar Radhakrishnan | 44c6436 | 2018-12-12 13:03:59 -0800 | [diff] [blame] | 3055 | if (display != active_builtin_disp_id) { |
| 3056 | Locker::ScopeLock lock_d(locker_[display]); |
Mathew Joseph Karimpanal | b1c1586 | 2019-07-04 11:14:24 +0530 | [diff] [blame] | 3057 | if (pending_power_mode_[display]) { |
| 3058 | pending_power_mode = true; |
Ramkumar Radhakrishnan | 44c6436 | 2018-12-12 13:03:59 -0800 | [diff] [blame] | 3059 | break; |
| 3060 | } |
Ramkumar Radhakrishnan | a38b760 | 2018-03-15 14:49:52 -0700 | [diff] [blame] | 3061 | } |
| 3062 | } |
Dileep Marchya | ad66843 | 2019-12-02 10:44:52 +0530 | [diff] [blame] | 3063 | |
| 3064 | if (!pending_power_mode) { |
Mathew Joseph Karimpanal | 71ac8a7 | 2018-09-25 22:27:22 +0530 | [diff] [blame] | 3065 | return; |
Ramkumar Radhakrishnan | a38b760 | 2018-03-15 14:49:52 -0700 | [diff] [blame] | 3066 | } |
| 3067 | |
Dileep Marchya | ad66843 | 2019-12-02 10:44:52 +0530 | [diff] [blame] | 3068 | // retire fence is set only after successful primary commit, So check for retire fence to know |
| 3069 | // non secure commit went through to notify driver to change the CRTC mode to non secure. |
| 3070 | // Otherwise any commit to non-primary display would fail. |
| 3071 | if (retire_fence == nullptr) { |
| 3072 | return; |
| 3073 | } |
| 3074 | |
| 3075 | Fence::Wait(retire_fence); |
| 3076 | |
Mathew Joseph Karimpanal | b1c1586 | 2019-07-04 11:14:24 +0530 | [diff] [blame] | 3077 | for (hwc2_display_t display = HWC_DISPLAY_PRIMARY + 1; |
Padmanabhan Komanduru | e74cf4f | 2019-04-25 17:38:43 -0700 | [diff] [blame] | 3078 | display < HWCCallbacks::kNumDisplays; display++) { |
Ramkumar Radhakrishnan | 44c6436 | 2018-12-12 13:03:59 -0800 | [diff] [blame] | 3079 | if (display != active_builtin_disp_id) { |
| 3080 | Locker::ScopeLock lock_d(locker_[display]); |
Mathew Joseph Karimpanal | b1c1586 | 2019-07-04 11:14:24 +0530 | [diff] [blame] | 3081 | if (pending_power_mode_[display] && hwc_display_[display]) { |
| 3082 | HWC2::Error error = |
| 3083 | hwc_display_[display]->SetPowerMode(hwc_display_[display]->GetPendingPowerMode(), false); |
| 3084 | if (HWC2::Error::None == error) { |
| 3085 | pending_power_mode_[display] = false; |
| 3086 | hwc_display_[display]->ClearPendingPowerMode(); |
| 3087 | pending_refresh_.set(UINT32(HWC_DISPLAY_PRIMARY)); |
| 3088 | } else { |
| 3089 | DLOGE("SetDisplayStatus error = %d (%s)", error, to_string(error).c_str()); |
Ramkumar Radhakrishnan | 44c6436 | 2018-12-12 13:03:59 -0800 | [diff] [blame] | 3090 | } |
Ramkumar Radhakrishnan | a38b760 | 2018-03-15 14:49:52 -0700 | [diff] [blame] | 3091 | } |
| 3092 | } |
| 3093 | } |
Mathew Joseph Karimpanal | b1c1586 | 2019-07-04 11:14:24 +0530 | [diff] [blame] | 3094 | secure_session_active_ = false; |
Ramkumar Radhakrishnan | a38b760 | 2018-03-15 14:49:52 -0700 | [diff] [blame] | 3095 | } |
| 3096 | |
Dileep Marchya | ad66843 | 2019-12-02 10:44:52 +0530 | [diff] [blame] | 3097 | void HWCSession::HandlePendingHotplug(hwc2_display_t disp_id, |
| 3098 | const shared_ptr<Fence> &retire_fence) { |
Ramkumar Radhakrishnan | 44c6436 | 2018-12-12 13:03:59 -0800 | [diff] [blame] | 3099 | hwc2_display_t active_builtin_disp_id = GetActiveBuiltinDisplay(); |
| 3100 | if (disp_id != active_builtin_disp_id || |
Mathew Joseph Karimpanal | b1c1586 | 2019-07-04 11:14:24 +0530 | [diff] [blame] | 3101 | (kHotPlugNone == pending_hotplug_event_ && !destroy_virtual_disp_pending_)) { |
Ramkumar Radhakrishnan | a38b760 | 2018-03-15 14:49:52 -0700 | [diff] [blame] | 3102 | return; |
| 3103 | } |
Rajavenu Kyatham | e45d1b7 | 2018-06-27 14:46:44 +0530 | [diff] [blame] | 3104 | |
Ramkumar Radhakrishnan | a38b760 | 2018-03-15 14:49:52 -0700 | [diff] [blame] | 3105 | std :: bitset < kSecureMax > secure_sessions = 0; |
Padmanabhan Komanduru | e74cf4f | 2019-04-25 17:38:43 -0700 | [diff] [blame] | 3106 | if (active_builtin_disp_id < HWCCallbacks::kNumDisplays) { |
Mathew Joseph Karimpanal | b1c1586 | 2019-07-04 11:14:24 +0530 | [diff] [blame] | 3107 | Locker::ScopeLock lock_d(locker_[active_builtin_disp_id]); |
Ramkumar Radhakrishnan | 44c6436 | 2018-12-12 13:03:59 -0800 | [diff] [blame] | 3108 | hwc_display_[active_builtin_disp_id]->GetActiveSecureSession(&secure_sessions); |
| 3109 | } |
| 3110 | |
Padmanabhan Komanduru | e74cf4f | 2019-04-25 17:38:43 -0700 | [diff] [blame] | 3111 | if (secure_sessions.any() || active_builtin_disp_id >= HWCCallbacks::kNumDisplays) { |
Ramkumar Radhakrishnan | 44c6436 | 2018-12-12 13:03:59 -0800 | [diff] [blame] | 3112 | return; |
| 3113 | } |
| 3114 | |
Mathew Joseph Karimpanal | b1c1586 | 2019-07-04 11:14:24 +0530 | [diff] [blame] | 3115 | if (destroy_virtual_disp_pending_ || kHotPlugEvent == pending_hotplug_event_) { |
Dileep Marchya | ad66843 | 2019-12-02 10:44:52 +0530 | [diff] [blame] | 3116 | Fence::Wait(retire_fence); |
| 3117 | |
Ramkumar Radhakrishnan | 44c6436 | 2018-12-12 13:03:59 -0800 | [diff] [blame] | 3118 | // Destroy the pending virtual display if secure session not present. |
| 3119 | if (destroy_virtual_disp_pending_) { |
| 3120 | for (auto &map_info : map_info_virtual_) { |
| 3121 | DestroyDisplay(&map_info); |
| 3122 | destroy_virtual_disp_pending_ = false; |
Padmanabhan Komanduru | f5b7f99 | 2019-07-08 13:33:44 +0530 | [diff] [blame] | 3123 | virtual_id_ = HWCCallbacks::kNumDisplays; |
Ramkumar Radhakrishnan | 44c6436 | 2018-12-12 13:03:59 -0800 | [diff] [blame] | 3124 | } |
Ramkumar Radhakrishnan | a38b760 | 2018-03-15 14:49:52 -0700 | [diff] [blame] | 3125 | } |
Ramkumar Radhakrishnan | 44c6436 | 2018-12-12 13:03:59 -0800 | [diff] [blame] | 3126 | // Handle connect/disconnect hotplugs if secure session is not present. |
| 3127 | 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] | 3128 | if (!hwc_display_[virtual_display_idx] && kHotPlugEvent == pending_hotplug_event_) { |
Mathew Joseph Karimpanal | abe3b3d | 2018-11-27 17:25:40 +0530 | [diff] [blame] | 3129 | // Handle deferred hotplug event. |
| 3130 | int32_t err = pluggable_handler_lock_.TryLock(); |
| 3131 | if (!err) { |
| 3132 | // Do hotplug handling in a different thread to avoid blocking PresentDisplay. |
| 3133 | std::thread(&HWCSession::HandlePluggableDisplays, this, true).detach(); |
| 3134 | pluggable_handler_lock_.Unlock(); |
| 3135 | } else { |
| 3136 | // EBUSY means another thread is already handling hotplug. Skip deferred hotplug handling. |
| 3137 | if (EBUSY != err) { |
| 3138 | DLOGW("Failed to acquire pluggable display handler lock. Error %d '%s'.", err, |
| 3139 | strerror(abs(err))); |
| 3140 | } |
Ramkumar Radhakrishnan | 44c6436 | 2018-12-12 13:03:59 -0800 | [diff] [blame] | 3141 | } |
Mathew Joseph Karimpanal | 71ac8a7 | 2018-09-25 22:27:22 +0530 | [diff] [blame] | 3142 | } |
Mathew Joseph Karimpanal | 71ac8a7 | 2018-09-25 22:27:22 +0530 | [diff] [blame] | 3143 | } |
Ramkumar Radhakrishnan | a38b760 | 2018-03-15 14:49:52 -0700 | [diff] [blame] | 3144 | } |
| 3145 | |
Rajavenu Kyatham | 42d11cb | 2019-04-16 13:03:29 +0530 | [diff] [blame] | 3146 | int32_t HWCSession::GetReadbackBufferAttributes(hwc2_display_t display, int32_t *format, |
| 3147 | int32_t *dataspace) { |
| 3148 | if (!format || !dataspace) { |
Sushil Chauhan | 0652158 | 2018-03-19 14:00:23 -0700 | [diff] [blame] | 3149 | return HWC2_ERROR_BAD_PARAMETER; |
| 3150 | } |
| 3151 | |
| 3152 | if (display != HWC_DISPLAY_PRIMARY) { |
| 3153 | return HWC2_ERROR_BAD_DISPLAY; |
| 3154 | } |
| 3155 | |
Rajavenu Kyatham | 42d11cb | 2019-04-16 13:03:29 +0530 | [diff] [blame] | 3156 | HWCDisplay *hwc_display = hwc_display_[display]; |
Venkat Thogaru | 8e9b124 | 2020-03-30 19:25:24 +0530 | [diff] [blame^] | 3157 | if (hwc_display == nullptr) { |
| 3158 | return HWC2_ERROR_BAD_DISPLAY; |
| 3159 | } else if (!hwc_display->HasReadBackBufferSupport()) { |
| 3160 | return HWC2_ERROR_UNSUPPORTED; |
Sushil Chauhan | fea3e90 | 2018-07-31 15:34:48 -0700 | [diff] [blame] | 3161 | } |
| 3162 | |
Venkat Thogaru | 8e9b124 | 2020-03-30 19:25:24 +0530 | [diff] [blame^] | 3163 | *format = HAL_PIXEL_FORMAT_RGB_888; |
| 3164 | *dataspace = GetDataspaceFromColorMode(hwc_display->GetCurrentColorMode()); |
| 3165 | |
| 3166 | return HWC2_ERROR_NONE; |
Sushil Chauhan | 0652158 | 2018-03-19 14:00:23 -0700 | [diff] [blame] | 3167 | } |
| 3168 | |
Rajavenu Kyatham | 42d11cb | 2019-04-16 13:03:29 +0530 | [diff] [blame] | 3169 | 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] | 3170 | const shared_ptr<Fence> &acquire_fence) { |
Sushil Chauhan | 0652158 | 2018-03-19 14:00:23 -0700 | [diff] [blame] | 3171 | if (!buffer) { |
| 3172 | return HWC2_ERROR_BAD_PARAMETER; |
| 3173 | } |
| 3174 | |
| 3175 | if (display != HWC_DISPLAY_PRIMARY) { |
| 3176 | return HWC2_ERROR_BAD_DISPLAY; |
| 3177 | } |
| 3178 | |
Sushil Chauhan | 0a1b15d | 2019-08-23 12:58:18 -0700 | [diff] [blame] | 3179 | int external_dpy_index = GetDisplayIndex(qdutils::DISPLAY_EXTERNAL); |
| 3180 | int virtual_dpy_index = GetDisplayIndex(qdutils::DISPLAY_VIRTUAL); |
| 3181 | if (((external_dpy_index != -1) && hwc_display_[external_dpy_index]) || |
| 3182 | ((virtual_dpy_index != -1) && hwc_display_[virtual_dpy_index])) { |
Sushil Chauhan | 062a7a4 | 2018-04-25 22:27:52 -0700 | [diff] [blame] | 3183 | return HWC2_ERROR_UNSUPPORTED; |
| 3184 | } |
| 3185 | |
Rajavenu Kyatham | 42d11cb | 2019-04-16 13:03:29 +0530 | [diff] [blame] | 3186 | return CallDisplayFunction(display, &HWCDisplay::SetReadbackBuffer, buffer, acquire_fence, |
Dileep Marchya | cb2a3a9 | 2019-06-21 17:30:50 +0530 | [diff] [blame] | 3187 | false, kCWBClientComposer); |
Sushil Chauhan | 0652158 | 2018-03-19 14:00:23 -0700 | [diff] [blame] | 3188 | } |
| 3189 | |
Rajavenu Kyatham | 7338b9e | 2019-12-30 19:52:16 +0530 | [diff] [blame] | 3190 | int32_t HWCSession::GetReadbackBufferFence(hwc2_display_t display, |
| 3191 | shared_ptr<Fence> *release_fence) { |
Sushil Chauhan | 0652158 | 2018-03-19 14:00:23 -0700 | [diff] [blame] | 3192 | if (!release_fence) { |
| 3193 | return HWC2_ERROR_BAD_PARAMETER; |
| 3194 | } |
| 3195 | |
| 3196 | if (display != HWC_DISPLAY_PRIMARY) { |
| 3197 | return HWC2_ERROR_BAD_DISPLAY; |
| 3198 | } |
| 3199 | |
Rajavenu Kyatham | 42d11cb | 2019-04-16 13:03:29 +0530 | [diff] [blame] | 3200 | return CallDisplayFunction(display, &HWCDisplay::GetReadbackBufferFence, release_fence); |
Sushil Chauhan | 0652158 | 2018-03-19 14:00:23 -0700 | [diff] [blame] | 3201 | } |
| 3202 | |
Rajavenu Kyatham | 42d11cb | 2019-04-16 13:03:29 +0530 | [diff] [blame] | 3203 | int32_t HWCSession::GetDisplayIdentificationData(hwc2_display_t display, uint8_t *outPort, |
| 3204 | uint32_t *outDataSize, uint8_t *outData) { |
Varun Arora | 6ba9eda | 2019-02-07 17:59:32 -0800 | [diff] [blame] | 3205 | if (!outPort || !outDataSize) { |
| 3206 | return HWC2_ERROR_BAD_PARAMETER; |
| 3207 | } |
| 3208 | |
Padmanabhan Komanduru | e74cf4f | 2019-04-25 17:38:43 -0700 | [diff] [blame] | 3209 | if (display >= HWCCallbacks::kNumDisplays) { |
Varun Arora | 6ba9eda | 2019-02-07 17:59:32 -0800 | [diff] [blame] | 3210 | return HWC2_ERROR_BAD_DISPLAY; |
| 3211 | } |
| 3212 | |
Rajavenu Kyatham | 42d11cb | 2019-04-16 13:03:29 +0530 | [diff] [blame] | 3213 | return CallDisplayFunction(display, &HWCDisplay::GetDisplayIdentificationData, outPort, |
Varun Arora | 6ba9eda | 2019-02-07 17:59:32 -0800 | [diff] [blame] | 3214 | outDataSize, outData); |
| 3215 | } |
| 3216 | |
Naseer Ahmed | 8584a0f | 2020-02-19 22:23:30 -0500 | [diff] [blame] | 3217 | int32_t HWCSession::GetDisplayCapabilities(hwc2_display_t display, |
| 3218 | hidl_vec<HwcDisplayCapability> *capabilities) { |
| 3219 | if (!capabilities) { |
Varun Arora | 9da54ef | 2019-05-03 16:17:22 -0700 | [diff] [blame] | 3220 | return HWC2_ERROR_BAD_PARAMETER; |
| 3221 | } |
| 3222 | |
| 3223 | if (display >= HWCCallbacks::kNumDisplays) { |
| 3224 | return HWC2_ERROR_BAD_DISPLAY; |
| 3225 | } |
| 3226 | |
Rajavenu Kyatham | 42d11cb | 2019-04-16 13:03:29 +0530 | [diff] [blame] | 3227 | if (!hwc_display_[display]) { |
Varun Arora | 9da54ef | 2019-05-03 16:17:22 -0700 | [diff] [blame] | 3228 | DLOGE("Expected valid hwc_display"); |
| 3229 | return HWC2_ERROR_BAD_PARAMETER; |
| 3230 | } |
Naseer Ahmed | 8584a0f | 2020-02-19 22:23:30 -0500 | [diff] [blame] | 3231 | |
Rajavenu Kyatham | 42d11cb | 2019-04-16 13:03:29 +0530 | [diff] [blame] | 3232 | bool isBuiltin = (hwc_display_[display]->GetDisplayClass() == DISPLAY_CLASS_BUILTIN); |
Pullakavi Srinivas | 5cb87bd | 2020-04-02 22:30:55 +0530 | [diff] [blame] | 3233 | int32_t has_doze_support = 0; |
| 3234 | GetDozeSupport(display, &has_doze_support); |
Naseer Ahmed | 8584a0f | 2020-02-19 22:23:30 -0500 | [diff] [blame] | 3235 | if (isBuiltin) { |
| 3236 | capabilities->resize(4); |
| 3237 | // TODO(user): Handle SKIP_CLIENT_COLOR_TRANSFORM based on DSPP availability |
Pullakavi Srinivas | 5cb87bd | 2020-04-02 22:30:55 +0530 | [diff] [blame] | 3238 | std::vector<HwcDisplayCapability> caps; |
| 3239 | if (has_doze_support) { |
| 3240 | caps = { |
| 3241 | HwcDisplayCapability::SKIP_CLIENT_COLOR_TRANSFORM, HwcDisplayCapability::DOZE, |
| 3242 | HwcDisplayCapability::BRIGHTNESS, HwcDisplayCapability::PROTECTED_CONTENTS}; |
| 3243 | } |
| 3244 | else { |
| 3245 | caps = { |
| 3246 | HwcDisplayCapability::SKIP_CLIENT_COLOR_TRANSFORM, |
| 3247 | HwcDisplayCapability::BRIGHTNESS, HwcDisplayCapability::PROTECTED_CONTENTS}; |
| 3248 | } |
Naseer Ahmed | 8584a0f | 2020-02-19 22:23:30 -0500 | [diff] [blame] | 3249 | capabilities->setToExternal(caps.data(), caps.size()); |
Varun Arora | 9da54ef | 2019-05-03 16:17:22 -0700 | [diff] [blame] | 3250 | } |
Naseer Ahmed | 8584a0f | 2020-02-19 22:23:30 -0500 | [diff] [blame] | 3251 | return HWC2_ERROR_NONE; |
| 3252 | } |
| 3253 | |
| 3254 | int32_t HWCSession::GetDisplayConnectionType(hwc2_display_t display, |
| 3255 | HwcDisplayConnectionType *type) { |
| 3256 | if (display >= HWCCallbacks::kNumDisplays) { |
| 3257 | return HWC2_ERROR_BAD_DISPLAY; |
| 3258 | } |
| 3259 | |
| 3260 | if (!type) { |
| 3261 | return HWC2_ERROR_BAD_PARAMETER; |
| 3262 | } |
| 3263 | |
| 3264 | if (!hwc_display_[display]) { |
| 3265 | DLOGE("Expected valid hwc_display"); |
| 3266 | return HWC2_ERROR_BAD_PARAMETER; |
| 3267 | } |
| 3268 | *type = HwcDisplayConnectionType::EXTERNAL; |
| 3269 | if (hwc_display_[display]->GetDisplayClass() == DISPLAY_CLASS_BUILTIN) { |
| 3270 | *type = HwcDisplayConnectionType::INTERNAL; |
| 3271 | } |
| 3272 | |
| 3273 | return HWC2_ERROR_NONE; |
Varun Arora | 9da54ef | 2019-05-03 16:17:22 -0700 | [diff] [blame] | 3274 | } |
| 3275 | |
Rajavenu Kyatham | 42d11cb | 2019-04-16 13:03:29 +0530 | [diff] [blame] | 3276 | int32_t HWCSession::GetDisplayBrightnessSupport(hwc2_display_t display, bool *outSupport) { |
| 3277 | if (!outSupport) { |
Varun Arora | 9da54ef | 2019-05-03 16:17:22 -0700 | [diff] [blame] | 3278 | return HWC2_ERROR_BAD_PARAMETER; |
| 3279 | } |
| 3280 | |
| 3281 | if (display >= HWCCallbacks::kNumDisplays) { |
| 3282 | return HWC2_ERROR_BAD_DISPLAY; |
| 3283 | } |
| 3284 | |
Rajavenu Kyatham | 42d11cb | 2019-04-16 13:03:29 +0530 | [diff] [blame] | 3285 | if (!hwc_display_[display]) { |
Varun Arora | 9da54ef | 2019-05-03 16:17:22 -0700 | [diff] [blame] | 3286 | DLOGE("Expected valid hwc_display"); |
| 3287 | return HWC2_ERROR_BAD_PARAMETER; |
| 3288 | } |
Rajavenu Kyatham | 42d11cb | 2019-04-16 13:03:29 +0530 | [diff] [blame] | 3289 | *outSupport = (hwc_display_[display]->GetDisplayClass() == DISPLAY_CLASS_BUILTIN); |
Varun Arora | 9da54ef | 2019-05-03 16:17:22 -0700 | [diff] [blame] | 3290 | return HWC2_ERROR_NONE; |
| 3291 | } |
| 3292 | |
Rajavenu Kyatham | 42d11cb | 2019-04-16 13:03:29 +0530 | [diff] [blame] | 3293 | int32_t HWCSession::SetDisplayBrightness(hwc2_display_t display, float brightness) { |
Sushil Chauhan | ab3c5c5 | 2019-07-12 14:54:29 -0700 | [diff] [blame] | 3294 | if (display >= HWCCallbacks::kNumDisplays) { |
| 3295 | return HWC2_ERROR_BAD_DISPLAY; |
| 3296 | } |
| 3297 | |
| 3298 | if (!hwc_display_[display]) { |
| 3299 | return HWC2_ERROR_BAD_PARAMETER; |
| 3300 | } |
| 3301 | |
| 3302 | return INT32(hwc_display_[display]->SetPanelBrightness(brightness)); |
Varun Arora | 75c05f0 | 2019-05-14 14:53:37 -0700 | [diff] [blame] | 3303 | } |
| 3304 | |
Sushil Chauhan | 380a59d | 2018-03-19 15:47:50 -0700 | [diff] [blame] | 3305 | android::status_t HWCSession::SetQSyncMode(const android::Parcel *input_parcel) { |
| 3306 | auto mode = input_parcel->readInt32(); |
Sushil Chauhan | 380a59d | 2018-03-19 15:47:50 -0700 | [diff] [blame] | 3307 | |
| 3308 | QSyncMode qsync_mode = kQSyncModeNone; |
| 3309 | switch (mode) { |
| 3310 | case qService::IQService::QSYNC_MODE_NONE: |
| 3311 | qsync_mode = kQSyncModeNone; |
| 3312 | break; |
| 3313 | case qService::IQService::QSYNC_MODE_CONTINUOUS: |
| 3314 | qsync_mode = kQSyncModeContinuous; |
| 3315 | break; |
| 3316 | case qService::IQService::QSYNC_MODE_ONESHOT: |
| 3317 | qsync_mode = kQsyncModeOneShot; |
| 3318 | break; |
| 3319 | default: |
| 3320 | DLOGE("Qsync mode not supported %d", mode); |
| 3321 | return -EINVAL; |
| 3322 | } |
Rajavenu Kyatham | 42d11cb | 2019-04-16 13:03:29 +0530 | [diff] [blame] | 3323 | return CallDisplayFunction(HWC_DISPLAY_PRIMARY, &HWCDisplay::SetQSyncMode, qsync_mode); |
Sushil Chauhan | 380a59d | 2018-03-19 15:47:50 -0700 | [diff] [blame] | 3324 | } |
| 3325 | |
Mahesh Aia | f3a1f99 | 2019-01-16 13:07:42 -0800 | [diff] [blame] | 3326 | void HWCSession::UpdateThrottlingRate() { |
| 3327 | uint32_t new_min = 0; |
| 3328 | |
Padmanabhan Komanduru | e74cf4f | 2019-04-25 17:38:43 -0700 | [diff] [blame] | 3329 | for (int i=0; i < HWCCallbacks::kNumDisplays; i++) { |
Mahesh Aia | f3a1f99 | 2019-01-16 13:07:42 -0800 | [diff] [blame] | 3330 | auto &display = hwc_display_[i]; |
| 3331 | if (!display) |
| 3332 | continue; |
| 3333 | if (display->GetCurrentPowerMode() != HWC2::PowerMode::Off) |
| 3334 | new_min = (new_min == 0) ? display->GetMaxRefreshRate() : |
| 3335 | std::min(new_min, display->GetMaxRefreshRate()); |
| 3336 | } |
| 3337 | |
| 3338 | SetNewThrottlingRate(new_min); |
| 3339 | } |
| 3340 | |
| 3341 | void HWCSession::SetNewThrottlingRate(const uint32_t new_rate) { |
| 3342 | if (new_rate !=0 && throttling_refresh_rate_ != new_rate) { |
| 3343 | HWCDisplay::SetThrottlingRefreshRate(new_rate); |
| 3344 | throttling_refresh_rate_ = new_rate; |
| 3345 | } |
| 3346 | } |
| 3347 | |
Ramkumar Radhakrishnan | f985d48 | 2018-07-23 18:10:41 -0700 | [diff] [blame] | 3348 | android::status_t HWCSession::SetIdlePC(const android::Parcel *input_parcel) { |
| 3349 | auto enable = input_parcel->readInt32(); |
| 3350 | auto synchronous = input_parcel->readInt32(); |
| 3351 | |
Padmanabhan Komanduru | 9e97162 | 2020-02-10 13:09:34 +0530 | [diff] [blame] | 3352 | return static_cast<android::status_t>(ControlIdlePowerCollapse(enable, synchronous)); |
Ramkumar Radhakrishnan | f985d48 | 2018-07-23 18:10:41 -0700 | [diff] [blame] | 3353 | } |
| 3354 | |
Ramkumar Radhakrishnan | 44c6436 | 2018-12-12 13:03:59 -0800 | [diff] [blame] | 3355 | hwc2_display_t HWCSession::GetActiveBuiltinDisplay() { |
Mathew Joseph Karimpanal | b1c1586 | 2019-07-04 11:14:24 +0530 | [diff] [blame] | 3356 | hwc2_display_t active_display = HWCCallbacks::kNumDisplays; |
Mathew Joseph Karimpanal | 1d5a23f | 2019-04-25 15:46:11 -0700 | [diff] [blame] | 3357 | // Get first active display among primary and built-in displays. |
| 3358 | std::vector<DisplayMapInfo> map_info = {map_info_primary_}; |
| 3359 | std::copy(map_info_builtin_.begin(), map_info_builtin_.end(), std::back_inserter(map_info)); |
| 3360 | |
| 3361 | for (auto &info : map_info) { |
Mathew Joseph Karimpanal | b1c1586 | 2019-07-04 11:14:24 +0530 | [diff] [blame] | 3362 | hwc2_display_t target_display = info.client_id; |
| 3363 | SCOPE_LOCK(power_state_[target_display]); |
| 3364 | if (power_state_transition_[target_display]) { |
| 3365 | // Route all interactions with client to dummy display. |
| 3366 | target_display = map_hwc_display_.find(target_display)->second; |
| 3367 | } |
| 3368 | Locker::ScopeLock lock_d(locker_[target_display]); |
| 3369 | auto &hwc_display = hwc_display_[target_display]; |
Mathew Joseph Karimpanal | 1d5a23f | 2019-04-25 15:46:11 -0700 | [diff] [blame] | 3370 | if (hwc_display && hwc_display->GetCurrentPowerMode() != HWC2::PowerMode::Off) { |
Mathew Joseph Karimpanal | b1c1586 | 2019-07-04 11:14:24 +0530 | [diff] [blame] | 3371 | active_display = info.client_id; |
Mathew Joseph Karimpanal | 1d5a23f | 2019-04-25 15:46:11 -0700 | [diff] [blame] | 3372 | break; |
| 3373 | } |
Ramkumar Radhakrishnan | 44c6436 | 2018-12-12 13:03:59 -0800 | [diff] [blame] | 3374 | } |
Mathew Joseph Karimpanal | 1d5a23f | 2019-04-25 15:46:11 -0700 | [diff] [blame] | 3375 | |
Mathew Joseph Karimpanal | b1c1586 | 2019-07-04 11:14:24 +0530 | [diff] [blame] | 3376 | return active_display; |
Ramkumar Radhakrishnan | 44c6436 | 2018-12-12 13:03:59 -0800 | [diff] [blame] | 3377 | } |
| 3378 | |
Xu Yang | 45d0abf | 2019-07-05 11:34:06 +0800 | [diff] [blame] | 3379 | int32_t HWCSession::SetDisplayBrightnessScale(const android::Parcel *input_parcel) { |
| 3380 | auto display = input_parcel->readInt32(); |
| 3381 | auto level = input_parcel->readInt32(); |
| 3382 | if (level < 0 || level > kBrightnessScaleMax) { |
| 3383 | DLOGE("Invalid backlight scale level %d", level); |
| 3384 | return -EINVAL; |
| 3385 | } |
| 3386 | auto bl_scale = level * kSvBlScaleMax / kBrightnessScaleMax; |
| 3387 | auto error = CallDisplayFunction(display, &HWCDisplay::SetBLScale, (uint32_t)bl_scale); |
| 3388 | if (INT32(error) == HWC2_ERROR_NONE) { |
| 3389 | callbacks_.Refresh(display); |
| 3390 | } |
| 3391 | |
| 3392 | return INT32(error); |
| 3393 | } |
| 3394 | |
Pullakavi Srinivas | 2d55f3a | 2019-07-16 14:49:06 +0530 | [diff] [blame] | 3395 | void HWCSession::NotifyClientStatus(bool connected) { |
| 3396 | for (uint32_t i = 0; i < HWCCallbacks::kNumDisplays; i++) { |
| 3397 | if (!hwc_display_[i]) { |
| 3398 | continue; |
| 3399 | } |
| 3400 | SCOPE_LOCK(locker_[i]); |
| 3401 | hwc_display_[i]->NotifyClientStatus(connected); |
| 3402 | } |
| 3403 | } |
| 3404 | |
Padmanabhan Komanduru | f5b7f99 | 2019-07-08 13:33:44 +0530 | [diff] [blame] | 3405 | void HWCSession::WaitForResources(bool wait_for_resources, hwc2_display_t active_builtin_id, |
| 3406 | hwc2_display_t display_id) { |
| 3407 | { |
| 3408 | SEQUENCE_WAIT_SCOPE_LOCK(locker_[active_builtin_id]); |
| 3409 | hwc_display_[active_builtin_id]->ResetValidation(); |
| 3410 | } |
| 3411 | |
| 3412 | if (wait_for_resources) { |
| 3413 | bool res_wait = true; |
| 3414 | do { |
| 3415 | if (client_connected_) { |
| 3416 | Refresh(active_builtin_id); |
| 3417 | } |
| 3418 | { |
| 3419 | std::unique_lock<std::mutex> caller_lock(hotplug_mutex_); |
| 3420 | hotplug_cv_.wait(caller_lock); |
| 3421 | } |
| 3422 | res_wait = hwc_display_[display_id]->CheckResourceState(); |
| 3423 | } while (res_wait); |
| 3424 | } |
| 3425 | } |
Padmanabhan Komanduru | 9e97162 | 2020-02-10 13:09:34 +0530 | [diff] [blame] | 3426 | |
Sushil Chauhan | dbd8db4 | 2020-02-28 13:07:48 -0800 | [diff] [blame] | 3427 | int32_t HWCSession::GetDisplayVsyncPeriod(hwc2_display_t disp, VsyncPeriodNanos *vsync_period) { |
| 3428 | if (vsync_period == nullptr) { |
| 3429 | return HWC2_ERROR_BAD_PARAMETER; |
| 3430 | } |
| 3431 | |
| 3432 | return CallDisplayFunction(disp, &HWCDisplay::GetDisplayVsyncPeriod, vsync_period); |
| 3433 | } |
| 3434 | |
| 3435 | int32_t HWCSession::SetActiveConfigWithConstraints( |
| 3436 | hwc2_display_t display, hwc2_config_t config, |
| 3437 | const VsyncPeriodChangeConstraints *vsync_period_change_constraints, |
| 3438 | VsyncPeriodChangeTimeline *out_timeline) { |
| 3439 | if ((vsync_period_change_constraints == nullptr) || (out_timeline == nullptr)) { |
| 3440 | return HWC2_ERROR_BAD_PARAMETER; |
| 3441 | } |
| 3442 | |
| 3443 | return CallDisplayFunction(display, &HWCDisplay::SetActiveConfigWithConstraints, config, |
| 3444 | vsync_period_change_constraints, out_timeline); |
| 3445 | } |
| 3446 | |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 3447 | } // namespace sdm |