1 /*
2 * Copyright (c) 2014 - 2016, The Linux Foundation. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without modification, are permitted
5 * provided that the following conditions are met:
6 * * Redistributions of source code must retain the above copyright notice, this list of
7 * conditions and the following disclaimer.
8 * * Redistributions in binary form must reproduce the above copyright notice, this list of
9 * conditions and the following disclaimer in the documentation and/or other materials provided
10 * with the distribution.
11 * * Neither the name of The Linux Foundation nor the names of its contributors may be used to
12 * endorse or promote products derived from this software without specific prior written
13 * permission.
14 *
15 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
16 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17 * NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
19 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
20 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
21 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
22 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23 */
24
25 #include <stdio.h>
26 #include <utils/constants.h>
27 #include <utils/debug.h>
28 #include <utils/rect.h>
29
30 #include "display_base.h"
31 #include "hw_info_interface.h"
32
33 #define __CLASS__ "DisplayBase"
34
35 namespace sdm {
36
37 // TODO(user): Have a single structure handle carries all the interface pointers and variables.
DisplayBase(DisplayType display_type,DisplayEventHandler * event_handler,HWDeviceType hw_device_type,BufferSyncHandler * buffer_sync_handler,CompManager * comp_manager,RotatorInterface * rotator_intf,HWInfoInterface * hw_info_intf)38 DisplayBase::DisplayBase(DisplayType display_type, DisplayEventHandler *event_handler,
39 HWDeviceType hw_device_type, BufferSyncHandler *buffer_sync_handler,
40 CompManager *comp_manager, RotatorInterface *rotator_intf,
41 HWInfoInterface *hw_info_intf)
42 : display_type_(display_type), event_handler_(event_handler), hw_device_type_(hw_device_type),
43 buffer_sync_handler_(buffer_sync_handler), comp_manager_(comp_manager),
44 rotator_intf_(rotator_intf), hw_info_intf_(hw_info_intf) {
45 }
46
Init()47 DisplayError DisplayBase::Init() {
48 DisplayError error = kErrorNone;
49 hw_panel_info_ = HWPanelInfo();
50 hw_intf_->GetHWPanelInfo(&hw_panel_info_);
51
52 HWDisplayAttributes display_attrib;
53 uint32_t active_index = 0;
54 hw_intf_->GetActiveConfig(&active_index);
55 hw_intf_->GetDisplayAttributes(active_index, &display_attrib);
56
57 error = comp_manager_->RegisterDisplay(display_type_, display_attrib,
58 hw_panel_info_, &display_comp_ctx_);
59 if (error != kErrorNone) {
60 goto CleanupOnError;
61 }
62
63 if (rotator_intf_) {
64 error = rotator_intf_->RegisterDisplay(display_type_, &display_rotator_ctx_);
65 if (error != kErrorNone) {
66 goto CleanupOnError;
67 }
68 }
69
70 if (hw_info_intf_) {
71 HWResourceInfo hw_resource_info = HWResourceInfo();
72 hw_info_intf_->GetHWResourceInfo(&hw_resource_info);
73 auto max_mixer_stages = hw_resource_info.num_blending_stages;
74 int property_value = Debug::GetMaxPipesPerMixer(display_type_);
75 if (property_value >= 0) {
76 max_mixer_stages = MIN(UINT32(property_value), hw_resource_info.num_blending_stages);
77 }
78 DisplayBase::SetMaxMixerStages(max_mixer_stages);
79 }
80
81 color_mgr_ = ColorManagerProxy::CreateColorManagerProxy(display_type_, hw_intf_,
82 display_attrib, hw_panel_info_);
83 if (!color_mgr_) {
84 DLOGW("Unable to create ColorManagerProxy for display = %d", display_type_);
85 }
86
87 return kErrorNone;
88
89 CleanupOnError:
90 if (display_comp_ctx_) {
91 comp_manager_->UnregisterDisplay(display_comp_ctx_);
92 }
93
94 return error;
95 }
96
Deinit()97 DisplayError DisplayBase::Deinit() {
98 if (rotator_intf_) {
99 rotator_intf_->UnregisterDisplay(display_rotator_ctx_);
100 }
101
102 if (color_mgr_) {
103 delete color_mgr_;
104 color_mgr_ = NULL;
105 }
106
107 comp_manager_->UnregisterDisplay(display_comp_ctx_);
108
109 return kErrorNone;
110 }
111
ValidateGPUTarget(LayerStack * layer_stack)112 DisplayError DisplayBase::ValidateGPUTarget(LayerStack *layer_stack) {
113 uint32_t i = 0;
114 Layer *layers = layer_stack->layers;
115
116 // TODO(user): Remove this check once we have query display attributes on virtual display
117 if (display_type_ == kVirtual) {
118 return kErrorNone;
119 }
120
121 while (i < layer_stack->layer_count && (layers[i].composition != kCompositionGPUTarget)) {
122 i++;
123 }
124
125 if (i >= layer_stack->layer_count) {
126 DLOGE("Either layer count is zero or GPU target layer is not present");
127 return kErrorParameters;
128 }
129
130 uint32_t gpu_target_index = i;
131
132 // Check GPU target layer
133 Layer &gpu_target_layer = layer_stack->layers[gpu_target_index];
134
135 if (!IsValid(gpu_target_layer.src_rect)) {
136 DLOGE("Invalid src rect for GPU target layer");
137 return kErrorParameters;
138 }
139
140 if (!IsValid(gpu_target_layer.dst_rect)) {
141 DLOGE("Invalid dst rect for GPU target layer");
142 return kErrorParameters;
143 }
144
145 auto gpu_target_layer_dst_xpixels = gpu_target_layer.dst_rect.right;
146 auto gpu_target_layer_dst_ypixels = gpu_target_layer.dst_rect.bottom;
147
148 HWDisplayAttributes display_attrib;
149 uint32_t active_index = 0;
150 hw_intf_->GetActiveConfig(&active_index);
151 hw_intf_->GetDisplayAttributes(active_index, &display_attrib);
152
153 if (gpu_target_layer_dst_xpixels > display_attrib.x_pixels ||
154 gpu_target_layer_dst_ypixels > display_attrib.y_pixels) {
155 DLOGE("GPU target layer dst rect is not with in limits");
156 return kErrorParameters;
157 }
158
159 return kErrorNone;
160 }
161
Prepare(LayerStack * layer_stack)162 DisplayError DisplayBase::Prepare(LayerStack *layer_stack) {
163 DisplayError error = kErrorNone;
164 bool disable_partial_update = false;
165 uint32_t pending = 0;
166
167 if (!layer_stack) {
168 return kErrorParameters;
169 }
170
171 pending_commit_ = false;
172
173 error = ValidateGPUTarget(layer_stack);
174 if (error != kErrorNone) {
175 return error;
176 }
177
178 if (!active_) {
179 return kErrorPermission;
180 }
181
182 // Request to disable partial update only if it is currently enabled.
183 if (color_mgr_ && partial_update_control_) {
184 disable_partial_update = color_mgr_->NeedsPartialUpdateDisable();
185 if (disable_partial_update) {
186 ControlPartialUpdate(false, &pending);
187 }
188 }
189
190 // Clean hw layers for reuse.
191 hw_layers_ = HWLayers();
192 hw_layers_.info.stack = layer_stack;
193 hw_layers_.output_compression = 1.0f;
194
195 comp_manager_->PrePrepare(display_comp_ctx_, &hw_layers_);
196 while (true) {
197 error = comp_manager_->Prepare(display_comp_ctx_, &hw_layers_);
198 if (error != kErrorNone) {
199 break;
200 }
201
202 if (IsRotationRequired(&hw_layers_)) {
203 if (!rotator_intf_) {
204 continue;
205 }
206 error = rotator_intf_->Prepare(display_rotator_ctx_, &hw_layers_);
207 } else {
208 // Release all the previous rotator sessions.
209 if (rotator_intf_) {
210 error = rotator_intf_->Purge(display_rotator_ctx_);
211 }
212 }
213
214 if (error == kErrorNone) {
215 error = hw_intf_->Validate(&hw_layers_);
216 if (error == kErrorNone) {
217 // Strategy is successful now, wait for Commit().
218 pending_commit_ = true;
219 break;
220 }
221 if (error == kErrorShutDown) {
222 comp_manager_->PostPrepare(display_comp_ctx_, &hw_layers_);
223 return error;
224 }
225 }
226 }
227
228 comp_manager_->PostPrepare(display_comp_ctx_, &hw_layers_);
229 if (disable_partial_update) {
230 ControlPartialUpdate(true, &pending);
231 }
232
233 return error;
234 }
235
Commit(LayerStack * layer_stack)236 DisplayError DisplayBase::Commit(LayerStack *layer_stack) {
237 DisplayError error = kErrorNone;
238
239 if (!layer_stack) {
240 return kErrorParameters;
241 }
242
243 if (!active_) {
244 return kErrorPermission;
245 }
246
247 if (!pending_commit_) {
248 DLOGE("Commit: Corresponding Prepare() is not called for display = %d", display_type_);
249 return kErrorUndefined;
250 }
251
252 pending_commit_ = false;
253
254 // Layer stack attributes has changed, need to Reconfigure, currently in use for Hybrid Comp
255 if (layer_stack->flags.attributes_changed) {
256 error = comp_manager_->ReConfigure(display_comp_ctx_, &hw_layers_);
257 if (error != kErrorNone) {
258 return error;
259 }
260
261 error = hw_intf_->Validate(&hw_layers_);
262 if (error != kErrorNone) {
263 return error;
264 }
265 }
266
267 if (rotator_intf_ && IsRotationRequired(&hw_layers_)) {
268 error = rotator_intf_->Commit(display_rotator_ctx_, &hw_layers_);
269 if (error != kErrorNone) {
270 return error;
271 }
272 }
273
274 // check if feature list cache is dirty and pending.
275 // If dirty, need program to hardware blocks.
276 if (color_mgr_)
277 error = color_mgr_->Commit();
278 if (error != kErrorNone) { // won't affect this execution path.
279 DLOGW("ColorManager::Commit(...) isn't working");
280 }
281
282 error = hw_intf_->Commit(&hw_layers_);
283 if (error != kErrorNone) {
284 return error;
285 }
286
287 if (rotator_intf_ && IsRotationRequired(&hw_layers_)) {
288 error = rotator_intf_->PostCommit(display_rotator_ctx_, &hw_layers_);
289 if (error != kErrorNone) {
290 return error;
291 }
292 }
293
294 error = comp_manager_->PostCommit(display_comp_ctx_, &hw_layers_);
295 if (error != kErrorNone) {
296 return error;
297 }
298
299 return kErrorNone;
300 }
301
Flush()302 DisplayError DisplayBase::Flush() {
303 DisplayError error = kErrorNone;
304
305 if (!active_) {
306 return kErrorPermission;
307 }
308
309 hw_layers_.info.count = 0;
310 error = hw_intf_->Flush();
311 if (error == kErrorNone) {
312 // Release all the rotator sessions.
313 if (rotator_intf_) {
314 error = rotator_intf_->Purge(display_rotator_ctx_);
315 if (error != kErrorNone) {
316 DLOGE("Rotator purge failed for display %d", display_type_);
317 return error;
318 }
319 }
320
321 comp_manager_->Purge(display_comp_ctx_);
322
323 pending_commit_ = false;
324 } else {
325 DLOGW("Unable to flush display = %d", display_type_);
326 }
327
328 return error;
329 }
330
GetDisplayState(DisplayState * state)331 DisplayError DisplayBase::GetDisplayState(DisplayState *state) {
332 if (!state) {
333 return kErrorParameters;
334 }
335
336 *state = state_;
337 return kErrorNone;
338 }
339
GetNumVariableInfoConfigs(uint32_t * count)340 DisplayError DisplayBase::GetNumVariableInfoConfigs(uint32_t *count) {
341 return hw_intf_->GetNumDisplayAttributes(count);
342 }
343
GetConfig(uint32_t index,DisplayConfigVariableInfo * variable_info)344 DisplayError DisplayBase::GetConfig(uint32_t index, DisplayConfigVariableInfo *variable_info) {
345 HWDisplayAttributes attrib;
346 if (hw_intf_->GetDisplayAttributes(index, &attrib) == kErrorNone) {
347 *variable_info = attrib;
348 return kErrorNone;
349 }
350
351 return kErrorNotSupported;
352 }
353
GetActiveConfig(uint32_t * index)354 DisplayError DisplayBase::GetActiveConfig(uint32_t *index) {
355 return hw_intf_->GetActiveConfig(index);
356 }
357
GetVSyncState(bool * enabled)358 DisplayError DisplayBase::GetVSyncState(bool *enabled) {
359 if (!enabled) {
360 return kErrorParameters;
361 }
362
363 *enabled = vsync_enable_;
364
365 return kErrorNone;
366 }
367
IsUnderscanSupported()368 bool DisplayBase::IsUnderscanSupported() {
369 return underscan_supported_;
370 }
371
SetDisplayState(DisplayState state)372 DisplayError DisplayBase::SetDisplayState(DisplayState state) {
373 DisplayError error = kErrorNone;
374 bool active = false;
375
376 DLOGI("Set state = %d, display %d", state, display_type_);
377
378 if (state == state_) {
379 DLOGI("Same state transition is requested.");
380 return kErrorNone;
381 }
382
383 switch (state) {
384 case kStateOff:
385 hw_layers_.info.count = 0;
386 error = hw_intf_->Flush();
387 if (error == kErrorNone) {
388 // Release all the rotator sessions.
389 if (rotator_intf_) {
390 error = rotator_intf_->Purge(display_rotator_ctx_);
391 if (error != kErrorNone) {
392 DLOGE("Rotator purge failed for display %d", display_type_);
393 return error;
394 }
395 }
396
397 comp_manager_->Purge(display_comp_ctx_);
398
399 error = hw_intf_->PowerOff();
400 }
401 break;
402
403 case kStateOn:
404 error = hw_intf_->PowerOn();
405 active = true;
406 break;
407
408 case kStateDoze:
409 error = hw_intf_->Doze();
410 active = true;
411 break;
412
413 case kStateDozeSuspend:
414 error = hw_intf_->DozeSuspend();
415 break;
416
417 case kStateStandby:
418 error = hw_intf_->Standby();
419 break;
420
421 default:
422 DLOGE("Spurious state = %d transition requested.", state);
423 break;
424 }
425
426 if (error == kErrorNone) {
427 active_ = active;
428 state_ = state;
429 }
430
431 return error;
432 }
433
SetActiveConfig(uint32_t index)434 DisplayError DisplayBase::SetActiveConfig(uint32_t index) {
435 DisplayError error = kErrorNone;
436 uint32_t active_index = 0;
437
438 hw_intf_->GetActiveConfig(&active_index);
439
440 if (active_index == index) {
441 return kErrorNone;
442 }
443
444 error = hw_intf_->SetDisplayAttributes(index);
445 if (error != kErrorNone) {
446 return error;
447 }
448
449 HWDisplayAttributes attrib;
450 error = hw_intf_->GetDisplayAttributes(index, &attrib);
451 if (error != kErrorNone) {
452 return error;
453 }
454
455 if (display_comp_ctx_) {
456 comp_manager_->UnregisterDisplay(display_comp_ctx_);
457 }
458
459 error = comp_manager_->RegisterDisplay(display_type_, attrib, hw_panel_info_,
460 &display_comp_ctx_);
461
462 return error;
463 }
464
SetMaxMixerStages(uint32_t max_mixer_stages)465 DisplayError DisplayBase::SetMaxMixerStages(uint32_t max_mixer_stages) {
466 DisplayError error = kErrorNone;
467
468 error = comp_manager_->SetMaxMixerStages(display_comp_ctx_, max_mixer_stages);
469
470 if (error == kErrorNone) {
471 max_mixer_stages_ = max_mixer_stages;
472 }
473
474 return error;
475 }
476
ControlPartialUpdate(bool enable,uint32_t * pending)477 DisplayError DisplayBase::ControlPartialUpdate(bool enable, uint32_t *pending) {
478 if (!pending) {
479 return kErrorParameters;
480 }
481
482 if (!hw_panel_info_.partial_update) {
483 // Nothing to be done.
484 DLOGI("partial update is not applicable for display=%d", display_type_);
485 return kErrorNotSupported;
486 }
487
488 *pending = 0;
489 if (enable == partial_update_control_) {
490 DLOGI("Same state transition is requested.");
491 return kErrorNone;
492 }
493
494 partial_update_control_ = enable;
495 comp_manager_->ControlPartialUpdate(display_comp_ctx_, enable);
496
497 if (!enable) {
498 // If the request is to turn off feature, new draw call is required to have
499 // the new setting into effect.
500 *pending = 1;
501 }
502
503 return kErrorNone;
504 }
505
SetDisplayMode(uint32_t mode)506 DisplayError DisplayBase::SetDisplayMode(uint32_t mode) {
507 return kErrorNotSupported;
508 }
509
IsScalingValid(const LayerRect & crop,const LayerRect & dst,bool rotate90)510 DisplayError DisplayBase::IsScalingValid(const LayerRect &crop, const LayerRect &dst,
511 bool rotate90) {
512 return comp_manager_->ValidateScaling(crop, dst, rotate90);
513 }
514
SetPanelBrightness(int level)515 DisplayError DisplayBase::SetPanelBrightness(int level) {
516 return kErrorNotSupported;
517 }
518
OnMinHdcpEncryptionLevelChange(uint32_t min_enc_level)519 DisplayError DisplayBase::OnMinHdcpEncryptionLevelChange(uint32_t min_enc_level) {
520 return kErrorNotSupported;
521 }
522
AppendDump(char * buffer,uint32_t length)523 void DisplayBase::AppendDump(char *buffer, uint32_t length) {
524 HWDisplayAttributes attrib;
525 uint32_t active_index = 0;
526 uint32_t num_modes = 0;
527 hw_intf_->GetNumDisplayAttributes(&num_modes);
528 hw_intf_->GetActiveConfig(&active_index);
529 hw_intf_->GetDisplayAttributes(active_index, &attrib);
530
531 DumpImpl::AppendString(buffer, length, "\n-----------------------");
532 DumpImpl::AppendString(buffer, length, "\ndevice type: %u", display_type_);
533 DumpImpl::AppendString(buffer, length, "\nstate: %u, vsync on: %u, max. mixer stages: %u",
534 state_, INT(vsync_enable_), max_mixer_stages_);
535 DumpImpl::AppendString(buffer, length, "\nnum configs: %u, active config index: %u",
536 num_modes, active_index);
537
538 DisplayConfigVariableInfo &info = attrib;
539
540 uint32_t num_hw_layers = 0;
541 if (hw_layers_.info.stack) {
542 num_hw_layers = hw_layers_.info.count;
543 }
544
545 if (num_hw_layers == 0) {
546 DumpImpl::AppendString(buffer, length, "\nNo hardware layers programmed");
547 return;
548 }
549
550 LayerBuffer *out_buffer = hw_layers_.info.stack->output_buffer;
551 if (out_buffer) {
552 DumpImpl::AppendString(buffer, length, "\nres:%u x %u format: %s", out_buffer->width,
553 out_buffer->height, GetName(out_buffer->format));
554 } else {
555 DumpImpl::AppendString(buffer, length, "\nres:%u x %u, dpi:%.2f x %.2f, fps:%u,"
556 "vsync period: %u", info.x_pixels, info.y_pixels, info.x_dpi,
557 info.y_dpi, info.fps, info.vsync_period_ns);
558 }
559
560 DumpImpl::AppendString(buffer, length, "\n");
561
562 HWLayersInfo &layer_info = hw_layers_.info;
563 LayerRect &l_roi = layer_info.left_partial_update;
564 LayerRect &r_roi = layer_info.right_partial_update;
565 DumpImpl::AppendString(buffer, length, "\nROI(L T R B) : LEFT(%d %d %d %d)", INT(l_roi.left),
566 INT(l_roi.top), INT(l_roi.right), INT(l_roi.bottom));
567
568 if (IsValid(r_roi)) {
569 DumpImpl::AppendString(buffer, length, ", RIGHT(%d %d %d %d)", INT(r_roi.left),
570 INT(r_roi.top), INT(r_roi.right), INT(r_roi.bottom));
571 }
572
573 const char *header = "\n| Idx | Comp Type | Split | WB | Pipe | W x H | Format | Src Rect (L T R B) | Dst Rect (L T R B) | Z | Flags | Deci(HxV) | CS |"; //NOLINT
574 const char *newline = "\n|-----|-------------|--------|----|-------|-------------|--------------------------|---------------------|---------------------|----|------------|-----------|----|"; //NOLINT
575 const char *format = "\n| %3s | %11s " "| %6s " "| %2s | 0x%03x | %4d x %4d | %24s " "| %4d %4d %4d %4d " "| %4d %4d %4d %4d " "| %2s | %10s " "| %9s | %2s |"; //NOLINT
576
577 DumpImpl::AppendString(buffer, length, "\n");
578 DumpImpl::AppendString(buffer, length, newline);
579 DumpImpl::AppendString(buffer, length, header);
580 DumpImpl::AppendString(buffer, length, newline);
581
582 for (uint32_t i = 0; i < num_hw_layers; i++) {
583 uint32_t layer_index = hw_layers_.info.index[i];
584 Layer &layer = hw_layers_.info.stack->layers[layer_index];
585 LayerBuffer *input_buffer = layer.input_buffer;
586 HWLayerConfig &layer_config = hw_layers_.config[i];
587 HWRotatorSession &hw_rotator_session = layer_config.hw_rotator_session;
588
589 char idx[8] = { 0 };
590 const char *comp_type = GetName(layer.composition);
591 const char *buffer_format = GetName(input_buffer->format);
592 const char *rotate_split[2] = { "Rot-1", "Rot-2" };
593 const char *comp_split[2] = { "Comp-1", "Comp-2" };
594
595 snprintf(idx, sizeof(idx), "%d", layer_index);
596
597 for (uint32_t count = 0; count < hw_rotator_session.hw_block_count; count++) {
598 char writeback_id[8] = { 0 };
599 HWRotateInfo &rotate = hw_rotator_session.hw_rotate_info[count];
600 LayerRect &src_roi = rotate.src_roi;
601 LayerRect &dst_roi = rotate.dst_roi;
602
603 snprintf(writeback_id, sizeof(writeback_id), "%d", rotate.writeback_id);
604
605 DumpImpl::AppendString(buffer, length, format, idx, comp_type, rotate_split[count],
606 writeback_id, rotate.pipe_id, input_buffer->width,
607 input_buffer->height, buffer_format, INT(src_roi.left),
608 INT(src_roi.top), INT(src_roi.right), INT(src_roi.bottom),
609 INT(dst_roi.left), INT(dst_roi.top), INT(dst_roi.right),
610 INT(dst_roi.bottom), "-", "- ", "- ", "-");
611
612 // print the below only once per layer block, fill with spaces for rest.
613 idx[0] = 0;
614 comp_type = "";
615 }
616
617 if (hw_rotator_session.hw_block_count > 0) {
618 input_buffer = &hw_rotator_session.output_buffer;
619 buffer_format = GetName(input_buffer->format);
620 }
621
622 for (uint32_t count = 0; count < 2; count++) {
623 char decimation[16] = { 0 };
624 char flags[16] = { 0 };
625 char z_order[8] = { 0 };
626 char csc[8] = { 0 };
627
628 HWPipeInfo &pipe = (count == 0) ? layer_config.left_pipe : layer_config.right_pipe;
629
630 if (!pipe.valid) {
631 continue;
632 }
633
634 LayerRect &src_roi = pipe.src_roi;
635 LayerRect &dst_roi = pipe.dst_roi;
636
637 snprintf(z_order, sizeof(z_order), "%d", pipe.z_order);
638 snprintf(flags, sizeof(flags), "0x%08x", layer.flags.flags);
639 snprintf(decimation, sizeof(decimation), "%3d x %3d", pipe.horizontal_decimation,
640 pipe.vertical_decimation);
641 snprintf(csc, sizeof(csc), "%d", layer.csc);
642
643 DumpImpl::AppendString(buffer, length, format, idx, comp_type, comp_split[count],
644 "-", pipe.pipe_id, input_buffer->width, input_buffer->height,
645 buffer_format, INT(src_roi.left), INT(src_roi.top),
646 INT(src_roi.right), INT(src_roi.bottom), INT(dst_roi.left),
647 INT(dst_roi.top), INT(dst_roi.right), INT(dst_roi.bottom),
648 z_order, flags, decimation, csc);
649
650 // print the below only once per layer block, fill with spaces for rest.
651 idx[0] = 0;
652 comp_type = "";
653 }
654
655 DumpImpl::AppendString(buffer, length, newline);
656 }
657 }
658
IsRotationRequired(HWLayers * hw_layers)659 bool DisplayBase::IsRotationRequired(HWLayers *hw_layers) {
660 HWLayersInfo &layer_info = hw_layers->info;
661
662 for (uint32_t i = 0; i < layer_info.count; i++) {
663 HWRotatorSession *hw_rotator_session = &hw_layers->config[i].hw_rotator_session;
664
665 if (hw_rotator_session->hw_block_count) {
666 return true;
667 }
668 }
669
670 return false;
671 }
672
GetName(const LayerComposition & composition)673 const char * DisplayBase::GetName(const LayerComposition &composition) {
674 switch (composition) {
675 case kCompositionGPU: return "GPU";
676 case kCompositionSDE: return "SDE";
677 case kCompositionHWCursor: return "CURSOR";
678 case kCompositionHybrid: return "HYBRID";
679 case kCompositionBlit: return "BLIT";
680 case kCompositionGPUTarget: return "GPU_TARGET";
681 case kCompositionBlitTarget: return "BLIT_TARGET";
682 default: return "UNKNOWN";
683 }
684 }
685
GetName(const LayerBufferFormat & format)686 const char * DisplayBase::GetName(const LayerBufferFormat &format) {
687 switch (format) {
688 case kFormatARGB8888: return "ARGB_8888";
689 case kFormatRGBA8888: return "RGBA_8888";
690 case kFormatBGRA8888: return "BGRA_8888";
691 case kFormatXRGB8888: return "XRGB_8888";
692 case kFormatRGBX8888: return "RGBX_8888";
693 case kFormatBGRX8888: return "BGRX_8888";
694 case kFormatRGBA5551: return "RGBA_5551";
695 case kFormatRGBA4444: return "RGBA_4444";
696 case kFormatRGB888: return "RGB_888";
697 case kFormatBGR888: return "BGR_888";
698 case kFormatRGB565: return "RGB_565";
699 case kFormatBGR565: return "BGR_565";
700 case kFormatRGBA8888Ubwc: return "RGBA_8888_UBWC";
701 case kFormatRGBX8888Ubwc: return "RGBX_8888_UBWC";
702 case kFormatBGR565Ubwc: return "BGR_565_UBWC";
703 case kFormatYCbCr420Planar: return "Y_CB_CR_420";
704 case kFormatYCrCb420Planar: return "Y_CR_CB_420";
705 case kFormatYCrCb420PlanarStride16: return "Y_CR_CB_420_STRIDE16";
706 case kFormatYCbCr420SemiPlanar: return "Y_CBCR_420";
707 case kFormatYCrCb420SemiPlanar: return "Y_CRCB_420";
708 case kFormatYCbCr420SemiPlanarVenus: return "Y_CBCR_420_VENUS";
709 case kFormatYCrCb420SemiPlanarVenus: return "Y_CRCB_420_VENUS";
710 case kFormatYCbCr422H1V2SemiPlanar: return "Y_CBCR_422_H1V2";
711 case kFormatYCrCb422H1V2SemiPlanar: return "Y_CRCB_422_H1V2";
712 case kFormatYCbCr422H2V1SemiPlanar: return "Y_CBCR_422_H2V1";
713 case kFormatYCrCb422H2V1SemiPlanar: return "Y_CRCB_422_H2V2";
714 case kFormatYCbCr420SPVenusUbwc: return "Y_CBCR_420_VENUS_UBWC";
715 case kFormatYCbCr422H2V1Packed: return "YCBYCR_422_H2V1";
716 case kFormatRGBA1010102: return "RGBA_1010102";
717 case kFormatARGB2101010: return "ARGB_2101010";
718 case kFormatRGBX1010102: return "RGBX_1010102";
719 case kFormatXRGB2101010: return "XRGB_2101010";
720 case kFormatBGRA1010102: return "BGRA_1010102";
721 case kFormatABGR2101010: return "ABGR_2101010";
722 case kFormatBGRX1010102: return "BGRX_1010102";
723 case kFormatXBGR2101010: return "XBGR_2101010";
724 case kFormatRGBA1010102Ubwc: return "RGBA_1010102_UBWC";
725 case kFormatRGBX1010102Ubwc: return "RGBX_1010102_UBWC";
726 case kFormatYCbCr420P010: return "Y_CBCR_420_P010";
727 case kFormatYCbCr420TP10Ubwc: return "Y_CBCR_420_TP10_UBWC";
728 default: return "UNKNOWN";
729 }
730 }
731
ColorSVCRequestRoute(const PPDisplayAPIPayload & in_payload,PPDisplayAPIPayload * out_payload,PPPendingParams * pending_action)732 DisplayError DisplayBase::ColorSVCRequestRoute(const PPDisplayAPIPayload &in_payload,
733 PPDisplayAPIPayload *out_payload,
734 PPPendingParams *pending_action) {
735 if (color_mgr_)
736 return color_mgr_->ColorSVCRequestRoute(in_payload, out_payload, pending_action);
737 else
738 return kErrorParameters;
739 }
740
ApplyDefaultDisplayMode()741 DisplayError DisplayBase::ApplyDefaultDisplayMode() {
742 if (color_mgr_)
743 return color_mgr_->ApplyDefaultDisplayMode();
744 else
745 return kErrorParameters;
746 }
747
SetCursorPosition(int x,int y)748 DisplayError DisplayBase::SetCursorPosition(int x, int y) {
749 if (state_ != kStateOn) {
750 return kErrorNotSupported;
751 }
752
753 DisplayError error = comp_manager_->ValidateCursorPosition(display_comp_ctx_, &hw_layers_, x, y);
754 if (error == kErrorNone) {
755 return hw_intf_->SetCursorPosition(&hw_layers_, x, y);
756 }
757
758 return kErrorNone;
759 }
760
GetRefreshRateRange(uint32_t * min_refresh_rate,uint32_t * max_refresh_rate)761 DisplayError DisplayBase::GetRefreshRateRange(uint32_t *min_refresh_rate,
762 uint32_t *max_refresh_rate) {
763 // The min and max refresh rates will be same when the HWPanelInfo does not contain valid rates.
764 // Usually for secondary displays, command mode panels
765 HWDisplayAttributes display_attributes;
766 uint32_t active_index = 0;
767 hw_intf_->GetActiveConfig(&active_index);
768 DisplayError error = hw_intf_->GetDisplayAttributes(active_index, &display_attributes);
769 if (error) {
770 return error;
771 }
772
773 *min_refresh_rate = display_attributes.fps;
774 *max_refresh_rate = display_attributes.fps;
775
776 return error;
777 }
778
GetPanelBrightness(int * level)779 DisplayError DisplayBase::GetPanelBrightness(int *level) {
780 return kErrorNotSupported;
781 }
782
783 } // namespace sdm
784