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 #ifndef EXYNOS_PRIMARY_DISPLAY_H 17 #define EXYNOS_PRIMARY_DISPLAY_H 18 19 #include <map> 20 21 #include "../libdevice/ExynosDisplay.h" 22 23 using namespace displaycolor; 24 25 class ExynosPrimaryDisplay : public ExynosDisplay { 26 public: 27 /* Methods */ 28 ExynosPrimaryDisplay(uint32_t index, ExynosDevice* device, const std::string& displayName); 29 ~ExynosPrimaryDisplay(); 30 virtual void setDDIScalerEnable(int width, int height); 31 virtual int getDDIScalerMode(int width, int height); 32 virtual int32_t SetCurrentPanelGammaSource(const displaycolor::DisplayType type, 33 const PanelGammaSource& source) override; GetCurrentPanelGammaSource()34 virtual PanelGammaSource GetCurrentPanelGammaSource() const override { 35 return currentPanelGammaSource; 36 } 37 38 virtual bool isLhbmSupported(); 39 virtual int32_t setLhbmState(bool enabled); 40 41 virtual bool getLhbmState(); 42 virtual void setEarlyWakeupDisplay(); 43 virtual void setExpectedPresentTime(uint64_t timestamp); 44 virtual uint64_t getPendingExpectedPresentTime(); 45 virtual void applyExpectedPresentTime(); 46 virtual int32_t setDisplayIdleTimer(const int32_t timeoutMs) override; 47 virtual void handleDisplayIdleEnter(const uint32_t idleTeRefreshRate) override; 48 49 virtual void initDisplayInterface(uint32_t interfaceType); 50 virtual int32_t doDisplayConfigInternal(hwc2_config_t config) override; 51 52 virtual int setMinIdleRefreshRate(const int fps, 53 const VrrThrottleRequester requester) override; 54 virtual int setRefreshRateThrottleNanos(const int64_t delayNs, 55 const VrrThrottleRequester requester) override; 56 virtual bool isDbmSupported() override; 57 virtual int32_t setDbmState(bool enabled) override; 58 59 virtual void dump(String8& result) override; 60 virtual void updateAppliedActiveConfig(const hwc2_config_t newConfig, 61 const int64_t ts) override; 62 virtual void checkBtsReassignResource(const uint32_t vsyncPeriod, 63 const uint32_t btsVsyncPeriod) override; 64 65 virtual int32_t setBootDisplayConfig(int32_t config) override; 66 virtual int32_t clearBootDisplayConfig() override; 67 virtual int32_t getPreferredDisplayConfigInternal(int32_t* outConfig) override; 68 virtual bool isConfigSettingEnabled() override; 69 virtual void enableConfigSetting(bool en) override; 70 71 protected: 72 /* setPowerMode(int32_t mode) 73 * Descriptor: HWC2_FUNCTION_SET_POWER_MODE 74 * Parameters: 75 * mode - hwc2_power_mode_t and ext_hwc2_power_mode_t 76 * 77 * Returns HWC2_ERROR_NONE or the following error: 78 * HWC2_ERROR_UNSUPPORTED when DOZE mode not support 79 */ 80 virtual int32_t setPowerMode(int32_t mode) override; 81 virtual bool getHDRException(ExynosLayer* __unused layer); 82 virtual int32_t setActiveConfigInternal(hwc2_config_t config, bool force) override; 83 virtual int32_t getActiveConfigInternal(hwc2_config_t* outConfig) override; getDisplayTypeFromIndex(uint32_t index)84 DisplayType getDisplayTypeFromIndex(uint32_t index) { 85 return (index >= DisplayType::DISPLAY_MAX) ? DisplayType::DISPLAY_PRIMARY 86 : DisplayType(mIndex); 87 }; 88 89 public: 90 // Prepare multi resolution 91 ResolutionInfo mResolutionInfo; 92 std::string getPanelSysfsPath(const displaycolor::DisplayType& type); 93 94 uint32_t mRcdId = -1; 95 96 private: 97 static constexpr const char* kDisplayCalFilePath = "/mnt/vendor/persist/display/"; 98 static constexpr const char* kPanelGammaCalFilePrefix = "gamma_calib_data"; 99 enum PanelGammaSource currentPanelGammaSource = PanelGammaSource::GAMMA_DEFAULT; 100 101 bool checkLhbmMode(bool status, nsecs_t timoutNs); 102 void setLHBMRefreshRateThrottle(const uint32_t delayMs); 103 104 bool mFirstPowerOn = true; 105 bool mNotifyPowerOn = false; 106 std::mutex mPowerModeMutex; 107 std::condition_variable mPowerOnCondition; 108 109 int32_t applyPendingConfig(); 110 int32_t setPowerOn(); 111 int32_t setPowerOff(); 112 int32_t setPowerDoze(hwc2_power_mode_t mode); 113 void firstPowerOn(); 114 int32_t setDisplayIdleTimerEnabled(const bool enabled); 115 int32_t getDisplayIdleTimerEnabled(bool& enabled); 116 void setDisplayNeedHandleIdleExit(const bool needed, const bool force); 117 int32_t setDisplayIdleDelayNanos(int32_t delayNanos, 118 const DispIdleTimerRequester requester); 119 void initDisplayHandleIdleExit(); 120 int32_t setLhbmDisplayConfigLocked(uint32_t peakRate); 121 void restoreLhbmDisplayConfigLocked(); 122 123 // LHBM 124 FILE* mLhbmFd; 125 std::atomic<bool> mLhbmOn; 126 int32_t mFramesToReachLhbmPeakBrightness; 127 bool mConfigSettingDisabled = false; 128 int64_t mConfigSettingDisabledTimestamp = 0; 129 // timeout value of waiting for peak refresh rate 130 static constexpr uint32_t kLhbmWaitForPeakRefreshRateMs = 100U; 131 static constexpr uint32_t kLhbmRefreshRateThrottleMs = 1000U; 132 static constexpr uint32_t kConfigDisablingMaxDurationMs = 1000U; 133 static constexpr uint32_t kSysfsCheckTimeoutMs = 500U; 134 getTimestampDeltaMs(int64_t endNs,int64_t beginNs)135 int32_t getTimestampDeltaMs(int64_t endNs, int64_t beginNs) { 136 if (endNs == 0) endNs = systemTime(SYSTEM_TIME_MONOTONIC); 137 return (endNs - beginNs) / 1000000; 138 } 139 140 FILE* mEarlyWakeupDispFd; 141 static constexpr const char* kWakeupDispFilePath = 142 "/sys/devices/platform/1c300000.drmdecon/early_wakeup"; 143 144 CtrlValue<uint64_t> mExpectedPresentTime; 145 146 void calculateTimeline(hwc2_config_t config, 147 hwc_vsync_period_change_constraints_t* vsyncPeriodChangeConstraints, 148 hwc_vsync_period_change_timeline_t* outTimeline) override; 149 150 // min idle refresh rate 151 int mDefaultMinIdleRefreshRate; 152 // the min refresh rate in the blocking zone, e.g. 10 means 10Hz in the zone 153 int mMinIdleRefreshRateForBlockingZone; 154 // blocking zone threshold, e.g. 492 means entering the zone if DBV < 492 155 uint32_t mDbvThresholdForBlockingZone; 156 bool mUseBlockingZoneForMinIdleRefreshRate; 157 int mMinIdleRefreshRate; 158 int mVrrThrottleFps[toUnderlying(VrrThrottleRequester::MAX)]; 159 std::mutex mMinIdleRefreshRateMutex; 160 161 std::mutex mIdleRefreshRateThrottleMutex; 162 int64_t mVrrThrottleNanos[toUnderlying(VrrThrottleRequester::MAX)]; 163 int64_t mRefreshRateDelayNanos; 164 int64_t mLastRefreshRateAppliedNanos; 165 hwc2_config_t mAppliedActiveConfig; 166 167 std::mutex mDisplayIdleDelayMutex; 168 bool mDisplayIdleTimerEnabled; 169 int64_t mDisplayIdleTimerNanos[toUnderlying(DispIdleTimerRequester::MAX)]; 170 std::ofstream mDisplayNeedHandleIdleExitOfs; 171 int64_t mDisplayIdleDelayNanos; 172 bool mDisplayNeedHandleIdleExit; 173 }; 174 175 #endif 176