• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "ExynosDeviceModule.h"
20 #include "ExynosDisplay.h"
21 #include "ExynosLayer.h"
22 #include "ExynosPrimaryDisplay.h"
23 
24 constexpr char kAtcJsonRaw[] =
25         "{\"version\":\"0.0\",\"modes\":[{\"name\":\"normal\",\"lux_map\":[0,5000,10000,"
26         "50000,70000],\"ambient_light_map\":[0,0,12,32,63],\"strength_map\":[0,0,128,128,200],"
27         "\"st_up_step\":2, \"st_down_step\":2,"
28         "\"sub_setting\":{\"local_tone_gain\":128,\"noise_suppression_gain\":128,\"dither\":0,"
29         "\"plain_weight_1\":10,\"plain_weight_2\":14,\"color_transform_mode\":2,\"preprocessing_"
30         "enable\":1,\"upgrade_on\":0,\"TDR_max\":900,\"TDR_min\":256,\"backlight\":255,\"dimming_"
31         "step\":4,\"scale_mode\":1,\"threshold_1\":1,\"threshold_2\":1,\"threshold_3\":1,\"gain_"
32         "limit\":511,\"lt_calc_ab_shift\":1}}]}";
33 
34 constexpr char kAtcProfilePath[] = "vendor/etc/atc_profile.json";
35 constexpr char kAtcProfileVersionStr[] = "version";
36 constexpr char kAtcProfileModesStr[] = "modes";
37 constexpr char kAtcProfileModeNameStr[] = "name";
38 constexpr char kAtcProfileLuxMapStr[] = "lux_map";
39 constexpr char kAtcProfileAlMapStr[] = "ambient_light_map";
40 constexpr char kAtcProfileStMapStr[] = "strength_map";
41 constexpr char kAtcProfileSubSettingStr[] = "sub_setting";
42 constexpr char kAtcProfileStUpStepStr[] = "st_up_step";
43 constexpr char kAtcProfileStDownStepStr[] = "st_down_step";
44 constexpr uint32_t kAtcStStep = 2;
45 
46 constexpr char kAtcModeNormalStr[] = "normal";
47 constexpr char kAtcModeHbmStr[] = "hbm";
48 constexpr char kAtcModePowerSaveStr[] = "power_save";
49 
50 #define ATC_AMBIENT_LIGHT_FILE_NAME "/sys/class/dqe%d/atc/ambient_light"
51 #define ATC_ST_FILE_NAME "/sys/class/dqe%d/atc/st"
52 #define ATC_ENABLE_FILE_NAME "/sys/class/dqe%d/atc/en"
53 #define ATC_LT_FILE_NAME "/sys/class/dqe%d/atc/lt"
54 #define ATC_NS_FILE_NAME "/sys/class/dqe%d/atc/ns"
55 #define ATC_DITHER_FILE_NAME "/sys/class/dqe%d/atc/dither"
56 #define ATC_PL_W1_FILE_NAME "/sys/class/dqe%d/atc/pl_w1"
57 #define ATC_PL_W2_FILE_NAME "/sys/class/dqe%d/atc/pl_w2"
58 #define ATC_CTMODE_FILE_NAME "/sys/class/dqe%d/atc/ctmode"
59 #define ATC_PP_EN_FILE_NAME "/sys/class/dqe%d/atc/pp_en"
60 #define ATC_UPGRADE_ON_FILE_NAME "/sys/class/dqe%d/atc/upgrade_on"
61 #define ATC_TDR_MAX_FILE_NAME "/sys/class/dqe%d/atc/tdr_max"
62 #define ATC_TDR_MIN_FILE_NAME "/sys/class/dqe%d/atc/tdr_min"
63 #define ATC_BACKLIGHT_FILE_NAME "/sys/class/dqe%d/atc/back_light"
64 #define ATC_DSTEP_FILE_NAME "/sys/class/dqe%d/atc/dstep"
65 #define ATC_SCALE_MODE_FILE_NAME "/sys/class/dqe%d/atc/scale_mode"
66 #define ATC_THRESHOLD_1_FILE_NAME "/sys/class/dqe%d/atc/threshold_1"
67 #define ATC_THRESHOLD_2_FILE_NAME "/sys/class/dqe%d/atc/threshold_2"
68 #define ATC_THRESHOLD_3_FILE_NAME "/sys/class/dqe%d/atc/threshold_3"
69 #define ATC_GAIN_LIMIT_FILE_NAME "/sys/class/dqe%d/atc/gain_limit"
70 #define ATC_LT_CALC_AB_SHIFT_FILE_NAME "/sys/class/dqe%d/atc/lt_calc_ab_shift"
71 
72 const std::unordered_map<std::string, std::string> kAtcSubSetting =
73         {{"local_tone_gain", ATC_LT_FILE_NAME},
74          {"noise_suppression_gain", ATC_NS_FILE_NAME},
75          {"dither", ATC_DITHER_FILE_NAME},
76          {"plain_weight_1", ATC_PL_W1_FILE_NAME},
77          {"plain_weight_2", ATC_PL_W2_FILE_NAME},
78          {"color_transform_mode", ATC_CTMODE_FILE_NAME},
79          {"preprocessing_enable", ATC_PP_EN_FILE_NAME},
80          {"upgrade_on", ATC_UPGRADE_ON_FILE_NAME},
81          {"TDR_max", ATC_TDR_MAX_FILE_NAME},
82          {"TDR_min", ATC_TDR_MIN_FILE_NAME},
83          {"backlight", ATC_BACKLIGHT_FILE_NAME},
84          {"dimming_step", ATC_DSTEP_FILE_NAME},
85          {"scale_mode", ATC_SCALE_MODE_FILE_NAME},
86          {"threshold_1", ATC_THRESHOLD_1_FILE_NAME},
87          {"threshold_2", ATC_THRESHOLD_2_FILE_NAME},
88          {"threshold_3", ATC_THRESHOLD_3_FILE_NAME},
89          {"gain_limit", ATC_GAIN_LIMIT_FILE_NAME},
90          {"lt_calc_ab_shift", ATC_LT_CALC_AB_SHIFT_FILE_NAME}};
91 
92 namespace gs101 {
93 
94 using namespace displaycolor;
95 
96 class ExynosPrimaryDisplayModule : public ExynosPrimaryDisplay {
97     using GsInterfaceType = gs::ColorDrmBlobFactory::GsInterfaceType;
98     public:
99         ExynosPrimaryDisplayModule(uint32_t index, ExynosDevice* device,
100                                    const std::string& displayName);
101         ~ExynosPrimaryDisplayModule();
102         void usePreDefinedWindow(bool use);
103         virtual int32_t validateWinConfigData();
104         void doPreProcessing();
105         virtual int32_t getColorModes(
106                 uint32_t* outNumModes,
107                 int32_t* outModes);
108         virtual int32_t setColorMode(int32_t mode);
109         virtual int32_t getRenderIntents(int32_t mode, uint32_t* outNumIntents,
110                 int32_t* outIntents);
111         virtual int32_t setColorModeWithRenderIntent(int32_t mode,
112                 int32_t intent);
113         virtual int32_t setColorTransform(const float* matrix, int32_t hint);
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();
119         virtual int32_t resetColorMappingInfo(ExynosMPPSource* mppSrc);
120         virtual int32_t updatePresentColorConversionInfo();
checkRrCompensationEnabled()121         virtual bool checkRrCompensationEnabled() {
122             const DisplayType display = getDisplayTypeFromIndex(mIndex);
123             GsInterfaceType* displayColorInterface = getDisplayColorInterface();
124             return displayColorInterface
125                 ? displayColorInterface->IsRrCompensationEnabled(display)
126                 : false;
127         }
128 
129         virtual bool isColorCalibratedByDevice();
130 
131         virtual int32_t getColorAdjustedDbv(uint32_t &dbv_adj);
132 
133         virtual void initLbe();
134         virtual bool isLbeSupported();
135         virtual void setLbeState(LbeState state);
136         virtual void setLbeAmbientLight(int value);
137         virtual LbeState getLbeState();
138 
139         virtual PanelCalibrationStatus getPanelCalibrationStatus();
140 
141         class DisplaySceneInfo {
142             public:
143                 struct LayerMappingInfo {
144                     bool operator==(const LayerMappingInfo &rhs) const {
145                         return ((dppIdx == rhs.dppIdx) && (planeId == rhs.planeId));
146                     }
147 
148                     // index in DisplayScene::layer_data
149                     uint32_t dppIdx;
150                     // assigned drm plane id in last color setting update
151                     uint32_t planeId;
152                     static constexpr uint32_t kPlaneIdNone = std::numeric_limits<uint32_t>::max();
153                 };
154                 bool colorSettingChanged = false;
155                 bool displaySettingDelivered = false;
156                 DisplayScene displayScene;
157 
158                 /*
159                  * Index of LayerColorData in DisplayScene::layer_data
160                  * and assigned plane id in last color setting update.
161                  * for each layer, including client composition
162                  * key: ExynosMPPSource*
163                  * data: LayerMappingInfo
164                  */
165                 std::map<ExynosMPPSource*, LayerMappingInfo> layerDataMappingInfo;
166                 std::map<ExynosMPPSource*, LayerMappingInfo> prev_layerDataMappingInfo;
167 
reset()168                 void reset() {
169                     colorSettingChanged = false;
170                     prev_layerDataMappingInfo = layerDataMappingInfo;
171                     layerDataMappingInfo.clear();
172                 };
173 
174                 template <typename T, typename M>
updateInfoSingleVal(T & dst,M & src)175                 void updateInfoSingleVal(T &dst, M &src) {
176                     if (src != dst) {
177                         colorSettingChanged = true;
178                         dst = src;
179                     }
180                 };
181 
182                 template <typename T, typename M>
updateInfoVectorVal(std::vector<T> & dst,M * src,uint32_t size)183                 void updateInfoVectorVal(std::vector<T> &dst, M *src, uint32_t size) {
184                     if ((dst.size() != size) ||
185                         !std::equal(dst.begin(), dst.end(), src)) {
186                         colorSettingChanged = true;
187                         dst.resize(size);
188                         for (uint32_t i = 0; i < size; i++) {
189                             dst[i] = src[i];
190                         }
191                     }
192                 };
193 
setColorMode(hwc::ColorMode mode)194                 void setColorMode(hwc::ColorMode mode) {
195                     updateInfoSingleVal(displayScene.color_mode, mode);
196                 };
197 
setRenderIntent(hwc::RenderIntent intent)198                 void setRenderIntent(hwc::RenderIntent intent) {
199                     updateInfoSingleVal(displayScene.render_intent, intent);
200                 };
201 
setColorTransform(const float * matrix)202                 void setColorTransform(const float* matrix) {
203                     for (uint32_t i = 0; i < displayScene.matrix.size(); i++) {
204                         if (displayScene.matrix[i] != matrix[i]) {
205                             colorSettingChanged = true;
206                             displayScene.matrix[i] = matrix[i];
207                         }
208                     }
209                 }
210 
211                 LayerColorData& getLayerColorDataInstance(uint32_t index);
212                 int32_t setLayerDataMappingInfo(ExynosMPPSource* layer, uint32_t index);
213                 void setLayerDataspace(LayerColorData& layerColorData,
214                         hwc::Dataspace dataspace);
215                 void disableLayerHdrStaticMetadata(LayerColorData& layerColorData);
216                 void setLayerHdrStaticMetadata(LayerColorData& layerColorData,
217                         const ExynosHdrStaticInfo& exynosHdrStaticInfo);
218                 void setLayerColorTransform(LayerColorData& layerColorData,
219                         std::array<float, TRANSFORM_MAT_SIZE> &matrix);
220                 void disableLayerHdrDynamicMetadata(LayerColorData& layerColorData);
221                 void setLayerHdrDynamicMetadata(LayerColorData& layerColorData,
222                         const ExynosHdrDynamicInfo& exynosHdrDynamicInfo);
223                 int32_t setLayerColorData(LayerColorData& layerData,
224                         ExynosLayer* layer, float dimSdrRatio);
225                 int32_t setClientCompositionColorData(
226                     const ExynosCompositionInfo& clientCompositionInfo,
227                     LayerColorData& layerData, float dimSdrRatio);
228                 bool needDisplayColorSetting();
229                 void printDisplayScene();
230                 void printLayerColorData(const LayerColorData& layerData);
231         };
232 
hasDisplayColor()233         bool hasDisplayColor() {
234             GsInterfaceType* displayColorInterface = getDisplayColorInterface();
235             return displayColorInterface != nullptr;
236         }
237 
238         /* Call getDppForLayer() only if hasDppForLayer() is true */
239         bool hasDppForLayer(ExynosMPPSource* layer);
240         const GsInterfaceType::IDpp& getDppForLayer(ExynosMPPSource* layer);
241         int32_t getDppIndexForLayer(ExynosMPPSource* layer);
242         /* Check if layer's assigned plane id has changed, save the new planeId.
243          * call only if hasDppForLayer is true */
checkAndSaveLayerPlaneId(ExynosMPPSource * layer,uint32_t planeId)244         bool checkAndSaveLayerPlaneId(ExynosMPPSource* layer, uint32_t planeId) {
245             auto &info = mDisplaySceneInfo.layerDataMappingInfo[layer];
246             bool change = info.planeId != planeId;
247             info.planeId = planeId;
248             return change;
249         }
250 
getNumOfDpp()251         size_t getNumOfDpp() {
252             const DisplayType display = getDisplayTypeFromIndex(mIndex);
253             GsInterfaceType* displayColorInterface = getDisplayColorInterface();
254             return displayColorInterface->GetPipelineData(display)->Dpp().size();
255         };
256 
getDqe()257         const GsInterfaceType::IDqe& getDqe()
258         {
259             const DisplayType display = getDisplayTypeFromIndex(mIndex);
260             GsInterfaceType* displayColorInterface = getDisplayColorInterface();
261             return displayColorInterface->GetPipelineData(display)->Dqe();
262         };
263 
264         // primary or secondary
getBuiltInDisplayType()265         DisplayType getBuiltInDisplayType() { return getDisplayTypeFromIndex(mIndex); }
266 
267         int32_t updateBrightnessTable();
268 
269     private:
270         int32_t setLayersColorData();
271         DisplaySceneInfo mDisplaySceneInfo;
272 
273         struct atc_lux_map {
274             uint32_t lux;
275             uint32_t al;
276             uint32_t st;
277         };
278 
279         struct atc_mode {
280             std::vector<atc_lux_map> lux_map;
281             std::unordered_map<std::string, int32_t> sub_setting;
282             uint32_t st_up_step;
283             uint32_t st_down_step;
284         };
285         struct atc_sysfs {
286             String8 node;
287             CtrlValue<int32_t> value;
288         };
289 
290         bool parseAtcProfile();
291         int32_t setAtcMode(std::string mode_name);
292         uint32_t getAtcLuxMapIndex(std::vector<atc_lux_map>, uint32_t lux);
293         int32_t setAtcAmbientLight(uint32_t ambient_light);
294         int32_t setAtcStrength(uint32_t strenght);
295         int32_t setAtcStDimming(uint32_t target);
296         int32_t setAtcEnable(bool enable);
297         void checkAtcAnimation();
isInAtcAnimation()298         bool isInAtcAnimation() {
299             if (mAtcStStepCount > 0)
300                 return true;
301             else
302                 return false;
303         };
304 
getDisplayColorInterface()305         GsInterfaceType* getDisplayColorInterface() {
306             ExynosDeviceModule* device = (ExynosDeviceModule*)mDevice;
307             return device->getDisplayColorInterface();
308         }
309 
isForceColorUpdate()310         bool isForceColorUpdate() const { return mForceColorUpdate; }
setForceColorUpdate(bool force)311         void setForceColorUpdate(bool force) { mForceColorUpdate = force; }
312         bool isDisplaySwitched(int32_t mode, int32_t prevMode);
313 
314         std::map<std::string, atc_mode> mAtcModeSetting;
315         bool mAtcInit;
316         LbeState mCurrentLbeState = LbeState::OFF;
317         std::string mCurrentAtcModeName;
318         uint32_t mCurrentLux = 0;
319         uint32_t mAtcLuxMapIndex = 0;
320         struct atc_sysfs mAtcAmbientLight;
321         struct atc_sysfs mAtcStrength;
322         struct atc_sysfs mAtcEnable;
323         std::unordered_map<std::string, struct atc_sysfs> mAtcSubSetting;
324         uint32_t mAtcStStepCount = 0;
325         uint32_t mAtcStTarget = 0;
326         uint32_t mAtcStUpStep;
327         uint32_t mAtcStDownStep;
328         Mutex mAtcStMutex;
329         bool mPendingAtcOff;
330         bool mForceColorUpdate = false;
331         bool mLbeSupported = false;
332 
333     protected:
334         virtual int32_t setPowerMode(int32_t mode) override;
335 };
336 
337 }  // namespace gs101
338 
339 #endif
340