blob: e6f33ba5c0b93d00a169a71c9fcde4d7b3addaa4 [file] [log] [blame]
Naseer Ahmedb92e73f2016-03-12 02:03:48 -05001/*
Gousemoodhin Nadaf087c3102019-01-07 19:34:56 +05302* Copyright (c) 2014-2019, 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"
Pullakavi Srinivas9189e602018-12-19 16:58:07 +053044#include "hwc_session.h"
Naseer Ahmedb92e73f2016-03-12 02:03:48 -050045
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +053046#define __CLASS__ "HWCDisplayBuiltIn"
Naseer Ahmedb92e73f2016-03-12 02:03:48 -050047
48namespace sdm {
49
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +053050int HWCDisplayBuiltIn::Create(CoreInterface *core_intf, BufferAllocator *buffer_allocator,
Varun Arora7c8ee542018-05-01 20:58:16 -070051 HWCCallbacks *callbacks, HWCDisplayEventHandler *event_handler,
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +053052 qService::QService *qservice, hwc2_display_t id, int32_t sdm_id,
53 HWCDisplay **hwc_display) {
Naseer Ahmedb92e73f2016-03-12 02:03:48 -050054 int status = 0;
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +053055 uint32_t builtin_width = 0;
56 uint32_t builtin_height = 0;
Naseer Ahmedb92e73f2016-03-12 02:03:48 -050057
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +053058 HWCDisplay *hwc_display_builtin =
59 new HWCDisplayBuiltIn(core_intf, buffer_allocator, callbacks, event_handler, qservice, id,
60 sdm_id);
61 status = hwc_display_builtin->Init();
Naseer Ahmedb92e73f2016-03-12 02:03:48 -050062 if (status) {
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +053063 delete hwc_display_builtin;
Naseer Ahmedb92e73f2016-03-12 02:03:48 -050064 return status;
65 }
66
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +053067 hwc_display_builtin->GetMixerResolution(&builtin_width, &builtin_height);
Naseer Ahmedb92e73f2016-03-12 02:03:48 -050068 int width = 0, height = 0;
Uday Kiran Pichika5e656b22018-05-15 18:48:24 +053069 HWCDebugHandler::Get()->GetProperty(FB_WIDTH_PROP, &width);
70 HWCDebugHandler::Get()->GetProperty(FB_HEIGHT_PROP, &height);
Naseer Ahmedb92e73f2016-03-12 02:03:48 -050071 if (width > 0 && height > 0) {
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +053072 builtin_width = UINT32(width);
73 builtin_height = UINT32(height);
Naseer Ahmedb92e73f2016-03-12 02:03:48 -050074 }
75
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +053076 status = hwc_display_builtin->SetFrameBufferResolution(builtin_width, builtin_height);
Naseer Ahmedb92e73f2016-03-12 02:03:48 -050077 if (status) {
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +053078 Destroy(hwc_display_builtin);
Naseer Ahmedb92e73f2016-03-12 02:03:48 -050079 return status;
80 }
81
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +053082 *hwc_display = hwc_display_builtin;
Naseer Ahmedb92e73f2016-03-12 02:03:48 -050083
84 return status;
85}
86
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +053087void HWCDisplayBuiltIn::Destroy(HWCDisplay *hwc_display) {
Naseer Ahmedb92e73f2016-03-12 02:03:48 -050088 hwc_display->Deinit();
89 delete hwc_display;
90}
91
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +053092HWCDisplayBuiltIn::HWCDisplayBuiltIn(CoreInterface *core_intf, BufferAllocator *buffer_allocator,
Varun Arora7c8ee542018-05-01 20:58:16 -070093 HWCCallbacks *callbacks, HWCDisplayEventHandler *event_handler,
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +053094 qService::QService *qservice, hwc2_display_t id,
95 int32_t sdm_id)
96 : HWCDisplay(core_intf, buffer_allocator, callbacks, event_handler, qservice, kBuiltIn, id,
Gousemoodhin Nadaf087c3102019-01-07 19:34:56 +053097 sdm_id, DISPLAY_CLASS_BUILTIN),
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +053098 buffer_allocator_(buffer_allocator),
99 cpu_hint_(NULL) {
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500100}
101
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +0530102int HWCDisplayBuiltIn::Init() {
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500103 cpu_hint_ = new CPUHint();
104 if (cpu_hint_->Init(static_cast<HWCDebugHandler *>(HWCDebugHandler::Get())) != kErrorNone) {
105 delete cpu_hint_;
106 cpu_hint_ = NULL;
107 }
108
109 use_metadata_refresh_rate_ = true;
110 int disable_metadata_dynfps = 0;
Uday Kiran Pichika5e656b22018-05-15 18:48:24 +0530111 HWCDebugHandler::Get()->GetProperty(DISABLE_METADATA_DYNAMIC_FPS_PROP, &disable_metadata_dynfps);
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500112 if (disable_metadata_dynfps) {
113 use_metadata_refresh_rate_ = false;
114 }
115
Arun Kumar K.R29cd6582016-05-10 19:12:45 -0700116 int status = HWCDisplay::Init();
117 if (status) {
118 return status;
119 }
120 color_mode_ = new HWCColorMode(display_intf_);
Naseer Ahmed61f60952017-05-24 16:48:35 -0400121 color_mode_->Init();
Arun Kumar K.R29cd6582016-05-10 19:12:45 -0700122
Padmanabhan Komanduru866bf6a2019-03-19 14:30:48 +0530123 int optimize_refresh = 0;
124 HWCDebugHandler::Get()->GetProperty(ENABLE_OPTIMIZE_REFRESH, &optimize_refresh);
125 enable_optimize_refresh_ = (optimize_refresh == 1);
126 if (enable_optimize_refresh_) {
Padmanabhan Komandurue74cf4f2019-04-25 17:38:43 -0700127 DLOGI("Drop redundant drawcycles %d", id_);
128 }
129
Mathew Joseph Karimpanalb1c15862019-07-04 11:14:24 +0530130 is_primary_ = display_intf_->IsPrimaryDisplay();
131
Naseer Ahmed61f60952017-05-24 16:48:35 -0400132 return status;
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500133}
134
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +0530135HWC2::Error HWCDisplayBuiltIn::Validate(uint32_t *out_num_types, uint32_t *out_num_requests) {
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500136 auto status = HWC2::Error::None;
137 DisplayError error = kErrorNone;
138
Gurpreet Singh Dhamia4276882019-04-12 10:30:58 -0700139 DTRACE_SCOPED();
140
Mathew Joseph Karimpanalb1c15862019-07-04 11:14:24 +0530141 if (display_paused_ || (!is_primary_ && active_secure_sessions_[kSecureDisplay])) {
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500142 MarkLayersForGPUBypass();
143 return status;
144 }
145
Arun Kumar K.R29cd6582016-05-10 19:12:45 -0700146 if (color_tranform_failed_) {
147 // Must fall back to client composition
148 MarkLayersForClientComposition();
149 }
150
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500151 // Fill in the remaining blanks in the layers and add them to the SDM layerstack
152 BuildLayerStack();
Arun Kumar K.R536c7d62016-06-14 18:47:39 -0700153 // Checks and replaces layer stack for solid fill
154 SolidFillPrepare();
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500155
Sushil Chauhan8008d602018-09-04 14:43:27 -0700156 // Apply current Color Mode and Render Intent.
Xu Yang84e61412018-12-06 14:52:16 +0800157 if (color_mode_->ApplyCurrentColorModeWithRenderIntent(
158 static_cast<bool>(layer_stack_.flags.hdr_present)) != HWC2::Error::None) {
Sushil Chauhan8008d602018-09-04 14:43:27 -0700159 // Fallback to GPU Composition, if Color Mode can't be applied.
160 MarkLayersForClientComposition();
161 }
162
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500163 bool pending_output_dump = dump_frame_count_ && dump_output_to_file_;
164
Sushil Chauhan06521582018-03-19 14:00:23 -0700165 if (readback_buffer_queued_ || pending_output_dump) {
166 CloseFd(&output_buffer_.release_fence_fd);
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500167 // RHS values were set in FrameCaptureAsync() called from a binder thread. They are picked up
Sushil Chauhan06521582018-03-19 14:00:23 -0700168 // here in a subsequent draw round. Readback is not allowed for any secure use case.
169 readback_configured_ = !layer_stack_.flags.secure_present;
170 if (readback_configured_) {
Sushil Chauhanf42d8622018-09-30 23:20:37 -0700171 DisablePartialUpdateOneFrame();
Sushil Chauhan06521582018-03-19 14:00:23 -0700172 layer_stack_.output_buffer = &output_buffer_;
173 layer_stack_.flags.post_processed_output = post_processed_output_;
174 }
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500175 }
176
Ramakant Singh5db0dfb2017-08-23 12:34:57 +0530177 uint32_t num_updating_layers = GetUpdatingLayersCount();
178 bool one_updating_layer = (num_updating_layers == 1);
179 if (num_updating_layers != 0) {
180 ToggleCPUHint(one_updating_layer);
181 }
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500182
183 uint32_t refresh_rate = GetOptimalRefreshRate(one_updating_layer);
Pullakavi Srinivas4619db92019-04-20 15:07:59 +0530184 error = display_intf_->SetRefreshRate(refresh_rate, force_refresh_rate_);
185
186 // Get the refresh rate set.
187 display_intf_->GetRefreshRate(&refresh_rate);
188 bool vsync_source = (callbacks_->GetVsyncSource() == id_);
189
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500190 if (error == kErrorNone) {
Pullakavi Srinivas4619db92019-04-20 15:07:59 +0530191 if (vsync_source && (current_refresh_rate_ < refresh_rate)) {
192 DTRACE_BEGIN("HWC2::Vsync::Enable");
193 // Display is ramping up from idle.
194 // Client realizes need for resync upon change in config.
195 // Since we know config has changed, triggering vsync proactively
196 // can help in reducing pipeline delays to enable events.
197 SetVsyncEnabled(HWC2::Vsync::Enable);
198 DTRACE_END();
199 }
200 // On success, set current refresh rate to new refresh rate.
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500201 current_refresh_rate_ = refresh_rate;
202 }
203
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500204 if (layer_set_.empty()) {
Uday Kiran Pichika8d827732018-01-09 18:08:38 +0530205 // Avoid flush for Command mode panel.
Pullakavi Srinivas2d55f3a2019-07-16 14:49:06 +0530206 flush_ = !client_connected_;
Ramkumar Radhakrishnana38b7602018-03-15 14:49:52 -0700207 validated_ = true;
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500208 return status;
209 }
210
211 status = PrepareLayerStack(out_num_types, out_num_requests);
Namit Solanki5b428dc2018-02-27 11:39:05 +0530212 pending_commit_ = true;
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500213 return status;
214}
215
Padmanabhan Komandurue74cf4f2019-04-25 17:38:43 -0700216HWC2::Error HWCDisplayBuiltIn::CommitLayerStack() {
217 skip_commit_ = CanSkipCommit();
218 return HWCDisplay::CommitLayerStack();
219}
220
221bool HWCDisplayBuiltIn::CanSkipCommit() {
222 if (layer_stack_invalid_) {
223 return false;
224 }
225
226 // Reject repeated drawcycle requests if it satisfies all conditions.
227 // 1. None of the layerstack attributes changed.
228 // 2. No new buffer latched.
229 // 3. No refresh request triggered by HWC.
230 // 4. This display is not source of vsync.
231 bool buffers_latched = false;
232 for (auto &hwc_layer : layer_set_) {
233 buffers_latched |= hwc_layer->BufferLatched();
234 hwc_layer->ResetBufferFlip();
235 }
236
Padmanabhan Komanduruf5e6c5d2019-04-04 13:56:31 +0530237 bool vsync_source = (callbacks_->GetVsyncSource() == id_);
Padmanabhan Komanduru866bf6a2019-03-19 14:30:48 +0530238 bool skip_commit = enable_optimize_refresh_ && !pending_commit_ && !buffers_latched &&
Padmanabhan Komanduruf5e6c5d2019-04-04 13:56:31 +0530239 !pending_refresh_ && !vsync_source;
Padmanabhan Komandurue74cf4f2019-04-25 17:38:43 -0700240 pending_refresh_ = false;
241
242 return skip_commit;
243}
244
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +0530245HWC2::Error HWCDisplayBuiltIn::Present(int32_t *out_retire_fence) {
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500246 auto status = HWC2::Error::None;
Gurpreet Singh Dhamia4276882019-04-12 10:30:58 -0700247
248 DTRACE_SCOPED();
Mathew Joseph Karimpanalb1c15862019-07-04 11:14:24 +0530249
250 if (!is_primary_ && active_secure_sessions_[kSecureDisplay]) {
251 return status;
252 } else if (display_paused_) {
Pullakavi Srinivas0a1dba62018-07-02 15:49:11 +0530253 DisplayError error = display_intf_->Flush(&layer_stack_);
Saurabh Shaha307e8c2017-09-28 18:05:40 -0700254 validated_ = false;
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500255 if (error != kErrorNone) {
256 DLOGE("Flush failed. Error = %d", error);
257 }
258 } else {
Padmanabhan Komandurue74cf4f2019-04-25 17:38:43 -0700259 status = CommitLayerStack();
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500260 if (status == HWC2::Error::None) {
261 HandleFrameOutput();
Arun Kumar K.R536c7d62016-06-14 18:47:39 -0700262 SolidFillCommit();
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500263 status = HWCDisplay::PostCommitLayerStack(out_retire_fence);
264 }
265 }
Arun Kumar K.R536c7d62016-06-14 18:47:39 -0700266
Sushil Chauhan06521582018-03-19 14:00:23 -0700267 CloseFd(&output_buffer_.acquire_fence_fd);
Namit Solanki5b428dc2018-02-27 11:39:05 +0530268 pending_commit_ = false;
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500269 return status;
270}
271
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +0530272HWC2::Error HWCDisplayBuiltIn::GetColorModes(uint32_t *out_num_modes, ColorMode *out_modes) {
Arun Kumar K.R29cd6582016-05-10 19:12:45 -0700273 if (out_modes == nullptr) {
274 *out_num_modes = color_mode_->GetColorModeCount();
275 } else {
276 color_mode_->GetColorModes(out_num_modes, out_modes);
277 }
278
279 return HWC2::Error::None;
280}
281
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +0530282HWC2::Error HWCDisplayBuiltIn::GetRenderIntents(ColorMode mode, uint32_t *out_num_intents,
Naseer Ahmede7a77982018-06-04 10:56:04 -0400283 RenderIntent *out_intents) {
284 if (out_intents == nullptr) {
285 *out_num_intents = color_mode_->GetRenderIntentCount(mode);
286 } else {
287 color_mode_->GetRenderIntents(mode, out_num_intents, out_intents);
288 }
289 return HWC2::Error::None;
290}
291
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +0530292HWC2::Error HWCDisplayBuiltIn::SetColorMode(ColorMode mode) {
Naseer Ahmede7a77982018-06-04 10:56:04 -0400293 return SetColorModeWithRenderIntent(mode, RenderIntent::COLORIMETRIC);
294}
295
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +0530296HWC2::Error HWCDisplayBuiltIn::SetColorModeWithRenderIntent(ColorMode mode, RenderIntent intent) {
Sushil Chauhan8008d602018-09-04 14:43:27 -0700297 auto status = color_mode_->CacheColorModeWithRenderIntent(mode, intent);
Arun Kumar K.R29cd6582016-05-10 19:12:45 -0700298 if (status != HWC2::Error::None) {
Naseer Ahmede7a77982018-06-04 10:56:04 -0400299 DLOGE("failed for mode = %d intent = %d", mode, intent);
Arun Kumar K.R29cd6582016-05-10 19:12:45 -0700300 return status;
301 }
Ramkumar Radhakrishnan44c64362018-12-12 13:03:59 -0800302 callbacks_->Refresh(id_);
Saurabh Shaha307e8c2017-09-28 18:05:40 -0700303 validated_ = false;
Arun Kumar K.R29cd6582016-05-10 19:12:45 -0700304 return status;
305}
306
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +0530307HWC2::Error HWCDisplayBuiltIn::SetColorModeById(int32_t color_mode_id) {
Naseer Ahmed6776dae2017-05-09 11:49:41 -0400308 auto status = color_mode_->SetColorModeById(color_mode_id);
309 if (status != HWC2::Error::None) {
310 DLOGE("failed for mode = %d", color_mode_id);
311 return status;
312 }
313
Ramkumar Radhakrishnan44c64362018-12-12 13:03:59 -0800314 callbacks_->Refresh(id_);
Saurabh Shaha307e8c2017-09-28 18:05:40 -0700315 validated_ = false;
Naseer Ahmed6776dae2017-05-09 11:49:41 -0400316
317 return status;
318}
319
Xu Yang84e61412018-12-06 14:52:16 +0800320HWC2::Error HWCDisplayBuiltIn::SetColorModeFromClientApi(int32_t color_mode_id) {
321 DisplayError error = kErrorNone;
322 std::string mode_string;
323
324 error = display_intf_->GetColorModeName(color_mode_id, &mode_string);
325 if (error) {
326 DLOGE("Failed to get mode name for mode %d", color_mode_id);
327 return HWC2::Error::BadParameter;
328 }
329
330 auto status = color_mode_->SetColorModeFromClientApi(mode_string);
331 if (status != HWC2::Error::None) {
332 DLOGE("Failed to set mode = %d", color_mode_id);
333 return status;
334 }
335
336 return status;
337}
338
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +0530339HWC2::Error HWCDisplayBuiltIn::RestoreColorTransform() {
Ch Ganesh Kumar5d43ff62017-10-13 19:01:47 +0530340 auto status = color_mode_->RestoreColorTransform();
341 if (status != HWC2::Error::None) {
342 DLOGE("failed to RestoreColorTransform");
343 return status;
344 }
345
Ramkumar Radhakrishnan44c64362018-12-12 13:03:59 -0800346 callbacks_->Refresh(id_);
Ch Ganesh Kumar5d43ff62017-10-13 19:01:47 +0530347
348 return status;
349}
350
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +0530351HWC2::Error HWCDisplayBuiltIn::SetColorTransform(const float *matrix,
Arun Kumar K.R29cd6582016-05-10 19:12:45 -0700352 android_color_transform_t hint) {
353 if (!matrix) {
354 return HWC2::Error::BadParameter;
355 }
356
357 auto status = color_mode_->SetColorTransform(matrix, hint);
358 if (status != HWC2::Error::None) {
359 DLOGE("failed for hint = %d", hint);
360 color_tranform_failed_ = true;
361 return status;
362 }
363
Ramkumar Radhakrishnan44c64362018-12-12 13:03:59 -0800364 callbacks_->Refresh(id_);
Arun Kumar K.R29cd6582016-05-10 19:12:45 -0700365 color_tranform_failed_ = false;
Saurabh Shaha307e8c2017-09-28 18:05:40 -0700366 validated_ = false;
Arun Kumar K.R29cd6582016-05-10 19:12:45 -0700367
368 return status;
369}
370
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +0530371HWC2::Error HWCDisplayBuiltIn::SetReadbackBuffer(const native_handle_t *buffer,
Dileep Marchyacb2a3a92019-06-21 17:30:50 +0530372 int32_t acquire_fence, bool post_processed_output,
373 CWBClient client) {
374 if (cwb_client_ != client && cwb_client_ != kCWBClientNone) {
375 DLOGE("CWB is in use with client = %d", cwb_client_);
376 return HWC2::Error::NoResources;
377 }
378
Sushil Chauhan06521582018-03-19 14:00:23 -0700379 const private_handle_t *handle = reinterpret_cast<const private_handle_t *>(buffer);
380 if (!handle || (handle->fd < 0)) {
381 return HWC2::Error::BadParameter;
382 }
383
384 // Configure the output buffer as Readback buffer
385 output_buffer_.width = UINT32(handle->width);
386 output_buffer_.height = UINT32(handle->height);
387 output_buffer_.unaligned_width = UINT32(handle->unaligned_width);
388 output_buffer_.unaligned_height = UINT32(handle->unaligned_height);
389 output_buffer_.format = HWCLayer::GetSDMFormat(handle->format, handle->flags);
390 output_buffer_.planes[0].fd = handle->fd;
391 output_buffer_.planes[0].stride = UINT32(handle->width);
392 output_buffer_.acquire_fence_fd = dup(acquire_fence);
393 output_buffer_.release_fence_fd = -1;
Sushil Chauhand0dc03d2018-09-19 07:08:40 -0700394 output_buffer_.handle_id = handle->id;
Sushil Chauhan06521582018-03-19 14:00:23 -0700395
396 post_processed_output_ = post_processed_output;
397 readback_buffer_queued_ = true;
398 readback_configured_ = false;
399 validated_ = false;
Dileep Marchyacb2a3a92019-06-21 17:30:50 +0530400 cwb_client_ = client;
Sushil Chauhan06521582018-03-19 14:00:23 -0700401
Sushil Chauhan06521582018-03-19 14:00:23 -0700402 return HWC2::Error::None;
403}
404
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +0530405HWC2::Error HWCDisplayBuiltIn::GetReadbackBufferFence(int32_t *release_fence) {
Sushil Chauhan06521582018-03-19 14:00:23 -0700406 auto status = HWC2::Error::None;
407
408 if (readback_configured_ && (output_buffer_.release_fence_fd >= 0)) {
409 *release_fence = output_buffer_.release_fence_fd;
410 } else {
411 status = HWC2::Error::Unsupported;
412 *release_fence = -1;
413 }
414
415 post_processed_output_ = false;
416 readback_buffer_queued_ = false;
417 readback_configured_ = false;
418 output_buffer_ = {};
Dileep Marchyacb2a3a92019-06-21 17:30:50 +0530419 cwb_client_ = kCWBClientNone;
Sushil Chauhan06521582018-03-19 14:00:23 -0700420
421 return status;
422}
423
Gurpreet Singh Dhami1207e462018-12-27 20:02:02 -0500424DisplayError HWCDisplayBuiltIn::TeardownConcurrentWriteback(void) {
425 DisplayError error = kErrorNotSupported;
426
427 if (output_buffer_.release_fence_fd >= 0) {
428 int32_t release_fence_fd = dup(output_buffer_.release_fence_fd);
429 int ret = sync_wait(output_buffer_.release_fence_fd, 1000);
430 if (ret < 0) {
431 DLOGE("sync_wait error errno = %d, desc = %s", errno, strerror(errno));
432 }
433
434 ::close(release_fence_fd);
435 if (ret)
436 return kErrorResources;
437 }
438
439 if (display_intf_) {
440 error = display_intf_->TeardownConcurrentWriteback();
441 }
442
443 return error;
444}
445
Yuchao Ma577f0f72018-07-09 11:20:00 +0800446HWC2::Error HWCDisplayBuiltIn::SetDisplayDppsAdROI(uint32_t h_start, uint32_t h_end,
447 uint32_t v_start, uint32_t v_end,
448 uint32_t factor_in, uint32_t factor_out) {
449 DisplayError error = kErrorNone;
450 DisplayDppsAd4RoiCfg dpps_ad4_roi_cfg = {};
451 uint32_t panel_width = 0, panel_height = 0;
452 constexpr uint16_t kMaxFactorVal = 0xffff;
453
454 if (h_start >= h_end || v_start >= v_end || factor_in > kMaxFactorVal ||
455 factor_out > kMaxFactorVal) {
456 DLOGE("Invalid roi region = [%u, %u, %u, %u, %u, %u]",
457 h_start, h_end, v_start, v_end, factor_in, factor_out);
458 return HWC2::Error::BadParameter;
459 }
460
461 GetPanelResolution(&panel_width, &panel_height);
462
463 if (h_start >= panel_width || h_end > panel_width ||
464 v_start >= panel_height || v_end > panel_height) {
465 DLOGE("Invalid roi region = [%u, %u, %u, %u], panel resolution = [%u, %u]",
466 h_start, h_end, v_start, v_end, panel_width, panel_height);
467 return HWC2::Error::BadParameter;
468 }
469
470 dpps_ad4_roi_cfg.h_start = h_start;
471 dpps_ad4_roi_cfg.h_end = h_end;
472 dpps_ad4_roi_cfg.v_start = v_start;
473 dpps_ad4_roi_cfg.v_end = v_end;
474 dpps_ad4_roi_cfg.factor_in = factor_in;
475 dpps_ad4_roi_cfg.factor_out = factor_out;
476
477 error = display_intf_->SetDisplayDppsAdROI(&dpps_ad4_roi_cfg);
478 if (error)
479 return HWC2::Error::BadConfig;
480
Ramkumar Radhakrishnan44c64362018-12-12 13:03:59 -0800481 callbacks_->Refresh(id_);
Yuchao Ma577f0f72018-07-09 11:20:00 +0800482
483 return HWC2::Error::None;
484}
485
Xu Yang9dacc872018-12-25 11:04:28 +0800486HWC2::Error HWCDisplayBuiltIn::SetFrameTriggerMode(uint32_t mode) {
487 DisplayError error = kErrorNone;
488 FrameTriggerMode trigger_mode = kFrameTriggerDefault;
489
490 if (mode >= kFrameTriggerMax) {
491 DLOGE("Invalid input mode %d", mode);
492 return HWC2::Error::BadParameter;
493 }
494
495 trigger_mode = static_cast<FrameTriggerMode>(mode);
496 error = display_intf_->SetFrameTriggerMode(trigger_mode);
497 if (error)
498 return HWC2::Error::BadConfig;
499
500 callbacks_->Refresh(HWC_DISPLAY_PRIMARY);
501 validated_ = false;
502
503 return HWC2::Error::None;
504}
505
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +0530506int HWCDisplayBuiltIn::Perform(uint32_t operation, ...) {
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500507 va_list args;
508 va_start(args, operation);
Arun Kumar K.R536c7d62016-06-14 18:47:39 -0700509 int val = 0;
Gopikrishnaiah Anandancc123062017-07-31 17:21:03 -0700510 LayerSolidFill *solid_fill_color;
Arun Kumar K.R536c7d62016-06-14 18:47:39 -0700511 LayerRect *rect = NULL;
512
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500513 switch (operation) {
514 case SET_METADATA_DYN_REFRESH_RATE:
Arun Kumar K.R536c7d62016-06-14 18:47:39 -0700515 val = va_arg(args, int32_t);
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500516 SetMetaDataRefreshRateFlag(val);
517 break;
518 case SET_BINDER_DYN_REFRESH_RATE:
Arun Kumar K.R536c7d62016-06-14 18:47:39 -0700519 val = va_arg(args, int32_t);
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500520 ForceRefreshRate(UINT32(val));
521 break;
522 case SET_DISPLAY_MODE:
Arun Kumar K.R536c7d62016-06-14 18:47:39 -0700523 val = va_arg(args, int32_t);
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500524 SetDisplayMode(UINT32(val));
525 break;
526 case SET_QDCM_SOLID_FILL_INFO:
Gopikrishnaiah Anandancc123062017-07-31 17:21:03 -0700527 solid_fill_color = va_arg(args, LayerSolidFill*);
528 SetQDCMSolidFillInfo(true, *solid_fill_color);
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500529 break;
530 case UNSET_QDCM_SOLID_FILL_INFO:
Gopikrishnaiah Anandancc123062017-07-31 17:21:03 -0700531 solid_fill_color = va_arg(args, LayerSolidFill*);
532 SetQDCMSolidFillInfo(false, *solid_fill_color);
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500533 break;
Arun Kumar K.R536c7d62016-06-14 18:47:39 -0700534 case SET_QDCM_SOLID_FILL_RECT:
535 rect = va_arg(args, LayerRect*);
536 solid_fill_rect_ = *rect;
537 break;
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500538 default:
539 DLOGW("Invalid operation %d", operation);
Arun Kumar K.R536c7d62016-06-14 18:47:39 -0700540 va_end(args);
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500541 return -EINVAL;
542 }
Arun Kumar K.R536c7d62016-06-14 18:47:39 -0700543 va_end(args);
Saurabh Shaha307e8c2017-09-28 18:05:40 -0700544 validated_ = false;
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500545
546 return 0;
547}
548
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +0530549DisplayError HWCDisplayBuiltIn::SetDisplayMode(uint32_t mode) {
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500550 DisplayError error = kErrorNone;
551
552 if (display_intf_) {
553 error = display_intf_->SetDisplayMode(mode);
Tharaga Balachandran04192a62018-08-29 16:23:25 -0400554 if (error == kErrorNone) {
555 DisplayConfigFixedInfo fixed_info = {};
556 display_intf_->GetConfig(&fixed_info);
557 is_cmd_mode_ = fixed_info.is_cmdmode;
558 partial_update_enabled_ = fixed_info.partial_update;
559 for (auto hwc_layer : layer_set_) {
560 hwc_layer->SetPartialUpdate(partial_update_enabled_);
561 }
562 client_target_->SetPartialUpdate(partial_update_enabled_);
563 }
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500564 }
565
566 return error;
567}
568
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +0530569void HWCDisplayBuiltIn::SetMetaDataRefreshRateFlag(bool enable) {
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500570 int disable_metadata_dynfps = 0;
571
Uday Kiran Pichika5e656b22018-05-15 18:48:24 +0530572 HWCDebugHandler::Get()->GetProperty(DISABLE_METADATA_DYNAMIC_FPS_PROP, &disable_metadata_dynfps);
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500573 if (disable_metadata_dynfps) {
574 return;
575 }
576 use_metadata_refresh_rate_ = enable;
577}
578
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +0530579void HWCDisplayBuiltIn::SetQDCMSolidFillInfo(bool enable, const LayerSolidFill &color) {
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500580 solid_fill_enable_ = enable;
581 solid_fill_color_ = color;
582}
583
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +0530584void HWCDisplayBuiltIn::ToggleCPUHint(bool set) {
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500585 if (!cpu_hint_) {
586 return;
587 }
588
589 if (set) {
590 cpu_hint_->Set();
591 } else {
592 cpu_hint_->Reset();
593 }
594}
595
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +0530596int HWCDisplayBuiltIn::HandleSecureSession(const std::bitset<kSecureMax> &secure_sessions,
Ramkumar Radhakrishnana38b7602018-03-15 14:49:52 -0700597 bool *power_on_pending) {
598 if (!power_on_pending) {
599 return -EINVAL;
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500600 }
Ramkumar Radhakrishnana38b7602018-03-15 14:49:52 -0700601
Mathew Joseph Karimpanalb1c15862019-07-04 11:14:24 +0530602 if (!is_primary_) {
603 return HWCDisplay::HandleSecureSession(secure_sessions, power_on_pending);
604 }
605
Ramkumar Radhakrishnan44c64362018-12-12 13:03:59 -0800606 if (current_power_mode_ != HWC2::PowerMode::On) {
607 return 0;
608 }
609
Ramkumar Radhakrishnana38b7602018-03-15 14:49:52 -0700610 if (active_secure_sessions_[kSecureDisplay] != secure_sessions[kSecureDisplay]) {
611 SecureEvent secure_event =
612 secure_sessions.test(kSecureDisplay) ? kSecureDisplayStart : kSecureDisplayEnd;
Pullakavi Srinivas0a1dba62018-07-02 15:49:11 +0530613 DisplayError err = display_intf_->HandleSecureEvent(secure_event, &layer_stack_);
Ramkumar Radhakrishnana38b7602018-03-15 14:49:52 -0700614 if (err != kErrorNone) {
615 DLOGE("Set secure event failed");
616 return err;
617 }
618
Mathew Joseph Karimpanalb1c15862019-07-04 11:14:24 +0530619 DLOGI("SecureDisplay state changed from %d to %d for display %d-%d",
Ramkumar Radhakrishnana38b7602018-03-15 14:49:52 -0700620 active_secure_sessions_.test(kSecureDisplay), secure_sessions.test(kSecureDisplay),
Mathew Joseph Karimpanalb1c15862019-07-04 11:14:24 +0530621 id_, type_);
Ramkumar Radhakrishnana38b7602018-03-15 14:49:52 -0700622 }
623 active_secure_sessions_ = secure_sessions;
624 *power_on_pending = false;
625 return 0;
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500626}
627
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +0530628void HWCDisplayBuiltIn::ForceRefreshRate(uint32_t refresh_rate) {
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500629 if ((refresh_rate && (refresh_rate < min_refresh_rate_ || refresh_rate > max_refresh_rate_)) ||
630 force_refresh_rate_ == refresh_rate) {
631 // Cannot honor force refresh rate, as its beyond the range or new request is same
632 return;
633 }
634
635 force_refresh_rate_ = refresh_rate;
636
Ramkumar Radhakrishnan44c64362018-12-12 13:03:59 -0800637 callbacks_->Refresh(id_);
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500638
639 return;
640}
641
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +0530642uint32_t HWCDisplayBuiltIn::GetOptimalRefreshRate(bool one_updating_layer) {
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500643 if (force_refresh_rate_) {
644 return force_refresh_rate_;
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500645 } else if (use_metadata_refresh_rate_ && one_updating_layer && metadata_refresh_rate_) {
646 return metadata_refresh_rate_;
647 }
648
649 return max_refresh_rate_;
650}
651
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +0530652void HWCDisplayBuiltIn::SetIdleTimeoutMs(uint32_t timeout_ms) {
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500653 display_intf_->SetIdleTimeoutMs(timeout_ms);
Saurabh Shaha307e8c2017-09-28 18:05:40 -0700654 validated_ = false;
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500655}
656
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +0530657void HWCDisplayBuiltIn::HandleFrameOutput() {
Sushil Chauhan06521582018-03-19 14:00:23 -0700658 if (readback_buffer_queued_) {
659 validated_ = false;
660 }
661
Sushil Chauhan1d3b90c2018-12-11 16:52:35 -0800662 if (frame_capture_buffer_queued_) {
663 HandleFrameCapture();
664 } else if (dump_output_to_file_) {
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500665 HandleFrameDump();
666 }
667}
668
Sushil Chauhan1d3b90c2018-12-11 16:52:35 -0800669void HWCDisplayBuiltIn::HandleFrameCapture() {
670 if (readback_configured_ && (output_buffer_.release_fence_fd >= 0)) {
671 frame_capture_status_ = sync_wait(output_buffer_.release_fence_fd, 1000);
672 ::close(output_buffer_.release_fence_fd);
673 output_buffer_.release_fence_fd = -1;
674 }
675
676 frame_capture_buffer_queued_ = false;
677 readback_buffer_queued_ = false;
678 post_processed_output_ = false;
679 readback_configured_ = false;
680 output_buffer_ = {};
Dileep Marchyacb2a3a92019-06-21 17:30:50 +0530681 cwb_client_ = kCWBClientNone;
Sushil Chauhan1d3b90c2018-12-11 16:52:35 -0800682}
683
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +0530684void HWCDisplayBuiltIn::HandleFrameDump() {
Ramkumar Radhakrishnan68331fc2019-06-19 11:24:12 -0700685 if (dump_frame_count_) {
686 int ret = 0;
687 if (output_buffer_.release_fence_fd >= 0) {
688 ret = sync_wait(output_buffer_.release_fence_fd, 1000);
689 if (ret < 0) {
690 DLOGE("sync_wait error errno = %d, desc = %s", errno, strerror(errno));
691 }
692 ::close(output_buffer_.release_fence_fd);
693 output_buffer_.release_fence_fd = -1;
694 }
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500695
Ramkumar Radhakrishnan68331fc2019-06-19 11:24:12 -0700696 if (!ret) {
697 DumpOutputBuffer(output_buffer_info_, output_buffer_base_, layer_stack_.retire_fence_fd);
698 validated_ = false;
699 }
700
701 if (0 == (dump_frame_count_ - 1)) {
702 dump_output_to_file_ = false;
703 // Unmap and Free buffer
704 if (munmap(output_buffer_base_, output_buffer_info_.alloc_buffer_info.size) != 0) {
705 DLOGE("unmap failed with err %d", errno);
706 }
707 if (buffer_allocator_->FreeBuffer(&output_buffer_info_) != 0) {
708 DLOGE("FreeBuffer failed");
709 }
710
Sushil Chauhan06521582018-03-19 14:00:23 -0700711 readback_buffer_queued_ = false;
Ramkumar Radhakrishnan68331fc2019-06-19 11:24:12 -0700712 post_processed_output_ = false;
713 readback_configured_ = false;
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500714
Ramkumar Radhakrishnan68331fc2019-06-19 11:24:12 -0700715 output_buffer_ = {};
716 output_buffer_info_ = {};
717 output_buffer_base_ = nullptr;
Dileep Marchyacb2a3a92019-06-21 17:30:50 +0530718 cwb_client_ = kCWBClientNone;
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500719 }
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500720 }
721}
722
Sushil Chauhan267a6192018-06-06 18:41:47 -0700723HWC2::Error HWCDisplayBuiltIn::SetFrameDumpConfig(uint32_t count, uint32_t bit_mask_layer_type,
724 int32_t format, bool post_processed) {
725 HWCDisplay::SetFrameDumpConfig(count, bit_mask_layer_type, format, post_processed);
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500726 dump_output_to_file_ = bit_mask_layer_type & (1 << OUTPUT_LAYER_DUMP);
727 DLOGI("output_layer_dump_enable %d", dump_output_to_file_);
728
Dileep Marchyacb2a3a92019-06-21 17:30:50 +0530729 if (dump_output_to_file_) {
730 if (cwb_client_ != kCWBClientNone) {
731 DLOGE("CWB is in use with client = %d", cwb_client_);
732 dump_output_to_file_ = false;
733 return HWC2::Error::NoResources;
734 }
735 }
736
Sushil Chauhand0dc03d2018-09-19 07:08:40 -0700737 if (!count || !dump_output_to_file_ || (output_buffer_info_.alloc_buffer_info.fd >= 0)) {
Mathew Joseph Karimpanaldbd64f82017-10-06 10:13:38 +0530738 return HWC2::Error::None;
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500739 }
740
741 // Allocate and map output buffer
Sushil Chauhan267a6192018-06-06 18:41:47 -0700742 if (post_processed) {
743 // To dump post-processed (DSPP) output, use Panel resolution.
744 GetPanelResolution(&output_buffer_info_.buffer_config.width,
745 &output_buffer_info_.buffer_config.height);
746 } else {
747 // To dump Layer Mixer output, use FrameBuffer resolution.
748 GetFrameBufferResolution(&output_buffer_info_.buffer_config.width,
749 &output_buffer_info_.buffer_config.height);
750 }
751
752 output_buffer_info_.buffer_config.format = HWCLayer::GetSDMFormat(format, 0);
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500753 output_buffer_info_.buffer_config.buffer_count = 1;
754 if (buffer_allocator_->AllocateBuffer(&output_buffer_info_) != 0) {
755 DLOGE("Buffer allocation failed");
756 output_buffer_info_ = {};
Mathew Joseph Karimpanaldbd64f82017-10-06 10:13:38 +0530757 return HWC2::Error::NoResources;
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500758 }
759
760 void *buffer = mmap(NULL, output_buffer_info_.alloc_buffer_info.size, PROT_READ | PROT_WRITE,
761 MAP_SHARED, output_buffer_info_.alloc_buffer_info.fd, 0);
762
763 if (buffer == MAP_FAILED) {
764 DLOGE("mmap failed with err %d", errno);
765 buffer_allocator_->FreeBuffer(&output_buffer_info_);
766 output_buffer_info_ = {};
Mathew Joseph Karimpanaldbd64f82017-10-06 10:13:38 +0530767 return HWC2::Error::NoResources;
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500768 }
769
770 output_buffer_base_ = buffer;
Sushil Chauhan06521582018-03-19 14:00:23 -0700771 const native_handle_t *handle = static_cast<native_handle_t *>(output_buffer_info_.private_data);
Dileep Marchyacb2a3a92019-06-21 17:30:50 +0530772 SetReadbackBuffer(handle, -1, post_processed, kCWBClientFrameDump);
Sushil Chauhan06521582018-03-19 14:00:23 -0700773
Mathew Joseph Karimpanaldbd64f82017-10-06 10:13:38 +0530774 return HWC2::Error::None;
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500775}
776
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +0530777int HWCDisplayBuiltIn::FrameCaptureAsync(const BufferInfo &output_buffer_info,
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500778 bool post_processed_output) {
Dileep Marchyacb2a3a92019-06-21 17:30:50 +0530779 if (cwb_client_ != kCWBClientNone) {
780 DLOGE("CWB is in use with client = %d", cwb_client_);
781 return -1;
782 }
783
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500784 // Note: This function is called in context of a binder thread and a lock is already held
785 if (output_buffer_info.alloc_buffer_info.fd < 0) {
786 DLOGE("Invalid fd %d", output_buffer_info.alloc_buffer_info.fd);
787 return -1;
788 }
789
790 auto panel_width = 0u;
791 auto panel_height = 0u;
792 auto fb_width = 0u;
793 auto fb_height = 0u;
794
795 GetPanelResolution(&panel_width, &panel_height);
796 GetFrameBufferResolution(&fb_width, &fb_height);
797
Ch Ganesh Kumar5c4988b2017-06-07 15:21:02 +0530798 if (post_processed_output && (output_buffer_info.buffer_config.width < panel_width ||
799 output_buffer_info.buffer_config.height < panel_height)) {
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500800 DLOGE("Buffer dimensions should not be less than panel resolution");
801 return -1;
Ch Ganesh Kumar5c4988b2017-06-07 15:21:02 +0530802 } else if (!post_processed_output && (output_buffer_info.buffer_config.width < fb_width ||
803 output_buffer_info.buffer_config.height < fb_height)) {
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500804 DLOGE("Buffer dimensions should not be less than FB resolution");
805 return -1;
806 }
807
Sushil Chauhan06521582018-03-19 14:00:23 -0700808 const native_handle_t *buffer = static_cast<native_handle_t *>(output_buffer_info.private_data);
Dileep Marchyacb2a3a92019-06-21 17:30:50 +0530809 SetReadbackBuffer(buffer, -1, post_processed_output, kCWBClientColor);
Sushil Chauhan1d3b90c2018-12-11 16:52:35 -0800810 frame_capture_buffer_queued_ = true;
811 frame_capture_status_ = -EAGAIN;
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500812
813 return 0;
814}
815
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +0530816DisplayError HWCDisplayBuiltIn::SetDetailEnhancerConfig
Alan Kwong2e136332016-08-16 07:50:16 -0400817 (const DisplayDetailEnhancerData &de_data) {
818 DisplayError error = kErrorNotSupported;
819
820 if (display_intf_) {
821 error = display_intf_->SetDetailEnhancerData(de_data);
Saurabh Shaha307e8c2017-09-28 18:05:40 -0700822 validated_ = false;
Alan Kwong2e136332016-08-16 07:50:16 -0400823 }
824 return error;
825}
826
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +0530827DisplayError HWCDisplayBuiltIn::ControlPartialUpdate(bool enable, uint32_t *pending) {
Arun Kumar K.R17bbd042016-06-07 17:38:02 -0700828 DisplayError error = kErrorNone;
829
830 if (display_intf_) {
831 error = display_intf_->ControlPartialUpdate(enable, pending);
Saurabh Shaha307e8c2017-09-28 18:05:40 -0700832 validated_ = false;
Arun Kumar K.R17bbd042016-06-07 17:38:02 -0700833 }
834
835 return error;
836}
837
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +0530838DisplayError HWCDisplayBuiltIn::DisablePartialUpdateOneFrame() {
Arun Kumar K.R17bbd042016-06-07 17:38:02 -0700839 DisplayError error = kErrorNone;
840
841 if (display_intf_) {
842 error = display_intf_->DisablePartialUpdateOneFrame();
Saurabh Shaha307e8c2017-09-28 18:05:40 -0700843 validated_ = false;
Arun Kumar K.R17bbd042016-06-07 17:38:02 -0700844 }
845
846 return error;
847}
848
849
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +0530850DisplayError HWCDisplayBuiltIn::SetMixerResolution(uint32_t width, uint32_t height) {
Sushil Chauhan409e8442017-06-12 17:43:25 -0700851 DisplayError error = display_intf_->SetMixerResolution(width, height);
Ramkumar Radhakrishnanf7f52162019-06-06 19:40:04 -0700852 callbacks_->Refresh(id_);
Saurabh Shaha307e8c2017-09-28 18:05:40 -0700853 validated_ = false;
Sushil Chauhan409e8442017-06-12 17:43:25 -0700854 return error;
Arun Kumar K.R8da7f502016-06-07 17:45:50 -0700855}
856
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +0530857DisplayError HWCDisplayBuiltIn::GetMixerResolution(uint32_t *width, uint32_t *height) {
Arun Kumar K.R8da7f502016-06-07 17:45:50 -0700858 return display_intf_->GetMixerResolution(width, height);
859}
860
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +0530861HWC2::Error HWCDisplayBuiltIn::SetQSyncMode(QSyncMode qsync_mode) {
Pullakavi Srinivas24574142019-08-14 12:18:12 +0530862 // Client needs to ensure that config change and qsync mode change
863 // are not triggered in the same drawcycle.
864 if (pending_config_) {
865 DLOGE("Failed to set qsync mode. Pending active config transition");
866 return HWC2::Error::Unsupported;
867 }
868
Sushil Chauhan380a59d2018-03-19 15:47:50 -0700869 auto err = display_intf_->SetQSyncMode(qsync_mode);
870 if (err != kErrorNone) {
871 return HWC2::Error::Unsupported;
872 }
873
Sushil Chauhanec4eb572019-02-07 13:29:42 -0800874 validated_ = false;
Sushil Chauhan380a59d2018-03-19 15:47:50 -0700875 return HWC2::Error::None;
876}
877
Ramkumar Radhakrishnan4faf8a62018-11-15 17:15:37 -0800878DisplayError HWCDisplayBuiltIn::ControlIdlePowerCollapse(bool enable, bool synchronous) {
Ramkumar Radhakrishnanf985d482018-07-23 18:10:41 -0700879 DisplayError error = kErrorNone;
880
881 if (display_intf_) {
882 error = display_intf_->ControlIdlePowerCollapse(enable, synchronous);
883 validated_ = false;
884 }
Ramkumar Radhakrishnan4faf8a62018-11-15 17:15:37 -0800885 return error;
Ramkumar Radhakrishnanf985d482018-07-23 18:10:41 -0700886}
887
Pullakavi Srinivas9189e602018-12-19 16:58:07 +0530888DisplayError HWCDisplayBuiltIn::SetDynamicDSIClock(uint64_t bitclk) {
Dileep Marchyaafa45bc2019-06-21 17:05:31 +0530889 DisablePartialUpdateOneFrame();
890 DisplayError error = display_intf_->SetDynamicDSIClock(bitclk);
891 if (error != kErrorNone) {
892 DLOGE(" failed: Clk: %llu Error: %d", bitclk, error);
893 return error;
Pullakavi Srinivas9189e602018-12-19 16:58:07 +0530894 }
895
896 callbacks_->Refresh(id_);
897 validated_ = false;
898
899 return kErrorNone;
900}
901
902DisplayError HWCDisplayBuiltIn::GetDynamicDSIClock(uint64_t *bitclk) {
Pullakavi Srinivas9189e602018-12-19 16:58:07 +0530903 if (display_intf_) {
904 return display_intf_->GetDynamicDSIClock(bitclk);
905 }
906
907 return kErrorNotSupported;
908}
909
910DisplayError HWCDisplayBuiltIn::GetSupportedDSIClock(std::vector<uint64_t> *bitclk_rates) {
911 if (display_intf_) {
912 return display_intf_->GetSupportedDSIClock(bitclk_rates);
913 }
914
915 return kErrorNotSupported;
916}
917
Padmanabhan Komandurue74cf4f2019-04-25 17:38:43 -0700918HWC2::Error HWCDisplayBuiltIn::UpdateDisplayId(hwc2_display_t id) {
919 id_ = id;
920 return HWC2::Error::None;
921}
922
923HWC2::Error HWCDisplayBuiltIn::SetPendingRefresh() {
924 pending_refresh_ = true;
925 return HWC2::Error::None;
926}
927
Varun Arora75c05f02019-05-14 14:53:37 -0700928HWC2::Error HWCDisplayBuiltIn::SetPanelBrightness(float brightness) {
929 DisplayError ret = display_intf_->SetPanelBrightness(brightness);
930 if (ret != kErrorNone) {
931 return HWC2::Error::NoResources;
932 }
933
934 return HWC2::Error::None;
935}
936
937HWC2::Error HWCDisplayBuiltIn::GetPanelBrightness(float *brightness) {
938 DisplayError ret = display_intf_->GetPanelBrightness(brightness);
939 if (ret != kErrorNone) {
940 return HWC2::Error::NoResources;
941 }
942
943 return HWC2::Error::None;
944}
Xu Yang45d0abf2019-07-05 11:34:06 +0800945
946HWC2::Error HWCDisplayBuiltIn::SetBLScale(uint32_t level) {
947 DisplayError ret = display_intf_->SetBLScale(level);
948 if (ret != kErrorNone) {
949 return HWC2::Error::NoResources;
950 }
Srinivas Pullakavi3c4337f2019-07-03 11:24:31 +0530951 return HWC2::Error::None;
952}
Xu Yang45d0abf2019-07-05 11:34:06 +0800953
Srinivas Pullakavi3c4337f2019-07-03 11:24:31 +0530954HWC2::Error HWCDisplayBuiltIn::UpdatePowerMode(HWC2::PowerMode mode) {
955 current_power_mode_ = mode;
956 validated_ = false;
Xu Yang45d0abf2019-07-05 11:34:06 +0800957 return HWC2::Error::None;
958}
959
Padmanabhan Komanduru9a91e9f2019-09-12 12:33:19 +0530960HWC2::Error HWCDisplayBuiltIn::SetClientTarget(buffer_handle_t target, int32_t acquire_fence,
961 int32_t dataspace, hwc_region_t damage) {
962 HWC2::Error error = HWCDisplay::SetClientTarget(target, acquire_fence, dataspace, damage);
963 if (error != HWC2::Error::None) {
964 return error;
965 }
966
967 Layer *sdm_layer = client_target_->GetSDMLayer();
968 SetFrameBufferResolution(sdm_layer->input_buffer.unaligned_width,
969 sdm_layer->input_buffer.unaligned_height);
970
971 return HWC2::Error::None;
972}
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500973} // namespace sdm