blob: 40a3ac3551a7e8ed0b8aec8fa02fb50a69d50a75 [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
Naseer Ahmed61f60952017-05-24 16:48:35 -0400130 return status;
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500131}
132
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +0530133HWC2::Error HWCDisplayBuiltIn::Validate(uint32_t *out_num_types, uint32_t *out_num_requests) {
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500134 auto status = HWC2::Error::None;
135 DisplayError error = kErrorNone;
136
Gurpreet Singh Dhamia4276882019-04-12 10:30:58 -0700137 DTRACE_SCOPED();
138
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500139 if (display_paused_) {
140 MarkLayersForGPUBypass();
141 return status;
142 }
143
Arun Kumar K.R29cd6582016-05-10 19:12:45 -0700144 if (color_tranform_failed_) {
145 // Must fall back to client composition
146 MarkLayersForClientComposition();
147 }
148
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500149 // Fill in the remaining blanks in the layers and add them to the SDM layerstack
150 BuildLayerStack();
Arun Kumar K.R536c7d62016-06-14 18:47:39 -0700151 // Checks and replaces layer stack for solid fill
152 SolidFillPrepare();
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500153
Sushil Chauhan8008d602018-09-04 14:43:27 -0700154 // Apply current Color Mode and Render Intent.
Xu Yang84e61412018-12-06 14:52:16 +0800155 if (color_mode_->ApplyCurrentColorModeWithRenderIntent(
156 static_cast<bool>(layer_stack_.flags.hdr_present)) != HWC2::Error::None) {
Sushil Chauhan8008d602018-09-04 14:43:27 -0700157 // Fallback to GPU Composition, if Color Mode can't be applied.
158 MarkLayersForClientComposition();
159 }
160
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500161 bool pending_output_dump = dump_frame_count_ && dump_output_to_file_;
162
Sushil Chauhan06521582018-03-19 14:00:23 -0700163 if (readback_buffer_queued_ || pending_output_dump) {
164 CloseFd(&output_buffer_.release_fence_fd);
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500165 // RHS values were set in FrameCaptureAsync() called from a binder thread. They are picked up
Sushil Chauhan06521582018-03-19 14:00:23 -0700166 // here in a subsequent draw round. Readback is not allowed for any secure use case.
167 readback_configured_ = !layer_stack_.flags.secure_present;
168 if (readback_configured_) {
Sushil Chauhanf42d8622018-09-30 23:20:37 -0700169 DisablePartialUpdateOneFrame();
Sushil Chauhan06521582018-03-19 14:00:23 -0700170 layer_stack_.output_buffer = &output_buffer_;
171 layer_stack_.flags.post_processed_output = post_processed_output_;
172 }
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500173 }
174
Ramakant Singh5db0dfb2017-08-23 12:34:57 +0530175 uint32_t num_updating_layers = GetUpdatingLayersCount();
176 bool one_updating_layer = (num_updating_layers == 1);
177 if (num_updating_layers != 0) {
178 ToggleCPUHint(one_updating_layer);
179 }
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500180
181 uint32_t refresh_rate = GetOptimalRefreshRate(one_updating_layer);
Pullakavi Srinivas4619db92019-04-20 15:07:59 +0530182 error = display_intf_->SetRefreshRate(refresh_rate, force_refresh_rate_);
183
184 // Get the refresh rate set.
185 display_intf_->GetRefreshRate(&refresh_rate);
186 bool vsync_source = (callbacks_->GetVsyncSource() == id_);
187
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500188 if (error == kErrorNone) {
Pullakavi Srinivas4619db92019-04-20 15:07:59 +0530189 if (vsync_source && (current_refresh_rate_ < refresh_rate)) {
190 DTRACE_BEGIN("HWC2::Vsync::Enable");
191 // Display is ramping up from idle.
192 // Client realizes need for resync upon change in config.
193 // Since we know config has changed, triggering vsync proactively
194 // can help in reducing pipeline delays to enable events.
195 SetVsyncEnabled(HWC2::Vsync::Enable);
196 DTRACE_END();
197 }
198 // On success, set current refresh rate to new refresh rate.
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500199 current_refresh_rate_ = refresh_rate;
200 }
201
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500202 if (layer_set_.empty()) {
Uday Kiran Pichika8d827732018-01-09 18:08:38 +0530203 // Avoid flush for Command mode panel.
Ramkumar Radhakrishnana38b7602018-03-15 14:49:52 -0700204 flush_ = !IsDisplayCommandMode();
205 validated_ = true;
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500206 return status;
207 }
208
209 status = PrepareLayerStack(out_num_types, out_num_requests);
Namit Solanki5b428dc2018-02-27 11:39:05 +0530210 pending_commit_ = true;
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500211 return status;
212}
213
Padmanabhan Komandurue74cf4f2019-04-25 17:38:43 -0700214HWC2::Error HWCDisplayBuiltIn::CommitLayerStack() {
215 skip_commit_ = CanSkipCommit();
216 return HWCDisplay::CommitLayerStack();
217}
218
219bool HWCDisplayBuiltIn::CanSkipCommit() {
220 if (layer_stack_invalid_) {
221 return false;
222 }
223
224 // Reject repeated drawcycle requests if it satisfies all conditions.
225 // 1. None of the layerstack attributes changed.
226 // 2. No new buffer latched.
227 // 3. No refresh request triggered by HWC.
228 // 4. This display is not source of vsync.
229 bool buffers_latched = false;
230 for (auto &hwc_layer : layer_set_) {
231 buffers_latched |= hwc_layer->BufferLatched();
232 hwc_layer->ResetBufferFlip();
233 }
234
Padmanabhan Komanduruf5e6c5d2019-04-04 13:56:31 +0530235 bool vsync_source = (callbacks_->GetVsyncSource() == id_);
Padmanabhan Komanduru866bf6a2019-03-19 14:30:48 +0530236 bool skip_commit = enable_optimize_refresh_ && !pending_commit_ && !buffers_latched &&
Padmanabhan Komanduruf5e6c5d2019-04-04 13:56:31 +0530237 !pending_refresh_ && !vsync_source;
Padmanabhan Komandurue74cf4f2019-04-25 17:38:43 -0700238 pending_refresh_ = false;
239
240 return skip_commit;
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;
Gurpreet Singh Dhamia4276882019-04-12 10:30:58 -0700245
246 DTRACE_SCOPED();
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500247 if (display_paused_) {
Pullakavi Srinivas0a1dba62018-07-02 15:49:11 +0530248 DisplayError error = display_intf_->Flush(&layer_stack_);
Saurabh Shaha307e8c2017-09-28 18:05:40 -0700249 validated_ = false;
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500250 if (error != kErrorNone) {
251 DLOGE("Flush failed. Error = %d", error);
252 }
253 } else {
Padmanabhan Komandurue74cf4f2019-04-25 17:38:43 -0700254 status = CommitLayerStack();
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500255 if (status == HWC2::Error::None) {
256 HandleFrameOutput();
Arun Kumar K.R536c7d62016-06-14 18:47:39 -0700257 SolidFillCommit();
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500258 status = HWCDisplay::PostCommitLayerStack(out_retire_fence);
259 }
260 }
Arun Kumar K.R536c7d62016-06-14 18:47:39 -0700261
Sushil Chauhan06521582018-03-19 14:00:23 -0700262 CloseFd(&output_buffer_.acquire_fence_fd);
Namit Solanki5b428dc2018-02-27 11:39:05 +0530263 pending_commit_ = false;
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500264 return status;
265}
266
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +0530267HWC2::Error HWCDisplayBuiltIn::GetColorModes(uint32_t *out_num_modes, ColorMode *out_modes) {
Arun Kumar K.R29cd6582016-05-10 19:12:45 -0700268 if (out_modes == nullptr) {
269 *out_num_modes = color_mode_->GetColorModeCount();
270 } else {
271 color_mode_->GetColorModes(out_num_modes, out_modes);
272 }
273
274 return HWC2::Error::None;
275}
276
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +0530277HWC2::Error HWCDisplayBuiltIn::GetRenderIntents(ColorMode mode, uint32_t *out_num_intents,
Naseer Ahmede7a77982018-06-04 10:56:04 -0400278 RenderIntent *out_intents) {
279 if (out_intents == nullptr) {
280 *out_num_intents = color_mode_->GetRenderIntentCount(mode);
281 } else {
282 color_mode_->GetRenderIntents(mode, out_num_intents, out_intents);
283 }
284 return HWC2::Error::None;
285}
286
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +0530287HWC2::Error HWCDisplayBuiltIn::SetColorMode(ColorMode mode) {
Naseer Ahmede7a77982018-06-04 10:56:04 -0400288 return SetColorModeWithRenderIntent(mode, RenderIntent::COLORIMETRIC);
289}
290
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +0530291HWC2::Error HWCDisplayBuiltIn::SetColorModeWithRenderIntent(ColorMode mode, RenderIntent intent) {
Sushil Chauhan8008d602018-09-04 14:43:27 -0700292 auto status = color_mode_->CacheColorModeWithRenderIntent(mode, intent);
Arun Kumar K.R29cd6582016-05-10 19:12:45 -0700293 if (status != HWC2::Error::None) {
Naseer Ahmede7a77982018-06-04 10:56:04 -0400294 DLOGE("failed for mode = %d intent = %d", mode, intent);
Arun Kumar K.R29cd6582016-05-10 19:12:45 -0700295 return status;
296 }
Ramkumar Radhakrishnan44c64362018-12-12 13:03:59 -0800297 callbacks_->Refresh(id_);
Saurabh Shaha307e8c2017-09-28 18:05:40 -0700298 validated_ = false;
Arun Kumar K.R29cd6582016-05-10 19:12:45 -0700299 return status;
300}
301
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +0530302HWC2::Error HWCDisplayBuiltIn::SetColorModeById(int32_t color_mode_id) {
Naseer Ahmed6776dae2017-05-09 11:49:41 -0400303 auto status = color_mode_->SetColorModeById(color_mode_id);
304 if (status != HWC2::Error::None) {
305 DLOGE("failed for mode = %d", color_mode_id);
306 return status;
307 }
308
Ramkumar Radhakrishnan44c64362018-12-12 13:03:59 -0800309 callbacks_->Refresh(id_);
Saurabh Shaha307e8c2017-09-28 18:05:40 -0700310 validated_ = false;
Naseer Ahmed6776dae2017-05-09 11:49:41 -0400311
312 return status;
313}
314
Xu Yang84e61412018-12-06 14:52:16 +0800315HWC2::Error HWCDisplayBuiltIn::SetColorModeFromClientApi(int32_t color_mode_id) {
316 DisplayError error = kErrorNone;
317 std::string mode_string;
318
319 error = display_intf_->GetColorModeName(color_mode_id, &mode_string);
320 if (error) {
321 DLOGE("Failed to get mode name for mode %d", color_mode_id);
322 return HWC2::Error::BadParameter;
323 }
324
325 auto status = color_mode_->SetColorModeFromClientApi(mode_string);
326 if (status != HWC2::Error::None) {
327 DLOGE("Failed to set mode = %d", color_mode_id);
328 return status;
329 }
330
331 return status;
332}
333
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +0530334HWC2::Error HWCDisplayBuiltIn::RestoreColorTransform() {
Ch Ganesh Kumar5d43ff62017-10-13 19:01:47 +0530335 auto status = color_mode_->RestoreColorTransform();
336 if (status != HWC2::Error::None) {
337 DLOGE("failed to RestoreColorTransform");
338 return status;
339 }
340
Ramkumar Radhakrishnan44c64362018-12-12 13:03:59 -0800341 callbacks_->Refresh(id_);
Ch Ganesh Kumar5d43ff62017-10-13 19:01:47 +0530342
343 return status;
344}
345
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +0530346HWC2::Error HWCDisplayBuiltIn::SetColorTransform(const float *matrix,
Arun Kumar K.R29cd6582016-05-10 19:12:45 -0700347 android_color_transform_t hint) {
348 if (!matrix) {
349 return HWC2::Error::BadParameter;
350 }
351
352 auto status = color_mode_->SetColorTransform(matrix, hint);
353 if (status != HWC2::Error::None) {
354 DLOGE("failed for hint = %d", hint);
355 color_tranform_failed_ = true;
356 return status;
357 }
358
Ramkumar Radhakrishnan44c64362018-12-12 13:03:59 -0800359 callbacks_->Refresh(id_);
Arun Kumar K.R29cd6582016-05-10 19:12:45 -0700360 color_tranform_failed_ = false;
Saurabh Shaha307e8c2017-09-28 18:05:40 -0700361 validated_ = false;
Arun Kumar K.R29cd6582016-05-10 19:12:45 -0700362
363 return status;
364}
365
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +0530366HWC2::Error HWCDisplayBuiltIn::SetReadbackBuffer(const native_handle_t *buffer,
Dileep Marchyacb2a3a92019-06-21 17:30:50 +0530367 int32_t acquire_fence, bool post_processed_output,
368 CWBClient client) {
369 if (cwb_client_ != client && cwb_client_ != kCWBClientNone) {
370 DLOGE("CWB is in use with client = %d", cwb_client_);
371 return HWC2::Error::NoResources;
372 }
373
Sushil Chauhan06521582018-03-19 14:00:23 -0700374 const private_handle_t *handle = reinterpret_cast<const private_handle_t *>(buffer);
375 if (!handle || (handle->fd < 0)) {
376 return HWC2::Error::BadParameter;
377 }
378
379 // Configure the output buffer as Readback buffer
380 output_buffer_.width = UINT32(handle->width);
381 output_buffer_.height = UINT32(handle->height);
382 output_buffer_.unaligned_width = UINT32(handle->unaligned_width);
383 output_buffer_.unaligned_height = UINT32(handle->unaligned_height);
384 output_buffer_.format = HWCLayer::GetSDMFormat(handle->format, handle->flags);
385 output_buffer_.planes[0].fd = handle->fd;
386 output_buffer_.planes[0].stride = UINT32(handle->width);
387 output_buffer_.acquire_fence_fd = dup(acquire_fence);
388 output_buffer_.release_fence_fd = -1;
Sushil Chauhand0dc03d2018-09-19 07:08:40 -0700389 output_buffer_.handle_id = handle->id;
Sushil Chauhan06521582018-03-19 14:00:23 -0700390
391 post_processed_output_ = post_processed_output;
392 readback_buffer_queued_ = true;
393 readback_configured_ = false;
394 validated_ = false;
Dileep Marchyacb2a3a92019-06-21 17:30:50 +0530395 cwb_client_ = client;
Sushil Chauhan06521582018-03-19 14:00:23 -0700396
Sushil Chauhan06521582018-03-19 14:00:23 -0700397 return HWC2::Error::None;
398}
399
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +0530400HWC2::Error HWCDisplayBuiltIn::GetReadbackBufferFence(int32_t *release_fence) {
Sushil Chauhan06521582018-03-19 14:00:23 -0700401 auto status = HWC2::Error::None;
402
403 if (readback_configured_ && (output_buffer_.release_fence_fd >= 0)) {
404 *release_fence = output_buffer_.release_fence_fd;
405 } else {
406 status = HWC2::Error::Unsupported;
407 *release_fence = -1;
408 }
409
410 post_processed_output_ = false;
411 readback_buffer_queued_ = false;
412 readback_configured_ = false;
413 output_buffer_ = {};
Dileep Marchyacb2a3a92019-06-21 17:30:50 +0530414 cwb_client_ = kCWBClientNone;
Sushil Chauhan06521582018-03-19 14:00:23 -0700415
416 return status;
417}
418
Gurpreet Singh Dhami1207e462018-12-27 20:02:02 -0500419DisplayError HWCDisplayBuiltIn::TeardownConcurrentWriteback(void) {
420 DisplayError error = kErrorNotSupported;
421
422 if (output_buffer_.release_fence_fd >= 0) {
423 int32_t release_fence_fd = dup(output_buffer_.release_fence_fd);
424 int ret = sync_wait(output_buffer_.release_fence_fd, 1000);
425 if (ret < 0) {
426 DLOGE("sync_wait error errno = %d, desc = %s", errno, strerror(errno));
427 }
428
429 ::close(release_fence_fd);
430 if (ret)
431 return kErrorResources;
432 }
433
434 if (display_intf_) {
435 error = display_intf_->TeardownConcurrentWriteback();
436 }
437
438 return error;
439}
440
Yuchao Ma577f0f72018-07-09 11:20:00 +0800441HWC2::Error HWCDisplayBuiltIn::SetDisplayDppsAdROI(uint32_t h_start, uint32_t h_end,
442 uint32_t v_start, uint32_t v_end,
443 uint32_t factor_in, uint32_t factor_out) {
444 DisplayError error = kErrorNone;
445 DisplayDppsAd4RoiCfg dpps_ad4_roi_cfg = {};
446 uint32_t panel_width = 0, panel_height = 0;
447 constexpr uint16_t kMaxFactorVal = 0xffff;
448
449 if (h_start >= h_end || v_start >= v_end || factor_in > kMaxFactorVal ||
450 factor_out > kMaxFactorVal) {
451 DLOGE("Invalid roi region = [%u, %u, %u, %u, %u, %u]",
452 h_start, h_end, v_start, v_end, factor_in, factor_out);
453 return HWC2::Error::BadParameter;
454 }
455
456 GetPanelResolution(&panel_width, &panel_height);
457
458 if (h_start >= panel_width || h_end > panel_width ||
459 v_start >= panel_height || v_end > panel_height) {
460 DLOGE("Invalid roi region = [%u, %u, %u, %u], panel resolution = [%u, %u]",
461 h_start, h_end, v_start, v_end, panel_width, panel_height);
462 return HWC2::Error::BadParameter;
463 }
464
465 dpps_ad4_roi_cfg.h_start = h_start;
466 dpps_ad4_roi_cfg.h_end = h_end;
467 dpps_ad4_roi_cfg.v_start = v_start;
468 dpps_ad4_roi_cfg.v_end = v_end;
469 dpps_ad4_roi_cfg.factor_in = factor_in;
470 dpps_ad4_roi_cfg.factor_out = factor_out;
471
472 error = display_intf_->SetDisplayDppsAdROI(&dpps_ad4_roi_cfg);
473 if (error)
474 return HWC2::Error::BadConfig;
475
Ramkumar Radhakrishnan44c64362018-12-12 13:03:59 -0800476 callbacks_->Refresh(id_);
Yuchao Ma577f0f72018-07-09 11:20:00 +0800477
478 return HWC2::Error::None;
479}
480
Xu Yang9dacc872018-12-25 11:04:28 +0800481HWC2::Error HWCDisplayBuiltIn::SetFrameTriggerMode(uint32_t mode) {
482 DisplayError error = kErrorNone;
483 FrameTriggerMode trigger_mode = kFrameTriggerDefault;
484
485 if (mode >= kFrameTriggerMax) {
486 DLOGE("Invalid input mode %d", mode);
487 return HWC2::Error::BadParameter;
488 }
489
490 trigger_mode = static_cast<FrameTriggerMode>(mode);
491 error = display_intf_->SetFrameTriggerMode(trigger_mode);
492 if (error)
493 return HWC2::Error::BadConfig;
494
495 callbacks_->Refresh(HWC_DISPLAY_PRIMARY);
496 validated_ = false;
497
498 return HWC2::Error::None;
499}
500
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +0530501int HWCDisplayBuiltIn::Perform(uint32_t operation, ...) {
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500502 va_list args;
503 va_start(args, operation);
Arun Kumar K.R536c7d62016-06-14 18:47:39 -0700504 int val = 0;
Gopikrishnaiah Anandancc123062017-07-31 17:21:03 -0700505 LayerSolidFill *solid_fill_color;
Arun Kumar K.R536c7d62016-06-14 18:47:39 -0700506 LayerRect *rect = NULL;
507
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500508 switch (operation) {
509 case SET_METADATA_DYN_REFRESH_RATE:
Arun Kumar K.R536c7d62016-06-14 18:47:39 -0700510 val = va_arg(args, int32_t);
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500511 SetMetaDataRefreshRateFlag(val);
512 break;
513 case SET_BINDER_DYN_REFRESH_RATE:
Arun Kumar K.R536c7d62016-06-14 18:47:39 -0700514 val = va_arg(args, int32_t);
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500515 ForceRefreshRate(UINT32(val));
516 break;
517 case SET_DISPLAY_MODE:
Arun Kumar K.R536c7d62016-06-14 18:47:39 -0700518 val = va_arg(args, int32_t);
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500519 SetDisplayMode(UINT32(val));
520 break;
521 case SET_QDCM_SOLID_FILL_INFO:
Gopikrishnaiah Anandancc123062017-07-31 17:21:03 -0700522 solid_fill_color = va_arg(args, LayerSolidFill*);
523 SetQDCMSolidFillInfo(true, *solid_fill_color);
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500524 break;
525 case UNSET_QDCM_SOLID_FILL_INFO:
Gopikrishnaiah Anandancc123062017-07-31 17:21:03 -0700526 solid_fill_color = va_arg(args, LayerSolidFill*);
527 SetQDCMSolidFillInfo(false, *solid_fill_color);
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500528 break;
Arun Kumar K.R536c7d62016-06-14 18:47:39 -0700529 case SET_QDCM_SOLID_FILL_RECT:
530 rect = va_arg(args, LayerRect*);
531 solid_fill_rect_ = *rect;
532 break;
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500533 default:
534 DLOGW("Invalid operation %d", operation);
Arun Kumar K.R536c7d62016-06-14 18:47:39 -0700535 va_end(args);
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500536 return -EINVAL;
537 }
Arun Kumar K.R536c7d62016-06-14 18:47:39 -0700538 va_end(args);
Saurabh Shaha307e8c2017-09-28 18:05:40 -0700539 validated_ = false;
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500540
541 return 0;
542}
543
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +0530544DisplayError HWCDisplayBuiltIn::SetDisplayMode(uint32_t mode) {
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500545 DisplayError error = kErrorNone;
546
547 if (display_intf_) {
548 error = display_intf_->SetDisplayMode(mode);
Tharaga Balachandran04192a62018-08-29 16:23:25 -0400549 if (error == kErrorNone) {
550 DisplayConfigFixedInfo fixed_info = {};
551 display_intf_->GetConfig(&fixed_info);
552 is_cmd_mode_ = fixed_info.is_cmdmode;
553 partial_update_enabled_ = fixed_info.partial_update;
554 for (auto hwc_layer : layer_set_) {
555 hwc_layer->SetPartialUpdate(partial_update_enabled_);
556 }
557 client_target_->SetPartialUpdate(partial_update_enabled_);
558 }
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500559 }
560
561 return error;
562}
563
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +0530564void HWCDisplayBuiltIn::SetMetaDataRefreshRateFlag(bool enable) {
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500565 int disable_metadata_dynfps = 0;
566
Uday Kiran Pichika5e656b22018-05-15 18:48:24 +0530567 HWCDebugHandler::Get()->GetProperty(DISABLE_METADATA_DYNAMIC_FPS_PROP, &disable_metadata_dynfps);
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500568 if (disable_metadata_dynfps) {
569 return;
570 }
571 use_metadata_refresh_rate_ = enable;
572}
573
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +0530574void HWCDisplayBuiltIn::SetQDCMSolidFillInfo(bool enable, const LayerSolidFill &color) {
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500575 solid_fill_enable_ = enable;
576 solid_fill_color_ = color;
577}
578
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +0530579void HWCDisplayBuiltIn::ToggleCPUHint(bool set) {
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500580 if (!cpu_hint_) {
581 return;
582 }
583
584 if (set) {
585 cpu_hint_->Set();
586 } else {
587 cpu_hint_->Reset();
588 }
589}
590
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +0530591int HWCDisplayBuiltIn::HandleSecureSession(const std::bitset<kSecureMax> &secure_sessions,
Ramkumar Radhakrishnana38b7602018-03-15 14:49:52 -0700592 bool *power_on_pending) {
593 if (!power_on_pending) {
594 return -EINVAL;
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500595 }
Ramkumar Radhakrishnana38b7602018-03-15 14:49:52 -0700596
Ramkumar Radhakrishnan44c64362018-12-12 13:03:59 -0800597 if (current_power_mode_ != HWC2::PowerMode::On) {
598 return 0;
599 }
600
Ramkumar Radhakrishnana38b7602018-03-15 14:49:52 -0700601 if (active_secure_sessions_[kSecureDisplay] != secure_sessions[kSecureDisplay]) {
602 SecureEvent secure_event =
603 secure_sessions.test(kSecureDisplay) ? kSecureDisplayStart : kSecureDisplayEnd;
Pullakavi Srinivas0a1dba62018-07-02 15:49:11 +0530604 DisplayError err = display_intf_->HandleSecureEvent(secure_event, &layer_stack_);
Ramkumar Radhakrishnana38b7602018-03-15 14:49:52 -0700605 if (err != kErrorNone) {
606 DLOGE("Set secure event failed");
607 return err;
608 }
609
610 DLOGI("SecureDisplay state changed from %d to %d for display %d",
611 active_secure_sessions_.test(kSecureDisplay), secure_sessions.test(kSecureDisplay),
612 type_);
613 }
614 active_secure_sessions_ = secure_sessions;
615 *power_on_pending = false;
616 return 0;
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500617}
618
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +0530619void HWCDisplayBuiltIn::ForceRefreshRate(uint32_t refresh_rate) {
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500620 if ((refresh_rate && (refresh_rate < min_refresh_rate_ || refresh_rate > max_refresh_rate_)) ||
621 force_refresh_rate_ == refresh_rate) {
622 // Cannot honor force refresh rate, as its beyond the range or new request is same
623 return;
624 }
625
626 force_refresh_rate_ = refresh_rate;
627
Ramkumar Radhakrishnan44c64362018-12-12 13:03:59 -0800628 callbacks_->Refresh(id_);
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500629
630 return;
631}
632
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +0530633uint32_t HWCDisplayBuiltIn::GetOptimalRefreshRate(bool one_updating_layer) {
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500634 if (force_refresh_rate_) {
635 return force_refresh_rate_;
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500636 } else if (use_metadata_refresh_rate_ && one_updating_layer && metadata_refresh_rate_) {
637 return metadata_refresh_rate_;
638 }
639
640 return max_refresh_rate_;
641}
642
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +0530643DisplayError HWCDisplayBuiltIn::Refresh() {
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500644 DisplayError error = kErrorNone;
645
Ramkumar Radhakrishnan44c64362018-12-12 13:03:59 -0800646 callbacks_->Refresh(id_);
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500647
648 return error;
649}
650
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +0530651void HWCDisplayBuiltIn::SetIdleTimeoutMs(uint32_t timeout_ms) {
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500652 display_intf_->SetIdleTimeoutMs(timeout_ms);
Saurabh Shaha307e8c2017-09-28 18:05:40 -0700653 validated_ = false;
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500654}
655
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +0530656void HWCDisplayBuiltIn::HandleFrameOutput() {
Sushil Chauhan06521582018-03-19 14:00:23 -0700657 if (readback_buffer_queued_) {
658 validated_ = false;
659 }
660
Sushil Chauhan1d3b90c2018-12-11 16:52:35 -0800661 if (frame_capture_buffer_queued_) {
662 HandleFrameCapture();
663 } else if (dump_output_to_file_) {
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500664 HandleFrameDump();
665 }
666}
667
Sushil Chauhan1d3b90c2018-12-11 16:52:35 -0800668void HWCDisplayBuiltIn::HandleFrameCapture() {
669 if (readback_configured_ && (output_buffer_.release_fence_fd >= 0)) {
670 frame_capture_status_ = sync_wait(output_buffer_.release_fence_fd, 1000);
671 ::close(output_buffer_.release_fence_fd);
672 output_buffer_.release_fence_fd = -1;
673 }
674
675 frame_capture_buffer_queued_ = false;
676 readback_buffer_queued_ = false;
677 post_processed_output_ = false;
678 readback_configured_ = false;
679 output_buffer_ = {};
Dileep Marchyacb2a3a92019-06-21 17:30:50 +0530680 cwb_client_ = kCWBClientNone;
Sushil Chauhan1d3b90c2018-12-11 16:52:35 -0800681}
682
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +0530683void HWCDisplayBuiltIn::HandleFrameDump() {
Ramkumar Radhakrishnan68331fc2019-06-19 11:24:12 -0700684 if (dump_frame_count_) {
685 int ret = 0;
686 if (output_buffer_.release_fence_fd >= 0) {
687 ret = sync_wait(output_buffer_.release_fence_fd, 1000);
688 if (ret < 0) {
689 DLOGE("sync_wait error errno = %d, desc = %s", errno, strerror(errno));
690 }
691 ::close(output_buffer_.release_fence_fd);
692 output_buffer_.release_fence_fd = -1;
693 }
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500694
Ramkumar Radhakrishnan68331fc2019-06-19 11:24:12 -0700695 if (!ret) {
696 DumpOutputBuffer(output_buffer_info_, output_buffer_base_, layer_stack_.retire_fence_fd);
697 validated_ = false;
698 }
699
700 if (0 == (dump_frame_count_ - 1)) {
701 dump_output_to_file_ = false;
702 // Unmap and Free buffer
703 if (munmap(output_buffer_base_, output_buffer_info_.alloc_buffer_info.size) != 0) {
704 DLOGE("unmap failed with err %d", errno);
705 }
706 if (buffer_allocator_->FreeBuffer(&output_buffer_info_) != 0) {
707 DLOGE("FreeBuffer failed");
708 }
709
Sushil Chauhan06521582018-03-19 14:00:23 -0700710 readback_buffer_queued_ = false;
Ramkumar Radhakrishnan68331fc2019-06-19 11:24:12 -0700711 post_processed_output_ = false;
712 readback_configured_ = false;
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500713
Ramkumar Radhakrishnan68331fc2019-06-19 11:24:12 -0700714 output_buffer_ = {};
715 output_buffer_info_ = {};
716 output_buffer_base_ = nullptr;
Dileep Marchyacb2a3a92019-06-21 17:30:50 +0530717 cwb_client_ = kCWBClientNone;
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500718 }
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500719 }
720}
721
Sushil Chauhan267a6192018-06-06 18:41:47 -0700722HWC2::Error HWCDisplayBuiltIn::SetFrameDumpConfig(uint32_t count, uint32_t bit_mask_layer_type,
723 int32_t format, bool post_processed) {
724 HWCDisplay::SetFrameDumpConfig(count, bit_mask_layer_type, format, post_processed);
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500725 dump_output_to_file_ = bit_mask_layer_type & (1 << OUTPUT_LAYER_DUMP);
726 DLOGI("output_layer_dump_enable %d", dump_output_to_file_);
727
Dileep Marchyacb2a3a92019-06-21 17:30:50 +0530728 if (dump_output_to_file_) {
729 if (cwb_client_ != kCWBClientNone) {
730 DLOGE("CWB is in use with client = %d", cwb_client_);
731 dump_output_to_file_ = false;
732 return HWC2::Error::NoResources;
733 }
734 }
735
Sushil Chauhand0dc03d2018-09-19 07:08:40 -0700736 if (!count || !dump_output_to_file_ || (output_buffer_info_.alloc_buffer_info.fd >= 0)) {
Mathew Joseph Karimpanaldbd64f82017-10-06 10:13:38 +0530737 return HWC2::Error::None;
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500738 }
739
740 // Allocate and map output buffer
Sushil Chauhan267a6192018-06-06 18:41:47 -0700741 if (post_processed) {
742 // To dump post-processed (DSPP) output, use Panel resolution.
743 GetPanelResolution(&output_buffer_info_.buffer_config.width,
744 &output_buffer_info_.buffer_config.height);
745 } else {
746 // To dump Layer Mixer output, use FrameBuffer resolution.
747 GetFrameBufferResolution(&output_buffer_info_.buffer_config.width,
748 &output_buffer_info_.buffer_config.height);
749 }
750
751 output_buffer_info_.buffer_config.format = HWCLayer::GetSDMFormat(format, 0);
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500752 output_buffer_info_.buffer_config.buffer_count = 1;
753 if (buffer_allocator_->AllocateBuffer(&output_buffer_info_) != 0) {
754 DLOGE("Buffer allocation failed");
755 output_buffer_info_ = {};
Mathew Joseph Karimpanaldbd64f82017-10-06 10:13:38 +0530756 return HWC2::Error::NoResources;
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500757 }
758
759 void *buffer = mmap(NULL, output_buffer_info_.alloc_buffer_info.size, PROT_READ | PROT_WRITE,
760 MAP_SHARED, output_buffer_info_.alloc_buffer_info.fd, 0);
761
762 if (buffer == MAP_FAILED) {
763 DLOGE("mmap failed with err %d", errno);
764 buffer_allocator_->FreeBuffer(&output_buffer_info_);
765 output_buffer_info_ = {};
Mathew Joseph Karimpanaldbd64f82017-10-06 10:13:38 +0530766 return HWC2::Error::NoResources;
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500767 }
768
769 output_buffer_base_ = buffer;
Sushil Chauhan06521582018-03-19 14:00:23 -0700770 const native_handle_t *handle = static_cast<native_handle_t *>(output_buffer_info_.private_data);
Dileep Marchyacb2a3a92019-06-21 17:30:50 +0530771 SetReadbackBuffer(handle, -1, post_processed, kCWBClientFrameDump);
Sushil Chauhan06521582018-03-19 14:00:23 -0700772
Mathew Joseph Karimpanaldbd64f82017-10-06 10:13:38 +0530773 return HWC2::Error::None;
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500774}
775
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +0530776int HWCDisplayBuiltIn::FrameCaptureAsync(const BufferInfo &output_buffer_info,
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500777 bool post_processed_output) {
Dileep Marchyacb2a3a92019-06-21 17:30:50 +0530778 if (cwb_client_ != kCWBClientNone) {
779 DLOGE("CWB is in use with client = %d", cwb_client_);
780 return -1;
781 }
782
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500783 // Note: This function is called in context of a binder thread and a lock is already held
784 if (output_buffer_info.alloc_buffer_info.fd < 0) {
785 DLOGE("Invalid fd %d", output_buffer_info.alloc_buffer_info.fd);
786 return -1;
787 }
788
789 auto panel_width = 0u;
790 auto panel_height = 0u;
791 auto fb_width = 0u;
792 auto fb_height = 0u;
793
794 GetPanelResolution(&panel_width, &panel_height);
795 GetFrameBufferResolution(&fb_width, &fb_height);
796
Ch Ganesh Kumar5c4988b2017-06-07 15:21:02 +0530797 if (post_processed_output && (output_buffer_info.buffer_config.width < panel_width ||
798 output_buffer_info.buffer_config.height < panel_height)) {
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500799 DLOGE("Buffer dimensions should not be less than panel resolution");
800 return -1;
Ch Ganesh Kumar5c4988b2017-06-07 15:21:02 +0530801 } else if (!post_processed_output && (output_buffer_info.buffer_config.width < fb_width ||
802 output_buffer_info.buffer_config.height < fb_height)) {
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500803 DLOGE("Buffer dimensions should not be less than FB resolution");
804 return -1;
805 }
806
Sushil Chauhan06521582018-03-19 14:00:23 -0700807 const native_handle_t *buffer = static_cast<native_handle_t *>(output_buffer_info.private_data);
Dileep Marchyacb2a3a92019-06-21 17:30:50 +0530808 SetReadbackBuffer(buffer, -1, post_processed_output, kCWBClientColor);
Sushil Chauhan1d3b90c2018-12-11 16:52:35 -0800809 frame_capture_buffer_queued_ = true;
810 frame_capture_status_ = -EAGAIN;
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500811
812 return 0;
813}
814
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +0530815DisplayError HWCDisplayBuiltIn::SetDetailEnhancerConfig
Alan Kwong2e136332016-08-16 07:50:16 -0400816 (const DisplayDetailEnhancerData &de_data) {
817 DisplayError error = kErrorNotSupported;
818
819 if (display_intf_) {
820 error = display_intf_->SetDetailEnhancerData(de_data);
Saurabh Shaha307e8c2017-09-28 18:05:40 -0700821 validated_ = false;
Alan Kwong2e136332016-08-16 07:50:16 -0400822 }
823 return error;
824}
825
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +0530826DisplayError HWCDisplayBuiltIn::ControlPartialUpdate(bool enable, uint32_t *pending) {
Arun Kumar K.R17bbd042016-06-07 17:38:02 -0700827 DisplayError error = kErrorNone;
828
829 if (display_intf_) {
830 error = display_intf_->ControlPartialUpdate(enable, pending);
Saurabh Shaha307e8c2017-09-28 18:05:40 -0700831 validated_ = false;
Arun Kumar K.R17bbd042016-06-07 17:38:02 -0700832 }
833
834 return error;
835}
836
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +0530837DisplayError HWCDisplayBuiltIn::DisablePartialUpdateOneFrame() {
Arun Kumar K.R17bbd042016-06-07 17:38:02 -0700838 DisplayError error = kErrorNone;
839
840 if (display_intf_) {
841 error = display_intf_->DisablePartialUpdateOneFrame();
Saurabh Shaha307e8c2017-09-28 18:05:40 -0700842 validated_ = false;
Arun Kumar K.R17bbd042016-06-07 17:38:02 -0700843 }
844
845 return error;
846}
847
848
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +0530849DisplayError HWCDisplayBuiltIn::SetMixerResolution(uint32_t width, uint32_t height) {
Sushil Chauhan409e8442017-06-12 17:43:25 -0700850 DisplayError error = display_intf_->SetMixerResolution(width, height);
Ramkumar Radhakrishnanf7f52162019-06-06 19:40:04 -0700851 callbacks_->Refresh(id_);
Saurabh Shaha307e8c2017-09-28 18:05:40 -0700852 validated_ = false;
Sushil Chauhan409e8442017-06-12 17:43:25 -0700853 return error;
Arun Kumar K.R8da7f502016-06-07 17:45:50 -0700854}
855
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +0530856DisplayError HWCDisplayBuiltIn::GetMixerResolution(uint32_t *width, uint32_t *height) {
Arun Kumar K.R8da7f502016-06-07 17:45:50 -0700857 return display_intf_->GetMixerResolution(width, height);
858}
859
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +0530860HWC2::Error HWCDisplayBuiltIn::SetQSyncMode(QSyncMode qsync_mode) {
Sushil Chauhan380a59d2018-03-19 15:47:50 -0700861 auto err = display_intf_->SetQSyncMode(qsync_mode);
862 if (err != kErrorNone) {
863 return HWC2::Error::Unsupported;
864 }
865
Sushil Chauhanec4eb572019-02-07 13:29:42 -0800866 validated_ = false;
Sushil Chauhan380a59d2018-03-19 15:47:50 -0700867 return HWC2::Error::None;
868}
869
Ramkumar Radhakrishnan4faf8a62018-11-15 17:15:37 -0800870DisplayError HWCDisplayBuiltIn::ControlIdlePowerCollapse(bool enable, bool synchronous) {
Ramkumar Radhakrishnanf985d482018-07-23 18:10:41 -0700871 DisplayError error = kErrorNone;
872
873 if (display_intf_) {
874 error = display_intf_->ControlIdlePowerCollapse(enable, synchronous);
875 validated_ = false;
876 }
Ramkumar Radhakrishnan4faf8a62018-11-15 17:15:37 -0800877 return error;
Ramkumar Radhakrishnanf985d482018-07-23 18:10:41 -0700878}
879
Pullakavi Srinivas9189e602018-12-19 16:58:07 +0530880DisplayError HWCDisplayBuiltIn::SetDynamicDSIClock(uint64_t bitclk) {
Dileep Marchyaafa45bc2019-06-21 17:05:31 +0530881 DisablePartialUpdateOneFrame();
882 DisplayError error = display_intf_->SetDynamicDSIClock(bitclk);
883 if (error != kErrorNone) {
884 DLOGE(" failed: Clk: %llu Error: %d", bitclk, error);
885 return error;
Pullakavi Srinivas9189e602018-12-19 16:58:07 +0530886 }
887
888 callbacks_->Refresh(id_);
889 validated_ = false;
890
891 return kErrorNone;
892}
893
894DisplayError HWCDisplayBuiltIn::GetDynamicDSIClock(uint64_t *bitclk) {
Pullakavi Srinivas9189e602018-12-19 16:58:07 +0530895 if (display_intf_) {
896 return display_intf_->GetDynamicDSIClock(bitclk);
897 }
898
899 return kErrorNotSupported;
900}
901
902DisplayError HWCDisplayBuiltIn::GetSupportedDSIClock(std::vector<uint64_t> *bitclk_rates) {
903 if (display_intf_) {
904 return display_intf_->GetSupportedDSIClock(bitclk_rates);
905 }
906
907 return kErrorNotSupported;
908}
909
Padmanabhan Komandurue74cf4f2019-04-25 17:38:43 -0700910HWC2::Error HWCDisplayBuiltIn::UpdateDisplayId(hwc2_display_t id) {
911 id_ = id;
912 return HWC2::Error::None;
913}
914
915HWC2::Error HWCDisplayBuiltIn::SetPendingRefresh() {
916 pending_refresh_ = true;
917 return HWC2::Error::None;
918}
919
Varun Arora75c05f02019-05-14 14:53:37 -0700920HWC2::Error HWCDisplayBuiltIn::SetPanelBrightness(float brightness) {
921 DisplayError ret = display_intf_->SetPanelBrightness(brightness);
922 if (ret != kErrorNone) {
923 return HWC2::Error::NoResources;
924 }
925
926 return HWC2::Error::None;
927}
928
929HWC2::Error HWCDisplayBuiltIn::GetPanelBrightness(float *brightness) {
930 DisplayError ret = display_intf_->GetPanelBrightness(brightness);
931 if (ret != kErrorNone) {
932 return HWC2::Error::NoResources;
933 }
934
935 return HWC2::Error::None;
936}
Xu Yang45d0abf2019-07-05 11:34:06 +0800937
938HWC2::Error HWCDisplayBuiltIn::SetBLScale(uint32_t level) {
939 DisplayError ret = display_intf_->SetBLScale(level);
940 if (ret != kErrorNone) {
941 return HWC2::Error::NoResources;
942 }
Srinivas Pullakavi3c4337f2019-07-03 11:24:31 +0530943 return HWC2::Error::None;
944}
Xu Yang45d0abf2019-07-05 11:34:06 +0800945
Srinivas Pullakavi3c4337f2019-07-03 11:24:31 +0530946HWC2::Error HWCDisplayBuiltIn::UpdatePowerMode(HWC2::PowerMode mode) {
947 current_power_mode_ = mode;
948 validated_ = false;
Xu Yang45d0abf2019-07-05 11:34:06 +0800949 return HWC2::Error::None;
950}
951
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500952} // namespace sdm