summaryrefslogtreecommitdiff
path: root/libhwc2.1/libmaindisplay/ExynosPrimaryDisplay.h
blob: f308d7d08e6156fdea42c0eda188b950fd85c005 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
/*
 * Copyright (C) 2012 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
#ifndef EXYNOS_PRIMARY_DISPLAY_H
#define EXYNOS_PRIMARY_DISPLAY_H

#include <map>

#include "../libdevice/ExynosDisplay.h"

using namespace displaycolor;

class ExynosPrimaryDisplay : public ExynosDisplay {
    public:
        /* Methods */
        ExynosPrimaryDisplay(uint32_t index, ExynosDevice* device, const std::string& displayName);
        ~ExynosPrimaryDisplay();
        virtual void setDDIScalerEnable(int width, int height);
        virtual int getDDIScalerMode(int width, int height);
        virtual int32_t SetCurrentPanelGammaSource(const displaycolor::DisplayType type,
                                                   const PanelGammaSource& source) override;
        virtual PanelGammaSource GetCurrentPanelGammaSource() const override {
            return currentPanelGammaSource;
        }

        virtual bool isLhbmSupported();
        virtual int32_t setLhbmState(bool enabled);

        virtual bool getLhbmState();
        virtual void setEarlyWakeupDisplay();
        virtual void setExpectedPresentTime(uint64_t timestamp);
        virtual uint64_t getPendingExpectedPresentTime();
        virtual void applyExpectedPresentTime();
        virtual int32_t setDisplayIdleTimer(const int32_t timeoutMs) override;
        virtual void handleDisplayIdleEnter(const uint32_t idleTeRefreshRate) override;

        virtual void initDisplayInterface(uint32_t interfaceType);
        virtual int32_t doDisplayConfigInternal(hwc2_config_t config) override;

        virtual int setMinIdleRefreshRate(const int fps,
                                          const VrrThrottleRequester requester) override;
        virtual int setRefreshRateThrottleNanos(const int64_t delayNs,
                                                const VrrThrottleRequester requester) override;
        virtual bool isDbmSupported() override;
        virtual int32_t setDbmState(bool enabled) override;

        virtual void dump(String8& result) override;
        virtual void updateAppliedActiveConfig(const hwc2_config_t newConfig,
                                               const int64_t ts) override;
        virtual void checkBtsReassignResource(const uint32_t vsyncPeriod,
                                              const uint32_t btsVsyncPeriod) override;

        virtual int32_t setBootDisplayConfig(int32_t config) override;
        virtual int32_t clearBootDisplayConfig() override;
        virtual int32_t getPreferredDisplayConfigInternal(int32_t* outConfig) override;
        virtual bool isConfigSettingEnabled() override;
        virtual void enableConfigSetting(bool en) override;

    protected:
        /* setPowerMode(int32_t mode)
         * Descriptor: HWC2_FUNCTION_SET_POWER_MODE
         * Parameters:
         *   mode - hwc2_power_mode_t and ext_hwc2_power_mode_t
         *
         * Returns HWC2_ERROR_NONE or the following error:
         *   HWC2_ERROR_UNSUPPORTED when DOZE mode not support
         */
        virtual int32_t setPowerMode(int32_t mode) override;
        virtual bool getHDRException(ExynosLayer* __unused layer);
        virtual int32_t setActiveConfigInternal(hwc2_config_t config, bool force) override;
        virtual int32_t getActiveConfigInternal(hwc2_config_t* outConfig) override;
        DisplayType getDisplayTypeFromIndex(uint32_t index) {
            return (index >= DisplayType::DISPLAY_MAX) ? DisplayType::DISPLAY_PRIMARY
                                                       : DisplayType(mIndex);
        };

    public:
        // Prepare multi resolution
        ResolutionInfo mResolutionInfo;
        std::string getPanelSysfsPath(const displaycolor::DisplayType& type);

        uint32_t mRcdId = -1;

    private:
        static constexpr const char* kDisplayCalFilePath = "/mnt/vendor/persist/display/";
        static constexpr const char* kPanelGammaCalFilePrefix = "gamma_calib_data";
        enum PanelGammaSource currentPanelGammaSource = PanelGammaSource::GAMMA_DEFAULT;

        bool checkLhbmMode(bool status, nsecs_t timoutNs);
        void setLHBMRefreshRateThrottle(const uint32_t delayMs);

        bool mFirstPowerOn = true;
        bool mNotifyPowerOn = false;
        std::mutex mPowerModeMutex;
        std::condition_variable mPowerOnCondition;

        int32_t applyPendingConfig();
        int32_t setPowerOn();
        int32_t setPowerOff();
        int32_t setPowerDoze(hwc2_power_mode_t mode);
        void firstPowerOn();
        int32_t setDisplayIdleTimerEnabled(const bool enabled);
        int32_t getDisplayIdleTimerEnabled(bool& enabled);
        void setDisplayNeedHandleIdleExit(const bool needed, const bool force);
        int32_t setDisplayIdleDelayNanos(int32_t delayNanos,
                                         const DispIdleTimerRequester requester);
        void initDisplayHandleIdleExit();
        int32_t setLhbmDisplayConfigLocked(uint32_t peakRate);
        void restoreLhbmDisplayConfigLocked();

        // LHBM
        FILE* mLhbmFd;
        std::atomic<bool> mLhbmOn;
        int32_t mFramesToReachLhbmPeakBrightness;
        bool mConfigSettingDisabled = false;
        int64_t mConfigSettingDisabledTimestamp = 0;
        // timeout value of waiting for peak refresh rate
        static constexpr uint32_t kLhbmWaitForPeakRefreshRateMs = 100U;
        static constexpr uint32_t kLhbmRefreshRateThrottleMs = 1000U;
        static constexpr uint32_t kConfigDisablingMaxDurationMs = 1000U;
        static constexpr uint32_t kSysfsCheckTimeoutMs = 500U;

        int32_t getTimestampDeltaMs(int64_t endNs, int64_t beginNs) {
            if (endNs == 0) endNs = systemTime(SYSTEM_TIME_MONOTONIC);
            return (endNs - beginNs) / 1000000;
        }

        FILE* mEarlyWakeupDispFd;
        static constexpr const char* kWakeupDispFilePath =
                "/sys/devices/platform/1c300000.drmdecon/early_wakeup";

        CtrlValue<uint64_t> mExpectedPresentTime;

        void calculateTimeline(hwc2_config_t config,
                               hwc_vsync_period_change_constraints_t* vsyncPeriodChangeConstraints,
                               hwc_vsync_period_change_timeline_t* outTimeline) override;

        // min idle refresh rate
        int mDefaultMinIdleRefreshRate;
        // the min refresh rate in the blocking zone, e.g. 10 means 10Hz in the zone
        int mMinIdleRefreshRateForBlockingZone;
        // blocking zone threshold, e.g. 492 means entering the zone if DBV < 492
        uint32_t mDbvThresholdForBlockingZone;
        bool mUseBlockingZoneForMinIdleRefreshRate;
        int mMinIdleRefreshRate;
        int mVrrThrottleFps[toUnderlying(VrrThrottleRequester::MAX)];
        std::mutex mMinIdleRefreshRateMutex;

        std::mutex mIdleRefreshRateThrottleMutex;
        int64_t mVrrThrottleNanos[toUnderlying(VrrThrottleRequester::MAX)];
        int64_t mRefreshRateDelayNanos;
        int64_t mLastRefreshRateAppliedNanos;
        hwc2_config_t mAppliedActiveConfig;

        std::mutex mDisplayIdleDelayMutex;
        bool mDisplayIdleTimerEnabled;
        int64_t mDisplayIdleTimerNanos[toUnderlying(DispIdleTimerRequester::MAX)];
        std::ofstream mDisplayNeedHandleIdleExitOfs;
        int64_t mDisplayIdleDelayNanos;
        bool mDisplayNeedHandleIdleExit;
};

#endif