blob: 95b94a74c8ef43519e2c54dfcb6f1abee58c49c9 [file] [log] [blame]
Naseer Ahmedb92e73f2016-03-12 02:03:48 -05001/*
Rajavenu Kyatham7338b9e2019-12-30 19:52:16 +05302* Copyright (c) 2014-2020, 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
Pullakavi Srinivas1ae4acb2019-11-18 19:33:45 +053050static void SetRect(LayerRect &src_rect, GLRect *target) {
51 target->left = src_rect.left;
52 target->top = src_rect.top;
53 target->right = src_rect.right;
54 target->bottom = src_rect.bottom;
55}
56
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +053057int HWCDisplayBuiltIn::Create(CoreInterface *core_intf, BufferAllocator *buffer_allocator,
Varun Arora7c8ee542018-05-01 20:58:16 -070058 HWCCallbacks *callbacks, HWCDisplayEventHandler *event_handler,
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +053059 qService::QService *qservice, hwc2_display_t id, int32_t sdm_id,
60 HWCDisplay **hwc_display) {
Naseer Ahmedb92e73f2016-03-12 02:03:48 -050061 int status = 0;
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +053062 uint32_t builtin_width = 0;
63 uint32_t builtin_height = 0;
Naseer Ahmedb92e73f2016-03-12 02:03:48 -050064
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +053065 HWCDisplay *hwc_display_builtin =
66 new HWCDisplayBuiltIn(core_intf, buffer_allocator, callbacks, event_handler, qservice, id,
67 sdm_id);
68 status = hwc_display_builtin->Init();
Naseer Ahmedb92e73f2016-03-12 02:03:48 -050069 if (status) {
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +053070 delete hwc_display_builtin;
Naseer Ahmedb92e73f2016-03-12 02:03:48 -050071 return status;
72 }
73
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +053074 hwc_display_builtin->GetMixerResolution(&builtin_width, &builtin_height);
Naseer Ahmedb92e73f2016-03-12 02:03:48 -050075 int width = 0, height = 0;
Uday Kiran Pichika5e656b22018-05-15 18:48:24 +053076 HWCDebugHandler::Get()->GetProperty(FB_WIDTH_PROP, &width);
77 HWCDebugHandler::Get()->GetProperty(FB_HEIGHT_PROP, &height);
Naseer Ahmedb92e73f2016-03-12 02:03:48 -050078 if (width > 0 && height > 0) {
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +053079 builtin_width = UINT32(width);
80 builtin_height = UINT32(height);
Naseer Ahmedb92e73f2016-03-12 02:03:48 -050081 }
82
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +053083 status = hwc_display_builtin->SetFrameBufferResolution(builtin_width, builtin_height);
Naseer Ahmedb92e73f2016-03-12 02:03:48 -050084 if (status) {
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +053085 Destroy(hwc_display_builtin);
Naseer Ahmedb92e73f2016-03-12 02:03:48 -050086 return status;
87 }
88
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +053089 *hwc_display = hwc_display_builtin;
Naseer Ahmedb92e73f2016-03-12 02:03:48 -050090
91 return status;
92}
93
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +053094void HWCDisplayBuiltIn::Destroy(HWCDisplay *hwc_display) {
Naseer Ahmedb92e73f2016-03-12 02:03:48 -050095 hwc_display->Deinit();
96 delete hwc_display;
97}
98
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +053099HWCDisplayBuiltIn::HWCDisplayBuiltIn(CoreInterface *core_intf, BufferAllocator *buffer_allocator,
Varun Arora7c8ee542018-05-01 20:58:16 -0700100 HWCCallbacks *callbacks, HWCDisplayEventHandler *event_handler,
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +0530101 qService::QService *qservice, hwc2_display_t id,
102 int32_t sdm_id)
103 : HWCDisplay(core_intf, buffer_allocator, callbacks, event_handler, qservice, kBuiltIn, id,
Gousemoodhin Nadaf087c3102019-01-07 19:34:56 +0530104 sdm_id, DISPLAY_CLASS_BUILTIN),
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +0530105 buffer_allocator_(buffer_allocator),
Pullakavi Srinivas1ae4acb2019-11-18 19:33:45 +0530106 cpu_hint_(NULL), layer_stitch_task_(*this) {
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500107}
108
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +0530109int HWCDisplayBuiltIn::Init() {
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500110 cpu_hint_ = new CPUHint();
111 if (cpu_hint_->Init(static_cast<HWCDebugHandler *>(HWCDebugHandler::Get())) != kErrorNone) {
112 delete cpu_hint_;
113 cpu_hint_ = NULL;
114 }
115
116 use_metadata_refresh_rate_ = true;
117 int disable_metadata_dynfps = 0;
Uday Kiran Pichika5e656b22018-05-15 18:48:24 +0530118 HWCDebugHandler::Get()->GetProperty(DISABLE_METADATA_DYNAMIC_FPS_PROP, &disable_metadata_dynfps);
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500119 if (disable_metadata_dynfps) {
120 use_metadata_refresh_rate_ = false;
121 }
122
Arun Kumar K.R29cd6582016-05-10 19:12:45 -0700123 int status = HWCDisplay::Init();
124 if (status) {
125 return status;
126 }
127 color_mode_ = new HWCColorMode(display_intf_);
Naseer Ahmed61f60952017-05-24 16:48:35 -0400128 color_mode_->Init();
Arun Kumar K.R29cd6582016-05-10 19:12:45 -0700129
Padmanabhan Komandurufa213652020-04-24 15:38:15 +0530130 int value = 0;
131 HWCDebugHandler::Get()->GetProperty(ENABLE_OPTIMIZE_REFRESH, &value);
132 enable_optimize_refresh_ = (value == 1);
Padmanabhan Komanduru866bf6a2019-03-19 14:30:48 +0530133 if (enable_optimize_refresh_) {
Pullakavi Srinivasce3692b2020-02-13 01:14:09 +0530134 DLOGI("Drop redundant drawcycles %" PRIu64 , id_);
Padmanabhan Komandurue74cf4f2019-04-25 17:38:43 -0700135 }
136
Sushil Chauhandbd8db42020-02-28 13:07:48 -0800137 int vsyncs = 0;
138 HWCDebugHandler::Get()->GetProperty(DEFER_FPS_FRAME_COUNT, &vsyncs);
139 if (vsyncs > 0) {
140 SetVsyncsApplyRateChange(UINT32(vsyncs));
141 }
142
Mathew Joseph Karimpanalb1c15862019-07-04 11:14:24 +0530143 is_primary_ = display_intf_->IsPrimaryDisplay();
144
Rajavenu Kyathamf87a7a72019-12-05 16:43:07 +0530145 if (is_primary_) {
Padmanabhan Komandurub5ff0fb2020-02-12 18:08:04 +0530146 int enable_bw_limits = 0;
147 HWCDebugHandler::Get()->GetProperty(ENABLE_BW_LIMITS, &enable_bw_limits);
148 enable_bw_limits_ = (enable_bw_limits == 1);
149 if (enable_bw_limits_) {
Pullakavi Srinivasce3692b2020-02-13 01:14:09 +0530150 DLOGI("Enable BW Limits %" PRIu64, id_);
Padmanabhan Komandurub5ff0fb2020-02-12 18:08:04 +0530151 }
Pullakavi Srinivasd32b4922020-02-10 10:08:31 +0530152 windowed_display_ = Debug::GetWindowRect(&window_rect_.left, &window_rect_.top,
153 &window_rect_.right, &window_rect_.bottom) != kErrorUndefined;
Rajavenu Kyathamf87a7a72019-12-05 16:43:07 +0530154 DLOGI("Window rect : [%f %f %f %f]", window_rect_.left, window_rect_.top,
Pullakavi Srinivasd32b4922020-02-10 10:08:31 +0530155 window_rect_.right, window_rect_.bottom);
Padmanabhan Komandurufa213652020-04-24 15:38:15 +0530156
157 value = 0;
158 HWCDebugHandler::Get()->GetProperty(ENABLE_POMS_DURING_DOZE, &value);
159 enable_poms_during_doze_ = (value == 1);
160 if (enable_poms_during_doze_) {
161 DLOGI("Enable POMS during Doze mode %" PRIu64 , id_);
162 }
Rajavenu Kyathamf87a7a72019-12-05 16:43:07 +0530163 }
Pullakavi Srinivas7bdcc762020-03-06 12:41:36 +0530164
165 uint32_t config_index = 0;
166 GetActiveDisplayConfig(&config_index);
167 DisplayConfigVariableInfo attr = {};
168 GetDisplayAttributesForConfig(INT(config_index), &attr);
169 active_refresh_rate_ = attr.fps;
170
171 DLOGI("active_refresh_rate: %d", active_refresh_rate_);
172
Naseer Ahmed61f60952017-05-24 16:48:35 -0400173 return status;
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500174}
175
Dileep Marchya58928122020-01-28 12:16:51 +0530176void HWCDisplayBuiltIn::Dump(std::ostringstream *os) {
177 HWCDisplay::Dump(os);
178 *os << histogram.Dump();
Lakshmi Narayana Kalavala25fe12c2019-12-11 20:44:55 -0800179}
180
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +0530181HWC2::Error HWCDisplayBuiltIn::Validate(uint32_t *out_num_types, uint32_t *out_num_requests) {
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500182 auto status = HWC2::Error::None;
183 DisplayError error = kErrorNone;
184
Gurpreet Singh Dhamia4276882019-04-12 10:30:58 -0700185 DTRACE_SCOPED();
186
Mathew Joseph Karimpanalb1c15862019-07-04 11:14:24 +0530187 if (display_paused_ || (!is_primary_ && active_secure_sessions_[kSecureDisplay])) {
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500188 MarkLayersForGPUBypass();
189 return status;
190 }
191
Arun Kumar K.R29cd6582016-05-10 19:12:45 -0700192 if (color_tranform_failed_) {
193 // Must fall back to client composition
194 MarkLayersForClientComposition();
195 }
196
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500197 // Fill in the remaining blanks in the layers and add them to the SDM layerstack
198 BuildLayerStack();
Pullakavi Srinivas1ae4acb2019-11-18 19:33:45 +0530199
200 // Add stitch layer to layer stack.
201 AppendStitchLayer();
202
Arun Kumar K.R536c7d62016-06-14 18:47:39 -0700203 // Checks and replaces layer stack for solid fill
204 SolidFillPrepare();
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500205
Sushil Chauhan8008d602018-09-04 14:43:27 -0700206 // Apply current Color Mode and Render Intent.
Xu Yang84e61412018-12-06 14:52:16 +0800207 if (color_mode_->ApplyCurrentColorModeWithRenderIntent(
208 static_cast<bool>(layer_stack_.flags.hdr_present)) != HWC2::Error::None) {
Sushil Chauhan8008d602018-09-04 14:43:27 -0700209 // Fallback to GPU Composition, if Color Mode can't be applied.
210 MarkLayersForClientComposition();
211 }
212
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500213 bool pending_output_dump = dump_frame_count_ && dump_output_to_file_;
214
Sushil Chauhan06521582018-03-19 14:00:23 -0700215 if (readback_buffer_queued_ || pending_output_dump) {
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500216 // RHS values were set in FrameCaptureAsync() called from a binder thread. They are picked up
Sushil Chauhan06521582018-03-19 14:00:23 -0700217 // here in a subsequent draw round. Readback is not allowed for any secure use case.
218 readback_configured_ = !layer_stack_.flags.secure_present;
219 if (readback_configured_) {
Sushil Chauhanf42d8622018-09-30 23:20:37 -0700220 DisablePartialUpdateOneFrame();
Sushil Chauhan06521582018-03-19 14:00:23 -0700221 layer_stack_.output_buffer = &output_buffer_;
222 layer_stack_.flags.post_processed_output = post_processed_output_;
223 }
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500224 }
225
Ramakant Singh5db0dfb2017-08-23 12:34:57 +0530226 uint32_t num_updating_layers = GetUpdatingLayersCount();
227 bool one_updating_layer = (num_updating_layers == 1);
228 if (num_updating_layers != 0) {
229 ToggleCPUHint(one_updating_layer);
230 }
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500231
232 uint32_t refresh_rate = GetOptimalRefreshRate(one_updating_layer);
Pullakavi Srinivas4619db92019-04-20 15:07:59 +0530233 error = display_intf_->SetRefreshRate(refresh_rate, force_refresh_rate_);
234
235 // Get the refresh rate set.
236 display_intf_->GetRefreshRate(&refresh_rate);
237 bool vsync_source = (callbacks_->GetVsyncSource() == id_);
238
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500239 if (error == kErrorNone) {
Pullakavi Srinivas4619db92019-04-20 15:07:59 +0530240 if (vsync_source && (current_refresh_rate_ < refresh_rate)) {
241 DTRACE_BEGIN("HWC2::Vsync::Enable");
242 // Display is ramping up from idle.
243 // Client realizes need for resync upon change in config.
244 // Since we know config has changed, triggering vsync proactively
245 // can help in reducing pipeline delays to enable events.
246 SetVsyncEnabled(HWC2::Vsync::Enable);
247 DTRACE_END();
248 }
249 // On success, set current refresh rate to new refresh rate.
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500250 current_refresh_rate_ = refresh_rate;
251 }
252
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500253 if (layer_set_.empty()) {
Uday Kiran Pichika8d827732018-01-09 18:08:38 +0530254 // Avoid flush for Command mode panel.
Pullakavi Srinivas2d55f3a2019-07-16 14:49:06 +0530255 flush_ = !client_connected_;
Ramkumar Radhakrishnana38b7602018-03-15 14:49:52 -0700256 validated_ = true;
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500257 return status;
258 }
259
260 status = PrepareLayerStack(out_num_types, out_num_requests);
Namit Solanki5b428dc2018-02-27 11:39:05 +0530261 pending_commit_ = true;
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500262 return status;
263}
264
Padmanabhan Komandurue74cf4f2019-04-25 17:38:43 -0700265HWC2::Error HWCDisplayBuiltIn::CommitLayerStack() {
266 skip_commit_ = CanSkipCommit();
267 return HWCDisplay::CommitLayerStack();
268}
269
270bool HWCDisplayBuiltIn::CanSkipCommit() {
271 if (layer_stack_invalid_) {
272 return false;
273 }
274
275 // Reject repeated drawcycle requests if it satisfies all conditions.
276 // 1. None of the layerstack attributes changed.
277 // 2. No new buffer latched.
278 // 3. No refresh request triggered by HWC.
279 // 4. This display is not source of vsync.
280 bool buffers_latched = false;
281 for (auto &hwc_layer : layer_set_) {
282 buffers_latched |= hwc_layer->BufferLatched();
283 hwc_layer->ResetBufferFlip();
284 }
285
Padmanabhan Komanduruf5e6c5d2019-04-04 13:56:31 +0530286 bool vsync_source = (callbacks_->GetVsyncSource() == id_);
Padmanabhan Komanduru866bf6a2019-03-19 14:30:48 +0530287 bool skip_commit = enable_optimize_refresh_ && !pending_commit_ && !buffers_latched &&
Padmanabhan Komanduruf5e6c5d2019-04-04 13:56:31 +0530288 !pending_refresh_ && !vsync_source;
Padmanabhan Komandurue74cf4f2019-04-25 17:38:43 -0700289 pending_refresh_ = false;
290
291 return skip_commit;
292}
293
Pullakavi Srinivas1ae4acb2019-11-18 19:33:45 +0530294HWC2::Error HWCDisplayBuiltIn::CommitStitchLayers() {
Pullakavi Srinivasdb2b84a2019-11-21 14:47:35 +0530295 if (disable_layer_stitch_) {
Pullakavi Srinivas1ae4acb2019-11-18 19:33:45 +0530296 return HWC2::Error::None;
297 }
298
Pullakavi Srinivasdb2b84a2019-11-21 14:47:35 +0530299 if (!validated_ || skip_commit_) {
Pullakavi Srinivas1ae4acb2019-11-18 19:33:45 +0530300 return HWC2::Error::None;
301 }
302
303 for (auto &layer : layer_stack_.layers) {
304 LayerComposition &composition = layer->composition;
305 if (composition != kCompositionStitch) {
306 continue;
307 }
308
Pullakavi Srinivasdb2b84a2019-11-21 14:47:35 +0530309 LayerStitchContext ctx = {};
Pullakavi Srinivas1ae4acb2019-11-18 19:33:45 +0530310 // Stitch target doesn't have an input fence.
311 // Render all layers at specified destination.
312 LayerBuffer &input_buffer = layer->input_buffer;
313 ctx.src_hnd = reinterpret_cast<const private_handle_t *>(input_buffer.buffer_id);
314 Layer *stitch_layer = stitch_target_->GetSDMLayer();
315 LayerBuffer &output_buffer = stitch_layer->input_buffer;
316 ctx.dst_hnd = reinterpret_cast<const private_handle_t *>(output_buffer.buffer_id);
Pullakavi Srinivasf25bc4a2020-02-27 12:07:39 +0530317 SetRect(layer->stitch_info.dst_rect, &ctx.dst_rect);
318 SetRect(layer->stitch_info.slice_rect, &ctx.scissor_rect);
Rajavenu Kyatham7338b9e2019-12-30 19:52:16 +0530319 ctx.src_acquire_fence = input_buffer.acquire_fence;
Pullakavi Srinivas1ae4acb2019-11-18 19:33:45 +0530320
321 layer_stitch_task_.PerformTask(LayerStitchTaskCode::kCodeStitch, &ctx);
322
Rajavenu Kyatham7338b9e2019-12-30 19:52:16 +0530323 // Merge with current fence.
324 output_buffer.acquire_fence = Fence::Merge(output_buffer.acquire_fence, ctx.release_fence);
Pullakavi Srinivas1ae4acb2019-11-18 19:33:45 +0530325 }
326
327 return HWC2::Error::None;
328}
329
Padmanabhan Komanduru6693fcb2019-11-22 21:06:52 +0530330void HWCDisplayBuiltIn::CacheAvrStatus() {
331 QSyncMode qsync_mode = kQSyncModeNone;
332
333 DisplayError error = display_intf_->GetQSyncMode(&qsync_mode);
334 if (error != kErrorNone) {
335 return;
336 }
337
338 bool qsync_enabled = (qsync_mode != kQSyncModeNone);
339 if (qsync_enabled_ != qsync_enabled) {
340 qsync_reconfigured_ = true;
341 qsync_enabled_ = qsync_enabled;
342 } else {
343 qsync_reconfigured_ = false;
344 }
345}
346
347bool HWCDisplayBuiltIn::IsQsyncCallbackNeeded(bool *qsync_enabled, int32_t *refresh_rate,
348 int32_t *qsync_refresh_rate) {
349 if (!qsync_reconfigured_) {
350 return false;
351 }
352
353 bool vsync_source = (callbacks_->GetVsyncSource() == id_);
354 // Qsync callback not needed if this display is not the source of vsync
355 if (!vsync_source) {
356 return false;
357 }
358
359 *qsync_enabled = qsync_enabled_;
360 uint32_t current_rate = 0;
361 display_intf_->GetRefreshRate(&current_rate);
362 *refresh_rate = INT32(current_rate);
363 *qsync_refresh_rate = min_refresh_rate_;
364
365 return true;
366}
367
Padmanabhan Komandurub5ff0fb2020-02-12 18:08:04 +0530368int HWCDisplayBuiltIn::GetBwCode(const DisplayConfigVariableInfo &attr) {
369 uint32_t min_refresh_rate = 0, max_refresh_rate = 0;
370 display_intf_->GetRefreshRateRange(&min_refresh_rate, &max_refresh_rate);
371 uint32_t fps = attr.smart_panel ? attr.fps : max_refresh_rate;
372
373 if (fps <= 60) {
374 return kBwLow;
375 } else if (fps <= 90) {
376 return kBwMedium;
377 } else {
378 return kBwHigh;
379 }
380}
381
382void HWCDisplayBuiltIn::SetBwLimitHint(bool enable) {
383 if (!enable_bw_limits_) {
384 return;
385 }
386
387 if (!enable) {
388 thermal_bandwidth_client_cancel_request(const_cast<char*>(kDisplayBwName));
389 curr_refresh_rate_ = 0;
390 return;
391 }
392
393 uint32_t config_index = 0;
394 DisplayConfigVariableInfo attr = {};
395 GetActiveDisplayConfig(&config_index);
396 GetDisplayAttributesForConfig(INT(config_index), &attr);
397 if (attr.fps != curr_refresh_rate_ || attr.smart_panel != is_smart_panel_) {
398 int bw_code = GetBwCode(attr);
399 int req_data = thermal_bandwidth_client_merge_input_info(bw_code, 0);
400 int error = thermal_bandwidth_client_request(const_cast<char*>(kDisplayBwName), req_data);
401 if (error) {
402 DLOGE("Thermal bandwidth request failed %d", error);
403 }
404 curr_refresh_rate_ = attr.fps;
405 is_smart_panel_ = attr.smart_panel;
406 }
407}
408
Padmanabhan Komanduru5ec3a872020-04-13 14:19:16 +0530409void HWCDisplayBuiltIn::SetPartialUpdate(DisplayConfigFixedInfo fixed_info) {
410 partial_update_enabled_ = fixed_info.partial_update || (!fixed_info.is_cmdmode);
411 for (auto hwc_layer : layer_set_) {
412 hwc_layer->SetPartialUpdate(partial_update_enabled_);
413 }
414 client_target_->SetPartialUpdate(partial_update_enabled_);
415}
416
Padmanabhan Komandurub5ff0fb2020-02-12 18:08:04 +0530417HWC2::Error HWCDisplayBuiltIn::SetPowerMode(HWC2::PowerMode mode, bool teardown) {
Padmanabhan Komanduru5ec3a872020-04-13 14:19:16 +0530418 DisplayConfigFixedInfo fixed_info = {};
419 display_intf_->GetConfig(&fixed_info);
420 bool command_mode = fixed_info.is_cmdmode;
421
Padmanabhan Komandurub5ff0fb2020-02-12 18:08:04 +0530422 auto status = HWCDisplay::SetPowerMode(mode, teardown);
423 if (status != HWC2::Error::None) {
424 return status;
425 }
426
Padmanabhan Komanduru5ec3a872020-04-13 14:19:16 +0530427 display_intf_->GetConfig(&fixed_info);
428 is_cmd_mode_ = fixed_info.is_cmdmode;
429 if (is_cmd_mode_ != command_mode) {
430 SetPartialUpdate(fixed_info);
431 }
432
Padmanabhan Komandurub5ff0fb2020-02-12 18:08:04 +0530433 if (mode == HWC2::PowerMode::Off) {
434 SetBwLimitHint(false);
435 }
436
437 return HWC2::Error::None;
438}
439
Dileep Marchyaad668432019-12-02 10:44:52 +0530440HWC2::Error HWCDisplayBuiltIn::Present(shared_ptr<Fence> *out_retire_fence) {
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500441 auto status = HWC2::Error::None;
Gurpreet Singh Dhamia4276882019-04-12 10:30:58 -0700442
443 DTRACE_SCOPED();
Mathew Joseph Karimpanalb1c15862019-07-04 11:14:24 +0530444
445 if (!is_primary_ && active_secure_sessions_[kSecureDisplay]) {
Pullakavi Srinivas1ae4acb2019-11-18 19:33:45 +0530446 return status;
Mathew Joseph Karimpanalb1c15862019-07-04 11:14:24 +0530447 } else if (display_paused_) {
Pullakavi Srinivas0a1dba62018-07-02 15:49:11 +0530448 DisplayError error = display_intf_->Flush(&layer_stack_);
Saurabh Shaha307e8c2017-09-28 18:05:40 -0700449 validated_ = false;
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500450 if (error != kErrorNone) {
451 DLOGE("Flush failed. Error = %d", error);
452 }
453 } else {
Padmanabhan Komanduru6693fcb2019-11-22 21:06:52 +0530454 CacheAvrStatus();
Padmanabhan Komanduru5ec3a872020-04-13 14:19:16 +0530455 DisplayConfigFixedInfo fixed_info = {};
456 display_intf_->GetConfig(&fixed_info);
457 bool command_mode = fixed_info.is_cmdmode;
Padmanabhan Komanduru6693fcb2019-11-22 21:06:52 +0530458
Pullakavi Srinivas1ae4acb2019-11-18 19:33:45 +0530459 status = CommitStitchLayers();
460 if (status != HWC2::Error::None) {
461 DLOGE("Stitch failed: %d", status);
462 return status;
463 }
464
Padmanabhan Komandurue74cf4f2019-04-25 17:38:43 -0700465 status = CommitLayerStack();
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500466 if (status == HWC2::Error::None) {
467 HandleFrameOutput();
Pullakavi Srinivasdb2b84a2019-11-21 14:47:35 +0530468 PostCommitStitchLayers();
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500469 status = HWCDisplay::PostCommitLayerStack(out_retire_fence);
Padmanabhan Komandurub5ff0fb2020-02-12 18:08:04 +0530470 SetBwLimitHint(true);
Padmanabhan Komanduru5ec3a872020-04-13 14:19:16 +0530471 display_intf_->GetConfig(&fixed_info);
472 is_cmd_mode_ = fixed_info.is_cmdmode;
473 if (is_cmd_mode_ != command_mode) {
474 SetPartialUpdate(fixed_info);
475 }
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500476 }
477 }
Arun Kumar K.R536c7d62016-06-14 18:47:39 -0700478
Namit Solanki5b428dc2018-02-27 11:39:05 +0530479 pending_commit_ = false;
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500480 return status;
481}
482
Pullakavi Srinivasdb2b84a2019-11-21 14:47:35 +0530483void HWCDisplayBuiltIn::PostCommitStitchLayers() {
484 if (disable_layer_stitch_) {
485 return;
486 }
487
488 // Close Stitch buffer acquire fence.
489 Layer *stitch_layer = stitch_target_->GetSDMLayer();
490 LayerBuffer &output_buffer = stitch_layer->input_buffer;
491 for (auto &layer : layer_stack_.layers) {
492 LayerComposition &composition = layer->composition;
493 if (composition != kCompositionStitch) {
494 continue;
495 }
496 LayerBuffer &input_buffer = layer->input_buffer;
Rajavenu Kyatham7338b9e2019-12-30 19:52:16 +0530497 input_buffer.release_fence = output_buffer.acquire_fence;
Pullakavi Srinivasdb2b84a2019-11-21 14:47:35 +0530498 }
Pullakavi Srinivasdb2b84a2019-11-21 14:47:35 +0530499}
500
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +0530501HWC2::Error HWCDisplayBuiltIn::GetColorModes(uint32_t *out_num_modes, ColorMode *out_modes) {
Arun Kumar K.R29cd6582016-05-10 19:12:45 -0700502 if (out_modes == nullptr) {
503 *out_num_modes = color_mode_->GetColorModeCount();
504 } else {
505 color_mode_->GetColorModes(out_num_modes, out_modes);
506 }
507
508 return HWC2::Error::None;
509}
510
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +0530511HWC2::Error HWCDisplayBuiltIn::GetRenderIntents(ColorMode mode, uint32_t *out_num_intents,
Naseer Ahmede7a77982018-06-04 10:56:04 -0400512 RenderIntent *out_intents) {
513 if (out_intents == nullptr) {
514 *out_num_intents = color_mode_->GetRenderIntentCount(mode);
515 } else {
516 color_mode_->GetRenderIntents(mode, out_num_intents, out_intents);
517 }
518 return HWC2::Error::None;
519}
520
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +0530521HWC2::Error HWCDisplayBuiltIn::SetColorMode(ColorMode mode) {
Naseer Ahmede7a77982018-06-04 10:56:04 -0400522 return SetColorModeWithRenderIntent(mode, RenderIntent::COLORIMETRIC);
523}
524
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +0530525HWC2::Error HWCDisplayBuiltIn::SetColorModeWithRenderIntent(ColorMode mode, RenderIntent intent) {
Sushil Chauhan8008d602018-09-04 14:43:27 -0700526 auto status = color_mode_->CacheColorModeWithRenderIntent(mode, intent);
Arun Kumar K.R29cd6582016-05-10 19:12:45 -0700527 if (status != HWC2::Error::None) {
Naseer Ahmede7a77982018-06-04 10:56:04 -0400528 DLOGE("failed for mode = %d intent = %d", mode, intent);
Arun Kumar K.R29cd6582016-05-10 19:12:45 -0700529 return status;
530 }
Ramkumar Radhakrishnan44c64362018-12-12 13:03:59 -0800531 callbacks_->Refresh(id_);
Saurabh Shaha307e8c2017-09-28 18:05:40 -0700532 validated_ = false;
Arun Kumar K.R29cd6582016-05-10 19:12:45 -0700533 return status;
534}
535
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +0530536HWC2::Error HWCDisplayBuiltIn::SetColorModeById(int32_t color_mode_id) {
Naseer Ahmed6776dae2017-05-09 11:49:41 -0400537 auto status = color_mode_->SetColorModeById(color_mode_id);
538 if (status != HWC2::Error::None) {
539 DLOGE("failed for mode = %d", color_mode_id);
540 return status;
541 }
542
Ramkumar Radhakrishnan44c64362018-12-12 13:03:59 -0800543 callbacks_->Refresh(id_);
Saurabh Shaha307e8c2017-09-28 18:05:40 -0700544 validated_ = false;
Naseer Ahmed6776dae2017-05-09 11:49:41 -0400545
546 return status;
547}
548
Xu Yang84e61412018-12-06 14:52:16 +0800549HWC2::Error HWCDisplayBuiltIn::SetColorModeFromClientApi(int32_t color_mode_id) {
550 DisplayError error = kErrorNone;
551 std::string mode_string;
552
553 error = display_intf_->GetColorModeName(color_mode_id, &mode_string);
554 if (error) {
555 DLOGE("Failed to get mode name for mode %d", color_mode_id);
556 return HWC2::Error::BadParameter;
557 }
558
559 auto status = color_mode_->SetColorModeFromClientApi(mode_string);
560 if (status != HWC2::Error::None) {
561 DLOGE("Failed to set mode = %d", color_mode_id);
562 return status;
563 }
564
565 return status;
566}
567
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +0530568HWC2::Error HWCDisplayBuiltIn::RestoreColorTransform() {
Ch Ganesh Kumar5d43ff62017-10-13 19:01:47 +0530569 auto status = color_mode_->RestoreColorTransform();
570 if (status != HWC2::Error::None) {
571 DLOGE("failed to RestoreColorTransform");
572 return status;
573 }
574
Ramkumar Radhakrishnan44c64362018-12-12 13:03:59 -0800575 callbacks_->Refresh(id_);
Ch Ganesh Kumar5d43ff62017-10-13 19:01:47 +0530576
577 return status;
578}
579
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +0530580HWC2::Error HWCDisplayBuiltIn::SetColorTransform(const float *matrix,
Arun Kumar K.R29cd6582016-05-10 19:12:45 -0700581 android_color_transform_t hint) {
582 if (!matrix) {
583 return HWC2::Error::BadParameter;
584 }
585
586 auto status = color_mode_->SetColorTransform(matrix, hint);
587 if (status != HWC2::Error::None) {
588 DLOGE("failed for hint = %d", hint);
589 color_tranform_failed_ = true;
590 return status;
591 }
592
Ramkumar Radhakrishnan44c64362018-12-12 13:03:59 -0800593 callbacks_->Refresh(id_);
Arun Kumar K.R29cd6582016-05-10 19:12:45 -0700594 color_tranform_failed_ = false;
Saurabh Shaha307e8c2017-09-28 18:05:40 -0700595 validated_ = false;
Arun Kumar K.R29cd6582016-05-10 19:12:45 -0700596
597 return status;
598}
599
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +0530600HWC2::Error HWCDisplayBuiltIn::SetReadbackBuffer(const native_handle_t *buffer,
Rajavenu Kyatham7338b9e2019-12-30 19:52:16 +0530601 shared_ptr<Fence> acquire_fence,
602 bool post_processed_output, CWBClient client) {
Dileep Marchyacb2a3a92019-06-21 17:30:50 +0530603 if (cwb_client_ != client && cwb_client_ != kCWBClientNone) {
604 DLOGE("CWB is in use with client = %d", cwb_client_);
605 return HWC2::Error::NoResources;
606 }
607
Sushil Chauhan06521582018-03-19 14:00:23 -0700608 const private_handle_t *handle = reinterpret_cast<const private_handle_t *>(buffer);
609 if (!handle || (handle->fd < 0)) {
610 return HWC2::Error::BadParameter;
611 }
612
613 // Configure the output buffer as Readback buffer
614 output_buffer_.width = UINT32(handle->width);
615 output_buffer_.height = UINT32(handle->height);
616 output_buffer_.unaligned_width = UINT32(handle->unaligned_width);
617 output_buffer_.unaligned_height = UINT32(handle->unaligned_height);
618 output_buffer_.format = HWCLayer::GetSDMFormat(handle->format, handle->flags);
619 output_buffer_.planes[0].fd = handle->fd;
620 output_buffer_.planes[0].stride = UINT32(handle->width);
Rajavenu Kyatham7338b9e2019-12-30 19:52:16 +0530621 output_buffer_.acquire_fence = acquire_fence;
Sushil Chauhand0dc03d2018-09-19 07:08:40 -0700622 output_buffer_.handle_id = handle->id;
Sushil Chauhan06521582018-03-19 14:00:23 -0700623
624 post_processed_output_ = post_processed_output;
625 readback_buffer_queued_ = true;
626 readback_configured_ = false;
627 validated_ = false;
Dileep Marchyacb2a3a92019-06-21 17:30:50 +0530628 cwb_client_ = client;
Sushil Chauhan06521582018-03-19 14:00:23 -0700629
Sushil Chauhan06521582018-03-19 14:00:23 -0700630 return HWC2::Error::None;
631}
632
Rajavenu Kyatham7338b9e2019-12-30 19:52:16 +0530633HWC2::Error HWCDisplayBuiltIn::GetReadbackBufferFence(shared_ptr<Fence> *release_fence) {
Sushil Chauhan06521582018-03-19 14:00:23 -0700634 auto status = HWC2::Error::None;
635
Rajavenu Kyatham7338b9e2019-12-30 19:52:16 +0530636 if (readback_configured_ && output_buffer_.release_fence) {
637 *release_fence = output_buffer_.release_fence;
Sushil Chauhan06521582018-03-19 14:00:23 -0700638 } else {
639 status = HWC2::Error::Unsupported;
Sushil Chauhan06521582018-03-19 14:00:23 -0700640 }
641
642 post_processed_output_ = false;
643 readback_buffer_queued_ = false;
644 readback_configured_ = false;
645 output_buffer_ = {};
Dileep Marchyacb2a3a92019-06-21 17:30:50 +0530646 cwb_client_ = kCWBClientNone;
Sushil Chauhan06521582018-03-19 14:00:23 -0700647
648 return status;
649}
650
Gurpreet Singh Dhami1207e462018-12-27 20:02:02 -0500651DisplayError HWCDisplayBuiltIn::TeardownConcurrentWriteback(void) {
652 DisplayError error = kErrorNotSupported;
Rajavenu Kyatham7338b9e2019-12-30 19:52:16 +0530653 if (Fence::Wait(output_buffer_.release_fence) != kErrorNone) {
654 DLOGE("sync_wait error errno = %d, desc = %s", errno, strerror(errno));
655 return kErrorResources;
Gurpreet Singh Dhami1207e462018-12-27 20:02:02 -0500656 }
657
658 if (display_intf_) {
659 error = display_intf_->TeardownConcurrentWriteback();
660 }
661
662 return error;
663}
664
Yuchao Ma577f0f72018-07-09 11:20:00 +0800665HWC2::Error HWCDisplayBuiltIn::SetDisplayDppsAdROI(uint32_t h_start, uint32_t h_end,
666 uint32_t v_start, uint32_t v_end,
667 uint32_t factor_in, uint32_t factor_out) {
668 DisplayError error = kErrorNone;
669 DisplayDppsAd4RoiCfg dpps_ad4_roi_cfg = {};
670 uint32_t panel_width = 0, panel_height = 0;
671 constexpr uint16_t kMaxFactorVal = 0xffff;
672
673 if (h_start >= h_end || v_start >= v_end || factor_in > kMaxFactorVal ||
674 factor_out > kMaxFactorVal) {
675 DLOGE("Invalid roi region = [%u, %u, %u, %u, %u, %u]",
676 h_start, h_end, v_start, v_end, factor_in, factor_out);
677 return HWC2::Error::BadParameter;
678 }
679
680 GetPanelResolution(&panel_width, &panel_height);
681
682 if (h_start >= panel_width || h_end > panel_width ||
683 v_start >= panel_height || v_end > panel_height) {
684 DLOGE("Invalid roi region = [%u, %u, %u, %u], panel resolution = [%u, %u]",
685 h_start, h_end, v_start, v_end, panel_width, panel_height);
686 return HWC2::Error::BadParameter;
687 }
688
689 dpps_ad4_roi_cfg.h_start = h_start;
690 dpps_ad4_roi_cfg.h_end = h_end;
691 dpps_ad4_roi_cfg.v_start = v_start;
692 dpps_ad4_roi_cfg.v_end = v_end;
693 dpps_ad4_roi_cfg.factor_in = factor_in;
694 dpps_ad4_roi_cfg.factor_out = factor_out;
695
696 error = display_intf_->SetDisplayDppsAdROI(&dpps_ad4_roi_cfg);
697 if (error)
698 return HWC2::Error::BadConfig;
699
Ramkumar Radhakrishnan44c64362018-12-12 13:03:59 -0800700 callbacks_->Refresh(id_);
Yuchao Ma577f0f72018-07-09 11:20:00 +0800701
702 return HWC2::Error::None;
703}
704
Xu Yang9dacc872018-12-25 11:04:28 +0800705HWC2::Error HWCDisplayBuiltIn::SetFrameTriggerMode(uint32_t mode) {
706 DisplayError error = kErrorNone;
707 FrameTriggerMode trigger_mode = kFrameTriggerDefault;
708
709 if (mode >= kFrameTriggerMax) {
710 DLOGE("Invalid input mode %d", mode);
711 return HWC2::Error::BadParameter;
712 }
713
714 trigger_mode = static_cast<FrameTriggerMode>(mode);
715 error = display_intf_->SetFrameTriggerMode(trigger_mode);
716 if (error)
717 return HWC2::Error::BadConfig;
718
719 callbacks_->Refresh(HWC_DISPLAY_PRIMARY);
720 validated_ = false;
721
722 return HWC2::Error::None;
723}
724
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +0530725int HWCDisplayBuiltIn::Perform(uint32_t operation, ...) {
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500726 va_list args;
727 va_start(args, operation);
Arun Kumar K.R536c7d62016-06-14 18:47:39 -0700728 int val = 0;
Gopikrishnaiah Anandancc123062017-07-31 17:21:03 -0700729 LayerSolidFill *solid_fill_color;
Arun Kumar K.R536c7d62016-06-14 18:47:39 -0700730 LayerRect *rect = NULL;
731
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500732 switch (operation) {
733 case SET_METADATA_DYN_REFRESH_RATE:
Arun Kumar K.R536c7d62016-06-14 18:47:39 -0700734 val = va_arg(args, int32_t);
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500735 SetMetaDataRefreshRateFlag(val);
736 break;
737 case SET_BINDER_DYN_REFRESH_RATE:
Arun Kumar K.R536c7d62016-06-14 18:47:39 -0700738 val = va_arg(args, int32_t);
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500739 ForceRefreshRate(UINT32(val));
740 break;
741 case SET_DISPLAY_MODE:
Arun Kumar K.R536c7d62016-06-14 18:47:39 -0700742 val = va_arg(args, int32_t);
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500743 SetDisplayMode(UINT32(val));
744 break;
745 case SET_QDCM_SOLID_FILL_INFO:
Gopikrishnaiah Anandancc123062017-07-31 17:21:03 -0700746 solid_fill_color = va_arg(args, LayerSolidFill*);
747 SetQDCMSolidFillInfo(true, *solid_fill_color);
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500748 break;
749 case UNSET_QDCM_SOLID_FILL_INFO:
Gopikrishnaiah Anandancc123062017-07-31 17:21:03 -0700750 solid_fill_color = va_arg(args, LayerSolidFill*);
751 SetQDCMSolidFillInfo(false, *solid_fill_color);
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500752 break;
Arun Kumar K.R536c7d62016-06-14 18:47:39 -0700753 case SET_QDCM_SOLID_FILL_RECT:
754 rect = va_arg(args, LayerRect*);
755 solid_fill_rect_ = *rect;
756 break;
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500757 default:
758 DLOGW("Invalid operation %d", operation);
Arun Kumar K.R536c7d62016-06-14 18:47:39 -0700759 va_end(args);
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500760 return -EINVAL;
761 }
Arun Kumar K.R536c7d62016-06-14 18:47:39 -0700762 va_end(args);
Saurabh Shaha307e8c2017-09-28 18:05:40 -0700763 validated_ = false;
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500764
765 return 0;
766}
767
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +0530768DisplayError HWCDisplayBuiltIn::SetDisplayMode(uint32_t mode) {
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500769 DisplayError error = kErrorNone;
770
771 if (display_intf_) {
772 error = display_intf_->SetDisplayMode(mode);
Tharaga Balachandran04192a62018-08-29 16:23:25 -0400773 if (error == kErrorNone) {
774 DisplayConfigFixedInfo fixed_info = {};
775 display_intf_->GetConfig(&fixed_info);
776 is_cmd_mode_ = fixed_info.is_cmdmode;
777 partial_update_enabled_ = fixed_info.partial_update;
778 for (auto hwc_layer : layer_set_) {
779 hwc_layer->SetPartialUpdate(partial_update_enabled_);
780 }
781 client_target_->SetPartialUpdate(partial_update_enabled_);
782 }
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500783 }
784
785 return error;
786}
787
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +0530788void HWCDisplayBuiltIn::SetMetaDataRefreshRateFlag(bool enable) {
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500789 int disable_metadata_dynfps = 0;
790
Uday Kiran Pichika5e656b22018-05-15 18:48:24 +0530791 HWCDebugHandler::Get()->GetProperty(DISABLE_METADATA_DYNAMIC_FPS_PROP, &disable_metadata_dynfps);
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500792 if (disable_metadata_dynfps) {
793 return;
794 }
795 use_metadata_refresh_rate_ = enable;
796}
797
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +0530798void HWCDisplayBuiltIn::SetQDCMSolidFillInfo(bool enable, const LayerSolidFill &color) {
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500799 solid_fill_enable_ = enable;
800 solid_fill_color_ = color;
801}
802
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +0530803void HWCDisplayBuiltIn::ToggleCPUHint(bool set) {
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500804 if (!cpu_hint_) {
805 return;
806 }
807
808 if (set) {
809 cpu_hint_->Set();
810 } else {
811 cpu_hint_->Reset();
812 }
813}
814
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +0530815int HWCDisplayBuiltIn::HandleSecureSession(const std::bitset<kSecureMax> &secure_sessions,
Ramkumar Radhakrishnana38b7602018-03-15 14:49:52 -0700816 bool *power_on_pending) {
817 if (!power_on_pending) {
818 return -EINVAL;
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500819 }
Ramkumar Radhakrishnana38b7602018-03-15 14:49:52 -0700820
Mathew Joseph Karimpanalb1c15862019-07-04 11:14:24 +0530821 if (!is_primary_) {
822 return HWCDisplay::HandleSecureSession(secure_sessions, power_on_pending);
823 }
824
Ramkumar Radhakrishnan44c64362018-12-12 13:03:59 -0800825 if (current_power_mode_ != HWC2::PowerMode::On) {
826 return 0;
827 }
828
Ramkumar Radhakrishnana38b7602018-03-15 14:49:52 -0700829 if (active_secure_sessions_[kSecureDisplay] != secure_sessions[kSecureDisplay]) {
830 SecureEvent secure_event =
831 secure_sessions.test(kSecureDisplay) ? kSecureDisplayStart : kSecureDisplayEnd;
Pullakavi Srinivas0a1dba62018-07-02 15:49:11 +0530832 DisplayError err = display_intf_->HandleSecureEvent(secure_event, &layer_stack_);
Ramkumar Radhakrishnana38b7602018-03-15 14:49:52 -0700833 if (err != kErrorNone) {
834 DLOGE("Set secure event failed");
835 return err;
836 }
837
Pullakavi Srinivasce3692b2020-02-13 01:14:09 +0530838 DLOGI("SecureDisplay state changed from %d to %d for display %" PRIu64 "-%d",
Ramkumar Radhakrishnana38b7602018-03-15 14:49:52 -0700839 active_secure_sessions_.test(kSecureDisplay), secure_sessions.test(kSecureDisplay),
Mathew Joseph Karimpanalb1c15862019-07-04 11:14:24 +0530840 id_, type_);
Ramkumar Radhakrishnana38b7602018-03-15 14:49:52 -0700841 }
842 active_secure_sessions_ = secure_sessions;
843 *power_on_pending = false;
844 return 0;
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500845}
846
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +0530847void HWCDisplayBuiltIn::ForceRefreshRate(uint32_t refresh_rate) {
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500848 if ((refresh_rate && (refresh_rate < min_refresh_rate_ || refresh_rate > max_refresh_rate_)) ||
849 force_refresh_rate_ == refresh_rate) {
850 // Cannot honor force refresh rate, as its beyond the range or new request is same
851 return;
852 }
853
854 force_refresh_rate_ = refresh_rate;
855
Ramkumar Radhakrishnan44c64362018-12-12 13:03:59 -0800856 callbacks_->Refresh(id_);
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500857
858 return;
859}
860
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +0530861uint32_t HWCDisplayBuiltIn::GetOptimalRefreshRate(bool one_updating_layer) {
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500862 if (force_refresh_rate_) {
863 return force_refresh_rate_;
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500864 } else if (use_metadata_refresh_rate_ && one_updating_layer && metadata_refresh_rate_) {
865 return metadata_refresh_rate_;
866 }
867
Venkat Thogaru0fafc8f2020-04-22 19:49:27 +0530868 DLOGV_IF(kTagClient, "active_refresh_rate_: %d", active_refresh_rate_);
Pullakavi Srinivas7bdcc762020-03-06 12:41:36 +0530869 return active_refresh_rate_;
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500870}
871
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +0530872void HWCDisplayBuiltIn::SetIdleTimeoutMs(uint32_t timeout_ms) {
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500873 display_intf_->SetIdleTimeoutMs(timeout_ms);
Saurabh Shaha307e8c2017-09-28 18:05:40 -0700874 validated_ = false;
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500875}
876
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +0530877void HWCDisplayBuiltIn::HandleFrameOutput() {
Sushil Chauhan06521582018-03-19 14:00:23 -0700878 if (readback_buffer_queued_) {
879 validated_ = false;
880 }
881
Sushil Chauhan1d3b90c2018-12-11 16:52:35 -0800882 if (frame_capture_buffer_queued_) {
883 HandleFrameCapture();
884 } else if (dump_output_to_file_) {
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500885 HandleFrameDump();
886 }
887}
888
Sushil Chauhan1d3b90c2018-12-11 16:52:35 -0800889void HWCDisplayBuiltIn::HandleFrameCapture() {
Rajavenu Kyatham7338b9e2019-12-30 19:52:16 +0530890 if (readback_configured_ && output_buffer_.release_fence) {
891 frame_capture_status_ = Fence::Wait(output_buffer_.release_fence);
Sushil Chauhan1d3b90c2018-12-11 16:52:35 -0800892 }
893
894 frame_capture_buffer_queued_ = false;
895 readback_buffer_queued_ = false;
896 post_processed_output_ = false;
897 readback_configured_ = false;
898 output_buffer_ = {};
Dileep Marchyacb2a3a92019-06-21 17:30:50 +0530899 cwb_client_ = kCWBClientNone;
Sushil Chauhan1d3b90c2018-12-11 16:52:35 -0800900}
901
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +0530902void HWCDisplayBuiltIn::HandleFrameDump() {
Ramkumar Radhakrishnan68331fc2019-06-19 11:24:12 -0700903 if (dump_frame_count_) {
904 int ret = 0;
Rajavenu Kyatham7338b9e2019-12-30 19:52:16 +0530905 ret = Fence::Wait(output_buffer_.release_fence);
906 if (ret != kErrorNone) {
907 DLOGE("sync_wait error errno = %d, desc = %s", errno, strerror(errno));
Ramkumar Radhakrishnan68331fc2019-06-19 11:24:12 -0700908 }
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500909
Ramkumar Radhakrishnan68331fc2019-06-19 11:24:12 -0700910 if (!ret) {
Dileep Marchyaad668432019-12-02 10:44:52 +0530911 DumpOutputBuffer(output_buffer_info_, output_buffer_base_, layer_stack_.retire_fence);
912 validated_ = false;
913 }
Ramkumar Radhakrishnan68331fc2019-06-19 11:24:12 -0700914
915 if (0 == (dump_frame_count_ - 1)) {
916 dump_output_to_file_ = false;
917 // Unmap and Free buffer
918 if (munmap(output_buffer_base_, output_buffer_info_.alloc_buffer_info.size) != 0) {
919 DLOGE("unmap failed with err %d", errno);
920 }
921 if (buffer_allocator_->FreeBuffer(&output_buffer_info_) != 0) {
922 DLOGE("FreeBuffer failed");
923 }
924
Sushil Chauhan06521582018-03-19 14:00:23 -0700925 readback_buffer_queued_ = false;
Ramkumar Radhakrishnan68331fc2019-06-19 11:24:12 -0700926 post_processed_output_ = false;
927 readback_configured_ = false;
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500928
Ramkumar Radhakrishnan68331fc2019-06-19 11:24:12 -0700929 output_buffer_ = {};
930 output_buffer_info_ = {};
931 output_buffer_base_ = nullptr;
Dileep Marchyacb2a3a92019-06-21 17:30:50 +0530932 cwb_client_ = kCWBClientNone;
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500933 }
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500934 }
935}
936
Sushil Chauhan267a6192018-06-06 18:41:47 -0700937HWC2::Error HWCDisplayBuiltIn::SetFrameDumpConfig(uint32_t count, uint32_t bit_mask_layer_type,
938 int32_t format, bool post_processed) {
939 HWCDisplay::SetFrameDumpConfig(count, bit_mask_layer_type, format, post_processed);
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500940 dump_output_to_file_ = bit_mask_layer_type & (1 << OUTPUT_LAYER_DUMP);
941 DLOGI("output_layer_dump_enable %d", dump_output_to_file_);
942
Dileep Marchyacb2a3a92019-06-21 17:30:50 +0530943 if (dump_output_to_file_) {
944 if (cwb_client_ != kCWBClientNone) {
Ramakant Singh2d617ae2020-05-12 23:41:37 +0530945 DLOGW("CWB is in use with client = %d", cwb_client_);
Dileep Marchyacb2a3a92019-06-21 17:30:50 +0530946 return HWC2::Error::NoResources;
947 }
948 }
949
Sushil Chauhand0dc03d2018-09-19 07:08:40 -0700950 if (!count || !dump_output_to_file_ || (output_buffer_info_.alloc_buffer_info.fd >= 0)) {
Mathew Joseph Karimpanaldbd64f82017-10-06 10:13:38 +0530951 return HWC2::Error::None;
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500952 }
953
954 // Allocate and map output buffer
Sushil Chauhan267a6192018-06-06 18:41:47 -0700955 if (post_processed) {
956 // To dump post-processed (DSPP) output, use Panel resolution.
957 GetPanelResolution(&output_buffer_info_.buffer_config.width,
958 &output_buffer_info_.buffer_config.height);
959 } else {
960 // To dump Layer Mixer output, use FrameBuffer resolution.
961 GetFrameBufferResolution(&output_buffer_info_.buffer_config.width,
962 &output_buffer_info_.buffer_config.height);
963 }
964
965 output_buffer_info_.buffer_config.format = HWCLayer::GetSDMFormat(format, 0);
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500966 output_buffer_info_.buffer_config.buffer_count = 1;
967 if (buffer_allocator_->AllocateBuffer(&output_buffer_info_) != 0) {
968 DLOGE("Buffer allocation failed");
969 output_buffer_info_ = {};
Mathew Joseph Karimpanaldbd64f82017-10-06 10:13:38 +0530970 return HWC2::Error::NoResources;
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500971 }
972
973 void *buffer = mmap(NULL, output_buffer_info_.alloc_buffer_info.size, PROT_READ | PROT_WRITE,
974 MAP_SHARED, output_buffer_info_.alloc_buffer_info.fd, 0);
975
976 if (buffer == MAP_FAILED) {
977 DLOGE("mmap failed with err %d", errno);
978 buffer_allocator_->FreeBuffer(&output_buffer_info_);
979 output_buffer_info_ = {};
Mathew Joseph Karimpanaldbd64f82017-10-06 10:13:38 +0530980 return HWC2::Error::NoResources;
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500981 }
982
983 output_buffer_base_ = buffer;
Sushil Chauhan06521582018-03-19 14:00:23 -0700984 const native_handle_t *handle = static_cast<native_handle_t *>(output_buffer_info_.private_data);
Rajavenu Kyatham7338b9e2019-12-30 19:52:16 +0530985 SetReadbackBuffer(handle, nullptr, post_processed, kCWBClientFrameDump);
Sushil Chauhan06521582018-03-19 14:00:23 -0700986
Mathew Joseph Karimpanaldbd64f82017-10-06 10:13:38 +0530987 return HWC2::Error::None;
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500988}
989
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +0530990int HWCDisplayBuiltIn::FrameCaptureAsync(const BufferInfo &output_buffer_info,
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500991 bool post_processed_output) {
Dileep Marchyacb2a3a92019-06-21 17:30:50 +0530992 if (cwb_client_ != kCWBClientNone) {
993 DLOGE("CWB is in use with client = %d", cwb_client_);
994 return -1;
995 }
996
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500997 // Note: This function is called in context of a binder thread and a lock is already held
998 if (output_buffer_info.alloc_buffer_info.fd < 0) {
999 DLOGE("Invalid fd %d", output_buffer_info.alloc_buffer_info.fd);
1000 return -1;
1001 }
1002
1003 auto panel_width = 0u;
1004 auto panel_height = 0u;
1005 auto fb_width = 0u;
1006 auto fb_height = 0u;
1007
1008 GetPanelResolution(&panel_width, &panel_height);
1009 GetFrameBufferResolution(&fb_width, &fb_height);
1010
Ch Ganesh Kumar5c4988b2017-06-07 15:21:02 +05301011 if (post_processed_output && (output_buffer_info.buffer_config.width < panel_width ||
1012 output_buffer_info.buffer_config.height < panel_height)) {
Naseer Ahmedb92e73f2016-03-12 02:03:48 -05001013 DLOGE("Buffer dimensions should not be less than panel resolution");
1014 return -1;
Ch Ganesh Kumar5c4988b2017-06-07 15:21:02 +05301015 } else if (!post_processed_output && (output_buffer_info.buffer_config.width < fb_width ||
1016 output_buffer_info.buffer_config.height < fb_height)) {
Naseer Ahmedb92e73f2016-03-12 02:03:48 -05001017 DLOGE("Buffer dimensions should not be less than FB resolution");
1018 return -1;
1019 }
1020
Sushil Chauhan06521582018-03-19 14:00:23 -07001021 const native_handle_t *buffer = static_cast<native_handle_t *>(output_buffer_info.private_data);
Rajavenu Kyatham7338b9e2019-12-30 19:52:16 +05301022 SetReadbackBuffer(buffer, nullptr, post_processed_output, kCWBClientColor);
Sushil Chauhan1d3b90c2018-12-11 16:52:35 -08001023 frame_capture_buffer_queued_ = true;
1024 frame_capture_status_ = -EAGAIN;
Naseer Ahmedb92e73f2016-03-12 02:03:48 -05001025
1026 return 0;
1027}
1028
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +05301029DisplayError HWCDisplayBuiltIn::SetDetailEnhancerConfig
Alan Kwong2e136332016-08-16 07:50:16 -04001030 (const DisplayDetailEnhancerData &de_data) {
1031 DisplayError error = kErrorNotSupported;
1032
1033 if (display_intf_) {
1034 error = display_intf_->SetDetailEnhancerData(de_data);
Saurabh Shaha307e8c2017-09-28 18:05:40 -07001035 validated_ = false;
Alan Kwong2e136332016-08-16 07:50:16 -04001036 }
1037 return error;
1038}
1039
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +05301040DisplayError HWCDisplayBuiltIn::ControlPartialUpdate(bool enable, uint32_t *pending) {
Arun Kumar K.R17bbd042016-06-07 17:38:02 -07001041 DisplayError error = kErrorNone;
1042
1043 if (display_intf_) {
1044 error = display_intf_->ControlPartialUpdate(enable, pending);
Saurabh Shaha307e8c2017-09-28 18:05:40 -07001045 validated_ = false;
Arun Kumar K.R17bbd042016-06-07 17:38:02 -07001046 }
1047
1048 return error;
1049}
1050
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +05301051DisplayError HWCDisplayBuiltIn::DisablePartialUpdateOneFrame() {
Arun Kumar K.R17bbd042016-06-07 17:38:02 -07001052 DisplayError error = kErrorNone;
1053
1054 if (display_intf_) {
1055 error = display_intf_->DisablePartialUpdateOneFrame();
Saurabh Shaha307e8c2017-09-28 18:05:40 -07001056 validated_ = false;
Arun Kumar K.R17bbd042016-06-07 17:38:02 -07001057 }
1058
1059 return error;
1060}
1061
Lakshmi Narayana Kalavala25fe12c2019-12-11 20:44:55 -08001062HWC2::Error HWCDisplayBuiltIn::SetDisplayedContentSamplingEnabledVndService(bool enabled) {
1063 std::unique_lock<decltype(sampling_mutex)> lk(sampling_mutex);
1064 vndservice_sampling_vote = enabled;
1065 if (api_sampling_vote || vndservice_sampling_vote) {
1066 histogram.start();
Lakshmi Narayana Kalavalaf30c2292019-09-26 15:26:24 -07001067 display_intf_->colorSamplingOn();
Lakshmi Narayana Kalavala25fe12c2019-12-11 20:44:55 -08001068 } else {
Lakshmi Narayana Kalavalaf30c2292019-09-26 15:26:24 -07001069 display_intf_->colorSamplingOff();
Lakshmi Narayana Kalavala25fe12c2019-12-11 20:44:55 -08001070 histogram.stop();
1071 }
1072 return HWC2::Error::None;
1073}
1074
1075HWC2::Error HWCDisplayBuiltIn::SetDisplayedContentSamplingEnabled(int32_t enabled,
1076 uint8_t component_mask,
1077 uint64_t max_frames) {
1078 if ((enabled != HWC2_DISPLAYED_CONTENT_SAMPLING_ENABLE) &&
1079 (enabled != HWC2_DISPLAYED_CONTENT_SAMPLING_DISABLE))
1080 return HWC2::Error::BadParameter;
1081
1082 std::unique_lock<decltype(sampling_mutex)> lk(sampling_mutex);
1083 if (enabled == HWC2_DISPLAYED_CONTENT_SAMPLING_ENABLE) {
1084 api_sampling_vote = true;
1085 } else {
1086 api_sampling_vote = false;
1087 }
1088
1089 auto start = api_sampling_vote || vndservice_sampling_vote;
1090 if (start && max_frames == 0) {
1091 histogram.start();
Lakshmi Narayana Kalavalaf30c2292019-09-26 15:26:24 -07001092 display_intf_->colorSamplingOn();
Lakshmi Narayana Kalavala25fe12c2019-12-11 20:44:55 -08001093 } else if (start) {
1094 histogram.start(max_frames);
Lakshmi Narayana Kalavalaf30c2292019-09-26 15:26:24 -07001095 display_intf_->colorSamplingOn();
Lakshmi Narayana Kalavala25fe12c2019-12-11 20:44:55 -08001096 } else {
Lakshmi Narayana Kalavalaf30c2292019-09-26 15:26:24 -07001097 display_intf_->colorSamplingOff();
Lakshmi Narayana Kalavala25fe12c2019-12-11 20:44:55 -08001098 histogram.stop();
1099 }
1100 return HWC2::Error::None;
1101}
1102
1103HWC2::Error HWCDisplayBuiltIn::GetDisplayedContentSamplingAttributes(
1104 int32_t *format, int32_t *dataspace, uint8_t *supported_components) {
1105 return histogram.getAttributes(format, dataspace, supported_components);
1106}
1107
1108HWC2::Error HWCDisplayBuiltIn::GetDisplayedContentSample(
1109 uint64_t max_frames, uint64_t timestamp, uint64_t *numFrames,
1110 int32_t samples_size[NUM_HISTOGRAM_COLOR_COMPONENTS],
1111 uint64_t *samples[NUM_HISTOGRAM_COLOR_COMPONENTS]) {
1112 histogram.collect(max_frames, timestamp, samples_size, samples, numFrames);
1113 return HWC2::Error::None;
1114}
Arun Kumar K.R17bbd042016-06-07 17:38:02 -07001115
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +05301116DisplayError HWCDisplayBuiltIn::SetMixerResolution(uint32_t width, uint32_t height) {
Sushil Chauhan409e8442017-06-12 17:43:25 -07001117 DisplayError error = display_intf_->SetMixerResolution(width, height);
Ramkumar Radhakrishnanf7f52162019-06-06 19:40:04 -07001118 callbacks_->Refresh(id_);
Saurabh Shaha307e8c2017-09-28 18:05:40 -07001119 validated_ = false;
Sushil Chauhan409e8442017-06-12 17:43:25 -07001120 return error;
Arun Kumar K.R8da7f502016-06-07 17:45:50 -07001121}
1122
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +05301123DisplayError HWCDisplayBuiltIn::GetMixerResolution(uint32_t *width, uint32_t *height) {
Arun Kumar K.R8da7f502016-06-07 17:45:50 -07001124 return display_intf_->GetMixerResolution(width, height);
1125}
1126
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +05301127HWC2::Error HWCDisplayBuiltIn::SetQSyncMode(QSyncMode qsync_mode) {
Pullakavi Srinivas24574142019-08-14 12:18:12 +05301128 // Client needs to ensure that config change and qsync mode change
1129 // are not triggered in the same drawcycle.
1130 if (pending_config_) {
1131 DLOGE("Failed to set qsync mode. Pending active config transition");
1132 return HWC2::Error::Unsupported;
1133 }
1134
Sushil Chauhan380a59d2018-03-19 15:47:50 -07001135 auto err = display_intf_->SetQSyncMode(qsync_mode);
1136 if (err != kErrorNone) {
1137 return HWC2::Error::Unsupported;
1138 }
1139
Sushil Chauhanec4eb572019-02-07 13:29:42 -08001140 validated_ = false;
Sushil Chauhan380a59d2018-03-19 15:47:50 -07001141 return HWC2::Error::None;
1142}
1143
Ramkumar Radhakrishnan4faf8a62018-11-15 17:15:37 -08001144DisplayError HWCDisplayBuiltIn::ControlIdlePowerCollapse(bool enable, bool synchronous) {
Ramkumar Radhakrishnanf985d482018-07-23 18:10:41 -07001145 DisplayError error = kErrorNone;
1146
1147 if (display_intf_) {
1148 error = display_intf_->ControlIdlePowerCollapse(enable, synchronous);
1149 validated_ = false;
1150 }
Ramkumar Radhakrishnan4faf8a62018-11-15 17:15:37 -08001151 return error;
Ramkumar Radhakrishnanf985d482018-07-23 18:10:41 -07001152}
1153
Pullakavi Srinivas9189e602018-12-19 16:58:07 +05301154DisplayError HWCDisplayBuiltIn::SetDynamicDSIClock(uint64_t bitclk) {
Dileep Marchyaafa45bc2019-06-21 17:05:31 +05301155 DisablePartialUpdateOneFrame();
1156 DisplayError error = display_intf_->SetDynamicDSIClock(bitclk);
1157 if (error != kErrorNone) {
Pullakavi Srinivasce3692b2020-02-13 01:14:09 +05301158 DLOGE(" failed: Clk: %" PRIu64 " Error: %d", bitclk, error);
Dileep Marchyaafa45bc2019-06-21 17:05:31 +05301159 return error;
Pullakavi Srinivas9189e602018-12-19 16:58:07 +05301160 }
1161
1162 callbacks_->Refresh(id_);
1163 validated_ = false;
1164
1165 return kErrorNone;
1166}
1167
1168DisplayError HWCDisplayBuiltIn::GetDynamicDSIClock(uint64_t *bitclk) {
Pullakavi Srinivas9189e602018-12-19 16:58:07 +05301169 if (display_intf_) {
1170 return display_intf_->GetDynamicDSIClock(bitclk);
1171 }
1172
1173 return kErrorNotSupported;
1174}
1175
1176DisplayError HWCDisplayBuiltIn::GetSupportedDSIClock(std::vector<uint64_t> *bitclk_rates) {
1177 if (display_intf_) {
1178 return display_intf_->GetSupportedDSIClock(bitclk_rates);
1179 }
1180
1181 return kErrorNotSupported;
1182}
1183
Padmanabhan Komandurue74cf4f2019-04-25 17:38:43 -07001184HWC2::Error HWCDisplayBuiltIn::UpdateDisplayId(hwc2_display_t id) {
1185 id_ = id;
1186 return HWC2::Error::None;
1187}
1188
1189HWC2::Error HWCDisplayBuiltIn::SetPendingRefresh() {
1190 pending_refresh_ = true;
1191 return HWC2::Error::None;
1192}
1193
Varun Arora75c05f02019-05-14 14:53:37 -07001194HWC2::Error HWCDisplayBuiltIn::SetPanelBrightness(float brightness) {
1195 DisplayError ret = display_intf_->SetPanelBrightness(brightness);
1196 if (ret != kErrorNone) {
1197 return HWC2::Error::NoResources;
1198 }
1199
1200 return HWC2::Error::None;
1201}
1202
1203HWC2::Error HWCDisplayBuiltIn::GetPanelBrightness(float *brightness) {
1204 DisplayError ret = display_intf_->GetPanelBrightness(brightness);
1205 if (ret != kErrorNone) {
1206 return HWC2::Error::NoResources;
1207 }
1208
1209 return HWC2::Error::None;
1210}
Xu Yang45d0abf2019-07-05 11:34:06 +08001211
Yuchao Maada1c402019-11-12 14:47:11 +08001212HWC2::Error HWCDisplayBuiltIn::GetPanelMaxBrightness(uint32_t *max_brightness_level) {
1213 DisplayError ret = display_intf_->GetPanelMaxBrightness(max_brightness_level);
1214 if (ret != kErrorNone) {
1215 return HWC2::Error::NoResources;
1216 }
1217
1218 return HWC2::Error::None;
1219}
1220
Xu Yang45d0abf2019-07-05 11:34:06 +08001221HWC2::Error HWCDisplayBuiltIn::SetBLScale(uint32_t level) {
1222 DisplayError ret = display_intf_->SetBLScale(level);
1223 if (ret != kErrorNone) {
1224 return HWC2::Error::NoResources;
1225 }
Srinivas Pullakavi3c4337f2019-07-03 11:24:31 +05301226 return HWC2::Error::None;
1227}
Xu Yang45d0abf2019-07-05 11:34:06 +08001228
Srinivas Pullakavi3c4337f2019-07-03 11:24:31 +05301229HWC2::Error HWCDisplayBuiltIn::UpdatePowerMode(HWC2::PowerMode mode) {
1230 current_power_mode_ = mode;
1231 validated_ = false;
Xu Yang45d0abf2019-07-05 11:34:06 +08001232 return HWC2::Error::None;
1233}
1234
Rajavenu Kyatham7338b9e2019-12-30 19:52:16 +05301235HWC2::Error HWCDisplayBuiltIn::SetClientTarget(buffer_handle_t target,
1236 shared_ptr<Fence> acquire_fence,
Padmanabhan Komanduru9a91e9f2019-09-12 12:33:19 +05301237 int32_t dataspace, hwc_region_t damage) {
1238 HWC2::Error error = HWCDisplay::SetClientTarget(target, acquire_fence, dataspace, damage);
1239 if (error != HWC2::Error::None) {
1240 return error;
1241 }
1242
Pullakavi Srinivasd32b4922020-02-10 10:08:31 +05301243 // windowed_display and dynamic scaling are not supported.
1244 if (windowed_display_) {
1245 return HWC2::Error::None;
1246 }
1247
Padmanabhan Komanduru9a91e9f2019-09-12 12:33:19 +05301248 Layer *sdm_layer = client_target_->GetSDMLayer();
Padmanabhan Komandurua4bf6062019-10-13 09:04:49 +05301249 uint32_t fb_width = 0, fb_height = 0;
1250
1251 GetFrameBufferResolution(&fb_width, &fb_height);
1252
1253 if (fb_width != sdm_layer->input_buffer.unaligned_width ||
1254 fb_height != sdm_layer->input_buffer.unaligned_height) {
1255 if (SetFrameBufferConfig(sdm_layer->input_buffer.unaligned_width,
1256 sdm_layer->input_buffer.unaligned_height)) {
1257 return HWC2::Error::BadParameter;
1258 }
1259 }
Padmanabhan Komanduru9a91e9f2019-09-12 12:33:19 +05301260
1261 return HWC2::Error::None;
1262}
Sushil Chauhan1566a132019-10-02 11:59:28 -07001263
1264bool HWCDisplayBuiltIn::IsSmartPanelConfig(uint32_t config_id) {
1265 if (config_id < hwc_config_map_.size()) {
1266 uint32_t index = hwc_config_map_.at(config_id);
1267 return variable_config_map_.at(index).smart_panel;
1268 }
1269
1270 return false;
1271}
1272
Padmanabhan Komandurue6087e42020-04-10 10:22:57 +05301273bool HWCDisplayBuiltIn::HasSmartPanelConfig(void) {
Padmanabhan Komandurufa213652020-04-24 15:38:15 +05301274 if (!enable_poms_during_doze_) {
1275 uint32_t config = 0;
1276 GetActiveDisplayConfig(&config);
1277 return IsSmartPanelConfig(config);
1278 }
1279
Padmanabhan Komandurue6087e42020-04-10 10:22:57 +05301280 for (auto &config : variable_config_map_) {
1281 if (config.second.smart_panel) {
1282 return true;
1283 }
1284 }
1285
1286 return false;
1287}
1288
Pullakavi Srinivas1ae4acb2019-11-18 19:33:45 +05301289int HWCDisplayBuiltIn::Deinit() {
1290 // Destory color convert instance. This destroys thread and underlying GL resources.
1291 if (gl_layer_stitch_) {
1292 layer_stitch_task_.PerformTask(LayerStitchTaskCode::kCodeDestroyInstance, nullptr);
1293 }
1294
Lakshmi Narayana Kalavala25fe12c2019-12-11 20:44:55 -08001295 histogram.stop();
Pullakavi Srinivas1ae4acb2019-11-18 19:33:45 +05301296 return HWCDisplay::Deinit();
1297}
1298
1299void HWCDisplayBuiltIn::OnTask(const LayerStitchTaskCode &task_code,
1300 SyncTask<LayerStitchTaskCode>::TaskContext *task_context) {
1301 switch (task_code) {
1302 case LayerStitchTaskCode::kCodeGetInstance: {
1303 gl_layer_stitch_ = GLLayerStitch::GetInstance(false /* Non-secure */);
1304 }
1305 break;
1306 case LayerStitchTaskCode::kCodeStitch: {
1307 DTRACE_SCOPED();
Pullakavi Srinivasdb2b84a2019-11-21 14:47:35 +05301308 LayerStitchContext* ctx = reinterpret_cast<LayerStitchContext*>(task_context);
Pullakavi Srinivas1ae4acb2019-11-18 19:33:45 +05301309 gl_layer_stitch_->Blit(ctx->src_hnd, ctx->dst_hnd, ctx->src_rect, ctx->dst_rect,
Pullakavi Srinivasf25bc4a2020-02-27 12:07:39 +05301310 ctx->scissor_rect, ctx->src_acquire_fence,
1311 ctx->dst_acquire_fence, &(ctx->release_fence));
Pullakavi Srinivas1ae4acb2019-11-18 19:33:45 +05301312 }
1313 break;
1314 case LayerStitchTaskCode::kCodeDestroyInstance: {
1315 if (gl_layer_stitch_) {
1316 GLLayerStitch::Destroy(gl_layer_stitch_);
1317 }
1318 }
1319 break;
1320 }
1321}
1322
1323bool HWCDisplayBuiltIn::InitLayerStitch() {
1324 if (!is_primary_) {
1325 // Disable on all non-primary builtins.
1326 DLOGI("Non-primary builtin.");
Pullakavi Srinivas94793b42019-11-27 20:03:50 +05301327 disable_layer_stitch_ = true;
Pullakavi Srinivas1ae4acb2019-11-18 19:33:45 +05301328 return true;
1329 }
1330
1331 // Disable by default.
1332 int value = 1;
1333 Debug::Get()->GetProperty(DISABLE_LAYER_STITCH, &value);
1334 disable_layer_stitch_ = (value == 1);
1335
1336 if (disable_layer_stitch_) {
1337 DLOGI("Layer Stitch Disabled !!!");
1338 return true;
1339 }
1340
1341 // Initialize stitch context. This will be non-secure.
1342 layer_stitch_task_.PerformTask(LayerStitchTaskCode::kCodeGetInstance, nullptr);
1343 if (gl_layer_stitch_ == nullptr) {
1344 DLOGE("Failed to get LayerStitch Instance");
1345 return false;
1346 }
1347
1348 if (!AllocateStitchBuffer()) {
1349 return true;
1350 }
1351
1352 stitch_target_ = new HWCLayer(id_, static_cast<HWCBufferAllocator *>(buffer_allocator_));
1353
1354 // Populate buffer params and pvt handle.
1355 InitStitchTarget();
1356
1357 DLOGI("Created LayerStitch instance: %p", gl_layer_stitch_);
1358
1359 return true;
1360}
1361
1362bool HWCDisplayBuiltIn::AllocateStitchBuffer() {
1363 // Buffer dimensions: FB width * (1.5 * height)
1364
1365 DisplayError error = display_intf_->GetFrameBufferConfig(&fb_config_);
1366 if (error != kErrorNone) {
1367 DLOGE("Get frame buffer config failed. Error = %d", error);
1368 return false;
1369 }
1370
1371 BufferConfig &config = buffer_info_.buffer_config;
1372 config.width = fb_config_.x_pixels;
1373 config.height = fb_config_.y_pixels * kBufferHeightFactor;
1374
1375 // By default UBWC is enabled and below property is global enable/disable for all
1376 // buffers allocated through gralloc , including framebuffer targets.
1377 int ubwc_disabled = 0;
1378 HWCDebugHandler::Get()->GetProperty(DISABLE_UBWC_PROP, &ubwc_disabled);
1379 config.format = ubwc_disabled ? kFormatRGBA8888 : kFormatRGBA8888Ubwc;
1380
1381 config.gfx_client = true;
1382
1383 // Populate default params.
1384 config.secure = false;
1385 config.cache = false;
1386 config.secure_camera = false;
1387
1388 error = buffer_allocator_->AllocateBuffer(&buffer_info_);
1389
1390 if (error != kErrorNone) {
1391 DLOGE("Failed to allocate buffer. Error: %d", error);
1392 return false;
1393 }
1394
1395 return true;
1396}
1397
1398void HWCDisplayBuiltIn::InitStitchTarget() {
1399 LayerBuffer buffer = {};
1400 buffer.planes[0].fd = buffer_info_.alloc_buffer_info.fd;
1401 buffer.planes[0].offset = 0;
1402 buffer.planes[0].stride = buffer_info_.alloc_buffer_info.stride;
1403 buffer.size = buffer_info_.alloc_buffer_info.size;
1404 buffer.handle_id = buffer_info_.alloc_buffer_info.id;
1405 buffer.width = buffer_info_.alloc_buffer_info.aligned_width;
1406 buffer.height = buffer_info_.alloc_buffer_info.aligned_height;
1407 buffer.unaligned_width = fb_config_.x_pixels;
Pullakavi Srinivasdb2b84a2019-11-21 14:47:35 +05301408 buffer.unaligned_height = fb_config_.y_pixels * kBufferHeightFactor;
Pullakavi Srinivas1ae4acb2019-11-18 19:33:45 +05301409 buffer.format = buffer_info_.alloc_buffer_info.format;
1410
1411 Layer *sdm_stitch_target = stitch_target_->GetSDMLayer();
1412 sdm_stitch_target->composition = kCompositionStitchTarget;
1413 sdm_stitch_target->input_buffer = buffer;
1414 sdm_stitch_target->input_buffer.buffer_id = reinterpret_cast<uint64_t>(buffer_info_.private_data);
1415}
1416
1417void HWCDisplayBuiltIn::AppendStitchLayer() {
1418 if (disable_layer_stitch_) {
1419 return;
1420 }
1421
1422 // Append stitch target buffer to layer stack.
1423 Layer *sdm_stitch_target = stitch_target_->GetSDMLayer();
1424 sdm_stitch_target->composition = kCompositionStitchTarget;
Pullakavi Srinivasdb2b84a2019-11-21 14:47:35 +05301425 sdm_stitch_target->dst_rect = {0, 0, FLOAT(fb_config_.x_pixels), FLOAT(fb_config_.y_pixels)};
Pullakavi Srinivas1ae4acb2019-11-18 19:33:45 +05301426 layer_stack_.layers.push_back(sdm_stitch_target);
1427}
1428
Lakshmi Narayana Kalavalae0127eb2019-12-03 11:07:26 -08001429DisplayError HWCDisplayBuiltIn::HistogramEvent(int fd, uint32_t blob_id) {
1430 histogram.notify_histogram_event(fd, blob_id);
1431 return kErrorNone;
1432}
Pullakavi Srinivasdb2b84a2019-11-21 14:47:35 +05301433
1434int HWCDisplayBuiltIn::PostInit() {
1435 auto status = InitLayerStitch();
1436 if (!status) {
1437 DLOGW("Failed to initialize Layer Stitch context");
1438 // Disable layer stitch.
1439 disable_layer_stitch_ = true;
1440 }
1441
1442 return 0;
1443}
1444
Venkat Thogaru8e9b1242020-03-30 19:25:24 +05301445bool HWCDisplayBuiltIn::HasReadBackBufferSupport() {
1446 DisplayConfigFixedInfo fixed_info = {};
1447 display_intf_->GetConfig(&fixed_info);
1448
1449 return fixed_info.readback_supported;
1450}
1451
Naseer Ahmedb92e73f2016-03-12 02:03:48 -05001452} // namespace sdm