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