1 /* 2 * Copyright (C) 2022 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 #ifndef EXYNOS_DISPLAY_DRM_INTERFACE_MODULE_H 18 #define EXYNOS_DISPLAY_DRM_INTERFACE_MODULE_H 19 20 #include <histogram/histogram.h> 21 #include "DisplayColorModule.h" 22 #include "ExynosDisplayDrmInterface.h" 23 24 namespace gs101 { 25 26 using namespace displaycolor; 27 28 class ExynosDisplayDrmInterfaceModule : public ExynosDisplayDrmInterface { 29 using GsInterfaceType = gs::ColorDrmBlobFactory::GsInterfaceType; 30 public: 31 ExynosDisplayDrmInterfaceModule(ExynosDisplay *exynosDisplay); 32 virtual ~ExynosDisplayDrmInterfaceModule(); 33 virtual int32_t initDrmDevice(DrmDevice *drmDevice); 34 35 virtual int32_t setDisplayColorSetting( 36 ExynosDisplayDrmInterface::DrmModeAtomicReq &drmReq); 37 virtual int32_t setPlaneColorSetting( 38 ExynosDisplayDrmInterface::DrmModeAtomicReq &drmReq, 39 const std::unique_ptr<DrmPlane> &plane, 40 const exynos_win_config_data &config, 41 uint32_t &solidColor); 42 void setColorSettingChanged(bool changed, bool forceDisplay = false) { 43 mColorSettingChanged = changed; 44 mForceDisplayColorSetting = forceDisplay; 45 }; 46 void destroyOldBlobs(std::vector<uint32_t> &oldBlobs); 47 void getDisplayInfo(std::vector<displaycolor::DisplayInfo> &display_info); 48 49 /* For Histogram */ 50 int32_t createHistoRoiBlob(uint32_t &blobId); 51 int32_t createHistoWeightsBlob(uint32_t &blobId); 52 53 virtual int32_t setDisplayHistogramSetting( 54 ExynosDisplayDrmInterface::DrmModeAtomicReq &drmReq); 55 registerHistogramInfo(const std::shared_ptr<IDLHistogram> & info)56 virtual void registerHistogramInfo(const std::shared_ptr<IDLHistogram> &info) { 57 mHistogramInfo = info; 58 } isHistogramInfoRegistered()59 bool isHistogramInfoRegistered() { return mHistogramInfo != nullptr; } 60 int32_t setHistogramControl(hidl_histogram_control_t enabled); 61 virtual int32_t setHistogramData(void *bin); 62 clearOldCrtcBlobs()63 void clearOldCrtcBlobs() override { mOldDqeBlobs.clearBlobs(); } 64 65 protected: 66 class SaveBlob { 67 public: 68 ~SaveBlob(); init(DrmDevice * drmDevice,uint32_t size)69 void init(DrmDevice *drmDevice, uint32_t size) { 70 mDrmDevice = drmDevice; 71 blobs.resize(size, 0); 72 }; 73 void addBlob(uint32_t type, uint32_t blob); 74 uint32_t getBlob(uint32_t type); 75 void clearBlobs(); 76 77 private: 78 DrmDevice *mDrmDevice = NULL; 79 std::vector<uint32_t> blobs; 80 }; 81 class DqeBlobs:public SaveBlob { 82 public: 83 enum Dqe_Blob_Type{ 84 CGC, 85 DEGAMMA_LUT, 86 REGAMMA_LUT, 87 GAMMA_MAT, 88 LINEAR_MAT, 89 DISP_DITHER, 90 CGC_DITHER, 91 DQE_BLOB_NUM // number of DQE blobs 92 }; init(DrmDevice * drmDevice)93 void init(DrmDevice *drmDevice) { 94 SaveBlob::init(drmDevice, DQE_BLOB_NUM); 95 }; 96 }; 97 class DppBlobs:public SaveBlob { 98 public: 99 enum Dpp_Blob_Type{ 100 EOTF, 101 GM, 102 DTM, 103 OETF, 104 DPP_BLOB_NUM // number of DPP blobs 105 }; DppBlobs(DrmDevice * drmDevice,uint32_t pid)106 DppBlobs(DrmDevice *drmDevice, uint32_t pid) : planeId(pid) { 107 SaveBlob::init(drmDevice, DPP_BLOB_NUM); 108 }; 109 uint32_t planeId; 110 }; 111 template<typename StageDataType> 112 int32_t setDisplayColorBlob( 113 const DrmProperty &prop, 114 const uint32_t type, 115 const StageDataType &stage, 116 const typename GsInterfaceType::IDqe &dqe, 117 ExynosDisplayDrmInterface::DrmModeAtomicReq &drmReq); 118 template<typename StageDataType> 119 int32_t setPlaneColorBlob( 120 const std::unique_ptr<DrmPlane> &plane, 121 const DrmProperty &prop, 122 const uint32_t type, 123 const StageDataType &stage, 124 const typename GsInterfaceType::IDpp &dpp, 125 const uint32_t dppIndex, 126 ExynosDisplayDrmInterface::DrmModeAtomicReq &drmReq, 127 bool forceUpdate); 128 void parseBpcEnums(const DrmProperty& property); 129 DqeBlobs mOldDqeBlobs; 130 std::vector<DppBlobs> mOldDppBlobs; initOldDppBlobs(DrmDevice * drmDevice)131 void initOldDppBlobs(DrmDevice *drmDevice) { 132 auto const &planes = drmDevice->planes(); 133 for (uint32_t ix = 0; ix < planes.size(); ++ix) 134 mOldDppBlobs.emplace_back(mDrmDevice, planes[ix]->id()); 135 }; 136 bool mColorSettingChanged = false; 137 bool mForceDisplayColorSetting = false; 138 enum Bpc_Type { 139 BPC_UNSPECIFIED = 0, 140 BPC_8, 141 BPC_10, 142 }; 143 DrmEnumParser::MapHal2DrmEnum mBpcEnums; 144 145 /* For Histogram */ 146 class HistoBlobs : public SaveBlob { 147 public: 148 enum Histo_Blob_Type { 149 ROI, 150 WEIGHTS, 151 HISTO_BLOB_NUM // number of Histogram blobs 152 }; init(DrmDevice * drmDevice)153 void init(DrmDevice *drmDevice) { SaveBlob::init(drmDevice, HISTO_BLOB_NUM); } 154 }; 155 int32_t setDisplayHistoBlob(const DrmProperty &prop, const uint32_t type, 156 ExynosDisplayDrmInterface::DrmModeAtomicReq &drmReq); 157 HistoBlobs mOldHistoBlobs; 158 159 std::shared_ptr<IDLHistogram> mHistogramInfo; 160 161 private: 162 const std::string GetPanelInfo(const std::string &sysfs_rel, char delim); GetPanelSerial()163 const std::string GetPanelSerial() { return GetPanelInfo("serial_number", '\n'); } GetPanelName()164 const std::string GetPanelName() { return GetPanelInfo("panel_name", '\n'); } 165 }; 166 167 class ExynosPrimaryDisplayDrmInterfaceModule : public ExynosDisplayDrmInterfaceModule { 168 public: 169 ExynosPrimaryDisplayDrmInterfaceModule(ExynosDisplay *exynosDisplay); 170 virtual ~ExynosPrimaryDisplayDrmInterfaceModule(); 171 }; 172 173 class ExynosExternalDisplayDrmInterfaceModule : public ExynosDisplayDrmInterfaceModule { 174 public: 175 ExynosExternalDisplayDrmInterfaceModule(ExynosDisplay *exynosDisplay); 176 virtual ~ExynosExternalDisplayDrmInterfaceModule(); 177 }; 178 179 } // namespace gs101 180 181 #endif 182