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 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 <math.h> 31 #include <errno.h> 32 #include <gralloc_priv.h> 33 #include <gr.h> 34 #include <utils/constants.h> 35 #include <utils/formats.h> 36 #include <utils/rect.h> 37 #include <utils/debug.h> 38 #include <sync/sync.h> 39 #include <cutils/properties.h> 40 #include <map> 41 #include <utility> 42 #include <vector> 43 44 #include "hwc_display.h" 45 #include "hwc_debugger.h" 46 #include "blit_engine_c2d.h" 47 48 #ifdef QTI_BSP 49 #include <hardware/display_defs.h> 50 #endif 51 52 #define __CLASS__ "HWCDisplay" 53 54 namespace sdm { 55 56 static void ApplyDeInterlaceAdjustment(Layer *layer) { 57 // De-interlacing adjustment 58 if (layer->input_buffer->flags.interlace) { 59 float height = (layer->src_rect.bottom - layer->src_rect.top) / 2.0f; 60 layer->src_rect.top = ROUND_UP_ALIGN_DOWN(layer->src_rect.top / 2.0f, 2); 61 layer->src_rect.bottom = layer->src_rect.top + floorf(height); 62 } 63 } 64 65 HWCDisplay::HWCDisplay(CoreInterface *core_intf, hwc_procs_t const **hwc_procs, DisplayType type, 66 int id, bool needs_blit, qService::QService *qservice, 67 DisplayClass display_class) 68 : core_intf_(core_intf), hwc_procs_(hwc_procs), type_(type), id_(id), needs_blit_(needs_blit), 69 qservice_(qservice), display_class_(display_class) { 70 } 71 72 int HWCDisplay::Init() { 73 DisplayError error = core_intf_->CreateDisplay(type_, this, &display_intf_); 74 if (error != kErrorNone) { 75 DLOGE("Display create failed. Error = %d display_type %d event_handler %p disp_intf %p", 76 error, type_, this, &display_intf_); 77 return -EINVAL; 78 } 79 80 int property_swap_interval = 1; 81 HWCDebugHandler::Get()->GetProperty("debug.egl.swapinterval", &property_swap_interval); 82 if (property_swap_interval == 0) { 83 swap_interval_zero_ = true; 84 } 85 86 int blit_enabled = 0; 87 HWCDebugHandler::Get()->GetProperty("persist.hwc.blit.comp", &blit_enabled); 88 if (needs_blit_ && blit_enabled) { 89 blit_engine_ = new BlitEngineC2d(); 90 if (!blit_engine_) { 91 DLOGI("Create Blit Engine C2D failed"); 92 } else { 93 if (blit_engine_->Init() < 0) { 94 DLOGI("Blit Engine Init failed, Blit Composition will not be used!!"); 95 delete blit_engine_; 96 blit_engine_ = NULL; 97 } 98 } 99 } 100 101 display_intf_->GetRefreshRateRange(&min_refresh_rate_, &max_refresh_rate_); 102 current_refresh_rate_ = max_refresh_rate_; 103 104 s3d_format_hwc_to_sdm_.insert(std::pair<int, LayerBufferS3DFormat>(HAL_NO_3D, kS3dFormatNone)); 105 s3d_format_hwc_to_sdm_.insert(std::pair<int, LayerBufferS3DFormat>(HAL_3D_SIDE_BY_SIDE_L_R, 106 kS3dFormatLeftRight)); 107 s3d_format_hwc_to_sdm_.insert(std::pair<int, LayerBufferS3DFormat>(HAL_3D_SIDE_BY_SIDE_R_L, 108 kS3dFormatRightLeft)); 109 s3d_format_hwc_to_sdm_.insert(std::pair<int, LayerBufferS3DFormat>(HAL_3D_TOP_BOTTOM, 110 kS3dFormatTopBottom)); 111 112 disable_animation_ = Debug::IsExtAnimDisabled(); 113 114 return 0; 115 } 116 117 int HWCDisplay::Deinit() { 118 DisplayError error = core_intf_->DestroyDisplay(display_intf_); 119 if (error != kErrorNone) { 120 DLOGE("Display destroy failed. Error = %d", error); 121 return -EINVAL; 122 } 123 124 if (blit_engine_) { 125 blit_engine_->DeInit(); 126 delete blit_engine_; 127 blit_engine_ = NULL; 128 } 129 130 return 0; 131 } 132 133 int HWCDisplay::EventControl(int event, int enable) { 134 DisplayError error = kErrorNone; 135 136 if (shutdown_pending_) { 137 return 0; 138 } 139 140 switch (event) { 141 case HWC_EVENT_VSYNC: 142 error = display_intf_->SetVSyncState(enable); 143 break; 144 default: 145 DLOGW("Unsupported event = %d", event); 146 } 147 148 if (error != kErrorNone) { 149 if (error == kErrorShutDown) { 150 shutdown_pending_ = true; 151 return 0; 152 } 153 DLOGE("Failed. event = %d, enable = %d, error = %d", event, enable, error); 154 return -EINVAL; 155 } 156 157 return 0; 158 } 159 160 int HWCDisplay::SetPowerMode(int mode) { 161 DLOGI("display = %d, mode = %d", id_, mode); 162 DisplayState state = kStateOff; 163 bool flush_on_error = flush_on_error_; 164 165 if (shutdown_pending_) { 166 return 0; 167 } 168 169 switch (mode) { 170 case HWC_POWER_MODE_OFF: 171 // During power off, all of the buffers are released. 172 // Do not flush until a buffer is successfully submitted again. 173 flush_on_error = false; 174 state = kStateOff; 175 break; 176 177 case HWC_POWER_MODE_NORMAL: 178 state = kStateOn; 179 last_power_mode_ = HWC_POWER_MODE_NORMAL; 180 break; 181 182 case HWC_POWER_MODE_DOZE: 183 state = kStateDoze; 184 last_power_mode_ = HWC_POWER_MODE_DOZE; 185 break; 186 187 case HWC_POWER_MODE_DOZE_SUSPEND: 188 state = kStateDozeSuspend; 189 last_power_mode_ = HWC_POWER_MODE_DOZE_SUSPEND; 190 break; 191 192 default: 193 return -EINVAL; 194 } 195 196 DisplayError error = display_intf_->SetDisplayState(state); 197 if (error == kErrorNone) { 198 flush_on_error_ = flush_on_error; 199 } else { 200 if (error == kErrorShutDown) { 201 shutdown_pending_ = true; 202 return 0; 203 } 204 DLOGE("Set state failed. Error = %d", error); 205 return -EINVAL; 206 } 207 208 return 0; 209 } 210 211 int HWCDisplay::GetDisplayConfigs(uint32_t *configs, size_t *num_configs) { 212 if (*num_configs > 0) { 213 configs[0] = 0; 214 *num_configs = 1; 215 } 216 217 return 0; 218 } 219 220 int HWCDisplay::GetDisplayAttributes(uint32_t config, const uint32_t *display_attributes, 221 int32_t *values) { 222 DisplayConfigVariableInfo variable_config; 223 DisplayError error = display_intf_->GetFrameBufferConfig(&variable_config); 224 if (error != kErrorNone) { 225 DLOGV("Get variable config failed. Error = %d", error); 226 return -EINVAL; 227 } 228 229 for (int i = 0; display_attributes[i] != HWC_DISPLAY_NO_ATTRIBUTE; i++) { 230 switch (display_attributes[i]) { 231 case HWC_DISPLAY_VSYNC_PERIOD: 232 values[i] = INT32(variable_config.vsync_period_ns); 233 break; 234 case HWC_DISPLAY_WIDTH: 235 values[i] = INT32(variable_config.x_pixels); 236 break; 237 case HWC_DISPLAY_HEIGHT: 238 values[i] = INT32(variable_config.y_pixels); 239 break; 240 case HWC_DISPLAY_DPI_X: 241 values[i] = INT32(variable_config.x_dpi * 1000.0f); 242 break; 243 case HWC_DISPLAY_DPI_Y: 244 values[i] = INT32(variable_config.y_dpi * 1000.0f); 245 break; 246 default: 247 DLOGW("Spurious attribute type = %d", display_attributes[i]); 248 return -EINVAL; 249 } 250 } 251 252 return 0; 253 } 254 255 int HWCDisplay::GetActiveConfig() { 256 return 0; 257 } 258 259 int HWCDisplay::SetActiveConfig(int index) { 260 return -1; 261 } 262 263 DisplayError HWCDisplay::SetMixerResolution(uint32_t width, uint32_t height) { 264 return kErrorNotSupported; 265 } 266 267 void HWCDisplay::SetFrameDumpConfig(uint32_t count, uint32_t bit_mask_layer_type) { 268 dump_frame_count_ = count; 269 dump_frame_index_ = 0; 270 dump_input_layers_ = ((bit_mask_layer_type & (1 << INPUT_LAYER_DUMP)) != 0); 271 272 if (blit_engine_) { 273 blit_engine_->SetFrameDumpConfig(count); 274 } 275 276 DLOGI("num_frame_dump %d, input_layer_dump_enable %d", dump_frame_count_, dump_input_layers_); 277 } 278 279 uint32_t HWCDisplay::GetLastPowerMode() { 280 return last_power_mode_; 281 } 282 283 DisplayError HWCDisplay::VSync(const DisplayEventVSync &vsync) { 284 const hwc_procs_t *hwc_procs = *hwc_procs_; 285 286 if (!hwc_procs) { 287 return kErrorParameters; 288 } 289 290 hwc_procs->vsync(hwc_procs, id_, vsync.timestamp); 291 292 return kErrorNone; 293 } 294 295 DisplayError HWCDisplay::Refresh() { 296 return kErrorNotSupported; 297 } 298 299 DisplayError HWCDisplay::CECMessage(char *message) { 300 if (qservice_) { 301 qservice_->onCECMessageReceived(message, 0); 302 } else { 303 DLOGW("Qservice instance not available."); 304 } 305 306 return kErrorNone; 307 } 308 309 int HWCDisplay::AllocateLayerStack(hwc_display_contents_1_t *content_list) { 310 if (!content_list || !content_list->numHwLayers) { 311 DLOGW("Invalid content list"); 312 return -EINVAL; 313 } 314 315 size_t num_hw_layers = content_list->numHwLayers; 316 uint32_t blit_target_count = 0; 317 318 if (blit_engine_) { 319 blit_target_count = kMaxBlitTargetLayers; 320 } 321 322 FreeLayerStack(); 323 324 for (size_t i = 0; i < num_hw_layers + blit_target_count; i++) { 325 Layer *layer = new Layer(); 326 LayerBuffer *layer_buffer = new LayerBuffer(); 327 layer->input_buffer = layer_buffer; 328 layer_stack_.layers.push_back(layer); 329 } 330 331 return 0; 332 } 333 334 void HWCDisplay::FreeLayerStack() { 335 for (Layer *layer : layer_stack_.layers) { 336 delete layer->input_buffer; 337 delete layer; 338 } 339 layer_stack_ = {}; 340 } 341 342 int HWCDisplay::PrepareLayerParams(hwc_layer_1_t *hwc_layer, Layer* layer) { 343 const private_handle_t *pvt_handle = static_cast<const private_handle_t *>(hwc_layer->handle); 344 345 LayerBuffer *layer_buffer = layer->input_buffer; 346 347 if (pvt_handle) { 348 layer_buffer->format = GetSDMFormat(pvt_handle->format, pvt_handle->flags); 349 int aligned_width, aligned_height; 350 int unaligned_width, unaligned_height; 351 352 AdrenoMemInfo::getInstance().getAlignedWidthAndHeight(pvt_handle, aligned_width, 353 aligned_height); 354 AdrenoMemInfo::getInstance().getUnalignedWidthAndHeight(pvt_handle, unaligned_width, 355 unaligned_height); 356 357 layer_buffer->width = UINT32(aligned_width); 358 layer_buffer->height = UINT32(aligned_height); 359 layer_buffer->unaligned_width = UINT32(unaligned_width); 360 layer_buffer->unaligned_height = UINT32(unaligned_height); 361 362 if (SetMetaData(pvt_handle, layer) != kErrorNone) { 363 return -EINVAL; 364 } 365 366 if (pvt_handle->bufferType == BUFFER_TYPE_VIDEO) { 367 layer_stack_.flags.video_present = true; 368 layer_buffer->flags.video = true; 369 } 370 // TZ Protected Buffer - L1 371 if (pvt_handle->flags & private_handle_t::PRIV_FLAGS_SECURE_BUFFER) { 372 layer_stack_.flags.secure_present = true; 373 layer_buffer->flags.secure = true; 374 } 375 // Gralloc Usage Protected Buffer - L3 - which needs to be treated as Secure & avoid fallback 376 if (pvt_handle->flags & private_handle_t::PRIV_FLAGS_PROTECTED_BUFFER) { 377 layer_stack_.flags.secure_present = true; 378 } 379 if (pvt_handle->flags & private_handle_t::PRIV_FLAGS_SECURE_DISPLAY) { 380 layer_buffer->flags.secure_display = true; 381 } 382 383 // check if this is special solid_fill layer without input_buffer. 384 if (solid_fill_enable_ && pvt_handle->fd == -1) { 385 layer->flags.solid_fill = true; 386 layer->solid_fill_color = solid_fill_color_; 387 } 388 } else { 389 // for FBT layer 390 if (hwc_layer->compositionType == HWC_FRAMEBUFFER_TARGET) { 391 uint32_t x_pixels; 392 uint32_t y_pixels; 393 int aligned_width; 394 int aligned_height; 395 int usage = GRALLOC_USAGE_HW_FB; 396 int format = HAL_PIXEL_FORMAT_RGBA_8888; 397 int ubwc_enabled = 0; 398 int flags = 0; 399 HWCDebugHandler::Get()->GetProperty("debug.gralloc.enable_fb_ubwc", &ubwc_enabled); 400 if (ubwc_enabled == 1) { 401 usage |= GRALLOC_USAGE_PRIVATE_ALLOC_UBWC; 402 flags |= private_handle_t::PRIV_FLAGS_UBWC_ALIGNED; 403 } 404 405 GetFrameBufferResolution(&x_pixels, &y_pixels); 406 407 AdrenoMemInfo::getInstance().getAlignedWidthAndHeight(INT(x_pixels), INT(y_pixels), format, 408 usage, aligned_width, aligned_height); 409 layer_buffer->width = UINT32(aligned_width); 410 layer_buffer->height = UINT32(aligned_height); 411 layer_buffer->unaligned_width = x_pixels; 412 layer_buffer->unaligned_height = y_pixels; 413 layer_buffer->format = GetSDMFormat(format, flags); 414 } 415 } 416 417 return 0; 418 } 419 420 void HWCDisplay::CommitLayerParams(hwc_layer_1_t *hwc_layer, Layer *layer) { 421 const private_handle_t *pvt_handle = static_cast<const private_handle_t *>(hwc_layer->handle); 422 LayerBuffer *layer_buffer = layer->input_buffer; 423 424 if (pvt_handle) { 425 layer_buffer->planes[0].fd = pvt_handle->fd; 426 layer_buffer->planes[0].offset = pvt_handle->offset; 427 layer_buffer->planes[0].stride = UINT32(pvt_handle->width); 428 layer_buffer->size = pvt_handle->size; 429 } 430 431 // if swapinterval property is set to 0 then close and reset the acquireFd 432 if (swap_interval_zero_ && hwc_layer->acquireFenceFd >= 0) { 433 close(hwc_layer->acquireFenceFd); 434 hwc_layer->acquireFenceFd = -1; 435 } 436 layer_buffer->acquire_fence_fd = hwc_layer->acquireFenceFd; 437 } 438 439 int HWCDisplay::PrePrepareLayerStack(hwc_display_contents_1_t *content_list) { 440 if (shutdown_pending_) { 441 return 0; 442 } 443 444 size_t num_hw_layers = content_list->numHwLayers; 445 446 use_blit_comp_ = false; 447 metadata_refresh_rate_ = 0; 448 display_rect_ = LayerRect(); 449 450 // Configure each layer 451 for (size_t i = 0; i < num_hw_layers; i++) { 452 hwc_layer_1_t &hwc_layer = content_list->hwLayers[i]; 453 454 Layer *layer = layer_stack_.layers.at(i); 455 int ret = PrepareLayerParams(&content_list->hwLayers[i], layer); 456 457 if (ret != kErrorNone) { 458 return ret; 459 } 460 461 layer->flags.skip = ((hwc_layer.flags & HWC_SKIP_LAYER) > 0); 462 layer->flags.solid_fill = (hwc_layer.flags & kDimLayer) || solid_fill_enable_; 463 if (layer->flags.skip || layer->flags.solid_fill) { 464 layer->dirty_regions.clear(); 465 } 466 467 hwc_rect_t scaled_display_frame = hwc_layer.displayFrame; 468 ApplyScanAdjustment(&scaled_display_frame); 469 470 SetRect(scaled_display_frame, &layer->dst_rect); 471 SetRect(hwc_layer.sourceCropf, &layer->src_rect); 472 ApplyDeInterlaceAdjustment(layer); 473 474 uint32_t num_visible_rects = UINT32(hwc_layer.visibleRegionScreen.numRects); 475 uint32_t num_dirty_rects = UINT32(hwc_layer.surfaceDamage.numRects); 476 477 for (uint32_t j = 0; j < num_visible_rects; j++) { 478 LayerRect visible_rect = {}; 479 SetRect(hwc_layer.visibleRegionScreen.rects[j], &visible_rect); 480 layer->visible_regions.push_back(visible_rect); 481 } 482 483 for (uint32_t j = 0; j < num_dirty_rects; j++) { 484 LayerRect dirty_rect = {}; 485 SetRect(hwc_layer.surfaceDamage.rects[j], &dirty_rect); 486 layer->dirty_regions.push_back(dirty_rect); 487 } 488 489 if (blit_engine_) { 490 for (uint32_t j = 0; j < kMaxBlitTargetLayers; j++) { 491 LayerRect blit_rect = {}; 492 layer->blit_regions.push_back(blit_rect); 493 } 494 } 495 496 SetComposition(hwc_layer.compositionType, &layer->composition); 497 if (hwc_layer.compositionType != HWC_FRAMEBUFFER_TARGET) { 498 display_rect_ = Union(display_rect_, layer->dst_rect); 499 } 500 501 // For dim layers, SurfaceFlinger 502 // - converts planeAlpha to per pixel alpha, 503 // - sets appropriate RGB color, 504 // - sets planeAlpha to 0xff, 505 // - blending to Premultiplied. 506 // This can be achieved at hardware by 507 // - solid fill ARGB to appropriate value, 508 // - incoming planeAlpha, 509 // - blending to Coverage. 510 if (hwc_layer.flags & kDimLayer) { 511 layer->input_buffer->format = kFormatARGB8888; 512 layer->solid_fill_color = 0xff000000; 513 #ifdef QTI_BSP 514 // Get ARGB color from HWC Dim Layer color 515 uint32_t a = UINT32(hwc_layer.color.a) << 24; 516 uint32_t r = UINT32(hwc_layer.color.r) << 16; 517 uint32_t g = UINT32(hwc_layer.color.g) << 8; 518 uint32_t b = UINT32(hwc_layer.color.b); 519 layer->solid_fill_color = a | r | g | b; 520 #endif 521 SetBlending(HWC_BLENDING_COVERAGE, &layer->blending); 522 } else { 523 SetBlending(hwc_layer.blending, &layer->blending); 524 LayerTransform &layer_transform = layer->transform; 525 uint32_t &hwc_transform = hwc_layer.transform; 526 layer_transform.flip_horizontal = ((hwc_transform & HWC_TRANSFORM_FLIP_H) > 0); 527 layer_transform.flip_vertical = ((hwc_transform & HWC_TRANSFORM_FLIP_V) > 0); 528 layer_transform.rotation = ((hwc_transform & HWC_TRANSFORM_ROT_90) ? 90.0f : 0.0f); 529 } 530 531 // TODO(user): Remove below block. 532 // For solid fill, only dest rect need to be specified. 533 if (layer->flags.solid_fill) { 534 LayerBuffer *input_buffer = layer->input_buffer; 535 input_buffer->width = UINT32(layer->dst_rect.right - layer->dst_rect.left); 536 input_buffer->height = UINT32(layer->dst_rect.bottom - layer->dst_rect.top); 537 input_buffer->unaligned_width = input_buffer->width; 538 input_buffer->unaligned_height = input_buffer->height; 539 layer->src_rect.left = 0; 540 layer->src_rect.top = 0; 541 layer->src_rect.right = input_buffer->width; 542 layer->src_rect.bottom = input_buffer->height; 543 } 544 545 layer->plane_alpha = hwc_layer.planeAlpha; 546 layer->flags.cursor = ((hwc_layer.flags & HWC_IS_CURSOR_LAYER) > 0); 547 layer->flags.updating = true; 548 549 if (num_hw_layers <= kMaxLayerCount) { 550 layer->flags.updating = IsLayerUpdating(content_list, layer); 551 } 552 #ifdef QTI_BSP 553 if (hwc_layer.flags & HWC_SCREENSHOT_ANIMATOR_LAYER) { 554 layer_stack_.flags.animating = true; 555 } 556 #endif 557 if (layer->flags.skip) { 558 layer_stack_.flags.skip_present = true; 559 } 560 561 if (layer->flags.cursor) { 562 layer_stack_.flags.cursor_present = true; 563 } 564 565 PrepareDynamicRefreshRate(layer); 566 567 layer->input_buffer->buffer_id = reinterpret_cast<uint64_t>(hwc_layer.handle); 568 } 569 570 // Prepare the Blit Target 571 if (blit_engine_) { 572 // TODO(user): Fix this to enable BLIT 573 #if 0 574 int ret = blit_engine_->Prepare(&layer_stack_); 575 if (ret) { 576 // Blit engine cannot handle this layer stack, hence set the layer stack 577 // count to num_hw_layers 578 layer_stack_.layer_count -= kMaxBlitTargetLayers; 579 } else { 580 use_blit_comp_ = true; 581 } 582 #endif 583 } 584 585 // Configure layer stack 586 layer_stack_.flags.geometry_changed = ((content_list->flags & HWC_GEOMETRY_CHANGED) > 0); 587 588 return 0; 589 } 590 591 void HWCDisplay::SetLayerS3DMode(const LayerBufferS3DFormat &source, uint32_t *target) { 592 #ifdef QTI_BSP 593 switch (source) { 594 case kS3dFormatNone: *target = HWC_S3DMODE_NONE; break; 595 case kS3dFormatLeftRight: *target = HWC_S3DMODE_LR; break; 596 case kS3dFormatRightLeft: *target = HWC_S3DMODE_RL; break; 597 case kS3dFormatTopBottom: *target = HWC_S3DMODE_TB; break; 598 case kS3dFormatFramePacking: *target = HWC_S3DMODE_FP; break; 599 default: *target = HWC_S3DMODE_MAX; break; 600 } 601 #endif 602 } 603 604 int HWCDisplay::PrepareLayerStack(hwc_display_contents_1_t *content_list) { 605 if (shutdown_pending_) { 606 return 0; 607 } 608 609 size_t num_hw_layers = content_list->numHwLayers; 610 611 if (!skip_prepare_) { 612 DisplayError error = display_intf_->Prepare(&layer_stack_); 613 if (error != kErrorNone) { 614 if (error == kErrorShutDown) { 615 shutdown_pending_ = true; 616 } else if (error != kErrorPermission) { 617 DLOGE("Prepare failed. Error = %d", error); 618 // To prevent surfaceflinger infinite wait, flush the previous frame during Commit() 619 // so that previous buffer and fences are released, and override the error. 620 flush_ = true; 621 } else { 622 DLOGI("Prepare failed for Display = %d Error = %d", type_, error); 623 } 624 return 0; 625 } 626 } else { 627 // Skip is not set 628 MarkLayersForGPUBypass(content_list); 629 skip_prepare_ = false; 630 DLOGI("SecureDisplay %s, Skip Prepare/Commit and Flush", secure_display_active_ ? "Starting" : 631 "Stopping"); 632 flush_ = true; 633 } 634 635 for (size_t i = 0; i < num_hw_layers; i++) { 636 hwc_layer_1_t &hwc_layer = content_list->hwLayers[i]; 637 Layer *layer = layer_stack_.layers.at(i); 638 LayerComposition composition = layer->composition; 639 private_handle_t* pvt_handle = static_cast<private_handle_t*> 640 (const_cast<native_handle_t*>(hwc_layer.handle)); 641 MetaData_t *meta_data = pvt_handle ? 642 reinterpret_cast<MetaData_t *>(pvt_handle->base_metadata) : NULL; 643 644 if ((composition == kCompositionSDE) || (composition == kCompositionHybrid) || 645 (composition == kCompositionBlit)) { 646 hwc_layer.hints |= HWC_HINT_CLEAR_FB; 647 } 648 SetComposition(composition, &hwc_layer.compositionType); 649 650 if (meta_data != NULL) { 651 if (composition == kCompositionGPUS3D) { 652 // Align HWC and client's dispaly ID in case of HDMI as primary 653 meta_data->s3dComp.displayId = 654 display_intf_->IsPrimaryDisplay() ? HWC_DISPLAY_PRIMARY: id_; 655 SetLayerS3DMode(layer->input_buffer->s3d_format, 656 &meta_data->s3dComp.s3dMode); 657 } 658 } 659 } 660 661 return 0; 662 } 663 664 int HWCDisplay::CommitLayerStack(hwc_display_contents_1_t *content_list) { 665 if (!content_list || !content_list->numHwLayers) { 666 DLOGW("Invalid content list"); 667 return -EINVAL; 668 } 669 670 if (shutdown_pending_) { 671 return 0; 672 } 673 674 int status = 0; 675 676 size_t num_hw_layers = content_list->numHwLayers; 677 678 DumpInputBuffers(content_list); 679 680 if (!flush_) { 681 for (size_t i = 0; i < num_hw_layers; i++) { 682 CommitLayerParams(&content_list->hwLayers[i], layer_stack_.layers.at(i)); 683 } 684 685 if (use_blit_comp_) { 686 status = blit_engine_->PreCommit(content_list, &layer_stack_); 687 if (status == 0) { 688 status = blit_engine_->Commit(content_list, &layer_stack_); 689 if (status != 0) { 690 DLOGE("Blit Comp Failed!"); 691 } 692 } 693 } 694 695 DisplayError error = kErrorUndefined; 696 if (status == 0) { 697 error = display_intf_->Commit(&layer_stack_); 698 status = 0; 699 } 700 701 if (error == kErrorNone) { 702 // A commit is successfully submitted, start flushing on failure now onwards. 703 flush_on_error_ = true; 704 } else { 705 if (error == kErrorShutDown) { 706 shutdown_pending_ = true; 707 return status; 708 } else if (error != kErrorPermission) { 709 DLOGE("Commit failed. Error = %d", error); 710 // To prevent surfaceflinger infinite wait, flush the previous frame during Commit() 711 // so that previous buffer and fences are released, and override the error. 712 flush_ = true; 713 } else { 714 DLOGI("Commit failed for Display = %d Error = %d", type_, error); 715 } 716 } 717 } 718 719 return status; 720 } 721 722 int HWCDisplay::PostCommitLayerStack(hwc_display_contents_1_t *content_list) { 723 size_t num_hw_layers = content_list->numHwLayers; 724 int status = 0; 725 726 // Do no call flush on errors, if a successful buffer is never submitted. 727 if (flush_ && flush_on_error_) { 728 display_intf_->Flush(); 729 } 730 731 // Set the release fence fd to the blit engine 732 if (use_blit_comp_ && blit_engine_->BlitActive()) { 733 blit_engine_->PostCommit(&layer_stack_); 734 } 735 736 for (size_t i = 0; i < num_hw_layers; i++) { 737 hwc_layer_1_t &hwc_layer = content_list->hwLayers[i]; 738 Layer *layer = layer_stack_.layers.at(i); 739 LayerBuffer *layer_buffer = layer->input_buffer; 740 741 if (!flush_) { 742 // If swapinterval property is set to 0 or for single buffer layers, do not update f/w 743 // release fences and discard fences from driver 744 if (swap_interval_zero_ || layer->flags.single_buffer) { 745 hwc_layer.releaseFenceFd = -1; 746 close(layer_buffer->release_fence_fd); 747 layer_buffer->release_fence_fd = -1; 748 } else if (layer->composition != kCompositionGPU) { 749 hwc_layer.releaseFenceFd = layer_buffer->release_fence_fd; 750 } 751 752 // During animation on external/virtual display, SDM will use the cached 753 // framebuffer layer throughout animation and do not allow framework to do eglswapbuffer on 754 // framebuffer target. So graphics doesn't close the release fence fd of framebuffer target, 755 // Hence close the release fencefd of framebuffer target here. 756 if (disable_animation_) { 757 if (layer->composition == kCompositionGPUTarget && animating_) { 758 close(hwc_layer.releaseFenceFd); 759 hwc_layer.releaseFenceFd = -1; 760 } 761 } 762 } 763 764 if (hwc_layer.acquireFenceFd >= 0) { 765 close(hwc_layer.acquireFenceFd); 766 hwc_layer.acquireFenceFd = -1; 767 } 768 } 769 770 if (!flush_) { 771 animating_ = layer_stack_.flags.animating; 772 // if swapinterval property is set to 0 then close and reset the list retire fence 773 if (swap_interval_zero_) { 774 close(layer_stack_.retire_fence_fd); 775 layer_stack_.retire_fence_fd = -1; 776 } 777 content_list->retireFenceFd = layer_stack_.retire_fence_fd; 778 779 if (dump_frame_count_) { 780 dump_frame_count_--; 781 dump_frame_index_++; 782 } 783 } 784 785 flush_ = false; 786 787 return status; 788 } 789 790 bool HWCDisplay::IsLayerUpdating(hwc_display_contents_1_t *content_list, const Layer *layer) { 791 // Layer should be considered updating if 792 // a) layer is in single buffer mode, or 793 // b) valid dirty_regions(android specific hint for updating status), or 794 // c) layer stack geometry has changed 795 return (layer->flags.single_buffer || IsSurfaceUpdated(layer->dirty_regions) || 796 (layer_stack_.flags.geometry_changed)); 797 } 798 799 void HWCDisplay::SetRect(const hwc_rect_t &source, LayerRect *target) { 800 target->left = FLOAT(source.left); 801 target->top = FLOAT(source.top); 802 target->right = FLOAT(source.right); 803 target->bottom = FLOAT(source.bottom); 804 } 805 806 void HWCDisplay::SetRect(const hwc_frect_t &source, LayerRect *target) { 807 target->left = floorf(source.left); 808 target->top = floorf(source.top); 809 target->right = ceilf(source.right); 810 target->bottom = ceilf(source.bottom); 811 } 812 813 void HWCDisplay::SetComposition(const int32_t &source, LayerComposition *target) { 814 switch (source) { 815 case HWC_FRAMEBUFFER_TARGET: *target = kCompositionGPUTarget; break; 816 default: *target = kCompositionGPU; break; 817 } 818 } 819 820 void HWCDisplay::SetComposition(const LayerComposition &source, int32_t *target) { 821 switch (source) { 822 case kCompositionGPUTarget: *target = HWC_FRAMEBUFFER_TARGET; break; 823 case kCompositionGPU: *target = HWC_FRAMEBUFFER; break; 824 case kCompositionGPUS3D: *target = HWC_FRAMEBUFFER; break; 825 case kCompositionHWCursor: *target = HWC_CURSOR_OVERLAY; break; 826 default: *target = HWC_OVERLAY; break; 827 } 828 } 829 830 void HWCDisplay::SetBlending(const int32_t &source, LayerBlending *target) { 831 switch (source) { 832 case HWC_BLENDING_PREMULT: *target = kBlendingPremultiplied; break; 833 case HWC_BLENDING_COVERAGE: *target = kBlendingCoverage; break; 834 default: *target = kBlendingOpaque; break; 835 } 836 } 837 838 void HWCDisplay::SetIdleTimeoutMs(uint32_t timeout_ms) { 839 return; 840 } 841 842 DisplayError HWCDisplay::SetMaxMixerStages(uint32_t max_mixer_stages) { 843 DisplayError error = kErrorNone; 844 845 if (display_intf_) { 846 error = display_intf_->SetMaxMixerStages(max_mixer_stages); 847 } 848 849 return error; 850 } 851 852 LayerBufferFormat HWCDisplay::GetSDMFormat(const int32_t &source, const int flags) { 853 LayerBufferFormat format = kFormatInvalid; 854 if (flags & private_handle_t::PRIV_FLAGS_UBWC_ALIGNED) { 855 switch (source) { 856 case HAL_PIXEL_FORMAT_RGBA_8888: format = kFormatRGBA8888Ubwc; break; 857 case HAL_PIXEL_FORMAT_RGBX_8888: format = kFormatRGBX8888Ubwc; break; 858 case HAL_PIXEL_FORMAT_BGR_565: format = kFormatBGR565Ubwc; break; 859 case HAL_PIXEL_FORMAT_YCbCr_420_SP_VENUS: 860 case HAL_PIXEL_FORMAT_YCbCr_420_SP_VENUS_UBWC: 861 case HAL_PIXEL_FORMAT_NV12_ENCODEABLE: format = kFormatYCbCr420SPVenusUbwc; break; 862 case HAL_PIXEL_FORMAT_RGBA_1010102: format = kFormatRGBA1010102Ubwc; break; 863 case HAL_PIXEL_FORMAT_RGBX_1010102: format = kFormatRGBX1010102Ubwc; break; 864 case HAL_PIXEL_FORMAT_YCbCr_420_TP10_UBWC: format = kFormatYCbCr420TP10Ubwc; break; 865 default: 866 DLOGE("Unsupported format type for UBWC %d", source); 867 return kFormatInvalid; 868 } 869 return format; 870 } 871 872 switch (source) { 873 case HAL_PIXEL_FORMAT_RGBA_8888: format = kFormatRGBA8888; break; 874 case HAL_PIXEL_FORMAT_RGBA_5551: format = kFormatRGBA5551; break; 875 case HAL_PIXEL_FORMAT_RGBA_4444: format = kFormatRGBA4444; break; 876 case HAL_PIXEL_FORMAT_BGRA_8888: format = kFormatBGRA8888; break; 877 case HAL_PIXEL_FORMAT_RGBX_8888: format = kFormatRGBX8888; break; 878 case HAL_PIXEL_FORMAT_BGRX_8888: format = kFormatBGRX8888; break; 879 case HAL_PIXEL_FORMAT_RGB_888: format = kFormatRGB888; break; 880 case HAL_PIXEL_FORMAT_RGB_565: format = kFormatRGB565; break; 881 case HAL_PIXEL_FORMAT_BGR_565: format = kFormatBGR565; break; 882 case HAL_PIXEL_FORMAT_NV12_ENCODEABLE: 883 case HAL_PIXEL_FORMAT_YCbCr_420_SP_VENUS: format = kFormatYCbCr420SemiPlanarVenus; break; 884 case HAL_PIXEL_FORMAT_YCrCb_420_SP_VENUS: format = kFormatYCrCb420SemiPlanarVenus; break; 885 case HAL_PIXEL_FORMAT_YCbCr_420_SP_VENUS_UBWC: format = kFormatYCbCr420SPVenusUbwc; break; 886 case HAL_PIXEL_FORMAT_YV12: format = kFormatYCrCb420PlanarStride16; break; 887 case HAL_PIXEL_FORMAT_YCrCb_420_SP: format = kFormatYCrCb420SemiPlanar; break; 888 case HAL_PIXEL_FORMAT_YCbCr_420_SP: format = kFormatYCbCr420SemiPlanar; break; 889 case HAL_PIXEL_FORMAT_YCbCr_422_SP: format = kFormatYCbCr422H2V1SemiPlanar; break; 890 case HAL_PIXEL_FORMAT_YCbCr_422_I: format = kFormatYCbCr422H2V1Packed; break; 891 case HAL_PIXEL_FORMAT_RGBA_1010102: format = kFormatRGBA1010102; break; 892 case HAL_PIXEL_FORMAT_ARGB_2101010: format = kFormatARGB2101010; break; 893 case HAL_PIXEL_FORMAT_RGBX_1010102: format = kFormatRGBX1010102; break; 894 case HAL_PIXEL_FORMAT_XRGB_2101010: format = kFormatXRGB2101010; break; 895 case HAL_PIXEL_FORMAT_BGRA_1010102: format = kFormatBGRA1010102; break; 896 case HAL_PIXEL_FORMAT_ABGR_2101010: format = kFormatABGR2101010; break; 897 case HAL_PIXEL_FORMAT_BGRX_1010102: format = kFormatBGRX1010102; break; 898 case HAL_PIXEL_FORMAT_XBGR_2101010: format = kFormatXBGR2101010; break; 899 case HAL_PIXEL_FORMAT_YCbCr_420_P010: format = kFormatYCbCr420P010; break; 900 case HAL_PIXEL_FORMAT_YCbCr_420_TP10_UBWC: format = kFormatYCbCr420TP10Ubwc; break; 901 default: 902 DLOGW("Unsupported format type = %d", source); 903 return kFormatInvalid; 904 } 905 906 return format; 907 } 908 909 void HWCDisplay::DumpInputBuffers(hwc_display_contents_1_t *content_list) { 910 size_t num_hw_layers = content_list->numHwLayers; 911 char dir_path[PATH_MAX]; 912 913 if (!dump_frame_count_ || flush_ || !dump_input_layers_) { 914 return; 915 } 916 917 snprintf(dir_path, sizeof(dir_path), "/data/misc/display/frame_dump_%s", GetDisplayString()); 918 919 if (mkdir(dir_path, 0777) != 0 && errno != EEXIST) { 920 DLOGW("Failed to create %s directory errno = %d, desc = %s", dir_path, errno, strerror(errno)); 921 return; 922 } 923 924 // if directory exists already, need to explicitly change the permission. 925 if (errno == EEXIST && chmod(dir_path, 0777) != 0) { 926 DLOGW("Failed to change permissions on %s directory", dir_path); 927 return; 928 } 929 930 for (uint32_t i = 0; i < num_hw_layers; i++) { 931 hwc_layer_1_t &hwc_layer = content_list->hwLayers[i]; 932 const private_handle_t *pvt_handle = static_cast<const private_handle_t *>(hwc_layer.handle); 933 934 if (hwc_layer.acquireFenceFd >= 0) { 935 int error = sync_wait(hwc_layer.acquireFenceFd, 1000); 936 if (error < 0) { 937 DLOGW("sync_wait error errno = %d, desc = %s", errno, strerror(errno)); 938 return; 939 } 940 } 941 942 if (pvt_handle && pvt_handle->base) { 943 char dump_file_name[PATH_MAX]; 944 size_t result = 0; 945 946 snprintf(dump_file_name, sizeof(dump_file_name), "%s/input_layer%d_%dx%d_%s_frame%d.raw", 947 dir_path, i, pvt_handle->width, pvt_handle->height, 948 GetHALPixelFormatString(pvt_handle->format), dump_frame_index_); 949 950 FILE* fp = fopen(dump_file_name, "w+"); 951 if (fp) { 952 result = fwrite(reinterpret_cast<void *>(pvt_handle->base), pvt_handle->size, 1, fp); 953 fclose(fp); 954 } 955 956 DLOGI("Frame Dump %s: is %s", dump_file_name, result ? "Successful" : "Failed"); 957 } 958 } 959 } 960 961 void HWCDisplay::DumpOutputBuffer(const BufferInfo& buffer_info, void *base, int fence) { 962 char dir_path[PATH_MAX]; 963 964 snprintf(dir_path, sizeof(dir_path), "/data/misc/display/frame_dump_%s", GetDisplayString()); 965 966 if (mkdir(dir_path, 777) != 0 && errno != EEXIST) { 967 DLOGW("Failed to create %s directory errno = %d, desc = %s", dir_path, errno, strerror(errno)); 968 return; 969 } 970 971 // if directory exists already, need to explicitly change the permission. 972 if (errno == EEXIST && chmod(dir_path, 0777) != 0) { 973 DLOGW("Failed to change permissions on %s directory", dir_path); 974 return; 975 } 976 977 if (base) { 978 char dump_file_name[PATH_MAX]; 979 size_t result = 0; 980 981 if (fence >= 0) { 982 int error = sync_wait(fence, 1000); 983 if (error < 0) { 984 DLOGW("sync_wait error errno = %d, desc = %s", errno, strerror(errno)); 985 return; 986 } 987 } 988 989 snprintf(dump_file_name, sizeof(dump_file_name), "%s/output_layer_%dx%d_%s_frame%d.raw", 990 dir_path, buffer_info.buffer_config.width, buffer_info.buffer_config.height, 991 GetFormatString(buffer_info.buffer_config.format), dump_frame_index_); 992 993 FILE* fp = fopen(dump_file_name, "w+"); 994 if (fp) { 995 result = fwrite(base, buffer_info.alloc_buffer_info.size, 1, fp); 996 fclose(fp); 997 } 998 999 DLOGI("Frame Dump of %s is %s", dump_file_name, result ? "Successful" : "Failed"); 1000 } 1001 } 1002 1003 const char *HWCDisplay::GetHALPixelFormatString(int format) { 1004 switch (format) { 1005 case HAL_PIXEL_FORMAT_RGBA_8888: 1006 return "RGBA_8888"; 1007 case HAL_PIXEL_FORMAT_RGBX_8888: 1008 return "RGBX_8888"; 1009 case HAL_PIXEL_FORMAT_RGB_888: 1010 return "RGB_888"; 1011 case HAL_PIXEL_FORMAT_RGB_565: 1012 return "RGB_565"; 1013 case HAL_PIXEL_FORMAT_BGR_565: 1014 return "BGR_565"; 1015 case HAL_PIXEL_FORMAT_BGRA_8888: 1016 return "BGRA_8888"; 1017 case HAL_PIXEL_FORMAT_RGBA_5551: 1018 return "RGBA_5551"; 1019 case HAL_PIXEL_FORMAT_RGBA_4444: 1020 return "RGBA_4444"; 1021 case HAL_PIXEL_FORMAT_YV12: 1022 return "YV12"; 1023 case HAL_PIXEL_FORMAT_YCbCr_422_SP: 1024 return "YCbCr_422_SP_NV16"; 1025 case HAL_PIXEL_FORMAT_YCrCb_420_SP: 1026 return "YCrCb_420_SP_NV21"; 1027 case HAL_PIXEL_FORMAT_YCbCr_422_I: 1028 return "YCbCr_422_I_YUY2"; 1029 case HAL_PIXEL_FORMAT_YCrCb_422_I: 1030 return "YCrCb_422_I_YVYU"; 1031 case HAL_PIXEL_FORMAT_NV12_ENCODEABLE: 1032 return "NV12_ENCODEABLE"; 1033 case HAL_PIXEL_FORMAT_YCbCr_420_SP_TILED: 1034 return "YCbCr_420_SP_TILED_TILE_4x2"; 1035 case HAL_PIXEL_FORMAT_YCbCr_420_SP: 1036 return "YCbCr_420_SP"; 1037 case HAL_PIXEL_FORMAT_YCrCb_420_SP_ADRENO: 1038 return "YCrCb_420_SP_ADRENO"; 1039 case HAL_PIXEL_FORMAT_YCrCb_422_SP: 1040 return "YCrCb_422_SP"; 1041 case HAL_PIXEL_FORMAT_R_8: 1042 return "R_8"; 1043 case HAL_PIXEL_FORMAT_RG_88: 1044 return "RG_88"; 1045 case HAL_PIXEL_FORMAT_INTERLACE: 1046 return "INTERLACE"; 1047 case HAL_PIXEL_FORMAT_YCbCr_420_SP_VENUS: 1048 return "YCbCr_420_SP_VENUS"; 1049 case HAL_PIXEL_FORMAT_YCrCb_420_SP_VENUS: 1050 return "YCrCb_420_SP_VENUS"; 1051 case HAL_PIXEL_FORMAT_YCbCr_420_SP_VENUS_UBWC: 1052 return "YCbCr_420_SP_VENUS_UBWC"; 1053 case HAL_PIXEL_FORMAT_RGBA_1010102: 1054 return "RGBA_1010102"; 1055 case HAL_PIXEL_FORMAT_ARGB_2101010: 1056 return "ARGB_2101010"; 1057 case HAL_PIXEL_FORMAT_RGBX_1010102: 1058 return "RGBX_1010102"; 1059 case HAL_PIXEL_FORMAT_XRGB_2101010: 1060 return "XRGB_2101010"; 1061 case HAL_PIXEL_FORMAT_BGRA_1010102: 1062 return "BGRA_1010102"; 1063 case HAL_PIXEL_FORMAT_ABGR_2101010: 1064 return "ABGR_2101010"; 1065 case HAL_PIXEL_FORMAT_BGRX_1010102: 1066 return "BGRX_1010102"; 1067 case HAL_PIXEL_FORMAT_XBGR_2101010: 1068 return "XBGR_2101010"; 1069 case HAL_PIXEL_FORMAT_YCbCr_420_P010: 1070 return "YCbCr_420_P010"; 1071 case HAL_PIXEL_FORMAT_YCbCr_420_TP10_UBWC: 1072 return "YCbCr_420_TP10_UBWC"; 1073 default: 1074 return "Unknown_format"; 1075 } 1076 } 1077 1078 const char *HWCDisplay::GetDisplayString() { 1079 switch (type_) { 1080 case kPrimary: 1081 return "primary"; 1082 case kHDMI: 1083 return "hdmi"; 1084 case kVirtual: 1085 return "virtual"; 1086 default: 1087 return "invalid"; 1088 } 1089 } 1090 1091 int HWCDisplay::SetFrameBufferResolution(uint32_t x_pixels, uint32_t y_pixels) { 1092 DisplayConfigVariableInfo fb_config; 1093 DisplayError error = display_intf_->GetFrameBufferConfig(&fb_config); 1094 if (error != kErrorNone) { 1095 DLOGV("Get frame buffer config failed. Error = %d", error); 1096 return -EINVAL; 1097 } 1098 1099 fb_config.x_pixels = x_pixels; 1100 fb_config.y_pixels = y_pixels; 1101 1102 error = display_intf_->SetFrameBufferConfig(fb_config); 1103 if (error != kErrorNone) { 1104 DLOGV("Set frame buffer config failed. Error = %d", error); 1105 return -EINVAL; 1106 } 1107 1108 DLOGI("New framebuffer resolution (%dx%d)", x_pixels, y_pixels); 1109 1110 return 0; 1111 } 1112 1113 void HWCDisplay::GetFrameBufferResolution(uint32_t *x_pixels, uint32_t *y_pixels) { 1114 DisplayConfigVariableInfo fb_config; 1115 display_intf_->GetFrameBufferConfig(&fb_config); 1116 1117 *x_pixels = fb_config.x_pixels; 1118 *y_pixels = fb_config.y_pixels; 1119 } 1120 1121 DisplayError HWCDisplay::GetMixerResolution(uint32_t *x_pixels, uint32_t *y_pixels) { 1122 return display_intf_->GetMixerResolution(x_pixels, y_pixels); 1123 } 1124 1125 1126 void HWCDisplay::GetPanelResolution(uint32_t *x_pixels, uint32_t *y_pixels) { 1127 DisplayConfigVariableInfo display_config; 1128 uint32_t active_index = 0; 1129 1130 display_intf_->GetActiveConfig(&active_index); 1131 display_intf_->GetConfig(active_index, &display_config); 1132 1133 *x_pixels = display_config.x_pixels; 1134 *y_pixels = display_config.y_pixels; 1135 } 1136 1137 int HWCDisplay::SetDisplayStatus(uint32_t display_status) { 1138 int status = 0; 1139 const hwc_procs_t *hwc_procs = *hwc_procs_; 1140 1141 switch (display_status) { 1142 case kDisplayStatusResume: 1143 display_paused_ = false; 1144 case kDisplayStatusOnline: 1145 status = SetPowerMode(HWC_POWER_MODE_NORMAL); 1146 break; 1147 case kDisplayStatusPause: 1148 display_paused_ = true; 1149 case kDisplayStatusOffline: 1150 status = SetPowerMode(HWC_POWER_MODE_OFF); 1151 break; 1152 default: 1153 DLOGW("Invalid display status %d", display_status); 1154 return -EINVAL; 1155 } 1156 1157 if (display_status == kDisplayStatusResume || 1158 display_status == kDisplayStatusPause) { 1159 hwc_procs->invalidate(hwc_procs); 1160 } 1161 1162 return status; 1163 } 1164 1165 int HWCDisplay::SetCursorPosition(int x, int y) { 1166 DisplayError error = kErrorNone; 1167 1168 if (shutdown_pending_) { 1169 return 0; 1170 } 1171 1172 error = display_intf_->SetCursorPosition(x, y); 1173 if (error != kErrorNone) { 1174 if (error == kErrorShutDown) { 1175 shutdown_pending_ = true; 1176 return 0; 1177 } 1178 DLOGE("Failed for x = %d y = %d, Error = %d", x, y, error); 1179 return -1; 1180 } 1181 1182 return 0; 1183 } 1184 1185 int HWCDisplay::OnMinHdcpEncryptionLevelChange(uint32_t min_enc_level) { 1186 DisplayError error = display_intf_->OnMinHdcpEncryptionLevelChange(min_enc_level); 1187 if (error != kErrorNone) { 1188 DLOGE("Failed. Error = %d", error); 1189 return -1; 1190 } 1191 1192 return 0; 1193 } 1194 1195 void HWCDisplay::MarkLayersForGPUBypass(hwc_display_contents_1_t *content_list) { 1196 for (size_t i = 0 ; i < (content_list->numHwLayers - 1); i++) { 1197 hwc_layer_1_t *layer = &content_list->hwLayers[i]; 1198 layer->compositionType = HWC_OVERLAY; 1199 } 1200 } 1201 1202 void HWCDisplay::ApplyScanAdjustment(hwc_rect_t *display_frame) { 1203 } 1204 1205 DisplayError HWCDisplay::SetCSC(ColorSpace_t source, LayerCSC *target) { 1206 switch (source) { 1207 case ITU_R_601: *target = kCSCLimitedRange601; break; 1208 case ITU_R_601_FR: *target = kCSCFullRange601; break; 1209 case ITU_R_709: *target = kCSCLimitedRange709; break; 1210 default: 1211 DLOGE("Unsupported CSC: %d", source); 1212 return kErrorNotSupported; 1213 } 1214 1215 return kErrorNone; 1216 } 1217 1218 DisplayError HWCDisplay::SetIGC(IGC_t source, LayerIGC *target) { 1219 switch (source) { 1220 case IGC_NotSpecified: *target = kIGCNotSpecified; break; 1221 case IGC_sRGB: *target = kIGCsRGB; break; 1222 default: 1223 DLOGE("Unsupported IGC: %d", source); 1224 return kErrorNotSupported; 1225 } 1226 1227 return kErrorNone; 1228 } 1229 1230 DisplayError HWCDisplay::SetMetaData(const private_handle_t *pvt_handle, Layer *layer) { 1231 const MetaData_t *meta_data = reinterpret_cast<MetaData_t *>(pvt_handle->base_metadata); 1232 LayerBuffer *layer_buffer = layer->input_buffer; 1233 1234 if (!meta_data) { 1235 return kErrorNone; 1236 } 1237 1238 if (meta_data->operation & UPDATE_COLOR_SPACE) { 1239 if (SetCSC(meta_data->colorSpace, &layer_buffer->csc) != kErrorNone) { 1240 return kErrorNotSupported; 1241 } 1242 } 1243 1244 if (meta_data->operation & SET_IGC) { 1245 if (SetIGC(meta_data->igc, &layer_buffer->igc) != kErrorNone) { 1246 return kErrorNotSupported; 1247 } 1248 } 1249 1250 if (meta_data->operation & UPDATE_REFRESH_RATE) { 1251 layer->frame_rate = RoundToStandardFPS(meta_data->refreshrate); 1252 } 1253 1254 if ((meta_data->operation & PP_PARAM_INTERLACED) && meta_data->interlaced) { 1255 layer_buffer->flags.interlace = true; 1256 } 1257 1258 if (meta_data->operation & LINEAR_FORMAT) { 1259 layer_buffer->format = GetSDMFormat(INT32(meta_data->linearFormat), 0); 1260 } 1261 1262 if (meta_data->operation & SET_SINGLE_BUFFER_MODE) { 1263 layer->flags.single_buffer = meta_data->isSingleBufferMode; 1264 // Graphics can set this operation on all types of layers including FB and set the actual value 1265 // to 0. To protect against SET operations of 0 value, we need to do a logical OR. 1266 layer_stack_.flags.single_buffered_layer_present |= meta_data->isSingleBufferMode; 1267 } 1268 1269 if (meta_data->operation & S3D_FORMAT) { 1270 std::map<int, LayerBufferS3DFormat>::iterator it = 1271 s3d_format_hwc_to_sdm_.find(INT32(meta_data->s3dFormat)); 1272 if (it != s3d_format_hwc_to_sdm_.end()) { 1273 layer->input_buffer->s3d_format = it->second; 1274 } else { 1275 DLOGW("Invalid S3D format %d", meta_data->s3dFormat); 1276 } 1277 } 1278 1279 return kErrorNone; 1280 } 1281 1282 int HWCDisplay::SetPanelBrightness(int level) { 1283 int ret = 0; 1284 if (display_intf_) 1285 ret = display_intf_->SetPanelBrightness(level); 1286 else 1287 ret = -EINVAL; 1288 1289 return ret; 1290 } 1291 1292 int HWCDisplay::GetPanelBrightness(int *level) { 1293 return display_intf_->GetPanelBrightness(level); 1294 } 1295 1296 int HWCDisplay::ToggleScreenUpdates(bool enable) { 1297 const hwc_procs_t *hwc_procs = *hwc_procs_; 1298 display_paused_ = enable ? false : true; 1299 hwc_procs->invalidate(hwc_procs); 1300 return 0; 1301 } 1302 1303 int HWCDisplay::ColorSVCRequestRoute(const PPDisplayAPIPayload &in_payload, 1304 PPDisplayAPIPayload *out_payload, 1305 PPPendingParams *pending_action) { 1306 int ret = 0; 1307 1308 if (display_intf_) 1309 ret = display_intf_->ColorSVCRequestRoute(in_payload, out_payload, pending_action); 1310 else 1311 ret = -EINVAL; 1312 1313 return ret; 1314 } 1315 1316 int HWCDisplay::GetVisibleDisplayRect(hwc_rect_t* visible_rect) { 1317 if (!IsValid(display_rect_)) { 1318 return -EINVAL; 1319 } 1320 1321 visible_rect->left = INT(display_rect_.left); 1322 visible_rect->top = INT(display_rect_.top); 1323 visible_rect->right = INT(display_rect_.right); 1324 visible_rect->bottom = INT(display_rect_.bottom); 1325 DLOGI("Dpy = %d Visible Display Rect(%d %d %d %d)", visible_rect->left, visible_rect->top, 1326 visible_rect->right, visible_rect->bottom); 1327 1328 return 0; 1329 } 1330 1331 void HWCDisplay::SetSecureDisplay(bool secure_display_active) { 1332 secure_display_active_ = secure_display_active; 1333 return; 1334 } 1335 1336 int HWCDisplay::SetActiveDisplayConfig(int config) { 1337 return display_intf_->SetActiveConfig(UINT32(config)) == kErrorNone ? 0 : -1; 1338 } 1339 1340 int HWCDisplay::GetActiveDisplayConfig(uint32_t *config) { 1341 return display_intf_->GetActiveConfig(config) == kErrorNone ? 0 : -1; 1342 } 1343 1344 int HWCDisplay::GetDisplayConfigCount(uint32_t *count) { 1345 return display_intf_->GetNumVariableInfoConfigs(count) == kErrorNone ? 0 : -1; 1346 } 1347 1348 int HWCDisplay::GetDisplayAttributesForConfig(int config, 1349 DisplayConfigVariableInfo *display_attributes) { 1350 return display_intf_->GetConfig(UINT32(config), display_attributes) == kErrorNone ? 0 : -1; 1351 } 1352 1353 // TODO(user): HWC needs to know updating for dyn_fps, cpu hint features, 1354 // once the features are moved to SDM, the two functions below can be removed. 1355 uint32_t HWCDisplay::GetUpdatingLayersCount(uint32_t app_layer_count) { 1356 uint32_t updating_count = 0; 1357 1358 for (uint i = 0; i < app_layer_count; i++) { 1359 Layer *layer = layer_stack_.layers.at(i); 1360 if (layer->flags.updating) { 1361 updating_count++; 1362 } 1363 } 1364 1365 return updating_count; 1366 } 1367 1368 bool HWCDisplay::SingleVideoLayerUpdating(uint32_t app_layer_count) { 1369 uint32_t updating_count = 0; 1370 1371 for (uint i = 0; i < app_layer_count; i++) { 1372 Layer *layer = layer_stack_.layers[i]; 1373 // TODO(user): disable DRC feature in S3D playbacl case.S3D video 1374 // need play in dedicate resolution and fps, if DRC switch the 1375 // mode to an non S3D supported mode, it would break S3D playback. 1376 // Need figure out a way to make S3D and DRC co-exist. 1377 if (layer->flags.updating && (layer->input_buffer->flags.video == true) && 1378 (layer->input_buffer->s3d_format == kS3dFormatNone)) { 1379 updating_count++; 1380 } 1381 } 1382 1383 return (updating_count == 1); 1384 } 1385 1386 uint32_t HWCDisplay::RoundToStandardFPS(float fps) { 1387 static const uint32_t standard_fps[4] = {30, 24, 48, 60}; 1388 uint32_t frame_rate = (uint32_t)(fps); 1389 1390 int count = INT(sizeof(standard_fps) / sizeof(standard_fps[0])); 1391 for (int i = 0; i < count; i++) { 1392 if ((standard_fps[i] - frame_rate) < 2) { 1393 // Most likely used for video, the fps can fluctuate 1394 // Ex: b/w 29 and 30 for 30 fps clip 1395 return standard_fps[i]; 1396 } 1397 } 1398 1399 return frame_rate; 1400 } 1401 1402 uint32_t HWCDisplay::SanitizeRefreshRate(uint32_t req_refresh_rate) { 1403 uint32_t refresh_rate = req_refresh_rate; 1404 1405 if (refresh_rate < min_refresh_rate_) { 1406 // Pick the next multiple of request which is within the range 1407 refresh_rate = (((min_refresh_rate_ / refresh_rate) + 1408 ((min_refresh_rate_ % refresh_rate) ? 1 : 0)) * refresh_rate); 1409 } 1410 1411 if (refresh_rate > max_refresh_rate_) { 1412 refresh_rate = max_refresh_rate_; 1413 } 1414 1415 return refresh_rate; 1416 } 1417 1418 DisplayClass HWCDisplay::GetDisplayClass() { 1419 return display_class_; 1420 } 1421 1422 void HWCDisplay::PrepareDynamicRefreshRate(Layer *layer) { 1423 if (layer->frame_rate > metadata_refresh_rate_) { 1424 metadata_refresh_rate_ = SanitizeRefreshRate(layer->frame_rate); 1425 } else { 1426 layer->frame_rate = current_refresh_rate_; 1427 } 1428 } 1429 1430 bool HWCDisplay::IsSurfaceUpdated(const std::vector<LayerRect> &dirty_regions) { 1431 // based on dirty_regions determine if its updating 1432 // dirty_rect count = 0 - whole layer - updating. 1433 // dirty_rect count = 1 or more valid rects - updating. 1434 // dirty_rect count = 1 with (0,0,0,0) - not updating. 1435 return (dirty_regions.empty() || IsValid(dirty_regions.at(0))); 1436 } 1437 1438 int HWCDisplay::GetDisplayPort(DisplayPort *port) { 1439 return display_intf_->GetDisplayPort(port) == kErrorNone ? 0 : -1; 1440 } 1441 1442 1443 } // namespace sdm 1444