1 /* 2 * Copyright (C) 2019 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_DISPLAY_MODULE_H 17 #define EXYNOS_DISPLAY_MODULE_H 18 19 #include "ColorManager.h" 20 #include "DisplaySceneInfo.h" 21 #include "ExynosDeviceModule.h" 22 #include "ExynosDisplay.h" 23 #include "ExynosLayer.h" 24 #include "ExynosPrimaryDisplay.h" 25 26 constexpr char kAtcJsonRaw[] = 27 "{\"version\":\"0.0\",\"modes\":[{\"name\":\"normal\",\"lux_map\":[0,5000,10000," 28 "50000,70000],\"ambient_light_map\":[0,0,12,32,63],\"strength_map\":[0,0,128,128,200]," 29 "\"st_up_step\":2, \"st_down_step\":2," 30 "\"sub_setting\":{\"local_tone_gain\":128,\"noise_suppression_gain\":128,\"dither\":0," 31 "\"plain_weight_1\":10,\"plain_weight_2\":14,\"color_transform_mode\":2,\"preprocessing_" 32 "enable\":1,\"upgrade_on\":0,\"TDR_max\":900,\"TDR_min\":256,\"backlight\":255,\"dimming_" 33 "step\":4,\"scale_mode\":1,\"threshold_1\":1,\"threshold_2\":1,\"threshold_3\":1,\"gain_" 34 "limit\":511,\"lt_calc_ab_shift\":1}}]}"; 35 36 constexpr char kAtcProfilePath[] = "vendor/etc/atc_profile.json"; 37 constexpr char kAtcProfileVersionStr[] = "version"; 38 constexpr char kAtcProfileModesStr[] = "modes"; 39 constexpr char kAtcProfileModeNameStr[] = "name"; 40 constexpr char kAtcProfileLuxMapStr[] = "lux_map"; 41 constexpr char kAtcProfileAlMapStr[] = "ambient_light_map"; 42 constexpr char kAtcProfileStMapStr[] = "strength_map"; 43 constexpr char kAtcProfileSubSettingStr[] = "sub_setting"; 44 constexpr char kAtcProfileStUpStepStr[] = "st_up_step"; 45 constexpr char kAtcProfileStDownStepStr[] = "st_down_step"; 46 constexpr uint32_t kAtcStStep = 2; 47 48 constexpr char kAtcModeNormalStr[] = "normal"; 49 constexpr char kAtcModeHbmStr[] = "hbm"; 50 constexpr char kAtcModePowerSaveStr[] = "power_save"; 51 constexpr char kAtcModeHdrStr[] = "hdr"; 52 53 #define ATC_AMBIENT_LIGHT_FILE_NAME "/sys/class/dqe%d/atc/ambient_light" 54 #define ATC_ST_FILE_NAME "/sys/class/dqe%d/atc/st" 55 #define ATC_ENABLE_FILE_NAME "/sys/class/dqe%d/atc/en" 56 #define ATC_LT_FILE_NAME "/sys/class/dqe%d/atc/lt" 57 #define ATC_NS_FILE_NAME "/sys/class/dqe%d/atc/ns" 58 #define ATC_DITHER_FILE_NAME "/sys/class/dqe%d/atc/dither" 59 #define ATC_PL_W1_FILE_NAME "/sys/class/dqe%d/atc/pl_w1" 60 #define ATC_PL_W2_FILE_NAME "/sys/class/dqe%d/atc/pl_w2" 61 #define ATC_CTMODE_FILE_NAME "/sys/class/dqe%d/atc/ctmode" 62 #define ATC_PP_EN_FILE_NAME "/sys/class/dqe%d/atc/pp_en" 63 #define ATC_UPGRADE_ON_FILE_NAME "/sys/class/dqe%d/atc/upgrade_on" 64 #define ATC_TDR_MAX_FILE_NAME "/sys/class/dqe%d/atc/tdr_max" 65 #define ATC_TDR_MIN_FILE_NAME "/sys/class/dqe%d/atc/tdr_min" 66 #define ATC_BACKLIGHT_FILE_NAME "/sys/class/dqe%d/atc/back_light" 67 #define ATC_DSTEP_FILE_NAME "/sys/class/dqe%d/atc/dstep" 68 #define ATC_SCALE_MODE_FILE_NAME "/sys/class/dqe%d/atc/scale_mode" 69 #define ATC_THRESHOLD_1_FILE_NAME "/sys/class/dqe%d/atc/threshold_1" 70 #define ATC_THRESHOLD_2_FILE_NAME "/sys/class/dqe%d/atc/threshold_2" 71 #define ATC_THRESHOLD_3_FILE_NAME "/sys/class/dqe%d/atc/threshold_3" 72 #define ATC_GAIN_LIMIT_FILE_NAME "/sys/class/dqe%d/atc/gain_limit" 73 #define ATC_LT_CALC_AB_SHIFT_FILE_NAME "/sys/class/dqe%d/atc/lt_calc_ab_shift" 74 75 const std::unordered_map<std::string, std::string> kAtcSubSetting = 76 {{"local_tone_gain", ATC_LT_FILE_NAME}, 77 {"noise_suppression_gain", ATC_NS_FILE_NAME}, 78 {"dither", ATC_DITHER_FILE_NAME}, 79 {"plain_weight_1", ATC_PL_W1_FILE_NAME}, 80 {"plain_weight_2", ATC_PL_W2_FILE_NAME}, 81 {"color_transform_mode", ATC_CTMODE_FILE_NAME}, 82 {"preprocessing_enable", ATC_PP_EN_FILE_NAME}, 83 {"upgrade_on", ATC_UPGRADE_ON_FILE_NAME}, 84 {"TDR_max", ATC_TDR_MAX_FILE_NAME}, 85 {"TDR_min", ATC_TDR_MIN_FILE_NAME}, 86 {"backlight", ATC_BACKLIGHT_FILE_NAME}, 87 {"dimming_step", ATC_DSTEP_FILE_NAME}, 88 {"scale_mode", ATC_SCALE_MODE_FILE_NAME}, 89 {"threshold_1", ATC_THRESHOLD_1_FILE_NAME}, 90 {"threshold_2", ATC_THRESHOLD_2_FILE_NAME}, 91 {"threshold_3", ATC_THRESHOLD_3_FILE_NAME}, 92 {"gain_limit", ATC_GAIN_LIMIT_FILE_NAME}, 93 {"lt_calc_ab_shift", ATC_LT_CALC_AB_SHIFT_FILE_NAME}}; 94 95 namespace gs101 { 96 97 using namespace displaycolor; 98 99 class ExynosPrimaryDisplayModule : public ExynosPrimaryDisplay { 100 using GsInterfaceType = gs::ColorDrmBlobFactory::GsInterfaceType; 101 public: 102 ExynosPrimaryDisplayModule(uint32_t index, ExynosDevice* device, 103 const std::string& displayName); 104 ~ExynosPrimaryDisplayModule(); 105 void usePreDefinedWindow(bool use); 106 virtual int32_t validateWinConfigData(); 107 void doPreProcessing(); 108 virtual int32_t getColorModes(uint32_t* outNumModes, int32_t* outModes) override; 109 virtual int32_t setColorMode(int32_t mode) override; 110 virtual int32_t getRenderIntents(int32_t mode, uint32_t* outNumIntents, 111 int32_t* outIntents) override; 112 virtual int32_t setColorModeWithRenderIntent(int32_t mode, int32_t intent) override; 113 virtual int32_t setColorTransform(const float* matrix, int32_t hint) override; 114 virtual int32_t getClientTargetProperty( 115 hwc_client_target_property_t* outClientTargetProperty, 116 HwcDimmingStage *outDimmingStage = nullptr) override; 117 virtual int deliverWinConfigData(); 118 virtual int32_t updateColorConversionInfo() override; 119 virtual int32_t resetColorMappingInfo(ExynosMPPSource* mppSrc) override; 120 virtual int32_t updatePresentColorConversionInfo(); checkRrCompensationEnabled()121 virtual bool checkRrCompensationEnabled() { 122 const DisplayType display = getDcDisplayType(); 123 GsInterfaceType* displayColorInterface = getDisplayColorInterface(); 124 return displayColorInterface 125 ? displayColorInterface->IsRrCompensationEnabled(display) 126 : false; 127 } 128 129 virtual int32_t getColorAdjustedDbv(uint32_t &dbv_adj); 130 131 virtual void initLbe(); 132 virtual bool isLbeSupported(); 133 virtual void setLbeState(LbeState state); 134 virtual void setLbeAmbientLight(int value); 135 virtual LbeState getLbeState(); 136 137 virtual PanelCalibrationStatus getPanelCalibrationStatus(); 138 hasDisplayColor()139 bool hasDisplayColor() { 140 GsInterfaceType* displayColorInterface = getDisplayColorInterface(); 141 return displayColorInterface != nullptr; 142 } 143 144 int32_t updateBrightnessTable(); 145 getColorManager()146 ColorManager* getColorManager() { return mColorManager.get(); } 147 148 private: 149 std::unique_ptr<ColorManager> mColorManager; 150 getDisplaySceneInfo()151 DisplaySceneInfo& getDisplaySceneInfo() { return mColorManager->getDisplaySceneInfo(); } 152 153 struct atc_lux_map { 154 uint32_t lux; 155 uint32_t al; 156 uint32_t st; 157 }; 158 159 struct atc_mode { 160 std::vector<atc_lux_map> lux_map; 161 std::unordered_map<std::string, int32_t> sub_setting; 162 uint32_t st_up_step; 163 uint32_t st_down_step; 164 }; 165 struct atc_sysfs { 166 String8 node; 167 CtrlValue<int32_t> value; 168 }; 169 170 bool parseAtcProfile(); 171 int32_t setAtcMode(std::string mode_name); 172 uint32_t getAtcLuxMapIndex(std::vector<atc_lux_map>, uint32_t lux); 173 int32_t setAtcAmbientLight(uint32_t ambient_light); 174 int32_t setAtcStrength(uint32_t strenght); 175 int32_t setAtcStDimming(uint32_t target); 176 int32_t setAtcEnable(bool enable); 177 void checkAtcAnimation(); 178 void checkAtcHdrMode(); isInAtcAnimation()179 bool isInAtcAnimation() { 180 if (mAtcStStepCount > 0) 181 return true; 182 else 183 return false; 184 }; 185 getDisplayColorInterface()186 GsInterfaceType* getDisplayColorInterface() { 187 ExynosDeviceModule* device = (ExynosDeviceModule*)mDevice; 188 return device->getDisplayColorInterface(); 189 } 190 isForceColorUpdate()191 bool isForceColorUpdate() const { return mForceColorUpdate; } setForceColorUpdate(bool force)192 void setForceColorUpdate(bool force) { mForceColorUpdate = force; } 193 bool isDisplaySwitched(int32_t mode, int32_t prevMode); 194 195 std::map<std::string, atc_mode> mAtcModeSetting; 196 bool mAtcInit; 197 LbeState mCurrentLbeState = LbeState::OFF; 198 std::string mCurrentAtcModeName; 199 uint32_t mCurrentLux = 0; 200 uint32_t mAtcLuxMapIndex = 0; 201 struct atc_sysfs mAtcAmbientLight; 202 struct atc_sysfs mAtcStrength; 203 struct atc_sysfs mAtcEnable; 204 std::unordered_map<std::string, struct atc_sysfs> mAtcSubSetting; 205 uint32_t mAtcStStepCount = 0; 206 uint32_t mAtcStTarget = 0; 207 uint32_t mAtcStUpStep; 208 uint32_t mAtcStDownStep; 209 Mutex mAtcStMutex; 210 bool mPendingAtcOff; 211 bool mForceColorUpdate = false; 212 bool mLbeSupported = false; 213 bool isFullScreenHdrLayer(); 214 215 protected: 216 virtual int32_t setPowerMode(int32_t mode) override; 217 }; 218 219 } // namespace gs101 220 221 #endif 222