blob: cc02ad641b81fd0e64e605bc2985cb398f4be547 [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() {
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500128 uint32_t numBootUpLayers = 0;
129 // TODO(user): Remove this hack
130
131 numBootUpLayers = static_cast<uint32_t>(Debug::GetBootAnimLayerCount());
132
133 if (numBootUpLayers == 0) {
134 numBootUpLayers = 2;
135 }
136 /* All other checks namely "init.svc.bootanim" or
137 * HWC_GEOMETRY_CHANGED fail in correctly identifying the
138 * exact bootup transition to homescreen
139 */
Naseer Ahmedac442ae2016-06-23 18:58:03 -0400140 char property[PROPERTY_VALUE_MAX];
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500141 bool isEncrypted = false;
142 bool main_class_services_started = false;
Naseer Ahmedac442ae2016-06-23 18:58:03 -0400143 property_get("ro.crypto.state", property, "unencrypted");
144 if (!strcmp(property, "encrypted")) {
145 property_get("ro.crypto.type", property, "block");
146 if (!strcmp(property, "block")) {
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500147 isEncrypted = true;
Naseer Ahmedac442ae2016-06-23 18:58:03 -0400148 property_get("vold.decrypt", property, "");
149 if (!strcmp(property, "trigger_restart_framework")) {
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500150 main_class_services_started = true;
Naseer Ahmedac442ae2016-06-23 18:58:03 -0400151 }
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500152 }
153 }
Naseer Ahmedac442ae2016-06-23 18:58:03 -0400154
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500155 if ((!isEncrypted || (isEncrypted && main_class_services_started)) &&
156 (layer_set_.size() > numBootUpLayers)) {
Naseer Ahmedac442ae2016-06-23 18:58:03 -0400157 DLOGI("Applying default mode");
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500158 boot_animation_completed_ = true;
159 // Applying default mode after bootanimation is finished And
160 // If Data is Encrypted, it is ready for access.
Ch Ganesh Kumar5d43ff62017-10-13 19:01:47 +0530161 if (display_intf_) {
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500162 display_intf_->ApplyDefaultDisplayMode();
Ch Ganesh Kumar5d43ff62017-10-13 19:01:47 +0530163 RestoreColorTransform();
164 }
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500165 }
166}
167
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +0530168HWC2::Error HWCDisplayBuiltIn::Validate(uint32_t *out_num_types, uint32_t *out_num_requests) {
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500169 auto status = HWC2::Error::None;
170 DisplayError error = kErrorNone;
171
Ch Ganesh Kumar86c46512017-06-13 13:09:22 +0530172 if (default_mode_status_ && !boot_animation_completed_) {
173 ProcessBootAnimCompleted();
174 }
175
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500176 if (display_paused_) {
177 MarkLayersForGPUBypass();
178 return status;
179 }
180
Arun Kumar K.R29cd6582016-05-10 19:12:45 -0700181 if (color_tranform_failed_) {
182 // Must fall back to client composition
183 MarkLayersForClientComposition();
184 }
185
Ramkumar Radhakrishnan3dcf8a22017-11-27 14:53:06 -0800186 if (config_pending_) {
187 if (display_intf_->SetActiveConfig(display_config_) != kErrorNone) {
188 DLOGW("Invalid display config %d", display_config_);
189 // Reset the display config with active config
190 display_intf_->GetActiveConfig(&display_config_);
191 }
192 }
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500193 // Fill in the remaining blanks in the layers and add them to the SDM layerstack
194 BuildLayerStack();
Arun Kumar K.R536c7d62016-06-14 18:47:39 -0700195 // Checks and replaces layer stack for solid fill
196 SolidFillPrepare();
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500197
198 bool pending_output_dump = dump_frame_count_ && dump_output_to_file_;
199
Sushil Chauhan06521582018-03-19 14:00:23 -0700200 if (readback_buffer_queued_ || pending_output_dump) {
201 CloseFd(&output_buffer_.release_fence_fd);
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500202 // RHS values were set in FrameCaptureAsync() called from a binder thread. They are picked up
Sushil Chauhan06521582018-03-19 14:00:23 -0700203 // here in a subsequent draw round. Readback is not allowed for any secure use case.
204 readback_configured_ = !layer_stack_.flags.secure_present;
205 if (readback_configured_) {
206 layer_stack_.output_buffer = &output_buffer_;
207 layer_stack_.flags.post_processed_output = post_processed_output_;
208 }
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500209 }
210
Ramakant Singh5db0dfb2017-08-23 12:34:57 +0530211 uint32_t num_updating_layers = GetUpdatingLayersCount();
212 bool one_updating_layer = (num_updating_layers == 1);
213 if (num_updating_layers != 0) {
214 ToggleCPUHint(one_updating_layer);
215 }
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500216
217 uint32_t refresh_rate = GetOptimalRefreshRate(one_updating_layer);
Anjaneya Prasad Musunuri4d65df72017-05-18 19:11:28 +0530218 bool final_rate = force_refresh_rate_ ? true : false;
219 error = display_intf_->SetRefreshRate(refresh_rate, final_rate);
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500220 if (error == kErrorNone) {
221 // On success, set current refresh rate to new refresh rate
222 current_refresh_rate_ = refresh_rate;
223 }
224
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500225 if (layer_set_.empty()) {
Uday Kiran Pichika8d827732018-01-09 18:08:38 +0530226 // Avoid flush for Command mode panel.
Ramkumar Radhakrishnana38b7602018-03-15 14:49:52 -0700227 flush_ = !IsDisplayCommandMode();
228 validated_ = true;
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500229 return status;
230 }
231
232 status = PrepareLayerStack(out_num_types, out_num_requests);
233 return status;
234}
235
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +0530236HWC2::Error HWCDisplayBuiltIn::Present(int32_t *out_retire_fence) {
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500237 auto status = HWC2::Error::None;
238 if (display_paused_) {
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500239 DisplayError error = display_intf_->Flush();
Saurabh Shaha307e8c2017-09-28 18:05:40 -0700240 validated_ = false;
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500241 if (error != kErrorNone) {
242 DLOGE("Flush failed. Error = %d", error);
243 }
244 } else {
245 status = HWCDisplay::CommitLayerStack();
246 if (status == HWC2::Error::None) {
247 HandleFrameOutput();
Arun Kumar K.R536c7d62016-06-14 18:47:39 -0700248 SolidFillCommit();
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500249 status = HWCDisplay::PostCommitLayerStack(out_retire_fence);
250 }
251 }
Arun Kumar K.R536c7d62016-06-14 18:47:39 -0700252
Sushil Chauhan06521582018-03-19 14:00:23 -0700253 CloseFd(&output_buffer_.acquire_fence_fd);
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500254 return status;
255}
256
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +0530257HWC2::Error HWCDisplayBuiltIn::GetColorModes(uint32_t *out_num_modes, ColorMode *out_modes) {
Arun Kumar K.R29cd6582016-05-10 19:12:45 -0700258 if (out_modes == nullptr) {
259 *out_num_modes = color_mode_->GetColorModeCount();
260 } else {
261 color_mode_->GetColorModes(out_num_modes, out_modes);
262 }
263
264 return HWC2::Error::None;
265}
266
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +0530267HWC2::Error HWCDisplayBuiltIn::GetRenderIntents(ColorMode mode, uint32_t *out_num_intents,
Naseer Ahmede7a77982018-06-04 10:56:04 -0400268 RenderIntent *out_intents) {
269 if (out_intents == nullptr) {
270 *out_num_intents = color_mode_->GetRenderIntentCount(mode);
271 } else {
272 color_mode_->GetRenderIntents(mode, out_num_intents, out_intents);
273 }
274 return HWC2::Error::None;
275}
276
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +0530277HWC2::Error HWCDisplayBuiltIn::SetColorMode(ColorMode mode) {
Naseer Ahmede7a77982018-06-04 10:56:04 -0400278 return SetColorModeWithRenderIntent(mode, RenderIntent::COLORIMETRIC);
279}
280
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +0530281HWC2::Error HWCDisplayBuiltIn::SetColorModeWithRenderIntent(ColorMode mode, RenderIntent intent) {
Naseer Ahmede7a77982018-06-04 10:56:04 -0400282 auto status = color_mode_->SetColorModeWithRenderIntent(mode, intent);
Arun Kumar K.R29cd6582016-05-10 19:12:45 -0700283 if (status != HWC2::Error::None) {
Naseer Ahmede7a77982018-06-04 10:56:04 -0400284 DLOGE("failed for mode = %d intent = %d", mode, intent);
Arun Kumar K.R29cd6582016-05-10 19:12:45 -0700285 return status;
286 }
Arun Kumar K.R29cd6582016-05-10 19:12:45 -0700287 callbacks_->Refresh(HWC_DISPLAY_PRIMARY);
Saurabh Shaha307e8c2017-09-28 18:05:40 -0700288 validated_ = false;
Arun Kumar K.R29cd6582016-05-10 19:12:45 -0700289 return status;
290}
291
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +0530292HWC2::Error HWCDisplayBuiltIn::SetColorModeById(int32_t color_mode_id) {
Naseer Ahmed6776dae2017-05-09 11:49:41 -0400293 auto status = color_mode_->SetColorModeById(color_mode_id);
294 if (status != HWC2::Error::None) {
295 DLOGE("failed for mode = %d", color_mode_id);
296 return status;
297 }
298
299 callbacks_->Refresh(HWC_DISPLAY_PRIMARY);
Saurabh Shaha307e8c2017-09-28 18:05:40 -0700300 validated_ = false;
Naseer Ahmed6776dae2017-05-09 11:49:41 -0400301
302 return status;
303}
304
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +0530305HWC2::Error HWCDisplayBuiltIn::RestoreColorTransform() {
Ch Ganesh Kumar5d43ff62017-10-13 19:01:47 +0530306 auto status = color_mode_->RestoreColorTransform();
307 if (status != HWC2::Error::None) {
308 DLOGE("failed to RestoreColorTransform");
309 return status;
310 }
311
312 callbacks_->Refresh(HWC_DISPLAY_PRIMARY);
313
314 return status;
315}
316
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +0530317HWC2::Error HWCDisplayBuiltIn::SetColorTransform(const float *matrix,
Arun Kumar K.R29cd6582016-05-10 19:12:45 -0700318 android_color_transform_t hint) {
319 if (!matrix) {
320 return HWC2::Error::BadParameter;
321 }
322
323 auto status = color_mode_->SetColorTransform(matrix, hint);
324 if (status != HWC2::Error::None) {
325 DLOGE("failed for hint = %d", hint);
326 color_tranform_failed_ = true;
327 return status;
328 }
329
330 callbacks_->Refresh(HWC_DISPLAY_PRIMARY);
331 color_tranform_failed_ = false;
Saurabh Shaha307e8c2017-09-28 18:05:40 -0700332 validated_ = false;
Arun Kumar K.R29cd6582016-05-10 19:12:45 -0700333
334 return status;
335}
336
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +0530337HWC2::Error HWCDisplayBuiltIn::SetReadbackBuffer(const native_handle_t *buffer,
Sushil Chauhan06521582018-03-19 14:00:23 -0700338 int32_t acquire_fence,
339 bool post_processed_output) {
340 const private_handle_t *handle = reinterpret_cast<const private_handle_t *>(buffer);
341 if (!handle || (handle->fd < 0)) {
342 return HWC2::Error::BadParameter;
343 }
344
345 // Configure the output buffer as Readback buffer
346 output_buffer_.width = UINT32(handle->width);
347 output_buffer_.height = UINT32(handle->height);
348 output_buffer_.unaligned_width = UINT32(handle->unaligned_width);
349 output_buffer_.unaligned_height = UINT32(handle->unaligned_height);
350 output_buffer_.format = HWCLayer::GetSDMFormat(handle->format, handle->flags);
351 output_buffer_.planes[0].fd = handle->fd;
352 output_buffer_.planes[0].stride = UINT32(handle->width);
353 output_buffer_.acquire_fence_fd = dup(acquire_fence);
354 output_buffer_.release_fence_fd = -1;
355
356 post_processed_output_ = post_processed_output;
357 readback_buffer_queued_ = true;
358 readback_configured_ = false;
359 validated_ = false;
360
361 DisablePartialUpdateOneFrame();
362 return HWC2::Error::None;
363}
364
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +0530365HWC2::Error HWCDisplayBuiltIn::GetReadbackBufferFence(int32_t *release_fence) {
Sushil Chauhan06521582018-03-19 14:00:23 -0700366 auto status = HWC2::Error::None;
367
368 if (readback_configured_ && (output_buffer_.release_fence_fd >= 0)) {
369 *release_fence = output_buffer_.release_fence_fd;
370 } else {
371 status = HWC2::Error::Unsupported;
372 *release_fence = -1;
373 }
374
375 post_processed_output_ = false;
376 readback_buffer_queued_ = false;
377 readback_configured_ = false;
378 output_buffer_ = {};
379
380 return status;
381}
382
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +0530383int HWCDisplayBuiltIn::Perform(uint32_t operation, ...) {
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500384 va_list args;
385 va_start(args, operation);
Arun Kumar K.R536c7d62016-06-14 18:47:39 -0700386 int val = 0;
Gopikrishnaiah Anandancc123062017-07-31 17:21:03 -0700387 LayerSolidFill *solid_fill_color;
Arun Kumar K.R536c7d62016-06-14 18:47:39 -0700388 LayerRect *rect = NULL;
389
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500390 switch (operation) {
391 case SET_METADATA_DYN_REFRESH_RATE:
Arun Kumar K.R536c7d62016-06-14 18:47:39 -0700392 val = va_arg(args, int32_t);
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500393 SetMetaDataRefreshRateFlag(val);
394 break;
395 case SET_BINDER_DYN_REFRESH_RATE:
Arun Kumar K.R536c7d62016-06-14 18:47:39 -0700396 val = va_arg(args, int32_t);
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500397 ForceRefreshRate(UINT32(val));
398 break;
399 case SET_DISPLAY_MODE:
Arun Kumar K.R536c7d62016-06-14 18:47:39 -0700400 val = va_arg(args, int32_t);
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500401 SetDisplayMode(UINT32(val));
402 break;
403 case SET_QDCM_SOLID_FILL_INFO:
Gopikrishnaiah Anandancc123062017-07-31 17:21:03 -0700404 solid_fill_color = va_arg(args, LayerSolidFill*);
405 SetQDCMSolidFillInfo(true, *solid_fill_color);
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500406 break;
407 case UNSET_QDCM_SOLID_FILL_INFO:
Gopikrishnaiah Anandancc123062017-07-31 17:21:03 -0700408 solid_fill_color = va_arg(args, LayerSolidFill*);
409 SetQDCMSolidFillInfo(false, *solid_fill_color);
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500410 break;
Arun Kumar K.R536c7d62016-06-14 18:47:39 -0700411 case SET_QDCM_SOLID_FILL_RECT:
412 rect = va_arg(args, LayerRect*);
413 solid_fill_rect_ = *rect;
414 break;
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500415 default:
416 DLOGW("Invalid operation %d", operation);
Arun Kumar K.R536c7d62016-06-14 18:47:39 -0700417 va_end(args);
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500418 return -EINVAL;
419 }
Arun Kumar K.R536c7d62016-06-14 18:47:39 -0700420 va_end(args);
Saurabh Shaha307e8c2017-09-28 18:05:40 -0700421 validated_ = false;
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500422
423 return 0;
424}
425
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +0530426DisplayError HWCDisplayBuiltIn::SetDisplayMode(uint32_t mode) {
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500427 DisplayError error = kErrorNone;
428
429 if (display_intf_) {
430 error = display_intf_->SetDisplayMode(mode);
431 }
432
433 return error;
434}
435
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +0530436void HWCDisplayBuiltIn::SetMetaDataRefreshRateFlag(bool enable) {
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500437 int disable_metadata_dynfps = 0;
438
Uday Kiran Pichika5e656b22018-05-15 18:48:24 +0530439 HWCDebugHandler::Get()->GetProperty(DISABLE_METADATA_DYNAMIC_FPS_PROP, &disable_metadata_dynfps);
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500440 if (disable_metadata_dynfps) {
441 return;
442 }
443 use_metadata_refresh_rate_ = enable;
444}
445
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +0530446void HWCDisplayBuiltIn::SetQDCMSolidFillInfo(bool enable, const LayerSolidFill &color) {
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500447 solid_fill_enable_ = enable;
448 solid_fill_color_ = color;
449}
450
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +0530451void HWCDisplayBuiltIn::ToggleCPUHint(bool set) {
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500452 if (!cpu_hint_) {
453 return;
454 }
455
456 if (set) {
457 cpu_hint_->Set();
458 } else {
459 cpu_hint_->Reset();
460 }
461}
462
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +0530463int HWCDisplayBuiltIn::HandleSecureSession(const std::bitset<kSecureMax> &secure_sessions,
Ramkumar Radhakrishnana38b7602018-03-15 14:49:52 -0700464 bool *power_on_pending) {
465 if (!power_on_pending) {
466 return -EINVAL;
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500467 }
Ramkumar Radhakrishnana38b7602018-03-15 14:49:52 -0700468
469 if (active_secure_sessions_[kSecureDisplay] != secure_sessions[kSecureDisplay]) {
470 SecureEvent secure_event =
471 secure_sessions.test(kSecureDisplay) ? kSecureDisplayStart : kSecureDisplayEnd;
472 DisplayError err = display_intf_->HandleSecureEvent(secure_event);
473 if (err != kErrorNone) {
474 DLOGE("Set secure event failed");
475 return err;
476 }
477
478 DLOGI("SecureDisplay state changed from %d to %d for display %d",
479 active_secure_sessions_.test(kSecureDisplay), secure_sessions.test(kSecureDisplay),
480 type_);
481 }
482 active_secure_sessions_ = secure_sessions;
483 *power_on_pending = false;
484 return 0;
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500485}
486
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +0530487void HWCDisplayBuiltIn::ForceRefreshRate(uint32_t refresh_rate) {
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500488 if ((refresh_rate && (refresh_rate < min_refresh_rate_ || refresh_rate > max_refresh_rate_)) ||
489 force_refresh_rate_ == refresh_rate) {
490 // Cannot honor force refresh rate, as its beyond the range or new request is same
491 return;
492 }
493
494 force_refresh_rate_ = refresh_rate;
495
496 callbacks_->Refresh(HWC_DISPLAY_PRIMARY);
497
498 return;
499}
500
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +0530501uint32_t HWCDisplayBuiltIn::GetOptimalRefreshRate(bool one_updating_layer) {
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500502 if (force_refresh_rate_) {
503 return force_refresh_rate_;
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500504 } else if (use_metadata_refresh_rate_ && one_updating_layer && metadata_refresh_rate_) {
505 return metadata_refresh_rate_;
506 }
507
508 return max_refresh_rate_;
509}
510
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +0530511DisplayError HWCDisplayBuiltIn::Refresh() {
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500512 DisplayError error = kErrorNone;
513
514 callbacks_->Refresh(HWC_DISPLAY_PRIMARY);
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500515
516 return error;
517}
518
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +0530519void HWCDisplayBuiltIn::SetIdleTimeoutMs(uint32_t timeout_ms) {
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500520 display_intf_->SetIdleTimeoutMs(timeout_ms);
Saurabh Shaha307e8c2017-09-28 18:05:40 -0700521 validated_ = false;
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500522}
523
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +0530524void HWCDisplayBuiltIn::HandleFrameOutput() {
Sushil Chauhan06521582018-03-19 14:00:23 -0700525 if (readback_buffer_queued_) {
526 validated_ = false;
527 }
528
529 if (dump_output_to_file_) {
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500530 HandleFrameDump();
531 }
532}
533
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +0530534void HWCDisplayBuiltIn::HandleFrameDump() {
Sushil Chauhan06521582018-03-19 14:00:23 -0700535 if (!readback_configured_) {
536 dump_frame_count_ = 0;
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500537 }
538
Sushil Chauhan06521582018-03-19 14:00:23 -0700539 if (dump_frame_count_ && output_buffer_.release_fence_fd >= 0) {
540 int ret = sync_wait(output_buffer_.release_fence_fd, 1000);
541 ::close(output_buffer_.release_fence_fd);
542 output_buffer_.release_fence_fd = -1;
543 if (ret < 0) {
544 DLOGE("sync_wait error errno = %d, desc = %s", errno, strerror(errno));
545 } else {
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500546 DumpOutputBuffer(output_buffer_info_, output_buffer_base_, layer_stack_.retire_fence_fd);
Sushil Chauhan06521582018-03-19 14:00:23 -0700547 readback_buffer_queued_ = false;
Sushil Chauhan062a7a42018-04-25 22:27:52 -0700548 validated_ = false;
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500549 }
550 }
551
552 if (0 == dump_frame_count_) {
553 dump_output_to_file_ = false;
554 // Unmap and Free buffer
555 if (munmap(output_buffer_base_, output_buffer_info_.alloc_buffer_info.size) != 0) {
556 DLOGE("unmap failed with err %d", errno);
557 }
558 if (buffer_allocator_->FreeBuffer(&output_buffer_info_) != 0) {
559 DLOGE("FreeBuffer failed");
560 }
561
Sushil Chauhan06521582018-03-19 14:00:23 -0700562 readback_buffer_queued_ = false;
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500563 post_processed_output_ = false;
Sushil Chauhan06521582018-03-19 14:00:23 -0700564 readback_configured_ = false;
565
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500566 output_buffer_ = {};
567 output_buffer_info_ = {};
568 output_buffer_base_ = nullptr;
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500569 }
570}
571
Sushil Chauhan267a6192018-06-06 18:41:47 -0700572HWC2::Error HWCDisplayBuiltIn::SetFrameDumpConfig(uint32_t count, uint32_t bit_mask_layer_type,
573 int32_t format, bool post_processed) {
574 HWCDisplay::SetFrameDumpConfig(count, bit_mask_layer_type, format, post_processed);
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500575 dump_output_to_file_ = bit_mask_layer_type & (1 << OUTPUT_LAYER_DUMP);
576 DLOGI("output_layer_dump_enable %d", dump_output_to_file_);
577
578 if (!count || !dump_output_to_file_) {
Mathew Joseph Karimpanaldbd64f82017-10-06 10:13:38 +0530579 return HWC2::Error::None;
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500580 }
581
582 // Allocate and map output buffer
583 output_buffer_info_ = {};
Sushil Chauhan267a6192018-06-06 18:41:47 -0700584
585 if (post_processed) {
586 // To dump post-processed (DSPP) output, use Panel resolution.
587 GetPanelResolution(&output_buffer_info_.buffer_config.width,
588 &output_buffer_info_.buffer_config.height);
589 } else {
590 // To dump Layer Mixer output, use FrameBuffer resolution.
591 GetFrameBufferResolution(&output_buffer_info_.buffer_config.width,
592 &output_buffer_info_.buffer_config.height);
593 }
594
595 output_buffer_info_.buffer_config.format = HWCLayer::GetSDMFormat(format, 0);
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500596 output_buffer_info_.buffer_config.buffer_count = 1;
597 if (buffer_allocator_->AllocateBuffer(&output_buffer_info_) != 0) {
598 DLOGE("Buffer allocation failed");
599 output_buffer_info_ = {};
Mathew Joseph Karimpanaldbd64f82017-10-06 10:13:38 +0530600 return HWC2::Error::NoResources;
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500601 }
602
603 void *buffer = mmap(NULL, output_buffer_info_.alloc_buffer_info.size, PROT_READ | PROT_WRITE,
604 MAP_SHARED, output_buffer_info_.alloc_buffer_info.fd, 0);
605
606 if (buffer == MAP_FAILED) {
607 DLOGE("mmap failed with err %d", errno);
608 buffer_allocator_->FreeBuffer(&output_buffer_info_);
609 output_buffer_info_ = {};
Mathew Joseph Karimpanaldbd64f82017-10-06 10:13:38 +0530610 return HWC2::Error::NoResources;
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500611 }
612
613 output_buffer_base_ = buffer;
Sushil Chauhan06521582018-03-19 14:00:23 -0700614 const native_handle_t *handle = static_cast<native_handle_t *>(output_buffer_info_.private_data);
Sushil Chauhan267a6192018-06-06 18:41:47 -0700615 SetReadbackBuffer(handle, -1, post_processed);
Sushil Chauhan06521582018-03-19 14:00:23 -0700616
Mathew Joseph Karimpanaldbd64f82017-10-06 10:13:38 +0530617 return HWC2::Error::None;
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500618}
619
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +0530620int HWCDisplayBuiltIn::FrameCaptureAsync(const BufferInfo &output_buffer_info,
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500621 bool post_processed_output) {
622 // Note: This function is called in context of a binder thread and a lock is already held
623 if (output_buffer_info.alloc_buffer_info.fd < 0) {
624 DLOGE("Invalid fd %d", output_buffer_info.alloc_buffer_info.fd);
625 return -1;
626 }
627
628 auto panel_width = 0u;
629 auto panel_height = 0u;
630 auto fb_width = 0u;
631 auto fb_height = 0u;
632
633 GetPanelResolution(&panel_width, &panel_height);
634 GetFrameBufferResolution(&fb_width, &fb_height);
635
Ch Ganesh Kumar5c4988b2017-06-07 15:21:02 +0530636 if (post_processed_output && (output_buffer_info.buffer_config.width < panel_width ||
637 output_buffer_info.buffer_config.height < panel_height)) {
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500638 DLOGE("Buffer dimensions should not be less than panel resolution");
639 return -1;
Ch Ganesh Kumar5c4988b2017-06-07 15:21:02 +0530640 } else if (!post_processed_output && (output_buffer_info.buffer_config.width < fb_width ||
641 output_buffer_info.buffer_config.height < fb_height)) {
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500642 DLOGE("Buffer dimensions should not be less than FB resolution");
643 return -1;
644 }
645
Sushil Chauhan06521582018-03-19 14:00:23 -0700646 const native_handle_t *buffer = static_cast<native_handle_t *>(output_buffer_info.private_data);
647 SetReadbackBuffer(buffer, -1, post_processed_output);
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500648
649 return 0;
650}
651
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +0530652bool HWCDisplayBuiltIn::GetFrameCaptureFence(int32_t *release_fence) {
Sushil Chauhan06521582018-03-19 14:00:23 -0700653 return (GetReadbackBufferFence(release_fence) == HWC2::Error::None);
654}
655
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +0530656DisplayError HWCDisplayBuiltIn::SetDetailEnhancerConfig
Alan Kwong2e136332016-08-16 07:50:16 -0400657 (const DisplayDetailEnhancerData &de_data) {
658 DisplayError error = kErrorNotSupported;
659
660 if (display_intf_) {
661 error = display_intf_->SetDetailEnhancerData(de_data);
Saurabh Shaha307e8c2017-09-28 18:05:40 -0700662 validated_ = false;
Alan Kwong2e136332016-08-16 07:50:16 -0400663 }
664 return error;
665}
666
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +0530667DisplayError HWCDisplayBuiltIn::ControlPartialUpdate(bool enable, uint32_t *pending) {
Arun Kumar K.R17bbd042016-06-07 17:38:02 -0700668 DisplayError error = kErrorNone;
669
670 if (display_intf_) {
671 error = display_intf_->ControlPartialUpdate(enable, pending);
Saurabh Shaha307e8c2017-09-28 18:05:40 -0700672 validated_ = false;
Arun Kumar K.R17bbd042016-06-07 17:38:02 -0700673 }
674
675 return error;
676}
677
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +0530678DisplayError HWCDisplayBuiltIn::DisablePartialUpdateOneFrame() {
Arun Kumar K.R17bbd042016-06-07 17:38:02 -0700679 DisplayError error = kErrorNone;
680
681 if (display_intf_) {
682 error = display_intf_->DisablePartialUpdateOneFrame();
Saurabh Shaha307e8c2017-09-28 18:05:40 -0700683 validated_ = false;
Arun Kumar K.R17bbd042016-06-07 17:38:02 -0700684 }
685
686 return error;
687}
688
689
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +0530690DisplayError HWCDisplayBuiltIn::SetMixerResolution(uint32_t width, uint32_t height) {
Sushil Chauhan409e8442017-06-12 17:43:25 -0700691 DisplayError error = display_intf_->SetMixerResolution(width, height);
Saurabh Shaha307e8c2017-09-28 18:05:40 -0700692 validated_ = false;
Sushil Chauhan409e8442017-06-12 17:43:25 -0700693 return error;
Arun Kumar K.R8da7f502016-06-07 17:45:50 -0700694}
695
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +0530696DisplayError HWCDisplayBuiltIn::GetMixerResolution(uint32_t *width, uint32_t *height) {
Arun Kumar K.R8da7f502016-06-07 17:45:50 -0700697 return display_intf_->GetMixerResolution(width, height);
698}
699
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +0530700HWC2::Error HWCDisplayBuiltIn::SetQSyncMode(QSyncMode qsync_mode) {
Sushil Chauhan380a59d2018-03-19 15:47:50 -0700701 auto err = display_intf_->SetQSyncMode(qsync_mode);
702 if (err != kErrorNone) {
703 return HWC2::Error::Unsupported;
704 }
705
706 return HWC2::Error::None;
707}
708
Ramkumar Radhakrishnanf985d482018-07-23 18:10:41 -0700709HWC2::Error HWCDisplayBuiltIn::ControlIdlePowerCollapse(bool enable, bool synchronous) {
710 DisplayError error = kErrorNone;
711
712 if (display_intf_) {
713 error = display_intf_->ControlIdlePowerCollapse(enable, synchronous);
714 validated_ = false;
715 }
716
717 return (error != kErrorNone) ? HWC2::Error::Unsupported : HWC2::Error::None;
718}
719
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500720} // namespace sdm