blob: ac312a14da23a5db6ddcdf3c65a2bb1f268bd576 [file] [log] [blame]
Naseer Ahmedb92e73f2016-03-12 02:03:48 -05001/*
Rajavenu Kyatham7338b9e2019-12-30 19:52:16 +05302 * Copyright (c) 2014-2020, The Linux Foundation. All rights reserved.
Naseer Ahmedb92e73f2016-03-12 02:03:48 -05003 * 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 Ahmedb92e73f2016-03-12 02:03:48 -050020#include <QService.h>
Naseer Ahmede7a77982018-06-04 10:56:04 -040021#include <binder/Parcel.h>
22#include <core/buffer_allocator.h>
23#include <cutils/properties.h>
Naseer Ahmedb92e73f2016-03-12 02:03:48 -050024#include <display_config.h>
Naseer Ahmede7a77982018-06-04 10:56:04 -040025#include <hardware_legacy/uevent.h>
26#include <private/color_params.h>
Ramakant Singhfae59892017-09-13 10:40:22 +053027#include <qd_utils.h>
Naseer Ahmede7a77982018-06-04 10:56:04 -040028#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 Marchyaf3ce11f2018-04-30 23:35:46 +053034#include <QService.h>
Ramakant Singhfae59892017-09-13 10:40:22 +053035#include <utils/utils.h>
Naseer Ahmed66d5b492017-02-23 20:30:17 -050036#include <algorithm>
Mahesh Aiaf3a1f992019-01-16 13:07:42 -080037#include <utility>
Dileep Marchya7290bd22016-06-09 11:37:20 +053038#include <bitset>
Mathew Joseph Karimpanal8abb6e02018-11-20 09:52:49 +053039#include <iterator>
Dileep Marchya550967a2017-05-24 17:03:30 +053040#include <memory>
Naseer Ahmede7a77982018-06-04 10:56:04 -040041#include <string>
42#include <thread>
43#include <vector>
Naseer Ahmedb92e73f2016-03-12 02:03:48 -050044
45#include "hwc_buffer_allocator.h"
Naseer Ahmedb92e73f2016-03-12 02:03:48 -050046#include "hwc_session.h"
47#include "hwc_debugger.h"
Naseer Ahmedb92e73f2016-03-12 02:03:48 -050048
49#define __CLASS__ "HWCSession"
50
51#define HWC_UEVENT_SWITCH_HDMI "change@/devices/virtual/switch/hdmi"
Prabhanjan Kandula34ffec02017-04-25 11:56:39 -070052#define HWC_UEVENT_DRM_EXT_HOTPLUG "mdss_mdp/drm/card"
Naseer Ahmedb92e73f2016-03-12 02:03:48 -050053
Naseer Ahmed8584a0f2020-02-19 22:23:30 -050054using HwcAttribute = composer_V2_4::IComposerClient::Attribute;
55
Naseer Ahmedb92e73f2016-03-12 02:03:48 -050056namespace sdm {
Dileep Marchya550967a2017-05-24 17:03:30 +053057
58static HWCUEvent g_hwc_uevent_;
Padmanabhan Komandurue74cf4f2019-04-25 17:38:43 -070059Locker HWCSession::locker_[HWCCallbacks::kNumDisplays];
Mathew Joseph Karimpanalb1c15862019-07-04 11:14:24 +053060bool HWCSession::pending_power_mode_[HWCCallbacks::kNumDisplays];
Srinivas Pullakavi3c4337f2019-07-03 11:24:31 +053061Locker HWCSession::power_state_[HWCCallbacks::kNumDisplays];
Pullakavi Srinivas1ae4acb2019-11-18 19:33:45 +053062Locker HWCSession::hdr_locker_[HWCCallbacks::kNumDisplays];
Srinivas Pullakavi3c4337f2019-07-03 11:24:31 +053063Locker HWCSession::display_config_locker_;
Gopikrishnaiah Anandana340b702018-01-16 15:37:15 -080064static const int kSolidFillDelay = 100 * 1000;
Varun Aroraad2719a2018-10-25 10:13:53 -070065int HWCSession::null_display_mode_ = 0;
Xu Yang45d0abf2019-07-05 11:34:06 +080066static const uint32_t kBrightnessScaleMax = 100;
67static const uint32_t kSvBlScaleMax = 65535;
Naseer Ahmedb92e73f2016-03-12 02:03:48 -050068
Sushil Chauhanfea3e902018-07-31 15:34:48 -070069// Map the known color modes to dataspace.
Arun Kumar K.R5b821552018-12-07 08:00:15 +053070int32_t GetDataspaceFromColorMode(ColorMode mode) {
Sushil Chauhanfea3e902018-07-31 15:34:48 -070071 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 Nadaf0e566872019-05-13 16:14:54 +053083 case ColorMode::DISPLAY_BT2020:
84 return HAL_DATASPACE_DISPLAY_BT2020;
Sushil Chauhanfea3e902018-07-31 15:34:48 -070085 default:
86 return HAL_DATASPACE_UNKNOWN;
87 }
88}
89
Ramkumar Radhakrishnan048dcc42017-06-09 16:20:56 -070090void HWCUEvent::UEventThread(HWCUEvent *hwc_uevent) {
Dileep Marchya550967a2017-05-24 17:03:30 +053091 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 Radhakrishnan048dcc42017-06-09 16:20:56 -070096 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 Marchya550967a2017-05-24 17:03:30 +0530109 }
110
111 while (1) {
112 char uevent_data[PAGE_SIZE] = {};
113
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +0530114 // keep last 2 zeros to ensure double 0 termination
Dileep Marchya550967a2017-05-24 17:03:30 +0530115 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 Radhakrishnan048dcc42017-06-09 16:20:56 -0700119 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 Marchya550967a2017-05-24 17:03:30 +0530122 } else {
123 DLOGW("UEvent dropped. No uevent listener.");
124 }
125 }
126 }
Dileep Marchya550967a2017-05-24 17:03:30 +0530127}
128
129HWCUEvent::HWCUEvent() {
Ramkumar Radhakrishnan048dcc42017-06-09 16:20:56 -0700130 std::unique_lock<std::mutex> caller_lock(mutex_);
Dileep Marchya550967a2017-05-24 17:03:30 +0530131 std::thread thread(HWCUEvent::UEventThread, this);
132 thread.detach();
Ramkumar Radhakrishnan048dcc42017-06-09 16:20:56 -0700133 caller_cv_.wait(caller_lock);
Dileep Marchya550967a2017-05-24 17:03:30 +0530134}
135
Ramkumar Radhakrishnan048dcc42017-06-09 16:20:56 -0700136void HWCUEvent::Register(HWCUEventListener *uevent_listener) {
137 DLOGI("Set uevent listener = %p", uevent_listener);
Dileep Marchya550967a2017-05-24 17:03:30 +0530138
139 std::lock_guard<std::mutex> obj(mutex_);
Ramkumar Radhakrishnan048dcc42017-06-09 16:20:56 -0700140 uevent_listener_ = uevent_listener;
Dileep Marchya550967a2017-05-24 17:03:30 +0530141}
142
Dileep Marchyacb2a3a92019-06-21 17:30:50 +0530143HWCSession::HWCSession() : cwb_(this) {}
Rajavenu Kyatham42d11cb2019-04-16 13:03:29 +0530144
145HWCSession *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 Ahmedb92e73f2016-03-12 02:03:48 -0500150}
151
152int HWCSession::Init() {
Saurabh Shahc5c687a2017-08-24 16:30:14 -0700153 SCOPE_LOCK(locker_[HWC_DISPLAY_PRIMARY]);
154
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500155 int status = -EINVAL;
156 const char *qservice_name = "display.qservice";
157
Ramkumar Radhakrishnan048dcc42017-06-09 16:20:56 -0700158 if (!g_hwc_uevent_.InitDone()) {
159 return status;
160 }
161
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +0530162
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500163 // 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 Marchya4cb86b42018-05-01 19:34:51 +0530172 DLOGE("Failed to acquire %s", qservice_name);
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500173 return -EINVAL;
174 }
175
Uday Kiran Pichika5e656b22018-05-15 18:48:24 +0530176 HWCDebugHandler::Get()->GetProperty(ENABLE_NULL_DISPLAY_PROP, &null_display_mode_);
Mathew Joseph Karimpanalabe3b3d2018-11-27 17:25:40 +0530177 HWCDebugHandler::Get()->GetProperty(DISABLE_HOTPLUG_BWCHECK, &disable_hotplug_bwcheck_);
Pullakavi Srinivas2fbff8d2019-04-22 18:32:52 -0700178 HWCDebugHandler::Get()->GetProperty(DISABLE_MASK_LAYER_HINT, &disable_mask_layer_hint_);
Ramkumar Radhakrishnanddbf83c2017-06-28 20:01:59 -0700179
Pullakavi Srinivasf2a31852019-04-23 14:32:08 -0700180 if (!null_display_mode_) {
Varun Arora429bf402018-10-01 13:32:33 -0700181 g_hwc_uevent_.Register(this);
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500182 }
183
Mathew Joseph Karimpanalb1c15862019-07-04 11:14:24 +0530184 int value = 1; // Default value when property is not present.
Srinivas Pullakavi3c4337f2019-07-03 11:24:31 +0530185 Debug::Get()->GetProperty(ENABLE_ASYNC_POWERMODE, &value);
186 async_powermode_ = (value == 1);
187 DLOGI("builtin_powermode_override: %d", async_powermode_);
188
Padmanabhan Komanduruf5b7f992019-07-08 13:33:44 +0530189 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 Srinivasf2a31852019-04-23 14:32:08 -0700194 InitSupportedDisplaySlots();
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +0530195 // 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 Ahmedb92e73f2016-03-12 02:03:48 -0500198 if (status) {
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +0530199 Deinit();
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500200 return status;
201 }
202
Prabhanjan Kandula63a613f2017-09-14 19:29:46 -0700203 is_composer_up_ = true;
Ramakant Singh2b8f5ec2019-09-20 09:43:29 +0530204 StartServices();
Dileep Marchyad16da3e2017-05-20 01:56:21 +0530205
Pullakavi Srinivasdb2b84a2019-11-21 14:47:35 +0530206 PostInit();
207
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500208 return 0;
209}
210
Pullakavi Srinivasdb2b84a2019-11-21 14:47:35 +0530211void 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 Ahmedb92e73f2016-03-12 02:03:48 -0500222int HWCSession::Deinit() {
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +0530223 // Destroy all connected displays
224 DestroyDisplay(&map_info_primary_);
Saurabh Shahc5c687a2017-08-24 16:30:14 -0700225
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +0530226 for (auto &map_info : map_info_builtin_) {
227 DestroyDisplay(&map_info);
Dileep Marchyad16da3e2017-05-20 01:56:21 +0530228 }
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +0530229
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 Marchyad16da3e2017-05-20 01:56:21 +0530237
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500238 if (color_mgr_) {
239 color_mgr_->DestroyColorManager();
240 }
Dileep Marchyad16da3e2017-05-20 01:56:21 +0530241
Varun Arora465c1f72018-02-08 16:18:50 -0800242 if (!null_display_mode_) {
243 g_hwc_uevent_.Register(nullptr);
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500244
Varun Arora465c1f72018-02-08 16:18:50 -0800245 DisplayError error = CoreInterface::DestroyCore();
246 if (error != kErrorNone) {
Dileep Marchya4cb86b42018-05-01 19:34:51 +0530247 DLOGE("Display core de-initialization failed. Error = %d", error);
Varun Arora465c1f72018-02-08 16:18:50 -0800248 }
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500249 }
250
251 return 0;
252}
253
Pullakavi Srinivasf2a31852019-04-23 14:32:08 -0700254void HWCSession::InitSupportedDisplaySlots() {
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +0530255 // Default slots:
Pullakavi Srinivasf2a31852019-04-23 14:32:08 -0700256 // 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 Marchyaf3ce11f2018-04-30 23:35:46 +0530262
263 map_info_primary_.client_id = qdutils::DISPLAY_PRIMARY;
264
Pullakavi Srinivasf2a31852019-04-23 14:32:08 -0700265 if (null_display_mode_) {
Varun Arorad7d8c912019-08-16 11:45:19 -0700266 InitSupportedNullDisplaySlots();
Pullakavi Srinivasf2a31852019-04-23 14:32:08 -0700267 return;
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +0530268 }
269
Dileep Marchya1b37f8c2020-01-20 19:14:12 +0530270 DisplayError error = CoreInterface::CreateCore(&buffer_allocator_, nullptr,
Pullakavi Srinivasf2a31852019-04-23 14:32:08 -0700271 &socket_handler_, &core_intf_);
272 if (error != kErrorNone) {
273 DLOGE("Failed to create CoreInterface");
274 return;
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +0530275 }
276
Pullakavi Srinivasf2a31852019-04-23 14:32:08 -0700277 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 Srinivas17495f12019-09-16 20:25:20 +0530310 if (max_virtual == 0) {
311 // Check if WB using GPU is supported.
312 max_virtual += virtual_display_factory_.IsGPUColorConvertSupported() ? 1 : 0;
313 }
314
Pullakavi Srinivasf2a31852019-04-23 14:32:08 -0700315 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 Marchyaf3ce11f2018-04-30 23:35:46 +0530340 }
Archit Srivastavafe060f72019-05-27 15:51:58 +0530341
342 // resize HDR supported map to total number of displays.
343 is_hdr_display_.resize(UINT32(base_id));
Srinivas Pullakavi3c4337f2019-07-03 11:24:31 +0530344
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 Marchyaf3ce11f2018-04-30 23:35:46 +0530357}
358
Varun Arorad7d8c912019-08-16 11:45:19 -0700359void 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 Marchyaf3ce11f2018-04-30 23:35:46 +0530379int 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 Karimpanal71ac8a72018-09-25 22:27:22 +0530388 case qdutils::DISPLAY_EXTERNAL_2:
389 map_info = (map_info_pluggable_.size() > 1) ? &map_info_pluggable_[1] : nullptr;
390 break;
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +0530391 case qdutils::DISPLAY_VIRTUAL:
392 map_info = map_info_virtual_.size() ? &map_info_virtual_[0] : nullptr;
393 break;
Dileep Marchya35e27532018-06-29 10:50:16 +0530394 case qdutils::DISPLAY_BUILTIN_2:
395 map_info = map_info_builtin_.size() ? &map_info_builtin_[0] : nullptr;
396 break;
Mathew Joseph Karimpanal71ac8a72018-09-25 22:27:22 +0530397 default:
398 DLOGW("Unknown display %d.", dpy);
399 break;
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +0530400 }
401
402 if (!map_info) {
Mathew Joseph Karimpanal71ac8a72018-09-25 22:27:22 +0530403 DLOGE("Display index not found for display %d.", dpy);
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +0530404 return -1;
405 }
406
407 return INT(map_info->client_id);
408}
409
Rajavenu Kyatham42d11cb2019-04-16 13:03:29 +0530410void HWCSession::GetCapabilities(uint32_t *outCount, int32_t *outCapabilities) {
Ramkumar Radhakrishnan82af7e92017-09-21 14:29:42 -0700411 if (!outCount) {
412 return;
413 }
414
Sushil Chauhan409e8442017-06-12 17:43:25 -0700415 int value = 0;
416 bool disable_skip_validate = false;
Uday Kiran Pichika5e656b22018-05-15 18:48:24 +0530417 if (Debug::Get()->GetProperty(DISABLE_SKIP_VALIDATE_PROP, &value) == kErrorNone) {
Sushil Chauhan409e8442017-06-12 17:43:25 -0700418 disable_skip_validate = (value == 1);
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500419 }
Sushil Chauhan409e8442017-06-12 17:43:25 -0700420 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 Ahmedb92e73f2016-03-12 02:03:48 -0500429}
430
431template <typename PFN, typename T>
432static 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 Kyatham42d11cb2019-04-16 13:03:29 +0530440int32_t HWCSession::AcceptDisplayChanges(hwc2_display_t display) {
441 return CallDisplayFunction(display, &HWCDisplay::AcceptDisplayChanges);
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500442}
443
Rajavenu Kyatham42d11cb2019-04-16 13:03:29 +0530444int32_t HWCSession::CreateLayer(hwc2_display_t display,
Naseer Ahmedaddcabf2016-05-04 15:49:29 -0400445 hwc2_layer_t *out_layer_id) {
Ramkumar Radhakrishnan82af7e92017-09-21 14:29:42 -0700446 if (!out_layer_id) {
447 return HWC2_ERROR_BAD_PARAMETER;
448 }
Saurabh Shah04f932b2017-10-12 18:47:45 -0700449
Rajavenu Kyatham42d11cb2019-04-16 13:03:29 +0530450 return CallDisplayFunction(display, &HWCDisplay::CreateLayer, out_layer_id);
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500451}
452
Rajavenu Kyatham42d11cb2019-04-16 13:03:29 +0530453int32_t HWCSession::CreateVirtualDisplay(uint32_t width, uint32_t height, int32_t *format,
454 hwc2_display_t *out_display_id) {
Naseer Ahmed42fc8d12016-05-11 18:33:57 -0400455 // TODO(user): Handle concurrency with HDMI
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500456
Ramkumar Radhakrishnan82af7e92017-09-21 14:29:42 -0700457 if (!out_display_id || !width || !height || !format) {
458 return HWC2_ERROR_BAD_PARAMETER;
459 }
460
Varun Arorad7d8c912019-08-16 11:45:19 -0700461 if (null_display_mode_) {
462 return 0;
463 }
464
Padmanabhan Komanduruf5b7f992019-07-08 13:33:44 +0530465 if (async_vds_creation_ && virtual_id_ != HWCCallbacks::kNumDisplays) {
466 *out_display_id = virtual_id_;
467 return HWC2_ERROR_NONE;
468 }
469
Rajavenu Kyatham42d11cb2019-04-16 13:03:29 +0530470 auto status = CreateVirtualDisplayObj(width, height, format, out_display_id);
Naseer Ahmed23633942016-07-13 19:46:56 -0400471 if (status == HWC2::Error::None) {
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +0530472 DLOGI("Created virtual display id:% " PRIu64 ", res: %dx%d", *out_display_id, width, height);
Naseer Ahmed23633942016-07-13 19:46:56 -0400473 } else {
474 DLOGE("Failed to create virtual display: %s", to_string(status).c_str());
475 }
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500476 return INT32(status);
477}
478
Rajavenu Kyatham42d11cb2019-04-16 13:03:29 +0530479int32_t HWCSession::DestroyLayer(hwc2_display_t display, hwc2_layer_t layer) {
480 return CallDisplayFunction(display, &HWCDisplay::DestroyLayer, layer);
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500481}
482
Rajavenu Kyatham42d11cb2019-04-16 13:03:29 +0530483int32_t HWCSession::DestroyVirtualDisplay(hwc2_display_t display) {
484 if (display >= HWCCallbacks::kNumDisplays) {
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500485 return HWC2_ERROR_BAD_DISPLAY;
486 }
487
Rajavenu Kyatham42d11cb2019-04-16 13:03:29 +0530488 hwc2_display_t active_builtin_disp_id = GetActiveBuiltinDisplay();
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500489
Padmanabhan Komandurue74cf4f2019-04-25 17:38:43 -0700490 if (active_builtin_disp_id < HWCCallbacks::kNumDisplays) {
Ramkumar Radhakrishnan44c64362018-12-12 13:03:59 -0800491 Locker::ScopeLock lock_a(locker_[active_builtin_disp_id]);
Mathew Joseph Karimpanal71ac8a72018-09-25 22:27:22 +0530492 std::bitset<kSecureMax> secure_sessions = 0;
Rajavenu Kyatham42d11cb2019-04-16 13:03:29 +0530493 hwc_display_[active_builtin_disp_id]->GetActiveSecureSession(&secure_sessions);
Ramkumar Radhakrishnana38b7602018-03-15 14:49:52 -0700494 if (secure_sessions.any()) {
Ramkumar Radhakrishnan44c64362018-12-12 13:03:59 -0800495 DLOGW("Secure session is active, defer destruction of virtual display id:%" PRIu64, display);
Rajavenu Kyatham42d11cb2019-04-16 13:03:29 +0530496 destroy_virtual_disp_pending_ = true;
Ramkumar Radhakrishnana38b7602018-03-15 14:49:52 -0700497 return HWC2_ERROR_NONE;
498 }
499 }
500
Rajavenu Kyatham42d11cb2019-04-16 13:03:29 +0530501 for (auto &map_info : map_info_virtual_) {
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +0530502 if (map_info.client_id == display) {
503 DLOGI("Destroying virtual display id:%" PRIu64, display);
Rajavenu Kyatham42d11cb2019-04-16 13:03:29 +0530504 DestroyDisplay(&map_info);
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +0530505 break;
506 }
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500507 }
Padmanabhan Komanduruf5b7f992019-07-08 13:33:44 +0530508 virtual_id_ = HWCCallbacks::kNumDisplays;
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +0530509
510 return HWC2_ERROR_NONE;
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500511}
512
Pullakavi Srinivasa3c292c2019-12-01 13:27:50 +0530513int32_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 Kyatham42d11cb2019-04-16 13:03:29 +0530528void HWCSession::Dump(uint32_t *out_size, char *out_buffer) {
529 if (!out_size) {
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500530 return;
531 }
Saurabh Shah9c224a32017-11-09 12:17:44 -0800532
Mathew Joseph Karimpanal50dfb992019-09-30 12:04:11 +0530533 const size_t max_dump_size = 16384; // 16 kB
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500534
535 if (out_buffer == nullptr) {
Naseer Ahmed66d5b492017-02-23 20:30:17 -0500536 *out_size = max_dump_size;
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500537 } else {
Dileep Marchya58928122020-01-28 12:16:51 +0530538 std::ostringstream os;
Srinivas Pullakavi3c4337f2019-07-03 11:24:31 +0530539 for (int id = 0; id < HWCCallbacks::kNumRealDisplays; id++) {
Saurabh Shah04f932b2017-10-12 18:47:45 -0700540 SCOPE_LOCK(locker_[id]);
Rajavenu Kyatham42d11cb2019-04-16 13:03:29 +0530541 if (hwc_display_[id]) {
Dileep Marchya58928122020-01-28 12:16:51 +0530542 hwc_display_[id]->Dump(&os);
Naseer Ahmed0f5b51c2016-06-22 19:39:38 -0400543 }
544 }
Dileep Marchya58928122020-01-28 12:16:51 +0530545 Fence::Dump(&os);
546
547 std::string s = os.str();
Naseer Ahmed66d5b492017-02-23 20:30:17 -0500548 auto copied = s.copy(out_buffer, std::min(s.size(), max_dump_size), 0);
549 *out_size = UINT32(copied);
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500550 }
551}
552
Rajavenu Kyatham42d11cb2019-04-16 13:03:29 +0530553uint32_t HWCSession::GetMaxVirtualDisplayCount() {
Pullakavi Srinivasa3c292c2019-12-01 13:27:50 +0530554 return map_info_virtual_.size();
Varun Aroraad2719a2018-10-25 10:13:53 -0700555}
556
Rajavenu Kyatham42d11cb2019-04-16 13:03:29 +0530557int32_t HWCSession::GetActiveConfig(hwc2_display_t display, hwc2_config_t *out_config) {
558 return CallDisplayFunction(display, &HWCDisplay::GetActiveConfig, out_config);
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500559}
560
Rajavenu Kyatham42d11cb2019-04-16 13:03:29 +0530561int32_t HWCSession::GetChangedCompositionTypes(hwc2_display_t display, uint32_t *out_num_elements,
562 hwc2_layer_t *out_layers, int32_t *out_types) {
Ramkumar Radhakrishnan82af7e92017-09-21 14:29:42 -0700563 // 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 Kyatham42d11cb2019-04-16 13:03:29 +0530567 return CallDisplayFunction(display, &HWCDisplay::GetChangedCompositionTypes, out_num_elements,
568 out_layers, out_types);
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500569}
570
Rajavenu Kyatham42d11cb2019-04-16 13:03:29 +0530571int32_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 Ahmedb92e73f2016-03-12 02:03:48 -0500575}
576
Rajavenu Kyatham42d11cb2019-04-16 13:03:29 +0530577int32_t HWCSession::GetColorModes(hwc2_display_t display, uint32_t *out_num_modes,
578 int32_t /*ColorMode*/ *int_out_modes) {
Naseer Ahmede7a77982018-06-04 10:56:04 -0400579 auto out_modes = reinterpret_cast<ColorMode *>(int_out_modes);
Arun Kumar K.R0e10fd22017-10-11 14:42:11 +0530580 if (out_num_modes == nullptr) {
581 return HWC2_ERROR_BAD_PARAMETER;
582 }
Rajavenu Kyatham42d11cb2019-04-16 13:03:29 +0530583 return CallDisplayFunction(display, &HWCDisplay::GetColorModes, out_num_modes, out_modes);
Arun Kumar K.R29cd6582016-05-10 19:12:45 -0700584}
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500585
Rajavenu Kyatham42d11cb2019-04-16 13:03:29 +0530586int32_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 Ahmede7a77982018-06-04 10:56:04 -0400589 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 Dhamiec0fa512018-08-29 16:51:26 -0400594
Gousemoodhin Nadaf0e566872019-05-13 16:14:54 +0530595 if (mode < ColorMode::NATIVE || mode > ColorMode::DISPLAY_BT2020) {
Gurpreet Singh Dhamiec0fa512018-08-29 16:51:26 -0400596 DLOGE("Invalid ColorMode: %d", mode);
597 return HWC2_ERROR_BAD_PARAMETER;
598 }
Rajavenu Kyatham42d11cb2019-04-16 13:03:29 +0530599 return CallDisplayFunction(display, &HWCDisplay::GetRenderIntents, mode, out_num_intents,
600 out_intents);
Naseer Ahmede7a77982018-06-04 10:56:04 -0400601}
602
Rajavenu Kyatham42d11cb2019-04-16 13:03:29 +0530603int32_t HWCSession::GetDataspaceSaturationMatrix(int32_t /*Dataspace*/ int_dataspace,
604 float *out_matrix) {
Naseer Ahmede7a77982018-06-04 10:56:04 -0400605 auto dataspace = static_cast<Dataspace>(int_dataspace);
Rajavenu Kyatham42d11cb2019-04-16 13:03:29 +0530606 if (out_matrix == nullptr || dataspace != Dataspace::SRGB_LINEAR) {
Naseer Ahmede7a77982018-06-04 10:56:04 -0400607 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 Ahmede7a77982018-06-04 10:56:04 -0400615 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 Kyatham42d11cb2019-04-16 13:03:29 +0530625int32_t HWCSession::GetPerFrameMetadataKeys(hwc2_display_t display, uint32_t *out_num_keys,
626 int32_t *int_out_keys) {
Naseer Ahmeda6782e42018-06-04 10:56:04 -0400627 auto out_keys = reinterpret_cast<PerFrameMetadataKey *>(int_out_keys);
Rajavenu Kyatham42d11cb2019-04-16 13:03:29 +0530628 return CallDisplayFunction(display, &HWCDisplay::GetPerFrameMetadataKeys, out_num_keys,
629 out_keys);
Naseer Ahmeda6782e42018-06-04 10:56:04 -0400630}
631
Rajavenu Kyatham42d11cb2019-04-16 13:03:29 +0530632int32_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 Ahmeda6782e42018-06-04 10:56:04 -0400635 auto keys = reinterpret_cast<const PerFrameMetadataKey *>(int_keys);
Rajavenu Kyatham42d11cb2019-04-16 13:03:29 +0530636 return CallLayerFunction(display, layer, &HWCLayer::SetLayerPerFrameMetadata, num_elements,
637 keys, metadata);
Naseer Ahmeda6782e42018-06-04 10:56:04 -0400638}
639
Gousemoodhin Nadaf4b096d02019-10-24 15:39:59 +0530640int32_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 Kalavala25fe12c2019-12-11 20:44:55 -0800649int32_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
660int32_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
667int32_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 Kyatham42d11cb2019-04-16 13:03:29 +0530675int32_t HWCSession::GetDisplayAttribute(hwc2_display_t display, hwc2_config_t config,
Naseer Ahmed8584a0f2020-02-19 22:23:30 -0500676 HwcAttribute attribute, int32_t *out_value) {
677 if (out_value == nullptr) {
Arun Kumar K.R0e10fd22017-10-11 14:42:11 +0530678 return HWC2_ERROR_BAD_PARAMETER;
679 }
Rajavenu Kyatham42d11cb2019-04-16 13:03:29 +0530680 return CallDisplayFunction(display, &HWCDisplay::GetDisplayAttribute, config, attribute,
681 out_value);
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500682}
683
Rajavenu Kyatham42d11cb2019-04-16 13:03:29 +0530684int32_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 Ahmedb92e73f2016-03-12 02:03:48 -0500688}
689
Rajavenu Kyatham42d11cb2019-04-16 13:03:29 +0530690int32_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 Ahmedb92e73f2016-03-12 02:03:48 -0500692}
693
Rajavenu Kyatham42d11cb2019-04-16 13:03:29 +0530694int32_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 Ahmedb92e73f2016-03-12 02:03:48 -0500699}
700
Rajavenu Kyatham42d11cb2019-04-16 13:03:29 +0530701int32_t HWCSession::GetDisplayType(hwc2_display_t display, int32_t *out_type) {
702 return CallDisplayFunction(display, &HWCDisplay::GetDisplayType, out_type);
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500703}
704
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500705
Rajavenu Kyatham42d11cb2019-04-16 13:03:29 +0530706int32_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 Ahmed77907722016-05-03 18:27:54 -0400712}
713
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500714
Rajavenu Kyatham42d11cb2019-04-16 13:03:29 +0530715int32_t HWCSession::GetReleaseFences(hwc2_display_t display, uint32_t *out_num_elements,
Rajavenu Kyatham7338b9e2019-12-30 19:52:16 +0530716 hwc2_layer_t *out_layers,
717 std::vector<shared_ptr<Fence>> *out_fences) {
Rajavenu Kyatham42d11cb2019-04-16 13:03:29 +0530718 return CallDisplayFunction(display, &HWCDisplay::GetReleaseFences, out_num_elements, out_layers,
719 out_fences);
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500720}
721
Padmanabhan Komanduru6693fcb2019-11-22 21:06:52 +0530722void HWCSession::PerformQsyncCallback(hwc2_display_t display) {
Padmanabhan Komanduru9e971622020-02-10 13:09:34 +0530723 std::shared_ptr<DisplayConfig::ConfigCallback> callback = qsync_callback_.lock();
724 if (!callback) {
Padmanabhan Komanduru6693fcb2019-11-22 21:06:52 +0530725 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 Komanduru9e971622020-02-10 13:09:34 +0530732 callback->NotifyQsyncChange(qsync_enabled, refresh_rate, qsync_refresh_rate);
Padmanabhan Komanduru6693fcb2019-11-22 21:06:52 +0530733 }
734}
735
Dileep Marchyaad668432019-12-02 10:44:52 +0530736int32_t HWCSession::PresentDisplay(hwc2_display_t display, shared_ptr<Fence> *out_retire_fence) {
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500737 auto status = HWC2::Error::BadDisplay;
Baldev Sahua5e48362017-08-31 15:36:44 +0530738 DTRACE_SCOPED();
Saurabh Shah04f932b2017-10-12 18:47:45 -0700739
Rajavenu Kyatham42d11cb2019-04-16 13:03:29 +0530740 if (display >= HWCCallbacks::kNumDisplays) {
741 DLOGW("Invalid Display : display = %" PRIu64, display);
Saurabh Shah04f932b2017-10-12 18:47:45 -0700742 return HWC2_ERROR_BAD_DISPLAY;
743 }
744
Rajavenu Kyatham42d11cb2019-04-16 13:03:29 +0530745 HandleSecureSession();
Mathew Joseph Karimpanalb1c15862019-07-04 11:14:24 +0530746
747
748 hwc2_display_t target_display = display;
749
Baldev Sahua5e48362017-08-31 15:36:44 +0530750 {
Srinivas Pullakavi3c4337f2019-07-03 11:24:31 +0530751 SCOPE_LOCK(power_state_[display]);
752 if (power_state_transition_[display]) {
753 // Route all interactions with client to dummy display.
Mathew Joseph Karimpanalb1c15862019-07-04 11:14:24 +0530754 target_display = map_hwc_display_.find(display)->second;
Srinivas Pullakavi3c4337f2019-07-03 11:24:31 +0530755 }
756 }
757
758 {
Mathew Joseph Karimpanalb1c15862019-07-04 11:14:24 +0530759 SEQUENCE_EXIT_SCOPE_LOCK(locker_[target_display]);
760 if (!hwc_display_[target_display]) {
761 DLOGW("Removed Display : display = %" PRIu64, target_display);
Baldev Sahua5e48362017-08-31 15:36:44 +0530762 return HWC2_ERROR_BAD_DISPLAY;
763 }
764
765 if (out_retire_fence == nullptr) {
766 return HWC2_ERROR_BAD_PARAMETER;
767 }
768
Mathew Joseph Karimpanalb1c15862019-07-04 11:14:24 +0530769 if (pending_power_mode_[display]) {
Mathew Joseph Karimpanal71ac8a72018-09-25 22:27:22 +0530770 status = HWC2::Error::None;
Gurpreet Singh Dhamia9478232018-08-21 12:19:47 -0400771 } else {
Sushil Chauhandbd8db42020-02-28 13:07:48 -0800772 hwc_display_[target_display]->ProcessActiveConfigChange();
Dileep Marchyaad668432019-12-02 10:44:52 +0530773 status = PresentDisplayInternal(target_display);
Padmanabhan Komandurue74cf4f2019-04-25 17:38:43 -0700774 if (status == HWC2::Error::None) {
775 // Check if hwc's refresh trigger is getting exercised.
Rajavenu Kyatham42d11cb2019-04-16 13:03:29 +0530776 if (callbacks_.NeedsRefresh(display)) {
Mathew Joseph Karimpanalb1c15862019-07-04 11:14:24 +0530777 hwc_display_[target_display]->SetPendingRefresh();
Rajavenu Kyatham42d11cb2019-04-16 13:03:29 +0530778 callbacks_.ResetRefresh(display);
Padmanabhan Komandurue74cf4f2019-04-25 17:38:43 -0700779 }
Mathew Joseph Karimpanalb1c15862019-07-04 11:14:24 +0530780 status = hwc_display_[target_display]->Present(out_retire_fence);
Padmanabhan Komanduru6693fcb2019-11-22 21:06:52 +0530781 if (status == HWC2::Error::None) {
782 PerformQsyncCallback(target_display);
783 }
Padmanabhan Komandurue74cf4f2019-04-25 17:38:43 -0700784 }
Baldev Sahua5e48362017-08-31 15:36:44 +0530785 }
786 }
787
Saurabh Shah04f932b2017-10-12 18:47:45 -0700788 if (status != HWC2::Error::None && status != HWC2::Error::NotValidated) {
Mathew Joseph Karimpanalb1c15862019-07-04 11:14:24 +0530789 SEQUENCE_CANCEL_SCOPE_LOCK(locker_[target_display]);
Saurabh Shah04f932b2017-10-12 18:47:45 -0700790 }
791
Mathew Joseph Karimpanalb1c15862019-07-04 11:14:24 +0530792 HandlePendingPowerMode(display, *out_retire_fence);
793 HandlePendingHotplug(display, *out_retire_fence);
Rajavenu Kyatham42d11cb2019-04-16 13:03:29 +0530794 HandlePendingRefresh();
Dileep Marchyacb2a3a92019-06-21 17:30:50 +0530795 cwb_.PresentDisplayDone(display);
Srinivas Pullakavi3c4337f2019-07-03 11:24:31 +0530796 display_ready_.set(UINT32(display));
Padmanabhan Komanduruf5b7f992019-07-08 13:33:44 +0530797 {
798 std::unique_lock<std::mutex> caller_lock(hotplug_mutex_);
799 hotplug_cv_.notify_one();
800 }
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500801
802 return INT32(status);
803}
804
Padmanabhan Komanduru1649f222019-03-05 11:25:00 +0530805void 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 Aroradff7d8d2019-08-05 18:12:43 -0700812 callbacks_.Refresh(i);
Padmanabhan Komanduru1649f222019-03-05 11:25:00 +0530813 }
814 break;
815 }
816
817 pending_refresh_.reset();
818}
819
Rajavenu Kyatham42d11cb2019-04-16 13:03:29 +0530820void HWCSession::RegisterCallback(int32_t descriptor, hwc2_callback_data_t callback_data,
821 hwc2_function_pointer_t pointer) {
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500822 auto desc = static_cast<HWC2::Callback>(descriptor);
Varun Arora2daeb072019-08-06 15:09:28 -0700823
824 // Detect if client died and now is back
825 bool already_connected = false;
826 vector<hwc2_display_t> pending_hotplugs;
Gousemoodhin Nadaf0db182e2019-09-05 23:02:31 +0530827 if (descriptor == HWC2_CALLBACK_HOTPLUG && pointer) {
Varun Arora2daeb072019-08-06 15:09:28 -0700828 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 Kyatham42d11cb2019-04-16 13:03:29 +0530845 auto error = callbacks_.Register(desc, callback_data, pointer);
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +0530846 if (error != HWC2::Error::None) {
Rajavenu Kyatham42d11cb2019-04-16 13:03:29 +0530847 return;
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +0530848 }
849
Varun Aroradff7d8d2019-08-05 18:12:43 -0700850 DLOGI("%s callback: %s", pointer ? "Registering" : "Deregistering", to_string(desc).c_str());
Gousemoodhin Nadaf0db182e2019-09-05 23:02:31 +0530851 if (descriptor == HWC2_CALLBACK_HOTPLUG && pointer) {
Rajavenu Kyatham42d11cb2019-04-16 13:03:29 +0530852 if (hwc_display_[HWC_DISPLAY_PRIMARY]) {
Mathew Joseph Karimpanal8abb6e02018-11-20 09:52:49 +0530853 DLOGI("Hotplugging primary...");
Rajavenu Kyatham42d11cb2019-04-16 13:03:29 +0530854 callbacks_.Hotplug(HWC_DISPLAY_PRIMARY, HWC2::Connection::Connected);
Dileep Marchyad16da3e2017-05-20 01:56:21 +0530855 }
Mathew Joseph Karimpanal8abb6e02018-11-20 09:52:49 +0530856 // Create displays since they should now have their final display indices set.
857 DLOGI("Handling built-in displays...");
Rajavenu Kyatham42d11cb2019-04-16 13:03:29 +0530858 if (HandleBuiltInDisplays()) {
Mathew Joseph Karimpanal8abb6e02018-11-20 09:52:49 +0530859 DLOGW("Failed handling built-in displays.");
860 }
861 DLOGI("Handling pluggable displays...");
Rajavenu Kyatham42d11cb2019-04-16 13:03:29 +0530862 int32_t err = HandlePluggableDisplays(false);
Mathew Joseph Karimpanalabe3b3d2018-11-27 17:25:40 +0530863 if (err) {
864 DLOGW("All displays could not be created. Error %d '%s'. Hotplug handling %s.", err,
Mathew Joseph Karimpanalb1c15862019-07-04 11:14:24 +0530865 strerror(abs(err)), pending_hotplug_event_ == kHotPlugEvent ? "deferred" :
Mathew Joseph Karimpanalabe3b3d2018-11-27 17:25:40 +0530866 "dropped");
Mathew Joseph Karimpanal8abb6e02018-11-20 09:52:49 +0530867 }
Varun Arora2daeb072019-08-06 15:09:28 -0700868
869 // If previously registered, call hotplug for all connected displays to refresh
870 if (already_connected) {
Gousemoodhin Nadaf0db182e2019-09-05 23:02:31 +0530871 std::vector<hwc2_display_t> updated_pending_hotplugs;
Varun Arora2daeb072019-08-06 15:09:28 -0700872 for (auto client_id : pending_hotplugs) {
873 SCOPE_LOCK(locker_[client_id]);
Gousemoodhin Nadaf0db182e2019-09-05 23:02:31 +0530874 // check if the display is unregistered
Varun Arora2daeb072019-08-06 15:09:28 -0700875 if (hwc_display_[client_id]) {
Gousemoodhin Nadaf0db182e2019-09-05 23:02:31 +0530876 updated_pending_hotplugs.push_back(client_id);
Varun Arora2daeb072019-08-06 15:09:28 -0700877 }
878 }
Gousemoodhin Nadaf0db182e2019-09-05 23:02:31 +0530879 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 Arora2daeb072019-08-06 15:09:28 -0700883 }
Rajavenu Kyatham59b67862019-11-26 21:02:56 +0530884 }
885
886 if (descriptor == HWC2_CALLBACK_HOTPLUG) {
Pullakavi Srinivas2d55f3a2019-07-16 14:49:06 +0530887 client_connected_ = !!pointer;
888 // Notfify all displays.
889 NotifyClientStatus(client_connected_);
Dileep Marchyad16da3e2017-05-20 01:56:21 +0530890 }
Rajavenu Kyatham42d11cb2019-04-16 13:03:29 +0530891 need_invalidate_ = false;
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500892}
893
Rajavenu Kyatham42d11cb2019-04-16 13:03:29 +0530894int32_t HWCSession::SetActiveConfig(hwc2_display_t display, hwc2_config_t config) {
895 return CallDisplayFunction(display, &HWCDisplay::SetActiveConfig, config);
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500896}
897
Rajavenu Kyatham42d11cb2019-04-16 13:03:29 +0530898int32_t HWCSession::SetClientTarget(hwc2_display_t display, buffer_handle_t target,
Rajavenu Kyatham7338b9e2019-12-30 19:52:16 +0530899 const shared_ptr<Fence> acquire_fence, int32_t dataspace,
Rajavenu Kyatham42d11cb2019-04-16 13:03:29 +0530900 hwc_region_t damage) {
901 return CallDisplayFunction(display, &HWCDisplay::SetClientTarget, target, acquire_fence,
902 dataspace, damage);
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500903}
904
Rajavenu Kyatham42d11cb2019-04-16 13:03:29 +0530905int32_t HWCSession::SetColorMode(hwc2_display_t display, int32_t /*ColorMode*/ int_mode) {
Naseer Ahmede7a77982018-06-04 10:56:04 -0400906 auto mode = static_cast<ColorMode>(int_mode);
Gousemoodhin Nadaf0e566872019-05-13 16:14:54 +0530907 if (mode < ColorMode::NATIVE || mode > ColorMode::DISPLAY_BT2020) {
Saurabh Dubey25069372017-10-10 14:21:22 +0530908 return HWC2_ERROR_BAD_PARAMETER;
909 }
Rajavenu Kyatham42d11cb2019-04-16 13:03:29 +0530910 return CallDisplayFunction(display, &HWCDisplay::SetColorMode, mode);
Arun Kumar K.R29cd6582016-05-10 19:12:45 -0700911}
912
Rajavenu Kyatham42d11cb2019-04-16 13:03:29 +0530913int32_t HWCSession::SetColorModeWithRenderIntent(hwc2_display_t display,
Naseer Ahmede7a77982018-06-04 10:56:04 -0400914 int32_t /*ColorMode*/ int_mode,
915 int32_t /*RenderIntent*/ int_render_intent) {
916 auto mode = static_cast<ColorMode>(int_mode);
Gousemoodhin Nadaf0e566872019-05-13 16:14:54 +0530917 if (mode < ColorMode::NATIVE || mode > ColorMode::DISPLAY_BT2020) {
Naseer Ahmede7a77982018-06-04 10:56:04 -0400918 return HWC2_ERROR_BAD_PARAMETER;
919 }
Xu Yang47f44092019-02-13 14:09:53 +0800920
921 if ((int_render_intent < 0) || (int_render_intent > MAX_EXTENDED_RENDER_INTENT)) {
922 DLOGE("Invalid RenderIntent: %d", int_render_intent);
Gurpreet Singh Dhamiec0fa512018-08-29 16:51:26 -0400923 return HWC2_ERROR_BAD_PARAMETER;
924 }
Xu Yang47f44092019-02-13 14:09:53 +0800925
926 auto render_intent = static_cast<RenderIntent>(int_render_intent);
Rajavenu Kyatham42d11cb2019-04-16 13:03:29 +0530927 return CallDisplayFunction(display, &HWCDisplay::SetColorModeWithRenderIntent, mode,
928 render_intent);
Naseer Ahmede7a77982018-06-04 10:56:04 -0400929}
930
Rajavenu Kyatham42d11cb2019-04-16 13:03:29 +0530931int32_t HWCSession::SetColorTransform(hwc2_display_t display, const float *matrix,
Arun Kumar K.R29cd6582016-05-10 19:12:45 -0700932 int32_t /*android_color_transform_t*/ hint) {
Saurabh Dubey25069372017-10-10 14:21:22 +0530933 if (!matrix || hint < HAL_COLOR_TRANSFORM_IDENTITY ||
934 hint > HAL_COLOR_TRANSFORM_CORRECT_TRITANOPIA) {
935 return HWC2_ERROR_BAD_PARAMETER;
936 }
Arun Kumar K.R29cd6582016-05-10 19:12:45 -0700937 android_color_transform_t transform_hint = static_cast<android_color_transform_t>(hint);
Rajavenu Kyatham42d11cb2019-04-16 13:03:29 +0530938 return CallDisplayFunction(display, &HWCDisplay::SetColorTransform, matrix, transform_hint);
Arun Kumar K.R29cd6582016-05-10 19:12:45 -0700939}
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500940
Rajavenu Kyatham42d11cb2019-04-16 13:03:29 +0530941int32_t HWCSession::SetCursorPosition(hwc2_display_t display, hwc2_layer_t layer, int32_t x,
942 int32_t y) {
Pullakavi Srinivas68a166c2017-05-24 12:17:07 +0530943 auto status = INT32(HWC2::Error::None);
Rajavenu Kyatham42d11cb2019-04-16 13:03:29 +0530944 status = CallDisplayFunction(display, &HWCDisplay::SetCursorPosition, layer, x, y);
Pullakavi Srinivas68a166c2017-05-24 12:17:07 +0530945 if (status == INT32(HWC2::Error::None)) {
946 // Update cursor position
Rajavenu Kyatham42d11cb2019-04-16 13:03:29 +0530947 CallLayerFunction(display, layer, &HWCLayer::SetCursorPosition, x, y);
Pullakavi Srinivas68a166c2017-05-24 12:17:07 +0530948 }
949 return status;
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500950}
951
Rajavenu Kyatham42d11cb2019-04-16 13:03:29 +0530952int32_t HWCSession::SetLayerBlendMode(hwc2_display_t display, hwc2_layer_t layer,
953 int32_t int_mode) {
Saurabh Dubey25069372017-10-10 14:21:22 +0530954 if (int_mode < HWC2_BLEND_MODE_INVALID || int_mode > HWC2_BLEND_MODE_COVERAGE) {
955 return HWC2_ERROR_BAD_PARAMETER;
956 }
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500957 auto mode = static_cast<HWC2::BlendMode>(int_mode);
Rajavenu Kyatham42d11cb2019-04-16 13:03:29 +0530958 return CallLayerFunction(display, layer, &HWCLayer::SetLayerBlendMode, mode);
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500959}
960
Rajavenu Kyatham42d11cb2019-04-16 13:03:29 +0530961int32_t HWCSession::SetLayerBuffer(hwc2_display_t display, hwc2_layer_t layer,
Rajavenu Kyatham7338b9e2019-12-30 19:52:16 +0530962 buffer_handle_t buffer,
963 const shared_ptr<Fence> &acquire_fence) {
Rajavenu Kyatham42d11cb2019-04-16 13:03:29 +0530964 return CallLayerFunction(display, layer, &HWCLayer::SetLayerBuffer, buffer, acquire_fence);
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500965}
966
Rajavenu Kyatham42d11cb2019-04-16 13:03:29 +0530967int32_t HWCSession::SetLayerColor(hwc2_display_t display, hwc2_layer_t layer, hwc_color_t color) {
968 return CallLayerFunction(display, layer, &HWCLayer::SetLayerColor, color);
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500969}
970
Rajavenu Kyatham42d11cb2019-04-16 13:03:29 +0530971int32_t HWCSession::SetLayerCompositionType(hwc2_display_t display, hwc2_layer_t layer,
972 int32_t int_type) {
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500973 auto type = static_cast<HWC2::Composition>(int_type);
Rajavenu Kyatham42d11cb2019-04-16 13:03:29 +0530974 return CallLayerFunction(display, layer, &HWCLayer::SetLayerCompositionType, type);
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500975}
976
Rajavenu Kyatham42d11cb2019-04-16 13:03:29 +0530977int32_t HWCSession::SetLayerDataspace(hwc2_display_t display, hwc2_layer_t layer,
978 int32_t dataspace) {
979 return CallLayerFunction(display, layer, &HWCLayer::SetLayerDataspace, dataspace);
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500980}
981
Rajavenu Kyatham42d11cb2019-04-16 13:03:29 +0530982int32_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 Ahmedb92e73f2016-03-12 02:03:48 -0500985}
986
Rajavenu Kyatham42d11cb2019-04-16 13:03:29 +0530987int32_t HWCSession::SetLayerPlaneAlpha(hwc2_display_t display, hwc2_layer_t layer, float alpha) {
988 return CallLayerFunction(display, layer, &HWCLayer::SetLayerPlaneAlpha, alpha);
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500989}
990
Rajavenu Kyatham42d11cb2019-04-16 13:03:29 +0530991int32_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 Ahmedb92e73f2016-03-12 02:03:48 -0500994}
995
Rajavenu Kyatham42d11cb2019-04-16 13:03:29 +0530996int32_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 Ahmedb92e73f2016-03-12 02:03:48 -0500999}
1000
Rajavenu Kyatham42d11cb2019-04-16 13:03:29 +05301001int32_t HWCSession::SetLayerTransform(hwc2_display_t display, hwc2_layer_t layer,
1002 int32_t int_transform) {
Naseer Ahmedb92e73f2016-03-12 02:03:48 -05001003 auto transform = static_cast<HWC2::Transform>(int_transform);
Rajavenu Kyatham42d11cb2019-04-16 13:03:29 +05301004 return CallLayerFunction(display, layer, &HWCLayer::SetLayerTransform, transform);
Naseer Ahmedb92e73f2016-03-12 02:03:48 -05001005}
1006
Rajavenu Kyatham42d11cb2019-04-16 13:03:29 +05301007int32_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 Ahmedb92e73f2016-03-12 02:03:48 -05001010}
1011
Rajavenu Kyatham42d11cb2019-04-16 13:03:29 +05301012int32_t HWCSession::SetLayerZOrder(hwc2_display_t display, hwc2_layer_t layer, uint32_t z) {
1013 return CallDisplayFunction(display, &HWCDisplay::SetLayerZOrder, layer, z);
Naseer Ahmedb92e73f2016-03-12 02:03:48 -05001014}
1015
Ray Zhang2ee82472019-09-05 02:53:29 +08001016int32_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 Kyatham42d11cb2019-04-16 13:03:29 +05301021int32_t HWCSession::SetLayerColorTransform(hwc2_display_t display, hwc2_layer_t layer,
1022 const float *matrix) {
1023 return CallLayerFunction(display, layer, &HWCLayer::SetLayerColorTransform, matrix);
Tharaga Balachandran209db582019-03-25 18:56:50 -04001024}
1025
Padmanabhan Komanduru13b5e102019-12-03 12:35:09 +05301026int32_t HWCSession::SetDisplayElapseTime(hwc2_display_t display, uint64_t time) {
1027 return CallDisplayFunction(display, &HWCDisplay::SetDisplayElapseTime, time);
1028}
1029
Rajavenu Kyatham42d11cb2019-04-16 13:03:29 +05301030int32_t HWCSession::SetOutputBuffer(hwc2_display_t display, buffer_handle_t buffer,
Rajavenu Kyatham7338b9e2019-12-30 19:52:16 +05301031 const shared_ptr<Fence> &release_fence) {
Rajavenu Kyatham42d11cb2019-04-16 13:03:29 +05301032 if (INT32(display) != GetDisplayIndex(qdutils::DISPLAY_VIRTUAL)) {
Arun Kumar K.R1018d5b2017-06-08 13:51:05 +05301033 return HWC2_ERROR_UNSUPPORTED;
1034 }
1035
Saurabh Shahc5c687a2017-08-24 16:30:14 -07001036 SCOPE_LOCK(locker_[display]);
Rajavenu Kyatham42d11cb2019-04-16 13:03:29 +05301037 if (hwc_display_[display]) {
1038 auto vds = reinterpret_cast<HWCDisplayVirtual *>(hwc_display_[display]);
Rajavenu Kyatham7338b9e2019-12-30 19:52:16 +05301039 auto status = vds->SetOutputBuffer(buffer, release_fence);
Naseer Ahmedb92e73f2016-03-12 02:03:48 -05001040 return INT32(status);
1041 } else {
1042 return HWC2_ERROR_BAD_DISPLAY;
1043 }
1044}
1045
Rajavenu Kyatham42d11cb2019-04-16 13:03:29 +05301046int32_t HWCSession::SetPowerMode(hwc2_display_t display, int32_t int_mode) {
Padmanabhan Komandurue74cf4f2019-04-25 17:38:43 -07001047 if (display >= HWCCallbacks::kNumDisplays) {
Varun Arora2c23e582017-10-10 15:07:13 -07001048 return HWC2_ERROR_BAD_DISPLAY;
1049 }
1050
1051 // validate device and also avoid undefined behavior in cast to HWC2::PowerMode
Rajavenu Kyatham42d11cb2019-04-16 13:03:29 +05301052 if (int_mode < HWC2_POWER_MODE_OFF || int_mode > HWC2_POWER_MODE_DOZE_SUSPEND) {
Varun Arora2c23e582017-10-10 15:07:13 -07001053 return HWC2_ERROR_BAD_PARAMETER;
1054 }
1055
Mathew Joseph Karimpanalb1c15862019-07-04 11:14:24 +05301056 if (pending_power_mode_[display]) {
Ramkumar Radhakrishnana38b7602018-03-15 14:49:52 -07001057 DLOGW("Set power mode is not allowed during secure display session");
1058 return HWC2_ERROR_UNSUPPORTED;
1059 }
1060
Naseer Ahmedb92e73f2016-03-12 02:03:48 -05001061 auto mode = static_cast<HWC2::PowerMode>(int_mode);
Varun Arora2c23e582017-10-10 15:07:13 -07001062
1063 // all displays support on/off. Check for doze modes
1064 int support = 0;
Rajavenu Kyatham42d11cb2019-04-16 13:03:29 +05301065 auto status = GetDozeSupport(display, &support);
Gurpreet Singh Dhamia9478232018-08-21 12:19:47 -04001066 if (status != HWC2_ERROR_NONE) {
1067 DLOGE("Failed to get doze support Error = %d", status);
1068 return INT32(status);
1069 }
1070
Varun Arora2c23e582017-10-10 15:07:13 -07001071 if (!support && (mode == HWC2::PowerMode::Doze || mode == HWC2::PowerMode::DozeSuspend)) {
1072 return HWC2_ERROR_UNSUPPORTED;
1073 }
1074
Srinivas Pullakavi3c4337f2019-07-03 11:24:31 +05301075 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 Karimpanalb1c15862019-07-04 11:14:24 +05301083 Locker::ScopeLock lock_disp(locker_[display]);
Srinivas Pullakavi3c4337f2019-07-03 11:24:31 +05301084 // Update hwc state for now. Actual poweron will handled through DisplayConfig.
1085 hwc_display_[display]->UpdatePowerMode(mode);
Srinivas Pullakavia747d832018-05-22 13:52:06 +05301086 }
Ramkumar Radhakrishnanf985d482018-07-23 18:10:41 -07001087 // Reset idle pc ref count on suspend, as we enable idle pc during suspend.
1088 if (mode == HWC2::PowerMode::Off) {
Rajavenu Kyatham42d11cb2019-04-16 13:03:29 +05301089 idle_pc_ref_cnt_ = 0;
Ramkumar Radhakrishnanf985d482018-07-23 18:10:41 -07001090 }
Srinivas Pullakavia747d832018-05-22 13:52:06 +05301091
Rajavenu Kyatham42d11cb2019-04-16 13:03:29 +05301092
1093 UpdateThrottlingRate();
Rajavenu Kyatham9d509582019-02-13 15:29:55 +05301094
Rajavenu Kyatham9d509582019-02-13 15:29:55 +05301095 if (mode == HWC2::PowerMode::Doze) {
Padmanabhan Komanduru1649f222019-03-05 11:25:00 +05301096 // Trigger one more refresh for PP features to take effect.
Rajavenu Kyatham42d11cb2019-04-16 13:03:29 +05301097 pending_refresh_.set(UINT32(display));
Rajavenu Kyatham9d509582019-02-13 15:29:55 +05301098 }
1099
Srinivas Pullakavia747d832018-05-22 13:52:06 +05301100 return HWC2_ERROR_NONE;
Naseer Ahmedb92e73f2016-03-12 02:03:48 -05001101}
1102
Rajavenu Kyatham42d11cb2019-04-16 13:03:29 +05301103int32_t HWCSession::SetVsyncEnabled(hwc2_display_t display, int32_t int_enabled) {
Varun Arora2c23e582017-10-10 15:07:13 -07001104 // 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 Ahmedb92e73f2016-03-12 02:03:48 -05001109 auto enabled = static_cast<HWC2::Vsync>(int_enabled);
Srinivas Pullakavia747d832018-05-22 13:52:06 +05301110
Padmanabhan Komanduruf5e6c5d2019-04-04 13:56:31 +05301111 if (int_enabled == HWC2_VSYNC_ENABLE) {
Rajavenu Kyatham42d11cb2019-04-16 13:03:29 +05301112 callbacks_.UpdateVsyncSource(display);
Padmanabhan Komanduruf5e6c5d2019-04-04 13:56:31 +05301113 }
Srinivas Pullakavia747d832018-05-22 13:52:06 +05301114
Rajavenu Kyatham42d11cb2019-04-16 13:03:29 +05301115 return CallDisplayFunction(display, &HWCDisplay::SetVsyncEnabled, enabled);
Naseer Ahmedb92e73f2016-03-12 02:03:48 -05001116}
1117
Rajavenu Kyatham42d11cb2019-04-16 13:03:29 +05301118int32_t HWCSession::GetDozeSupport(hwc2_display_t display, int32_t *out_support) {
1119 if (!out_support) {
Pullakavi Srinivas04e52422018-07-31 15:12:57 +05301120 return HWC2_ERROR_BAD_PARAMETER;
1121 }
1122
Rajavenu Kyatham42d11cb2019-04-16 13:03:29 +05301123 if (display >= HWCCallbacks::kNumDisplays || (hwc_display_[display] == nullptr)) {
1124 DLOGE("Invalid Display %d Handle %s ", display, hwc_display_[display] ?
Gurpreet Singh Dhamia9478232018-08-21 12:19:47 -04001125 "Valid" : "NULL");
Pullakavi Srinivas04e52422018-07-31 15:12:57 +05301126 return HWC2_ERROR_BAD_DISPLAY;
1127 }
1128
Pullakavi Srinivas04e52422018-07-31 15:12:57 +05301129 *out_support = 0;
Rajavenu Kyatham42d11cb2019-04-16 13:03:29 +05301130 if (hwc_display_[display]->GetDisplayClass() == DISPLAY_CLASS_BUILTIN) {
Pullakavi Srinivas04e52422018-07-31 15:12:57 +05301131 *out_support = 1;
1132 }
1133
1134 return HWC2_ERROR_NONE;
1135}
1136
Rajavenu Kyatham42d11cb2019-04-16 13:03:29 +05301137int32_t HWCSession::ValidateDisplay(hwc2_display_t display, uint32_t *out_num_types,
1138 uint32_t *out_num_requests) {
Varun Arora2c23e582017-10-10 15:07:13 -07001139 // out_num_types and out_num_requests will be non-NULL
Varun Arora2c23e582017-10-10 15:07:13 -07001140
Padmanabhan Komandurue74cf4f2019-04-25 17:38:43 -07001141 if (display >= HWCCallbacks::kNumDisplays) {
Naseer Ahmedb92e73f2016-03-12 02:03:48 -05001142 return HWC2_ERROR_BAD_DISPLAY;
1143 }
Srinivas Pullakavi3c4337f2019-07-03 11:24:31 +05301144
Mathew Joseph Karimpanalb1c15862019-07-04 11:14:24 +05301145 hwc2_display_t target_display = display;
1146
Srinivas Pullakavi3c4337f2019-07-03 11:24:31 +05301147 {
1148 SCOPE_LOCK(power_state_[display]);
1149 if (power_state_transition_[display]) {
1150 // Route all interactions with client to dummy display.
Mathew Joseph Karimpanalb1c15862019-07-04 11:14:24 +05301151 target_display = map_hwc_display_.find(display)->second;
Srinivas Pullakavi3c4337f2019-07-03 11:24:31 +05301152 }
1153 }
Varun Arora2c23e582017-10-10 15:07:13 -07001154 DTRACE_SCOPED();
Naseer Ahmedb92e73f2016-03-12 02:03:48 -05001155 // TODO(user): Handle secure session, handle QDCM solid fill
Naseer Ahmedb92e73f2016-03-12 02:03:48 -05001156 auto status = HWC2::Error::BadDisplay;
Rajavenu Kyatham42d11cb2019-04-16 13:03:29 +05301157 HandleSecureSession();
Saurabh Shahc5c687a2017-08-24 16:30:14 -07001158 {
Mathew Joseph Karimpanalb1c15862019-07-04 11:14:24 +05301159 SEQUENCE_ENTRY_SCOPE_LOCK(locker_[target_display]);
1160 if (pending_power_mode_[display]) {
Mathew Joseph Karimpanal71ac8a72018-09-25 22:27:22 +05301161 status = HWC2::Error::None;
Mathew Joseph Karimpanalb1c15862019-07-04 11:14:24 +05301162 } else if (hwc_display_[target_display]) {
Sushil Chauhanba8e4652020-03-20 10:07:47 -07001163 hwc_display_[target_display]->ProcessActiveConfigChange();
Mathew Joseph Karimpanalb1c15862019-07-04 11:14:24 +05301164 hwc_display_[target_display]->SetFastPathComposition(false);
1165 status = ValidateDisplayInternal(target_display, out_num_types, out_num_requests);
Naseer Ahmedb92e73f2016-03-12 02:03:48 -05001166 }
Naseer Ahmedb92e73f2016-03-12 02:03:48 -05001167 }
Saurabh Shahc5c687a2017-08-24 16:30:14 -07001168
Saurabh Shah04f932b2017-10-12 18:47:45 -07001169 // Sequence locking currently begins on Validate, so cancel the sequence lock on failures
Saurabh Shah998ad472018-01-18 11:44:08 -08001170 if (status != HWC2::Error::None && status != HWC2::Error::HasChanges) {
Mathew Joseph Karimpanalb1c15862019-07-04 11:14:24 +05301171 SEQUENCE_CANCEL_SCOPE_LOCK(locker_[target_display]);
1172 }
1173
1174 if (display != target_display) {
1175 // Validate done on a dummy display. Assume present is complete.
1176 SEQUENCE_EXIT_SCOPE_LOCK(locker_[target_display]);
Saurabh Shahc5c687a2017-08-24 16:30:14 -07001177 }
1178
Naseer Ahmedb92e73f2016-03-12 02:03:48 -05001179 return INT32(status);
1180}
1181
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +05301182HWC2::Error HWCSession::CreateVirtualDisplayObj(uint32_t width, uint32_t height, int32_t *format,
1183 hwc2_display_t *out_display_id) {
Ramkumar Radhakrishnan44c64362018-12-12 13:03:59 -08001184 hwc2_display_t active_builtin_disp_id = GetActiveBuiltinDisplay();
Padmanabhan Komanduruf5b7f992019-07-08 13:33:44 +05301185 hwc2_display_t client_id = HWCCallbacks::kNumDisplays;
Padmanabhan Komandurue74cf4f2019-04-25 17:38:43 -07001186 if (active_builtin_disp_id < HWCCallbacks::kNumDisplays) {
Ramkumar Radhakrishnan44c64362018-12-12 13:03:59 -08001187 SEQUENCE_WAIT_SCOPE_LOCK(locker_[active_builtin_disp_id]);
Mathew Joseph Karimpanal71ac8a72018-09-25 22:27:22 +05301188 std::bitset<kSecureMax> secure_sessions = 0;
Ramkumar Radhakrishnan44c64362018-12-12 13:03:59 -08001189 if (hwc_display_[active_builtin_disp_id]) {
1190 hwc_display_[active_builtin_disp_id]->GetActiveSecureSession(&secure_sessions);
1191 }
Mathew Joseph Karimpanal71ac8a72018-09-25 22:27:22 +05301192 if (secure_sessions.any()) {
1193 DLOGE("Secure session is active, cannot create virtual display.");
1194 return HWC2::Error::Unsupported;
1195 } else if (IsPluggableDisplayConnected()) {
1196 DLOGE("External session is active, cannot create virtual display.");
1197 return HWC2::Error::Unsupported;
1198 }
1199 }
1200
Pullakavi Srinivasf2a31852019-04-23 14:32:08 -07001201 if (hwc_display_[HWC_DISPLAY_PRIMARY]) {
1202 DisplayError error = hwc_display_[HWC_DISPLAY_PRIMARY]->TeardownConcurrentWriteback();
1203 if (error) {
1204 return HWC2::Error::NoResources;
1205 }
1206 }
1207
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +05301208 // Lock confined to this scope
1209 int status = -EINVAL;
Pullakavi Srinivasa3c292c2019-12-01 13:27:50 +05301210 for (auto &map_info : map_info_virtual_) {
1211 client_id = map_info.client_id;
1212 {
1213 SCOPE_LOCK(locker_[client_id]);
1214 auto &hwc_display = hwc_display_[client_id];
1215 if (hwc_display) {
1216 continue;
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +05301217 }
Pullakavi Srinivasa3c292c2019-12-01 13:27:50 +05301218
1219 int32_t display_id = GetVirtualDisplayId();
1220 status = virtual_display_factory_.Create(core_intf_, &buffer_allocator_, &callbacks_,
1221 client_id, display_id, width, height,
1222 format, set_min_lum_, set_max_lum_, &hwc_display);
1223 // TODO(user): validate width and height support
1224 if (status) {
1225 return HWC2::Error::NoResources;
1226 }
1227
1228 {
1229 SCOPE_LOCK(hdr_locker_[client_id]);
1230 is_hdr_display_[UINT32(client_id)] = HasHDRSupport(hwc_display);
1231 }
1232
1233 DLOGI("Created virtual display id:% " PRIu64 " with res: %dx%d", client_id, width, height);
1234
1235 *out_display_id = client_id;
1236 map_info.disp_type = kVirtual;
1237 map_info.sdm_id = display_id;
1238 break;
Saurabh Shaha307e8c2017-09-28 18:05:40 -07001239 }
Naseer Ahmedb92e73f2016-03-12 02:03:48 -05001240 }
Saurabh Shaha307e8c2017-09-28 18:05:40 -07001241
Padmanabhan Komanduruf5b7f992019-07-08 13:33:44 +05301242 // Active builtin display needs revalidation
1243 if (!async_vds_creation_ && active_builtin_disp_id < HWCCallbacks::kNumRealDisplays) {
Ramkumar Radhakrishnan44c64362018-12-12 13:03:59 -08001244 SEQUENCE_WAIT_SCOPE_LOCK(locker_[active_builtin_disp_id]);
1245 hwc_display_[active_builtin_disp_id]->ResetValidation();
1246 }
Naseer Ahmedb92e73f2016-03-12 02:03:48 -05001247
1248 return HWC2::Error::None;
1249}
1250
Mathew Joseph Karimpanal71ac8a72018-09-25 22:27:22 +05301251bool HWCSession::IsPluggableDisplayConnected() {
1252 for (auto &map_info : map_info_pluggable_) {
1253 if (hwc_display_[map_info.client_id]) {
1254 return true;
1255 }
1256 }
1257 return false;
Pullakavi Srinivas04e52422018-07-31 15:12:57 +05301258}
1259
Naseer Ahmedb92e73f2016-03-12 02:03:48 -05001260// Qclient methods
1261android::status_t HWCSession::notifyCallback(uint32_t command, const android::Parcel *input_parcel,
1262 android::Parcel *output_parcel) {
Mathew Joseph Karimpanaldbd64f82017-10-06 10:13:38 +05301263 android::status_t status = -EINVAL;
Naseer Ahmedb92e73f2016-03-12 02:03:48 -05001264
1265 switch (command) {
1266 case qService::IQService::DYNAMIC_DEBUG:
Mathew Joseph Karimpanaldbd64f82017-10-06 10:13:38 +05301267 if (!input_parcel) {
1268 DLOGE("QService command = %d: input_parcel needed.", command);
1269 break;
1270 }
1271 status = 0;
Naseer Ahmedb92e73f2016-03-12 02:03:48 -05001272 DynamicDebug(input_parcel);
1273 break;
1274
1275 case qService::IQService::SCREEN_REFRESH:
Dileep Marchya35e27532018-06-29 10:50:16 +05301276 if (!input_parcel) {
1277 DLOGE("QService command = %d: input_parcel needed.", command);
1278 break;
1279 }
1280 status = RefreshScreen(input_parcel);
Naseer Ahmedb92e73f2016-03-12 02:03:48 -05001281 break;
1282
1283 case qService::IQService::SET_IDLE_TIMEOUT:
Mathew Joseph Karimpanaldbd64f82017-10-06 10:13:38 +05301284 if (!input_parcel) {
1285 DLOGE("QService command = %d: input_parcel needed.", command);
1286 break;
1287 }
Padmanabhan Komanduru9e971622020-02-10 13:09:34 +05301288 status = SetIdleTimeout(UINT32(input_parcel->readInt32()));
Naseer Ahmedb92e73f2016-03-12 02:03:48 -05001289 break;
1290
1291 case qService::IQService::SET_FRAME_DUMP_CONFIG:
Mathew Joseph Karimpanaldbd64f82017-10-06 10:13:38 +05301292 if (!input_parcel) {
1293 DLOGE("QService command = %d: input_parcel needed.", command);
1294 break;
1295 }
1296 status = SetFrameDumpConfig(input_parcel);
Naseer Ahmedb92e73f2016-03-12 02:03:48 -05001297 break;
1298
1299 case qService::IQService::SET_MAX_PIPES_PER_MIXER:
Mathew Joseph Karimpanaldbd64f82017-10-06 10:13:38 +05301300 if (!input_parcel) {
1301 DLOGE("QService command = %d: input_parcel needed.", command);
1302 break;
1303 }
Naseer Ahmedb92e73f2016-03-12 02:03:48 -05001304 status = SetMaxMixerStages(input_parcel);
1305 break;
1306
1307 case qService::IQService::SET_DISPLAY_MODE:
Mathew Joseph Karimpanaldbd64f82017-10-06 10:13:38 +05301308 if (!input_parcel) {
1309 DLOGE("QService command = %d: input_parcel needed.", command);
1310 break;
1311 }
Naseer Ahmedb92e73f2016-03-12 02:03:48 -05001312 status = SetDisplayMode(input_parcel);
1313 break;
1314
Dileep Marchya6860b2b2017-04-07 15:56:47 +05301315 case qService::IQService::SET_SECONDARY_DISPLAY_STATUS: {
Mathew Joseph Karimpanaldbd64f82017-10-06 10:13:38 +05301316 if (!input_parcel || !output_parcel) {
1317 DLOGE("QService command = %d: input_parcel and output_parcel needed.", command);
1318 break;
1319 }
Dileep Marchya6860b2b2017-04-07 15:56:47 +05301320 int disp_id = INT(input_parcel->readInt32());
1321 HWCDisplay::DisplayStatus disp_status =
1322 static_cast<HWCDisplay::DisplayStatus>(input_parcel->readInt32());
Padmanabhan Komanduru9e971622020-02-10 13:09:34 +05301323 status = SetDisplayStatus(disp_id, disp_status);
Dileep Marchya6860b2b2017-04-07 15:56:47 +05301324 output_parcel->writeInt32(status);
1325 }
Naseer Ahmedb92e73f2016-03-12 02:03:48 -05001326 break;
1327
1328 case qService::IQService::CONFIGURE_DYN_REFRESH_RATE:
Mathew Joseph Karimpanaldbd64f82017-10-06 10:13:38 +05301329 if (!input_parcel) {
1330 DLOGE("QService command = %d: input_parcel needed.", command);
1331 break;
1332 }
Naseer Ahmedb92e73f2016-03-12 02:03:48 -05001333 status = ConfigureRefreshRate(input_parcel);
1334 break;
1335
Dileep Marchya6860b2b2017-04-07 15:56:47 +05301336 case qService::IQService::TOGGLE_SCREEN_UPDATES: {
Mathew Joseph Karimpanaldbd64f82017-10-06 10:13:38 +05301337 if (!input_parcel || !output_parcel) {
1338 DLOGE("QService command = %d: input_parcel and output_parcel needed.", command);
1339 break;
1340 }
Dileep Marchya6860b2b2017-04-07 15:56:47 +05301341 int32_t input = input_parcel->readInt32();
Padmanabhan Komanduru9e971622020-02-10 13:09:34 +05301342 status = ToggleScreenUpdate(input == 1);
Dileep Marchya6860b2b2017-04-07 15:56:47 +05301343 output_parcel->writeInt32(status);
1344 }
Naseer Ahmedb92e73f2016-03-12 02:03:48 -05001345 break;
1346
1347 case qService::IQService::QDCM_SVC_CMDS:
Mathew Joseph Karimpanaldbd64f82017-10-06 10:13:38 +05301348 if (!input_parcel || !output_parcel) {
1349 DLOGE("QService command = %d: input_parcel and output_parcel needed.", command);
1350 break;
1351 }
Naseer Ahmedb92e73f2016-03-12 02:03:48 -05001352 status = QdcmCMDHandler(input_parcel, output_parcel);
1353 break;
1354
Dileep Marchya6860b2b2017-04-07 15:56:47 +05301355 case qService::IQService::MIN_HDCP_ENCRYPTION_LEVEL_CHANGED: {
Mathew Joseph Karimpanaldbd64f82017-10-06 10:13:38 +05301356 if (!input_parcel || !output_parcel) {
1357 DLOGE("QService command = %d: input_parcel and output_parcel needed.", command);
1358 break;
1359 }
Dileep Marchya6860b2b2017-04-07 15:56:47 +05301360 int disp_id = input_parcel->readInt32();
1361 uint32_t min_enc_level = UINT32(input_parcel->readInt32());
1362 status = MinHdcpEncryptionLevelChanged(disp_id, min_enc_level);
1363 output_parcel->writeInt32(status);
1364 }
Naseer Ahmedb92e73f2016-03-12 02:03:48 -05001365 break;
1366
Dileep Marchya6860b2b2017-04-07 15:56:47 +05301367 case qService::IQService::CONTROL_PARTIAL_UPDATE: {
Mathew Joseph Karimpanaldbd64f82017-10-06 10:13:38 +05301368 if (!input_parcel || !output_parcel) {
1369 DLOGE("QService command = %d: input_parcel and output_parcel needed.", command);
1370 break;
1371 }
Dileep Marchya6860b2b2017-04-07 15:56:47 +05301372 int disp_id = input_parcel->readInt32();
1373 uint32_t enable = UINT32(input_parcel->readInt32());
1374 status = ControlPartialUpdate(disp_id, enable == 1);
1375 output_parcel->writeInt32(status);
1376 }
Naseer Ahmedb92e73f2016-03-12 02:03:48 -05001377 break;
1378
Dileep Marchya6860b2b2017-04-07 15:56:47 +05301379 case qService::IQService::SET_ACTIVE_CONFIG: {
Mathew Joseph Karimpanaldbd64f82017-10-06 10:13:38 +05301380 if (!input_parcel) {
1381 DLOGE("QService command = %d: input_parcel needed.", command);
1382 break;
1383 }
Dileep Marchya6860b2b2017-04-07 15:56:47 +05301384 uint32_t config = UINT32(input_parcel->readInt32());
1385 int disp_id = input_parcel->readInt32();
1386 status = SetActiveConfigIndex(disp_id, config);
1387 }
Naseer Ahmedb92e73f2016-03-12 02:03:48 -05001388 break;
1389
Dileep Marchya6860b2b2017-04-07 15:56:47 +05301390 case qService::IQService::GET_ACTIVE_CONFIG: {
Mathew Joseph Karimpanaldbd64f82017-10-06 10:13:38 +05301391 if (!input_parcel || !output_parcel) {
1392 DLOGE("QService command = %d: input_parcel and output_parcel needed.", command);
1393 break;
1394 }
Dileep Marchya6860b2b2017-04-07 15:56:47 +05301395 int disp_id = input_parcel->readInt32();
1396 uint32_t config = 0;
1397 status = GetActiveConfigIndex(disp_id, &config);
1398 output_parcel->writeInt32(INT(config));
1399 }
Naseer Ahmedb92e73f2016-03-12 02:03:48 -05001400 break;
1401
Dileep Marchya6860b2b2017-04-07 15:56:47 +05301402 case qService::IQService::GET_CONFIG_COUNT: {
Mathew Joseph Karimpanaldbd64f82017-10-06 10:13:38 +05301403 if (!input_parcel || !output_parcel) {
1404 DLOGE("QService command = %d: input_parcel and output_parcel needed.", command);
1405 break;
1406 }
Dileep Marchya6860b2b2017-04-07 15:56:47 +05301407 int disp_id = input_parcel->readInt32();
1408 uint32_t count = 0;
1409 status = GetConfigCount(disp_id, &count);
1410 output_parcel->writeInt32(INT(count));
1411 }
Naseer Ahmedb92e73f2016-03-12 02:03:48 -05001412 break;
1413
1414 case qService::IQService::GET_DISPLAY_ATTRIBUTES_FOR_CONFIG:
Mathew Joseph Karimpanaldbd64f82017-10-06 10:13:38 +05301415 if (!input_parcel || !output_parcel) {
1416 DLOGE("QService command = %d: input_parcel and output_parcel needed.", command);
1417 break;
1418 }
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +05301419 status = GetDisplayAttributesForConfig(input_parcel, output_parcel);
Naseer Ahmedb92e73f2016-03-12 02:03:48 -05001420 break;
1421
Dileep Marchya6860b2b2017-04-07 15:56:47 +05301422 case qService::IQService::GET_PANEL_BRIGHTNESS: {
Mathew Joseph Karimpanaldbd64f82017-10-06 10:13:38 +05301423 if (!output_parcel) {
1424 DLOGE("QService command = %d: output_parcel needed.", command);
1425 break;
1426 }
Yuchao Maada1c402019-11-12 14:47:11 +08001427
Varun Arora75c05f02019-05-14 14:53:37 -07001428 uint32_t display = input_parcel->readUint32();
Yuchao Maada1c402019-11-12 14:47:11 +08001429 uint32_t max_brightness_level = 0;
1430 status = getDisplayMaxBrightness(display, &max_brightness_level);
1431 if (status || !max_brightness_level) {
1432 output_parcel->writeInt32(max_brightness_level);
1433 DLOGE("Failed to get max brightness %u, status %d", max_brightness_level, status);
1434 break;
1435 }
1436 DLOGV("Panel Max brightness is %u", max_brightness_level);
1437
1438 float brightness_precent = -1.0f;
1439 status = getDisplayBrightness(display, &brightness_precent);
1440 if (brightness_precent == -1.0f) {
Varun Arora75c05f02019-05-14 14:53:37 -07001441 output_parcel->writeInt32(0);
1442 } else {
Yuchao Maada1c402019-11-12 14:47:11 +08001443 output_parcel->writeInt32(INT32(brightness_precent*(max_brightness_level - 1) + 1));
Varun Arora75c05f02019-05-14 14:53:37 -07001444 }
Dileep Marchya6860b2b2017-04-07 15:56:47 +05301445 }
Naseer Ahmedb92e73f2016-03-12 02:03:48 -05001446 break;
1447
Dileep Marchya6860b2b2017-04-07 15:56:47 +05301448 case qService::IQService::SET_PANEL_BRIGHTNESS: {
Mathew Joseph Karimpanaldbd64f82017-10-06 10:13:38 +05301449 if (!input_parcel || !output_parcel) {
1450 DLOGE("QService command = %d: input_parcel and output_parcel needed.", command);
1451 break;
1452 }
Yuchao Maada1c402019-11-12 14:47:11 +08001453
1454 uint32_t max_brightness_level = 0;
1455 uint32_t display = HWC_DISPLAY_PRIMARY;
1456 status = getDisplayMaxBrightness(display, &max_brightness_level);
1457 if (status || max_brightness_level <= 1) {
1458 output_parcel->writeInt32(max_brightness_level);
1459 DLOGE("Failed to get max brightness %u, status %d", max_brightness_level, status);
1460 break;
1461 }
1462 DLOGV("Panel Max brightness is %u", max_brightness_level);
1463
Varun Arora75c05f02019-05-14 14:53:37 -07001464 int level = input_parcel->readInt32();
Varun Arora75c05f02019-05-14 14:53:37 -07001465 if (level == 0) {
Yuchao Maada1c402019-11-12 14:47:11 +08001466 status = SetDisplayBrightness(display, -1.0f);
Varun Arora75c05f02019-05-14 14:53:37 -07001467 } else {
Yuchao Maada1c402019-11-12 14:47:11 +08001468 status = SetDisplayBrightness(display,
1469 (level - 1)/(static_cast<float>(max_brightness_level - 1)));
Varun Arora75c05f02019-05-14 14:53:37 -07001470 }
Dileep Marchya6860b2b2017-04-07 15:56:47 +05301471 output_parcel->writeInt32(status);
1472 }
Naseer Ahmedb92e73f2016-03-12 02:03:48 -05001473 break;
1474
1475 case qService::IQService::GET_DISPLAY_VISIBLE_REGION:
Mathew Joseph Karimpanaldbd64f82017-10-06 10:13:38 +05301476 if (!input_parcel || !output_parcel) {
1477 DLOGE("QService command = %d: input_parcel and output_parcel needed.", command);
1478 break;
1479 }
Naseer Ahmedb92e73f2016-03-12 02:03:48 -05001480 status = GetVisibleDisplayRect(input_parcel, output_parcel);
1481 break;
1482
Dileep Marchya6860b2b2017-04-07 15:56:47 +05301483 case qService::IQService::SET_CAMERA_STATUS: {
Mathew Joseph Karimpanaldbd64f82017-10-06 10:13:38 +05301484 if (!input_parcel) {
1485 DLOGE("QService command = %d: input_parcel needed.", command);
1486 break;
1487 }
Dileep Marchya6860b2b2017-04-07 15:56:47 +05301488 uint32_t camera_status = UINT32(input_parcel->readInt32());
Padmanabhan Komanduru9e971622020-02-10 13:09:34 +05301489 status = SetCameraLaunchStatus(camera_status);
Dileep Marchya6860b2b2017-04-07 15:56:47 +05301490 }
Naseer Ahmedb92e73f2016-03-12 02:03:48 -05001491 break;
1492
Dileep Marchya6860b2b2017-04-07 15:56:47 +05301493 case qService::IQService::GET_BW_TRANSACTION_STATUS: {
Mathew Joseph Karimpanaldbd64f82017-10-06 10:13:38 +05301494 if (!output_parcel) {
1495 DLOGE("QService command = %d: output_parcel needed.", command);
1496 break;
1497 }
Dileep Marchya6860b2b2017-04-07 15:56:47 +05301498 bool state = true;
1499 status = DisplayBWTransactionPending(&state);
1500 output_parcel->writeInt32(state);
1501 }
Naseer Ahmedb92e73f2016-03-12 02:03:48 -05001502 break;
1503
Naseer Ahmedad495442016-06-27 14:59:18 -04001504 case qService::IQService::SET_LAYER_MIXER_RESOLUTION:
Mathew Joseph Karimpanaldbd64f82017-10-06 10:13:38 +05301505 if (!input_parcel) {
1506 DLOGE("QService command = %d: input_parcel needed.", command);
1507 break;
1508 }
Naseer Ahmedad495442016-06-27 14:59:18 -04001509 status = SetMixerResolution(input_parcel);
1510 break;
1511
1512 case qService::IQService::SET_COLOR_MODE:
Mathew Joseph Karimpanaldbd64f82017-10-06 10:13:38 +05301513 if (!input_parcel) {
1514 DLOGE("QService command = %d: input_parcel needed.", command);
1515 break;
1516 }
Naseer Ahmedad495442016-06-27 14:59:18 -04001517 status = SetColorModeOverride(input_parcel);
1518 break;
Arun Kumar K.R8da7f502016-06-07 17:45:50 -07001519
Naseer Ahmede7a77982018-06-04 10:56:04 -04001520 case qService::IQService::SET_COLOR_MODE_WITH_RENDER_INTENT:
1521 if (!input_parcel) {
1522 DLOGE("QService command = %d: input_parcel needed.", command);
1523 break;
1524 }
1525 status = SetColorModeWithRenderIntentOverride(input_parcel);
1526 break;
1527
Naseer Ahmed6776dae2017-05-09 11:49:41 -04001528 case qService::IQService::SET_COLOR_MODE_BY_ID:
Mathew Joseph Karimpanaldbd64f82017-10-06 10:13:38 +05301529 if (!input_parcel) {
1530 DLOGE("QService command = %d: input_parcel needed.", command);
1531 break;
1532 }
Naseer Ahmed6776dae2017-05-09 11:49:41 -04001533 status = SetColorModeById(input_parcel);
1534 break;
1535
Prabhanjan Kandula63a613f2017-09-14 19:29:46 -07001536 case qService::IQService::GET_COMPOSER_STATUS:
Mathew Joseph Karimpanaldbd64f82017-10-06 10:13:38 +05301537 if (!output_parcel) {
1538 DLOGE("QService command = %d: output_parcel needed.", command);
1539 break;
1540 }
1541 status = 0;
Prabhanjan Kandula63a613f2017-09-14 19:29:46 -07001542 output_parcel->writeInt32(getComposerStatus());
1543 break;
1544
Sushil Chauhan380a59d2018-03-19 15:47:50 -07001545 case qService::IQService::SET_QSYNC_MODE:
1546 if (!input_parcel) {
1547 DLOGE("QService command = %d: input_parcel needed.", command);
1548 break;
1549 }
1550 status = SetQSyncMode(input_parcel);
1551 break;
1552
Lakshmi Narayana Kalavala25fe12c2019-12-11 20:44:55 -08001553 case qService::IQService::SET_COLOR_SAMPLING_ENABLED:
1554 if (!input_parcel) {
1555 DLOGE("QService command = %d: input_parcel needed.", command);
1556 break;
1557 }
1558 status = setColorSamplingEnabled(input_parcel);
1559 break;
1560
Ramkumar Radhakrishnanf985d482018-07-23 18:10:41 -07001561 case qService::IQService::SET_IDLE_PC:
1562 if (!input_parcel) {
1563 DLOGE("QService command = %d: input_parcel needed.", command);
1564 break;
1565 }
1566 status = SetIdlePC(input_parcel);
1567 break;
1568
Yuchao Ma577f0f72018-07-09 11:20:00 +08001569 case qService::IQService::SET_DPPS_AD4_ROI_CONFIG:
1570 if (!input_parcel) {
1571 DLOGE("QService command = %d: input_parcel needed.", command);
1572 break;
1573 }
1574 status = SetAd4RoiConfig(input_parcel);
1575 break;
1576
Pullakavi Srinivas9189e602018-12-19 16:58:07 +05301577 case qService::IQService::SET_DSI_CLK:
1578 if (!input_parcel) {
1579 DLOGE("QService command = %d: input_parcel needed.", command);
1580 break;
1581 }
1582 status = SetDsiClk(input_parcel);
1583 break;
1584
1585 case qService::IQService::GET_DSI_CLK:
1586 if (!input_parcel || !output_parcel) {
1587 DLOGE("QService command = %d: input_parcel and output_parcel needed.", command);
1588 break;
1589 }
1590 status = GetDsiClk(input_parcel, output_parcel);
1591 break;
1592
1593 case qService::IQService::GET_SUPPORTED_DSI_CLK:
1594 if (!input_parcel || !output_parcel) {
1595 DLOGE("QService command = %d: input_parcel and output_parcel needed.", command);
1596 break;
1597 }
1598 status = GetSupportedDsiClk(input_parcel, output_parcel);
1599 break;
1600
Archit Srivastavaa59c4ff2019-05-20 10:54:22 +05301601 case qService::IQService::SET_PANEL_LUMINANCE:
1602 if (!input_parcel) {
1603 DLOGE("QService command = %d: input_parcel needed.", command);
1604 break;
1605 }
1606 status = SetPanelLuminanceAttributes(input_parcel);
1607 break;
1608
Qing Huangda3a91d2019-01-15 14:34:11 +08001609 case qService::IQService::SET_COLOR_MODE_FROM_CLIENT:
1610 if (!input_parcel) {
1611 DLOGE("QService command = %d: input_parcel needed.", command);
1612 break;
1613 }
1614 status = SetColorModeFromClient(input_parcel);
1615 break;
1616
Xu Yang9dacc872018-12-25 11:04:28 +08001617 case qService::IQService::SET_FRAME_TRIGGER_MODE:
1618 if (!input_parcel) {
1619 DLOGE("QService command = %d: input_parcel needed.", command);
1620 break;
1621 }
1622 status = SetFrameTriggerMode(input_parcel);
1623 break;
1624
Xu Yang45d0abf2019-07-05 11:34:06 +08001625 case qService::IQService::SET_BRIGHTNESS_SCALE:
1626 if (!input_parcel) {
1627 DLOGE("QService command = %d: input_parcel needed.", command);
1628 break;
1629 }
1630 status = SetDisplayBrightnessScale(input_parcel);
1631 break;
1632
Naseer Ahmedb92e73f2016-03-12 02:03:48 -05001633 default:
Mathew Joseph Karimpanaldbd64f82017-10-06 10:13:38 +05301634 DLOGW("QService command = %d is not supported.", command);
1635 break;
Naseer Ahmedb92e73f2016-03-12 02:03:48 -05001636 }
1637
1638 return status;
1639}
1640
Prabhanjan Kandula63a613f2017-09-14 19:29:46 -07001641android::status_t HWCSession::getComposerStatus() {
1642 return is_composer_up_;
1643}
1644
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +05301645android::status_t HWCSession::GetDisplayAttributesForConfig(const android::Parcel *input_parcel,
1646 android::Parcel *output_parcel) {
Naseer Ahmedb92e73f2016-03-12 02:03:48 -05001647 int config = input_parcel->readInt32();
1648 int dpy = input_parcel->readInt32();
1649 int error = android::BAD_VALUE;
Arun Kumar K.R8da7f502016-06-07 17:45:50 -07001650 DisplayConfigVariableInfo display_attributes;
Naseer Ahmedb92e73f2016-03-12 02:03:48 -05001651
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +05301652 int disp_idx = GetDisplayIndex(dpy);
1653 if (disp_idx == -1 || config < 0) {
1654 DLOGE("Invalid display = %d, or config = %d", dpy, config);
Naseer Ahmedb92e73f2016-03-12 02:03:48 -05001655 return android::BAD_VALUE;
1656 }
1657
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +05301658 SEQUENCE_WAIT_SCOPE_LOCK(locker_[disp_idx]);
1659 if (hwc_display_[disp_idx]) {
1660 error = hwc_display_[disp_idx]->GetDisplayAttributesForConfig(config, &display_attributes);
Naseer Ahmedb92e73f2016-03-12 02:03:48 -05001661 if (error == 0) {
Arun Kumar K.R8da7f502016-06-07 17:45:50 -07001662 output_parcel->writeInt32(INT(display_attributes.vsync_period_ns));
1663 output_parcel->writeInt32(INT(display_attributes.x_pixels));
1664 output_parcel->writeInt32(INT(display_attributes.y_pixels));
1665 output_parcel->writeFloat(display_attributes.x_dpi);
1666 output_parcel->writeFloat(display_attributes.y_dpi);
Naseer Ahmedb92e73f2016-03-12 02:03:48 -05001667 output_parcel->writeInt32(0); // Panel type, unsupported.
1668 }
1669 }
1670
1671 return error;
1672}
1673
Lakshmi Narayana Kalavala25fe12c2019-12-11 20:44:55 -08001674android::status_t HWCSession::setColorSamplingEnabled(const android::Parcel *input_parcel) {
1675 int dpy = input_parcel->readInt32();
1676 int enabled_cmd = input_parcel->readInt32();
1677 if (dpy < HWC_DISPLAY_PRIMARY || dpy >= HWC_NUM_DISPLAY_TYPES || enabled_cmd < 0 ||
1678 enabled_cmd > 1) {
1679 return android::BAD_VALUE;
1680 }
1681
1682 SEQUENCE_WAIT_SCOPE_LOCK(locker_[dpy]);
1683 if (!hwc_display_[dpy]) {
1684 DLOGW("No display id %i active to enable histogram event", dpy);
1685 return android::BAD_VALUE;
1686 }
1687
1688 auto error = hwc_display_[dpy]->SetDisplayedContentSamplingEnabledVndService(enabled_cmd);
1689 return (error == HWC2::Error::None) ? android::OK : android::BAD_VALUE;
1690}
1691
Naseer Ahmedb92e73f2016-03-12 02:03:48 -05001692android::status_t HWCSession::ConfigureRefreshRate(const android::Parcel *input_parcel) {
Saurabh Shahc5c687a2017-08-24 16:30:14 -07001693 SEQUENCE_WAIT_SCOPE_LOCK(locker_[HWC_DISPLAY_PRIMARY]);
Dileep Marchya6860b2b2017-04-07 15:56:47 +05301694
Naseer Ahmedb92e73f2016-03-12 02:03:48 -05001695 uint32_t operation = UINT32(input_parcel->readInt32());
Dileep Marchya6860b2b2017-04-07 15:56:47 +05301696 HWCDisplay *hwc_display = hwc_display_[HWC_DISPLAY_PRIMARY];
1697
Mathew Joseph Karimpanaldbd64f82017-10-06 10:13:38 +05301698 if (!hwc_display) {
1699 DLOGW("Display = %d is not connected.", HWC_DISPLAY_PRIMARY);
1700 return -ENODEV;
1701 }
1702
Naseer Ahmedb92e73f2016-03-12 02:03:48 -05001703 switch (operation) {
1704 case qdutils::DISABLE_METADATA_DYN_REFRESH_RATE:
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +05301705 return hwc_display->Perform(HWCDisplayBuiltIn::SET_METADATA_DYN_REFRESH_RATE, false);
Dileep Marchya6860b2b2017-04-07 15:56:47 +05301706
Naseer Ahmedb92e73f2016-03-12 02:03:48 -05001707 case qdutils::ENABLE_METADATA_DYN_REFRESH_RATE:
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +05301708 return hwc_display->Perform(HWCDisplayBuiltIn::SET_METADATA_DYN_REFRESH_RATE, true);
Dileep Marchya6860b2b2017-04-07 15:56:47 +05301709
Naseer Ahmedb92e73f2016-03-12 02:03:48 -05001710 case qdutils::SET_BINDER_DYN_REFRESH_RATE: {
1711 uint32_t refresh_rate = UINT32(input_parcel->readInt32());
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +05301712 return hwc_display->Perform(HWCDisplayBuiltIn::SET_BINDER_DYN_REFRESH_RATE, refresh_rate);
Naseer Ahmedb92e73f2016-03-12 02:03:48 -05001713 }
Dileep Marchya6860b2b2017-04-07 15:56:47 +05301714
Naseer Ahmedb92e73f2016-03-12 02:03:48 -05001715 default:
1716 DLOGW("Invalid operation %d", operation);
1717 return -EINVAL;
1718 }
1719
1720 return 0;
1721}
1722
1723android::status_t HWCSession::SetDisplayMode(const android::Parcel *input_parcel) {
Saurabh Shahc5c687a2017-08-24 16:30:14 -07001724 SEQUENCE_WAIT_SCOPE_LOCK(locker_[HWC_DISPLAY_PRIMARY]);
Dileep Marchya6860b2b2017-04-07 15:56:47 +05301725
Mathew Joseph Karimpanaldbd64f82017-10-06 10:13:38 +05301726 if (!hwc_display_[HWC_DISPLAY_PRIMARY]) {
1727 DLOGW("Display = %d is not connected.", HWC_DISPLAY_PRIMARY);
1728 return -ENODEV;
1729 }
1730
Naseer Ahmedb92e73f2016-03-12 02:03:48 -05001731 uint32_t mode = UINT32(input_parcel->readInt32());
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +05301732 return hwc_display_[HWC_DISPLAY_PRIMARY]->Perform(HWCDisplayBuiltIn::SET_DISPLAY_MODE, mode);
Naseer Ahmedb92e73f2016-03-12 02:03:48 -05001733}
1734
1735android::status_t HWCSession::SetMaxMixerStages(const android::Parcel *input_parcel) {
1736 DisplayError error = kErrorNone;
Dileep Marchya7290bd22016-06-09 11:37:20 +05301737 std::bitset<32> bit_mask_display_type = UINT32(input_parcel->readInt32());
Naseer Ahmedb92e73f2016-03-12 02:03:48 -05001738 uint32_t max_mixer_stages = UINT32(input_parcel->readInt32());
Mathew Joseph Karimpanaldbd64f82017-10-06 10:13:38 +05301739 android::status_t status = 0;
Naseer Ahmedb92e73f2016-03-12 02:03:48 -05001740
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +05301741 for (uint32_t i = 0; i < 32 && bit_mask_display_type[i]; i++) {
1742 int disp_idx = GetDisplayIndex(INT(i));
1743 if (disp_idx == -1) {
1744 continue;
1745 }
1746 SEQUENCE_WAIT_SCOPE_LOCK(locker_[disp_idx]);
1747 auto &hwc_display = hwc_display_[disp_idx];
1748 if (!hwc_display) {
1749 DLOGW("Display = %d is not connected.", disp_idx);
1750 status = (status)? status : -ENODEV; // Return higher priority error.
1751 continue;
1752 }
1753
1754 error = hwc_display->SetMaxMixerStages(max_mixer_stages);
1755 if (error != kErrorNone) {
1756 status = -EINVAL;
Naseer Ahmedb92e73f2016-03-12 02:03:48 -05001757 }
1758 }
1759
Mathew Joseph Karimpanaldbd64f82017-10-06 10:13:38 +05301760 return status;
Naseer Ahmedb92e73f2016-03-12 02:03:48 -05001761}
1762
Mathew Joseph Karimpanaldbd64f82017-10-06 10:13:38 +05301763android::status_t HWCSession::SetFrameDumpConfig(const android::Parcel *input_parcel) {
Naseer Ahmedb92e73f2016-03-12 02:03:48 -05001764 uint32_t frame_dump_count = UINT32(input_parcel->readInt32());
Dileep Marchya7290bd22016-06-09 11:37:20 +05301765 std::bitset<32> bit_mask_display_type = UINT32(input_parcel->readInt32());
Naseer Ahmedb92e73f2016-03-12 02:03:48 -05001766 uint32_t bit_mask_layer_type = UINT32(input_parcel->readInt32());
Sushil Chauhan267a6192018-06-06 18:41:47 -07001767 int32_t output_format = HAL_PIXEL_FORMAT_RGB_888;
1768 bool post_processed = true;
1769
Sushil Chauhan0a1b15d2019-08-23 12:58:18 -07001770 // Output buffer dump is not supported, if External or Virtual display is present.
1771 bool output_buffer_dump = bit_mask_layer_type & (1 << OUTPUT_LAYER_DUMP);
1772 if (output_buffer_dump) {
1773 int external_dpy_index = GetDisplayIndex(qdutils::DISPLAY_EXTERNAL);
1774 int virtual_dpy_index = GetDisplayIndex(qdutils::DISPLAY_VIRTUAL);
1775 if (((external_dpy_index != -1) && hwc_display_[external_dpy_index]) ||
1776 ((virtual_dpy_index != -1) && hwc_display_[virtual_dpy_index])) {
1777 DLOGW("Output buffer dump is not supported with External or Virtual display!");
1778 return -EINVAL;
1779 }
1780 }
1781
Sushil Chauhan267a6192018-06-06 18:41:47 -07001782 // Read optional user preferences: output_format and post_processed.
1783 if (input_parcel->dataPosition() != input_parcel->dataSize()) {
1784 // HAL Pixel Format for output buffer
1785 output_format = input_parcel->readInt32();
1786 }
1787 if (input_parcel->dataPosition() != input_parcel->dataSize()) {
1788 // Option to dump Layer Mixer output (0) or DSPP output (1)
1789 post_processed = (input_parcel->readInt32() != 0);
1790 }
1791
Mathew Joseph Karimpanaldbd64f82017-10-06 10:13:38 +05301792 android::status_t status = 0;
Naseer Ahmedb92e73f2016-03-12 02:03:48 -05001793
Mathew Joseph Karimpanal0a2fff52018-10-17 12:11:07 +05301794 for (uint32_t i = 0; i < bit_mask_display_type.size(); i++) {
1795 if (!bit_mask_display_type[i]) {
1796 continue;
1797 }
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +05301798 int disp_idx = GetDisplayIndex(INT(i));
1799 if (disp_idx == -1) {
1800 continue;
1801 }
1802 SEQUENCE_WAIT_SCOPE_LOCK(locker_[disp_idx]);
1803 auto &hwc_display = hwc_display_[disp_idx];
1804 if (!hwc_display) {
1805 DLOGW("Display = %d is not connected.", disp_idx);
1806 status = (status)? status : -ENODEV; // Return higher priority error.
1807 continue;
1808 }
1809
Sushil Chauhan267a6192018-06-06 18:41:47 -07001810 HWC2::Error error = hwc_display->SetFrameDumpConfig(frame_dump_count, bit_mask_layer_type,
1811 output_format, post_processed);
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +05301812 if (error != HWC2::Error::None) {
1813 status = (HWC2::Error::NoResources == error) ? -ENOMEM : -EINVAL;
Naseer Ahmedb92e73f2016-03-12 02:03:48 -05001814 }
1815 }
1816
Mathew Joseph Karimpanaldbd64f82017-10-06 10:13:38 +05301817 return status;
Naseer Ahmedb92e73f2016-03-12 02:03:48 -05001818}
1819
Arun Kumar K.R8da7f502016-06-07 17:45:50 -07001820android::status_t HWCSession::SetMixerResolution(const android::Parcel *input_parcel) {
1821 DisplayError error = kErrorNone;
1822 uint32_t dpy = UINT32(input_parcel->readInt32());
1823
1824 if (dpy != HWC_DISPLAY_PRIMARY) {
Mathew Joseph Karimpanaldbd64f82017-10-06 10:13:38 +05301825 DLOGW("Resolution change not supported for this display = %d", dpy);
Arun Kumar K.R8da7f502016-06-07 17:45:50 -07001826 return -EINVAL;
1827 }
1828
Saurabh Shahc5c687a2017-08-24 16:30:14 -07001829 SEQUENCE_WAIT_SCOPE_LOCK(locker_[HWC_DISPLAY_PRIMARY]);
Arun Kumar K.R8da7f502016-06-07 17:45:50 -07001830 if (!hwc_display_[HWC_DISPLAY_PRIMARY]) {
Mathew Joseph Karimpanaldbd64f82017-10-06 10:13:38 +05301831 DLOGW("Primary display is not initialized");
1832 return -ENODEV;
Arun Kumar K.R8da7f502016-06-07 17:45:50 -07001833 }
1834
1835 uint32_t width = UINT32(input_parcel->readInt32());
1836 uint32_t height = UINT32(input_parcel->readInt32());
1837
1838 error = hwc_display_[HWC_DISPLAY_PRIMARY]->SetMixerResolution(width, height);
1839 if (error != kErrorNone) {
1840 return -EINVAL;
1841 }
1842
1843 return 0;
1844}
1845
Naseer Ahmedad495442016-06-27 14:59:18 -04001846android::status_t HWCSession::SetColorModeOverride(const android::Parcel *input_parcel) {
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +05301847 int display = static_cast<int>(input_parcel->readInt32());
Naseer Ahmede7a77982018-06-04 10:56:04 -04001848 auto mode = static_cast<ColorMode>(input_parcel->readInt32());
Saurabh Shahc5c687a2017-08-24 16:30:14 -07001849
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +05301850 int disp_idx = GetDisplayIndex(display);
1851 if (disp_idx == -1) {
1852 DLOGE("Invalid display = %d", display);
1853 return -EINVAL;
1854 }
1855
Gousemoodhin Nadaf0e566872019-05-13 16:14:54 +05301856 if (mode < ColorMode::NATIVE || mode > ColorMode::DISPLAY_BT2020) {
Gurpreet Singh Dhamiec0fa512018-08-29 16:51:26 -04001857 DLOGE("Invalid ColorMode: %d", mode);
1858 return HWC2_ERROR_BAD_PARAMETER;
1859 }
Rajavenu Kyatham42d11cb2019-04-16 13:03:29 +05301860 auto err = CallDisplayFunction(static_cast<hwc2_display_t>(disp_idx), &HWCDisplay::SetColorMode,
1861 mode);
Naseer Ahmedad495442016-06-27 14:59:18 -04001862 if (err != HWC2_ERROR_NONE)
1863 return -EINVAL;
Saurabh Shah04f932b2017-10-12 18:47:45 -07001864
Naseer Ahmedad495442016-06-27 14:59:18 -04001865 return 0;
1866}
1867
Yuchao Ma577f0f72018-07-09 11:20:00 +08001868android::status_t HWCSession::SetAd4RoiConfig(const android::Parcel *input_parcel) {
1869 auto display_id = static_cast<uint32_t>(input_parcel->readInt32());
1870 auto h_s = static_cast<uint32_t>(input_parcel->readInt32());
1871 auto h_e = static_cast<uint32_t>(input_parcel->readInt32());
1872 auto v_s = static_cast<uint32_t>(input_parcel->readInt32());
1873 auto v_e = static_cast<uint32_t>(input_parcel->readInt32());
1874 auto f_in = static_cast<uint32_t>(input_parcel->readInt32());
1875 auto f_out = static_cast<uint32_t>(input_parcel->readInt32());
1876
Padmanabhan Komanduru9e971622020-02-10 13:09:34 +05301877 return static_cast<android::status_t>(SetDisplayDppsAdROI(display_id, h_s, h_e, v_s,
1878 v_e, f_in, f_out));
Yuchao Ma577f0f72018-07-09 11:20:00 +08001879}
1880
Xu Yang9dacc872018-12-25 11:04:28 +08001881android::status_t HWCSession::SetFrameTriggerMode(const android::Parcel *input_parcel) {
1882 auto display_id = static_cast<int>(input_parcel->readInt32());
1883 auto mode = static_cast<uint32_t>(input_parcel->readInt32());
1884
1885 int disp_idx = GetDisplayIndex(display_id);
1886 if (disp_idx == -1) {
1887 DLOGE("Invalid display = %d", display_id);
1888 return -EINVAL;
1889 }
1890
Rajavenu Kyatham42d11cb2019-04-16 13:03:29 +05301891 auto err = CallDisplayFunction(static_cast<hwc2_display_t>(disp_idx),
Xu Yang9dacc872018-12-25 11:04:28 +08001892 &HWCDisplay::SetFrameTriggerMode, mode);
1893 if (err != HWC2_ERROR_NONE)
1894 return -EINVAL;
1895
1896 return 0;
1897}
1898
Naseer Ahmede7a77982018-06-04 10:56:04 -04001899android::status_t HWCSession::SetColorModeWithRenderIntentOverride(
1900 const android::Parcel *input_parcel) {
1901 auto display = static_cast<hwc2_display_t>(input_parcel->readInt32());
1902 auto mode = static_cast<ColorMode>(input_parcel->readInt32());
Xu Yang47f44092019-02-13 14:09:53 +08001903 auto int_intent = static_cast<int>(input_parcel->readInt32());
Naseer Ahmede7a77982018-06-04 10:56:04 -04001904
Gousemoodhin Nadaf0e566872019-05-13 16:14:54 +05301905 if (mode < ColorMode::NATIVE || mode > ColorMode::DISPLAY_BT2020) {
Gurpreet Singh Dhamiec0fa512018-08-29 16:51:26 -04001906 DLOGE("Invalid ColorMode: %d", mode);
1907 return HWC2_ERROR_BAD_PARAMETER;
1908 }
1909
Xu Yang47f44092019-02-13 14:09:53 +08001910 if ((int_intent < 0) || (int_intent > MAX_EXTENDED_RENDER_INTENT)) {
1911 DLOGE("Invalid RenderIntent: %d", int_intent);
Gurpreet Singh Dhamiec0fa512018-08-29 16:51:26 -04001912 return HWC2_ERROR_BAD_PARAMETER;
1913 }
1914
Xu Yang47f44092019-02-13 14:09:53 +08001915 auto intent = static_cast<RenderIntent>(int_intent);
Naseer Ahmede7a77982018-06-04 10:56:04 -04001916 auto err =
Rajavenu Kyatham42d11cb2019-04-16 13:03:29 +05301917 CallDisplayFunction(display, &HWCDisplay::SetColorModeWithRenderIntent, mode, intent);
Naseer Ahmede7a77982018-06-04 10:56:04 -04001918 if (err != HWC2_ERROR_NONE)
1919 return -EINVAL;
1920
1921 return 0;
1922}
Naseer Ahmed6776dae2017-05-09 11:49:41 -04001923android::status_t HWCSession::SetColorModeById(const android::Parcel *input_parcel) {
Dileep Marchya35e27532018-06-29 10:50:16 +05301924 int display = input_parcel->readInt32();
Naseer Ahmed6776dae2017-05-09 11:49:41 -04001925 auto mode = input_parcel->readInt32();
Naseer Ahmedab768202017-07-20 12:20:27 -04001926
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +05301927 int disp_idx = GetDisplayIndex(display);
1928 if (disp_idx == -1) {
1929 DLOGE("Invalid display = %d", display);
1930 return -EINVAL;
1931 }
1932
Rajavenu Kyatham42d11cb2019-04-16 13:03:29 +05301933 auto err = CallDisplayFunction(static_cast<hwc2_display_t>(disp_idx),
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +05301934 &HWCDisplay::SetColorModeById, mode);
Naseer Ahmed6776dae2017-05-09 11:49:41 -04001935 if (err != HWC2_ERROR_NONE)
1936 return -EINVAL;
Saurabh Shah04f932b2017-10-12 18:47:45 -07001937
Naseer Ahmed6776dae2017-05-09 11:49:41 -04001938 return 0;
1939}
1940
Qing Huangda3a91d2019-01-15 14:34:11 +08001941android::status_t HWCSession::SetColorModeFromClient(const android::Parcel *input_parcel) {
1942 int display = input_parcel->readInt32();
1943 auto mode = input_parcel->readInt32();
Qing Huangda3a91d2019-01-15 14:34:11 +08001944
1945 int disp_idx = GetDisplayIndex(display);
1946 if (disp_idx == -1) {
1947 DLOGE("Invalid display = %d", display);
1948 return -EINVAL;
1949 }
1950
Rajavenu Kyatham42d11cb2019-04-16 13:03:29 +05301951 auto err = CallDisplayFunction(static_cast<hwc2_display_t>(disp_idx),
Qing Huangda3a91d2019-01-15 14:34:11 +08001952 &HWCDisplay::SetColorModeFromClientApi, mode);
1953 if (err != HWC2_ERROR_NONE)
1954 return -EINVAL;
1955
Varun Aroradff7d8d2019-08-05 18:12:43 -07001956 callbacks_.Refresh(static_cast<hwc2_display_t>(disp_idx));
Qing Huangda3a91d2019-01-15 14:34:11 +08001957
1958 return 0;
1959}
1960
Dileep Marchya35e27532018-06-29 10:50:16 +05301961android::status_t HWCSession::RefreshScreen(const android::Parcel *input_parcel) {
1962 int display = input_parcel->readInt32();
1963
1964 int disp_idx = GetDisplayIndex(display);
1965 if (disp_idx == -1) {
1966 DLOGE("Invalid display = %d", display);
1967 return -EINVAL;
1968 }
1969
Varun Aroradff7d8d2019-08-05 18:12:43 -07001970 callbacks_.Refresh(static_cast<hwc2_display_t>(disp_idx));
Dileep Marchya35e27532018-06-29 10:50:16 +05301971
1972 return 0;
1973}
1974
Naseer Ahmedb92e73f2016-03-12 02:03:48 -05001975void HWCSession::DynamicDebug(const android::Parcel *input_parcel) {
1976 int type = input_parcel->readInt32();
1977 bool enable = (input_parcel->readInt32() > 0);
1978 DLOGI("type = %d enable = %d", type, enable);
1979 int verbose_level = input_parcel->readInt32();
1980
1981 switch (type) {
1982 case qService::IQService::DEBUG_ALL:
1983 HWCDebugHandler::DebugAll(enable, verbose_level);
1984 break;
1985
1986 case qService::IQService::DEBUG_MDPCOMP:
1987 HWCDebugHandler::DebugStrategy(enable, verbose_level);
1988 HWCDebugHandler::DebugCompManager(enable, verbose_level);
1989 break;
1990
1991 case qService::IQService::DEBUG_PIPE_LIFECYCLE:
1992 HWCDebugHandler::DebugResources(enable, verbose_level);
Varun Aroracc301f12018-12-13 14:32:24 -08001993 HWCDebugHandler::DebugQos(enable, verbose_level);
Naseer Ahmedb92e73f2016-03-12 02:03:48 -05001994 break;
1995
1996 case qService::IQService::DEBUG_DRIVER_CONFIG:
1997 HWCDebugHandler::DebugDriverConfig(enable, verbose_level);
1998 break;
1999
2000 case qService::IQService::DEBUG_ROTATOR:
2001 HWCDebugHandler::DebugResources(enable, verbose_level);
2002 HWCDebugHandler::DebugDriverConfig(enable, verbose_level);
2003 HWCDebugHandler::DebugRotator(enable, verbose_level);
Varun Aroracc301f12018-12-13 14:32:24 -08002004 HWCDebugHandler::DebugQos(enable, verbose_level);
Naseer Ahmedb92e73f2016-03-12 02:03:48 -05002005 break;
2006
2007 case qService::IQService::DEBUG_QDCM:
2008 HWCDebugHandler::DebugQdcm(enable, verbose_level);
2009 break;
2010
Rohit Kulkarniaa5111b2017-06-13 10:26:39 -07002011 case qService::IQService::DEBUG_SCALAR:
2012 HWCDebugHandler::DebugScalar(enable, verbose_level);
2013 break;
2014
Saurabh Dubeyd90a6a42017-10-24 16:28:01 +05302015 case qService::IQService::DEBUG_CLIENT:
2016 HWCDebugHandler::DebugClient(enable, verbose_level);
2017 break;
2018
2019 case qService::IQService::DEBUG_DISPLAY:
2020 HWCDebugHandler::DebugDisplay(enable, verbose_level);
2021 break;
2022
Naseer Ahmedb92e73f2016-03-12 02:03:48 -05002023 default:
2024 DLOGW("type = %d is not supported", type);
2025 }
2026}
2027
Xu Yang2a979af2018-05-07 17:10:49 +08002028android::status_t HWCSession::QdcmCMDDispatch(uint32_t display_id,
2029 const PPDisplayAPIPayload &req_payload,
2030 PPDisplayAPIPayload *resp_payload,
2031 PPPendingParams *pending_action) {
2032 int ret = 0;
2033 bool is_physical_display = false;
2034
Padmanabhan Komandurue74cf4f2019-04-25 17:38:43 -07002035 if (display_id >= HWCCallbacks::kNumDisplays || !hwc_display_[display_id]) {
Xu Yang2a979af2018-05-07 17:10:49 +08002036 DLOGW("Invalid display id or display = %d is not connected.", display_id);
2037 return -ENODEV;
2038 }
2039
2040 if (display_id == map_info_primary_.client_id) {
2041 is_physical_display = true;
2042 } else {
2043 for (auto &map_info : map_info_builtin_) {
2044 if (map_info.client_id == display_id) {
2045 is_physical_display = true;
2046 break;
2047 }
2048 }
2049 }
2050
2051 if (!is_physical_display) {
2052 DLOGW("Skipping QDCM command dispatch on display = %d", display_id);
2053 return ret;
2054 }
2055
Rajavenu Kyatham42d11cb2019-04-16 13:03:29 +05302056 ret = hwc_display_[display_id]->ColorSVCRequestRoute(req_payload, resp_payload, pending_action);
Xu Yang2a979af2018-05-07 17:10:49 +08002057
2058 return ret;
2059}
2060
Naseer Ahmedb92e73f2016-03-12 02:03:48 -05002061android::status_t HWCSession::QdcmCMDHandler(const android::Parcel *input_parcel,
2062 android::Parcel *output_parcel) {
2063 int ret = 0;
Varun Arora75c05f02019-05-14 14:53:37 -07002064 float *brightness = NULL;
Naseer Ahmedb92e73f2016-03-12 02:03:48 -05002065 uint32_t display_id(0);
2066 PPPendingParams pending_action;
2067 PPDisplayAPIPayload resp_payload, req_payload;
Xu Yang2a979af2018-05-07 17:10:49 +08002068 uint8_t *disp_id = NULL;
Qing Huang02285c32018-12-06 16:30:38 +08002069 int32_t *mode_id = NULL;
Naseer Ahmedb92e73f2016-03-12 02:03:48 -05002070
2071 if (!color_mgr_) {
Mathew Joseph Karimpanaldbd64f82017-10-06 10:13:38 +05302072 DLOGW("color_mgr_ not initialized.");
2073 return -ENOENT;
Naseer Ahmedb92e73f2016-03-12 02:03:48 -05002074 }
2075
2076 pending_action.action = kNoAction;
2077 pending_action.params = NULL;
2078
2079 // Read display_id, payload_size and payload from in_parcel.
2080 ret = HWCColorManager::CreatePayloadFromParcel(*input_parcel, &display_id, &req_payload);
2081 if (!ret) {
Xu Yang2a979af2018-05-07 17:10:49 +08002082 ret = QdcmCMDDispatch(display_id, req_payload, &resp_payload, &pending_action);
Naseer Ahmedb92e73f2016-03-12 02:03:48 -05002083 }
2084
2085 if (ret) {
2086 output_parcel->writeInt32(ret); // first field in out parcel indicates return code.
2087 req_payload.DestroyPayload();
2088 resp_payload.DestroyPayload();
2089 return ret;
2090 }
2091
Mathew Joseph Karimpanaldbd64f82017-10-06 10:13:38 +05302092 if (kNoAction != pending_action.action) {
Ch Ganesh Kumar5d43ff62017-10-13 19:01:47 +05302093 int32_t action = pending_action.action;
2094 int count = -1;
2095 while (action > 0) {
2096 count++;
2097 int32_t bit = (action & 1);
2098 action = action >> 1;
2099
2100 if (!bit)
2101 continue;
2102
Xu Yang2a979af2018-05-07 17:10:49 +08002103 DLOGV_IF(kTagQDCM, "pending action = %d, display_id = %d", BITMAP(count), display_id);
Ch Ganesh Kumar5d43ff62017-10-13 19:01:47 +05302104 switch (BITMAP(count)) {
2105 case kInvalidating:
Ray Zhang2ee82472019-09-05 02:53:29 +08002106 callbacks_.Refresh(display_id);
Ch Ganesh Kumar5d43ff62017-10-13 19:01:47 +05302107 break;
2108 case kEnterQDCMMode:
Xu Yang2a979af2018-05-07 17:10:49 +08002109 ret = color_mgr_->EnableQDCMMode(true, hwc_display_[display_id]);
Ch Ganesh Kumar5d43ff62017-10-13 19:01:47 +05302110 break;
2111 case kExitQDCMMode:
Xu Yang2a979af2018-05-07 17:10:49 +08002112 ret = color_mgr_->EnableQDCMMode(false, hwc_display_[display_id]);
Ch Ganesh Kumar5d43ff62017-10-13 19:01:47 +05302113 break;
2114 case kApplySolidFill:
Gopikrishnaiah Anandana340b702018-01-16 15:37:15 -08002115 {
Xu Yang2a979af2018-05-07 17:10:49 +08002116 SCOPE_LOCK(locker_[display_id]);
Gopikrishnaiah Anandana340b702018-01-16 15:37:15 -08002117 ret = color_mgr_->SetSolidFill(pending_action.params,
Xu Yang2a979af2018-05-07 17:10:49 +08002118 true, hwc_display_[display_id]);
Gopikrishnaiah Anandana340b702018-01-16 15:37:15 -08002119 }
Varun Aroradff7d8d2019-08-05 18:12:43 -07002120 callbacks_.Refresh(display_id);
Gopikrishnaiah Anandana340b702018-01-16 15:37:15 -08002121 usleep(kSolidFillDelay);
Ch Ganesh Kumar5d43ff62017-10-13 19:01:47 +05302122 break;
2123 case kDisableSolidFill:
Gopikrishnaiah Anandana340b702018-01-16 15:37:15 -08002124 {
Xu Yang2a979af2018-05-07 17:10:49 +08002125 SCOPE_LOCK(locker_[display_id]);
Gopikrishnaiah Anandana340b702018-01-16 15:37:15 -08002126 ret = color_mgr_->SetSolidFill(pending_action.params,
Xu Yang2a979af2018-05-07 17:10:49 +08002127 false, hwc_display_[display_id]);
Gopikrishnaiah Anandana340b702018-01-16 15:37:15 -08002128 }
Varun Aroradff7d8d2019-08-05 18:12:43 -07002129 callbacks_.Refresh(display_id);
Gopikrishnaiah Anandana340b702018-01-16 15:37:15 -08002130 usleep(kSolidFillDelay);
Ch Ganesh Kumar5d43ff62017-10-13 19:01:47 +05302131 break;
2132 case kSetPanelBrightness:
Varun Arora75c05f02019-05-14 14:53:37 -07002133 ret = -EINVAL;
2134 brightness = reinterpret_cast<float *>(resp_payload.payload);
2135 if (brightness == NULL) {
2136 DLOGE("Brightness payload is Null");
Ch Ganesh Kumar5d43ff62017-10-13 19:01:47 +05302137 } else {
Rajavenu Kyatham42d11cb2019-04-16 13:03:29 +05302138 ret = INT(SetDisplayBrightness(static_cast<hwc2_display_t>(display_id), *brightness));
Ch Ganesh Kumar5d43ff62017-10-13 19:01:47 +05302139 }
2140 break;
2141 case kEnableFrameCapture:
Rajavenu Kyatham42d11cb2019-04-16 13:03:29 +05302142 ret = color_mgr_->SetFrameCapture(pending_action.params, true, hwc_display_[display_id]);
Varun Aroradff7d8d2019-08-05 18:12:43 -07002143 callbacks_.Refresh(display_id);
Ch Ganesh Kumar5d43ff62017-10-13 19:01:47 +05302144 break;
2145 case kDisableFrameCapture:
2146 ret = color_mgr_->SetFrameCapture(pending_action.params, false,
Xu Yang2a979af2018-05-07 17:10:49 +08002147 hwc_display_[display_id]);
Ch Ganesh Kumar5d43ff62017-10-13 19:01:47 +05302148 break;
2149 case kConfigureDetailedEnhancer:
Rajavenu Kyatham42d11cb2019-04-16 13:03:29 +05302150 ret = color_mgr_->SetDetailedEnhancer(pending_action.params, hwc_display_[display_id]);
Varun Aroradff7d8d2019-08-05 18:12:43 -07002151 callbacks_.Refresh(display_id);
Ch Ganesh Kumar5d43ff62017-10-13 19:01:47 +05302152 break;
2153 case kModeSet:
2154 ret = static_cast<int>
Xu Yang2a979af2018-05-07 17:10:49 +08002155 (hwc_display_[display_id]->RestoreColorTransform());
Varun Aroradff7d8d2019-08-05 18:12:43 -07002156 callbacks_.Refresh(display_id);
Ch Ganesh Kumar5d43ff62017-10-13 19:01:47 +05302157 break;
2158 case kNoAction:
2159 break;
Xu Yang2a979af2018-05-07 17:10:49 +08002160 case kMultiDispProc:
2161 for (auto &map_info : map_info_builtin_) {
2162 uint32_t id = UINT32(map_info.client_id);
Padmanabhan Komandurue74cf4f2019-04-25 17:38:43 -07002163 if (id < HWCCallbacks::kNumDisplays && hwc_display_[id]) {
Xu Yang2a979af2018-05-07 17:10:49 +08002164 int result = 0;
2165 resp_payload.DestroyPayload();
Rajavenu Kyatham42d11cb2019-04-16 13:03:29 +05302166 result = hwc_display_[id]->ColorSVCRequestRoute(req_payload, &resp_payload,
Xu Yang2a979af2018-05-07 17:10:49 +08002167 &pending_action);
2168 if (result) {
2169 DLOGW("Failed to dispatch action to disp %d ret %d", id, result);
2170 ret = result;
2171 }
2172 }
2173 }
2174 break;
2175 case kMultiDispGetId:
Padmanabhan Komandurue74cf4f2019-04-25 17:38:43 -07002176 ret = resp_payload.CreatePayloadBytes(HWCCallbacks::kNumDisplays, &disp_id);
Xu Yang2a979af2018-05-07 17:10:49 +08002177 if (ret) {
2178 DLOGW("Unable to create response payload!");
2179 } else {
Padmanabhan Komandurue74cf4f2019-04-25 17:38:43 -07002180 for (int i = 0; i < HWCCallbacks::kNumDisplays; i++) {
2181 disp_id[i] = HWCCallbacks::kNumDisplays;
Xu Yang2a979af2018-05-07 17:10:49 +08002182 }
2183 if (hwc_display_[HWC_DISPLAY_PRIMARY]) {
2184 disp_id[HWC_DISPLAY_PRIMARY] = HWC_DISPLAY_PRIMARY;
2185 }
2186 for (auto &map_info : map_info_builtin_) {
2187 uint64_t id = map_info.client_id;
Padmanabhan Komandurue74cf4f2019-04-25 17:38:43 -07002188 if (id < HWCCallbacks::kNumDisplays && hwc_display_[id]) {
Xu Yang2a979af2018-05-07 17:10:49 +08002189 disp_id[id] = (uint8_t)id;
2190 }
2191 }
2192 }
2193 break;
Qing Huang02285c32018-12-06 16:30:38 +08002194 case kSetModeFromClient:
2195 {
2196 SCOPE_LOCK(locker_[display_id]);
2197 mode_id = reinterpret_cast<int32_t *>(resp_payload.payload);
2198 if (mode_id) {
2199 ret = static_cast<int>(hwc_display_[display_id]->SetColorModeFromClientApi(*mode_id));
2200 } else {
2201 DLOGE("mode_id is Null");
2202 ret = -EINVAL;
2203 }
2204 }
2205 if (!ret) {
Varun Aroradff7d8d2019-08-05 18:12:43 -07002206 callbacks_.Refresh(display_id);
Qing Huang02285c32018-12-06 16:30:38 +08002207 }
2208 break;
Ch Ganesh Kumar5d43ff62017-10-13 19:01:47 +05302209 default:
2210 DLOGW("Invalid pending action = %d!", pending_action.action);
2211 break;
2212 }
Mathew Joseph Karimpanaldbd64f82017-10-06 10:13:38 +05302213 }
Naseer Ahmedb92e73f2016-03-12 02:03:48 -05002214 }
Naseer Ahmedb92e73f2016-03-12 02:03:48 -05002215 // for display API getter case, marshall returned params into out_parcel.
2216 output_parcel->writeInt32(ret);
2217 HWCColorManager::MarshallStructIntoParcel(resp_payload, output_parcel);
2218 req_payload.DestroyPayload();
2219 resp_payload.DestroyPayload();
Sushil Chauhand6429af2018-11-15 11:34:27 -08002220
2221 SEQUENCE_WAIT_SCOPE_LOCK(locker_[display_id]);
Ray Zhang2ee82472019-09-05 02:53:29 +08002222 hwc_display_[display_id]->ResetValidation();
Naseer Ahmedb92e73f2016-03-12 02:03:48 -05002223
Mathew Joseph Karimpanaldbd64f82017-10-06 10:13:38 +05302224 return ret;
Naseer Ahmedb92e73f2016-03-12 02:03:48 -05002225}
2226
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +05302227int GetEventValue(const char *uevent_data, int length, const char *event_info) {
2228 const char *iterator_str = uevent_data;
2229 while (((iterator_str - uevent_data) <= length) && (*iterator_str)) {
2230 const char *pstr = strstr(iterator_str, event_info);
2231 if (pstr != NULL) {
2232 return (atoi(iterator_str + strlen(event_info)));
Naseer Ahmedb92e73f2016-03-12 02:03:48 -05002233 }
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +05302234 iterator_str += strlen(iterator_str) + 1;
Naseer Ahmedb92e73f2016-03-12 02:03:48 -05002235 }
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +05302236
2237 return -1;
Naseer Ahmedb92e73f2016-03-12 02:03:48 -05002238}
2239
Prabhanjan Kandula02367712017-08-10 20:09:25 -07002240const char *GetTokenValue(const char *uevent_data, int length, const char *token) {
Prabhanjan Kandula34ffec02017-04-25 11:56:39 -07002241 const char *iterator_str = uevent_data;
Prabhanjan Kandula34ffec02017-04-25 11:56:39 -07002242 const char *pstr = NULL;
2243 while (((iterator_str - uevent_data) <= length) && (*iterator_str)) {
Prabhanjan Kandula02367712017-08-10 20:09:25 -07002244 pstr = strstr(iterator_str, token);
2245 if (pstr) {
Prabhanjan Kandula34ffec02017-04-25 11:56:39 -07002246 break;
2247 }
2248 iterator_str += strlen(iterator_str) + 1;
2249 }
2250
Prabhanjan Kandula02367712017-08-10 20:09:25 -07002251 if (pstr)
2252 pstr = pstr+strlen(token);
2253
2254 return pstr;
2255}
2256
Pullakavi Srinivas9189e602018-12-19 16:58:07 +05302257android::status_t HWCSession::SetDsiClk(const android::Parcel *input_parcel) {
2258 int disp_id = input_parcel->readInt32();
2259 uint64_t clk = UINT64(input_parcel->readInt64());
Dileep Marchyaafa45bc2019-06-21 17:05:31 +05302260 if (disp_id < 0) {
2261 return -EINVAL;
2262 }
2263
2264 SEQUENCE_WAIT_SCOPE_LOCK(locker_[disp_id]);
2265 if (!hwc_display_[disp_id]) {
Pullakavi Srinivas9189e602018-12-19 16:58:07 +05302266 return -EINVAL;
2267 }
2268
2269 return hwc_display_[disp_id]->SetDynamicDSIClock(clk);
2270}
2271
2272android::status_t HWCSession::GetDsiClk(const android::Parcel *input_parcel,
2273 android::Parcel *output_parcel) {
2274 int disp_id = input_parcel->readInt32();
Dileep Marchyaafa45bc2019-06-21 17:05:31 +05302275 if (disp_id < 0) {
2276 return -EINVAL;
2277 }
2278
2279 SEQUENCE_WAIT_SCOPE_LOCK(locker_[disp_id]);
2280 if (!hwc_display_[disp_id]) {
Pullakavi Srinivas9189e602018-12-19 16:58:07 +05302281 return -EINVAL;
2282 }
2283
2284 uint64_t bitrate = 0;
2285 hwc_display_[disp_id]->GetDynamicDSIClock(&bitrate);
2286 output_parcel->writeUint64(bitrate);
2287
2288 return 0;
2289}
2290
2291android::status_t HWCSession::GetSupportedDsiClk(const android::Parcel *input_parcel,
2292 android::Parcel *output_parcel) {
2293 int disp_id = input_parcel->readInt32();
Dileep Marchyaafa45bc2019-06-21 17:05:31 +05302294 if (disp_id < 0) {
2295 return -EINVAL;
2296 }
2297
2298 SCOPE_LOCK(locker_[disp_id]);
2299 if (!hwc_display_[disp_id]) {
Pullakavi Srinivas9189e602018-12-19 16:58:07 +05302300 return -EINVAL;
2301 }
2302
2303 std::vector<uint64_t> bit_rates;
2304 hwc_display_[disp_id]->GetSupportedDSIClock(&bit_rates);
2305 output_parcel->writeInt32(INT32(bit_rates.size()));
2306 for (auto &bit_rate : bit_rates) {
2307 output_parcel->writeUint64(bit_rate);
2308 }
2309
2310 return 0;
2311}
2312
Archit Srivastavaa59c4ff2019-05-20 10:54:22 +05302313android::status_t HWCSession::SetPanelLuminanceAttributes(const android::Parcel *input_parcel) {
2314 int disp_id = input_parcel->readInt32();
2315
2316 // currently doing only for virtual display
2317 if (disp_id != qdutils::DISPLAY_VIRTUAL) {
2318 return -EINVAL;
2319 }
2320
Padmanabhan Komandurue4d31fc2019-09-12 19:13:17 +05302321 float min_lum = input_parcel->readFloat();
2322 float max_lum = input_parcel->readFloat();
2323
2324 // check for out of range luminance values
2325 if (min_lum <= 0.0f || min_lum >= 1.0f || max_lum <= 100.0f || max_lum >= 1000.0f) {
2326 return -EINVAL;
2327 }
2328
Archit Srivastavaa59c4ff2019-05-20 10:54:22 +05302329 std::lock_guard<std::mutex> obj(mutex_lum_);
Padmanabhan Komandurue4d31fc2019-09-12 19:13:17 +05302330 set_min_lum_ = min_lum;
2331 set_max_lum_ = max_lum;
Archit Srivastavaa59c4ff2019-05-20 10:54:22 +05302332 DLOGI("set max_lum %f, min_lum %f", set_max_lum_, set_min_lum_);
2333
2334 return 0;
2335}
2336
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +05302337void HWCSession::UEventHandler(const char *uevent_data, int length) {
Mathew Joseph Karimpanal12892292019-03-21 16:07:59 +05302338 // Drop hotplug uevents until SurfaceFlinger (the client) is connected. The equivalent of hotplug
2339 // uevent handling will be done once when SurfaceFlinger connects, at RegisterCallback(). Since
2340 // HandlePluggableDisplays() reads the latest connection states of all displays, no uevent is
2341 // lost.
Varun Aroradff7d8d2019-08-05 18:12:43 -07002342 if (callbacks_.IsClientConnected() && strcasestr(uevent_data, HWC_UEVENT_DRM_EXT_HOTPLUG)) {
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +05302343 // MST hotplug will not carry connection status/test pattern etc.
2344 // Pluggable display handler will check all connection status' and take action accordingly.
2345 const char *str_status = GetTokenValue(uevent_data, length, "status=");
2346 const char *str_mst = GetTokenValue(uevent_data, length, "MST_HOTPLUG=");
2347 if (!str_status && !str_mst) {
2348 return;
Ramakant Singhfae59892017-09-13 10:40:22 +05302349 }
Prabhanjan Kandula34ffec02017-04-25 11:56:39 -07002350
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +05302351 hpd_bpp_ = GetEventValue(uevent_data, length, "bpp=");
2352 hpd_pattern_ = GetEventValue(uevent_data, length, "pattern=");
Varun Arorad366c202018-09-26 14:00:56 -07002353 DLOGI("Uevent = %s, status = %s, MST_HOTPLUG = %s, bpp = %d, pattern = %d", uevent_data,
2354 str_status ? str_status : "NULL", str_mst ? str_mst : "NULL", hpd_bpp_, hpd_pattern_);
Mathew Joseph Karimpanal71ac8a72018-09-25 22:27:22 +05302355
2356 hwc2_display_t virtual_display_index =
2357 (hwc2_display_t)GetDisplayIndex(qdutils::DISPLAY_VIRTUAL);
2358
2359 std::bitset<kSecureMax> secure_sessions = 0;
Ramkumar Radhakrishnan44c64362018-12-12 13:03:59 -08002360 hwc2_display_t active_builtin_disp_id = GetActiveBuiltinDisplay();
Padmanabhan Komandurue74cf4f2019-04-25 17:38:43 -07002361 if (active_builtin_disp_id < HWCCallbacks::kNumDisplays) {
Ramkumar Radhakrishnan44c64362018-12-12 13:03:59 -08002362 Locker::ScopeLock lock_a(locker_[active_builtin_disp_id]);
2363 hwc_display_[active_builtin_disp_id]->GetActiveSecureSession(&secure_sessions);
Mathew Joseph Karimpanal71ac8a72018-09-25 22:27:22 +05302364 }
2365 if (secure_sessions[kSecureDisplay] || hwc_display_[virtual_display_index]) {
Mathew Joseph Karimpanalabe3b3d2018-11-27 17:25:40 +05302366 // Defer hotplug handling.
2367 SCOPE_LOCK(pluggable_handler_lock_);
2368 DLOGI("Marking hotplug pending...");
Mathew Joseph Karimpanalb1c15862019-07-04 11:14:24 +05302369 pending_hotplug_event_ = kHotPlugEvent;
Mathew Joseph Karimpanalabe3b3d2018-11-27 17:25:40 +05302370 } else {
2371 // Handle hotplug.
2372 int32_t err = HandlePluggableDisplays(true);
2373 if (err) {
2374 DLOGW("Hotplug handling failed. Error %d '%s'. Hotplug handling %s.", err,
Mathew Joseph Karimpanalb1c15862019-07-04 11:14:24 +05302375 strerror(abs(err)), (pending_hotplug_event_ == kHotPlugEvent) ?
Mathew Joseph Karimpanalabe3b3d2018-11-27 17:25:40 +05302376 "deferred" : "dropped");
2377 }
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +05302378 }
2379
2380 if (str_status) {
2381 bool connected = (strncmp(str_status, "connected", strlen("connected")) == 0);
2382 DLOGI("Connected = %d", connected);
Mathew Joseph Karimpanal71ac8a72018-09-25 22:27:22 +05302383 // Pass on legacy HDMI hot-plug event.
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +05302384 qservice_->onHdmiHotplug(INT(connected));
2385 }
Prabhanjan Kandula34ffec02017-04-25 11:56:39 -07002386 }
2387}
2388
Naseer Ahmed8584a0f2020-02-19 22:23:30 -05002389int32_t HWCSession::GetVsyncPeriod(hwc2_display_t disp, uint32_t *vsync_period) {
2390 if (disp >= HWCCallbacks::kNumDisplays) {
2391 DLOGW("Invalid Display : display = %" PRIu64, disp);
2392 return HWC2_ERROR_BAD_DISPLAY;
Naseer Ahmedb92e73f2016-03-12 02:03:48 -05002393 }
2394
Naseer Ahmed8584a0f2020-02-19 22:23:30 -05002395 SCOPE_LOCK(locker_[(int)disp]);
2396 // default value
2397 *vsync_period = 1000000000ul / 60;
2398
2399 if (hwc_display_[disp]) {
2400 hwc_display_[disp]->GetDisplayAttribute(0, HwcAttribute::VSYNC_PERIOD, (int32_t *)vsync_period);
2401 }
2402
2403 return HWC2_ERROR_NONE;
Naseer Ahmedb92e73f2016-03-12 02:03:48 -05002404}
2405
Mathew Joseph Karimpanalf9297472019-08-21 15:49:15 +05302406void HWCSession::Refresh(hwc2_display_t display) {
2407 callbacks_.Refresh(display);
2408}
2409
Naseer Ahmedb92e73f2016-03-12 02:03:48 -05002410android::status_t HWCSession::GetVisibleDisplayRect(const android::Parcel *input_parcel,
2411 android::Parcel *output_parcel) {
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +05302412 int disp_idx = GetDisplayIndex(input_parcel->readInt32());
2413 if (disp_idx == -1) {
2414 DLOGE("Invalid display = %d", disp_idx);
Naseer Ahmedb92e73f2016-03-12 02:03:48 -05002415 return android::BAD_VALUE;
2416 }
2417
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +05302418 SEQUENCE_WAIT_SCOPE_LOCK(locker_[disp_idx]);
2419 if (!hwc_display_[disp_idx]) {
Naseer Ahmedb92e73f2016-03-12 02:03:48 -05002420 return android::NO_INIT;
2421 }
2422
2423 hwc_rect_t visible_rect = {0, 0, 0, 0};
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +05302424 int error = hwc_display_[disp_idx]->GetVisibleDisplayRect(&visible_rect);
Naseer Ahmedb92e73f2016-03-12 02:03:48 -05002425 if (error < 0) {
2426 return error;
2427 }
2428
2429 output_parcel->writeInt32(visible_rect.left);
2430 output_parcel->writeInt32(visible_rect.top);
2431 output_parcel->writeInt32(visible_rect.right);
2432 output_parcel->writeInt32(visible_rect.bottom);
2433
2434 return android::NO_ERROR;
2435}
2436
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +05302437int HWCSession::CreatePrimaryDisplay() {
2438 int status = -EINVAL;
2439 HWDisplaysInfo hw_displays_info = {};
Ramakant Singhfae59892017-09-13 10:40:22 +05302440
Varun Aroraad2719a2018-10-25 10:13:53 -07002441 if (null_display_mode_) {
2442 HWDisplayInfo hw_info = {};
2443 hw_info.display_type = kBuiltIn;
2444 hw_info.is_connected = 1;
2445 hw_info.is_primary = 1;
2446 hw_info.is_wb_ubwc_supported = 0;
2447 hw_info.display_id = 1;
2448 hw_displays_info[hw_info.display_id] = hw_info;
2449 } else {
2450 DisplayError error = core_intf_->GetDisplaysStatus(&hw_displays_info);
2451 if (error != kErrorNone) {
2452 DLOGE("Failed to get connected display list. Error = %d", error);
2453 return status;
2454 }
Ramakant Singhfae59892017-09-13 10:40:22 +05302455 }
2456
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +05302457 for (auto &iter : hw_displays_info) {
2458 auto &info = iter.second;
2459 if (!info.is_primary) {
2460 continue;
2461 }
2462
2463 // todo (user): If primary display is not connected (e.g. hdmi as primary), a NULL display
2464 // need to be created. SF expects primary display hotplug during callback registration unlike
2465 // previous implementation where first hotplug could be notified anytime.
2466 if (!info.is_connected) {
2467 DLOGE("Primary display is not connected. Not supported at present.");
2468 break;
2469 }
2470
2471 auto hwc_display = &hwc_display_[HWC_DISPLAY_PRIMARY];
2472 hwc2_display_t client_id = map_info_primary_.client_id;
2473
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +05302474 if (info.display_type == kBuiltIn) {
2475 status = HWCDisplayBuiltIn::Create(core_intf_, &buffer_allocator_, &callbacks_, this,
2476 qservice_, client_id, info.display_id, hwc_display);
2477 } else if (info.display_type == kPluggable) {
2478 status = HWCDisplayPluggable::Create(core_intf_, &buffer_allocator_, &callbacks_, this,
2479 qservice_, client_id, info.display_id, 0, 0, false,
2480 hwc_display);
2481 } else {
2482 DLOGE("Spurious primary display type = %d", info.display_type);
2483 break;
2484 }
2485
2486 if (!status) {
Varun Arorad7d8c912019-08-16 11:45:19 -07002487 DLOGI("Created primary display type = %d, sdm id = %d, client id = %d", info.display_type,
Pullakavi Srinivas1ae4acb2019-11-18 19:33:45 +05302488 info.display_id, client_id);
2489 {
2490 SCOPE_LOCK(hdr_locker_[client_id]);
2491 is_hdr_display_[UINT32(client_id)] = HasHDRSupport(*hwc_display);
2492 }
2493
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +05302494 map_info_primary_.disp_type = info.display_type;
2495 map_info_primary_.sdm_id = info.display_id;
Srinivas Pullakavi3c4337f2019-07-03 11:24:31 +05302496 CreateDummyDisplay(HWC_DISPLAY_PRIMARY);
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +05302497 color_mgr_ = HWCColorManager::CreateColorManager(&buffer_allocator_);
2498 if (!color_mgr_) {
2499 DLOGW("Failed to load HWCColorManager.");
2500 }
2501 } else {
Varun Arorad7d8c912019-08-16 11:45:19 -07002502 DLOGE("Primary display creation has failed! status = %d", status);
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +05302503 }
2504
2505 // Primary display is found, no need to parse more.
2506 break;
Ramakant Singhfae59892017-09-13 10:40:22 +05302507 }
2508
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +05302509 return status;
Ramakant Singhfae59892017-09-13 10:40:22 +05302510}
2511
Srinivas Pullakavi3c4337f2019-07-03 11:24:31 +05302512void HWCSession::CreateDummyDisplay(hwc2_display_t client_id) {
2513 if (!async_powermode_) {
2514 return;
2515 }
2516
2517 hwc2_display_t dummy_disp_id = map_hwc_display_.find(client_id)->second;
2518 auto hwc_display_dummy = &hwc_display_[dummy_disp_id];
2519 HWCDisplayDummy::Create(core_intf_, &buffer_allocator_, &callbacks_, this, qservice_,
2520 0, 0, hwc_display_dummy);
2521 if (!*hwc_display_dummy) {
2522 DLOGE("Dummy display creation failed for %d display\n", client_id);
2523 }
2524}
2525
Varun Aroraad2719a2018-10-25 10:13:53 -07002526int HWCSession::HandleBuiltInDisplays() {
2527 if (null_display_mode_) {
2528 DLOGW("Skipped BuiltIn display handling in null-display mode");
2529 return 0;
2530 }
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +05302531
Varun Aroraad2719a2018-10-25 10:13:53 -07002532 HWDisplaysInfo hw_displays_info = {};
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +05302533 DisplayError error = core_intf_->GetDisplaysStatus(&hw_displays_info);
2534 if (error != kErrorNone) {
2535 DLOGE("Failed to get connected display list. Error = %d", error);
2536 return -EINVAL;
2537 }
2538
2539 int status = 0;
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +05302540 for (auto &iter : hw_displays_info) {
2541 auto &info = iter.second;
2542
2543 // Do not recreate primary display.
2544 if (info.is_primary || info.display_type != kBuiltIn) {
2545 continue;
2546 }
2547
Pullakavi Srinivasf2a31852019-04-23 14:32:08 -07002548 for (auto &map_info : map_info_builtin_) {
2549 hwc2_display_t client_id = map_info.client_id;
Mathew Joseph Karimpanal8abb6e02018-11-20 09:52:49 +05302550
Pullakavi Srinivasf2a31852019-04-23 14:32:08 -07002551 {
2552 SCOPE_LOCK(locker_[client_id]);
2553 // Lock confined to this scope
2554 if (hwc_display_[client_id]) {
2555 continue;
2556 }
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +05302557
Pullakavi Srinivasf2a31852019-04-23 14:32:08 -07002558 DLOGI("Create builtin display, sdm id = %d, client id = %d", info.display_id, client_id);
2559 status = HWCDisplayBuiltIn::Create(core_intf_, &buffer_allocator_, &callbacks_, this,
2560 qservice_, client_id, info.display_id,
2561 &hwc_display_[client_id]);
2562 if (status) {
2563 DLOGE("Builtin display creation failed.");
2564 break;
2565 }
Pullakavi Srinivas1ae4acb2019-11-18 19:33:45 +05302566
2567 {
2568 SCOPE_LOCK(hdr_locker_[client_id]);
2569 is_hdr_display_[UINT32(client_id)] = HasHDRSupport(hwc_display_[client_id]);
2570 }
2571
Mathew Joseph Karimpanal8abb6e02018-11-20 09:52:49 +05302572 DLOGI("Builtin display created: sdm id = %d, client id = %d", info.display_id, client_id);
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +05302573 map_info.disp_type = info.display_type;
2574 map_info.sdm_id = info.display_id;
Srinivas Pullakavi3c4337f2019-07-03 11:24:31 +05302575 CreateDummyDisplay(client_id);
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +05302576 }
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +05302577
Pullakavi Srinivasf2a31852019-04-23 14:32:08 -07002578 DLOGI("Hotplugging builtin display, sdm id = %d, client id = %d", info.display_id, client_id);
2579 callbacks_.Hotplug(client_id, HWC2::Connection::Connected);
2580 break;
2581 }
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +05302582 }
2583
2584 return status;
Saurabh Shah04f932b2017-10-12 18:47:45 -07002585}
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +05302586
Varun Arorad366c202018-09-26 14:00:56 -07002587int HWCSession::HandlePluggableDisplays(bool delay_hotplug) {
Mathew Joseph Karimpanalabe3b3d2018-11-27 17:25:40 +05302588 SCOPE_LOCK(pluggable_handler_lock_);
Varun Aroraad2719a2018-10-25 10:13:53 -07002589 if (null_display_mode_) {
2590 DLOGW("Skipped pluggable display handling in null-display mode");
2591 return 0;
2592 }
2593
Mathew Joseph Karimpanalabe3b3d2018-11-27 17:25:40 +05302594 DLOGI("Handling hotplug...");
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +05302595 HWDisplaysInfo hw_displays_info = {};
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +05302596 DisplayError error = core_intf_->GetDisplaysStatus(&hw_displays_info);
2597 if (error != kErrorNone) {
2598 DLOGE("Failed to get connected display list. Error = %d", error);
2599 return -EINVAL;
2600 }
2601
2602 int status = HandleDisconnectedDisplays(&hw_displays_info);
2603 if (status) {
2604 DLOGE("All displays could not be disconnected.");
2605 return status;
2606 }
2607
2608 status = HandleConnectedDisplays(&hw_displays_info, delay_hotplug);
2609 if (status) {
Mathew Joseph Karimpanalabe3b3d2018-11-27 17:25:40 +05302610 switch (status) {
2611 case -EAGAIN:
2612 case -ENODEV:
2613 // Errors like device removal or deferral for which we want to try another hotplug handling.
Mathew Joseph Karimpanalb1c15862019-07-04 11:14:24 +05302614 pending_hotplug_event_ = kHotPlugEvent;
Mathew Joseph Karimpanalabe3b3d2018-11-27 17:25:40 +05302615 status = 0;
2616 break;
2617 default:
2618 // Real errors we want to flag and stop hotplug handling.
Mathew Joseph Karimpanalb1c15862019-07-04 11:14:24 +05302619 pending_hotplug_event_ = kHotPlugNone;
Mathew Joseph Karimpanalabe3b3d2018-11-27 17:25:40 +05302620 DLOGE("All displays could not be connected. Error %d '%s'.", status, strerror(abs(status)));
2621 }
Mathew Joseph Karimpanalb1c15862019-07-04 11:14:24 +05302622 DLOGI("Handling hotplug... %s", (kHotPlugNone == pending_hotplug_event_) ?
Mathew Joseph Karimpanalabe3b3d2018-11-27 17:25:40 +05302623 "Stopped." : "Done. Hotplug events pending.");
2624 return status;
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +05302625 }
2626
Mathew Joseph Karimpanalb1c15862019-07-04 11:14:24 +05302627 pending_hotplug_event_ = kHotPlugNone;
Mathew Joseph Karimpanalabe3b3d2018-11-27 17:25:40 +05302628
2629 DLOGI("Handling hotplug... Done.");
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +05302630 return 0;
2631}
2632
2633int HWCSession::HandleConnectedDisplays(HWDisplaysInfo *hw_displays_info, bool delay_hotplug) {
2634 int status = 0;
2635 std::vector<hwc2_display_t> pending_hotplugs = {};
Padmanabhan Komanduruf5b7f992019-07-08 13:33:44 +05302636 hwc2_display_t client_id = 0;
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +05302637
2638 for (auto &iter : *hw_displays_info) {
2639 auto &info = iter.second;
2640
2641 // Do not recreate primary display or if display is not connected.
2642 if (info.is_primary || info.display_type != kPluggable || !info.is_connected) {
2643 continue;
2644 }
2645
Mathew Joseph Karimpanalbbc700b2018-07-19 19:54:24 +05302646 // Check if we are already using the display.
2647 auto display_used = std::find_if(map_info_pluggable_.begin(), map_info_pluggable_.end(),
2648 [&](auto &p) {
2649 return (p.sdm_id == info.display_id);
2650 });
2651 if (display_used != map_info_pluggable_.end()) {
2652 // Display is already used in a slot.
2653 continue;
2654 }
2655
Mathew Joseph Karimpanalabe3b3d2018-11-27 17:25:40 +05302656 // Count active pluggable display slots and slots with no commits.
Mathew Joseph Karimpanalabe3b3d2018-11-27 17:25:40 +05302657 bool first_commit_pending = false;
Mathew Joseph Karimpanal8abb6e02018-11-20 09:52:49 +05302658 std::for_each(map_info_pluggable_.begin(), map_info_pluggable_.end(),
2659 [&](auto &p) {
Mathew Joseph Karimpanalabe3b3d2018-11-27 17:25:40 +05302660 SCOPE_LOCK(locker_[p.client_id]);
Mathew Joseph Karimpanal8abb6e02018-11-20 09:52:49 +05302661 if (hwc_display_[p.client_id]) {
Mathew Joseph Karimpanalabe3b3d2018-11-27 17:25:40 +05302662 if (!hwc_display_[p.client_id]->IsFirstCommitDone()) {
2663 DLOGI("Display commit pending on display %d-1", p.sdm_id);
2664 first_commit_pending = true;
2665 }
Mathew Joseph Karimpanal8abb6e02018-11-20 09:52:49 +05302666 }
2667 });
2668
Mathew Joseph Karimpanalabe3b3d2018-11-27 17:25:40 +05302669 if (!disable_hotplug_bwcheck_ && first_commit_pending) {
2670 // Hotplug bandwidth check is accomplished by creating and hotplugging a new display after
2671 // a display commit has happened on previous hotplugged displays. This allows the driver to
2672 // return updated modes for the new display based on available link bandwidth.
2673 DLOGI("Pending display commit on one of the displays. Deferring display creation.");
2674 status = -EAGAIN;
Varun Aroradff7d8d2019-08-05 18:12:43 -07002675 if (callbacks_.IsClientConnected()) {
Mathew Joseph Karimpanalabe3b3d2018-11-27 17:25:40 +05302676 // Trigger a display refresh since we depend on PresentDisplay() to handle pending hotplugs.
2677 hwc2_display_t active_builtin_disp_id = GetActiveBuiltinDisplay();
Padmanabhan Komandurue74cf4f2019-04-25 17:38:43 -07002678 if (active_builtin_disp_id >= HWCCallbacks::kNumDisplays) {
Mathew Joseph Karimpanalabe3b3d2018-11-27 17:25:40 +05302679 active_builtin_disp_id = HWC_DISPLAY_PRIMARY;
2680 }
Varun Aroradff7d8d2019-08-05 18:12:43 -07002681 callbacks_.Refresh(active_builtin_disp_id);
Mathew Joseph Karimpanalabe3b3d2018-11-27 17:25:40 +05302682 }
2683 break;
2684 }
Mathew Joseph Karimpanal71ac8a72018-09-25 22:27:22 +05302685
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +05302686 // find an empty slot to create display.
2687 for (auto &map_info : map_info_pluggable_) {
Padmanabhan Komanduruf5b7f992019-07-08 13:33:44 +05302688 client_id = map_info.client_id;
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +05302689
2690 // Lock confined to this scope
2691 {
2692 SCOPE_LOCK(locker_[client_id]);
2693 auto &hwc_display = hwc_display_[client_id];
2694 if (hwc_display) {
Mathew Joseph Karimpanalbbc700b2018-07-19 19:54:24 +05302695 // Display slot is already used.
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +05302696 continue;
2697 }
2698
2699 DLOGI("Create pluggable display, sdm id = %d, client id = %d", info.display_id, client_id);
2700
2701 // Test pattern generation ?
2702 map_info.test_pattern = (hpd_bpp_ > 0) && (hpd_pattern_ > 0);
Mathew Joseph Karimpanal23e2da02018-11-13 17:44:43 +05302703 int err = 0;
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +05302704 if (!map_info.test_pattern) {
Mathew Joseph Karimpanal23e2da02018-11-13 17:44:43 +05302705 err = HWCDisplayPluggable::Create(core_intf_, &buffer_allocator_,
2706 &callbacks_, this, qservice_, client_id,
2707 info.display_id, 0, 0, false, &hwc_display);
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +05302708 } else {
Mathew Joseph Karimpanal23e2da02018-11-13 17:44:43 +05302709 err = HWCDisplayPluggableTest::Create(core_intf_, &buffer_allocator_,
2710 &callbacks_, this, qservice_, client_id,
2711 info.display_id, UINT32(hpd_bpp_),
2712 UINT32(hpd_pattern_), &hwc_display);
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +05302713 }
2714
Mathew Joseph Karimpanal23e2da02018-11-13 17:44:43 +05302715 if (err) {
Mathew Joseph Karimpanalabe3b3d2018-11-27 17:25:40 +05302716 DLOGW("Pluggable display creation failed/aborted. Error %d '%s'.", err,
2717 strerror(abs(err)));
Mathew Joseph Karimpanal23e2da02018-11-13 17:44:43 +05302718 status = err;
2719 // Attempt creating remaining pluggable displays.
2720 break;
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +05302721 }
2722
Pullakavi Srinivas1ae4acb2019-11-18 19:33:45 +05302723 {
2724 SCOPE_LOCK(hdr_locker_[client_id]);
2725 is_hdr_display_[UINT32(client_id)] = HasHDRSupport(hwc_display);
2726 }
2727
Mathew Joseph Karimpanalbbc700b2018-07-19 19:54:24 +05302728 DLOGI("Created pluggable display successfully: sdm id = %d, client id = %d",
2729 info.display_id, client_id);
Srinivas Pullakavi3c4337f2019-07-03 11:24:31 +05302730 CreateDummyDisplay(client_id);
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +05302731 }
2732
2733 map_info.disp_type = info.display_type;
2734 map_info.sdm_id = info.display_id;
2735
2736 pending_hotplugs.push_back((hwc2_display_t)client_id);
2737
2738 // Display is created for this sdm id, move to next connected display.
2739 break;
2740 }
2741 }
2742
2743 // No display was created.
2744 if (!pending_hotplugs.size()) {
Mathew Joseph Karimpanal23e2da02018-11-13 17:44:43 +05302745 return status;
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +05302746 }
2747
Ramkumar Radhakrishnan44c64362018-12-12 13:03:59 -08002748 // Active builtin display needs revalidation
2749 hwc2_display_t active_builtin_disp_id = GetActiveBuiltinDisplay();
Padmanabhan Komandurue74cf4f2019-04-25 17:38:43 -07002750 if (active_builtin_disp_id < HWCCallbacks::kNumDisplays) {
Padmanabhan Komanduruf5b7f992019-07-08 13:33:44 +05302751 WaitForResources(delay_hotplug, active_builtin_disp_id, client_id);
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +05302752 }
2753
2754 for (auto client_id : pending_hotplugs) {
Mathew Joseph Karimpanalbbc700b2018-07-19 19:54:24 +05302755 DLOGI("Notify hotplug display connected: client id = %d", client_id);
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +05302756 callbacks_.Hotplug(client_id, HWC2::Connection::Connected);
2757 }
2758
Mathew Joseph Karimpanal23e2da02018-11-13 17:44:43 +05302759 return status;
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +05302760}
2761
Archit Srivastavafe060f72019-05-27 15:51:58 +05302762bool HWCSession::HasHDRSupport(HWCDisplay *hwc_display) {
2763 // query number of hdr types
2764 uint32_t out_num_types = 0;
2765 float out_max_luminance = 0.0f;
2766 float out_max_average_luminance = 0.0f;
2767 float out_min_luminance = 0.0f;
2768 if (hwc_display->GetHdrCapabilities(&out_num_types, nullptr, &out_max_luminance,
2769 &out_max_average_luminance, &out_min_luminance)
2770 != HWC2::Error::None) {
2771 return false;
2772 }
2773
2774 return (out_num_types > 0);
2775}
2776
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +05302777int HWCSession::HandleDisconnectedDisplays(HWDisplaysInfo *hw_displays_info) {
2778 // Destroy pluggable displays which were connected earlier but got disconnected now.
2779 for (auto &map_info : map_info_pluggable_) {
2780 bool disconnect = true; // disconnect in case display id is not found in list.
2781
2782 for (auto &iter : *hw_displays_info) {
2783 auto &info = iter.second;
2784 if (info.display_id != map_info.sdm_id) {
2785 continue;
2786 }
2787 if (info.is_connected) {
2788 disconnect = false;
2789 }
Mathew Joseph Karimpanalbbc700b2018-07-19 19:54:24 +05302790 break;
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +05302791 }
2792
2793 if (disconnect) {
Mathew Joseph Karimpanal71ac8a72018-09-25 22:27:22 +05302794 DestroyDisplay(&map_info);
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +05302795 }
2796 }
2797
2798 return 0;
2799}
2800
2801void HWCSession::DestroyDisplay(DisplayMapInfo *map_info) {
Ramakant Singh07254e02018-10-31 20:45:01 +05302802 switch (map_info->disp_type) {
2803 case kPluggable:
2804 DestroyPluggableDisplay(map_info);
2805 break;
2806 default:
2807 DestroyNonPluggableDisplay(map_info);
2808 break;
2809 }
2810}
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +05302811
Ramakant Singh07254e02018-10-31 20:45:01 +05302812void HWCSession::DestroyPluggableDisplay(DisplayMapInfo *map_info) {
2813 hwc2_display_t client_id = map_info->client_id;
2814
2815 DLOGI("Notify hotplug display disconnected: client id = %d", client_id);
2816 callbacks_.Hotplug(client_id, HWC2::Connection::Disconnected);
Rajavenu Kyatham418acc22019-02-25 15:36:25 +05302817
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +05302818 {
2819 SCOPE_LOCK(locker_[client_id]);
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +05302820 auto &hwc_display = hwc_display_[client_id];
2821 if (!hwc_display) {
2822 return;
2823 }
Mathew Joseph Karimpanalbbc700b2018-07-19 19:54:24 +05302824 DLOGI("Destroy display %d-%d, client id = %d", map_info->sdm_id, map_info->disp_type,
Ramakant Singh07254e02018-10-31 20:45:01 +05302825 client_id);
Pullakavi Srinivas1ae4acb2019-11-18 19:33:45 +05302826 {
2827 SCOPE_LOCK(hdr_locker_[client_id]);
2828 is_hdr_display_[UINT32(client_id)] = false;
2829 }
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +05302830
Ramakant Singh07254e02018-10-31 20:45:01 +05302831 if (!map_info->test_pattern) {
2832 HWCDisplayPluggable::Destroy(hwc_display);
2833 } else {
2834 HWCDisplayPluggableTest::Destroy(hwc_display);
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +05302835 }
Ramakant Singh07254e02018-10-31 20:45:01 +05302836
Srinivas Pullakavi3c4337f2019-07-03 11:24:31 +05302837 if (async_powermode_) {
2838 hwc2_display_t dummy_disp_id = map_hwc_display_.find(client_id)->second;
2839 auto &hwc_display_dummy = hwc_display_[dummy_disp_id];
2840 display_ready_.reset(UINT32(dummy_disp_id));
2841 if (hwc_display_dummy) {
2842 HWCDisplayDummy::Destroy(hwc_display_dummy);
2843 hwc_display_dummy = nullptr;
2844 }
2845 }
2846 display_ready_.reset(UINT32(client_id));
Rajavenu Kyathamb0352242019-12-17 12:08:55 +05302847 pending_power_mode_[client_id] = false;
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +05302848 hwc_display = nullptr;
2849 map_info->Reset();
2850 }
Ramakant Singh07254e02018-10-31 20:45:01 +05302851}
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +05302852
Ramakant Singh07254e02018-10-31 20:45:01 +05302853void HWCSession::DestroyNonPluggableDisplay(DisplayMapInfo *map_info) {
2854 hwc2_display_t client_id = map_info->client_id;
2855
2856 SCOPE_LOCK(locker_[client_id]);
2857 auto &hwc_display = hwc_display_[client_id];
2858 if (!hwc_display) {
2859 return;
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +05302860 }
Ramakant Singh07254e02018-10-31 20:45:01 +05302861 DLOGI("Destroy display %d-%d, client id = %d", map_info->sdm_id, map_info->disp_type,
2862 client_id);
Pullakavi Srinivas1ae4acb2019-11-18 19:33:45 +05302863 {
2864 SCOPE_LOCK(hdr_locker_[client_id]);
2865 is_hdr_display_[UINT32(client_id)] = false;
2866 }
2867
Ramakant Singh07254e02018-10-31 20:45:01 +05302868 switch (map_info->disp_type) {
2869 case kBuiltIn:
2870 HWCDisplayBuiltIn::Destroy(hwc_display);
2871 break;
2872 default:
Pullakavi Srinivas17495f12019-09-16 20:25:20 +05302873 virtual_display_factory_.Destroy(hwc_display);
Ramakant Singh07254e02018-10-31 20:45:01 +05302874 break;
2875 }
2876
Srinivas Pullakavi3c4337f2019-07-03 11:24:31 +05302877 if (async_powermode_ && map_info->disp_type == kBuiltIn) {
2878 hwc2_display_t dummy_disp_id = map_hwc_display_.find(client_id)->second;
2879 auto &hwc_display_dummy = hwc_display_[dummy_disp_id];
2880 display_ready_.reset(UINT32(dummy_disp_id));
2881 if (hwc_display_dummy) {
2882 HWCDisplayDummy::Destroy(hwc_display_dummy);
2883 hwc_display_dummy = nullptr;
2884 }
2885 }
Rajavenu Kyathamb0352242019-12-17 12:08:55 +05302886 pending_power_mode_[client_id] = false;
Ramakant Singh07254e02018-10-31 20:45:01 +05302887 hwc_display = nullptr;
Srinivas Pullakavi3c4337f2019-07-03 11:24:31 +05302888 display_ready_.reset(UINT32(client_id));
Ramakant Singh07254e02018-10-31 20:45:01 +05302889 map_info->Reset();
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +05302890}
Saurabh Shah04f932b2017-10-12 18:47:45 -07002891
Sushil Chauhane3a9fd02017-10-12 18:00:05 -07002892HWC2::Error HWCSession::ValidateDisplayInternal(hwc2_display_t display, uint32_t *out_num_types,
2893 uint32_t *out_num_requests) {
2894 HWCDisplay *hwc_display = hwc_display_[display];
Gurpreet Singh Dhamia4276882019-04-12 10:30:58 -07002895
2896 DTRACE_SCOPED();
Sushil Chauhane3a9fd02017-10-12 18:00:05 -07002897 if (hwc_display->IsInternalValidateState()) {
2898 // Internal Validation has already been done on display, get the Output params.
2899 return hwc_display->GetValidateDisplayOutput(out_num_types, out_num_requests);
2900 }
2901
2902 if (display == HWC_DISPLAY_PRIMARY) {
2903 // TODO(user): This can be moved to HWCDisplayPrimary
Sushil Chauhane3a9fd02017-10-12 18:00:05 -07002904 if (need_invalidate_) {
Varun Aroradff7d8d2019-08-05 18:12:43 -07002905 callbacks_.Refresh(display);
Sushil Chauhane3a9fd02017-10-12 18:00:05 -07002906 need_invalidate_ = false;
2907 }
2908
2909 if (color_mgr_) {
2910 color_mgr_->SetColorModeDetailEnhancer(hwc_display_[display]);
2911 }
2912 }
2913
2914 return hwc_display->Validate(out_num_types, out_num_requests);
2915}
2916
Dileep Marchyaad668432019-12-02 10:44:52 +05302917HWC2::Error HWCSession::PresentDisplayInternal(hwc2_display_t display) {
Sushil Chauhane3a9fd02017-10-12 18:00:05 -07002918 HWCDisplay *hwc_display = hwc_display_[display];
Gurpreet Singh Dhamia4276882019-04-12 10:30:58 -07002919
2920 DTRACE_SCOPED();
Sushil Chauhane3a9fd02017-10-12 18:00:05 -07002921 // If display is in Skip-Validate state and Validate cannot be skipped, do Internal
2922 // Validation to optimize for the frames which don't require the Client composition.
2923 if (hwc_display->IsSkipValidateState() && !hwc_display->CanSkipValidate()) {
2924 uint32_t out_num_types = 0, out_num_requests = 0;
Sushil Chauhan7bd20662018-08-20 17:51:32 -07002925 hwc_display->SetFastPathComposition(true);
Sushil Chauhane3a9fd02017-10-12 18:00:05 -07002926 HWC2::Error error = ValidateDisplayInternal(display, &out_num_types, &out_num_requests);
Sushil Chauhan181d9502018-12-13 16:40:58 -08002927 if ((error != HWC2::Error::None) || hwc_display->HWCClientNeedsValidate()) {
Sushil Chauhane3a9fd02017-10-12 18:00:05 -07002928 hwc_display->SetValidationState(HWCDisplay::kInternalValidate);
Sushil Chauhan7bd20662018-08-20 17:51:32 -07002929 hwc_display->SetFastPathComposition(false);
Sushil Chauhane3a9fd02017-10-12 18:00:05 -07002930 return HWC2::Error::NotValidated;
2931 }
2932 }
Padmanabhan Komandurue74cf4f2019-04-25 17:38:43 -07002933 return HWC2::Error::None;
Sushil Chauhane3a9fd02017-10-12 18:00:05 -07002934}
2935
Varun Arora7c8ee542018-05-01 20:58:16 -07002936void HWCSession::DisplayPowerReset() {
Mathew Joseph Karimpanal8abb6e02018-11-20 09:52:49 +05302937 // Acquire lock on all displays.
Padmanabhan Komandurue74cf4f2019-04-25 17:38:43 -07002938 for (hwc2_display_t display = HWC_DISPLAY_PRIMARY;
2939 display < HWCCallbacks::kNumDisplays; display++) {
Mathew Joseph Karimpanal8abb6e02018-11-20 09:52:49 +05302940 locker_[display].Lock();
2941 }
Varun Arora7c8ee542018-05-01 20:58:16 -07002942
Mathew Joseph Karimpanal8abb6e02018-11-20 09:52:49 +05302943 HWC2::Error status = HWC2::Error::None;
Padmanabhan Komandurue74cf4f2019-04-25 17:38:43 -07002944 HWC2::PowerMode last_power_mode[HWCCallbacks::kNumDisplays] = {};
Varun Arora7c8ee542018-05-01 20:58:16 -07002945
Padmanabhan Komandurue74cf4f2019-04-25 17:38:43 -07002946 for (hwc2_display_t display = HWC_DISPLAY_PRIMARY;
2947 display < HWCCallbacks::kNumDisplays; display++) {
Mathew Joseph Karimpanal8abb6e02018-11-20 09:52:49 +05302948 if (hwc_display_[display] != NULL) {
2949 last_power_mode[display] = hwc_display_[display]->GetCurrentPowerMode();
2950 DLOGI("Powering off display = %d", display);
2951 status = hwc_display_[display]->SetPowerMode(HWC2::PowerMode::Off,
2952 true /* teardown */);
2953 if (status != HWC2::Error::None) {
2954 DLOGE("Power off for display = %d failed with error = %d", display, status);
Varun Arora7c8ee542018-05-01 20:58:16 -07002955 }
2956 }
Mathew Joseph Karimpanal8abb6e02018-11-20 09:52:49 +05302957 }
Padmanabhan Komandurue74cf4f2019-04-25 17:38:43 -07002958 for (hwc2_display_t display = HWC_DISPLAY_PRIMARY;
2959 display < HWCCallbacks::kNumDisplays; display++) {
Mathew Joseph Karimpanal8abb6e02018-11-20 09:52:49 +05302960 if (hwc_display_[display] != NULL) {
2961 HWC2::PowerMode mode = last_power_mode[display];
2962 DLOGI("Setting display %d to mode = %d", display, mode);
2963 status = hwc_display_[display]->SetPowerMode(mode, false /* teardown */);
2964 if (status != HWC2::Error::None) {
2965 DLOGE("%d mode for display = %d failed with error = %d", mode, display, status);
2966 }
2967 ColorMode color_mode = hwc_display_[display]->GetCurrentColorMode();
2968 status = hwc_display_[display]->SetColorMode(color_mode);
2969 if (status != HWC2::Error::None) {
2970 DLOGE("SetColorMode failed for display = %d error = %d", display, status);
Varun Arora7c8ee542018-05-01 20:58:16 -07002971 }
2972 }
Mathew Joseph Karimpanal8abb6e02018-11-20 09:52:49 +05302973 }
Varun Arora7c8ee542018-05-01 20:58:16 -07002974
Padmanabhan Komanduruf5e6c5d2019-04-04 13:56:31 +05302975 hwc2_display_t vsync_source = callbacks_.GetVsyncSource();
Pullakavi Srinivasf2a31852019-04-23 14:32:08 -07002976 status = hwc_display_[vsync_source]->SetVsyncEnabled(HWC2::Vsync::Enable);
Mathew Joseph Karimpanal8abb6e02018-11-20 09:52:49 +05302977 if (status != HWC2::Error::None) {
Pullakavi Srinivasf2a31852019-04-23 14:32:08 -07002978 DLOGE("Enabling vsync failed for disp: %" PRIu64 " with error = %d", vsync_source, status);
Mathew Joseph Karimpanal8abb6e02018-11-20 09:52:49 +05302979 }
2980
2981 // Release lock on all displays.
Padmanabhan Komandurue74cf4f2019-04-25 17:38:43 -07002982 for (hwc2_display_t display = HWC_DISPLAY_PRIMARY;
2983 display < HWCCallbacks::kNumDisplays; display++) {
Mathew Joseph Karimpanal8abb6e02018-11-20 09:52:49 +05302984 locker_[display].Unlock();
Varun Arora7c8ee542018-05-01 20:58:16 -07002985 }
Pullakavi Srinivasf2a31852019-04-23 14:32:08 -07002986
Varun Aroradff7d8d2019-08-05 18:12:43 -07002987 callbacks_.Refresh(vsync_source);
Varun Arora7c8ee542018-05-01 20:58:16 -07002988}
Ramkumar Radhakrishnana38b7602018-03-15 14:49:52 -07002989
Ramkumar Radhakrishnan44c64362018-12-12 13:03:59 -08002990void HWCSession::HandleSecureSession() {
Mathew Joseph Karimpanal71ac8a72018-09-25 22:27:22 +05302991 std::bitset<kSecureMax> secure_sessions = 0;
2992 {
Mathew Joseph Karimpanalb1c15862019-07-04 11:14:24 +05302993 // TODO(user): Revisit if supporting secure display on non-primary.
Ramkumar Radhakrishnan44c64362018-12-12 13:03:59 -08002994 hwc2_display_t active_builtin_disp_id = GetActiveBuiltinDisplay();
Padmanabhan Komandurue74cf4f2019-04-25 17:38:43 -07002995 if (active_builtin_disp_id >= HWCCallbacks::kNumDisplays) {
Ramkumar Radhakrishnan44c64362018-12-12 13:03:59 -08002996 return;
Mathew Joseph Karimpanal71ac8a72018-09-25 22:27:22 +05302997 }
Mathew Joseph Karimpanalb1c15862019-07-04 11:14:24 +05302998 Locker::ScopeLock lock_pwr(power_state_[active_builtin_disp_id]);
2999 if (power_state_transition_[active_builtin_disp_id]) {
3000 // Route all interactions with client to dummy display.
3001 active_builtin_disp_id = map_hwc_display_.find(active_builtin_disp_id)->second;
3002 }
3003 Locker::ScopeLock lock_d(locker_[active_builtin_disp_id]);
Ramkumar Radhakrishnan44c64362018-12-12 13:03:59 -08003004 hwc_display_[active_builtin_disp_id]->GetActiveSecureSession(&secure_sessions);
Ramkumar Radhakrishnana38b7602018-03-15 14:49:52 -07003005 }
3006
Mathew Joseph Karimpanalb1c15862019-07-04 11:14:24 +05303007 if (secure_sessions.any()) {
3008 secure_session_active_ = true;
3009 } else if (!secure_session_active_) {
3010 // No secure session active. No secure session transition to handle. Skip remaining steps.
3011 return;
3012 }
3013
Ramkumar Radhakrishnan44c64362018-12-12 13:03:59 -08003014 // If it is called during primary prepare/commit, we need to pause any ongoing commit on
Ramkumar Radhakrishnana38b7602018-03-15 14:49:52 -07003015 // external/virtual display.
Padmanabhan Komandurue74cf4f2019-04-25 17:38:43 -07003016 for (hwc2_display_t display = HWC_DISPLAY_PRIMARY;
3017 display < HWCCallbacks::kNumDisplays; display++) {
Mathew Joseph Karimpanal8abb6e02018-11-20 09:52:49 +05303018 Locker::ScopeLock lock_d(locker_[display]);
3019 if (hwc_display_[display]) {
Mathew Joseph Karimpanalb1c15862019-07-04 11:14:24 +05303020 hwc_display_[display]->HandleSecureSession(secure_sessions, &pending_power_mode_[display]);
Ramkumar Radhakrishnana38b7602018-03-15 14:49:52 -07003021 }
Ramkumar Radhakrishnana38b7602018-03-15 14:49:52 -07003022 }
3023}
3024
Dileep Marchyaad668432019-12-02 10:44:52 +05303025void HWCSession::HandlePendingPowerMode(hwc2_display_t disp_id,
3026 const shared_ptr<Fence> &retire_fence) {
Mathew Joseph Karimpanalb1c15862019-07-04 11:14:24 +05303027 if (!secure_session_active_) {
3028 // No secure session active. Skip remaining steps.
3029 return;
3030 }
3031
Ramkumar Radhakrishnan44c64362018-12-12 13:03:59 -08003032 hwc2_display_t active_builtin_disp_id = GetActiveBuiltinDisplay();
3033 if (disp_id != active_builtin_disp_id) {
Ramkumar Radhakrishnana38b7602018-03-15 14:49:52 -07003034 return;
3035 }
Mathew Joseph Karimpanal71ac8a72018-09-25 22:27:22 +05303036
Mathew Joseph Karimpanalb1c15862019-07-04 11:14:24 +05303037 Locker::ScopeLock lock_d(locker_[active_builtin_disp_id]);
3038 bool pending_power_mode = false;
3039 for (hwc2_display_t display = HWC_DISPLAY_PRIMARY + 1;
Padmanabhan Komandurue74cf4f2019-04-25 17:38:43 -07003040 display < HWCCallbacks::kNumDisplays; display++) {
Ramkumar Radhakrishnan44c64362018-12-12 13:03:59 -08003041 if (display != active_builtin_disp_id) {
3042 Locker::ScopeLock lock_d(locker_[display]);
Mathew Joseph Karimpanalb1c15862019-07-04 11:14:24 +05303043 if (pending_power_mode_[display]) {
3044 pending_power_mode = true;
Ramkumar Radhakrishnan44c64362018-12-12 13:03:59 -08003045 break;
3046 }
Ramkumar Radhakrishnana38b7602018-03-15 14:49:52 -07003047 }
3048 }
Dileep Marchyaad668432019-12-02 10:44:52 +05303049
3050 if (!pending_power_mode) {
Mathew Joseph Karimpanal71ac8a72018-09-25 22:27:22 +05303051 return;
Ramkumar Radhakrishnana38b7602018-03-15 14:49:52 -07003052 }
3053
Dileep Marchyaad668432019-12-02 10:44:52 +05303054 // retire fence is set only after successful primary commit, So check for retire fence to know
3055 // non secure commit went through to notify driver to change the CRTC mode to non secure.
3056 // Otherwise any commit to non-primary display would fail.
3057 if (retire_fence == nullptr) {
3058 return;
3059 }
3060
3061 Fence::Wait(retire_fence);
3062
Mathew Joseph Karimpanalb1c15862019-07-04 11:14:24 +05303063 for (hwc2_display_t display = HWC_DISPLAY_PRIMARY + 1;
Padmanabhan Komandurue74cf4f2019-04-25 17:38:43 -07003064 display < HWCCallbacks::kNumDisplays; display++) {
Ramkumar Radhakrishnan44c64362018-12-12 13:03:59 -08003065 if (display != active_builtin_disp_id) {
3066 Locker::ScopeLock lock_d(locker_[display]);
Mathew Joseph Karimpanalb1c15862019-07-04 11:14:24 +05303067 if (pending_power_mode_[display] && hwc_display_[display]) {
3068 HWC2::Error error =
3069 hwc_display_[display]->SetPowerMode(hwc_display_[display]->GetPendingPowerMode(), false);
3070 if (HWC2::Error::None == error) {
3071 pending_power_mode_[display] = false;
3072 hwc_display_[display]->ClearPendingPowerMode();
3073 pending_refresh_.set(UINT32(HWC_DISPLAY_PRIMARY));
3074 } else {
3075 DLOGE("SetDisplayStatus error = %d (%s)", error, to_string(error).c_str());
Ramkumar Radhakrishnan44c64362018-12-12 13:03:59 -08003076 }
Ramkumar Radhakrishnana38b7602018-03-15 14:49:52 -07003077 }
3078 }
3079 }
Mathew Joseph Karimpanalb1c15862019-07-04 11:14:24 +05303080 secure_session_active_ = false;
Ramkumar Radhakrishnana38b7602018-03-15 14:49:52 -07003081}
3082
Dileep Marchyaad668432019-12-02 10:44:52 +05303083void HWCSession::HandlePendingHotplug(hwc2_display_t disp_id,
3084 const shared_ptr<Fence> &retire_fence) {
Ramkumar Radhakrishnan44c64362018-12-12 13:03:59 -08003085 hwc2_display_t active_builtin_disp_id = GetActiveBuiltinDisplay();
3086 if (disp_id != active_builtin_disp_id ||
Mathew Joseph Karimpanalb1c15862019-07-04 11:14:24 +05303087 (kHotPlugNone == pending_hotplug_event_ && !destroy_virtual_disp_pending_)) {
Ramkumar Radhakrishnana38b7602018-03-15 14:49:52 -07003088 return;
3089 }
Rajavenu Kyathame45d1b72018-06-27 14:46:44 +05303090
Ramkumar Radhakrishnana38b7602018-03-15 14:49:52 -07003091 std :: bitset < kSecureMax > secure_sessions = 0;
Padmanabhan Komandurue74cf4f2019-04-25 17:38:43 -07003092 if (active_builtin_disp_id < HWCCallbacks::kNumDisplays) {
Mathew Joseph Karimpanalb1c15862019-07-04 11:14:24 +05303093 Locker::ScopeLock lock_d(locker_[active_builtin_disp_id]);
Ramkumar Radhakrishnan44c64362018-12-12 13:03:59 -08003094 hwc_display_[active_builtin_disp_id]->GetActiveSecureSession(&secure_sessions);
3095 }
3096
Padmanabhan Komandurue74cf4f2019-04-25 17:38:43 -07003097 if (secure_sessions.any() || active_builtin_disp_id >= HWCCallbacks::kNumDisplays) {
Ramkumar Radhakrishnan44c64362018-12-12 13:03:59 -08003098 return;
3099 }
3100
Mathew Joseph Karimpanalb1c15862019-07-04 11:14:24 +05303101 if (destroy_virtual_disp_pending_ || kHotPlugEvent == pending_hotplug_event_) {
Dileep Marchyaad668432019-12-02 10:44:52 +05303102 Fence::Wait(retire_fence);
3103
Ramkumar Radhakrishnan44c64362018-12-12 13:03:59 -08003104 // Destroy the pending virtual display if secure session not present.
3105 if (destroy_virtual_disp_pending_) {
3106 for (auto &map_info : map_info_virtual_) {
3107 DestroyDisplay(&map_info);
3108 destroy_virtual_disp_pending_ = false;
Padmanabhan Komanduruf5b7f992019-07-08 13:33:44 +05303109 virtual_id_ = HWCCallbacks::kNumDisplays;
Ramkumar Radhakrishnan44c64362018-12-12 13:03:59 -08003110 }
Ramkumar Radhakrishnana38b7602018-03-15 14:49:52 -07003111 }
Ramkumar Radhakrishnan44c64362018-12-12 13:03:59 -08003112 // Handle connect/disconnect hotplugs if secure session is not present.
3113 hwc2_display_t virtual_display_idx = (hwc2_display_t)GetDisplayIndex(qdutils::DISPLAY_VIRTUAL);
Mathew Joseph Karimpanalb1c15862019-07-04 11:14:24 +05303114 if (!hwc_display_[virtual_display_idx] && kHotPlugEvent == pending_hotplug_event_) {
Mathew Joseph Karimpanalabe3b3d2018-11-27 17:25:40 +05303115 // Handle deferred hotplug event.
3116 int32_t err = pluggable_handler_lock_.TryLock();
3117 if (!err) {
3118 // Do hotplug handling in a different thread to avoid blocking PresentDisplay.
3119 std::thread(&HWCSession::HandlePluggableDisplays, this, true).detach();
3120 pluggable_handler_lock_.Unlock();
3121 } else {
3122 // EBUSY means another thread is already handling hotplug. Skip deferred hotplug handling.
3123 if (EBUSY != err) {
3124 DLOGW("Failed to acquire pluggable display handler lock. Error %d '%s'.", err,
3125 strerror(abs(err)));
3126 }
Ramkumar Radhakrishnan44c64362018-12-12 13:03:59 -08003127 }
Mathew Joseph Karimpanal71ac8a72018-09-25 22:27:22 +05303128 }
Mathew Joseph Karimpanal71ac8a72018-09-25 22:27:22 +05303129 }
Ramkumar Radhakrishnana38b7602018-03-15 14:49:52 -07003130}
3131
Rajavenu Kyatham42d11cb2019-04-16 13:03:29 +05303132int32_t HWCSession::GetReadbackBufferAttributes(hwc2_display_t display, int32_t *format,
3133 int32_t *dataspace) {
3134 if (!format || !dataspace) {
Sushil Chauhan06521582018-03-19 14:00:23 -07003135 return HWC2_ERROR_BAD_PARAMETER;
3136 }
3137
3138 if (display != HWC_DISPLAY_PRIMARY) {
3139 return HWC2_ERROR_BAD_DISPLAY;
3140 }
3141
Rajavenu Kyatham42d11cb2019-04-16 13:03:29 +05303142 HWCDisplay *hwc_display = hwc_display_[display];
Sushil Chauhan06521582018-03-19 14:00:23 -07003143
Sushil Chauhanfea3e902018-07-31 15:34:48 -07003144 if (hwc_display) {
3145 *format = HAL_PIXEL_FORMAT_RGB_888;
Arun Kumar K.R5b821552018-12-07 08:00:15 +05303146 *dataspace = GetDataspaceFromColorMode(hwc_display->GetCurrentColorMode());
Sushil Chauhanfea3e902018-07-31 15:34:48 -07003147 return HWC2_ERROR_NONE;
3148 }
3149
3150 return HWC2_ERROR_BAD_DISPLAY;
Sushil Chauhan06521582018-03-19 14:00:23 -07003151}
3152
Rajavenu Kyatham42d11cb2019-04-16 13:03:29 +05303153int32_t HWCSession::SetReadbackBuffer(hwc2_display_t display, const native_handle_t *buffer,
Rajavenu Kyatham7338b9e2019-12-30 19:52:16 +05303154 const shared_ptr<Fence> &acquire_fence) {
Sushil Chauhan06521582018-03-19 14:00:23 -07003155 if (!buffer) {
3156 return HWC2_ERROR_BAD_PARAMETER;
3157 }
3158
3159 if (display != HWC_DISPLAY_PRIMARY) {
3160 return HWC2_ERROR_BAD_DISPLAY;
3161 }
3162
Sushil Chauhan0a1b15d2019-08-23 12:58:18 -07003163 int external_dpy_index = GetDisplayIndex(qdutils::DISPLAY_EXTERNAL);
3164 int virtual_dpy_index = GetDisplayIndex(qdutils::DISPLAY_VIRTUAL);
3165 if (((external_dpy_index != -1) && hwc_display_[external_dpy_index]) ||
3166 ((virtual_dpy_index != -1) && hwc_display_[virtual_dpy_index])) {
Sushil Chauhan062a7a42018-04-25 22:27:52 -07003167 return HWC2_ERROR_UNSUPPORTED;
3168 }
3169
Rajavenu Kyatham42d11cb2019-04-16 13:03:29 +05303170 return CallDisplayFunction(display, &HWCDisplay::SetReadbackBuffer, buffer, acquire_fence,
Dileep Marchyacb2a3a92019-06-21 17:30:50 +05303171 false, kCWBClientComposer);
Sushil Chauhan06521582018-03-19 14:00:23 -07003172}
3173
Rajavenu Kyatham7338b9e2019-12-30 19:52:16 +05303174int32_t HWCSession::GetReadbackBufferFence(hwc2_display_t display,
3175 shared_ptr<Fence> *release_fence) {
Sushil Chauhan06521582018-03-19 14:00:23 -07003176 if (!release_fence) {
3177 return HWC2_ERROR_BAD_PARAMETER;
3178 }
3179
3180 if (display != HWC_DISPLAY_PRIMARY) {
3181 return HWC2_ERROR_BAD_DISPLAY;
3182 }
3183
Rajavenu Kyatham42d11cb2019-04-16 13:03:29 +05303184 return CallDisplayFunction(display, &HWCDisplay::GetReadbackBufferFence, release_fence);
Sushil Chauhan06521582018-03-19 14:00:23 -07003185}
3186
Rajavenu Kyatham42d11cb2019-04-16 13:03:29 +05303187int32_t HWCSession::GetDisplayIdentificationData(hwc2_display_t display, uint8_t *outPort,
3188 uint32_t *outDataSize, uint8_t *outData) {
Varun Arora6ba9eda2019-02-07 17:59:32 -08003189 if (!outPort || !outDataSize) {
3190 return HWC2_ERROR_BAD_PARAMETER;
3191 }
3192
Padmanabhan Komandurue74cf4f2019-04-25 17:38:43 -07003193 if (display >= HWCCallbacks::kNumDisplays) {
Varun Arora6ba9eda2019-02-07 17:59:32 -08003194 return HWC2_ERROR_BAD_DISPLAY;
3195 }
3196
Rajavenu Kyatham42d11cb2019-04-16 13:03:29 +05303197 return CallDisplayFunction(display, &HWCDisplay::GetDisplayIdentificationData, outPort,
Varun Arora6ba9eda2019-02-07 17:59:32 -08003198 outDataSize, outData);
3199}
3200
Naseer Ahmed8584a0f2020-02-19 22:23:30 -05003201int32_t HWCSession::GetDisplayCapabilities(hwc2_display_t display,
3202 hidl_vec<HwcDisplayCapability> *capabilities) {
3203 if (!capabilities) {
Varun Arora9da54ef2019-05-03 16:17:22 -07003204 return HWC2_ERROR_BAD_PARAMETER;
3205 }
3206
3207 if (display >= HWCCallbacks::kNumDisplays) {
3208 return HWC2_ERROR_BAD_DISPLAY;
3209 }
3210
Rajavenu Kyatham42d11cb2019-04-16 13:03:29 +05303211 if (!hwc_display_[display]) {
Varun Arora9da54ef2019-05-03 16:17:22 -07003212 DLOGE("Expected valid hwc_display");
3213 return HWC2_ERROR_BAD_PARAMETER;
3214 }
Naseer Ahmed8584a0f2020-02-19 22:23:30 -05003215
Rajavenu Kyatham42d11cb2019-04-16 13:03:29 +05303216 bool isBuiltin = (hwc_display_[display]->GetDisplayClass() == DISPLAY_CLASS_BUILTIN);
Naseer Ahmed8584a0f2020-02-19 22:23:30 -05003217 if (isBuiltin) {
3218 capabilities->resize(4);
3219 // TODO(user): Handle SKIP_CLIENT_COLOR_TRANSFORM based on DSPP availability
3220 std::vector<HwcDisplayCapability> caps{
3221 HwcDisplayCapability::SKIP_CLIENT_COLOR_TRANSFORM, HwcDisplayCapability::DOZE,
3222 HwcDisplayCapability::BRIGHTNESS, HwcDisplayCapability::PROTECTED_CONTENTS};
3223 capabilities->setToExternal(caps.data(), caps.size());
Varun Arora9da54ef2019-05-03 16:17:22 -07003224 }
Naseer Ahmed8584a0f2020-02-19 22:23:30 -05003225 return HWC2_ERROR_NONE;
3226}
3227
3228int32_t HWCSession::GetDisplayConnectionType(hwc2_display_t display,
3229 HwcDisplayConnectionType *type) {
3230 if (display >= HWCCallbacks::kNumDisplays) {
3231 return HWC2_ERROR_BAD_DISPLAY;
3232 }
3233
3234 if (!type) {
3235 return HWC2_ERROR_BAD_PARAMETER;
3236 }
3237
3238 if (!hwc_display_[display]) {
3239 DLOGE("Expected valid hwc_display");
3240 return HWC2_ERROR_BAD_PARAMETER;
3241 }
3242 *type = HwcDisplayConnectionType::EXTERNAL;
3243 if (hwc_display_[display]->GetDisplayClass() == DISPLAY_CLASS_BUILTIN) {
3244 *type = HwcDisplayConnectionType::INTERNAL;
3245 }
3246
3247 return HWC2_ERROR_NONE;
Varun Arora9da54ef2019-05-03 16:17:22 -07003248}
3249
Rajavenu Kyatham42d11cb2019-04-16 13:03:29 +05303250int32_t HWCSession::GetDisplayBrightnessSupport(hwc2_display_t display, bool *outSupport) {
3251 if (!outSupport) {
Varun Arora9da54ef2019-05-03 16:17:22 -07003252 return HWC2_ERROR_BAD_PARAMETER;
3253 }
3254
3255 if (display >= HWCCallbacks::kNumDisplays) {
3256 return HWC2_ERROR_BAD_DISPLAY;
3257 }
3258
Rajavenu Kyatham42d11cb2019-04-16 13:03:29 +05303259 if (!hwc_display_[display]) {
Varun Arora9da54ef2019-05-03 16:17:22 -07003260 DLOGE("Expected valid hwc_display");
3261 return HWC2_ERROR_BAD_PARAMETER;
3262 }
Rajavenu Kyatham42d11cb2019-04-16 13:03:29 +05303263 *outSupport = (hwc_display_[display]->GetDisplayClass() == DISPLAY_CLASS_BUILTIN);
Varun Arora9da54ef2019-05-03 16:17:22 -07003264 return HWC2_ERROR_NONE;
3265}
3266
Rajavenu Kyatham42d11cb2019-04-16 13:03:29 +05303267int32_t HWCSession::SetDisplayBrightness(hwc2_display_t display, float brightness) {
Sushil Chauhanab3c5c52019-07-12 14:54:29 -07003268 if (display >= HWCCallbacks::kNumDisplays) {
3269 return HWC2_ERROR_BAD_DISPLAY;
3270 }
3271
3272 if (!hwc_display_[display]) {
3273 return HWC2_ERROR_BAD_PARAMETER;
3274 }
3275
3276 return INT32(hwc_display_[display]->SetPanelBrightness(brightness));
Varun Arora75c05f02019-05-14 14:53:37 -07003277}
3278
Sushil Chauhan380a59d2018-03-19 15:47:50 -07003279android::status_t HWCSession::SetQSyncMode(const android::Parcel *input_parcel) {
3280 auto mode = input_parcel->readInt32();
Sushil Chauhan380a59d2018-03-19 15:47:50 -07003281
3282 QSyncMode qsync_mode = kQSyncModeNone;
3283 switch (mode) {
3284 case qService::IQService::QSYNC_MODE_NONE:
3285 qsync_mode = kQSyncModeNone;
3286 break;
3287 case qService::IQService::QSYNC_MODE_CONTINUOUS:
3288 qsync_mode = kQSyncModeContinuous;
3289 break;
3290 case qService::IQService::QSYNC_MODE_ONESHOT:
3291 qsync_mode = kQsyncModeOneShot;
3292 break;
3293 default:
3294 DLOGE("Qsync mode not supported %d", mode);
3295 return -EINVAL;
3296 }
Rajavenu Kyatham42d11cb2019-04-16 13:03:29 +05303297 return CallDisplayFunction(HWC_DISPLAY_PRIMARY, &HWCDisplay::SetQSyncMode, qsync_mode);
Sushil Chauhan380a59d2018-03-19 15:47:50 -07003298}
3299
Mahesh Aiaf3a1f992019-01-16 13:07:42 -08003300void HWCSession::UpdateThrottlingRate() {
3301 uint32_t new_min = 0;
3302
Padmanabhan Komandurue74cf4f2019-04-25 17:38:43 -07003303 for (int i=0; i < HWCCallbacks::kNumDisplays; i++) {
Mahesh Aiaf3a1f992019-01-16 13:07:42 -08003304 auto &display = hwc_display_[i];
3305 if (!display)
3306 continue;
3307 if (display->GetCurrentPowerMode() != HWC2::PowerMode::Off)
3308 new_min = (new_min == 0) ? display->GetMaxRefreshRate() :
3309 std::min(new_min, display->GetMaxRefreshRate());
3310 }
3311
3312 SetNewThrottlingRate(new_min);
3313}
3314
3315void HWCSession::SetNewThrottlingRate(const uint32_t new_rate) {
3316 if (new_rate !=0 && throttling_refresh_rate_ != new_rate) {
3317 HWCDisplay::SetThrottlingRefreshRate(new_rate);
3318 throttling_refresh_rate_ = new_rate;
3319 }
3320}
3321
Ramkumar Radhakrishnanf985d482018-07-23 18:10:41 -07003322android::status_t HWCSession::SetIdlePC(const android::Parcel *input_parcel) {
3323 auto enable = input_parcel->readInt32();
3324 auto synchronous = input_parcel->readInt32();
3325
Padmanabhan Komanduru9e971622020-02-10 13:09:34 +05303326 return static_cast<android::status_t>(ControlIdlePowerCollapse(enable, synchronous));
Ramkumar Radhakrishnanf985d482018-07-23 18:10:41 -07003327}
3328
Ramkumar Radhakrishnan44c64362018-12-12 13:03:59 -08003329hwc2_display_t HWCSession::GetActiveBuiltinDisplay() {
Mathew Joseph Karimpanalb1c15862019-07-04 11:14:24 +05303330 hwc2_display_t active_display = HWCCallbacks::kNumDisplays;
Mathew Joseph Karimpanal1d5a23f2019-04-25 15:46:11 -07003331 // Get first active display among primary and built-in displays.
3332 std::vector<DisplayMapInfo> map_info = {map_info_primary_};
3333 std::copy(map_info_builtin_.begin(), map_info_builtin_.end(), std::back_inserter(map_info));
3334
3335 for (auto &info : map_info) {
Mathew Joseph Karimpanalb1c15862019-07-04 11:14:24 +05303336 hwc2_display_t target_display = info.client_id;
3337 SCOPE_LOCK(power_state_[target_display]);
3338 if (power_state_transition_[target_display]) {
3339 // Route all interactions with client to dummy display.
3340 target_display = map_hwc_display_.find(target_display)->second;
3341 }
3342 Locker::ScopeLock lock_d(locker_[target_display]);
3343 auto &hwc_display = hwc_display_[target_display];
Mathew Joseph Karimpanal1d5a23f2019-04-25 15:46:11 -07003344 if (hwc_display && hwc_display->GetCurrentPowerMode() != HWC2::PowerMode::Off) {
Mathew Joseph Karimpanalb1c15862019-07-04 11:14:24 +05303345 active_display = info.client_id;
Mathew Joseph Karimpanal1d5a23f2019-04-25 15:46:11 -07003346 break;
3347 }
Ramkumar Radhakrishnan44c64362018-12-12 13:03:59 -08003348 }
Mathew Joseph Karimpanal1d5a23f2019-04-25 15:46:11 -07003349
Mathew Joseph Karimpanalb1c15862019-07-04 11:14:24 +05303350 return active_display;
Ramkumar Radhakrishnan44c64362018-12-12 13:03:59 -08003351}
3352
Xu Yang45d0abf2019-07-05 11:34:06 +08003353int32_t HWCSession::SetDisplayBrightnessScale(const android::Parcel *input_parcel) {
3354 auto display = input_parcel->readInt32();
3355 auto level = input_parcel->readInt32();
3356 if (level < 0 || level > kBrightnessScaleMax) {
3357 DLOGE("Invalid backlight scale level %d", level);
3358 return -EINVAL;
3359 }
3360 auto bl_scale = level * kSvBlScaleMax / kBrightnessScaleMax;
3361 auto error = CallDisplayFunction(display, &HWCDisplay::SetBLScale, (uint32_t)bl_scale);
3362 if (INT32(error) == HWC2_ERROR_NONE) {
3363 callbacks_.Refresh(display);
3364 }
3365
3366 return INT32(error);
3367}
3368
Pullakavi Srinivas2d55f3a2019-07-16 14:49:06 +05303369void HWCSession::NotifyClientStatus(bool connected) {
3370 for (uint32_t i = 0; i < HWCCallbacks::kNumDisplays; i++) {
3371 if (!hwc_display_[i]) {
3372 continue;
3373 }
3374 SCOPE_LOCK(locker_[i]);
3375 hwc_display_[i]->NotifyClientStatus(connected);
3376 }
3377}
3378
Padmanabhan Komanduruf5b7f992019-07-08 13:33:44 +05303379void HWCSession::WaitForResources(bool wait_for_resources, hwc2_display_t active_builtin_id,
3380 hwc2_display_t display_id) {
3381 {
3382 SEQUENCE_WAIT_SCOPE_LOCK(locker_[active_builtin_id]);
3383 hwc_display_[active_builtin_id]->ResetValidation();
3384 }
3385
3386 if (wait_for_resources) {
3387 bool res_wait = true;
3388 do {
3389 if (client_connected_) {
3390 Refresh(active_builtin_id);
3391 }
3392 {
3393 std::unique_lock<std::mutex> caller_lock(hotplug_mutex_);
3394 hotplug_cv_.wait(caller_lock);
3395 }
3396 res_wait = hwc_display_[display_id]->CheckResourceState();
3397 } while (res_wait);
3398 }
3399}
Padmanabhan Komanduru9e971622020-02-10 13:09:34 +05303400
Sushil Chauhandbd8db42020-02-28 13:07:48 -08003401int32_t HWCSession::GetDisplayVsyncPeriod(hwc2_display_t disp, VsyncPeriodNanos *vsync_period) {
3402 if (vsync_period == nullptr) {
3403 return HWC2_ERROR_BAD_PARAMETER;
3404 }
3405
3406 return CallDisplayFunction(disp, &HWCDisplay::GetDisplayVsyncPeriod, vsync_period);
3407}
3408
3409int32_t HWCSession::SetActiveConfigWithConstraints(
3410 hwc2_display_t display, hwc2_config_t config,
3411 const VsyncPeriodChangeConstraints *vsync_period_change_constraints,
3412 VsyncPeriodChangeTimeline *out_timeline) {
3413 if ((vsync_period_change_constraints == nullptr) || (out_timeline == nullptr)) {
3414 return HWC2_ERROR_BAD_PARAMETER;
3415 }
3416
3417 return CallDisplayFunction(display, &HWCDisplay::SetActiveConfigWithConstraints, config,
3418 vsync_period_change_constraints, out_timeline);
3419}
3420
Naseer Ahmedb92e73f2016-03-12 02:03:48 -05003421} // namespace sdm