1 /* 2 * Copyright (C) 2012 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #ifndef _EXYNOSDISPLAY_H 18 #define _EXYNOSDISPLAY_H 19 20 #include <android/hardware/graphics/composer/2.4/types.h> 21 #include <hardware/hwcomposer2.h> 22 #include <system/graphics.h> 23 #include <utils/KeyedVector.h> 24 #include <utils/Vector.h> 25 26 #include <atomic> 27 #include <chrono> 28 #include <set> 29 30 #include "ExynosDisplayInterface.h" 31 #include "ExynosHWC.h" 32 #include "ExynosHWCDebug.h" 33 #include "ExynosHWCHelper.h" 34 #include "ExynosHwc3Types.h" 35 #include "ExynosMPP.h" 36 #include "ExynosResourceManager.h" 37 #include "worker.h" 38 39 #define HWC_CLEARDISPLAY_WITH_COLORMAP 40 #define HWC_PRINT_FRAME_NUM 10 41 42 #define LOW_FPS_THRESHOLD 5 43 44 using ::android::hardware::graphics::composer::V2_4::VsyncPeriodNanos; 45 using namespace std::chrono_literals; 46 47 #ifndef SECOND_DISPLAY_START_BIT 48 #define SECOND_DISPLAY_START_BIT 4 49 #endif 50 51 typedef hwc2_composition_t exynos_composition; 52 53 class BrightnessController; 54 class ExynosLayer; 55 class ExynosDevice; 56 class ExynosMPP; 57 class ExynosMPPSource; 58 59 namespace aidl { 60 namespace google { 61 namespace hardware { 62 namespace power { 63 namespace extension { 64 namespace pixel { 65 66 class IPowerExt; 67 68 } // namespace pixel 69 } // namespace extension 70 } // namespace power 71 } // namespace hardware 72 } // namespace google 73 } // namespace aidl 74 namespace aidl { 75 namespace android { 76 namespace hardware { 77 namespace power { 78 79 class IPower; 80 class IPowerHintSession; 81 class WorkDuration; 82 83 } // namespace power 84 } // namespace hardware 85 } // namespace android 86 } // namespace aidl 87 88 using WorkDuration = aidl::android::hardware::power::WorkDuration; 89 90 enum dynamic_recomp_mode { 91 NO_MODE_SWITCH, 92 DEVICE_2_CLIENT, 93 CLIENT_2_DEVICE 94 }; 95 96 enum rendering_state { 97 RENDERING_STATE_NONE = 0, 98 RENDERING_STATE_VALIDATED, 99 RENDERING_STATE_ACCEPTED_CHANGE, 100 RENDERING_STATE_PRESENTED, 101 RENDERING_STATE_MAX 102 }; 103 104 enum composition_type { 105 COMPOSITION_NONE = 0, 106 COMPOSITION_CLIENT, 107 COMPOSITION_EXYNOS, 108 COMPOSITION_MAX 109 }; 110 111 enum { 112 PSR_NONE = 0, 113 PSR_DP, 114 PSR_MIPI, 115 PSR_MAX, 116 }; 117 118 enum { 119 PANEL_LEGACY = 0, 120 PANEL_DSC, 121 PANEL_MIC, 122 }; 123 124 enum { 125 eDisplayNone = 0x0, 126 ePrimaryDisplay = 0x00000001, 127 eExternalDisplay = 0x00000002, 128 eVirtualDisplay = 0x00000004, 129 }; 130 131 // served as extension of hwc2_power_mode_t for use with setPowerMode 132 enum class ext_hwc2_power_mode_t{ 133 PAUSE = 10, 134 RESUME, 135 }; 136 137 enum class PanelGammaSource { 138 GAMMA_DEFAULT, // Resotre gamma table to default 139 GAMMA_CALIBRATION, // Update gamma table from calibration file 140 GAMMA_TYPES, 141 }; 142 143 enum class hwc_request_state_t { 144 SET_CONFIG_STATE_DONE = 0, 145 SET_CONFIG_STATE_PENDING, 146 SET_CONFIG_STATE_REQUESTED, 147 }; 148 149 enum class VrrThrottleRequester : uint32_t { 150 PIXEL_DISP = 0, 151 TEST, 152 LHBM, 153 MAX, 154 }; 155 156 enum class DispIdleTimerRequester : uint32_t { 157 SF = 0, 158 VRR_THROTTLE, 159 MAX, 160 }; 161 162 #define NUM_SKIP_STATIC_LAYER 5 163 struct ExynosFrameInfo 164 { 165 uint32_t srcNum; 166 exynos_image srcInfo[NUM_SKIP_STATIC_LAYER]; 167 exynos_image dstInfo[NUM_SKIP_STATIC_LAYER]; 168 }; 169 170 struct exynos_readback_info 171 { 172 buffer_handle_t handle = NULL; 173 /* release sync fence file descriptor, 174 * which will be signaled when it is safe to write to the output buffer. 175 */ 176 int rel_fence = -1; 177 /* acquire sync fence file descriptor which will signal when the 178 * buffer provided to setReadbackBuffer has been filled by the device and is 179 * safe for the client to read. 180 */ 181 int acq_fence = -1; 182 /* Requested from HWCService */ 183 bool requested_from_service = false; 184 }; 185 186 struct exynos_win_config_data 187 { 188 enum { 189 WIN_STATE_DISABLED = 0, 190 WIN_STATE_COLOR, 191 WIN_STATE_BUFFER, 192 WIN_STATE_UPDATE, 193 WIN_STATE_CURSOR, 194 WIN_STATE_RCD, 195 } state = WIN_STATE_DISABLED; 196 197 uint32_t color = 0; 198 const ExynosLayer* layer = nullptr; 199 uint64_t buffer_id = 0; 200 int fd_idma[3] = {-1, -1, -1}; 201 int acq_fence = -1; 202 int rel_fence = -1; 203 float plane_alpha = 1; 204 int32_t blending = HWC2_BLEND_MODE_NONE; 205 ExynosMPP* assignedMPP = NULL; 206 int format = 0; 207 uint32_t transform = 0; 208 android_dataspace dataspace = HAL_DATASPACE_UNKNOWN; 209 bool hdr_enable = false; 210 enum dpp_comp_src comp_src = DPP_COMP_SRC_NONE; 211 uint32_t min_luminance = 0; 212 uint32_t max_luminance = 0; 213 struct decon_win_rect block_area = { 0, 0, 0, 0}; 214 struct decon_win_rect transparent_area = {0, 0, 0, 0}; 215 struct decon_win_rect opaque_area = {0, 0, 0, 0}; 216 struct decon_frame src = {0, 0, 0, 0, 0, 0}; 217 struct decon_frame dst = {0, 0, 0, 0, 0, 0}; 218 bool protection = false; 219 bool compression = false; 220 bool needColorTransform = false; 221 resetexynos_win_config_data222 void reset(){ 223 *this = {}; 224 }; 225 }; 226 struct exynos_dpu_data 227 { 228 int retire_fence = -1; 229 std::vector<exynos_win_config_data> configs; 230 std::vector<exynos_win_config_data> rcdConfigs; 231 232 bool enable_win_update = false; 233 std::atomic<bool> enable_readback = false; 234 struct decon_frame win_update_region = {0, 0, 0, 0, 0, 0}; 235 struct exynos_readback_info readback_info; 236 initexynos_dpu_data237 void init(size_t configNum, size_t rcdConfigNum) { 238 configs.resize(configNum); 239 rcdConfigs.resize(rcdConfigNum); 240 }; 241 resetexynos_dpu_data242 void reset() { 243 retire_fence = -1; 244 for (auto& config : configs) config.reset(); 245 for (auto& config : rcdConfigs) config.reset(); 246 247 /* 248 * Should not initialize readback_info 249 * readback_info should be initialized after present 250 */ 251 }; 252 exynos_dpu_data& operator =(const exynos_dpu_data &configs_data){ 253 retire_fence = configs_data.retire_fence; 254 if (configs.size() != configs_data.configs.size()) { 255 HWC_LOGE(NULL, "invalid config, it has different configs size"); 256 return *this; 257 } 258 configs = configs_data.configs; 259 if (rcdConfigs.size() != configs_data.rcdConfigs.size()) { 260 HWC_LOGE(NULL, "invalid config, it has different rcdConfigs size"); 261 return *this; 262 } 263 rcdConfigs = configs_data.rcdConfigs; 264 return *this; 265 }; 266 }; 267 268 class ExynosLowFpsLayerInfo 269 { 270 public: 271 ExynosLowFpsLayerInfo(); 272 bool mHasLowFpsLayer; 273 int32_t mFirstIndex; 274 int32_t mLastIndex; 275 276 void initializeInfos(); 277 int32_t addLowFpsLayer(uint32_t layerIndex); 278 }; 279 280 class ExynosSortedLayer : public Vector <ExynosLayer*> 281 { 282 public: 283 ssize_t remove(const ExynosLayer *item); 284 status_t vector_sort(); 285 static int compare(ExynosLayer * const *lhs, ExynosLayer *const *rhs); 286 }; 287 288 class ExynosCompositionInfo : public ExynosMPPSource { 289 public: ExynosCompositionInfo()290 ExynosCompositionInfo():ExynosCompositionInfo(COMPOSITION_NONE){}; 291 ExynosCompositionInfo(uint32_t type); 292 uint32_t mType; 293 bool mHasCompositionLayer; 294 int32_t mFirstIndex; 295 int32_t mLastIndex; 296 buffer_handle_t mTargetBuffer; 297 android_dataspace mDataSpace; 298 int32_t mAcquireFence; 299 int32_t mReleaseFence; 300 bool mEnableSkipStatic; 301 bool mSkipStaticInitFlag; 302 bool mSkipFlag; 303 ExynosFrameInfo mSkipSrcInfo; 304 exynos_win_config_data mLastWinConfigData; 305 306 int32_t mWindowIndex; 307 bool mCompressed; 308 309 void initializeInfos(ExynosDisplay *display); 310 void setTargetBuffer(ExynosDisplay *display, buffer_handle_t handle, 311 int32_t acquireFence, android_dataspace dataspace); 312 void setCompressed(bool compressed); 313 bool getCompressed(); 314 void dump(String8& result); 315 String8 getTypeStr(); 316 }; 317 318 // Prepare multi-resolution 319 struct ResolutionSize { 320 uint32_t w; 321 uint32_t h; 322 }; 323 324 struct ResolutionInfo { 325 uint32_t nNum; 326 ResolutionSize nResolution[3]; 327 uint32_t nDSCYSliceSize[3]; 328 uint32_t nDSCXSliceSize[3]; 329 int nPanelType[3]; 330 }; 331 332 typedef struct displayConfigs { 333 // HWC2_ATTRIBUTE_VSYNC_PERIOD 334 VsyncPeriodNanos vsyncPeriod; 335 // HWC2_ATTRIBUTE_WIDTH 336 uint32_t width; 337 // case HWC2_ATTRIBUTE_HEIGHT 338 uint32_t height; 339 // HWC2_ATTRIBUTE_DPI_X 340 uint32_t Xdpi; 341 // HWC2_ATTRIBUTE_DPI_Y 342 uint32_t Ydpi; 343 // HWC2_ATTRIBUTE_CONFIG_GROUP 344 uint32_t groupId; 345 } displayConfigs_t; 346 347 struct DisplayControl { 348 /** Composition crop en/disable **/ 349 bool enableCompositionCrop; 350 /** Resource assignment optimization for exynos composition **/ 351 bool enableExynosCompositionOptimization; 352 /** Resource assignment optimization for client composition **/ 353 bool enableClientCompositionOptimization; 354 /** Use G2D as much as possible **/ 355 bool useMaxG2DSrc; 356 /** Low fps layer optimization **/ 357 bool handleLowFpsLayers; 358 /** start m2mMPP before persentDisplay **/ 359 bool earlyStartMPP; 360 /** Adjust display size of the layer having high priority */ 361 bool adjustDisplayFrame; 362 /** setCursorPosition support **/ 363 bool cursorSupport; 364 /** readback support **/ 365 bool readbackSupport = false; 366 /** Reserve MPP regardless of plug state **/ 367 bool forceReserveMPP = false; 368 /** Skip M2MMPP processing **/ 369 bool skipM2mProcessing = true; 370 }; 371 372 class ExynosDisplay { 373 public: 374 uint32_t mDisplayId; 375 uint32_t mType; 376 uint32_t mIndex; 377 String8 mDeconNodeName; 378 uint32_t mXres; 379 uint32_t mYres; 380 uint32_t mXdpi; 381 uint32_t mYdpi; 382 uint32_t mVsyncPeriod; 383 uint32_t mBtsVsyncPeriod; 384 385 int mPanelType; 386 int mPsrMode; 387 388 /* Constructor */ 389 ExynosDisplay(uint32_t index, ExynosDevice *device); 390 /* Destructor */ 391 virtual ~ExynosDisplay(); 392 393 ExynosDevice *mDevice; 394 395 String8 mDisplayName; 396 HwcMountOrientation mMountOrientation = HwcMountOrientation::ROT_0; 397 Mutex mDisplayMutex; 398 399 /** State variables */ 400 bool mPlugState; 401 std::optional<hwc2_power_mode_t> mPowerModeState; 402 hwc2_vsync_t mVsyncState; 403 bool mHasSingleBuffer; 404 bool mPauseDisplay = false; 405 406 DisplayControl mDisplayControl; 407 408 /** 409 * TODO : Should be defined as ExynosLayer type 410 * Layer list those sorted by z-order 411 */ 412 ExynosSortedLayer mLayers; 413 std::vector<ExynosLayer*> mIgnoreLayers; 414 415 ExynosResourceManager *mResourceManager; 416 417 /** 418 * Layer index, target buffer information for GLES. 419 */ 420 ExynosCompositionInfo mClientCompositionInfo; 421 422 /** 423 * Layer index, target buffer information for G2D. 424 */ 425 ExynosCompositionInfo mExynosCompositionInfo; 426 427 /** 428 * Geometry change info is described by bit map. 429 * This flag is cleared when resource assignment for all displays 430 * is done. 431 */ 432 uint64_t mGeometryChanged; 433 434 /** 435 * Rendering step information that is seperated by 436 * VALIDATED, ACCEPTED_CHANGE, PRESENTED. 437 */ 438 rendering_state mRenderingState; 439 440 /** 441 * Rendering step information that is called by client 442 */ 443 rendering_state mHWCRenderingState; 444 445 /** 446 * Window total bandwidth by enabled window, It's used as dynamic re-composition enable/disable. 447 */ 448 uint32_t mDisplayBW; 449 450 /** 451 * Mode information Dynamic re-composition feature. 452 * DEVICE_2_CLIENT: All layers are composited by GLES composition. 453 * CLIENT_2_DEVICE: Device composition. 454 */ 455 dynamic_recomp_mode mDynamicReCompMode; 456 bool mDREnable; 457 bool mDRDefault; 458 Mutex mDRMutex; 459 460 nsecs_t mLastFpsTime; 461 uint64_t mFrameCount; 462 uint64_t mLastFrameCount; 463 uint64_t mErrorFrameCount; 464 uint64_t mLastModeSwitchTimeStamp; 465 uint64_t mLastUpdateTimeStamp; 466 uint64_t mUpdateEventCnt; 467 uint64_t mUpdateCallCnt; 468 469 /* default DMA for the display */ 470 decon_idma_type mDefaultDMA; 471 472 /** 473 * DECON WIN_CONFIG information. 474 */ 475 exynos_dpu_data mDpuData; 476 477 /** 478 * Last win_config data is used as WIN_CONFIG skip decision or debugging. 479 */ 480 exynos_dpu_data mLastDpuData; 481 482 /** 483 * Restore release fenc from DECON. 484 */ 485 int mLastRetireFence; 486 487 bool mUseDpu; 488 489 /** 490 * Max Window number, It should be set by display module(chip) 491 */ 492 uint32_t mMaxWindowNum; 493 uint32_t mWindowNumUsed; 494 uint32_t mBaseWindowIndex; 495 496 // Priority 497 uint32_t mNumMaxPriorityAllowed; 498 int32_t mCursorIndex; 499 500 int32_t mColorTransformHint; 501 502 ExynosLowFpsLayerInfo mLowFpsLayerInfo; 503 504 // HDR capabilities 505 std::vector<int32_t> mHdrTypes; 506 float mMaxLuminance; 507 float mMaxAverageLuminance; 508 float mMinLuminance; 509 510 std::unique_ptr<BrightnessController> mBrightnessController; 511 512 /* For debugging */ 513 hwc_display_contents_1_t *mHWC1LayerList; 514 515 /* Support Multi-resolution scheme */ 516 int mOldScalerMode; 517 int mNewScaledWidth; 518 int mNewScaledHeight; 519 int32_t mDeviceXres; 520 int32_t mDeviceYres; 521 ResolutionInfo mResolutionInfo; 522 std::map<uint32_t, displayConfigs_t> mDisplayConfigs; 523 524 // WCG 525 android_color_mode_t mColorMode; 526 527 // Skip present frame if there was no validate after power on 528 bool mSkipFrame; 529 530 hwc_vsync_period_change_constraints_t mVsyncPeriodChangeConstraints; 531 hwc_vsync_period_change_timeline_t mVsyncAppliedTimeLine; 532 hwc_request_state_t mConfigRequestState; 533 hwc2_config_t mDesiredConfig; 534 535 hwc2_config_t mActiveConfig = UINT_MAX; 536 537 bool mNotifyPeakRefreshRate = false; 538 std::mutex mPeakRefreshRateMutex; 539 std::condition_variable mPeakRefreshRateCondition; 540 541 void initDisplay(); 542 543 int getId(); getDisplayMutex()544 Mutex& getDisplayMutex() {return mDisplayMutex; }; 545 546 int32_t setCompositionTargetExynosImage(uint32_t targetType, exynos_image *src_img, exynos_image *dst_img); 547 int32_t initializeValidateInfos(); 548 int32_t addClientCompositionLayer(uint32_t layerIndex); 549 int32_t removeClientCompositionLayer(uint32_t layerIndex); 550 int32_t addExynosCompositionLayer(uint32_t layerIndex); 551 552 /** 553 * Dynamic AFBC Control solution : To get the prepared information is applied to current or not. 554 */ 555 bool comparePreferedLayers(); 556 557 /** 558 * @param *outLayer 559 */ 560 int32_t destroyLayer(hwc2_layer_t outLayer); 561 562 void destroyLayers(); 563 564 ExynosLayer *checkLayer(hwc2_layer_t addr); 565 566 void checkIgnoreLayers(); 567 virtual void doPreProcessing(); 568 569 int checkLayerFps(); 570 571 int switchDynamicReCompMode(dynamic_recomp_mode mode); 572 573 int checkDynamicReCompMode(); 574 575 int handleDynamicReCompMode(); 576 577 void updateBrightnessState(); 578 579 /** 580 * @param compositionType 581 */ 582 int skipStaticLayers(ExynosCompositionInfo& compositionInfo); 583 int handleStaticLayers(ExynosCompositionInfo& compositionInfo); 584 585 int doPostProcessing(); 586 587 int doExynosComposition(); 588 589 int32_t configureOverlay(ExynosLayer *layer, exynos_win_config_data &cfg); 590 int32_t configureOverlay(ExynosCompositionInfo &compositionInfo); 591 592 int32_t configureHandle(ExynosLayer &layer, int fence_fd, exynos_win_config_data &cfg); 593 594 virtual int setWinConfigData(); 595 596 virtual int setDisplayWinConfigData(); 597 598 virtual int32_t validateWinConfigData(); 599 600 virtual int deliverWinConfigData(); 601 602 virtual int setReleaseFences(); 603 604 virtual bool checkFrameValidation(); 605 606 /** 607 * Display Functions for HWC 2.0 608 */ 609 610 /** 611 * Descriptor: HWC2_FUNCTION_ACCEPT_DISPLAY_CHANGES 612 * HWC2_PFN_ACCEPT_DISPLAY_CHANGES 613 **/ 614 virtual int32_t acceptDisplayChanges(); 615 616 /** 617 * Descriptor: HWC2_FUNCTION_CREATE_LAYER 618 * HWC2_PFN_CREATE_LAYER 619 */ 620 virtual int32_t createLayer(hwc2_layer_t* outLayer); 621 622 /** 623 * Descriptor: HWC2_FUNCTION_GET_ACTIVE_CONFIG 624 * HWC2_PFN_GET_ACTIVE_CONFIG 625 */ 626 virtual int32_t getActiveConfig(hwc2_config_t* outConfig); 627 628 /** 629 * Descriptor: HWC2_FUNCTION_GET_CHANGED_COMPOSITION_TYPES 630 * HWC2_PFN_GET_CHANGED_COMPOSITION_TYPES 631 */ 632 virtual int32_t getChangedCompositionTypes( 633 uint32_t* outNumElements, hwc2_layer_t* outLayers, 634 int32_t* /*hwc2_composition_t*/ outTypes); 635 636 /** 637 * Descriptor: HWC2_FUNCTION_GET_CLIENT_TARGET_SUPPORT 638 * HWC2_PFN_GET_CLIENT_TARGET_SUPPORT 639 */ 640 virtual int32_t getClientTargetSupport( 641 uint32_t width, uint32_t height, 642 int32_t /*android_pixel_format_t*/ format, 643 int32_t /*android_dataspace_t*/ dataspace); 644 645 /** 646 * Descriptor: HWC2_FUNCTION_GET_COLOR_MODES 647 * HWC2_PFN_GET_COLOR_MODES 648 */ 649 virtual int32_t getColorModes( 650 uint32_t* outNumModes, 651 int32_t* /*android_color_mode_t*/ outModes); 652 653 /* getDisplayAttribute(..., config, attribute, outValue) 654 * Descriptor: HWC2_FUNCTION_GET_DISPLAY_ATTRIBUTE 655 * HWC2_PFN_GET_DISPLAY_ATTRIBUTE 656 */ 657 virtual int32_t getDisplayAttribute( 658 hwc2_config_t config, 659 int32_t /*hwc2_attribute_t*/ attribute, int32_t* outValue); 660 661 /* getDisplayConfigs(..., outNumConfigs, outConfigs) 662 * Descriptor: HWC2_FUNCTION_GET_DISPLAY_CONFIGS 663 * HWC2_PFN_GET_DISPLAY_CONFIGS 664 */ 665 virtual int32_t getDisplayConfigs( 666 uint32_t* outNumConfigs, 667 hwc2_config_t* outConfigs); 668 669 /* getDisplayName(..., outSize, outName) 670 * Descriptor: HWC2_FUNCTION_GET_DISPLAY_NAME 671 * HWC2_PFN_GET_DISPLAY_NAME 672 */ 673 virtual int32_t getDisplayName(uint32_t* outSize, char* outName); 674 675 /* getDisplayRequests(..., outDisplayRequests, outNumElements, outLayers, 676 * outLayerRequests) 677 * Descriptor: HWC2_FUNCTION_GET_DISPLAY_REQUESTS 678 * HWC2_PFN_GET_DISPLAY_REQUESTS 679 */ 680 virtual int32_t getDisplayRequests( 681 int32_t* /*hwc2_display_request_t*/ outDisplayRequests, 682 uint32_t* outNumElements, hwc2_layer_t* outLayers, 683 int32_t* /*hwc2_layer_request_t*/ outLayerRequests); 684 685 /* getDisplayType(..., outType) 686 * Descriptor: HWC2_FUNCTION_GET_DISPLAY_TYPE 687 * HWC2_PFN_GET_DISPLAY_TYPE 688 */ 689 virtual int32_t getDisplayType( 690 int32_t* /*hwc2_display_type_t*/ outType); 691 /* getDozeSupport(..., outSupport) 692 * Descriptor: HWC2_FUNCTION_GET_DOZE_SUPPORT 693 * HWC2_PFN_GET_DOZE_SUPPORT 694 */ 695 virtual int32_t getDozeSupport(int32_t* outSupport); 696 697 /* getReleaseFences(..., outNumElements, outLayers, outFences) 698 * Descriptor: HWC2_FUNCTION_GET_RELEASE_FENCES 699 * HWC2_PFN_GET_RELEASE_FENCES 700 */ 701 virtual int32_t getReleaseFences( 702 uint32_t* outNumElements, 703 hwc2_layer_t* outLayers, int32_t* outFences); 704 705 enum { 706 SKIP_ERR_NONE = 0, 707 SKIP_ERR_CONFIG_DISABLED, 708 SKIP_ERR_FIRST_FRAME, 709 SKIP_ERR_GEOMETRY_CHAGNED, 710 SKIP_ERR_HAS_CLIENT_COMP, 711 SKIP_ERR_SKIP_STATIC_CHANGED, 712 SKIP_ERR_HAS_REQUEST, 713 SKIP_ERR_DISP_NOT_CONNECTED, 714 SKIP_ERR_DISP_NOT_POWER_ON, 715 SKIP_ERR_FORCE_VALIDATE, 716 SKIP_ERR_INVALID_CLIENT_TARGET_BUFFER 717 }; 718 virtual int32_t canSkipValidate(); 719 720 /* presentDisplay(..., outRetireFence) 721 * Descriptor: HWC2_FUNCTION_PRESENT_DISPLAY 722 * HWC2_PFN_PRESENT_DISPLAY 723 */ 724 virtual int32_t presentDisplay(int32_t* outRetireFence); 725 virtual int32_t presentPostProcessing(); 726 727 /* setActiveConfig(..., config) 728 * Descriptor: HWC2_FUNCTION_SET_ACTIVE_CONFIG 729 * HWC2_PFN_SET_ACTIVE_CONFIG 730 */ 731 virtual int32_t setActiveConfig(hwc2_config_t config); 732 733 /* setClientTarget(..., target, acquireFence, dataspace) 734 * Descriptor: HWC2_FUNCTION_SET_CLIENT_TARGET 735 * HWC2_PFN_SET_CLIENT_TARGET 736 */ 737 virtual int32_t setClientTarget( 738 buffer_handle_t target, 739 int32_t acquireFence, int32_t /*android_dataspace_t*/ dataspace); 740 741 /* setColorTransform(..., matrix, hint) 742 * Descriptor: HWC2_FUNCTION_SET_COLOR_TRANSFORM 743 * HWC2_PFN_SET_COLOR_TRANSFORM 744 */ 745 virtual int32_t setColorTransform( 746 const float* matrix, 747 int32_t /*android_color_transform_t*/ hint); 748 749 /* setColorMode(..., mode) 750 * Descriptor: HWC2_FUNCTION_SET_COLOR_MODE 751 * HWC2_PFN_SET_COLOR_MODE 752 */ 753 virtual int32_t setColorMode( 754 int32_t /*android_color_mode_t*/ mode); 755 756 /* setOutputBuffer(..., buffer, releaseFence) 757 * Descriptor: HWC2_FUNCTION_SET_OUTPUT_BUFFER 758 * HWC2_PFN_SET_OUTPUT_BUFFER 759 */ 760 virtual int32_t setOutputBuffer( 761 buffer_handle_t buffer, 762 int32_t releaseFence); 763 764 virtual int clearDisplay(bool needModeClear = false); 765 766 /* setPowerMode(..., mode) 767 * Descriptor: HWC2_FUNCTION_SET_POWER_MODE 768 * HWC2_PFN_SET_POWER_MODE 769 */ 770 virtual int32_t setPowerMode( 771 int32_t /*hwc2_power_mode_t*/ mode); 772 773 /* setVsyncEnabled(..., enabled) 774 * Descriptor: HWC2_FUNCTION_SET_VSYNC_ENABLED 775 * HWC2_PFN_SET_VSYNC_ENABLED 776 */ 777 virtual int32_t setVsyncEnabled( 778 int32_t /*hwc2_vsync_t*/ enabled); 779 int32_t setVsyncEnabledInternal( 780 int32_t /*hwc2_vsync_t*/ enabled); 781 782 /* validateDisplay(..., outNumTypes, outNumRequests) 783 * Descriptor: HWC2_FUNCTION_VALIDATE_DISPLAY 784 * HWC2_PFN_VALIDATE_DISPLAY 785 */ 786 virtual int32_t validateDisplay( 787 uint32_t* outNumTypes, uint32_t* outNumRequests); 788 789 /* getHdrCapabilities(..., outNumTypes, outTypes, outMaxLuminance, 790 * outMaxAverageLuminance, outMinLuminance) 791 * Descriptor: HWC2_FUNCTION_GET_HDR_CAPABILITIES 792 */ 793 virtual int32_t getHdrCapabilities(uint32_t* outNumTypes, int32_t* /*android_hdr_t*/ outTypes, float* outMaxLuminance, 794 float* outMaxAverageLuminance, float* outMinLuminance); 795 796 virtual int32_t getRenderIntents(int32_t mode, uint32_t* outNumIntents, 797 int32_t* /*android_render_intent_v1_1_t*/ outIntents); 798 virtual int32_t setColorModeWithRenderIntent(int32_t /*android_color_mode_t*/ mode, 799 int32_t /*android_render_intent_v1_1_t */ intent); 800 801 /* HWC 2.3 APIs */ 802 803 /* getDisplayIdentificationData(..., outPort, outDataSize, outData) 804 * Descriptor: HWC2_FUNCTION_GET_DISPLAY_IDENTIFICATION_DATA 805 * Parameters: 806 * outPort - the connector to which the display is connected; 807 * pointer will be non-NULL 808 * outDataSize - if outData is NULL, the size in bytes of the data which would 809 * have been returned; if outData is not NULL, the size of outData, which 810 * must not exceed the value stored in outDataSize prior to the call; 811 * pointer will be non-NULL 812 * outData - the EDID 1.3 blob identifying the display 813 * 814 * Returns HWC2_ERROR_NONE or one of the following errors: 815 * HWC2_ERROR_BAD_DISPLAY - an invalid display handle was passed in 816 */ 817 int32_t getDisplayIdentificationData(uint8_t* outPort, 818 uint32_t* outDataSize, uint8_t* outData); 819 820 /* getDisplayCapabilities(..., outCapabilities) 821 * Descriptor: HWC2_FUNCTION_GET_DISPLAY_CAPABILITIES 822 * Parameters: 823 * outNumCapabilities - if outCapabilities was nullptr, returns the number of capabilities 824 * if outCapabilities was not nullptr, returns the number of capabilities stored in 825 * outCapabilities, which must not exceed the value stored in outNumCapabilities prior 826 * to the call; pointer will be non-NULL 827 * outCapabilities - a list of supported capabilities. 828 * 829 * Returns HWC2_ERROR_NONE or one of the following errors: 830 * HWC2_ERROR_BAD_DISPLAY - an invalid display handle was passed in 831 */ 832 /* Capabilities 833 Invalid = HWC2_CAPABILITY_INVALID, 834 SidebandStream = HWC2_CAPABILITY_SIDEBAND_STREAM, 835 SkipClientColorTransform = HWC2_CAPABILITY_SKIP_CLIENT_COLOR_TRANSFORM, 836 PresentFenceIsNotReliable = HWC2_CAPABILITY_PRESENT_FENCE_IS_NOT_RELIABLE, 837 SkipValidate = HWC2_CAPABILITY_SKIP_VALIDATE, 838 */ 839 int32_t getDisplayCapabilities(uint32_t* outNumCapabilities, 840 uint32_t* outCapabilities); 841 842 /* getDisplayBrightnessSupport(displayToken) 843 * Descriptor: HWC2_FUNCTION_GET_DISPLAY_BRIGHTNESS_SUPPORT 844 * Parameters: 845 * outSupport - whether the display supports operations. 846 * 847 * Returns HWC2_ERROR_NONE or one of the following errors: 848 * HWC2_ERROR_BAD_DISPLAY when the display is invalid. 849 */ 850 int32_t getDisplayBrightnessSupport(bool* outSupport); 851 852 /* setDisplayBrightness(displayToken, brightnesss, waitPresent) 853 * Descriptor: HWC2_FUNCTION_SET_DISPLAY_BRIGHTNESS 854 * Parameters: 855 * brightness - a number between 0.0f (minimum brightness) and 1.0f (maximum brightness), or 856 * -1.0f to turn the backlight off. 857 * waitPresent - apply this brightness change at next Present time. 858 * 859 * Returns HWC2_ERROR_NONE or one of the following errors: 860 * HWC2_ERROR_BAD_DISPLAY when the display is invalid, or 861 * HWC2_ERROR_UNSUPPORTED when brightness operations are not supported, or 862 * HWC2_ERROR_BAD_PARAMETER when the brightness is invalid, or 863 * HWC2_ERROR_NO_RESOURCES when the brightness cannot be applied. 864 */ 865 virtual int32_t setDisplayBrightness(float brightness, bool waitPresent = false); 866 867 /* getDisplayConnectionType(..., outType) 868 * Descriptor: HWC2_FUNCTION_GET_DISPLAY_CONNECTION_TYPE 869 * Optional for all HWC2 devices 870 * 871 * Returns whether the given physical display is internal or external. 872 * 873 * Parameters: 874 * outType - the connection type of the display; pointer will be non-NULL 875 * 876 * Returns HWC2_ERROR_NONE or one of the following errors: 877 * HWC2_ERROR_BAD_DISPLAY when the display is invalid or virtual. 878 */ 879 int32_t getDisplayConnectionType(uint32_t* outType); 880 881 /* getDisplayVsyncPeriod(..., outVsyncPeriods) 882 * Descriptor: HWC2_FUNCTION_GET_DISPLAY_VSYNC_PERIOD 883 * Required for HWC2 devices for composer 2.4 884 * 885 * Retrieves which vsync period the display is currently using. 886 * 887 * If no display configuration is currently active, this function must 888 * return BAD_CONFIG. If a vsync period is about to change due to a 889 * setActiveConfigWithConstraints call, this function must return the current vsync period 890 * until the change has taken place. 891 * 892 * Parameters: 893 * outVsyncPeriod - the current vsync period of the display. 894 * 895 * Returns HWC2_ERROR_NONE or one of the following errors: 896 * HWC2_ERROR_BAD_DISPLAY - an invalid display handle was passed in 897 * HWC2_ERROR_BAD_CONFIG - no configuration is currently active 898 */ 899 int32_t getDisplayVsyncPeriod(hwc2_vsync_period_t* __unused outVsyncPeriod); 900 901 /* setActiveConfigWithConstraints(..., 902 * config, 903 * vsyncPeriodChangeConstraints, 904 * outTimeline) 905 * Descriptor: HWC2_FUNCTION_SET_ACTIVE_CONFIG_WITH_CONSTRAINTS 906 * Required for HWC2 devices for composer 2.4 907 * 908 * Sets the active configuration and the refresh rate for this display. 909 * If the new config shares the same config group as the current config, 910 * only the vsync period shall change. 911 * Upon returning, the given display configuration, except vsync period, must be active and 912 * remain so until either this function is called again or the display is disconnected. 913 * When the display starts to refresh at the new vsync period, onVsync_2_4 callback must be 914 * called with the new vsync period. 915 * 916 * Parameters: 917 * config - the new display configuration. 918 * vsyncPeriodChangeConstraints - constraints required for changing vsync period: 919 * desiredTimeNanos - the time in CLOCK_MONOTONIC after 920 * which the vsync period may change 921 * (i.e., the vsync period must not change 922 * before this time). 923 * seamlessRequired - if true, requires that the vsync period 924 * change must happen seamlessly without 925 * a noticeable visual artifact. 926 * When the conditions change and it may be 927 * possible to change the vsync period 928 * seamlessly, HWC2_CALLBACK_SEAMLESS_POSSIBLE 929 * callback must be called to indicate that 930 * caller should retry. 931 * outTimeline - the timeline for the vsync period change. 932 * 933 * Returns HWC2_ERROR_NONE or one of the following errors: 934 * HWC2_ERROR_BAD_DISPLAY - an invalid display handle was passed in. 935 * HWC2_ERROR_BAD_CONFIG - an invalid configuration handle passed in. 936 * HWC2_ERROR_SEAMLESS_NOT_ALLOWED - when seamlessRequired was true but config provided doesn't 937 * share the same config group as the current config. 938 * HWC2_ERROR_SEAMLESS_NOT_POSSIBLE - when seamlessRequired was true but the display cannot 939 * achieve the vsync period change without a noticeable 940 * visual artifact. 941 */ 942 int32_t setActiveConfigWithConstraints(hwc2_config_t __unused config, 943 hwc_vsync_period_change_constraints_t* __unused vsyncPeriodChangeConstraints, 944 hwc_vsync_period_change_timeline_t* __unused outTimeline); 945 946 /** 947 * setBootDisplayConfig(..., config) 948 * Descriptor: HWC2_FUNCTION_SET_BOOT_DISPLAY_CONFIG 949 * Optional for HWC2 devices 950 * 951 * Sets the display config in which the device boots. 952 * If the device is unable to boot in this config for any reason (example HDMI display 953 * changed), the implementation should try to find a config which matches the resolution 954 * and refresh-rate of this config. If no such config exists, the implementation's 955 * preferred display config should be used. 956 * 957 * See also: 958 * getPreferredBootDisplayConfig 959 * 960 * Parameters: 961 * config - is the new boot time config for the display. 962 * 963 * Returns HWC2_ERROR_NONE or one of the following errors: 964 * HWC2_ERROR_BAD_DISPLAY - when the display is invalid 965 * HWC2_ERROR_BAD_CONFIG - when the configuration is invalid 966 * HWC2_ERROR_UNSUPPORTED - when the display does not support boot display config 967 */ 968 virtual int32_t setBootDisplayConfig(int32_t config); 969 970 /** 971 * clearBootDisplayConfig(...) 972 * Descriptor: HWC2_FUNCTION_CLEAR_BOOT_DISPLAY_CONFIG 973 * Optional for HWC2 devices 974 * 975 * Clears the boot display config. 976 * The device should boot in the implementation's preferred display config. 977 * 978 * Returns HWC2_ERROR_NONE or one of the following errors: 979 * HWC2_ERROR_BAD_DISPLAY - when the display is invalid 980 * HWC2_ERROR_UNSUPPORTED - when the display does not support boot display config 981 */ 982 virtual int32_t clearBootDisplayConfig(); 983 984 /** 985 * getPreferredBootDisplayConfig(..., config*) 986 * Descriptor: HWC2_FUNCTION_GET_PREFERRED_DISPLAY_CONFIG 987 * Optional for HWC2 devices 988 * 989 * Returns the implementation's preferred display config. 990 * This is display config used by the implementation at boot time, if the boot 991 * display config has not been requested yet, or if it has been previously cleared. 992 * 993 * See also: 994 * setBootDisplayConfig 995 * 996 * Parameters: 997 * outConfig - is the implementation's preferred display config 998 * 999 * Returns HWC2_ERROR_NONE or one of the following errors: 1000 * HWC2_ERROR_BAD_DISPLAY - when the display is invalid 1001 * HWC2_ERROR_BAD_CONFIG - when the configuration is invalid 1002 * HWC2_ERROR_UNSUPPORTED - when the display does not support boot display config 1003 */ 1004 int32_t getPreferredBootDisplayConfig(int32_t* outConfig); 1005 1006 virtual int32_t getPreferredDisplayConfigInternal(int32_t* outConfig); 1007 1008 /* setAutoLowLatencyMode(displayToken, on) 1009 * Descriptor: HWC2_FUNCTION_SET_AUTO_LOW_LATENCY_MODE 1010 * Optional for HWC2 devices 1011 * 1012 * setAutoLowLatencyMode requests that the display goes into low latency mode. If the display 1013 * is connected via HDMI 2.1, then Auto Low Latency Mode should be triggered. If the display is 1014 * internally connected, then a custom low latency mode should be triggered (if available). 1015 * 1016 * Parameters: 1017 * on - indicates whether to turn low latency mode on (=true) or off (=false) 1018 * 1019 * Returns HWC2_ERROR_NONE or one of the following errors: 1020 * HWC2_ERROR_BAD_DISPLAY - when the display is invalid, or 1021 * HWC2_ERROR_UNSUPPORTED - when the display does not support any low latency mode 1022 */ 1023 int32_t setAutoLowLatencyMode(bool __unused on); 1024 1025 /* getSupportedContentTypes(..., outSupportedContentTypes) 1026 * Descriptor: HWC2_FUNCTION_GET_SUPPORTED_CONTENT_TYPES 1027 * Optional for HWC2 devices 1028 * 1029 * getSupportedContentTypes returns a list of supported content types 1030 * (as described in the definition of ContentType above). 1031 * This list must not change after initialization. 1032 * 1033 * Parameters: 1034 * outNumSupportedContentTypes - if outSupportedContentTypes was nullptr, returns the number 1035 * of supported content types; if outSupportedContentTypes was not nullptr, returns the 1036 * number of capabilities stored in outSupportedContentTypes, which must not exceed the 1037 * value stored in outNumSupportedContentTypes prior to the call; pointer will be non-NULL 1038 * outSupportedContentTypes - a list of supported content types. 1039 * 1040 * Returns HWC2_ERROR_NONE or one of the following errors: 1041 * HWC2_ERROR_BAD_DISPLAY - an invalid display handle was passed in 1042 */ 1043 int32_t getSupportedContentTypes(uint32_t* __unused outNumSupportedContentTypes, 1044 uint32_t* __unused outSupportedContentTypes); 1045 1046 /* setContentType(displayToken, contentType) 1047 * Descriptor: HWC2_FUNCTION_SET_CONTENT_TYPE 1048 * Optional for HWC2 devices 1049 * 1050 * setContentType instructs the display that the content being shown is of the given contentType 1051 * (one of GRAPHICS, PHOTO, CINEMA, GAME). 1052 * 1053 * According to the HDMI 1.4 specification, supporting all content types is optional. Whether 1054 * the display supports a given content type is reported by getSupportedContentTypes. 1055 * 1056 * Parameters: 1057 * contentType - the type of content that is currently being shown on the display 1058 * 1059 * Returns HWC2_ERROR_NONE or one of the following errors: 1060 * HWC2_ERROR_BAD_DISPLAY - when the display is invalid, or 1061 * HWC2_ERROR_UNSUPPORTED - when the given content type is a valid content type, but is not 1062 * supported on this display, or 1063 * HWC2_ERROR_BAD_PARAMETER - when the given content type is invalid 1064 */ 1065 int32_t setContentType(int32_t /* hwc2_content_type_t */ __unused contentType); 1066 1067 /* getClientTargetProperty(..., outClientTargetProperty) 1068 * Descriptor: HWC2_FUNCTION_GET_CLIENT_TARGET_PROPERTY 1069 * Optional for HWC2 devices 1070 * 1071 * Retrieves the client target properties for which the hardware composer 1072 * requests after the last call to validateDisplay. The client must set the 1073 * properties of the client target to match the returned values. 1074 * When this API is implemented, if client composition is needed, the hardware 1075 * composer must return meaningful client target property with dataspace not 1076 * setting to UNKNOWN. 1077 * When the returned dataspace is set to UNKNOWN, it means hardware composer 1078 * requests nothing, the client must ignore the returned client target property 1079 * structrue. 1080 * 1081 * Parameters: 1082 * outClientTargetProperty - the client target properties that hardware 1083 * composer requests. If dataspace field is set to UNKNOWN, it means 1084 * the hardware composer requests nothing, the client must ignore the 1085 * returned client target property structure. 1086 * outDimmingStage - where should the SDR dimming happen. HWC3 only. 1087 * Returns HWC2_ERROR_NONE or one of the following errors: 1088 * HWC2_ERROR_BAD_DISPLAY - an invalid display handle was passed in 1089 * HWC2_ERROR_NOT_VALIDATED - validateDisplay has not been called for this 1090 * display 1091 */ 1092 virtual int32_t getClientTargetProperty( 1093 hwc_client_target_property_t* outClientTargetProperty, 1094 HwcDimmingStage *outDimmingStage = nullptr); 1095 1096 /* 1097 * HWC3 1098 * 1099 * Execute any pending brightness changes. 1100 */ 1101 int32_t flushDisplayBrightnessChange(); 1102 1103 /* 1104 * HWC3 1105 * 1106 * Get display mount orientation. 1107 * 1108 */ 1109 int32_t getMountOrientation(HwcMountOrientation *orientation); 1110 1111 /* setActiveConfig MISCs */ 1112 bool isBadConfig(hwc2_config_t config); 1113 bool needNotChangeConfig(hwc2_config_t config); 1114 int32_t updateInternalDisplayConfigVariables( 1115 hwc2_config_t config, bool updateVsync = true); 1116 int32_t resetConfigRequestStateLocked(hwc2_config_t config); 1117 int32_t updateConfigRequestAppliedTime(); 1118 int32_t updateVsyncAppliedTimeLine(int64_t actualChangeTime); 1119 int32_t getDisplayVsyncPeriodInternal( 1120 hwc2_vsync_period_t* outVsyncPeriod); 1121 virtual int32_t doDisplayConfigInternal(hwc2_config_t config); 1122 int32_t doDisplayConfigPostProcess(ExynosDevice *dev); 1123 int32_t getConfigAppliedTime(const uint64_t desiredTime, 1124 const uint64_t actualChangeTime, 1125 int64_t &appliedTime, int64_t &refreshTime); 1126 void updateBtsVsyncPeriod(uint32_t vsyncPeriod, bool configApplied = false); 1127 uint32_t getBtsRefreshRate() const; checkBtsReassignResource(const uint32_t __unused vsyncPeriod,const uint32_t __unused btsVsyncPeriod)1128 virtual void checkBtsReassignResource(const uint32_t __unused vsyncPeriod, 1129 const uint32_t __unused btsVsyncPeriod) {} 1130 1131 /* TODO : TBD */ 1132 int32_t setCursorPositionAsync(uint32_t x_pos, uint32_t y_pos); 1133 1134 int32_t getReadbackBufferAttributes(int32_t* /*android_pixel_format_t*/ outFormat, 1135 int32_t* /*android_dataspace_t*/ outDataspace); 1136 int32_t setReadbackBuffer(buffer_handle_t buffer, int32_t releaseFence, bool requestedService = false); 1137 void setReadbackBufferInternal(buffer_handle_t buffer, int32_t releaseFence, bool requestedService = false); 1138 int32_t getReadbackBufferFence(int32_t* outFence); 1139 /* This function is called by ExynosDisplayInterface class to set acquire fence*/ 1140 int32_t setReadbackBufferAcqFence(int32_t acqFence); 1141 1142 virtual void dump(String8& result); 1143 1144 virtual int32_t startPostProcessing(); 1145 1146 void dumpConfig(const exynos_win_config_data &c); 1147 void dumpConfig(String8 &result, const exynos_win_config_data &c); 1148 void printConfig(exynos_win_config_data &c); 1149 1150 unsigned int getLayerRegion(ExynosLayer *layer, 1151 hwc_rect *rect_area, uint32_t regionType); 1152 1153 int handleWindowUpdate(); 1154 bool windowUpdateExceptions(); 1155 1156 /* For debugging */ setHWC1LayerList(hwc_display_contents_1_t * contents)1157 void setHWC1LayerList(hwc_display_contents_1_t *contents) {mHWC1LayerList = contents;}; 1158 void traceLayerTypes(); 1159 1160 bool validateExynosCompositionLayer(); 1161 void printDebugInfos(String8 &reason); 1162 1163 bool checkConfigChanged(const exynos_dpu_data &lastConfigsData, 1164 const exynos_dpu_data &newConfigsData); 1165 int checkConfigDstChanged(const exynos_dpu_data &lastConfigData, 1166 const exynos_dpu_data &newConfigData, uint32_t index); 1167 1168 uint32_t getRestrictionIndex(int halFormat); 1169 void closeFences(); 1170 void closeFencesForSkipFrame(rendering_state renderingState); 1171 1172 int32_t getLayerCompositionTypeForValidationType(uint32_t layerIndex); 1173 void setHWCControl(uint32_t ctrl, int32_t val); 1174 void setGeometryChanged(uint64_t changedBit); 1175 void clearGeometryChanged(); 1176 1177 virtual void setDDIScalerEnable(int width, int height); 1178 virtual int getDDIScalerMode(int width, int height); 1179 void increaseMPPDstBufIndex(); 1180 virtual void initDisplayInterface(uint32_t interfaceType); updateColorConversionInfo()1181 virtual int32_t updateColorConversionInfo() { return NO_ERROR; }; updatePresentColorConversionInfo()1182 virtual int32_t updatePresentColorConversionInfo() { return NO_ERROR; }; checkRrCompensationEnabled()1183 virtual bool checkRrCompensationEnabled() { return false; }; isColorCalibratedByDevice()1184 virtual bool isColorCalibratedByDevice() { return false; }; getColorAdjustedDbv(uint32_t &)1185 virtual int32_t getColorAdjustedDbv(uint32_t &) { return NO_ERROR; } 1186 SetCurrentPanelGammaSource(const displaycolor::DisplayType,const PanelGammaSource &)1187 virtual int32_t SetCurrentPanelGammaSource(const displaycolor::DisplayType /* type */, 1188 const PanelGammaSource& /* source */) { 1189 return HWC2_ERROR_UNSUPPORTED; 1190 } GetCurrentPanelGammaSource()1191 virtual PanelGammaSource GetCurrentPanelGammaSource() const { 1192 return PanelGammaSource::GAMMA_DEFAULT; 1193 } initLbe()1194 virtual void initLbe(){}; isLbeSupported()1195 virtual bool isLbeSupported() { return false; } setLbeState(LbeState __unused state)1196 virtual void setLbeState(LbeState __unused state) {} setLbeAmbientLight(int __unused value)1197 virtual void setLbeAmbientLight(int __unused value) {} getLbeState()1198 virtual LbeState getLbeState() { return LbeState::OFF; } 1199 1200 int32_t checkPowerHalExtHintSupport(const std::string& mode); 1201 isLhbmSupported()1202 virtual bool isLhbmSupported() { return false; } setLhbmState(bool __unused enabled)1203 virtual int32_t setLhbmState(bool __unused enabled) { return NO_ERROR; } getLhbmState()1204 virtual bool getLhbmState() { return false; }; setEarlyWakeupDisplay()1205 virtual void setEarlyWakeupDisplay() {} setExpectedPresentTime(uint64_t __unused timestamp)1206 virtual void setExpectedPresentTime(uint64_t __unused timestamp) {} getPendingExpectedPresentTime()1207 virtual uint64_t getPendingExpectedPresentTime() { return 0; } applyExpectedPresentTime()1208 virtual void applyExpectedPresentTime() {} 1209 virtual int32_t getDisplayIdleTimerSupport(bool& outSupport); setDisplayIdleTimer(const int32_t __unused timeoutMs)1210 virtual int32_t setDisplayIdleTimer(const int32_t __unused timeoutMs) { 1211 return HWC2_ERROR_UNSUPPORTED; 1212 } handleDisplayIdleEnter(const uint32_t __unused idleTeRefreshRate)1213 virtual void handleDisplayIdleEnter(const uint32_t __unused idleTeRefreshRate) {} 1214 getPanelCalibrationStatus()1215 virtual PanelCalibrationStatus getPanelCalibrationStatus() { 1216 return PanelCalibrationStatus::UNCALIBRATED; 1217 } isDbmSupported()1218 virtual bool isDbmSupported() { return false; } setDbmState(bool __unused enabled)1219 virtual int32_t setDbmState(bool __unused enabled) { return NO_ERROR; } 1220 1221 /* getDisplayPreAssignBit support mIndex up to 1. 1222 It supports only dual LCD and 2 external displays */ getDisplayPreAssignBit()1223 inline uint32_t getDisplayPreAssignBit() { 1224 uint32_t type = SECOND_DISPLAY_START_BIT * mIndex + mType; 1225 return 1 << type; 1226 } 1227 1228 void cleanupAfterClientDeath(); 1229 int32_t getRCDLayerSupport(bool& outSupport) const; 1230 int32_t setDebugRCDLayerEnabled(bool enable); 1231 1232 protected: 1233 virtual bool getHDRException(ExynosLayer *layer); 1234 virtual int32_t getActiveConfigInternal(hwc2_config_t* outConfig); 1235 virtual int32_t setActiveConfigInternal(hwc2_config_t config, bool force); 1236 1237 void updateRefreshRateHint(); 1238 bool isFullScreenComposition(); 1239 1240 public: 1241 /** 1242 * This will be initialized with differnt class 1243 * that inherits ExynosDisplayInterface according to 1244 * interface type. 1245 */ 1246 std::unique_ptr<ExynosDisplayInterface> mDisplayInterface; 1247 void requestLhbm(bool on); 1248 setMinIdleRefreshRate(const int __unused fps)1249 virtual int setMinIdleRefreshRate(const int __unused fps) { return NO_ERROR; } setRefreshRateThrottleNanos(const int64_t __unused delayNanos,const VrrThrottleRequester __unused requester)1250 virtual int setRefreshRateThrottleNanos(const int64_t __unused delayNanos, 1251 const VrrThrottleRequester __unused requester) { 1252 return NO_ERROR; 1253 } 1254 updateAppliedActiveConfig(const hwc2_config_t,const int64_t)1255 virtual void updateAppliedActiveConfig(const hwc2_config_t /*newConfig*/, 1256 const int64_t /*ts*/) {} 1257 1258 // is the hint session both enabled and supported 1259 bool usePowerHintSession(); 1260 setMinDisplayVsyncPeriod(uint32_t period)1261 void setMinDisplayVsyncPeriod(uint32_t period) { mMinDisplayVsyncPeriod = period; } 1262 isCurrentPeakRefreshRate(void)1263 bool isCurrentPeakRefreshRate(void) { 1264 return ((mConfigRequestState == hwc_request_state_t::SET_CONFIG_STATE_DONE) && 1265 (mVsyncPeriod == mMinDisplayVsyncPeriod)); 1266 } 1267 1268 // check if there are any dimmed layers 1269 bool isMixedComposition(); isPriorFrameMixedCompostion()1270 bool isPriorFrameMixedCompostion() { return mPriorFrameMixedComposition; } 1271 int lookupDisplayConfigs(const int32_t& width, 1272 const int32_t& height, 1273 const int32_t& fps, 1274 int32_t* outConfig); 1275 1276 private: 1277 bool skipStaticLayerChanged(ExynosCompositionInfo& compositionInfo); 1278 1279 bool skipSignalIdleForVideoLayer(); 1280 1281 /// minimum possible dim rate in the case hbm peak is 1000 nits and norml 1282 // display brightness is 2 nits 1283 static constexpr float kGhbmMinDimRatio = 0.002; 1284 1285 /// consider HDR as full screen playback when its frame coverage 1286 //exceeds this threshold. 1287 static constexpr float kHdrFullScreen = 0.5; 1288 uint32_t mHdrFullScrenAreaThreshold; 1289 1290 // vsync period of peak refresh rate 1291 uint32_t mMinDisplayVsyncPeriod; 1292 1293 // track if the last frame is a mixed composition, to detect mixed 1294 // composition to non-mixed composition transition. 1295 bool mPriorFrameMixedComposition; 1296 1297 /* Display hint to notify power hal */ 1298 class PowerHalHintWorker : public Worker { 1299 public: 1300 PowerHalHintWorker(uint32_t displayId); 1301 virtual ~PowerHalHintWorker(); 1302 int Init(); 1303 1304 void signalRefreshRate(hwc2_power_mode_t powerMode, uint32_t vsyncPeriod); 1305 void signalIdle(); 1306 void signalActualWorkDuration(nsecs_t actualDurationNanos); 1307 void signalTargetWorkDuration(nsecs_t targetDurationNanos); 1308 1309 void addBinderTid(pid_t tid); 1310 void removeBinderTid(pid_t tid); 1311 1312 bool signalStartHintSession(); 1313 void trackThisThread(); 1314 1315 // is the hint session both enabled and supported 1316 bool usePowerHintSession(); 1317 // is it known if the hint session is enabled + supported yet 1318 bool checkPowerHintSessionReady(); 1319 1320 protected: 1321 void Routine() override; 1322 1323 private: 1324 static void BinderDiedCallback(void*); 1325 int32_t connectPowerHal(); 1326 int32_t connectPowerHalExt(); 1327 int32_t checkPowerHalExtHintSupport(const std::string& mode); 1328 int32_t sendPowerHalExtHint(const std::string& mode, bool enabled); 1329 1330 int32_t checkRefreshRateHintSupport(int refreshRate); 1331 int32_t updateRefreshRateHintInternal(hwc2_power_mode_t powerMode, 1332 uint32_t vsyncPeriod); 1333 int32_t sendRefreshRateHint(int refreshRate, bool enabled); 1334 void forceUpdateHints(); 1335 1336 int32_t checkIdleHintSupport(); 1337 int32_t updateIdleHint(int64_t deadlineTime, bool forceUpdate); 1338 bool needUpdateIdleHintLocked(int64_t& timeout) REQUIRES(mutex_); 1339 1340 // for adpf cpu hints 1341 int32_t sendActualWorkDuration(); 1342 int32_t updateTargetWorkDuration(); 1343 1344 // Update checking methods 1345 bool needUpdateTargetWorkDurationLocked() REQUIRES(mutex_); 1346 bool needSendActualWorkDurationLocked() REQUIRES(mutex_); 1347 1348 // is it known if the hint session is enabled + supported yet 1349 bool checkPowerHintSessionReadyLocked(); 1350 // Hint session lifecycle management 1351 int32_t startHintSession(); 1352 1353 int32_t checkPowerHintSessionSupport(); 1354 bool mNeedUpdateRefreshRateHint; 1355 1356 // The last refresh rate hint that is still being enabled 1357 // If all refresh rate hints are disabled, then mLastRefreshRateHint = 0 1358 int mLastRefreshRateHint; 1359 1360 // support list of refresh rate hints 1361 std::map<int, bool> mRefreshRateHintSupportMap; 1362 1363 bool mIdleHintIsEnabled; 1364 bool mForceUpdateIdleHint; 1365 int64_t mIdleHintDeadlineTime; 1366 1367 // whether idle hint support is checked 1368 bool mIdleHintSupportIsChecked; 1369 1370 // whether idle hint is supported 1371 bool mIdleHintIsSupported; 1372 1373 std::string mIdleHintStr; 1374 std::string mRefreshRateHintPrefixStr; 1375 1376 hwc2_power_mode_t mPowerModeState; 1377 uint32_t mVsyncPeriod; 1378 1379 ndk::ScopedAIBinder_DeathRecipient mDeathRecipient; 1380 1381 // for power HAL extension hints 1382 std::shared_ptr<aidl::google::hardware::power::extension::pixel::IPowerExt> 1383 mPowerHalExtAidl; 1384 1385 // for normal power HAL hints 1386 std::shared_ptr<aidl::android::hardware::power::IPower> mPowerHalAidl; 1387 // Max amount the error term can vary without causing an actual value report, 1388 // as well as the target durations if not normalized 1389 static constexpr const std::chrono::nanoseconds kAllowedDeviation = 300us; 1390 // Target value used for initialization and normalization, 1391 // the actual value does not really matter 1392 static constexpr const std::chrono::nanoseconds kDefaultTarget = 50ms; 1393 // Whether to normalize all the actual values as error terms relative to a constant 1394 // target. This saves a binder call by not setting the target 1395 static const bool sNormalizeTarget; 1396 // Whether we should emit ATRACE_INT data for hint sessions 1397 static const bool sTraceHintSessionData; 1398 // Whether we use or disable the rate limiter for target and actual values 1399 static const bool sUseRateLimiter; 1400 std::shared_ptr<aidl::android::hardware::power::IPowerHintSession> mPowerHintSession; 1401 // queue of actual durations waiting to be reported 1402 std::vector<WorkDuration> mPowerHintQueue; 1403 // display-specific binder thread tids 1404 std::set<pid_t> mBinderTids; 1405 // indicates that the tid list has changed, so the session must be rebuilt 1406 bool mTidsUpdated = false; 1407 1408 static std::mutex sSharedDisplayMutex; 1409 struct SharedDisplayData { 1410 std::optional<bool> hintSessionEnabled; 1411 std::optional<int32_t> hintSessionSupported; 1412 }; 1413 // caches the output of usePowerHintSession to avoid sSharedDisplayMutex 1414 std::atomic<std::optional<bool>> mUsePowerHintSession{std::nullopt}; 1415 // this lets us know if we can skip calling checkPowerHintSessionSupport 1416 bool mHintSessionSupportChecked = false; 1417 // used to indicate to all displays whether hint sessions are enabled/supported 1418 static SharedDisplayData sSharedDisplayData GUARDED_BY(sSharedDisplayMutex); 1419 // latest target that was signalled 1420 nsecs_t mTargetWorkDuration = kDefaultTarget.count(); 1421 // last target duration reported to PowerHAL 1422 nsecs_t mLastTargetDurationReported = kDefaultTarget.count(); 1423 // latest actual duration signalled 1424 std::optional<nsecs_t> mActualWorkDuration; 1425 // last error term reported to PowerHAL, used for rate limiting 1426 std::optional<nsecs_t> mLastErrorSent; 1427 // timestamp of the last report we sent, used to avoid stale sessions 1428 nsecs_t mLastActualReportTimestamp = 0; 1429 // amount of time after the last message was sent before the session goes stale 1430 // actually 100ms but we use 80 here to ideally avoid going stale 1431 static constexpr const std::chrono::nanoseconds kStaleTimeout = 80ms; 1432 // An adjustable safety margin which moves the "target" earlier to allow flinger to 1433 // go a bit over without dropping a frame, especially since we can't measure 1434 // the exact time HWC finishes composition so "actual" durations are measured 1435 // from the end of present() instead, which is a bit later. 1436 static constexpr const std::chrono::nanoseconds kTargetSafetyMargin = 2ms; 1437 }; 1438 1439 // union here permits use as a key in the unordered_map without a custom hash 1440 union AveragesKey { 1441 struct { 1442 uint16_t layers; 1443 bool validated; 1444 bool beforeReleaseFence; 1445 }; 1446 uint32_t value; AveragesKey(size_t layers,bool validated,bool beforeReleaseFence)1447 AveragesKey(size_t layers, bool validated, bool beforeReleaseFence) 1448 : layers(static_cast<uint16_t>(layers)), 1449 validated(validated), 1450 beforeReleaseFence(beforeReleaseFence) {} uint32_t()1451 operator uint32_t() const { return value; } 1452 }; 1453 1454 static const constexpr int kAveragesBufferSize = 3; 1455 static const constexpr nsecs_t SIGNAL_TIME_PENDING = INT64_MAX; 1456 static const constexpr nsecs_t SIGNAL_TIME_INVALID = -1; 1457 std::unordered_map<uint32_t, RollingAverage<kAveragesBufferSize>> mRollingAverages; 1458 // mPowerHalHint should be declared only after mDisplayId and mIndex have been declared 1459 // since the result of getDisplayId(mDisplayId, mIndex) is needed as the parameter of 1460 // PowerHalHintWorker's constructor 1461 PowerHalHintWorker mPowerHalHint; 1462 1463 std::optional<nsecs_t> mValidateStartTime; 1464 nsecs_t mPresentStartTime; 1465 std::optional<nsecs_t> mValidationDuration; 1466 // cached value used to skip evaluation once set 1467 std::optional<bool> mUsePowerHintSession; 1468 // tracks the time right before we start to wait for the fence 1469 std::optional<nsecs_t> mRetireFenceWaitTime; 1470 // tracks the time right after we finish waiting for the fence 1471 std::optional<nsecs_t> mRetireFenceAcquireTime; 1472 // tracks the time when the retire fence previously signaled 1473 std::optional<nsecs_t> mRetireFencePreviousSignalTime; 1474 // tracks the expected present time of the last frame 1475 std::optional<nsecs_t> mLastExpectedPresentTime; 1476 // tracks the expected present time of the current frame 1477 nsecs_t mExpectedPresentTime; 1478 // set once at the start of composition to ensure consistency 1479 bool mUsePowerHints = false; 1480 nsecs_t getExpectedPresentTime(nsecs_t startTime); 1481 nsecs_t getPredictedPresentTime(nsecs_t startTime); 1482 nsecs_t getSignalTime(int32_t fd) const; 1483 void updateAverages(nsecs_t endTime); 1484 std::optional<nsecs_t> getPredictedDuration(bool duringValidation); 1485 atomic_bool mDebugRCDLayerEnabled = true; 1486 1487 protected: getDisplayVsyncPeriodFromConfig(hwc2_config_t config)1488 inline uint32_t getDisplayVsyncPeriodFromConfig(hwc2_config_t config) { 1489 int32_t vsync_period; 1490 getDisplayAttribute(config, HWC2_ATTRIBUTE_VSYNC_PERIOD, &vsync_period); 1491 assert(vsync_period > 0); 1492 return static_cast<uint32_t>(vsync_period); 1493 } 1494 1495 virtual void calculateTimeline( 1496 hwc2_config_t config, 1497 hwc_vsync_period_change_constraints_t* vsyncPeriodChangeConstraints, 1498 hwc_vsync_period_change_timeline_t* outTimeline); 1499 }; 1500 1501 #endif //_EXYNOSDISPLAY_H 1502