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 
17 #include "ExynosPrimaryDisplayModule.h"
18 
19 #include <android-base/file.h>
20 #include <json/reader.h>
21 #include <json/value.h>
22 
23 #include <cmath>
24 
25 #include "ExynosDisplayDrmInterfaceModule.h"
26 #include "ExynosHWCDebug.h"
27 
28 #ifdef FORCE_GPU_COMPOSITION
29 extern exynos_hwc_control exynosHWCControl;
30 #endif
31 
getMPPTypeFromDPPChannel(uint32_t channel)32 mpp_phycal_type_t getMPPTypeFromDPPChannel(uint32_t channel) {
33 
34     for (int i=0; i < MAX_DECON_DMA_TYPE; i++){
35         if(IDMA_CHANNEL_MAP[i].channel == channel)
36             return IDMA_CHANNEL_MAP[i].type;
37     }
38 
39     return MPP_P_TYPE_MAX;
40 }
41 
42 using namespace gs101;
43 
44 // enable map layerDataMappingInfo comparison in needDisplayColorSetting()
operator ==(const ExynosPrimaryDisplayModule::DisplaySceneInfo::LayerMappingInfo & lm1,const ExynosPrimaryDisplayModule::DisplaySceneInfo::LayerMappingInfo & lm2)45 inline bool operator==(const ExynosPrimaryDisplayModule::DisplaySceneInfo::LayerMappingInfo &lm1,
46                        const ExynosPrimaryDisplayModule::DisplaySceneInfo::LayerMappingInfo &lm2) {
47     return lm1.dppIdx == lm2.dppIdx && lm1.planeId == lm2.planeId;
48 }
49 
ExynosPrimaryDisplayModule(uint32_t index,ExynosDevice * device)50 ExynosPrimaryDisplayModule::ExynosPrimaryDisplayModule(uint32_t index, ExynosDevice* device)
51       : ExynosPrimaryDisplay(index, device) {
52 #ifdef FORCE_GPU_COMPOSITION
53     exynosHWCControl.forceGpu = true;
54 #endif
55 }
56 
~ExynosPrimaryDisplayModule()57 ExynosPrimaryDisplayModule::~ExynosPrimaryDisplayModule () {
58 }
59 
usePreDefinedWindow(bool use)60 void ExynosPrimaryDisplayModule::usePreDefinedWindow(bool use)
61 {
62 #ifdef FIX_BASE_WINDOW_INDEX
63     /* Use fixed base window index */
64     mBaseWindowIndex = FIX_BASE_WINDOW_INDEX;
65     return;
66 #endif
67 
68     if (use) {
69         mBaseWindowIndex = PRIMARY_DISP_BASE_WIN[mDevice->mDisplayMode];
70         mMaxWindowNum = mDisplayInterface->getMaxWindowNum() - PRIMARY_DISP_BASE_WIN[mDevice->mDisplayMode];
71     } else {
72         mBaseWindowIndex = 0;
73         mMaxWindowNum = mDisplayInterface->getMaxWindowNum();
74     }
75 }
76 
validateWinConfigData()77 int32_t ExynosPrimaryDisplayModule::validateWinConfigData()
78 {
79     bool flagValidConfig = true;
80 
81     if (ExynosDisplay::validateWinConfigData() != NO_ERROR)
82         flagValidConfig = false;
83 
84     for (size_t i = 0; i < mDpuData.configs.size(); i++) {
85         struct exynos_win_config_data &config = mDpuData.configs[i];
86         if (config.state == config.WIN_STATE_BUFFER) {
87             bool configInvalid = false;
88             uint32_t mppType = config.assignedMPP->mPhysicalType;
89             if ((config.src.w != config.dst.w) ||
90                 (config.src.h != config.dst.h)) {
91                 if ((mppType == MPP_DPP_GF) ||
92                     (mppType == MPP_DPP_VG) ||
93                     (mppType == MPP_DPP_VGF)) {
94                     DISPLAY_LOGE("WIN_CONFIG error: invalid assign id : "
95                             "%zu,  s_w : %d, d_w : %d, s_h : %d, d_h : %d, mppType : %d",
96                             i, config.src.w, config.dst.w, config.src.h, config.dst.h, mppType);
97                     configInvalid = true;
98                 }
99             }
100             if (configInvalid) {
101                 config.state = config.WIN_STATE_DISABLED;
102                 flagValidConfig = false;
103             }
104         }
105     }
106     if (flagValidConfig)
107         return NO_ERROR;
108     else
109         return -EINVAL;
110 }
111 
doPreProcessing()112 void ExynosPrimaryDisplayModule::doPreProcessing() {
113     ExynosDisplay::doPreProcessing();
114 
115     if (mDevice->checkNonInternalConnection()) {
116         mDisplayControl.adjustDisplayFrame = true;
117     } else {
118         mDisplayControl.adjustDisplayFrame = false;
119     }
120 }
121 
getColorModes(uint32_t * outNumModes,int32_t * outModes)122 int32_t ExynosPrimaryDisplayModule::getColorModes(
123         uint32_t* outNumModes, int32_t* outModes)
124 {
125     IDisplayColorGS101* displayColorInterface = getDisplayColorInterface();
126     const DisplayType display = getDisplayTypeFromIndex(mIndex);
127     const ColorModesMap colorModeMap = displayColorInterface == nullptr
128             ? ColorModesMap()
129             : displayColorInterface->ColorModesAndRenderIntents(display);
130     ALOGD("%s: size(%zu)", __func__, colorModeMap.size());
131     if (outModes == nullptr) {
132         *outNumModes = colorModeMap.size();
133         return HWC2_ERROR_NONE;
134     }
135     if (*outNumModes != colorModeMap.size()) {
136         DISPLAY_LOGE("%s: Invalid color mode size(%d), It should be(%zu)",
137                 __func__, *outNumModes, colorModeMap.size());
138         return HWC2_ERROR_BAD_PARAMETER;
139     }
140 
141     uint32_t index = 0;
142     for (const auto &it : colorModeMap)
143     {
144         outModes[index] = static_cast<int32_t>(it.first);
145         ALOGD("\tmode[%d] %d", index, outModes[index]);
146         index++;
147     }
148 
149     return HWC2_ERROR_NONE;
150 }
151 
setColorMode(int32_t mode)152 int32_t ExynosPrimaryDisplayModule::setColorMode(int32_t mode)
153 {
154     ALOGD("%s: mode(%d)", __func__, mode);
155     IDisplayColorGS101* displayColorInterface = getDisplayColorInterface();
156     const DisplayType display = getDisplayTypeFromIndex(mIndex);
157     const ColorModesMap colorModeMap = displayColorInterface == nullptr
158             ? ColorModesMap()
159             : displayColorInterface->ColorModesAndRenderIntents(display);
160     hwc::ColorMode colorMode =
161         static_cast<hwc::ColorMode>(mode);
162     const auto it = colorModeMap.find(colorMode);
163     if (it == colorModeMap.end()) {
164         DISPLAY_LOGE("%s: Invalid color mode(%d)", __func__, mode);
165         return HWC2_ERROR_BAD_PARAMETER;
166     }
167     mDisplaySceneInfo.setColorMode(colorMode);
168 
169     if (mColorMode != mode)
170         setGeometryChanged(GEOMETRY_DISPLAY_COLOR_MODE_CHANGED);
171     mColorMode = (android_color_mode_t)mode;
172 
173     return HWC2_ERROR_NONE;
174 }
175 
getRenderIntents(int32_t mode,uint32_t * outNumIntents,int32_t * outIntents)176 int32_t ExynosPrimaryDisplayModule::getRenderIntents(int32_t mode,
177         uint32_t* outNumIntents, int32_t* outIntents)
178 {
179     IDisplayColorGS101* displayColorInterface = getDisplayColorInterface();
180     const DisplayType display = getDisplayTypeFromIndex(mIndex);
181     const ColorModesMap colorModeMap = displayColorInterface == nullptr
182             ? ColorModesMap()
183             : displayColorInterface->ColorModesAndRenderIntents(display);
184     ALOGD("%s, size(%zu)", __func__, colorModeMap.size());
185     hwc::ColorMode colorMode =
186         static_cast<hwc::ColorMode>(mode);
187     const auto it = colorModeMap.find(colorMode);
188     if (it == colorModeMap.end()) {
189         DISPLAY_LOGE("%s: Invalid color mode(%d)", __func__, mode);
190         return HWC2_ERROR_BAD_PARAMETER;
191     }
192     auto &renderIntents = it->second;
193     if (outIntents == NULL) {
194         *outNumIntents = renderIntents.size();
195         ALOGD("\tintent num(%zu)", renderIntents.size());
196         return HWC2_ERROR_NONE;
197     }
198     if (*outNumIntents != renderIntents.size()) {
199         DISPLAY_LOGE("%s: Invalid intent size(%d), It should be(%zu)",
200                 __func__, *outNumIntents, renderIntents.size());
201         return HWC2_ERROR_BAD_PARAMETER;
202     }
203 
204     for (uint32_t i = 0; i < renderIntents.size(); i++)
205     {
206         outIntents[i] = static_cast<uint32_t>(renderIntents[i]);
207         ALOGD("\tintent[%d] %d", i, outIntents[i]);
208     }
209 
210     return HWC2_ERROR_NONE;
211 }
212 
setColorModeWithRenderIntent(int32_t mode,int32_t intent)213 int32_t ExynosPrimaryDisplayModule::setColorModeWithRenderIntent(int32_t mode,
214         int32_t intent)
215 {
216     ALOGD("%s: mode(%d), intent(%d)", __func__, mode, intent);
217     IDisplayColorGS101* displayColorInterface = getDisplayColorInterface();
218     const DisplayType display = getDisplayTypeFromIndex(mIndex);
219     const ColorModesMap colorModeMap = displayColorInterface == nullptr
220             ? ColorModesMap()
221             : displayColorInterface->ColorModesAndRenderIntents(display);
222     hwc::ColorMode colorMode =
223         static_cast<hwc::ColorMode>(mode);
224     hwc::RenderIntent renderIntent =
225         static_cast<hwc::RenderIntent>(intent);
226 
227     const auto mode_it = colorModeMap.find(colorMode);
228     if (mode_it == colorModeMap.end()) {
229         DISPLAY_LOGE("%s: Invalid color mode(%d)", __func__, mode);
230         return HWC2_ERROR_BAD_PARAMETER;
231     }
232 
233     auto &renderIntents = mode_it->second;
234     auto intent_it = std::find(renderIntents.begin(),
235             renderIntents.end(), renderIntent);
236     if (intent_it == renderIntents.end()) {
237         DISPLAY_LOGE("%s: Invalid render intent(%d)", __func__, intent);
238         return HWC2_ERROR_BAD_PARAMETER;
239     }
240 
241     mDisplaySceneInfo.setColorMode(colorMode);
242     mDisplaySceneInfo.setRenderIntent(renderIntent);
243 
244     if (mColorMode != mode)
245         setGeometryChanged(GEOMETRY_DISPLAY_COLOR_MODE_CHANGED);
246     mColorMode = (android_color_mode_t)mode;
247 
248     return HWC2_ERROR_NONE;
249 }
250 
setColorTransform(const float * matrix,int32_t hint)251 int32_t ExynosPrimaryDisplayModule::setColorTransform(
252         const float* matrix, int32_t hint)
253 {
254     if ((hint < HAL_COLOR_TRANSFORM_IDENTITY) ||
255         (hint > HAL_COLOR_TRANSFORM_CORRECT_TRITANOPIA))
256         return HWC2_ERROR_BAD_PARAMETER;
257     ALOGI("%s:: %d, %d", __func__, mColorTransformHint, hint);
258     if (mColorTransformHint != hint)
259         setGeometryChanged(GEOMETRY_DISPLAY_COLOR_TRANSFORM_CHANGED);
260     mColorTransformHint = hint;
261 #ifdef HWC_SUPPORT_COLOR_TRANSFORM
262     mDisplaySceneInfo.setColorTransform(matrix);
263 #endif
264     return HWC2_ERROR_NONE;
265 
266 }
267 
setLayersColorData()268 int32_t ExynosPrimaryDisplayModule::setLayersColorData()
269 {
270     int32_t ret = 0;
271     uint32_t layerNum = 0;
272 
273     for (uint32_t i = 0; i < mLayers.size(); i++)
274     {
275         ExynosLayer* layer = mLayers[i];
276 
277         if (layer->mValidateCompositionType == HWC2_COMPOSITION_CLIENT)
278             continue;
279 
280         LayerColorData& layerColorData =
281             mDisplaySceneInfo.getLayerColorDataInstance(layerNum);
282 
283         /* set layer data mapping info */
284         if ((ret = mDisplaySceneInfo.setLayerDataMappingInfo(layer, layerNum))
285                 != NO_ERROR) {
286             DISPLAY_LOGE("%s: layer[%d] setLayerDataMappingInfo fail, layerNum(%d)",
287                     __func__, i, layerNum);
288             return ret;
289         }
290 
291         if ((ret = mDisplaySceneInfo.setLayerColorData(layerColorData, layer,
292                                                        getBrightnessState().dim_sdr_ratio))
293                 != NO_ERROR) {
294             DISPLAY_LOGE("%s: layer[%d] setLayerColorData fail, layerNum(%d)",
295                     __func__, i, layerNum);
296             return ret;
297         }
298 
299         layerNum++;
300     }
301 
302     if (mClientCompositionInfo.mHasCompositionLayer) {
303         LayerColorData& layerColorData =
304             mDisplaySceneInfo.getLayerColorDataInstance(layerNum);
305 
306         /* set layer data mapping info */
307         if ((ret = mDisplaySceneInfo.setLayerDataMappingInfo(&mClientCompositionInfo,
308                                                              layerNum)) != NO_ERROR) {
309             DISPLAY_LOGE("%s: setLayerDataMappingInfo fail for client composition", __func__);
310             return ret;
311         }
312 
313         if ((ret = mDisplaySceneInfo.setClientCompositionColorData(
314                  mClientCompositionInfo, layerColorData,
315                  getBrightnessState().dim_sdr_ratio)) != NO_ERROR) {
316           DISPLAY_LOGE("%s: setClientCompositionColorData fail", __func__);
317           return ret;
318         }
319 
320         layerNum++;
321     }
322 
323     /* Resize layer_data when layers were destroyed */
324     if (layerNum < mDisplaySceneInfo.displayScene.layer_data.size())
325         mDisplaySceneInfo.displayScene.layer_data.resize(layerNum);
326 
327     return NO_ERROR;
328 }
329 
hasDppForLayer(ExynosMPPSource * layer)330 bool ExynosPrimaryDisplayModule::hasDppForLayer(ExynosMPPSource* layer)
331 {
332     IDisplayColorGS101* displayColorInterface = getDisplayColorInterface();
333     if (displayColorInterface == nullptr) {
334         return false;
335     }
336 
337     if (mDisplaySceneInfo.layerDataMappingInfo.count(layer) == 0)
338         return false;
339 
340     uint32_t index =  mDisplaySceneInfo.layerDataMappingInfo[layer].dppIdx;
341     const DisplayType display = getDisplayTypeFromIndex(mIndex);
342     auto size = displayColorInterface->GetPipelineData(display)->Dpp().size();
343     if (index >= size) {
344         DISPLAY_LOGE("%s: invalid dpp index(%d) dpp size(%zu)", __func__, index, size);
345         return false;
346     }
347 
348     return true;
349 }
350 
getDppForLayer(ExynosMPPSource * layer)351 const IDisplayColorGS101::IDpp& ExynosPrimaryDisplayModule::getDppForLayer(ExynosMPPSource* layer)
352 {
353     uint32_t index = mDisplaySceneInfo.layerDataMappingInfo[layer].dppIdx;
354     IDisplayColorGS101* displayColorInterface = getDisplayColorInterface();
355     const DisplayType display = getDisplayTypeFromIndex(mIndex);
356     return displayColorInterface->GetPipelineData(display)->Dpp()[index].get();
357 }
358 
getDppIndexForLayer(ExynosMPPSource * layer)359 int32_t ExynosPrimaryDisplayModule::getDppIndexForLayer(ExynosMPPSource* layer)
360 {
361     if (mDisplaySceneInfo.layerDataMappingInfo.count(layer) == 0)
362         return -1;
363     uint32_t index = mDisplaySceneInfo.layerDataMappingInfo[layer].dppIdx;
364 
365     return static_cast<int32_t>(index);
366 }
367 
deliverWinConfigData()368 int ExynosPrimaryDisplayModule::deliverWinConfigData()
369 {
370     int ret = 0;
371     ExynosDisplayDrmInterfaceModule *moduleDisplayInterface =
372         (ExynosDisplayDrmInterfaceModule*)(mDisplayInterface.get());
373     IDisplayColorGS101* displayColorInterface = getDisplayColorInterface();
374 
375     bool forceDisplayColorSetting = false;
376     if (!mDisplaySceneInfo.displaySettingDelivered || isForceColorUpdate())
377         forceDisplayColorSetting = true;
378 
379     setForceColorUpdate(false);
380 
381     if (displayColorInterface != nullptr) {
382         moduleDisplayInterface->setColorSettingChanged(
383             mDisplaySceneInfo.needDisplayColorSetting(),
384             forceDisplayColorSetting);
385     }
386 
387     ret = ExynosDisplay::deliverWinConfigData();
388 
389     checkAtcAnimation();
390 
391     if (mDpuData.enable_readback &&
392        !mDpuData.readback_info.requested_from_service)
393         mDisplaySceneInfo.displaySettingDelivered = false;
394     else
395         mDisplaySceneInfo.displaySettingDelivered = true;
396 
397     return ret;
398 }
399 
getLayerColorDataInstance(uint32_t index)400 LayerColorData& ExynosPrimaryDisplayModule::DisplaySceneInfo::getLayerColorDataInstance(
401         uint32_t index)
402 {
403     size_t currentSize = displayScene.layer_data.size();
404     if (index >= currentSize) {
405         displayScene.layer_data.resize(currentSize+1);
406         colorSettingChanged = true;
407     }
408     return displayScene.layer_data[index];
409 }
410 
setLayerDataMappingInfo(ExynosMPPSource * layer,uint32_t index)411 int32_t ExynosPrimaryDisplayModule::DisplaySceneInfo::setLayerDataMappingInfo(
412         ExynosMPPSource* layer, uint32_t index)
413 {
414     if (layerDataMappingInfo.count(layer) != 0) {
415         ALOGE("layer mapping is already inserted (layer: %p, index:%d)",
416                 layer, index);
417         return -EINVAL;
418     }
419     // if assigned displaycolor dppIdx changes, do not reuse it (force plane color update).
420     uint32_t oldPlaneId = prev_layerDataMappingInfo.count(layer) != 0 &&
421                     prev_layerDataMappingInfo[layer].dppIdx != index
422             ? prev_layerDataMappingInfo[layer].planeId
423             : UINT_MAX;
424     layerDataMappingInfo.insert(std::make_pair(layer, LayerMappingInfo{ index, oldPlaneId }));
425 
426     return NO_ERROR;
427 }
428 
setLayerDataspace(LayerColorData & layerColorData,hwc::Dataspace dataspace)429 void ExynosPrimaryDisplayModule::DisplaySceneInfo::setLayerDataspace(
430         LayerColorData& layerColorData,
431         hwc::Dataspace dataspace)
432 {
433     if (layerColorData.dataspace != dataspace) {
434         colorSettingChanged = true;
435         layerColorData.dataspace = dataspace;
436     }
437 }
438 
disableLayerHdrStaticMetadata(LayerColorData & layerColorData)439 void ExynosPrimaryDisplayModule::DisplaySceneInfo::disableLayerHdrStaticMetadata(
440         LayerColorData& layerColorData)
441 {
442     if (layerColorData.static_metadata.is_valid) {
443         colorSettingChanged = true;
444         layerColorData.static_metadata.is_valid = false;
445     }
446 }
447 
setLayerHdrStaticMetadata(LayerColorData & layerColorData,const ExynosHdrStaticInfo & exynosHdrStaticInfo)448 void ExynosPrimaryDisplayModule::DisplaySceneInfo::setLayerHdrStaticMetadata(
449         LayerColorData& layerColorData,
450         const ExynosHdrStaticInfo &exynosHdrStaticInfo)
451 {
452     if (layerColorData.static_metadata.is_valid == false) {
453         colorSettingChanged = true;
454         layerColorData.static_metadata.is_valid = true;
455     }
456 
457     updateInfoSingleVal(layerColorData.static_metadata.display_red_primary_x,
458             exynosHdrStaticInfo.sType1.mR.x);
459     updateInfoSingleVal(layerColorData.static_metadata.display_red_primary_y,
460             exynosHdrStaticInfo.sType1.mR.y);
461     updateInfoSingleVal(layerColorData.static_metadata.display_green_primary_x,
462             exynosHdrStaticInfo.sType1.mG.x);
463     updateInfoSingleVal(layerColorData.static_metadata.display_green_primary_y,
464             exynosHdrStaticInfo.sType1.mG.y);
465     updateInfoSingleVal(layerColorData.static_metadata.display_blue_primary_x,
466             exynosHdrStaticInfo.sType1.mB.x);
467     updateInfoSingleVal(layerColorData.static_metadata.display_blue_primary_y,
468             exynosHdrStaticInfo.sType1.mB.y);
469     updateInfoSingleVal(layerColorData.static_metadata.white_point_x,
470             exynosHdrStaticInfo.sType1.mW.x);
471     updateInfoSingleVal(layerColorData.static_metadata.white_point_y,
472             exynosHdrStaticInfo.sType1.mW.y);
473     updateInfoSingleVal(layerColorData.static_metadata.max_luminance,
474             exynosHdrStaticInfo.sType1.mMaxDisplayLuminance);
475     updateInfoSingleVal(layerColorData.static_metadata.min_luminance,
476             exynosHdrStaticInfo.sType1.mMinDisplayLuminance);
477     updateInfoSingleVal(layerColorData.static_metadata.max_content_light_level,
478             exynosHdrStaticInfo.sType1.mMaxContentLightLevel);
479     updateInfoSingleVal(
480             layerColorData.static_metadata.max_frame_average_light_level,
481             exynosHdrStaticInfo.sType1.mMaxFrameAverageLightLevel);
482 }
483 
setLayerColorTransform(LayerColorData & layerColorData,std::array<float,TRANSFORM_MAT_SIZE> & matrix)484 void ExynosPrimaryDisplayModule::DisplaySceneInfo::setLayerColorTransform(
485         LayerColorData& layerColorData,
486         std::array<float, TRANSFORM_MAT_SIZE> &matrix)
487 {
488     updateInfoSingleVal(layerColorData.matrix, matrix);
489 }
490 
disableLayerHdrDynamicMetadata(LayerColorData & layerColorData)491 void ExynosPrimaryDisplayModule::DisplaySceneInfo::disableLayerHdrDynamicMetadata(
492         LayerColorData& layerColorData)
493 {
494     if (layerColorData.dynamic_metadata.is_valid) {
495         colorSettingChanged = true;
496         layerColorData.dynamic_metadata.is_valid = false;
497     }
498 }
499 
setLayerHdrDynamicMetadata(LayerColorData & layerColorData,const ExynosHdrDynamicInfo & exynosHdrDynamicInfo)500 void ExynosPrimaryDisplayModule::DisplaySceneInfo::setLayerHdrDynamicMetadata(
501         LayerColorData& layerColorData,
502         const ExynosHdrDynamicInfo &exynosHdrDynamicInfo)
503 {
504     if (layerColorData.dynamic_metadata.is_valid == false) {
505         colorSettingChanged = true;
506         layerColorData.dynamic_metadata.is_valid = true;
507     }
508     updateInfoSingleVal(layerColorData.dynamic_metadata.display_maximum_luminance,
509             exynosHdrDynamicInfo.data.display_maximum_luminance);
510 
511     if (!std::equal(layerColorData.dynamic_metadata.maxscl.begin(),
512                 layerColorData.dynamic_metadata.maxscl.end(),
513                 exynosHdrDynamicInfo.data.maxscl)) {
514         colorSettingChanged = true;
515         for (uint32_t i = 0 ; i < layerColorData.dynamic_metadata.maxscl.size(); i++) {
516             layerColorData.dynamic_metadata.maxscl[i] =
517                 exynosHdrDynamicInfo.data.maxscl[i];
518         }
519     }
520     static constexpr uint32_t DYNAMIC_META_DAT_SIZE = 15;
521 
522     updateInfoVectorVal(layerColorData.dynamic_metadata.maxrgb_percentages,
523             exynosHdrDynamicInfo.data.maxrgb_percentages,
524             DYNAMIC_META_DAT_SIZE);
525     updateInfoVectorVal(layerColorData.dynamic_metadata.maxrgb_percentiles,
526             exynosHdrDynamicInfo.data.maxrgb_percentiles,
527             DYNAMIC_META_DAT_SIZE);
528     updateInfoSingleVal(layerColorData.dynamic_metadata.tm_flag,
529             exynosHdrDynamicInfo.data.tone_mapping.tone_mapping_flag);
530     updateInfoSingleVal(layerColorData.dynamic_metadata.tm_knee_x,
531             exynosHdrDynamicInfo.data.tone_mapping.knee_point_x);
532     updateInfoSingleVal(layerColorData.dynamic_metadata.tm_knee_y,
533             exynosHdrDynamicInfo.data.tone_mapping.knee_point_y);
534     updateInfoVectorVal(layerColorData.dynamic_metadata.bezier_curve_anchors,
535             exynosHdrDynamicInfo.data.tone_mapping.bezier_curve_anchors,
536             DYNAMIC_META_DAT_SIZE);
537 }
538 
setClientCompositionColorData(const ExynosCompositionInfo & clientCompositionInfo,LayerColorData & layerData,float dimSdrRatio)539 int32_t ExynosPrimaryDisplayModule::DisplaySceneInfo::setClientCompositionColorData(
540         const ExynosCompositionInfo &clientCompositionInfo, LayerColorData& layerData,
541         float dimSdrRatio)
542 {
543     setLayerDataspace(layerData,
544                       static_cast<hwc::Dataspace>(clientCompositionInfo.mDataSpace));
545     disableLayerHdrStaticMetadata(layerData);
546     disableLayerHdrDynamicMetadata(layerData);
547 
548     if (dimSdrRatio != 1.0) {
549         std::array<float, TRANSFORM_MAT_SIZE> scaleMatrix = {
550             dimSdrRatio, 0.0, 0.0, 0.0,
551             0.0, dimSdrRatio, 0.0, 0.0,
552             0.0, 0.0, dimSdrRatio, 0.0,
553             0.0, 0.0, 0.0, 1.0
554         };
555         setLayerColorTransform(layerData, scaleMatrix);
556     }
557 
558     return NO_ERROR;
559 }
560 
setLayerColorData(LayerColorData & layerData,ExynosLayer * layer,float dimSdrRatio)561 int32_t ExynosPrimaryDisplayModule::DisplaySceneInfo::setLayerColorData(
562         LayerColorData& layerData, ExynosLayer* layer, float dimSdrRatio)
563 {
564     setLayerDataspace(layerData,
565             static_cast<hwc::Dataspace>(layer->mDataSpace));
566     if (layer->mIsHdrLayer) {
567         if (layer->getMetaParcel() == nullptr) {
568             HDEBUGLOGE("%s:: meta data parcel is null", __func__);
569             return -EINVAL;
570         }
571         if (layer->getMetaParcel()->eType & VIDEO_INFO_TYPE_HDR_STATIC)
572             setLayerHdrStaticMetadata(layerData, layer->getMetaParcel()->sHdrStaticInfo);
573         else
574             disableLayerHdrStaticMetadata(layerData);
575 
576         if (layer->getMetaParcel()->eType & VIDEO_INFO_TYPE_HDR_DYNAMIC)
577             setLayerHdrDynamicMetadata(layerData, layer->getMetaParcel()->sHdrDynamicInfo);
578         else
579             disableLayerHdrDynamicMetadata(layerData);
580     } else {
581         disableLayerHdrStaticMetadata(layerData);
582         disableLayerHdrDynamicMetadata(layerData);
583     }
584 
585     static std::array<float, TRANSFORM_MAT_SIZE> defaultMatrix {
586         1.0, 0.0, 0.0, 0.0,
587         0.0, 1.0, 0.0, 0.0,
588         0.0, 0.0, 1.0, 0.0,
589         0.0, 0.0, 0.0, 1.0
590     };
591 
592     if (dimSdrRatio == 1.0 || layer->mIsHdrLayer) {
593         if (layer->mLayerColorTransform.enable)
594             setLayerColorTransform(layerData,
595                     layer->mLayerColorTransform.mat);
596         else
597             setLayerColorTransform(layerData,
598                     defaultMatrix);
599     } else {
600         if (layer->mLayerColorTransform.enable) {
601             std::array<float, TRANSFORM_MAT_SIZE> scaleMatrix =
602                 layer->mLayerColorTransform.mat;
603 
604             // scale coeffs
605             scaleMatrix[0] *= dimSdrRatio;
606             scaleMatrix[1] *= dimSdrRatio;
607             scaleMatrix[2] *= dimSdrRatio;
608             scaleMatrix[4] *= dimSdrRatio;
609             scaleMatrix[5] *= dimSdrRatio;
610             scaleMatrix[6] *= dimSdrRatio;
611             scaleMatrix[8] *= dimSdrRatio;
612             scaleMatrix[9] *= dimSdrRatio;
613             scaleMatrix[10] *= dimSdrRatio;
614 
615             // scale offsets
616             scaleMatrix[12] *= dimSdrRatio;
617             scaleMatrix[13] *= dimSdrRatio;
618             scaleMatrix[14] *= dimSdrRatio;
619 
620             setLayerColorTransform(layerData, scaleMatrix);
621         } else {
622             std::array<float, TRANSFORM_MAT_SIZE> scaleMatrix = {
623                 dimSdrRatio, 0.0, 0.0, 0.0,
624                 0.0, dimSdrRatio, 0.0, 0.0,
625                 0.0, 0.0, dimSdrRatio, 0.0,
626                 0.0, 0.0, 0.0, 1.0
627             };
628 
629             setLayerColorTransform(layerData, scaleMatrix);
630         }
631     }
632 
633     return NO_ERROR;
634 }
635 
updateColorConversionInfo()636 int32_t ExynosPrimaryDisplayModule::updateColorConversionInfo()
637 {
638     int ret = 0;
639     IDisplayColorGS101* displayColorInterface = getDisplayColorInterface();
640     if (displayColorInterface == nullptr) {
641         return ret;
642     }
643 
644     /* clear flag and layer mapping info before setting */
645     mDisplaySceneInfo.reset();
646 
647     if ((ret = setLayersColorData()) != NO_ERROR)
648         return ret;
649 
650     ExynosDisplayDrmInterfaceModule *moduleDisplayInterface =
651         (ExynosDisplayDrmInterfaceModule*)(mDisplayInterface.get());
652     mDisplaySceneInfo.displayScene.bm = moduleDisplayInterface->isHbmOn()
653             ? displaycolor::BrightnessMode::BM_HBM
654             : displaycolor::BrightnessMode::BM_NOMINAL;
655 
656     mDisplaySceneInfo.displayScene.force_hdr = getBrightnessState().dim_sdr_ratio != 1.0;
657     mDisplaySceneInfo.displayScene.lhbm_on = getBrightnessState().local_hbm;
658     mDisplaySceneInfo.displayScene.hdr_full_screen = getBrightnessState().hdr_full_screen;
659     mDisplaySceneInfo.displayScene.dbv = moduleDisplayInterface->getDbv();
660 
661     if (hwcCheckDebugMessages(eDebugColorManagement))
662         mDisplaySceneInfo.printDisplayScene();
663 
664     const DisplayType display = getDisplayTypeFromIndex(mIndex);
665     if ((ret = displayColorInterface->Update(display, mDisplaySceneInfo.displayScene)) != 0) {
666         DISPLAY_LOGE("Display Scene update error (%d)", ret);
667         return ret;
668     }
669 
670     return ret;
671 }
672 
updatePresentColorConversionInfo()673 int32_t ExynosPrimaryDisplayModule::updatePresentColorConversionInfo()
674 {
675     int ret = NO_ERROR;
676     IDisplayColorGS101* displayColorInterface = getDisplayColorInterface();
677     if (displayColorInterface == nullptr) {
678         return ret;
679     }
680 
681     ExynosDisplayDrmInterfaceModule *moduleDisplayInterface =
682         (ExynosDisplayDrmInterfaceModule*)(mDisplayInterface.get());
683     auto refresh_rate = moduleDisplayInterface->getDesiredRefreshRate();
684     if (refresh_rate > 0) {
685         mDisplaySceneInfo.displayScene.refresh_rate = refresh_rate;
686     }
687 
688     const DisplayType display = getDisplayTypeFromIndex(mIndex);
689     if ((ret = displayColorInterface->UpdatePresent(display, mDisplaySceneInfo.displayScene)) !=
690         0) {
691         DISPLAY_LOGE("Display Scene update error (%d)", ret);
692         return ret;
693     }
694 
695     return ret;
696 }
697 
getColorAdjustedDbv(uint32_t & dbv_adj)698 int32_t ExynosPrimaryDisplayModule::getColorAdjustedDbv(uint32_t &dbv_adj) {
699     IDisplayColorGS101* displayColorInterface = getDisplayColorInterface();
700     if (displayColorInterface == nullptr) {
701         return NO_ERROR;
702     }
703 
704     const DisplayType display = getDisplayTypeFromIndex(mIndex);
705     dbv_adj = displayColorInterface->GetPipelineData(display)->Panel().GetAdjustedBrightnessLevel();
706     return NO_ERROR;
707 }
708 
needDisplayColorSetting()709 bool ExynosPrimaryDisplayModule::DisplaySceneInfo::needDisplayColorSetting()
710 {
711     /* TODO: Check if we can skip color setting */
712     /* For now, propage setting every frame */
713     return true;
714 
715     if (colorSettingChanged)
716         return true;
717     if (prev_layerDataMappingInfo != layerDataMappingInfo)
718         return true;
719 
720     return false;
721 }
722 
printDisplayScene()723 void ExynosPrimaryDisplayModule::DisplaySceneInfo::printDisplayScene()
724 {
725     ALOGD("======================= DisplayScene info ========================");
726     ALOGD("dpu_bit_depth: %d", static_cast<uint32_t>(displayScene.dpu_bit_depth));
727     ALOGD("color_mode: %d", static_cast<uint32_t>(displayScene.color_mode));
728     ALOGD("render_intent: %d", static_cast<uint32_t>(displayScene.render_intent));
729     ALOGD("matrix");
730     for (uint32_t i = 0; i < 16; (i += 4)) {
731         ALOGD("%f, %f, %f, %f",
732                 displayScene.matrix[i], displayScene.matrix[i+1],
733                 displayScene.matrix[i+2], displayScene.matrix[i+3]);
734     }
735     ALOGD("layer: %zu ++++++",
736             displayScene.layer_data.size());
737     for (uint32_t i = 0; i < displayScene.layer_data.size(); i++) {
738         ALOGD("layer[%d] info", i);
739         printLayerColorData(displayScene.layer_data[i]);
740     }
741 
742     ALOGD("layerDataMappingInfo: %zu ++++++",
743             layerDataMappingInfo.size());
744     for (auto layer : layerDataMappingInfo) {
745         ALOGD("[layer: %p] [%d, %d]", layer.first, layer.second.dppIdx, layer.second.planeId);
746     }
747 }
748 
printLayerColorData(const LayerColorData & layerData)749 void ExynosPrimaryDisplayModule::DisplaySceneInfo::printLayerColorData(
750     const LayerColorData& layerData)
751 {
752     ALOGD("dataspace: 0x%8x", static_cast<uint32_t>(layerData.dataspace));
753     ALOGD("matrix");
754     for (uint32_t i = 0; i < 16; (i += 4)) {
755         ALOGD("%f, %f, %f, %f",
756                 layerData.matrix[i], layerData.matrix[i+1],
757                 layerData.matrix[i+2], layerData.matrix[i+3]);
758     }
759     ALOGD("static_metadata.is_valid(%d)", layerData.static_metadata.is_valid);
760     if (layerData.static_metadata.is_valid) {
761         ALOGD("\tdisplay_red_primary(%d, %d)",
762                 layerData.static_metadata.display_red_primary_x,
763                 layerData.static_metadata.display_red_primary_y);
764         ALOGD("\tdisplay_green_primary(%d, %d)",
765                 layerData.static_metadata.display_green_primary_x,
766                 layerData.static_metadata.display_green_primary_y);
767         ALOGD("\tdisplay_blue_primary(%d, %d)",
768                 layerData.static_metadata.display_blue_primary_x,
769                 layerData.static_metadata.display_blue_primary_y);
770         ALOGD("\twhite_point(%d, %d)",
771                 layerData.static_metadata.white_point_x,
772                 layerData.static_metadata.white_point_y);
773     }
774     ALOGD("dynamic_metadata.is_valid(%d)", layerData.dynamic_metadata.is_valid);
775     if (layerData.dynamic_metadata.is_valid) {
776         ALOGD("\tdisplay_maximum_luminance: %d",
777                 layerData.dynamic_metadata.display_maximum_luminance);
778         ALOGD("\tmaxscl(%d, %d, %d)", layerData.dynamic_metadata.maxscl[0],
779                 layerData.dynamic_metadata.maxscl[1],
780                 layerData.dynamic_metadata.maxscl[2]);
781         ALOGD("\ttm_flag(%d)", layerData.dynamic_metadata.tm_flag);
782         ALOGD("\ttm_knee_x(%d)", layerData.dynamic_metadata.tm_knee_x);
783         ALOGD("\ttm_knee_y(%d)", layerData.dynamic_metadata.tm_knee_y);
784     }
785 }
786 
parseAtcProfile()787 bool ExynosPrimaryDisplayModule::parseAtcProfile() {
788     Json::Value root;
789     Json::CharReaderBuilder reader_builder;
790     std::unique_ptr<Json::CharReader> reader(reader_builder.newCharReader());
791     std::string atc_profile;
792 
793     if (!android::base::ReadFileToString(kAtcProfilePath, &atc_profile)) {
794         atc_profile = kAtcJsonRaw;
795         ALOGI("Use default atc profile file");
796     }
797 
798     if (!reader->parse(atc_profile.c_str(), atc_profile.c_str() + atc_profile.size(), &root,
799                        nullptr)) {
800         ALOGE("Failed to parse atc profile file");
801         return false;
802     }
803 
804     ALOGI("Atc Profile version = %s", root[kAtcProfileVersionStr].asString().c_str());
805     Json::Value nodes = root[kAtcProfileModesStr];
806     atc_mode mode;
807 
808     for (Json::Value::ArrayIndex i = 0; i < nodes.size(); ++i) {
809         std::string name = nodes[i][kAtcProfileModeNameStr].asString();
810 
811         if (nodes[i][kAtcProfileLuxMapStr].size() != nodes[i][kAtcProfileAlMapStr].size() &&
812             nodes[i][kAtcProfileAlMapStr].size() != nodes[i][kAtcProfileStMapStr].size()) {
813             ALOGE("Atc profile is unavailable !");
814             return false;
815         }
816 
817         uint32_t map_cnt = nodes[i][kAtcProfileLuxMapStr].size();
818 
819         mode.lux_map.clear();
820         for (uint32_t index = 0; index < map_cnt; ++index) {
821             mode.lux_map.emplace_back(atc_lux_map{nodes[i][kAtcProfileLuxMapStr][index].asUInt(),
822                                                   nodes[i][kAtcProfileAlMapStr][index].asUInt(),
823                                                   nodes[i][kAtcProfileStMapStr][index].asUInt()});
824         }
825 
826         if (!nodes[i][kAtcProfileStUpStepStr].empty())
827             mode.st_up_step = nodes[i][kAtcProfileStUpStepStr].asUInt();
828         else
829             mode.st_up_step = kAtcStStep;
830 
831         if (!nodes[i][kAtcProfileStDownStepStr].empty())
832             mode.st_down_step = nodes[i][kAtcProfileStDownStepStr].asUInt();
833         else
834             mode.st_down_step = kAtcStStep;
835 
836         if (nodes[i][kAtcProfileSubSettingStr].size() != kAtcSubSetting.size()) return false;
837 
838         for (auto it = kAtcSubSetting.begin(); it != kAtcSubSetting.end(); it++) {
839             mode.sub_setting[it->first.c_str()] =
840                     nodes[i][kAtcProfileSubSettingStr][it->first.c_str()].asUInt();
841         }
842         auto ret = mAtcModeSetting.insert(std::make_pair(name.c_str(), mode));
843         if (ret.second == false) {
844             ALOGE("Atc mode %s is already existed!", ret.first->first.c_str());
845             return false;
846         }
847     }
848 
849     if (mAtcModeSetting.find(kAtcModeNormalStr) == mAtcModeSetting.end()) {
850         ALOGW("Failed to find atc normal mode");
851         return false;
852     }
853     return true;
854 }
855 
initLbe()856 void ExynosPrimaryDisplayModule::initLbe() {
857     if (!parseAtcProfile()) {
858         ALOGD("Failed to parseAtcMode");
859         mAtcInit = false;
860         return;
861     }
862 
863     mAtcInit = true;
864     mAtcAmbientLight.set_dirty();
865     mAtcStrength.set_dirty();
866     for (auto it = kAtcSubSetting.begin(); it != kAtcSubSetting.end(); it++)
867         mAtcSubSetting[it->first.c_str()].set_dirty();
868 }
869 
getAtcLuxMapIndex(std::vector<atc_lux_map> map,uint32_t lux)870 uint32_t ExynosPrimaryDisplayModule::getAtcLuxMapIndex(std::vector<atc_lux_map> map, uint32_t lux) {
871     uint32_t index = 0;
872     for (uint32_t i = 0; i < map.size(); i++) {
873         if (lux < map[i].lux) {
874             break;
875         }
876         index = i;
877     }
878 
879     return index;
880 }
881 
setAtcStrength(uint32_t strength)882 int32_t ExynosPrimaryDisplayModule::setAtcStrength(uint32_t strength) {
883     mAtcStrength.store(strength);
884     if (mAtcStrength.is_dirty()) {
885         if (writeIntToFile(ATC_ST_FILE_NAME, mAtcStrength.get()) != NO_ERROR) return -EPERM;
886         mAtcStrength.clear_dirty();
887     }
888     return NO_ERROR;
889 }
890 
setAtcAmbientLight(uint32_t ambient_light)891 int32_t ExynosPrimaryDisplayModule::setAtcAmbientLight(uint32_t ambient_light) {
892     mAtcAmbientLight.store(ambient_light);
893     if (mAtcAmbientLight.is_dirty()) {
894         if (writeIntToFile(ATC_AMBIENT_LIGHT_FILE_NAME, mAtcAmbientLight.get()) != NO_ERROR)
895             return -EPERM;
896         mAtcAmbientLight.clear_dirty();
897     }
898 
899     return NO_ERROR;
900 }
901 
setAtcMode(std::string mode_name)902 int32_t ExynosPrimaryDisplayModule::setAtcMode(std::string mode_name) {
903     auto mode_data = mAtcModeSetting.find(mode_name);
904     uint32_t ambient_light = 0;
905     uint32_t strength = 0;
906     bool enable = (!mode_name.empty()) && (mode_data != mAtcModeSetting.end());
907 
908     if (enable) {
909         atc_mode mode = mode_data->second;
910         for (auto it = kAtcSubSetting.begin(); it != kAtcSubSetting.end(); it++) {
911             mAtcSubSetting[it->first.c_str()].store(mode.sub_setting[it->first.c_str()]);
912             if (mAtcSubSetting[it->first.c_str()].is_dirty()) {
913                 if (writeIntToFile(it->second.c_str(), mAtcSubSetting[it->first.c_str()].get()) !=
914                     NO_ERROR)
915                     return -EPERM;
916                 mAtcSubSetting[it->first.c_str()].clear_dirty();
917             }
918         }
919         mAtcStUpStep = mode.st_up_step;
920         mAtcStDownStep = mode.st_down_step;
921 
922         uint32_t index = getAtcLuxMapIndex(mode.lux_map, mCurrentLux);
923         ambient_light = mode.lux_map[index].al;
924         strength = mode.lux_map[index].st;
925     }
926 
927     if (setAtcAmbientLight(ambient_light) != NO_ERROR) {
928         ALOGE("Fail to set atc ambient light for %s mode", mode_name.c_str());
929         return -EPERM;
930     }
931 
932     if (setAtcStDimming(strength) != NO_ERROR) {
933         ALOGE("Fail to set atc st dimming for %s mode", mode_name.c_str());
934         return -EPERM;
935     }
936 
937     if (!enable && isInAtcAnimation()) {
938         mPendingAtcOff = true;
939     } else {
940         if (setAtcEnable(enable) != NO_ERROR) {
941             ALOGE("Fail to set atc enable = %d", enable);
942             return -EPERM;
943         }
944     }
945 
946     mCurrentAtcModeName = enable ? mode_name : "NULL";
947     ALOGI("atc enable=%d (mode=%s, pending off=%s)", enable, mCurrentAtcModeName.c_str(),
948           mPendingAtcOff ? "true" : "false");
949     return NO_ERROR;
950 }
setLbeState(LbeState state)951 void ExynosPrimaryDisplayModule::setLbeState(LbeState state) {
952     if (!mAtcInit) return;
953     std::string modeStr;
954     bool enhanced_hbm = false;
955     switch (state) {
956         case LbeState::OFF:
957             mCurrentLux = 0;
958             break;
959         case LbeState::NORMAL:
960             modeStr = kAtcModeNormalStr;
961             break;
962         case LbeState::HIGH_BRIGHTNESS:
963             modeStr = kAtcModeHbmStr;
964             enhanced_hbm = true;
965             break;
966         case LbeState::POWER_SAVE:
967             modeStr = kAtcModePowerSaveStr;
968             break;
969         default:
970             ALOGE("Lbe state not support");
971             return;
972     }
973 
974     if (setAtcMode(modeStr) != NO_ERROR) return;
975 
976     requestEnhancedHbm(enhanced_hbm);
977     mDisplayInterface->updateBrightness(false);
978 
979     if (mCurrentLbeState != state) {
980         mCurrentLbeState = state;
981         mDevice->invalidate();
982     }
983     ALOGI("Lbe state %hhd", mCurrentLbeState);
984 }
985 
setLbeAmbientLight(int value)986 void ExynosPrimaryDisplayModule::setLbeAmbientLight(int value) {
987     if (!mAtcInit) return;
988 
989     auto it = mAtcModeSetting.find(mCurrentAtcModeName);
990     if (it == mAtcModeSetting.end()) {
991         ALOGE("Atc mode not found");
992         return;
993     }
994     atc_mode mode = it->second;
995 
996     uint32_t index = getAtcLuxMapIndex(mode.lux_map, value);
997     if (setAtcAmbientLight(mode.lux_map[index].al) != NO_ERROR) {
998         ALOGE("Failed to set atc ambient light");
999         return;
1000     }
1001 
1002     if (setAtcStDimming(mode.lux_map[index].st) != NO_ERROR) {
1003         ALOGE("Failed to set atc st dimming");
1004         return;
1005     }
1006 
1007     if (mAtcLuxMapIndex != index) {
1008         mAtcLuxMapIndex = index;
1009         mDevice->invalidate();
1010     }
1011     mCurrentLux = value;
1012 }
1013 
getLbeState()1014 LbeState ExynosPrimaryDisplayModule::getLbeState() {
1015     return mCurrentLbeState;
1016 }
1017 
setAtcStDimming(uint32_t value)1018 int32_t ExynosPrimaryDisplayModule::setAtcStDimming(uint32_t value) {
1019     Mutex::Autolock lock(mAtcStMutex);
1020     int32_t strength = mAtcStrength.get();
1021     if (mAtcStTarget != value) {
1022         mAtcStTarget = value;
1023         uint32_t step = mAtcStTarget > strength ? mAtcStUpStep : mAtcStDownStep;
1024 
1025         int diff = value - strength;
1026         uint32_t count = (std::abs(diff) + step - 1) / step;
1027         mAtcStStepCount = count;
1028         ALOGI("setup atc st dimming=%d, count=%d, step=%d", value, count, step);
1029     }
1030 
1031     if (mAtcStStepCount == 0 && !mAtcStrength.is_dirty()) return NO_ERROR;
1032 
1033     if ((strength + mAtcStUpStep) < mAtcStTarget) {
1034         strength = strength + mAtcStUpStep;
1035     } else if (strength > (mAtcStTarget + mAtcStDownStep)) {
1036         strength = strength - mAtcStDownStep;
1037     } else {
1038         strength = mAtcStTarget;
1039     }
1040 
1041     if (setAtcStrength(strength) != NO_ERROR) {
1042         ALOGE("Failed to set atc st");
1043         return -EPERM;
1044     }
1045 
1046     if (mAtcStStepCount > 0) mAtcStStepCount--;
1047     return NO_ERROR;
1048 }
1049 
setAtcEnable(bool enable)1050 int32_t ExynosPrimaryDisplayModule::setAtcEnable(bool enable) {
1051     mAtcEnable.store(enable);
1052     if (mAtcEnable.is_dirty()) {
1053         if (writeIntToFile(ATC_ENABLE_FILE_NAME, enable) != NO_ERROR) return -EPERM;
1054         mAtcEnable.clear_dirty();
1055     }
1056     return NO_ERROR;
1057 }
1058 
checkAtcAnimation()1059 void ExynosPrimaryDisplayModule::checkAtcAnimation() {
1060     if (!isInAtcAnimation()) return;
1061 
1062     if (setAtcStDimming(mAtcStTarget) != NO_ERROR) {
1063         ALOGE("Failed to set atc st dimming");
1064         return;
1065     }
1066 
1067     if (mPendingAtcOff && mAtcStStepCount == 0) {
1068         if (setAtcEnable(false) != NO_ERROR) {
1069             ALOGE("Failed to set atc enable to off");
1070             return;
1071         }
1072         mPendingAtcOff = false;
1073         ALOGI("atc enable is off (pending off=false)");
1074     }
1075 
1076     mDevice->invalidate();
1077 }
1078 
setPowerMode(int32_t mode)1079 int32_t ExynosPrimaryDisplayModule::setPowerMode(int32_t mode) {
1080     hwc2_power_mode_t prevPowerModeState = mPowerModeState;
1081     int32_t ret;
1082 
1083     ret = ExynosPrimaryDisplay::setPowerMode(mode);
1084 
1085     if ((ret == HWC2_ERROR_NONE) && isDisplaySwitched(mode, prevPowerModeState)) {
1086         ExynosDeviceModule* device = static_cast<ExynosDeviceModule*>(mDevice);
1087 
1088         device->setActiveDisplay(mIndex);
1089         setForceColorUpdate(true);
1090     }
1091     return ret;
1092 }
1093 
isDisplaySwitched(int32_t mode,int32_t prevMode)1094 bool ExynosPrimaryDisplayModule::isDisplaySwitched(int32_t mode, int32_t prevMode) {
1095     ExynosDeviceModule* device = static_cast<ExynosDeviceModule*>(mDevice);
1096 
1097     return (device->getActiveDisplay() != mIndex) && (prevMode == HWC_POWER_MODE_OFF) &&
1098             (mode != HWC_POWER_MODE_OFF);
1099 }
1100 
isColorCalibratedByDevice()1101 bool ExynosPrimaryDisplayModule::isColorCalibratedByDevice() {
1102     const DisplayType display = getDisplayTypeFromIndex(mIndex);
1103     IDisplayColorGS101* displayColorInterface = getDisplayColorInterface();
1104     return displayColorInterface->GetCalibrationInfo(display).factory_cal_loaded;
1105 };
1106