blob: 16de8d96954be548db017b033c62d23d3a70ff34 [file] [log] [blame]
Naseer Ahmedb92e73f2016-03-12 02:03:48 -05001/*
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +05302* 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
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +053042#include "hwc_display_builtin.h"
Naseer Ahmedb92e73f2016-03-12 02:03:48 -050043#include "hwc_debugger.h"
44
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +053045#define __CLASS__ "HWCDisplayBuiltIn"
Naseer Ahmedb92e73f2016-03-12 02:03:48 -050046
47namespace sdm {
48
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +053049int HWCDisplayBuiltIn::Create(CoreInterface *core_intf, BufferAllocator *buffer_allocator,
Varun Arora7c8ee542018-05-01 20:58:16 -070050 HWCCallbacks *callbacks, HWCDisplayEventHandler *event_handler,
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +053051 qService::QService *qservice, hwc2_display_t id, int32_t sdm_id,
52 HWCDisplay **hwc_display) {
Naseer Ahmedb92e73f2016-03-12 02:03:48 -050053 int status = 0;
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +053054 uint32_t builtin_width = 0;
55 uint32_t builtin_height = 0;
Naseer Ahmedb92e73f2016-03-12 02:03:48 -050056
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +053057 HWCDisplay *hwc_display_builtin =
58 new HWCDisplayBuiltIn(core_intf, buffer_allocator, callbacks, event_handler, qservice, id,
59 sdm_id);
60 status = hwc_display_builtin->Init();
Naseer Ahmedb92e73f2016-03-12 02:03:48 -050061 if (status) {
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +053062 delete hwc_display_builtin;
Naseer Ahmedb92e73f2016-03-12 02:03:48 -050063 return status;
64 }
65
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +053066 hwc_display_builtin->GetMixerResolution(&builtin_width, &builtin_height);
Naseer Ahmedb92e73f2016-03-12 02:03:48 -050067 int width = 0, height = 0;
Uday Kiran Pichika5e656b22018-05-15 18:48:24 +053068 HWCDebugHandler::Get()->GetProperty(FB_WIDTH_PROP, &width);
69 HWCDebugHandler::Get()->GetProperty(FB_HEIGHT_PROP, &height);
Naseer Ahmedb92e73f2016-03-12 02:03:48 -050070 if (width > 0 && height > 0) {
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +053071 builtin_width = UINT32(width);
72 builtin_height = UINT32(height);
Naseer Ahmedb92e73f2016-03-12 02:03:48 -050073 }
74
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +053075 status = hwc_display_builtin->SetFrameBufferResolution(builtin_width, builtin_height);
Naseer Ahmedb92e73f2016-03-12 02:03:48 -050076 if (status) {
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +053077 Destroy(hwc_display_builtin);
Naseer Ahmedb92e73f2016-03-12 02:03:48 -050078 return status;
79 }
80
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +053081 *hwc_display = hwc_display_builtin;
Naseer Ahmedb92e73f2016-03-12 02:03:48 -050082
83 return status;
84}
85
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +053086void HWCDisplayBuiltIn::Destroy(HWCDisplay *hwc_display) {
Naseer Ahmedb92e73f2016-03-12 02:03:48 -050087 hwc_display->Deinit();
88 delete hwc_display;
89}
90
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +053091HWCDisplayBuiltIn::HWCDisplayBuiltIn(CoreInterface *core_intf, BufferAllocator *buffer_allocator,
Varun Arora7c8ee542018-05-01 20:58:16 -070092 HWCCallbacks *callbacks, HWCDisplayEventHandler *event_handler,
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +053093 qService::QService *qservice, hwc2_display_t id,
94 int32_t sdm_id)
95 : HWCDisplay(core_intf, buffer_allocator, callbacks, event_handler, qservice, kBuiltIn, id,
96 sdm_id, true, DISPLAY_CLASS_BUILTIN),
97 buffer_allocator_(buffer_allocator),
98 cpu_hint_(NULL) {
Naseer Ahmedb92e73f2016-03-12 02:03:48 -050099}
100
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +0530101int HWCDisplayBuiltIn::Init() {
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500102 cpu_hint_ = new CPUHint();
103 if (cpu_hint_->Init(static_cast<HWCDebugHandler *>(HWCDebugHandler::Get())) != kErrorNone) {
104 delete cpu_hint_;
105 cpu_hint_ = NULL;
106 }
107
108 use_metadata_refresh_rate_ = true;
109 int disable_metadata_dynfps = 0;
Uday Kiran Pichika5e656b22018-05-15 18:48:24 +0530110 HWCDebugHandler::Get()->GetProperty(DISABLE_METADATA_DYNAMIC_FPS_PROP, &disable_metadata_dynfps);
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500111 if (disable_metadata_dynfps) {
112 use_metadata_refresh_rate_ = false;
113 }
114
Arun Kumar K.R29cd6582016-05-10 19:12:45 -0700115 int status = HWCDisplay::Init();
116 if (status) {
117 return status;
118 }
119 color_mode_ = new HWCColorMode(display_intf_);
Naseer Ahmed61f60952017-05-24 16:48:35 -0400120 color_mode_->Init();
Uday Kiran Pichika5e656b22018-05-15 18:48:24 +0530121 HWCDebugHandler::Get()->GetProperty(ENABLE_DEFAULT_COLOR_MODE,
Ch Ganesh Kumar86c46512017-06-13 13:09:22 +0530122 &default_mode_status_);
Arun Kumar K.R29cd6582016-05-10 19:12:45 -0700123
Naseer Ahmed61f60952017-05-24 16:48:35 -0400124 return status;
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500125}
126
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +0530127void HWCDisplayBuiltIn::ProcessBootAnimCompleted() {
Xu Yang340a3692018-07-10 16:50:52 +0800128 bool bootanim_exit = false;
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500129
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500130 /* All other checks namely "init.svc.bootanim" or
131 * HWC_GEOMETRY_CHANGED fail in correctly identifying the
132 * exact bootup transition to homescreen
133 */
Naseer Ahmedac442ae2016-06-23 18:58:03 -0400134 char property[PROPERTY_VALUE_MAX];
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500135 bool isEncrypted = false;
136 bool main_class_services_started = false;
Naseer Ahmedac442ae2016-06-23 18:58:03 -0400137 property_get("ro.crypto.state", property, "unencrypted");
138 if (!strcmp(property, "encrypted")) {
139 property_get("ro.crypto.type", property, "block");
140 if (!strcmp(property, "block")) {
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500141 isEncrypted = true;
Naseer Ahmedac442ae2016-06-23 18:58:03 -0400142 property_get("vold.decrypt", property, "");
143 if (!strcmp(property, "trigger_restart_framework")) {
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500144 main_class_services_started = true;
Naseer Ahmedac442ae2016-06-23 18:58:03 -0400145 }
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500146 }
147 }
Naseer Ahmedac442ae2016-06-23 18:58:03 -0400148
Xu Yang340a3692018-07-10 16:50:52 +0800149 property_get("service.bootanim.exit", property, "0");
150 if (!strcmp(property, "1")) {
151 bootanim_exit = true;
152 }
153
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500154 if ((!isEncrypted || (isEncrypted && main_class_services_started)) &&
Xu Yang340a3692018-07-10 16:50:52 +0800155 bootanim_exit) {
Xu Yang2a979af2018-05-07 17:10:49 +0800156 DLOGI("Applying default mode for display %d", sdm_id_);
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500157 boot_animation_completed_ = true;
158 // Applying default mode after bootanimation is finished And
159 // If Data is Encrypted, it is ready for access.
Ch Ganesh Kumar5d43ff62017-10-13 19:01:47 +0530160 if (display_intf_) {
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500161 display_intf_->ApplyDefaultDisplayMode();
Ch Ganesh Kumar5d43ff62017-10-13 19:01:47 +0530162 RestoreColorTransform();
163 }
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500164 }
165}
166
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +0530167HWC2::Error HWCDisplayBuiltIn::Validate(uint32_t *out_num_types, uint32_t *out_num_requests) {
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500168 auto status = HWC2::Error::None;
169 DisplayError error = kErrorNone;
170
Ch Ganesh Kumar86c46512017-06-13 13:09:22 +0530171 if (default_mode_status_ && !boot_animation_completed_) {
172 ProcessBootAnimCompleted();
173 }
174
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500175 if (display_paused_) {
176 MarkLayersForGPUBypass();
177 return status;
178 }
179
Arun Kumar K.R29cd6582016-05-10 19:12:45 -0700180 if (color_tranform_failed_) {
181 // Must fall back to client composition
182 MarkLayersForClientComposition();
183 }
184
Ramkumar Radhakrishnan3dcf8a22017-11-27 14:53:06 -0800185 if (config_pending_) {
186 if (display_intf_->SetActiveConfig(display_config_) != kErrorNone) {
187 DLOGW("Invalid display config %d", display_config_);
188 // Reset the display config with active config
189 display_intf_->GetActiveConfig(&display_config_);
190 }
191 }
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500192 // Fill in the remaining blanks in the layers and add them to the SDM layerstack
193 BuildLayerStack();
Arun Kumar K.R536c7d62016-06-14 18:47:39 -0700194 // Checks and replaces layer stack for solid fill
195 SolidFillPrepare();
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500196
Sushil Chauhan8008d602018-09-04 14:43:27 -0700197 // Apply current Color Mode and Render Intent.
198 if (color_mode_->ApplyCurrentColorModeWithRenderIntent() != HWC2::Error::None) {
199 // Fallback to GPU Composition, if Color Mode can't be applied.
200 MarkLayersForClientComposition();
201 }
202
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500203 bool pending_output_dump = dump_frame_count_ && dump_output_to_file_;
204
Sushil Chauhan06521582018-03-19 14:00:23 -0700205 if (readback_buffer_queued_ || pending_output_dump) {
206 CloseFd(&output_buffer_.release_fence_fd);
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500207 // RHS values were set in FrameCaptureAsync() called from a binder thread. They are picked up
Sushil Chauhan06521582018-03-19 14:00:23 -0700208 // here in a subsequent draw round. Readback is not allowed for any secure use case.
209 readback_configured_ = !layer_stack_.flags.secure_present;
210 if (readback_configured_) {
Sushil Chauhanf42d8622018-09-30 23:20:37 -0700211 DisablePartialUpdateOneFrame();
Sushil Chauhan06521582018-03-19 14:00:23 -0700212 layer_stack_.output_buffer = &output_buffer_;
213 layer_stack_.flags.post_processed_output = post_processed_output_;
214 }
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500215 }
216
Ramakant Singh5db0dfb2017-08-23 12:34:57 +0530217 uint32_t num_updating_layers = GetUpdatingLayersCount();
218 bool one_updating_layer = (num_updating_layers == 1);
219 if (num_updating_layers != 0) {
220 ToggleCPUHint(one_updating_layer);
221 }
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500222
223 uint32_t refresh_rate = GetOptimalRefreshRate(one_updating_layer);
Anjaneya Prasad Musunuri4d65df72017-05-18 19:11:28 +0530224 bool final_rate = force_refresh_rate_ ? true : false;
225 error = display_intf_->SetRefreshRate(refresh_rate, final_rate);
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500226 if (error == kErrorNone) {
227 // On success, set current refresh rate to new refresh rate
228 current_refresh_rate_ = refresh_rate;
229 }
230
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500231 if (layer_set_.empty()) {
Uday Kiran Pichika8d827732018-01-09 18:08:38 +0530232 // Avoid flush for Command mode panel.
Ramkumar Radhakrishnana38b7602018-03-15 14:49:52 -0700233 flush_ = !IsDisplayCommandMode();
234 validated_ = true;
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500235 return status;
236 }
237
238 status = PrepareLayerStack(out_num_types, out_num_requests);
Namit Solanki5b428dc2018-02-27 11:39:05 +0530239 pending_commit_ = true;
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500240 return status;
241}
242
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +0530243HWC2::Error HWCDisplayBuiltIn::Present(int32_t *out_retire_fence) {
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500244 auto status = HWC2::Error::None;
245 if (display_paused_) {
Pullakavi Srinivas0a1dba62018-07-02 15:49:11 +0530246 DisplayError error = display_intf_->Flush(&layer_stack_);
Saurabh Shaha307e8c2017-09-28 18:05:40 -0700247 validated_ = false;
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500248 if (error != kErrorNone) {
249 DLOGE("Flush failed. Error = %d", error);
250 }
251 } else {
252 status = HWCDisplay::CommitLayerStack();
253 if (status == HWC2::Error::None) {
254 HandleFrameOutput();
Arun Kumar K.R536c7d62016-06-14 18:47:39 -0700255 SolidFillCommit();
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500256 status = HWCDisplay::PostCommitLayerStack(out_retire_fence);
257 }
258 }
Arun Kumar K.R536c7d62016-06-14 18:47:39 -0700259
Sushil Chauhan06521582018-03-19 14:00:23 -0700260 CloseFd(&output_buffer_.acquire_fence_fd);
Namit Solanki5b428dc2018-02-27 11:39:05 +0530261 pending_commit_ = false;
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500262 return status;
263}
264
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +0530265HWC2::Error HWCDisplayBuiltIn::GetColorModes(uint32_t *out_num_modes, ColorMode *out_modes) {
Arun Kumar K.R29cd6582016-05-10 19:12:45 -0700266 if (out_modes == nullptr) {
267 *out_num_modes = color_mode_->GetColorModeCount();
268 } else {
269 color_mode_->GetColorModes(out_num_modes, out_modes);
270 }
271
272 return HWC2::Error::None;
273}
274
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +0530275HWC2::Error HWCDisplayBuiltIn::GetRenderIntents(ColorMode mode, uint32_t *out_num_intents,
Naseer Ahmede7a77982018-06-04 10:56:04 -0400276 RenderIntent *out_intents) {
277 if (out_intents == nullptr) {
278 *out_num_intents = color_mode_->GetRenderIntentCount(mode);
279 } else {
280 color_mode_->GetRenderIntents(mode, out_num_intents, out_intents);
281 }
282 return HWC2::Error::None;
283}
284
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +0530285HWC2::Error HWCDisplayBuiltIn::SetColorMode(ColorMode mode) {
Naseer Ahmede7a77982018-06-04 10:56:04 -0400286 return SetColorModeWithRenderIntent(mode, RenderIntent::COLORIMETRIC);
287}
288
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +0530289HWC2::Error HWCDisplayBuiltIn::SetColorModeWithRenderIntent(ColorMode mode, RenderIntent intent) {
Sushil Chauhan8008d602018-09-04 14:43:27 -0700290 auto status = color_mode_->CacheColorModeWithRenderIntent(mode, intent);
Arun Kumar K.R29cd6582016-05-10 19:12:45 -0700291 if (status != HWC2::Error::None) {
Naseer Ahmede7a77982018-06-04 10:56:04 -0400292 DLOGE("failed for mode = %d intent = %d", mode, intent);
Arun Kumar K.R29cd6582016-05-10 19:12:45 -0700293 return status;
294 }
Arun Kumar K.R29cd6582016-05-10 19:12:45 -0700295 callbacks_->Refresh(HWC_DISPLAY_PRIMARY);
Saurabh Shaha307e8c2017-09-28 18:05:40 -0700296 validated_ = false;
Arun Kumar K.R29cd6582016-05-10 19:12:45 -0700297 return status;
298}
299
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +0530300HWC2::Error HWCDisplayBuiltIn::SetColorModeById(int32_t color_mode_id) {
Naseer Ahmed6776dae2017-05-09 11:49:41 -0400301 auto status = color_mode_->SetColorModeById(color_mode_id);
302 if (status != HWC2::Error::None) {
303 DLOGE("failed for mode = %d", color_mode_id);
304 return status;
305 }
306
307 callbacks_->Refresh(HWC_DISPLAY_PRIMARY);
Saurabh Shaha307e8c2017-09-28 18:05:40 -0700308 validated_ = false;
Naseer Ahmed6776dae2017-05-09 11:49:41 -0400309
310 return status;
311}
312
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +0530313HWC2::Error HWCDisplayBuiltIn::RestoreColorTransform() {
Ch Ganesh Kumar5d43ff62017-10-13 19:01:47 +0530314 auto status = color_mode_->RestoreColorTransform();
315 if (status != HWC2::Error::None) {
316 DLOGE("failed to RestoreColorTransform");
317 return status;
318 }
319
320 callbacks_->Refresh(HWC_DISPLAY_PRIMARY);
321
322 return status;
323}
324
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +0530325HWC2::Error HWCDisplayBuiltIn::SetColorTransform(const float *matrix,
Arun Kumar K.R29cd6582016-05-10 19:12:45 -0700326 android_color_transform_t hint) {
327 if (!matrix) {
328 return HWC2::Error::BadParameter;
329 }
330
331 auto status = color_mode_->SetColorTransform(matrix, hint);
332 if (status != HWC2::Error::None) {
333 DLOGE("failed for hint = %d", hint);
334 color_tranform_failed_ = true;
335 return status;
336 }
337
338 callbacks_->Refresh(HWC_DISPLAY_PRIMARY);
339 color_tranform_failed_ = false;
Saurabh Shaha307e8c2017-09-28 18:05:40 -0700340 validated_ = false;
Arun Kumar K.R29cd6582016-05-10 19:12:45 -0700341
342 return status;
343}
344
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +0530345HWC2::Error HWCDisplayBuiltIn::SetReadbackBuffer(const native_handle_t *buffer,
Sushil Chauhan06521582018-03-19 14:00:23 -0700346 int32_t acquire_fence,
347 bool post_processed_output) {
348 const private_handle_t *handle = reinterpret_cast<const private_handle_t *>(buffer);
349 if (!handle || (handle->fd < 0)) {
350 return HWC2::Error::BadParameter;
351 }
352
353 // Configure the output buffer as Readback buffer
354 output_buffer_.width = UINT32(handle->width);
355 output_buffer_.height = UINT32(handle->height);
356 output_buffer_.unaligned_width = UINT32(handle->unaligned_width);
357 output_buffer_.unaligned_height = UINT32(handle->unaligned_height);
358 output_buffer_.format = HWCLayer::GetSDMFormat(handle->format, handle->flags);
359 output_buffer_.planes[0].fd = handle->fd;
360 output_buffer_.planes[0].stride = UINT32(handle->width);
361 output_buffer_.acquire_fence_fd = dup(acquire_fence);
362 output_buffer_.release_fence_fd = -1;
Sushil Chauhand0dc03d2018-09-19 07:08:40 -0700363 output_buffer_.handle_id = handle->id;
Sushil Chauhan06521582018-03-19 14:00:23 -0700364
365 post_processed_output_ = post_processed_output;
366 readback_buffer_queued_ = true;
367 readback_configured_ = false;
368 validated_ = false;
369
Sushil Chauhan06521582018-03-19 14:00:23 -0700370 return HWC2::Error::None;
371}
372
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +0530373HWC2::Error HWCDisplayBuiltIn::GetReadbackBufferFence(int32_t *release_fence) {
Sushil Chauhan06521582018-03-19 14:00:23 -0700374 auto status = HWC2::Error::None;
375
376 if (readback_configured_ && (output_buffer_.release_fence_fd >= 0)) {
377 *release_fence = output_buffer_.release_fence_fd;
378 } else {
379 status = HWC2::Error::Unsupported;
380 *release_fence = -1;
381 }
382
383 post_processed_output_ = false;
384 readback_buffer_queued_ = false;
385 readback_configured_ = false;
386 output_buffer_ = {};
387
388 return status;
389}
390
Yuchao Ma577f0f72018-07-09 11:20:00 +0800391HWC2::Error HWCDisplayBuiltIn::SetDisplayDppsAdROI(uint32_t h_start, uint32_t h_end,
392 uint32_t v_start, uint32_t v_end,
393 uint32_t factor_in, uint32_t factor_out) {
394 DisplayError error = kErrorNone;
395 DisplayDppsAd4RoiCfg dpps_ad4_roi_cfg = {};
396 uint32_t panel_width = 0, panel_height = 0;
397 constexpr uint16_t kMaxFactorVal = 0xffff;
398
399 if (h_start >= h_end || v_start >= v_end || factor_in > kMaxFactorVal ||
400 factor_out > kMaxFactorVal) {
401 DLOGE("Invalid roi region = [%u, %u, %u, %u, %u, %u]",
402 h_start, h_end, v_start, v_end, factor_in, factor_out);
403 return HWC2::Error::BadParameter;
404 }
405
406 GetPanelResolution(&panel_width, &panel_height);
407
408 if (h_start >= panel_width || h_end > panel_width ||
409 v_start >= panel_height || v_end > panel_height) {
410 DLOGE("Invalid roi region = [%u, %u, %u, %u], panel resolution = [%u, %u]",
411 h_start, h_end, v_start, v_end, panel_width, panel_height);
412 return HWC2::Error::BadParameter;
413 }
414
415 dpps_ad4_roi_cfg.h_start = h_start;
416 dpps_ad4_roi_cfg.h_end = h_end;
417 dpps_ad4_roi_cfg.v_start = v_start;
418 dpps_ad4_roi_cfg.v_end = v_end;
419 dpps_ad4_roi_cfg.factor_in = factor_in;
420 dpps_ad4_roi_cfg.factor_out = factor_out;
421
422 error = display_intf_->SetDisplayDppsAdROI(&dpps_ad4_roi_cfg);
423 if (error)
424 return HWC2::Error::BadConfig;
425
426 callbacks_->Refresh(HWC_DISPLAY_PRIMARY);
427
428 return HWC2::Error::None;
429}
430
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +0530431int HWCDisplayBuiltIn::Perform(uint32_t operation, ...) {
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500432 va_list args;
433 va_start(args, operation);
Arun Kumar K.R536c7d62016-06-14 18:47:39 -0700434 int val = 0;
Gopikrishnaiah Anandancc123062017-07-31 17:21:03 -0700435 LayerSolidFill *solid_fill_color;
Arun Kumar K.R536c7d62016-06-14 18:47:39 -0700436 LayerRect *rect = NULL;
437
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500438 switch (operation) {
439 case SET_METADATA_DYN_REFRESH_RATE:
Arun Kumar K.R536c7d62016-06-14 18:47:39 -0700440 val = va_arg(args, int32_t);
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500441 SetMetaDataRefreshRateFlag(val);
442 break;
443 case SET_BINDER_DYN_REFRESH_RATE:
Arun Kumar K.R536c7d62016-06-14 18:47:39 -0700444 val = va_arg(args, int32_t);
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500445 ForceRefreshRate(UINT32(val));
446 break;
447 case SET_DISPLAY_MODE:
Arun Kumar K.R536c7d62016-06-14 18:47:39 -0700448 val = va_arg(args, int32_t);
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500449 SetDisplayMode(UINT32(val));
450 break;
451 case SET_QDCM_SOLID_FILL_INFO:
Gopikrishnaiah Anandancc123062017-07-31 17:21:03 -0700452 solid_fill_color = va_arg(args, LayerSolidFill*);
453 SetQDCMSolidFillInfo(true, *solid_fill_color);
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500454 break;
455 case UNSET_QDCM_SOLID_FILL_INFO:
Gopikrishnaiah Anandancc123062017-07-31 17:21:03 -0700456 solid_fill_color = va_arg(args, LayerSolidFill*);
457 SetQDCMSolidFillInfo(false, *solid_fill_color);
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500458 break;
Arun Kumar K.R536c7d62016-06-14 18:47:39 -0700459 case SET_QDCM_SOLID_FILL_RECT:
460 rect = va_arg(args, LayerRect*);
461 solid_fill_rect_ = *rect;
462 break;
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500463 default:
464 DLOGW("Invalid operation %d", operation);
Arun Kumar K.R536c7d62016-06-14 18:47:39 -0700465 va_end(args);
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500466 return -EINVAL;
467 }
Arun Kumar K.R536c7d62016-06-14 18:47:39 -0700468 va_end(args);
Saurabh Shaha307e8c2017-09-28 18:05:40 -0700469 validated_ = false;
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500470
471 return 0;
472}
473
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +0530474DisplayError HWCDisplayBuiltIn::SetDisplayMode(uint32_t mode) {
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500475 DisplayError error = kErrorNone;
476
477 if (display_intf_) {
478 error = display_intf_->SetDisplayMode(mode);
Tharaga Balachandran04192a62018-08-29 16:23:25 -0400479 if (error == kErrorNone) {
480 DisplayConfigFixedInfo fixed_info = {};
481 display_intf_->GetConfig(&fixed_info);
482 is_cmd_mode_ = fixed_info.is_cmdmode;
483 partial_update_enabled_ = fixed_info.partial_update;
484 for (auto hwc_layer : layer_set_) {
485 hwc_layer->SetPartialUpdate(partial_update_enabled_);
486 }
487 client_target_->SetPartialUpdate(partial_update_enabled_);
488 }
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500489 }
490
491 return error;
492}
493
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +0530494void HWCDisplayBuiltIn::SetMetaDataRefreshRateFlag(bool enable) {
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500495 int disable_metadata_dynfps = 0;
496
Uday Kiran Pichika5e656b22018-05-15 18:48:24 +0530497 HWCDebugHandler::Get()->GetProperty(DISABLE_METADATA_DYNAMIC_FPS_PROP, &disable_metadata_dynfps);
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500498 if (disable_metadata_dynfps) {
499 return;
500 }
501 use_metadata_refresh_rate_ = enable;
502}
503
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +0530504void HWCDisplayBuiltIn::SetQDCMSolidFillInfo(bool enable, const LayerSolidFill &color) {
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500505 solid_fill_enable_ = enable;
506 solid_fill_color_ = color;
507}
508
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +0530509void HWCDisplayBuiltIn::ToggleCPUHint(bool set) {
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500510 if (!cpu_hint_) {
511 return;
512 }
513
514 if (set) {
515 cpu_hint_->Set();
516 } else {
517 cpu_hint_->Reset();
518 }
519}
520
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +0530521int HWCDisplayBuiltIn::HandleSecureSession(const std::bitset<kSecureMax> &secure_sessions,
Ramkumar Radhakrishnana38b7602018-03-15 14:49:52 -0700522 bool *power_on_pending) {
523 if (!power_on_pending) {
524 return -EINVAL;
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500525 }
Ramkumar Radhakrishnana38b7602018-03-15 14:49:52 -0700526
527 if (active_secure_sessions_[kSecureDisplay] != secure_sessions[kSecureDisplay]) {
528 SecureEvent secure_event =
529 secure_sessions.test(kSecureDisplay) ? kSecureDisplayStart : kSecureDisplayEnd;
Pullakavi Srinivas0a1dba62018-07-02 15:49:11 +0530530 DisplayError err = display_intf_->HandleSecureEvent(secure_event, &layer_stack_);
Ramkumar Radhakrishnana38b7602018-03-15 14:49:52 -0700531 if (err != kErrorNone) {
532 DLOGE("Set secure event failed");
533 return err;
534 }
535
536 DLOGI("SecureDisplay state changed from %d to %d for display %d",
537 active_secure_sessions_.test(kSecureDisplay), secure_sessions.test(kSecureDisplay),
538 type_);
539 }
540 active_secure_sessions_ = secure_sessions;
541 *power_on_pending = false;
542 return 0;
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500543}
544
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +0530545void HWCDisplayBuiltIn::ForceRefreshRate(uint32_t refresh_rate) {
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500546 if ((refresh_rate && (refresh_rate < min_refresh_rate_ || refresh_rate > max_refresh_rate_)) ||
547 force_refresh_rate_ == refresh_rate) {
548 // Cannot honor force refresh rate, as its beyond the range or new request is same
549 return;
550 }
551
552 force_refresh_rate_ = refresh_rate;
553
554 callbacks_->Refresh(HWC_DISPLAY_PRIMARY);
555
556 return;
557}
558
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +0530559uint32_t HWCDisplayBuiltIn::GetOptimalRefreshRate(bool one_updating_layer) {
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500560 if (force_refresh_rate_) {
561 return force_refresh_rate_;
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500562 } else if (use_metadata_refresh_rate_ && one_updating_layer && metadata_refresh_rate_) {
563 return metadata_refresh_rate_;
564 }
565
566 return max_refresh_rate_;
567}
568
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +0530569DisplayError HWCDisplayBuiltIn::Refresh() {
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500570 DisplayError error = kErrorNone;
571
572 callbacks_->Refresh(HWC_DISPLAY_PRIMARY);
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500573
574 return error;
575}
576
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +0530577void HWCDisplayBuiltIn::SetIdleTimeoutMs(uint32_t timeout_ms) {
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500578 display_intf_->SetIdleTimeoutMs(timeout_ms);
Saurabh Shaha307e8c2017-09-28 18:05:40 -0700579 validated_ = false;
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500580}
581
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +0530582void HWCDisplayBuiltIn::HandleFrameOutput() {
Sushil Chauhan06521582018-03-19 14:00:23 -0700583 if (readback_buffer_queued_) {
584 validated_ = false;
585 }
586
587 if (dump_output_to_file_) {
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500588 HandleFrameDump();
589 }
590}
591
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +0530592void HWCDisplayBuiltIn::HandleFrameDump() {
Sushil Chauhan06521582018-03-19 14:00:23 -0700593 if (!readback_configured_) {
594 dump_frame_count_ = 0;
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500595 }
596
Sushil Chauhan06521582018-03-19 14:00:23 -0700597 if (dump_frame_count_ && output_buffer_.release_fence_fd >= 0) {
598 int ret = sync_wait(output_buffer_.release_fence_fd, 1000);
599 ::close(output_buffer_.release_fence_fd);
600 output_buffer_.release_fence_fd = -1;
601 if (ret < 0) {
602 DLOGE("sync_wait error errno = %d, desc = %s", errno, strerror(errno));
603 } else {
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500604 DumpOutputBuffer(output_buffer_info_, output_buffer_base_, layer_stack_.retire_fence_fd);
Sushil Chauhan06521582018-03-19 14:00:23 -0700605 readback_buffer_queued_ = false;
Sushil Chauhan062a7a42018-04-25 22:27:52 -0700606 validated_ = false;
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500607 }
608 }
609
610 if (0 == dump_frame_count_) {
611 dump_output_to_file_ = false;
612 // Unmap and Free buffer
613 if (munmap(output_buffer_base_, output_buffer_info_.alloc_buffer_info.size) != 0) {
614 DLOGE("unmap failed with err %d", errno);
615 }
616 if (buffer_allocator_->FreeBuffer(&output_buffer_info_) != 0) {
617 DLOGE("FreeBuffer failed");
618 }
619
Sushil Chauhan06521582018-03-19 14:00:23 -0700620 readback_buffer_queued_ = false;
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500621 post_processed_output_ = false;
Sushil Chauhan06521582018-03-19 14:00:23 -0700622 readback_configured_ = false;
623
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500624 output_buffer_ = {};
625 output_buffer_info_ = {};
626 output_buffer_base_ = nullptr;
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500627 }
628}
629
Sushil Chauhan267a6192018-06-06 18:41:47 -0700630HWC2::Error HWCDisplayBuiltIn::SetFrameDumpConfig(uint32_t count, uint32_t bit_mask_layer_type,
631 int32_t format, bool post_processed) {
632 HWCDisplay::SetFrameDumpConfig(count, bit_mask_layer_type, format, post_processed);
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500633 dump_output_to_file_ = bit_mask_layer_type & (1 << OUTPUT_LAYER_DUMP);
634 DLOGI("output_layer_dump_enable %d", dump_output_to_file_);
635
Sushil Chauhand0dc03d2018-09-19 07:08:40 -0700636 if (!count || !dump_output_to_file_ || (output_buffer_info_.alloc_buffer_info.fd >= 0)) {
Mathew Joseph Karimpanaldbd64f82017-10-06 10:13:38 +0530637 return HWC2::Error::None;
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500638 }
639
640 // Allocate and map output buffer
Sushil Chauhan267a6192018-06-06 18:41:47 -0700641 if (post_processed) {
642 // To dump post-processed (DSPP) output, use Panel resolution.
643 GetPanelResolution(&output_buffer_info_.buffer_config.width,
644 &output_buffer_info_.buffer_config.height);
645 } else {
646 // To dump Layer Mixer output, use FrameBuffer resolution.
647 GetFrameBufferResolution(&output_buffer_info_.buffer_config.width,
648 &output_buffer_info_.buffer_config.height);
649 }
650
651 output_buffer_info_.buffer_config.format = HWCLayer::GetSDMFormat(format, 0);
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500652 output_buffer_info_.buffer_config.buffer_count = 1;
653 if (buffer_allocator_->AllocateBuffer(&output_buffer_info_) != 0) {
654 DLOGE("Buffer allocation failed");
655 output_buffer_info_ = {};
Mathew Joseph Karimpanaldbd64f82017-10-06 10:13:38 +0530656 return HWC2::Error::NoResources;
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500657 }
658
659 void *buffer = mmap(NULL, output_buffer_info_.alloc_buffer_info.size, PROT_READ | PROT_WRITE,
660 MAP_SHARED, output_buffer_info_.alloc_buffer_info.fd, 0);
661
662 if (buffer == MAP_FAILED) {
663 DLOGE("mmap failed with err %d", errno);
664 buffer_allocator_->FreeBuffer(&output_buffer_info_);
665 output_buffer_info_ = {};
Mathew Joseph Karimpanaldbd64f82017-10-06 10:13:38 +0530666 return HWC2::Error::NoResources;
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500667 }
668
669 output_buffer_base_ = buffer;
Sushil Chauhan06521582018-03-19 14:00:23 -0700670 const native_handle_t *handle = static_cast<native_handle_t *>(output_buffer_info_.private_data);
Sushil Chauhan267a6192018-06-06 18:41:47 -0700671 SetReadbackBuffer(handle, -1, post_processed);
Sushil Chauhan06521582018-03-19 14:00:23 -0700672
Mathew Joseph Karimpanaldbd64f82017-10-06 10:13:38 +0530673 return HWC2::Error::None;
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500674}
675
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +0530676int HWCDisplayBuiltIn::FrameCaptureAsync(const BufferInfo &output_buffer_info,
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500677 bool post_processed_output) {
678 // Note: This function is called in context of a binder thread and a lock is already held
679 if (output_buffer_info.alloc_buffer_info.fd < 0) {
680 DLOGE("Invalid fd %d", output_buffer_info.alloc_buffer_info.fd);
681 return -1;
682 }
683
684 auto panel_width = 0u;
685 auto panel_height = 0u;
686 auto fb_width = 0u;
687 auto fb_height = 0u;
688
689 GetPanelResolution(&panel_width, &panel_height);
690 GetFrameBufferResolution(&fb_width, &fb_height);
691
Ch Ganesh Kumar5c4988b2017-06-07 15:21:02 +0530692 if (post_processed_output && (output_buffer_info.buffer_config.width < panel_width ||
693 output_buffer_info.buffer_config.height < panel_height)) {
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500694 DLOGE("Buffer dimensions should not be less than panel resolution");
695 return -1;
Ch Ganesh Kumar5c4988b2017-06-07 15:21:02 +0530696 } else if (!post_processed_output && (output_buffer_info.buffer_config.width < fb_width ||
697 output_buffer_info.buffer_config.height < fb_height)) {
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500698 DLOGE("Buffer dimensions should not be less than FB resolution");
699 return -1;
700 }
701
Sushil Chauhan06521582018-03-19 14:00:23 -0700702 const native_handle_t *buffer = static_cast<native_handle_t *>(output_buffer_info.private_data);
703 SetReadbackBuffer(buffer, -1, post_processed_output);
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500704
705 return 0;
706}
707
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +0530708bool HWCDisplayBuiltIn::GetFrameCaptureFence(int32_t *release_fence) {
Sushil Chauhan06521582018-03-19 14:00:23 -0700709 return (GetReadbackBufferFence(release_fence) == HWC2::Error::None);
710}
711
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +0530712DisplayError HWCDisplayBuiltIn::SetDetailEnhancerConfig
Alan Kwong2e136332016-08-16 07:50:16 -0400713 (const DisplayDetailEnhancerData &de_data) {
714 DisplayError error = kErrorNotSupported;
715
716 if (display_intf_) {
717 error = display_intf_->SetDetailEnhancerData(de_data);
Saurabh Shaha307e8c2017-09-28 18:05:40 -0700718 validated_ = false;
Alan Kwong2e136332016-08-16 07:50:16 -0400719 }
720 return error;
721}
722
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +0530723DisplayError HWCDisplayBuiltIn::ControlPartialUpdate(bool enable, uint32_t *pending) {
Arun Kumar K.R17bbd042016-06-07 17:38:02 -0700724 DisplayError error = kErrorNone;
725
726 if (display_intf_) {
727 error = display_intf_->ControlPartialUpdate(enable, pending);
Saurabh Shaha307e8c2017-09-28 18:05:40 -0700728 validated_ = false;
Arun Kumar K.R17bbd042016-06-07 17:38:02 -0700729 }
730
731 return error;
732}
733
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +0530734DisplayError HWCDisplayBuiltIn::DisablePartialUpdateOneFrame() {
Arun Kumar K.R17bbd042016-06-07 17:38:02 -0700735 DisplayError error = kErrorNone;
736
737 if (display_intf_) {
738 error = display_intf_->DisablePartialUpdateOneFrame();
Saurabh Shaha307e8c2017-09-28 18:05:40 -0700739 validated_ = false;
Arun Kumar K.R17bbd042016-06-07 17:38:02 -0700740 }
741
742 return error;
743}
744
745
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +0530746DisplayError HWCDisplayBuiltIn::SetMixerResolution(uint32_t width, uint32_t height) {
Sushil Chauhan409e8442017-06-12 17:43:25 -0700747 DisplayError error = display_intf_->SetMixerResolution(width, height);
Saurabh Shaha307e8c2017-09-28 18:05:40 -0700748 validated_ = false;
Sushil Chauhan409e8442017-06-12 17:43:25 -0700749 return error;
Arun Kumar K.R8da7f502016-06-07 17:45:50 -0700750}
751
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +0530752DisplayError HWCDisplayBuiltIn::GetMixerResolution(uint32_t *width, uint32_t *height) {
Arun Kumar K.R8da7f502016-06-07 17:45:50 -0700753 return display_intf_->GetMixerResolution(width, height);
754}
755
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +0530756HWC2::Error HWCDisplayBuiltIn::SetQSyncMode(QSyncMode qsync_mode) {
Sushil Chauhan380a59d2018-03-19 15:47:50 -0700757 auto err = display_intf_->SetQSyncMode(qsync_mode);
758 if (err != kErrorNone) {
759 return HWC2::Error::Unsupported;
760 }
761
762 return HWC2::Error::None;
763}
764
Ramkumar Radhakrishnanf985d482018-07-23 18:10:41 -0700765HWC2::Error HWCDisplayBuiltIn::ControlIdlePowerCollapse(bool enable, bool synchronous) {
766 DisplayError error = kErrorNone;
767
768 if (display_intf_) {
769 error = display_intf_->ControlIdlePowerCollapse(enable, synchronous);
770 validated_ = false;
771 }
772
773 return (error != kErrorNone) ? HWC2::Error::Unsupported : HWC2::Error::None;
774}
775
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500776} // namespace sdm