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); 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) override; 53 virtual int setRefreshRateThrottleNanos(const int64_t delayNs, 54 const VrrThrottleRequester requester) override; 55 virtual bool isDbmSupported() override; 56 virtual int32_t setDbmState(bool enabled) override; 57 58 virtual void dump(String8& result) override; 59 virtual void updateAppliedActiveConfig(const hwc2_config_t newConfig, 60 const int64_t ts) override; 61 virtual void checkBtsReassignResource(const uint32_t vsyncPeriod, 62 const uint32_t btsVsyncPeriod) override; 63 64 virtual int32_t setBootDisplayConfig(int32_t config) override; 65 virtual int32_t clearBootDisplayConfig() override; 66 virtual int32_t getPreferredDisplayConfigInternal(int32_t* outConfig) override; 67 68 protected: 69 /* setPowerMode(int32_t mode) 70 * Descriptor: HWC2_FUNCTION_SET_POWER_MODE 71 * Parameters: 72 * mode - hwc2_power_mode_t and ext_hwc2_power_mode_t 73 * 74 * Returns HWC2_ERROR_NONE or the following error: 75 * HWC2_ERROR_UNSUPPORTED when DOZE mode not support 76 */ 77 virtual int32_t setPowerMode(int32_t mode) override; 78 virtual bool getHDRException(ExynosLayer* __unused layer); 79 virtual int32_t setActiveConfigInternal(hwc2_config_t config, bool force) override; 80 virtual int32_t getActiveConfigInternal(hwc2_config_t* outConfig) override; getDisplayTypeFromIndex(uint32_t index)81 DisplayType getDisplayTypeFromIndex(uint32_t index) { 82 return (index >= DisplayType::DISPLAY_MAX) ? DisplayType::DISPLAY_PRIMARY 83 : DisplayType(mIndex); 84 }; 85 86 public: 87 // Prepare multi resolution 88 ResolutionInfo mResolutionInfo; 89 std::string getPanelSysfsPath(const displaycolor::DisplayType& type); 90 91 private: 92 static constexpr const char* kDisplayCalFilePath = "/mnt/vendor/persist/display/"; 93 static constexpr const char* kPanelGammaCalFilePrefix = "gamma_calib_data"; 94 enum PanelGammaSource currentPanelGammaSource = PanelGammaSource::GAMMA_DEFAULT; 95 96 bool checkLhbmMode(bool status, nsecs_t timoutNs); 97 void setLHBMRefreshRateThrottle(const uint32_t delayMs); 98 99 hwc2_config_t mPendActiveConfig = UINT_MAX; 100 bool mFirstPowerOn = true; 101 bool mNotifyPowerOn = false; 102 std::mutex mPowerModeMutex; 103 std::condition_variable mPowerOnCondition; 104 105 int32_t applyPendingConfig(); 106 int32_t setPowerOn(); 107 int32_t setPowerOff(); 108 int32_t setPowerDoze(hwc2_power_mode_t mode); 109 void firstPowerOn(); 110 int32_t setDisplayIdleTimerEnabled(const bool enabled); 111 int32_t getDisplayIdleTimerEnabled(bool& enabled); 112 void setDisplayNeedHandleIdleExit(const bool needed, const bool force); 113 int32_t setDisplayIdleDelayNanos(int32_t delayNanos, 114 const DispIdleTimerRequester requester); 115 void initDisplayHandleIdleExit(); 116 117 // LHBM 118 FILE* mLhbmFd; 119 std::atomic<bool> mLhbmOn; 120 int32_t mFramesToReachLhbmPeakBrightness; 121 // timeout value of waiting for peak refresh rate 122 static constexpr uint32_t kLhbmWaitForPeakRefreshRateMs = 200; 123 static constexpr uint32_t kLhbmRefreshRateThrottleMs = 1000; 124 125 FILE* mEarlyWakeupDispFd; 126 static constexpr const char* kWakeupDispFilePath = 127 "/sys/devices/platform/1c300000.drmdecon/early_wakeup"; 128 129 CtrlValue<uint64_t> mExpectedPresentTime; 130 131 void calculateTimeline(hwc2_config_t config, 132 hwc_vsync_period_change_constraints_t* vsyncPeriodChangeConstraints, 133 hwc_vsync_period_change_timeline_t* outTimeline) override; 134 std::mutex mIdleRefreshRateThrottleMutex; 135 int mMinIdleRefreshRate; 136 int64_t mVrrThrottleNanos[toUnderlying(VrrThrottleRequester::MAX)]; 137 int64_t mRefreshRateDelayNanos; 138 int64_t mLastRefreshRateAppliedNanos; 139 hwc2_config_t mAppliedActiveConfig; 140 141 std::mutex mDisplayIdleDelayMutex; 142 bool mDisplayIdleTimerEnabled; 143 int64_t mDisplayIdleTimerNanos[toUnderlying(DispIdleTimerRequester::MAX)]; 144 std::ofstream mDisplayNeedHandleIdleExitOfs; 145 int64_t mDisplayIdleDelayNanos; 146 bool mDisplayNeedHandleIdleExit; 147 }; 148 149 #endif 150