1 /* 2 * Copyright (C) 2023 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 __DISPLAY_SCENE_INFO_H__ 17 #define __DISPLAY_SCENE_INFO_H__ 18 19 #include <displaycolor/displaycolor.h> 20 #include "ExynosHWCHelper.h" 21 #include "VendorVideoAPI.h" 22 23 using namespace displaycolor; 24 25 class ExynosCompositionInfo; 26 class ExynosLayer; 27 class ExynosMPPSource; 28 29 class DisplaySceneInfo { 30 public: 31 struct LayerMappingInfo { 32 bool operator==(const LayerMappingInfo& rhs) const { 33 return ((dppIdx == rhs.dppIdx) && (planeId == rhs.planeId)); 34 } 35 36 // index in DisplayScene::layer_data 37 uint32_t dppIdx; 38 // assigned drm plane id in last color setting update 39 uint32_t planeId; 40 static constexpr uint32_t kPlaneIdNone = std::numeric_limits<uint32_t>::max(); 41 }; 42 bool colorSettingChanged = false; 43 bool displaySettingDelivered = false; 44 DisplayScene displayScene; 45 46 /* 47 * Index of LayerColorData in DisplayScene::layer_data 48 * and assigned plane id in last color setting update. 49 * for each layer, including client composition 50 * key: ExynosMPPSource* 51 * data: LayerMappingInfo 52 */ 53 std::map<ExynosMPPSource*, LayerMappingInfo> layerDataMappingInfo; 54 std::map<ExynosMPPSource*, LayerMappingInfo> prev_layerDataMappingInfo; 55 reset()56 void reset() { 57 colorSettingChanged = false; 58 prev_layerDataMappingInfo = layerDataMappingInfo; 59 layerDataMappingInfo.clear(); 60 }; 61 clear()62 void clear() { 63 colorSettingChanged = false; 64 layerDataMappingInfo.clear(); 65 prev_layerDataMappingInfo.clear(); 66 } 67 68 template <typename T, typename M> updateInfoSingleVal(T & dst,M & src)69 void updateInfoSingleVal(T& dst, M& src) { 70 if (src != dst) { 71 colorSettingChanged = true; 72 dst = src; 73 } 74 }; 75 76 template <typename T, typename M> updateInfoVectorVal(std::vector<T> & dst,M * src,uint32_t size)77 void updateInfoVectorVal(std::vector<T>& dst, M* src, uint32_t size) { 78 if ((dst.size() != size) || !std::equal(dst.begin(), dst.end(), src)) { 79 colorSettingChanged = true; 80 dst.resize(size); 81 for (uint32_t i = 0; i < size; i++) { 82 dst[i] = src[i]; 83 } 84 } 85 }; 86 setColorMode(hwc::ColorMode mode)87 void setColorMode(hwc::ColorMode mode) { updateInfoSingleVal(displayScene.color_mode, mode); }; 88 setRenderIntent(hwc::RenderIntent intent)89 void setRenderIntent(hwc::RenderIntent intent) { 90 updateInfoSingleVal(displayScene.render_intent, intent); 91 }; 92 setColorTransform(const float * matrix)93 void setColorTransform(const float* matrix) { 94 for (uint32_t i = 0; i < displayScene.matrix.size(); i++) { 95 if (displayScene.matrix[i] != matrix[i]) { 96 colorSettingChanged = true; 97 displayScene.matrix[i] = matrix[i]; 98 } 99 } 100 } 101 102 LayerColorData& getLayerColorDataInstance(uint32_t index); 103 int32_t setLayerDataMappingInfo(ExynosMPPSource* layer, uint32_t index); 104 void setLayerDataspace(LayerColorData& layerColorData, hwc::Dataspace dataspace); 105 void disableLayerHdrStaticMetadata(LayerColorData& layerColorData); 106 void setLayerHdrStaticMetadata(LayerColorData& layerColorData, 107 const ExynosHdrStaticInfo& exynosHdrStaticInfo); 108 void setLayerColorTransform(LayerColorData& layerColorData, 109 std::array<float, TRANSFORM_MAT_SIZE>& matrix); 110 void disableLayerHdrDynamicMetadata(LayerColorData& layerColorData); 111 void setLayerHdrDynamicMetadata(LayerColorData& layerColorData, 112 const ExynosHdrDynamicInfo& exynosHdrDynamicInfo); 113 int32_t setLayerColorData(LayerColorData& layerData, ExynosLayer* layer, float dimSdrRatio); 114 int32_t setClientCompositionColorData(const ExynosCompositionInfo& clientCompositionInfo, 115 LayerColorData& layerData, float dimSdrRatio); 116 bool needDisplayColorSetting(); 117 void printDisplayScene(); 118 void printLayerColorData(const LayerColorData& layerData); 119 }; 120 121 #endif // __DISPLAY_SCENE_INFO_H__ 122