blob: bdeb4de4bcd5c3aa35d8c11e6ae07ae10d7e849c [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 Komanduru866bf6a2019-03-19 14:30:48 +0530130 int optimize_refresh = 0;
131 HWCDebugHandler::Get()->GetProperty(ENABLE_OPTIMIZE_REFRESH, &optimize_refresh);
132 enable_optimize_refresh_ = (optimize_refresh == 1);
133 if (enable_optimize_refresh_) {
Padmanabhan Komandurue74cf4f2019-04-25 17:38:43 -0700134 DLOGI("Drop redundant drawcycles %d", id_);
135 }
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
Naseer Ahmed61f60952017-05-24 16:48:35 -0400145 return status;
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500146}
147
Dileep Marchya58928122020-01-28 12:16:51 +0530148void HWCDisplayBuiltIn::Dump(std::ostringstream *os) {
149 HWCDisplay::Dump(os);
150 *os << histogram.Dump();
Lakshmi Narayana Kalavala25fe12c2019-12-11 20:44:55 -0800151}
152
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +0530153HWC2::Error HWCDisplayBuiltIn::Validate(uint32_t *out_num_types, uint32_t *out_num_requests) {
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500154 auto status = HWC2::Error::None;
155 DisplayError error = kErrorNone;
156
Gurpreet Singh Dhamia4276882019-04-12 10:30:58 -0700157 DTRACE_SCOPED();
158
Mathew Joseph Karimpanalb1c15862019-07-04 11:14:24 +0530159 if (display_paused_ || (!is_primary_ && active_secure_sessions_[kSecureDisplay])) {
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500160 MarkLayersForGPUBypass();
161 return status;
162 }
163
Arun Kumar K.R29cd6582016-05-10 19:12:45 -0700164 if (color_tranform_failed_) {
165 // Must fall back to client composition
166 MarkLayersForClientComposition();
167 }
168
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500169 // Fill in the remaining blanks in the layers and add them to the SDM layerstack
170 BuildLayerStack();
Pullakavi Srinivas1ae4acb2019-11-18 19:33:45 +0530171
172 // Add stitch layer to layer stack.
173 AppendStitchLayer();
174
Arun Kumar K.R536c7d62016-06-14 18:47:39 -0700175 // Checks and replaces layer stack for solid fill
176 SolidFillPrepare();
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500177
Sushil Chauhan8008d602018-09-04 14:43:27 -0700178 // Apply current Color Mode and Render Intent.
Xu Yang84e61412018-12-06 14:52:16 +0800179 if (color_mode_->ApplyCurrentColorModeWithRenderIntent(
180 static_cast<bool>(layer_stack_.flags.hdr_present)) != HWC2::Error::None) {
Sushil Chauhan8008d602018-09-04 14:43:27 -0700181 // Fallback to GPU Composition, if Color Mode can't be applied.
182 MarkLayersForClientComposition();
183 }
184
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500185 bool pending_output_dump = dump_frame_count_ && dump_output_to_file_;
186
Sushil Chauhan06521582018-03-19 14:00:23 -0700187 if (readback_buffer_queued_ || pending_output_dump) {
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500188 // RHS values were set in FrameCaptureAsync() called from a binder thread. They are picked up
Sushil Chauhan06521582018-03-19 14:00:23 -0700189 // here in a subsequent draw round. Readback is not allowed for any secure use case.
190 readback_configured_ = !layer_stack_.flags.secure_present;
191 if (readback_configured_) {
Sushil Chauhanf42d8622018-09-30 23:20:37 -0700192 DisablePartialUpdateOneFrame();
Sushil Chauhan06521582018-03-19 14:00:23 -0700193 layer_stack_.output_buffer = &output_buffer_;
194 layer_stack_.flags.post_processed_output = post_processed_output_;
195 }
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500196 }
197
Ramakant Singh5db0dfb2017-08-23 12:34:57 +0530198 uint32_t num_updating_layers = GetUpdatingLayersCount();
199 bool one_updating_layer = (num_updating_layers == 1);
200 if (num_updating_layers != 0) {
201 ToggleCPUHint(one_updating_layer);
202 }
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500203
204 uint32_t refresh_rate = GetOptimalRefreshRate(one_updating_layer);
Pullakavi Srinivas4619db92019-04-20 15:07:59 +0530205 error = display_intf_->SetRefreshRate(refresh_rate, force_refresh_rate_);
206
207 // Get the refresh rate set.
208 display_intf_->GetRefreshRate(&refresh_rate);
209 bool vsync_source = (callbacks_->GetVsyncSource() == id_);
210
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500211 if (error == kErrorNone) {
Pullakavi Srinivas4619db92019-04-20 15:07:59 +0530212 if (vsync_source && (current_refresh_rate_ < refresh_rate)) {
213 DTRACE_BEGIN("HWC2::Vsync::Enable");
214 // Display is ramping up from idle.
215 // Client realizes need for resync upon change in config.
216 // Since we know config has changed, triggering vsync proactively
217 // can help in reducing pipeline delays to enable events.
218 SetVsyncEnabled(HWC2::Vsync::Enable);
219 DTRACE_END();
220 }
221 // On success, set current refresh rate to new refresh rate.
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500222 current_refresh_rate_ = refresh_rate;
223 }
224
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500225 if (layer_set_.empty()) {
Uday Kiran Pichika8d827732018-01-09 18:08:38 +0530226 // Avoid flush for Command mode panel.
Pullakavi Srinivas2d55f3a2019-07-16 14:49:06 +0530227 flush_ = !client_connected_;
Ramkumar Radhakrishnana38b7602018-03-15 14:49:52 -0700228 validated_ = true;
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500229 return status;
230 }
231
232 status = PrepareLayerStack(out_num_types, out_num_requests);
Namit Solanki5b428dc2018-02-27 11:39:05 +0530233 pending_commit_ = true;
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500234 return status;
235}
236
Padmanabhan Komandurue74cf4f2019-04-25 17:38:43 -0700237HWC2::Error HWCDisplayBuiltIn::CommitLayerStack() {
238 skip_commit_ = CanSkipCommit();
239 return HWCDisplay::CommitLayerStack();
240}
241
242bool HWCDisplayBuiltIn::CanSkipCommit() {
243 if (layer_stack_invalid_) {
244 return false;
245 }
246
247 // Reject repeated drawcycle requests if it satisfies all conditions.
248 // 1. None of the layerstack attributes changed.
249 // 2. No new buffer latched.
250 // 3. No refresh request triggered by HWC.
251 // 4. This display is not source of vsync.
252 bool buffers_latched = false;
253 for (auto &hwc_layer : layer_set_) {
254 buffers_latched |= hwc_layer->BufferLatched();
255 hwc_layer->ResetBufferFlip();
256 }
257
Padmanabhan Komanduruf5e6c5d2019-04-04 13:56:31 +0530258 bool vsync_source = (callbacks_->GetVsyncSource() == id_);
Padmanabhan Komanduru866bf6a2019-03-19 14:30:48 +0530259 bool skip_commit = enable_optimize_refresh_ && !pending_commit_ && !buffers_latched &&
Padmanabhan Komanduruf5e6c5d2019-04-04 13:56:31 +0530260 !pending_refresh_ && !vsync_source;
Padmanabhan Komandurue74cf4f2019-04-25 17:38:43 -0700261 pending_refresh_ = false;
262
263 return skip_commit;
264}
265
Pullakavi Srinivas1ae4acb2019-11-18 19:33:45 +0530266HWC2::Error HWCDisplayBuiltIn::CommitStitchLayers() {
Pullakavi Srinivasdb2b84a2019-11-21 14:47:35 +0530267 if (disable_layer_stitch_) {
Pullakavi Srinivas1ae4acb2019-11-18 19:33:45 +0530268 return HWC2::Error::None;
269 }
270
Pullakavi Srinivasdb2b84a2019-11-21 14:47:35 +0530271 if (!validated_ || skip_commit_) {
Pullakavi Srinivas1ae4acb2019-11-18 19:33:45 +0530272 return HWC2::Error::None;
273 }
274
275 for (auto &layer : layer_stack_.layers) {
276 LayerComposition &composition = layer->composition;
277 if (composition != kCompositionStitch) {
278 continue;
279 }
280
Pullakavi Srinivasdb2b84a2019-11-21 14:47:35 +0530281 LayerStitchContext ctx = {};
Pullakavi Srinivas1ae4acb2019-11-18 19:33:45 +0530282 // Stitch target doesn't have an input fence.
283 // Render all layers at specified destination.
284 LayerBuffer &input_buffer = layer->input_buffer;
285 ctx.src_hnd = reinterpret_cast<const private_handle_t *>(input_buffer.buffer_id);
286 Layer *stitch_layer = stitch_target_->GetSDMLayer();
287 LayerBuffer &output_buffer = stitch_layer->input_buffer;
288 ctx.dst_hnd = reinterpret_cast<const private_handle_t *>(output_buffer.buffer_id);
289 SetRect(layer->stitch_dst_rect, &ctx.dst_rect);
Rajavenu Kyatham7338b9e2019-12-30 19:52:16 +0530290 ctx.src_acquire_fence = input_buffer.acquire_fence;
Pullakavi Srinivas1ae4acb2019-11-18 19:33:45 +0530291
292 layer_stitch_task_.PerformTask(LayerStitchTaskCode::kCodeStitch, &ctx);
293
Rajavenu Kyatham7338b9e2019-12-30 19:52:16 +0530294 // Merge with current fence.
295 output_buffer.acquire_fence = Fence::Merge(output_buffer.acquire_fence, ctx.release_fence);
Pullakavi Srinivas1ae4acb2019-11-18 19:33:45 +0530296 }
297
298 return HWC2::Error::None;
299}
300
Padmanabhan Komanduru6693fcb2019-11-22 21:06:52 +0530301void HWCDisplayBuiltIn::CacheAvrStatus() {
302 QSyncMode qsync_mode = kQSyncModeNone;
303
304 DisplayError error = display_intf_->GetQSyncMode(&qsync_mode);
305 if (error != kErrorNone) {
306 return;
307 }
308
309 bool qsync_enabled = (qsync_mode != kQSyncModeNone);
310 if (qsync_enabled_ != qsync_enabled) {
311 qsync_reconfigured_ = true;
312 qsync_enabled_ = qsync_enabled;
313 } else {
314 qsync_reconfigured_ = false;
315 }
316}
317
318bool HWCDisplayBuiltIn::IsQsyncCallbackNeeded(bool *qsync_enabled, int32_t *refresh_rate,
319 int32_t *qsync_refresh_rate) {
320 if (!qsync_reconfigured_) {
321 return false;
322 }
323
324 bool vsync_source = (callbacks_->GetVsyncSource() == id_);
325 // Qsync callback not needed if this display is not the source of vsync
326 if (!vsync_source) {
327 return false;
328 }
329
330 *qsync_enabled = qsync_enabled_;
331 uint32_t current_rate = 0;
332 display_intf_->GetRefreshRate(&current_rate);
333 *refresh_rate = INT32(current_rate);
334 *qsync_refresh_rate = min_refresh_rate_;
335
336 return true;
337}
338
Dileep Marchyaad668432019-12-02 10:44:52 +0530339HWC2::Error HWCDisplayBuiltIn::Present(shared_ptr<Fence> *out_retire_fence) {
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500340 auto status = HWC2::Error::None;
Gurpreet Singh Dhamia4276882019-04-12 10:30:58 -0700341
342 DTRACE_SCOPED();
Mathew Joseph Karimpanalb1c15862019-07-04 11:14:24 +0530343
344 if (!is_primary_ && active_secure_sessions_[kSecureDisplay]) {
Pullakavi Srinivas1ae4acb2019-11-18 19:33:45 +0530345 return status;
Mathew Joseph Karimpanalb1c15862019-07-04 11:14:24 +0530346 } else if (display_paused_) {
Pullakavi Srinivas0a1dba62018-07-02 15:49:11 +0530347 DisplayError error = display_intf_->Flush(&layer_stack_);
Saurabh Shaha307e8c2017-09-28 18:05:40 -0700348 validated_ = false;
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500349 if (error != kErrorNone) {
350 DLOGE("Flush failed. Error = %d", error);
351 }
352 } else {
Padmanabhan Komanduru6693fcb2019-11-22 21:06:52 +0530353 CacheAvrStatus();
354
Pullakavi Srinivas1ae4acb2019-11-18 19:33:45 +0530355 status = CommitStitchLayers();
356 if (status != HWC2::Error::None) {
357 DLOGE("Stitch failed: %d", status);
358 return status;
359 }
360
Padmanabhan Komandurue74cf4f2019-04-25 17:38:43 -0700361 status = CommitLayerStack();
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500362 if (status == HWC2::Error::None) {
363 HandleFrameOutput();
Pullakavi Srinivasdb2b84a2019-11-21 14:47:35 +0530364 PostCommitStitchLayers();
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500365 status = HWCDisplay::PostCommitLayerStack(out_retire_fence);
366 }
367 }
Arun Kumar K.R536c7d62016-06-14 18:47:39 -0700368
Namit Solanki5b428dc2018-02-27 11:39:05 +0530369 pending_commit_ = false;
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500370 return status;
371}
372
Pullakavi Srinivasdb2b84a2019-11-21 14:47:35 +0530373void HWCDisplayBuiltIn::PostCommitStitchLayers() {
374 if (disable_layer_stitch_) {
375 return;
376 }
377
378 // Close Stitch buffer acquire fence.
379 Layer *stitch_layer = stitch_target_->GetSDMLayer();
380 LayerBuffer &output_buffer = stitch_layer->input_buffer;
381 for (auto &layer : layer_stack_.layers) {
382 LayerComposition &composition = layer->composition;
383 if (composition != kCompositionStitch) {
384 continue;
385 }
386 LayerBuffer &input_buffer = layer->input_buffer;
Rajavenu Kyatham7338b9e2019-12-30 19:52:16 +0530387 input_buffer.release_fence = output_buffer.acquire_fence;
Pullakavi Srinivasdb2b84a2019-11-21 14:47:35 +0530388 }
Pullakavi Srinivasdb2b84a2019-11-21 14:47:35 +0530389}
390
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +0530391HWC2::Error HWCDisplayBuiltIn::GetColorModes(uint32_t *out_num_modes, ColorMode *out_modes) {
Arun Kumar K.R29cd6582016-05-10 19:12:45 -0700392 if (out_modes == nullptr) {
393 *out_num_modes = color_mode_->GetColorModeCount();
394 } else {
395 color_mode_->GetColorModes(out_num_modes, out_modes);
396 }
397
398 return HWC2::Error::None;
399}
400
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +0530401HWC2::Error HWCDisplayBuiltIn::GetRenderIntents(ColorMode mode, uint32_t *out_num_intents,
Naseer Ahmede7a77982018-06-04 10:56:04 -0400402 RenderIntent *out_intents) {
403 if (out_intents == nullptr) {
404 *out_num_intents = color_mode_->GetRenderIntentCount(mode);
405 } else {
406 color_mode_->GetRenderIntents(mode, out_num_intents, out_intents);
407 }
408 return HWC2::Error::None;
409}
410
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +0530411HWC2::Error HWCDisplayBuiltIn::SetColorMode(ColorMode mode) {
Naseer Ahmede7a77982018-06-04 10:56:04 -0400412 return SetColorModeWithRenderIntent(mode, RenderIntent::COLORIMETRIC);
413}
414
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +0530415HWC2::Error HWCDisplayBuiltIn::SetColorModeWithRenderIntent(ColorMode mode, RenderIntent intent) {
Sushil Chauhan8008d602018-09-04 14:43:27 -0700416 auto status = color_mode_->CacheColorModeWithRenderIntent(mode, intent);
Arun Kumar K.R29cd6582016-05-10 19:12:45 -0700417 if (status != HWC2::Error::None) {
Naseer Ahmede7a77982018-06-04 10:56:04 -0400418 DLOGE("failed for mode = %d intent = %d", mode, intent);
Arun Kumar K.R29cd6582016-05-10 19:12:45 -0700419 return status;
420 }
Ramkumar Radhakrishnan44c64362018-12-12 13:03:59 -0800421 callbacks_->Refresh(id_);
Saurabh Shaha307e8c2017-09-28 18:05:40 -0700422 validated_ = false;
Arun Kumar K.R29cd6582016-05-10 19:12:45 -0700423 return status;
424}
425
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +0530426HWC2::Error HWCDisplayBuiltIn::SetColorModeById(int32_t color_mode_id) {
Naseer Ahmed6776dae2017-05-09 11:49:41 -0400427 auto status = color_mode_->SetColorModeById(color_mode_id);
428 if (status != HWC2::Error::None) {
429 DLOGE("failed for mode = %d", color_mode_id);
430 return status;
431 }
432
Ramkumar Radhakrishnan44c64362018-12-12 13:03:59 -0800433 callbacks_->Refresh(id_);
Saurabh Shaha307e8c2017-09-28 18:05:40 -0700434 validated_ = false;
Naseer Ahmed6776dae2017-05-09 11:49:41 -0400435
436 return status;
437}
438
Xu Yang84e61412018-12-06 14:52:16 +0800439HWC2::Error HWCDisplayBuiltIn::SetColorModeFromClientApi(int32_t color_mode_id) {
440 DisplayError error = kErrorNone;
441 std::string mode_string;
442
443 error = display_intf_->GetColorModeName(color_mode_id, &mode_string);
444 if (error) {
445 DLOGE("Failed to get mode name for mode %d", color_mode_id);
446 return HWC2::Error::BadParameter;
447 }
448
449 auto status = color_mode_->SetColorModeFromClientApi(mode_string);
450 if (status != HWC2::Error::None) {
451 DLOGE("Failed to set mode = %d", color_mode_id);
452 return status;
453 }
454
455 return status;
456}
457
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +0530458HWC2::Error HWCDisplayBuiltIn::RestoreColorTransform() {
Ch Ganesh Kumar5d43ff62017-10-13 19:01:47 +0530459 auto status = color_mode_->RestoreColorTransform();
460 if (status != HWC2::Error::None) {
461 DLOGE("failed to RestoreColorTransform");
462 return status;
463 }
464
Ramkumar Radhakrishnan44c64362018-12-12 13:03:59 -0800465 callbacks_->Refresh(id_);
Ch Ganesh Kumar5d43ff62017-10-13 19:01:47 +0530466
467 return status;
468}
469
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +0530470HWC2::Error HWCDisplayBuiltIn::SetColorTransform(const float *matrix,
Arun Kumar K.R29cd6582016-05-10 19:12:45 -0700471 android_color_transform_t hint) {
472 if (!matrix) {
473 return HWC2::Error::BadParameter;
474 }
475
476 auto status = color_mode_->SetColorTransform(matrix, hint);
477 if (status != HWC2::Error::None) {
478 DLOGE("failed for hint = %d", hint);
479 color_tranform_failed_ = true;
480 return status;
481 }
482
Ramkumar Radhakrishnan44c64362018-12-12 13:03:59 -0800483 callbacks_->Refresh(id_);
Arun Kumar K.R29cd6582016-05-10 19:12:45 -0700484 color_tranform_failed_ = false;
Saurabh Shaha307e8c2017-09-28 18:05:40 -0700485 validated_ = false;
Arun Kumar K.R29cd6582016-05-10 19:12:45 -0700486
487 return status;
488}
489
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +0530490HWC2::Error HWCDisplayBuiltIn::SetReadbackBuffer(const native_handle_t *buffer,
Rajavenu Kyatham7338b9e2019-12-30 19:52:16 +0530491 shared_ptr<Fence> acquire_fence,
492 bool post_processed_output, CWBClient client) {
Dileep Marchyacb2a3a92019-06-21 17:30:50 +0530493 if (cwb_client_ != client && cwb_client_ != kCWBClientNone) {
494 DLOGE("CWB is in use with client = %d", cwb_client_);
495 return HWC2::Error::NoResources;
496 }
497
Sushil Chauhan06521582018-03-19 14:00:23 -0700498 const private_handle_t *handle = reinterpret_cast<const private_handle_t *>(buffer);
499 if (!handle || (handle->fd < 0)) {
500 return HWC2::Error::BadParameter;
501 }
502
503 // Configure the output buffer as Readback buffer
504 output_buffer_.width = UINT32(handle->width);
505 output_buffer_.height = UINT32(handle->height);
506 output_buffer_.unaligned_width = UINT32(handle->unaligned_width);
507 output_buffer_.unaligned_height = UINT32(handle->unaligned_height);
508 output_buffer_.format = HWCLayer::GetSDMFormat(handle->format, handle->flags);
509 output_buffer_.planes[0].fd = handle->fd;
510 output_buffer_.planes[0].stride = UINT32(handle->width);
Rajavenu Kyatham7338b9e2019-12-30 19:52:16 +0530511 output_buffer_.acquire_fence = acquire_fence;
Sushil Chauhand0dc03d2018-09-19 07:08:40 -0700512 output_buffer_.handle_id = handle->id;
Sushil Chauhan06521582018-03-19 14:00:23 -0700513
514 post_processed_output_ = post_processed_output;
515 readback_buffer_queued_ = true;
516 readback_configured_ = false;
517 validated_ = false;
Dileep Marchyacb2a3a92019-06-21 17:30:50 +0530518 cwb_client_ = client;
Sushil Chauhan06521582018-03-19 14:00:23 -0700519
Sushil Chauhan06521582018-03-19 14:00:23 -0700520 return HWC2::Error::None;
521}
522
Rajavenu Kyatham7338b9e2019-12-30 19:52:16 +0530523HWC2::Error HWCDisplayBuiltIn::GetReadbackBufferFence(shared_ptr<Fence> *release_fence) {
Sushil Chauhan06521582018-03-19 14:00:23 -0700524 auto status = HWC2::Error::None;
525
Rajavenu Kyatham7338b9e2019-12-30 19:52:16 +0530526 if (readback_configured_ && output_buffer_.release_fence) {
527 *release_fence = output_buffer_.release_fence;
Sushil Chauhan06521582018-03-19 14:00:23 -0700528 } else {
529 status = HWC2::Error::Unsupported;
Sushil Chauhan06521582018-03-19 14:00:23 -0700530 }
531
532 post_processed_output_ = false;
533 readback_buffer_queued_ = false;
534 readback_configured_ = false;
535 output_buffer_ = {};
Dileep Marchyacb2a3a92019-06-21 17:30:50 +0530536 cwb_client_ = kCWBClientNone;
Sushil Chauhan06521582018-03-19 14:00:23 -0700537
538 return status;
539}
540
Gurpreet Singh Dhami1207e462018-12-27 20:02:02 -0500541DisplayError HWCDisplayBuiltIn::TeardownConcurrentWriteback(void) {
542 DisplayError error = kErrorNotSupported;
Rajavenu Kyatham7338b9e2019-12-30 19:52:16 +0530543 if (Fence::Wait(output_buffer_.release_fence) != kErrorNone) {
544 DLOGE("sync_wait error errno = %d, desc = %s", errno, strerror(errno));
545 return kErrorResources;
Gurpreet Singh Dhami1207e462018-12-27 20:02:02 -0500546 }
547
548 if (display_intf_) {
549 error = display_intf_->TeardownConcurrentWriteback();
550 }
551
552 return error;
553}
554
Yuchao Ma577f0f72018-07-09 11:20:00 +0800555HWC2::Error HWCDisplayBuiltIn::SetDisplayDppsAdROI(uint32_t h_start, uint32_t h_end,
556 uint32_t v_start, uint32_t v_end,
557 uint32_t factor_in, uint32_t factor_out) {
558 DisplayError error = kErrorNone;
559 DisplayDppsAd4RoiCfg dpps_ad4_roi_cfg = {};
560 uint32_t panel_width = 0, panel_height = 0;
561 constexpr uint16_t kMaxFactorVal = 0xffff;
562
563 if (h_start >= h_end || v_start >= v_end || factor_in > kMaxFactorVal ||
564 factor_out > kMaxFactorVal) {
565 DLOGE("Invalid roi region = [%u, %u, %u, %u, %u, %u]",
566 h_start, h_end, v_start, v_end, factor_in, factor_out);
567 return HWC2::Error::BadParameter;
568 }
569
570 GetPanelResolution(&panel_width, &panel_height);
571
572 if (h_start >= panel_width || h_end > panel_width ||
573 v_start >= panel_height || v_end > panel_height) {
574 DLOGE("Invalid roi region = [%u, %u, %u, %u], panel resolution = [%u, %u]",
575 h_start, h_end, v_start, v_end, panel_width, panel_height);
576 return HWC2::Error::BadParameter;
577 }
578
579 dpps_ad4_roi_cfg.h_start = h_start;
580 dpps_ad4_roi_cfg.h_end = h_end;
581 dpps_ad4_roi_cfg.v_start = v_start;
582 dpps_ad4_roi_cfg.v_end = v_end;
583 dpps_ad4_roi_cfg.factor_in = factor_in;
584 dpps_ad4_roi_cfg.factor_out = factor_out;
585
586 error = display_intf_->SetDisplayDppsAdROI(&dpps_ad4_roi_cfg);
587 if (error)
588 return HWC2::Error::BadConfig;
589
Ramkumar Radhakrishnan44c64362018-12-12 13:03:59 -0800590 callbacks_->Refresh(id_);
Yuchao Ma577f0f72018-07-09 11:20:00 +0800591
592 return HWC2::Error::None;
593}
594
Xu Yang9dacc872018-12-25 11:04:28 +0800595HWC2::Error HWCDisplayBuiltIn::SetFrameTriggerMode(uint32_t mode) {
596 DisplayError error = kErrorNone;
597 FrameTriggerMode trigger_mode = kFrameTriggerDefault;
598
599 if (mode >= kFrameTriggerMax) {
600 DLOGE("Invalid input mode %d", mode);
601 return HWC2::Error::BadParameter;
602 }
603
604 trigger_mode = static_cast<FrameTriggerMode>(mode);
605 error = display_intf_->SetFrameTriggerMode(trigger_mode);
606 if (error)
607 return HWC2::Error::BadConfig;
608
609 callbacks_->Refresh(HWC_DISPLAY_PRIMARY);
610 validated_ = false;
611
612 return HWC2::Error::None;
613}
614
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +0530615int HWCDisplayBuiltIn::Perform(uint32_t operation, ...) {
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500616 va_list args;
617 va_start(args, operation);
Arun Kumar K.R536c7d62016-06-14 18:47:39 -0700618 int val = 0;
Gopikrishnaiah Anandancc123062017-07-31 17:21:03 -0700619 LayerSolidFill *solid_fill_color;
Arun Kumar K.R536c7d62016-06-14 18:47:39 -0700620 LayerRect *rect = NULL;
621
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500622 switch (operation) {
623 case SET_METADATA_DYN_REFRESH_RATE:
Arun Kumar K.R536c7d62016-06-14 18:47:39 -0700624 val = va_arg(args, int32_t);
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500625 SetMetaDataRefreshRateFlag(val);
626 break;
627 case SET_BINDER_DYN_REFRESH_RATE:
Arun Kumar K.R536c7d62016-06-14 18:47:39 -0700628 val = va_arg(args, int32_t);
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500629 ForceRefreshRate(UINT32(val));
630 break;
631 case SET_DISPLAY_MODE:
Arun Kumar K.R536c7d62016-06-14 18:47:39 -0700632 val = va_arg(args, int32_t);
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500633 SetDisplayMode(UINT32(val));
634 break;
635 case SET_QDCM_SOLID_FILL_INFO:
Gopikrishnaiah Anandancc123062017-07-31 17:21:03 -0700636 solid_fill_color = va_arg(args, LayerSolidFill*);
637 SetQDCMSolidFillInfo(true, *solid_fill_color);
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500638 break;
639 case UNSET_QDCM_SOLID_FILL_INFO:
Gopikrishnaiah Anandancc123062017-07-31 17:21:03 -0700640 solid_fill_color = va_arg(args, LayerSolidFill*);
641 SetQDCMSolidFillInfo(false, *solid_fill_color);
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500642 break;
Arun Kumar K.R536c7d62016-06-14 18:47:39 -0700643 case SET_QDCM_SOLID_FILL_RECT:
644 rect = va_arg(args, LayerRect*);
645 solid_fill_rect_ = *rect;
646 break;
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500647 default:
648 DLOGW("Invalid operation %d", operation);
Arun Kumar K.R536c7d62016-06-14 18:47:39 -0700649 va_end(args);
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500650 return -EINVAL;
651 }
Arun Kumar K.R536c7d62016-06-14 18:47:39 -0700652 va_end(args);
Saurabh Shaha307e8c2017-09-28 18:05:40 -0700653 validated_ = false;
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500654
655 return 0;
656}
657
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +0530658DisplayError HWCDisplayBuiltIn::SetDisplayMode(uint32_t mode) {
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500659 DisplayError error = kErrorNone;
660
661 if (display_intf_) {
662 error = display_intf_->SetDisplayMode(mode);
Tharaga Balachandran04192a62018-08-29 16:23:25 -0400663 if (error == kErrorNone) {
664 DisplayConfigFixedInfo fixed_info = {};
665 display_intf_->GetConfig(&fixed_info);
666 is_cmd_mode_ = fixed_info.is_cmdmode;
667 partial_update_enabled_ = fixed_info.partial_update;
668 for (auto hwc_layer : layer_set_) {
669 hwc_layer->SetPartialUpdate(partial_update_enabled_);
670 }
671 client_target_->SetPartialUpdate(partial_update_enabled_);
672 }
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500673 }
674
675 return error;
676}
677
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +0530678void HWCDisplayBuiltIn::SetMetaDataRefreshRateFlag(bool enable) {
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500679 int disable_metadata_dynfps = 0;
680
Uday Kiran Pichika5e656b22018-05-15 18:48:24 +0530681 HWCDebugHandler::Get()->GetProperty(DISABLE_METADATA_DYNAMIC_FPS_PROP, &disable_metadata_dynfps);
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500682 if (disable_metadata_dynfps) {
683 return;
684 }
685 use_metadata_refresh_rate_ = enable;
686}
687
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +0530688void HWCDisplayBuiltIn::SetQDCMSolidFillInfo(bool enable, const LayerSolidFill &color) {
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500689 solid_fill_enable_ = enable;
690 solid_fill_color_ = color;
691}
692
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +0530693void HWCDisplayBuiltIn::ToggleCPUHint(bool set) {
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500694 if (!cpu_hint_) {
695 return;
696 }
697
698 if (set) {
699 cpu_hint_->Set();
700 } else {
701 cpu_hint_->Reset();
702 }
703}
704
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +0530705int HWCDisplayBuiltIn::HandleSecureSession(const std::bitset<kSecureMax> &secure_sessions,
Ramkumar Radhakrishnana38b7602018-03-15 14:49:52 -0700706 bool *power_on_pending) {
707 if (!power_on_pending) {
708 return -EINVAL;
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500709 }
Ramkumar Radhakrishnana38b7602018-03-15 14:49:52 -0700710
Mathew Joseph Karimpanalb1c15862019-07-04 11:14:24 +0530711 if (!is_primary_) {
712 return HWCDisplay::HandleSecureSession(secure_sessions, power_on_pending);
713 }
714
Ramkumar Radhakrishnan44c64362018-12-12 13:03:59 -0800715 if (current_power_mode_ != HWC2::PowerMode::On) {
716 return 0;
717 }
718
Ramkumar Radhakrishnana38b7602018-03-15 14:49:52 -0700719 if (active_secure_sessions_[kSecureDisplay] != secure_sessions[kSecureDisplay]) {
720 SecureEvent secure_event =
721 secure_sessions.test(kSecureDisplay) ? kSecureDisplayStart : kSecureDisplayEnd;
Pullakavi Srinivas0a1dba62018-07-02 15:49:11 +0530722 DisplayError err = display_intf_->HandleSecureEvent(secure_event, &layer_stack_);
Ramkumar Radhakrishnana38b7602018-03-15 14:49:52 -0700723 if (err != kErrorNone) {
724 DLOGE("Set secure event failed");
725 return err;
726 }
727
Mathew Joseph Karimpanalb1c15862019-07-04 11:14:24 +0530728 DLOGI("SecureDisplay state changed from %d to %d for display %d-%d",
Ramkumar Radhakrishnana38b7602018-03-15 14:49:52 -0700729 active_secure_sessions_.test(kSecureDisplay), secure_sessions.test(kSecureDisplay),
Mathew Joseph Karimpanalb1c15862019-07-04 11:14:24 +0530730 id_, type_);
Ramkumar Radhakrishnana38b7602018-03-15 14:49:52 -0700731 }
732 active_secure_sessions_ = secure_sessions;
733 *power_on_pending = false;
734 return 0;
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500735}
736
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +0530737void HWCDisplayBuiltIn::ForceRefreshRate(uint32_t refresh_rate) {
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500738 if ((refresh_rate && (refresh_rate < min_refresh_rate_ || refresh_rate > max_refresh_rate_)) ||
739 force_refresh_rate_ == refresh_rate) {
740 // Cannot honor force refresh rate, as its beyond the range or new request is same
741 return;
742 }
743
744 force_refresh_rate_ = refresh_rate;
745
Ramkumar Radhakrishnan44c64362018-12-12 13:03:59 -0800746 callbacks_->Refresh(id_);
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500747
748 return;
749}
750
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +0530751uint32_t HWCDisplayBuiltIn::GetOptimalRefreshRate(bool one_updating_layer) {
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500752 if (force_refresh_rate_) {
753 return force_refresh_rate_;
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500754 } else if (use_metadata_refresh_rate_ && one_updating_layer && metadata_refresh_rate_) {
755 return metadata_refresh_rate_;
756 }
757
758 return max_refresh_rate_;
759}
760
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +0530761void HWCDisplayBuiltIn::SetIdleTimeoutMs(uint32_t timeout_ms) {
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500762 display_intf_->SetIdleTimeoutMs(timeout_ms);
Saurabh Shaha307e8c2017-09-28 18:05:40 -0700763 validated_ = false;
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500764}
765
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +0530766void HWCDisplayBuiltIn::HandleFrameOutput() {
Sushil Chauhan06521582018-03-19 14:00:23 -0700767 if (readback_buffer_queued_) {
768 validated_ = false;
769 }
770
Sushil Chauhan1d3b90c2018-12-11 16:52:35 -0800771 if (frame_capture_buffer_queued_) {
772 HandleFrameCapture();
773 } else if (dump_output_to_file_) {
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500774 HandleFrameDump();
775 }
776}
777
Sushil Chauhan1d3b90c2018-12-11 16:52:35 -0800778void HWCDisplayBuiltIn::HandleFrameCapture() {
Rajavenu Kyatham7338b9e2019-12-30 19:52:16 +0530779 if (readback_configured_ && output_buffer_.release_fence) {
780 frame_capture_status_ = Fence::Wait(output_buffer_.release_fence);
Sushil Chauhan1d3b90c2018-12-11 16:52:35 -0800781 }
782
783 frame_capture_buffer_queued_ = false;
784 readback_buffer_queued_ = false;
785 post_processed_output_ = false;
786 readback_configured_ = false;
787 output_buffer_ = {};
Dileep Marchyacb2a3a92019-06-21 17:30:50 +0530788 cwb_client_ = kCWBClientNone;
Sushil Chauhan1d3b90c2018-12-11 16:52:35 -0800789}
790
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +0530791void HWCDisplayBuiltIn::HandleFrameDump() {
Ramkumar Radhakrishnan68331fc2019-06-19 11:24:12 -0700792 if (dump_frame_count_) {
793 int ret = 0;
Rajavenu Kyatham7338b9e2019-12-30 19:52:16 +0530794 ret = Fence::Wait(output_buffer_.release_fence);
795 if (ret != kErrorNone) {
796 DLOGE("sync_wait error errno = %d, desc = %s", errno, strerror(errno));
Ramkumar Radhakrishnan68331fc2019-06-19 11:24:12 -0700797 }
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500798
Ramkumar Radhakrishnan68331fc2019-06-19 11:24:12 -0700799 if (!ret) {
Dileep Marchyaad668432019-12-02 10:44:52 +0530800 DumpOutputBuffer(output_buffer_info_, output_buffer_base_, layer_stack_.retire_fence);
801 validated_ = false;
802 }
Ramkumar Radhakrishnan68331fc2019-06-19 11:24:12 -0700803
804 if (0 == (dump_frame_count_ - 1)) {
805 dump_output_to_file_ = false;
806 // Unmap and Free buffer
807 if (munmap(output_buffer_base_, output_buffer_info_.alloc_buffer_info.size) != 0) {
808 DLOGE("unmap failed with err %d", errno);
809 }
810 if (buffer_allocator_->FreeBuffer(&output_buffer_info_) != 0) {
811 DLOGE("FreeBuffer failed");
812 }
813
Sushil Chauhan06521582018-03-19 14:00:23 -0700814 readback_buffer_queued_ = false;
Ramkumar Radhakrishnan68331fc2019-06-19 11:24:12 -0700815 post_processed_output_ = false;
816 readback_configured_ = false;
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500817
Ramkumar Radhakrishnan68331fc2019-06-19 11:24:12 -0700818 output_buffer_ = {};
819 output_buffer_info_ = {};
820 output_buffer_base_ = nullptr;
Dileep Marchyacb2a3a92019-06-21 17:30:50 +0530821 cwb_client_ = kCWBClientNone;
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500822 }
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500823 }
824}
825
Sushil Chauhan267a6192018-06-06 18:41:47 -0700826HWC2::Error HWCDisplayBuiltIn::SetFrameDumpConfig(uint32_t count, uint32_t bit_mask_layer_type,
827 int32_t format, bool post_processed) {
828 HWCDisplay::SetFrameDumpConfig(count, bit_mask_layer_type, format, post_processed);
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500829 dump_output_to_file_ = bit_mask_layer_type & (1 << OUTPUT_LAYER_DUMP);
830 DLOGI("output_layer_dump_enable %d", dump_output_to_file_);
831
Dileep Marchyacb2a3a92019-06-21 17:30:50 +0530832 if (dump_output_to_file_) {
833 if (cwb_client_ != kCWBClientNone) {
834 DLOGE("CWB is in use with client = %d", cwb_client_);
835 dump_output_to_file_ = false;
836 return HWC2::Error::NoResources;
837 }
838 }
839
Sushil Chauhand0dc03d2018-09-19 07:08:40 -0700840 if (!count || !dump_output_to_file_ || (output_buffer_info_.alloc_buffer_info.fd >= 0)) {
Mathew Joseph Karimpanaldbd64f82017-10-06 10:13:38 +0530841 return HWC2::Error::None;
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500842 }
843
844 // Allocate and map output buffer
Sushil Chauhan267a6192018-06-06 18:41:47 -0700845 if (post_processed) {
846 // To dump post-processed (DSPP) output, use Panel resolution.
847 GetPanelResolution(&output_buffer_info_.buffer_config.width,
848 &output_buffer_info_.buffer_config.height);
849 } else {
850 // To dump Layer Mixer output, use FrameBuffer resolution.
851 GetFrameBufferResolution(&output_buffer_info_.buffer_config.width,
852 &output_buffer_info_.buffer_config.height);
853 }
854
855 output_buffer_info_.buffer_config.format = HWCLayer::GetSDMFormat(format, 0);
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500856 output_buffer_info_.buffer_config.buffer_count = 1;
857 if (buffer_allocator_->AllocateBuffer(&output_buffer_info_) != 0) {
858 DLOGE("Buffer allocation failed");
859 output_buffer_info_ = {};
Mathew Joseph Karimpanaldbd64f82017-10-06 10:13:38 +0530860 return HWC2::Error::NoResources;
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500861 }
862
863 void *buffer = mmap(NULL, output_buffer_info_.alloc_buffer_info.size, PROT_READ | PROT_WRITE,
864 MAP_SHARED, output_buffer_info_.alloc_buffer_info.fd, 0);
865
866 if (buffer == MAP_FAILED) {
867 DLOGE("mmap failed with err %d", errno);
868 buffer_allocator_->FreeBuffer(&output_buffer_info_);
869 output_buffer_info_ = {};
Mathew Joseph Karimpanaldbd64f82017-10-06 10:13:38 +0530870 return HWC2::Error::NoResources;
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500871 }
872
873 output_buffer_base_ = buffer;
Sushil Chauhan06521582018-03-19 14:00:23 -0700874 const native_handle_t *handle = static_cast<native_handle_t *>(output_buffer_info_.private_data);
Rajavenu Kyatham7338b9e2019-12-30 19:52:16 +0530875 SetReadbackBuffer(handle, nullptr, post_processed, kCWBClientFrameDump);
Sushil Chauhan06521582018-03-19 14:00:23 -0700876
Mathew Joseph Karimpanaldbd64f82017-10-06 10:13:38 +0530877 return HWC2::Error::None;
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500878}
879
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +0530880int HWCDisplayBuiltIn::FrameCaptureAsync(const BufferInfo &output_buffer_info,
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500881 bool post_processed_output) {
Dileep Marchyacb2a3a92019-06-21 17:30:50 +0530882 if (cwb_client_ != kCWBClientNone) {
883 DLOGE("CWB is in use with client = %d", cwb_client_);
884 return -1;
885 }
886
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500887 // Note: This function is called in context of a binder thread and a lock is already held
888 if (output_buffer_info.alloc_buffer_info.fd < 0) {
889 DLOGE("Invalid fd %d", output_buffer_info.alloc_buffer_info.fd);
890 return -1;
891 }
892
893 auto panel_width = 0u;
894 auto panel_height = 0u;
895 auto fb_width = 0u;
896 auto fb_height = 0u;
897
898 GetPanelResolution(&panel_width, &panel_height);
899 GetFrameBufferResolution(&fb_width, &fb_height);
900
Ch Ganesh Kumar5c4988b2017-06-07 15:21:02 +0530901 if (post_processed_output && (output_buffer_info.buffer_config.width < panel_width ||
902 output_buffer_info.buffer_config.height < panel_height)) {
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500903 DLOGE("Buffer dimensions should not be less than panel resolution");
904 return -1;
Ch Ganesh Kumar5c4988b2017-06-07 15:21:02 +0530905 } else if (!post_processed_output && (output_buffer_info.buffer_config.width < fb_width ||
906 output_buffer_info.buffer_config.height < fb_height)) {
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500907 DLOGE("Buffer dimensions should not be less than FB resolution");
908 return -1;
909 }
910
Sushil Chauhan06521582018-03-19 14:00:23 -0700911 const native_handle_t *buffer = static_cast<native_handle_t *>(output_buffer_info.private_data);
Rajavenu Kyatham7338b9e2019-12-30 19:52:16 +0530912 SetReadbackBuffer(buffer, nullptr, post_processed_output, kCWBClientColor);
Sushil Chauhan1d3b90c2018-12-11 16:52:35 -0800913 frame_capture_buffer_queued_ = true;
914 frame_capture_status_ = -EAGAIN;
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500915
916 return 0;
917}
918
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +0530919DisplayError HWCDisplayBuiltIn::SetDetailEnhancerConfig
Alan Kwong2e136332016-08-16 07:50:16 -0400920 (const DisplayDetailEnhancerData &de_data) {
921 DisplayError error = kErrorNotSupported;
922
923 if (display_intf_) {
924 error = display_intf_->SetDetailEnhancerData(de_data);
Saurabh Shaha307e8c2017-09-28 18:05:40 -0700925 validated_ = false;
Alan Kwong2e136332016-08-16 07:50:16 -0400926 }
927 return error;
928}
929
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +0530930DisplayError HWCDisplayBuiltIn::ControlPartialUpdate(bool enable, uint32_t *pending) {
Arun Kumar K.R17bbd042016-06-07 17:38:02 -0700931 DisplayError error = kErrorNone;
932
933 if (display_intf_) {
934 error = display_intf_->ControlPartialUpdate(enable, pending);
Saurabh Shaha307e8c2017-09-28 18:05:40 -0700935 validated_ = false;
Arun Kumar K.R17bbd042016-06-07 17:38:02 -0700936 }
937
938 return error;
939}
940
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +0530941DisplayError HWCDisplayBuiltIn::DisablePartialUpdateOneFrame() {
Arun Kumar K.R17bbd042016-06-07 17:38:02 -0700942 DisplayError error = kErrorNone;
943
944 if (display_intf_) {
945 error = display_intf_->DisablePartialUpdateOneFrame();
Saurabh Shaha307e8c2017-09-28 18:05:40 -0700946 validated_ = false;
Arun Kumar K.R17bbd042016-06-07 17:38:02 -0700947 }
948
949 return error;
950}
951
Lakshmi Narayana Kalavala25fe12c2019-12-11 20:44:55 -0800952HWC2::Error HWCDisplayBuiltIn::SetDisplayedContentSamplingEnabledVndService(bool enabled) {
953 std::unique_lock<decltype(sampling_mutex)> lk(sampling_mutex);
954 vndservice_sampling_vote = enabled;
955 if (api_sampling_vote || vndservice_sampling_vote) {
956 histogram.start();
Lakshmi Narayana Kalavalaf30c2292019-09-26 15:26:24 -0700957 display_intf_->colorSamplingOn();
Lakshmi Narayana Kalavala25fe12c2019-12-11 20:44:55 -0800958 } else {
Lakshmi Narayana Kalavalaf30c2292019-09-26 15:26:24 -0700959 display_intf_->colorSamplingOff();
Lakshmi Narayana Kalavala25fe12c2019-12-11 20:44:55 -0800960 histogram.stop();
961 }
962 return HWC2::Error::None;
963}
964
965HWC2::Error HWCDisplayBuiltIn::SetDisplayedContentSamplingEnabled(int32_t enabled,
966 uint8_t component_mask,
967 uint64_t max_frames) {
968 if ((enabled != HWC2_DISPLAYED_CONTENT_SAMPLING_ENABLE) &&
969 (enabled != HWC2_DISPLAYED_CONTENT_SAMPLING_DISABLE))
970 return HWC2::Error::BadParameter;
971
972 std::unique_lock<decltype(sampling_mutex)> lk(sampling_mutex);
973 if (enabled == HWC2_DISPLAYED_CONTENT_SAMPLING_ENABLE) {
974 api_sampling_vote = true;
975 } else {
976 api_sampling_vote = false;
977 }
978
979 auto start = api_sampling_vote || vndservice_sampling_vote;
980 if (start && max_frames == 0) {
981 histogram.start();
Lakshmi Narayana Kalavalaf30c2292019-09-26 15:26:24 -0700982 display_intf_->colorSamplingOn();
Lakshmi Narayana Kalavala25fe12c2019-12-11 20:44:55 -0800983 } else if (start) {
984 histogram.start(max_frames);
Lakshmi Narayana Kalavalaf30c2292019-09-26 15:26:24 -0700985 display_intf_->colorSamplingOn();
Lakshmi Narayana Kalavala25fe12c2019-12-11 20:44:55 -0800986 } else {
Lakshmi Narayana Kalavalaf30c2292019-09-26 15:26:24 -0700987 display_intf_->colorSamplingOff();
Lakshmi Narayana Kalavala25fe12c2019-12-11 20:44:55 -0800988 histogram.stop();
989 }
990 return HWC2::Error::None;
991}
992
993HWC2::Error HWCDisplayBuiltIn::GetDisplayedContentSamplingAttributes(
994 int32_t *format, int32_t *dataspace, uint8_t *supported_components) {
995 return histogram.getAttributes(format, dataspace, supported_components);
996}
997
998HWC2::Error HWCDisplayBuiltIn::GetDisplayedContentSample(
999 uint64_t max_frames, uint64_t timestamp, uint64_t *numFrames,
1000 int32_t samples_size[NUM_HISTOGRAM_COLOR_COMPONENTS],
1001 uint64_t *samples[NUM_HISTOGRAM_COLOR_COMPONENTS]) {
1002 histogram.collect(max_frames, timestamp, samples_size, samples, numFrames);
1003 return HWC2::Error::None;
1004}
Arun Kumar K.R17bbd042016-06-07 17:38:02 -07001005
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +05301006DisplayError HWCDisplayBuiltIn::SetMixerResolution(uint32_t width, uint32_t height) {
Sushil Chauhan409e8442017-06-12 17:43:25 -07001007 DisplayError error = display_intf_->SetMixerResolution(width, height);
Ramkumar Radhakrishnanf7f52162019-06-06 19:40:04 -07001008 callbacks_->Refresh(id_);
Saurabh Shaha307e8c2017-09-28 18:05:40 -07001009 validated_ = false;
Sushil Chauhan409e8442017-06-12 17:43:25 -07001010 return error;
Arun Kumar K.R8da7f502016-06-07 17:45:50 -07001011}
1012
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +05301013DisplayError HWCDisplayBuiltIn::GetMixerResolution(uint32_t *width, uint32_t *height) {
Arun Kumar K.R8da7f502016-06-07 17:45:50 -07001014 return display_intf_->GetMixerResolution(width, height);
1015}
1016
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +05301017HWC2::Error HWCDisplayBuiltIn::SetQSyncMode(QSyncMode qsync_mode) {
Pullakavi Srinivas24574142019-08-14 12:18:12 +05301018 // Client needs to ensure that config change and qsync mode change
1019 // are not triggered in the same drawcycle.
1020 if (pending_config_) {
1021 DLOGE("Failed to set qsync mode. Pending active config transition");
1022 return HWC2::Error::Unsupported;
1023 }
1024
Sushil Chauhan380a59d2018-03-19 15:47:50 -07001025 auto err = display_intf_->SetQSyncMode(qsync_mode);
1026 if (err != kErrorNone) {
1027 return HWC2::Error::Unsupported;
1028 }
1029
Sushil Chauhanec4eb572019-02-07 13:29:42 -08001030 validated_ = false;
Sushil Chauhan380a59d2018-03-19 15:47:50 -07001031 return HWC2::Error::None;
1032}
1033
Ramkumar Radhakrishnan4faf8a62018-11-15 17:15:37 -08001034DisplayError HWCDisplayBuiltIn::ControlIdlePowerCollapse(bool enable, bool synchronous) {
Ramkumar Radhakrishnanf985d482018-07-23 18:10:41 -07001035 DisplayError error = kErrorNone;
1036
1037 if (display_intf_) {
1038 error = display_intf_->ControlIdlePowerCollapse(enable, synchronous);
1039 validated_ = false;
1040 }
Ramkumar Radhakrishnan4faf8a62018-11-15 17:15:37 -08001041 return error;
Ramkumar Radhakrishnanf985d482018-07-23 18:10:41 -07001042}
1043
Pullakavi Srinivas9189e602018-12-19 16:58:07 +05301044DisplayError HWCDisplayBuiltIn::SetDynamicDSIClock(uint64_t bitclk) {
Dileep Marchyaafa45bc2019-06-21 17:05:31 +05301045 DisablePartialUpdateOneFrame();
1046 DisplayError error = display_intf_->SetDynamicDSIClock(bitclk);
1047 if (error != kErrorNone) {
1048 DLOGE(" failed: Clk: %llu Error: %d", bitclk, error);
1049 return error;
Pullakavi Srinivas9189e602018-12-19 16:58:07 +05301050 }
1051
1052 callbacks_->Refresh(id_);
1053 validated_ = false;
1054
1055 return kErrorNone;
1056}
1057
1058DisplayError HWCDisplayBuiltIn::GetDynamicDSIClock(uint64_t *bitclk) {
Pullakavi Srinivas9189e602018-12-19 16:58:07 +05301059 if (display_intf_) {
1060 return display_intf_->GetDynamicDSIClock(bitclk);
1061 }
1062
1063 return kErrorNotSupported;
1064}
1065
1066DisplayError HWCDisplayBuiltIn::GetSupportedDSIClock(std::vector<uint64_t> *bitclk_rates) {
1067 if (display_intf_) {
1068 return display_intf_->GetSupportedDSIClock(bitclk_rates);
1069 }
1070
1071 return kErrorNotSupported;
1072}
1073
Padmanabhan Komandurue74cf4f2019-04-25 17:38:43 -07001074HWC2::Error HWCDisplayBuiltIn::UpdateDisplayId(hwc2_display_t id) {
1075 id_ = id;
1076 return HWC2::Error::None;
1077}
1078
1079HWC2::Error HWCDisplayBuiltIn::SetPendingRefresh() {
1080 pending_refresh_ = true;
1081 return HWC2::Error::None;
1082}
1083
Varun Arora75c05f02019-05-14 14:53:37 -07001084HWC2::Error HWCDisplayBuiltIn::SetPanelBrightness(float brightness) {
1085 DisplayError ret = display_intf_->SetPanelBrightness(brightness);
1086 if (ret != kErrorNone) {
1087 return HWC2::Error::NoResources;
1088 }
1089
1090 return HWC2::Error::None;
1091}
1092
1093HWC2::Error HWCDisplayBuiltIn::GetPanelBrightness(float *brightness) {
1094 DisplayError ret = display_intf_->GetPanelBrightness(brightness);
1095 if (ret != kErrorNone) {
1096 return HWC2::Error::NoResources;
1097 }
1098
1099 return HWC2::Error::None;
1100}
Xu Yang45d0abf2019-07-05 11:34:06 +08001101
Yuchao Maada1c402019-11-12 14:47:11 +08001102HWC2::Error HWCDisplayBuiltIn::GetPanelMaxBrightness(uint32_t *max_brightness_level) {
1103 DisplayError ret = display_intf_->GetPanelMaxBrightness(max_brightness_level);
1104 if (ret != kErrorNone) {
1105 return HWC2::Error::NoResources;
1106 }
1107
1108 return HWC2::Error::None;
1109}
1110
Xu Yang45d0abf2019-07-05 11:34:06 +08001111HWC2::Error HWCDisplayBuiltIn::SetBLScale(uint32_t level) {
1112 DisplayError ret = display_intf_->SetBLScale(level);
1113 if (ret != kErrorNone) {
1114 return HWC2::Error::NoResources;
1115 }
Srinivas Pullakavi3c4337f2019-07-03 11:24:31 +05301116 return HWC2::Error::None;
1117}
Xu Yang45d0abf2019-07-05 11:34:06 +08001118
Srinivas Pullakavi3c4337f2019-07-03 11:24:31 +05301119HWC2::Error HWCDisplayBuiltIn::UpdatePowerMode(HWC2::PowerMode mode) {
1120 current_power_mode_ = mode;
1121 validated_ = false;
Xu Yang45d0abf2019-07-05 11:34:06 +08001122 return HWC2::Error::None;
1123}
1124
Rajavenu Kyatham7338b9e2019-12-30 19:52:16 +05301125HWC2::Error HWCDisplayBuiltIn::SetClientTarget(buffer_handle_t target,
1126 shared_ptr<Fence> acquire_fence,
Padmanabhan Komanduru9a91e9f2019-09-12 12:33:19 +05301127 int32_t dataspace, hwc_region_t damage) {
1128 HWC2::Error error = HWCDisplay::SetClientTarget(target, acquire_fence, dataspace, damage);
1129 if (error != HWC2::Error::None) {
1130 return error;
1131 }
1132
1133 Layer *sdm_layer = client_target_->GetSDMLayer();
Padmanabhan Komandurua4bf6062019-10-13 09:04:49 +05301134 uint32_t fb_width = 0, fb_height = 0;
1135
1136 GetFrameBufferResolution(&fb_width, &fb_height);
1137
1138 if (fb_width != sdm_layer->input_buffer.unaligned_width ||
1139 fb_height != sdm_layer->input_buffer.unaligned_height) {
1140 if (SetFrameBufferConfig(sdm_layer->input_buffer.unaligned_width,
1141 sdm_layer->input_buffer.unaligned_height)) {
1142 return HWC2::Error::BadParameter;
1143 }
1144 }
Padmanabhan Komanduru9a91e9f2019-09-12 12:33:19 +05301145
1146 return HWC2::Error::None;
1147}
Sushil Chauhan1566a132019-10-02 11:59:28 -07001148
1149bool HWCDisplayBuiltIn::IsSmartPanelConfig(uint32_t config_id) {
1150 if (config_id < hwc_config_map_.size()) {
1151 uint32_t index = hwc_config_map_.at(config_id);
1152 return variable_config_map_.at(index).smart_panel;
1153 }
1154
1155 return false;
1156}
1157
Pullakavi Srinivas1ae4acb2019-11-18 19:33:45 +05301158int HWCDisplayBuiltIn::Deinit() {
1159 // Destory color convert instance. This destroys thread and underlying GL resources.
1160 if (gl_layer_stitch_) {
1161 layer_stitch_task_.PerformTask(LayerStitchTaskCode::kCodeDestroyInstance, nullptr);
1162 }
1163
Lakshmi Narayana Kalavala25fe12c2019-12-11 20:44:55 -08001164 histogram.stop();
Pullakavi Srinivas1ae4acb2019-11-18 19:33:45 +05301165 return HWCDisplay::Deinit();
1166}
1167
1168void HWCDisplayBuiltIn::OnTask(const LayerStitchTaskCode &task_code,
1169 SyncTask<LayerStitchTaskCode>::TaskContext *task_context) {
1170 switch (task_code) {
1171 case LayerStitchTaskCode::kCodeGetInstance: {
1172 gl_layer_stitch_ = GLLayerStitch::GetInstance(false /* Non-secure */);
1173 }
1174 break;
1175 case LayerStitchTaskCode::kCodeStitch: {
1176 DTRACE_SCOPED();
Pullakavi Srinivasdb2b84a2019-11-21 14:47:35 +05301177 LayerStitchContext* ctx = reinterpret_cast<LayerStitchContext*>(task_context);
Pullakavi Srinivas1ae4acb2019-11-18 19:33:45 +05301178 gl_layer_stitch_->Blit(ctx->src_hnd, ctx->dst_hnd, ctx->src_rect, ctx->dst_rect,
Rajavenu Kyatham7338b9e2019-12-30 19:52:16 +05301179 ctx->src_acquire_fence, ctx->dst_acquire_fence,
1180 &(ctx->release_fence));
Pullakavi Srinivas1ae4acb2019-11-18 19:33:45 +05301181 }
1182 break;
1183 case LayerStitchTaskCode::kCodeDestroyInstance: {
1184 if (gl_layer_stitch_) {
1185 GLLayerStitch::Destroy(gl_layer_stitch_);
1186 }
1187 }
1188 break;
1189 }
1190}
1191
1192bool HWCDisplayBuiltIn::InitLayerStitch() {
1193 if (!is_primary_) {
1194 // Disable on all non-primary builtins.
1195 DLOGI("Non-primary builtin.");
Pullakavi Srinivas94793b42019-11-27 20:03:50 +05301196 disable_layer_stitch_ = true;
Pullakavi Srinivas1ae4acb2019-11-18 19:33:45 +05301197 return true;
1198 }
1199
1200 // Disable by default.
1201 int value = 1;
1202 Debug::Get()->GetProperty(DISABLE_LAYER_STITCH, &value);
1203 disable_layer_stitch_ = (value == 1);
1204
1205 if (disable_layer_stitch_) {
1206 DLOGI("Layer Stitch Disabled !!!");
1207 return true;
1208 }
1209
1210 // Initialize stitch context. This will be non-secure.
1211 layer_stitch_task_.PerformTask(LayerStitchTaskCode::kCodeGetInstance, nullptr);
1212 if (gl_layer_stitch_ == nullptr) {
1213 DLOGE("Failed to get LayerStitch Instance");
1214 return false;
1215 }
1216
1217 if (!AllocateStitchBuffer()) {
1218 return true;
1219 }
1220
1221 stitch_target_ = new HWCLayer(id_, static_cast<HWCBufferAllocator *>(buffer_allocator_));
1222
1223 // Populate buffer params and pvt handle.
1224 InitStitchTarget();
1225
1226 DLOGI("Created LayerStitch instance: %p", gl_layer_stitch_);
1227
1228 return true;
1229}
1230
1231bool HWCDisplayBuiltIn::AllocateStitchBuffer() {
1232 // Buffer dimensions: FB width * (1.5 * height)
1233
1234 DisplayError error = display_intf_->GetFrameBufferConfig(&fb_config_);
1235 if (error != kErrorNone) {
1236 DLOGE("Get frame buffer config failed. Error = %d", error);
1237 return false;
1238 }
1239
1240 BufferConfig &config = buffer_info_.buffer_config;
1241 config.width = fb_config_.x_pixels;
1242 config.height = fb_config_.y_pixels * kBufferHeightFactor;
1243
1244 // By default UBWC is enabled and below property is global enable/disable for all
1245 // buffers allocated through gralloc , including framebuffer targets.
1246 int ubwc_disabled = 0;
1247 HWCDebugHandler::Get()->GetProperty(DISABLE_UBWC_PROP, &ubwc_disabled);
1248 config.format = ubwc_disabled ? kFormatRGBA8888 : kFormatRGBA8888Ubwc;
1249
1250 config.gfx_client = true;
1251
1252 // Populate default params.
1253 config.secure = false;
1254 config.cache = false;
1255 config.secure_camera = false;
1256
1257 error = buffer_allocator_->AllocateBuffer(&buffer_info_);
1258
1259 if (error != kErrorNone) {
1260 DLOGE("Failed to allocate buffer. Error: %d", error);
1261 return false;
1262 }
1263
1264 return true;
1265}
1266
1267void HWCDisplayBuiltIn::InitStitchTarget() {
1268 LayerBuffer buffer = {};
1269 buffer.planes[0].fd = buffer_info_.alloc_buffer_info.fd;
1270 buffer.planes[0].offset = 0;
1271 buffer.planes[0].stride = buffer_info_.alloc_buffer_info.stride;
1272 buffer.size = buffer_info_.alloc_buffer_info.size;
1273 buffer.handle_id = buffer_info_.alloc_buffer_info.id;
1274 buffer.width = buffer_info_.alloc_buffer_info.aligned_width;
1275 buffer.height = buffer_info_.alloc_buffer_info.aligned_height;
1276 buffer.unaligned_width = fb_config_.x_pixels;
Pullakavi Srinivasdb2b84a2019-11-21 14:47:35 +05301277 buffer.unaligned_height = fb_config_.y_pixels * kBufferHeightFactor;
Pullakavi Srinivas1ae4acb2019-11-18 19:33:45 +05301278 buffer.format = buffer_info_.alloc_buffer_info.format;
1279
1280 Layer *sdm_stitch_target = stitch_target_->GetSDMLayer();
1281 sdm_stitch_target->composition = kCompositionStitchTarget;
1282 sdm_stitch_target->input_buffer = buffer;
1283 sdm_stitch_target->input_buffer.buffer_id = reinterpret_cast<uint64_t>(buffer_info_.private_data);
1284}
1285
1286void HWCDisplayBuiltIn::AppendStitchLayer() {
1287 if (disable_layer_stitch_) {
1288 return;
1289 }
1290
1291 // Append stitch target buffer to layer stack.
1292 Layer *sdm_stitch_target = stitch_target_->GetSDMLayer();
1293 sdm_stitch_target->composition = kCompositionStitchTarget;
Pullakavi Srinivasdb2b84a2019-11-21 14:47:35 +05301294 sdm_stitch_target->dst_rect = {0, 0, FLOAT(fb_config_.x_pixels), FLOAT(fb_config_.y_pixels)};
Pullakavi Srinivas1ae4acb2019-11-18 19:33:45 +05301295 layer_stack_.layers.push_back(sdm_stitch_target);
1296}
1297
Lakshmi Narayana Kalavalae0127eb2019-12-03 11:07:26 -08001298DisplayError HWCDisplayBuiltIn::HistogramEvent(int fd, uint32_t blob_id) {
1299 histogram.notify_histogram_event(fd, blob_id);
1300 return kErrorNone;
1301}
Pullakavi Srinivasdb2b84a2019-11-21 14:47:35 +05301302
1303int HWCDisplayBuiltIn::PostInit() {
1304 auto status = InitLayerStitch();
1305 if (!status) {
1306 DLOGW("Failed to initialize Layer Stitch context");
1307 // Disable layer stitch.
1308 disable_layer_stitch_ = true;
1309 }
1310
1311 return 0;
1312}
1313
Naseer Ahmedb92e73f2016-03-12 02:03:48 -05001314} // namespace sdm