blob: 36050d2f6c1ddcb5928b258fcfa42e55829ab883 [file] [log] [blame]
Naseer Ahmedb92e73f2016-03-12 02:03:48 -05001/*
Varun Arora465c1f72018-02-08 16:18:50 -08002* Copyright (c) 2014 - 2018, The Linux Foundation. All rights reserved.
Naseer Ahmedb92e73f2016-03-12 02:03:48 -05003*
4* Redistribution and use in source and binary forms, with or without
5* modification, are permitted provided that the following conditions are
6* met:
7* * Redistributions of source code must retain the above copyright
8* notice, this list of conditions and the following disclaimer.
9* * Redistributions in binary form must reproduce the above
10* copyright notice, this list of conditions and the following
11* disclaimer in the documentation and/or other materials provided
12* with the distribution.
13* * Neither the name of The Linux Foundation nor the names of its
14* contributors may be used to endorse or promote products derived
15* from this software without specific prior written permission.
16*
17* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
18* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
19* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
20* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
21* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
24* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
25* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
26* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
27* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28*/
29
30#include <cutils/properties.h>
31#include <sync/sync.h>
32#include <utils/constants.h>
33#include <utils/debug.h>
Sushil Chauhan06521582018-03-19 14:00:23 -070034#include <utils/utils.h>
Naseer Ahmedb92e73f2016-03-12 02:03:48 -050035#include <stdarg.h>
36#include <sys/mman.h>
37
Arun Kumar K.R29cd6582016-05-10 19:12:45 -070038#include <map>
39#include <string>
40#include <vector>
41
Naseer Ahmedb92e73f2016-03-12 02:03:48 -050042#include "hwc_display_primary.h"
43#include "hwc_debugger.h"
44
45#define __CLASS__ "HWCDisplayPrimary"
46
47namespace sdm {
48
49int HWCDisplayPrimary::Create(CoreInterface *core_intf, BufferAllocator *buffer_allocator,
Varun Arora7c8ee542018-05-01 20:58:16 -070050 HWCCallbacks *callbacks, HWCDisplayEventHandler *event_handler,
51 qService::QService *qservice, HWCDisplay **hwc_display) {
Naseer Ahmedb92e73f2016-03-12 02:03:48 -050052 int status = 0;
53 uint32_t primary_width = 0;
54 uint32_t primary_height = 0;
55
56 HWCDisplay *hwc_display_primary =
Varun Arora7c8ee542018-05-01 20:58:16 -070057 new HWCDisplayPrimary(core_intf, buffer_allocator, callbacks, event_handler, qservice);
Naseer Ahmedb92e73f2016-03-12 02:03:48 -050058 status = hwc_display_primary->Init();
59 if (status) {
60 delete hwc_display_primary;
61 return status;
62 }
63
Arun Kumar K.R8da7f502016-06-07 17:45:50 -070064 hwc_display_primary->GetMixerResolution(&primary_width, &primary_height);
Naseer Ahmedb92e73f2016-03-12 02:03:48 -050065 int width = 0, height = 0;
Uday Kiran Pichika5e656b22018-05-15 18:48:24 +053066 HWCDebugHandler::Get()->GetProperty(FB_WIDTH_PROP, &width);
67 HWCDebugHandler::Get()->GetProperty(FB_HEIGHT_PROP, &height);
Naseer Ahmedb92e73f2016-03-12 02:03:48 -050068 if (width > 0 && height > 0) {
69 primary_width = UINT32(width);
70 primary_height = UINT32(height);
71 }
72
73 status = hwc_display_primary->SetFrameBufferResolution(primary_width, primary_height);
74 if (status) {
75 Destroy(hwc_display_primary);
76 return status;
77 }
78
79 *hwc_display = hwc_display_primary;
80
81 return status;
82}
83
84void HWCDisplayPrimary::Destroy(HWCDisplay *hwc_display) {
85 hwc_display->Deinit();
86 delete hwc_display;
87}
88
89HWCDisplayPrimary::HWCDisplayPrimary(CoreInterface *core_intf, BufferAllocator *buffer_allocator,
Varun Arora7c8ee542018-05-01 20:58:16 -070090 HWCCallbacks *callbacks, HWCDisplayEventHandler *event_handler,
91 qService::QService *qservice)
92 : HWCDisplay(core_intf, callbacks, event_handler, kPrimary, HWC_DISPLAY_PRIMARY, true,
93 qservice, DISPLAY_CLASS_PRIMARY, buffer_allocator),
94 buffer_allocator_(buffer_allocator), cpu_hint_(NULL) {
Naseer Ahmedb92e73f2016-03-12 02:03:48 -050095}
96
97int HWCDisplayPrimary::Init() {
98 cpu_hint_ = new CPUHint();
99 if (cpu_hint_->Init(static_cast<HWCDebugHandler *>(HWCDebugHandler::Get())) != kErrorNone) {
100 delete cpu_hint_;
101 cpu_hint_ = NULL;
102 }
103
104 use_metadata_refresh_rate_ = true;
105 int disable_metadata_dynfps = 0;
Uday Kiran Pichika5e656b22018-05-15 18:48:24 +0530106 HWCDebugHandler::Get()->GetProperty(DISABLE_METADATA_DYNAMIC_FPS_PROP, &disable_metadata_dynfps);
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500107 if (disable_metadata_dynfps) {
108 use_metadata_refresh_rate_ = false;
109 }
110
Arun Kumar K.R29cd6582016-05-10 19:12:45 -0700111 int status = HWCDisplay::Init();
112 if (status) {
113 return status;
114 }
115 color_mode_ = new HWCColorMode(display_intf_);
Naseer Ahmed61f60952017-05-24 16:48:35 -0400116 color_mode_->Init();
Uday Kiran Pichika5e656b22018-05-15 18:48:24 +0530117 HWCDebugHandler::Get()->GetProperty(ENABLE_DEFAULT_COLOR_MODE,
Ch Ganesh Kumar86c46512017-06-13 13:09:22 +0530118 &default_mode_status_);
Arun Kumar K.R29cd6582016-05-10 19:12:45 -0700119
Naseer Ahmed61f60952017-05-24 16:48:35 -0400120 return status;
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500121}
122
123void HWCDisplayPrimary::ProcessBootAnimCompleted() {
124 uint32_t numBootUpLayers = 0;
125 // TODO(user): Remove this hack
126
127 numBootUpLayers = static_cast<uint32_t>(Debug::GetBootAnimLayerCount());
128
129 if (numBootUpLayers == 0) {
130 numBootUpLayers = 2;
131 }
132 /* All other checks namely "init.svc.bootanim" or
133 * HWC_GEOMETRY_CHANGED fail in correctly identifying the
134 * exact bootup transition to homescreen
135 */
Naseer Ahmedac442ae2016-06-23 18:58:03 -0400136 char property[PROPERTY_VALUE_MAX];
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500137 bool isEncrypted = false;
138 bool main_class_services_started = false;
Naseer Ahmedac442ae2016-06-23 18:58:03 -0400139 property_get("ro.crypto.state", property, "unencrypted");
140 if (!strcmp(property, "encrypted")) {
141 property_get("ro.crypto.type", property, "block");
142 if (!strcmp(property, "block")) {
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500143 isEncrypted = true;
Naseer Ahmedac442ae2016-06-23 18:58:03 -0400144 property_get("vold.decrypt", property, "");
145 if (!strcmp(property, "trigger_restart_framework")) {
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500146 main_class_services_started = true;
Naseer Ahmedac442ae2016-06-23 18:58:03 -0400147 }
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500148 }
149 }
Naseer Ahmedac442ae2016-06-23 18:58:03 -0400150
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500151 if ((!isEncrypted || (isEncrypted && main_class_services_started)) &&
152 (layer_set_.size() > numBootUpLayers)) {
Naseer Ahmedac442ae2016-06-23 18:58:03 -0400153 DLOGI("Applying default mode");
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500154 boot_animation_completed_ = true;
155 // Applying default mode after bootanimation is finished And
156 // If Data is Encrypted, it is ready for access.
Ch Ganesh Kumar5d43ff62017-10-13 19:01:47 +0530157 if (display_intf_) {
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500158 display_intf_->ApplyDefaultDisplayMode();
Ch Ganesh Kumar5d43ff62017-10-13 19:01:47 +0530159 RestoreColorTransform();
160 }
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500161 }
162}
163
164HWC2::Error HWCDisplayPrimary::Validate(uint32_t *out_num_types, uint32_t *out_num_requests) {
165 auto status = HWC2::Error::None;
166 DisplayError error = kErrorNone;
167
Ch Ganesh Kumar86c46512017-06-13 13:09:22 +0530168 if (default_mode_status_ && !boot_animation_completed_) {
169 ProcessBootAnimCompleted();
170 }
171
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500172 if (display_paused_) {
173 MarkLayersForGPUBypass();
174 return status;
175 }
176
Arun Kumar K.R29cd6582016-05-10 19:12:45 -0700177 if (color_tranform_failed_) {
178 // Must fall back to client composition
179 MarkLayersForClientComposition();
180 }
181
Ramkumar Radhakrishnan3dcf8a22017-11-27 14:53:06 -0800182 if (config_pending_) {
183 if (display_intf_->SetActiveConfig(display_config_) != kErrorNone) {
184 DLOGW("Invalid display config %d", display_config_);
185 // Reset the display config with active config
186 display_intf_->GetActiveConfig(&display_config_);
187 }
188 }
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500189 // Fill in the remaining blanks in the layers and add them to the SDM layerstack
190 BuildLayerStack();
Arun Kumar K.R536c7d62016-06-14 18:47:39 -0700191 // Checks and replaces layer stack for solid fill
192 SolidFillPrepare();
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500193
194 bool pending_output_dump = dump_frame_count_ && dump_output_to_file_;
195
Sushil Chauhan06521582018-03-19 14:00:23 -0700196 if (readback_buffer_queued_ || pending_output_dump) {
197 CloseFd(&output_buffer_.release_fence_fd);
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500198 // RHS values were set in FrameCaptureAsync() called from a binder thread. They are picked up
Sushil Chauhan06521582018-03-19 14:00:23 -0700199 // here in a subsequent draw round. Readback is not allowed for any secure use case.
200 readback_configured_ = !layer_stack_.flags.secure_present;
201 if (readback_configured_) {
202 layer_stack_.output_buffer = &output_buffer_;
203 layer_stack_.flags.post_processed_output = post_processed_output_;
204 }
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500205 }
206
Ramakant Singh5db0dfb2017-08-23 12:34:57 +0530207 uint32_t num_updating_layers = GetUpdatingLayersCount();
208 bool one_updating_layer = (num_updating_layers == 1);
209 if (num_updating_layers != 0) {
210 ToggleCPUHint(one_updating_layer);
211 }
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500212
213 uint32_t refresh_rate = GetOptimalRefreshRate(one_updating_layer);
Anjaneya Prasad Musunuri4d65df72017-05-18 19:11:28 +0530214 bool final_rate = force_refresh_rate_ ? true : false;
215 error = display_intf_->SetRefreshRate(refresh_rate, final_rate);
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500216 if (error == kErrorNone) {
217 // On success, set current refresh rate to new refresh rate
218 current_refresh_rate_ = refresh_rate;
219 }
220
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500221 if (layer_set_.empty()) {
Uday Kiran Pichika8d827732018-01-09 18:08:38 +0530222 // Avoid flush for Command mode panel.
Ramkumar Radhakrishnana38b7602018-03-15 14:49:52 -0700223 flush_ = !IsDisplayCommandMode();
224 validated_ = true;
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500225 return status;
226 }
227
228 status = PrepareLayerStack(out_num_types, out_num_requests);
229 return status;
230}
231
232HWC2::Error HWCDisplayPrimary::Present(int32_t *out_retire_fence) {
233 auto status = HWC2::Error::None;
234 if (display_paused_) {
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500235 DisplayError error = display_intf_->Flush();
Saurabh Shaha307e8c2017-09-28 18:05:40 -0700236 validated_ = false;
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500237 if (error != kErrorNone) {
238 DLOGE("Flush failed. Error = %d", error);
239 }
240 } else {
241 status = HWCDisplay::CommitLayerStack();
242 if (status == HWC2::Error::None) {
243 HandleFrameOutput();
Arun Kumar K.R536c7d62016-06-14 18:47:39 -0700244 SolidFillCommit();
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500245 status = HWCDisplay::PostCommitLayerStack(out_retire_fence);
246 }
247 }
Arun Kumar K.R536c7d62016-06-14 18:47:39 -0700248
Sushil Chauhan06521582018-03-19 14:00:23 -0700249 CloseFd(&output_buffer_.acquire_fence_fd);
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500250 return status;
251}
252
Arun Kumar K.R29cd6582016-05-10 19:12:45 -0700253HWC2::Error HWCDisplayPrimary::GetColorModes(uint32_t *out_num_modes,
Naseer Ahmedeae28122016-06-27 15:47:05 -0400254 android_color_mode_t *out_modes) {
Arun Kumar K.R29cd6582016-05-10 19:12:45 -0700255 if (out_modes == nullptr) {
256 *out_num_modes = color_mode_->GetColorModeCount();
257 } else {
258 color_mode_->GetColorModes(out_num_modes, out_modes);
259 }
260
261 return HWC2::Error::None;
262}
263
Naseer Ahmedeae28122016-06-27 15:47:05 -0400264HWC2::Error HWCDisplayPrimary::SetColorMode(android_color_mode_t mode) {
Arun Kumar K.R29cd6582016-05-10 19:12:45 -0700265 auto status = color_mode_->SetColorMode(mode);
266 if (status != HWC2::Error::None) {
267 DLOGE("failed for mode = %d", mode);
268 return status;
269 }
270
271 callbacks_->Refresh(HWC_DISPLAY_PRIMARY);
Saurabh Shaha307e8c2017-09-28 18:05:40 -0700272 validated_ = false;
Arun Kumar K.R29cd6582016-05-10 19:12:45 -0700273
274 return status;
275}
276
Naseer Ahmed6776dae2017-05-09 11:49:41 -0400277HWC2::Error HWCDisplayPrimary::SetColorModeById(int32_t color_mode_id) {
278 auto status = color_mode_->SetColorModeById(color_mode_id);
279 if (status != HWC2::Error::None) {
280 DLOGE("failed for mode = %d", color_mode_id);
281 return status;
282 }
283
284 callbacks_->Refresh(HWC_DISPLAY_PRIMARY);
Saurabh Shaha307e8c2017-09-28 18:05:40 -0700285 validated_ = false;
Naseer Ahmed6776dae2017-05-09 11:49:41 -0400286
287 return status;
288}
289
Ch Ganesh Kumar5d43ff62017-10-13 19:01:47 +0530290HWC2::Error HWCDisplayPrimary::RestoreColorTransform() {
291 auto status = color_mode_->RestoreColorTransform();
292 if (status != HWC2::Error::None) {
293 DLOGE("failed to RestoreColorTransform");
294 return status;
295 }
296
297 callbacks_->Refresh(HWC_DISPLAY_PRIMARY);
298
299 return status;
300}
301
Arun Kumar K.R29cd6582016-05-10 19:12:45 -0700302HWC2::Error HWCDisplayPrimary::SetColorTransform(const float *matrix,
303 android_color_transform_t hint) {
304 if (!matrix) {
305 return HWC2::Error::BadParameter;
306 }
307
308 auto status = color_mode_->SetColorTransform(matrix, hint);
309 if (status != HWC2::Error::None) {
310 DLOGE("failed for hint = %d", hint);
311 color_tranform_failed_ = true;
312 return status;
313 }
314
315 callbacks_->Refresh(HWC_DISPLAY_PRIMARY);
316 color_tranform_failed_ = false;
Saurabh Shaha307e8c2017-09-28 18:05:40 -0700317 validated_ = false;
Arun Kumar K.R29cd6582016-05-10 19:12:45 -0700318
319 return status;
320}
321
Sushil Chauhan06521582018-03-19 14:00:23 -0700322HWC2::Error HWCDisplayPrimary::SetReadbackBuffer(const native_handle_t *buffer,
323 int32_t acquire_fence,
324 bool post_processed_output) {
325 const private_handle_t *handle = reinterpret_cast<const private_handle_t *>(buffer);
326 if (!handle || (handle->fd < 0)) {
327 return HWC2::Error::BadParameter;
328 }
329
330 // Configure the output buffer as Readback buffer
331 output_buffer_.width = UINT32(handle->width);
332 output_buffer_.height = UINT32(handle->height);
333 output_buffer_.unaligned_width = UINT32(handle->unaligned_width);
334 output_buffer_.unaligned_height = UINT32(handle->unaligned_height);
335 output_buffer_.format = HWCLayer::GetSDMFormat(handle->format, handle->flags);
336 output_buffer_.planes[0].fd = handle->fd;
337 output_buffer_.planes[0].stride = UINT32(handle->width);
338 output_buffer_.acquire_fence_fd = dup(acquire_fence);
339 output_buffer_.release_fence_fd = -1;
340
341 post_processed_output_ = post_processed_output;
342 readback_buffer_queued_ = true;
343 readback_configured_ = false;
344 validated_ = false;
345
346 DisablePartialUpdateOneFrame();
347 return HWC2::Error::None;
348}
349
350HWC2::Error HWCDisplayPrimary::GetReadbackBufferFence(int32_t *release_fence) {
351 auto status = HWC2::Error::None;
352
353 if (readback_configured_ && (output_buffer_.release_fence_fd >= 0)) {
354 *release_fence = output_buffer_.release_fence_fd;
355 } else {
356 status = HWC2::Error::Unsupported;
357 *release_fence = -1;
358 }
359
360 post_processed_output_ = false;
361 readback_buffer_queued_ = false;
362 readback_configured_ = false;
363 output_buffer_ = {};
364
365 return status;
366}
367
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500368int HWCDisplayPrimary::Perform(uint32_t operation, ...) {
369 va_list args;
370 va_start(args, operation);
Arun Kumar K.R536c7d62016-06-14 18:47:39 -0700371 int val = 0;
Gopikrishnaiah Anandancc123062017-07-31 17:21:03 -0700372 LayerSolidFill *solid_fill_color;
Arun Kumar K.R536c7d62016-06-14 18:47:39 -0700373 LayerRect *rect = NULL;
374
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500375 switch (operation) {
376 case SET_METADATA_DYN_REFRESH_RATE:
Arun Kumar K.R536c7d62016-06-14 18:47:39 -0700377 val = va_arg(args, int32_t);
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500378 SetMetaDataRefreshRateFlag(val);
379 break;
380 case SET_BINDER_DYN_REFRESH_RATE:
Arun Kumar K.R536c7d62016-06-14 18:47:39 -0700381 val = va_arg(args, int32_t);
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500382 ForceRefreshRate(UINT32(val));
383 break;
384 case SET_DISPLAY_MODE:
Arun Kumar K.R536c7d62016-06-14 18:47:39 -0700385 val = va_arg(args, int32_t);
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500386 SetDisplayMode(UINT32(val));
387 break;
388 case SET_QDCM_SOLID_FILL_INFO:
Gopikrishnaiah Anandancc123062017-07-31 17:21:03 -0700389 solid_fill_color = va_arg(args, LayerSolidFill*);
390 SetQDCMSolidFillInfo(true, *solid_fill_color);
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500391 break;
392 case UNSET_QDCM_SOLID_FILL_INFO:
Gopikrishnaiah Anandancc123062017-07-31 17:21:03 -0700393 solid_fill_color = va_arg(args, LayerSolidFill*);
394 SetQDCMSolidFillInfo(false, *solid_fill_color);
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500395 break;
Arun Kumar K.R536c7d62016-06-14 18:47:39 -0700396 case SET_QDCM_SOLID_FILL_RECT:
397 rect = va_arg(args, LayerRect*);
398 solid_fill_rect_ = *rect;
399 break;
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500400 default:
401 DLOGW("Invalid operation %d", operation);
Arun Kumar K.R536c7d62016-06-14 18:47:39 -0700402 va_end(args);
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500403 return -EINVAL;
404 }
Arun Kumar K.R536c7d62016-06-14 18:47:39 -0700405 va_end(args);
Saurabh Shaha307e8c2017-09-28 18:05:40 -0700406 validated_ = false;
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500407
408 return 0;
409}
410
411DisplayError HWCDisplayPrimary::SetDisplayMode(uint32_t mode) {
412 DisplayError error = kErrorNone;
413
414 if (display_intf_) {
415 error = display_intf_->SetDisplayMode(mode);
416 }
417
418 return error;
419}
420
421void HWCDisplayPrimary::SetMetaDataRefreshRateFlag(bool enable) {
422 int disable_metadata_dynfps = 0;
423
Uday Kiran Pichika5e656b22018-05-15 18:48:24 +0530424 HWCDebugHandler::Get()->GetProperty(DISABLE_METADATA_DYNAMIC_FPS_PROP, &disable_metadata_dynfps);
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500425 if (disable_metadata_dynfps) {
426 return;
427 }
428 use_metadata_refresh_rate_ = enable;
429}
430
Gopikrishnaiah Anandancc123062017-07-31 17:21:03 -0700431void HWCDisplayPrimary::SetQDCMSolidFillInfo(bool enable, const LayerSolidFill &color) {
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500432 solid_fill_enable_ = enable;
433 solid_fill_color_ = color;
434}
435
436void HWCDisplayPrimary::ToggleCPUHint(bool set) {
437 if (!cpu_hint_) {
438 return;
439 }
440
441 if (set) {
442 cpu_hint_->Set();
443 } else {
444 cpu_hint_->Reset();
445 }
446}
447
Ramkumar Radhakrishnana38b7602018-03-15 14:49:52 -0700448int HWCDisplayPrimary::HandleSecureSession(const std::bitset<kSecureMax> &secure_sessions,
449 bool *power_on_pending) {
450 if (!power_on_pending) {
451 return -EINVAL;
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500452 }
Ramkumar Radhakrishnana38b7602018-03-15 14:49:52 -0700453
454 if (active_secure_sessions_[kSecureDisplay] != secure_sessions[kSecureDisplay]) {
455 SecureEvent secure_event =
456 secure_sessions.test(kSecureDisplay) ? kSecureDisplayStart : kSecureDisplayEnd;
457 DisplayError err = display_intf_->HandleSecureEvent(secure_event);
458 if (err != kErrorNone) {
459 DLOGE("Set secure event failed");
460 return err;
461 }
462
463 DLOGI("SecureDisplay state changed from %d to %d for display %d",
464 active_secure_sessions_.test(kSecureDisplay), secure_sessions.test(kSecureDisplay),
465 type_);
466 }
467 active_secure_sessions_ = secure_sessions;
468 *power_on_pending = false;
469 return 0;
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500470}
471
472void HWCDisplayPrimary::ForceRefreshRate(uint32_t refresh_rate) {
473 if ((refresh_rate && (refresh_rate < min_refresh_rate_ || refresh_rate > max_refresh_rate_)) ||
474 force_refresh_rate_ == refresh_rate) {
475 // Cannot honor force refresh rate, as its beyond the range or new request is same
476 return;
477 }
478
479 force_refresh_rate_ = refresh_rate;
480
481 callbacks_->Refresh(HWC_DISPLAY_PRIMARY);
482
483 return;
484}
485
486uint32_t HWCDisplayPrimary::GetOptimalRefreshRate(bool one_updating_layer) {
487 if (force_refresh_rate_) {
488 return force_refresh_rate_;
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500489 } else if (use_metadata_refresh_rate_ && one_updating_layer && metadata_refresh_rate_) {
490 return metadata_refresh_rate_;
491 }
492
493 return max_refresh_rate_;
494}
495
496DisplayError HWCDisplayPrimary::Refresh() {
497 DisplayError error = kErrorNone;
498
499 callbacks_->Refresh(HWC_DISPLAY_PRIMARY);
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500500
501 return error;
502}
503
504void HWCDisplayPrimary::SetIdleTimeoutMs(uint32_t timeout_ms) {
505 display_intf_->SetIdleTimeoutMs(timeout_ms);
Saurabh Shaha307e8c2017-09-28 18:05:40 -0700506 validated_ = false;
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500507}
508
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500509void HWCDisplayPrimary::HandleFrameOutput() {
Sushil Chauhan06521582018-03-19 14:00:23 -0700510 if (readback_buffer_queued_) {
511 validated_ = false;
512 }
513
514 if (dump_output_to_file_) {
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500515 HandleFrameDump();
516 }
517}
518
Sushil Chauhan06521582018-03-19 14:00:23 -0700519void HWCDisplayPrimary::HandleFrameDump() {
520 if (!readback_configured_) {
521 dump_frame_count_ = 0;
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500522 }
523
Sushil Chauhan06521582018-03-19 14:00:23 -0700524 if (dump_frame_count_ && output_buffer_.release_fence_fd >= 0) {
525 int ret = sync_wait(output_buffer_.release_fence_fd, 1000);
526 ::close(output_buffer_.release_fence_fd);
527 output_buffer_.release_fence_fd = -1;
528 if (ret < 0) {
529 DLOGE("sync_wait error errno = %d, desc = %s", errno, strerror(errno));
530 } else {
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500531 DumpOutputBuffer(output_buffer_info_, output_buffer_base_, layer_stack_.retire_fence_fd);
Sushil Chauhan06521582018-03-19 14:00:23 -0700532 readback_buffer_queued_ = false;
Sushil Chauhan062a7a42018-04-25 22:27:52 -0700533 validated_ = false;
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500534 }
535 }
536
537 if (0 == dump_frame_count_) {
538 dump_output_to_file_ = false;
539 // Unmap and Free buffer
540 if (munmap(output_buffer_base_, output_buffer_info_.alloc_buffer_info.size) != 0) {
541 DLOGE("unmap failed with err %d", errno);
542 }
543 if (buffer_allocator_->FreeBuffer(&output_buffer_info_) != 0) {
544 DLOGE("FreeBuffer failed");
545 }
546
Sushil Chauhan06521582018-03-19 14:00:23 -0700547 readback_buffer_queued_ = false;
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500548 post_processed_output_ = false;
Sushil Chauhan06521582018-03-19 14:00:23 -0700549 readback_configured_ = false;
550
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500551 output_buffer_ = {};
552 output_buffer_info_ = {};
553 output_buffer_base_ = nullptr;
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500554 }
555}
556
Mathew Joseph Karimpanaldbd64f82017-10-06 10:13:38 +0530557HWC2::Error HWCDisplayPrimary::SetFrameDumpConfig(uint32_t count, uint32_t bit_mask_layer_type) {
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500558 HWCDisplay::SetFrameDumpConfig(count, bit_mask_layer_type);
559 dump_output_to_file_ = bit_mask_layer_type & (1 << OUTPUT_LAYER_DUMP);
560 DLOGI("output_layer_dump_enable %d", dump_output_to_file_);
561
562 if (!count || !dump_output_to_file_) {
Mathew Joseph Karimpanaldbd64f82017-10-06 10:13:38 +0530563 return HWC2::Error::None;
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500564 }
565
566 // Allocate and map output buffer
567 output_buffer_info_ = {};
568 // Since we dump DSPP output use Panel resolution.
569 GetPanelResolution(&output_buffer_info_.buffer_config.width,
570 &output_buffer_info_.buffer_config.height);
571 output_buffer_info_.buffer_config.format = kFormatRGB888;
572 output_buffer_info_.buffer_config.buffer_count = 1;
573 if (buffer_allocator_->AllocateBuffer(&output_buffer_info_) != 0) {
574 DLOGE("Buffer allocation failed");
575 output_buffer_info_ = {};
Mathew Joseph Karimpanaldbd64f82017-10-06 10:13:38 +0530576 return HWC2::Error::NoResources;
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500577 }
578
579 void *buffer = mmap(NULL, output_buffer_info_.alloc_buffer_info.size, PROT_READ | PROT_WRITE,
580 MAP_SHARED, output_buffer_info_.alloc_buffer_info.fd, 0);
581
582 if (buffer == MAP_FAILED) {
583 DLOGE("mmap failed with err %d", errno);
584 buffer_allocator_->FreeBuffer(&output_buffer_info_);
585 output_buffer_info_ = {};
Mathew Joseph Karimpanaldbd64f82017-10-06 10:13:38 +0530586 return HWC2::Error::NoResources;
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500587 }
588
589 output_buffer_base_ = buffer;
Sushil Chauhan06521582018-03-19 14:00:23 -0700590 const native_handle_t *handle = static_cast<native_handle_t *>(output_buffer_info_.private_data);
591 SetReadbackBuffer(handle, -1, true);
592
Mathew Joseph Karimpanaldbd64f82017-10-06 10:13:38 +0530593 return HWC2::Error::None;
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500594}
595
596int HWCDisplayPrimary::FrameCaptureAsync(const BufferInfo &output_buffer_info,
597 bool post_processed_output) {
598 // Note: This function is called in context of a binder thread and a lock is already held
599 if (output_buffer_info.alloc_buffer_info.fd < 0) {
600 DLOGE("Invalid fd %d", output_buffer_info.alloc_buffer_info.fd);
601 return -1;
602 }
603
604 auto panel_width = 0u;
605 auto panel_height = 0u;
606 auto fb_width = 0u;
607 auto fb_height = 0u;
608
609 GetPanelResolution(&panel_width, &panel_height);
610 GetFrameBufferResolution(&fb_width, &fb_height);
611
Ch Ganesh Kumar5c4988b2017-06-07 15:21:02 +0530612 if (post_processed_output && (output_buffer_info.buffer_config.width < panel_width ||
613 output_buffer_info.buffer_config.height < panel_height)) {
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500614 DLOGE("Buffer dimensions should not be less than panel resolution");
615 return -1;
Ch Ganesh Kumar5c4988b2017-06-07 15:21:02 +0530616 } else if (!post_processed_output && (output_buffer_info.buffer_config.width < fb_width ||
617 output_buffer_info.buffer_config.height < fb_height)) {
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500618 DLOGE("Buffer dimensions should not be less than FB resolution");
619 return -1;
620 }
621
Sushil Chauhan06521582018-03-19 14:00:23 -0700622 const native_handle_t *buffer = static_cast<native_handle_t *>(output_buffer_info.private_data);
623 SetReadbackBuffer(buffer, -1, post_processed_output);
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500624
625 return 0;
626}
627
Sushil Chauhan06521582018-03-19 14:00:23 -0700628bool HWCDisplayPrimary::GetFrameCaptureFence(int32_t *release_fence) {
629 return (GetReadbackBufferFence(release_fence) == HWC2::Error::None);
630}
631
Alan Kwong2e136332016-08-16 07:50:16 -0400632DisplayError HWCDisplayPrimary::SetDetailEnhancerConfig
633 (const DisplayDetailEnhancerData &de_data) {
634 DisplayError error = kErrorNotSupported;
635
636 if (display_intf_) {
637 error = display_intf_->SetDetailEnhancerData(de_data);
Saurabh Shaha307e8c2017-09-28 18:05:40 -0700638 validated_ = false;
Alan Kwong2e136332016-08-16 07:50:16 -0400639 }
640 return error;
641}
642
Arun Kumar K.R17bbd042016-06-07 17:38:02 -0700643DisplayError HWCDisplayPrimary::ControlPartialUpdate(bool enable, uint32_t *pending) {
644 DisplayError error = kErrorNone;
645
646 if (display_intf_) {
647 error = display_intf_->ControlPartialUpdate(enable, pending);
Saurabh Shaha307e8c2017-09-28 18:05:40 -0700648 validated_ = false;
Arun Kumar K.R17bbd042016-06-07 17:38:02 -0700649 }
650
651 return error;
652}
653
654DisplayError HWCDisplayPrimary::DisablePartialUpdateOneFrame() {
655 DisplayError error = kErrorNone;
656
657 if (display_intf_) {
658 error = display_intf_->DisablePartialUpdateOneFrame();
Saurabh Shaha307e8c2017-09-28 18:05:40 -0700659 validated_ = false;
Arun Kumar K.R17bbd042016-06-07 17:38:02 -0700660 }
661
662 return error;
663}
664
665
Arun Kumar K.R8da7f502016-06-07 17:45:50 -0700666DisplayError HWCDisplayPrimary::SetMixerResolution(uint32_t width, uint32_t height) {
Sushil Chauhan409e8442017-06-12 17:43:25 -0700667 DisplayError error = display_intf_->SetMixerResolution(width, height);
Saurabh Shaha307e8c2017-09-28 18:05:40 -0700668 validated_ = false;
Sushil Chauhan409e8442017-06-12 17:43:25 -0700669 return error;
Arun Kumar K.R8da7f502016-06-07 17:45:50 -0700670}
671
672DisplayError HWCDisplayPrimary::GetMixerResolution(uint32_t *width, uint32_t *height) {
673 return display_intf_->GetMixerResolution(width, height);
674}
675
Sushil Chauhan380a59d2018-03-19 15:47:50 -0700676HWC2::Error HWCDisplayPrimary::SetQSyncMode(QSyncMode qsync_mode) {
677 auto err = display_intf_->SetQSyncMode(qsync_mode);
678 if (err != kErrorNone) {
679 return HWC2::Error::Unsupported;
680 }
681
682 return HWC2::Error::None;
683}
684
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500685} // namespace sdm