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