1 /* Copyright (c) 2015-2019, The Linux Foundataion. All rights reserved. 2 * 3 * Redistribution and use in source and binary forms, with or without 4 * modification, are permitted provided that the following conditions are 5 * met: 6 * * Redistributions of source code must retain the above copyright 7 * notice, this list of conditions and the following disclaimer. 8 * * Redistributions in binary form must reproduce the above 9 * copyright notice, this list of conditions and the following 10 * disclaimer in the documentation and/or other materials provided 11 * with the distribution. 12 * * Neither the name of The Linux Foundation nor the names of its 13 * contributors may be used to endorse or promote products derived 14 * from this software without specific prior written permission. 15 * 16 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED 17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT 19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS 20 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 23 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 24 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 25 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN 26 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 * 28 */ 29 30 #ifndef __COLOR_MANAGER_H__ 31 #define __COLOR_MANAGER_H__ 32 33 #include <stdlib.h> 34 #include <core/sdm_types.h> 35 #include <utils/locker.h> 36 #include <private/color_interface.h> 37 #include <private/snapdragon_color_intf.h> 38 #include <utils/sys.h> 39 #include <utils/debug.h> 40 #include <array> 41 #include <vector> 42 #include <map> 43 #include <string> 44 #include <mutex> 45 46 #include "hw_interface.h" 47 48 namespace sdm { 49 50 using std::mutex; 51 using std::lock_guard; 52 using snapdragoncolor::HwConfigOutputParams; 53 using snapdragoncolor::HwConfigPayload; 54 using snapdragoncolor::ScPayload; 55 using snapdragoncolor::ScOps; 56 using snapdragoncolor::ScPostBlendInterface; 57 using snapdragoncolor::kScModeRenderIntent; 58 using snapdragoncolor::PostBlendInverseGammaHwConfig; 59 using snapdragoncolor::PostBlendGammaHwConfig; 60 using snapdragoncolor::PostBlendGamutHwConfig; 61 using snapdragoncolor::kPostBlendInverseGammaHwConfig; 62 using snapdragoncolor::kPostBlendGammaHwConfig; 63 using snapdragoncolor::kPostBlendGamutHwConfig; 64 using snapdragoncolor::kHwConfigPayloadParam; 65 using snapdragoncolor::GamutConfig; 66 using snapdragoncolor::GammaPostBlendConfig; 67 using snapdragoncolor::kPbIgc; 68 using snapdragoncolor::kPbGamut; 69 using snapdragoncolor::kPbGC; 70 using snapdragoncolor::kModeRenderInputParams; 71 using snapdragoncolor::kNeedsUpdate; 72 using snapdragoncolor::kSupportToneMap; 73 74 enum FeatureOps { 75 kFeatureSwitchMode, 76 kFeatureOpsMax, 77 }; 78 79 class FeatureInterface { 80 public: ~FeatureInterface()81 virtual ~FeatureInterface() {} 82 virtual DisplayError Init() = 0; 83 virtual DisplayError Deinit() = 0; 84 virtual DisplayError SetParams(FeatureOps param_type, void *payload) = 0; 85 virtual DisplayError GetParams(FeatureOps param_type, void *payload) = 0; 86 }; 87 88 FeatureInterface* GetPostedStartFeatureCheckIntf(HWInterface *intf, 89 PPFeaturesConfig *config); 90 91 class STCIntfClient { 92 public: STCIntfClient()93 STCIntfClient() {} ~STCIntfClient()94 ~STCIntfClient() {} 95 DisplayError Init(const std::string &panel_name); 96 DisplayError DeInit(); 97 98 // Property functions 99 DisplayError SetProperty(const ScPayload &payload); 100 DisplayError GetProperty(ScPayload *payload); 101 102 // ProcessOps functions 103 DisplayError ProcessOps(const ScOps op, const ScPayload &input, ScPayload *output); 104 105 private: 106 const char *kStcIntfLib_ = "libsnapdragoncolor.so"; 107 DynLib stc_intf_lib_; 108 ScPostBlendInterface *stc_intf_ = nullptr; 109 ScPostBlendInterface* (*GetScPostBlendInterface) 110 (uint32_t major_version, uint32_t minor_version) = nullptr; 111 mutex lock_; 112 }; 113 114 /* 115 * ColorManager proxy to maintain necessary information to interact with underlying color service. 116 * Each display object has its own proxy. 117 */ 118 class ColorManagerProxy { 119 public: 120 static DisplayError Init(const HWResourceInfo &hw_res_info); 121 static void Deinit(); 122 123 /* Create ColorManagerProxy for this display object, following things need to be happening 124 * 1. Instantiates concrete ColorInerface implementation. 125 * 2. Pass all display object specific informations into it. 126 * 3. Populate necessary resources. 127 * 4. Need get panel name for hw_panel_info_. 128 */ 129 static ColorManagerProxy *CreateColorManagerProxy(DisplayType type, HWInterface *hw_intf, 130 const HWDisplayAttributes &attribute, 131 const HWPanelInfo &panel_info, 132 DppsControlInterface *dpps_intf); 133 134 /* need reverse the effect of CreateColorManagerProxy. */ 135 ~ColorManagerProxy(); 136 137 DisplayError ColorSVCRequestRoute(const PPDisplayAPIPayload &in_payload, 138 PPDisplayAPIPayload *out_payload, 139 PPPendingParams *pending_action); 140 DisplayError ApplyDefaultDisplayMode(); 141 DisplayError ColorMgrGetNumOfModes(uint32_t *mode_cnt); 142 DisplayError ColorMgrGetModes(uint32_t *mode_cnt, SDEDisplayMode *modes); 143 DisplayError ColorMgrSetMode(int32_t color_mode_id); 144 DisplayError ColorMgrGetModeInfo(int32_t mode_id, AttrVal *query); 145 DisplayError ColorMgrSetColorTransform(uint32_t length, const double *trans_data); 146 DisplayError ColorMgrGetDefaultModeID(int32_t *mode_id); 147 DisplayError ColorMgrCombineColorModes(); 148 bool NeedsPartialUpdateDisable(); 149 DisplayError Commit(); 150 DisplayError ColorMgrSetModeWithRenderIntent(int32_t color_mode_id, 151 const PrimariesTransfer &blend_space, 152 uint32_t intent); 153 DisplayError Validate(HWLayers *hw_layers); 154 bool IsSupportStcTonemap(); 155 bool GameEnhanceSupported(); 156 157 protected: ColorManagerProxy()158 ColorManagerProxy() {} 159 ColorManagerProxy(int32_t id, DisplayType type, HWInterface *intf, 160 const HWDisplayAttributes &attr, const HWPanelInfo &info); 161 162 private: 163 static DynLib color_lib_; 164 static CreateColorInterface create_intf_; 165 static DestroyColorInterface destroy_intf_; 166 static HWResourceInfo hw_res_info_; 167 168 typedef DisplayError (ColorManagerProxy::*ConvertProc)(const HwConfigPayload &in_data, 169 PPFeaturesConfig *out_data); 170 typedef std::map<std::string, ConvertProc> ConvertTable; 171 172 bool NeedHwassetsUpdate(); 173 DisplayError UpdateModeHwassets(int32_t mode_id, snapdragoncolor::ColorMode color_mode, 174 bool valid_meta_data, const ColorMetaData &meta_data); 175 DisplayError ConvertToPPFeatures(HwConfigOutputParams *params, PPFeaturesConfig *out_data); 176 DisplayError ConvertToIgc(const HwConfigPayload &in_data, PPFeaturesConfig *out_data); 177 DisplayError ConvertToGc(const HwConfigPayload &in_data, PPFeaturesConfig *out_data); 178 DisplayError ConvertToGamut(const HwConfigPayload &in_data, PPFeaturesConfig *out_data); 179 void DumpColorMetaData(const ColorMetaData &color_metadata); 180 snapdragoncolor::ColorMode GetColorPrimaries(const PrimariesTransfer &blend_space, 181 uint32_t intent); 182 183 bool GetSupportStcTonemap(); 184 ConvertTable convert_; 185 186 int32_t display_id_; 187 DisplayType device_type_; 188 PPHWAttributes pp_hw_attributes_; 189 HWInterface *hw_intf_; 190 ColorInterface *color_intf_; 191 PPFeaturesConfig pp_features_; 192 FeatureInterface *feature_intf_; 193 bool apply_mode_ = false; 194 PrimariesTransfer cur_blend_space_ = {}; 195 uint32_t cur_intent_ = 0; 196 int32_t cur_mode_id_ = -1; 197 ColorMetaData meta_data_ = {}; 198 STCIntfClient *stc_intf_client_ = NULL; 199 bool support_stc_tonemap_ = false; 200 }; 201 202 class ColorFeatureCheckingImpl : public FeatureInterface { 203 public: 204 explicit ColorFeatureCheckingImpl(HWInterface *hw_intf, PPFeaturesConfig *pp_features); ~ColorFeatureCheckingImpl()205 virtual ~ColorFeatureCheckingImpl() { } 206 207 DisplayError Init(); 208 DisplayError Deinit(); 209 DisplayError SetParams(FeatureOps param_type, void *payload); 210 DisplayError GetParams(FeatureOps param_type, void *payload); 211 212 private: 213 friend class FeatureStatePostedStart; 214 friend class FeatureStateDefaultTrigger; 215 friend class FeatureStateSerializedTrigger; 216 217 HWInterface *hw_intf_; 218 PPFeaturesConfig *pp_features_; 219 std::array<FeatureInterface*, kFrameTriggerMax> states_ = {{NULL}}; 220 FeatureInterface *curr_state_ = NULL; 221 std::vector<PPGlobalColorFeatureID> single_buffer_feature_; 222 void CheckColorFeature(FrameTriggerMode *mode); 223 }; 224 225 class FeatureStatePostedStart : public FeatureInterface { 226 public: 227 explicit FeatureStatePostedStart(ColorFeatureCheckingImpl *obj); ~FeatureStatePostedStart()228 virtual ~FeatureStatePostedStart() {} 229 230 DisplayError Init(); 231 DisplayError Deinit(); 232 DisplayError SetParams(FeatureOps param_type, void *payload); 233 DisplayError GetParams(FeatureOps param_type, void *payload); 234 235 private: 236 ColorFeatureCheckingImpl *obj_; 237 }; 238 239 class FeatureStateDefaultTrigger : public FeatureInterface { 240 public: 241 explicit FeatureStateDefaultTrigger(ColorFeatureCheckingImpl *obj); ~FeatureStateDefaultTrigger()242 virtual ~FeatureStateDefaultTrigger() {} 243 244 DisplayError Init(); 245 DisplayError Deinit(); 246 DisplayError SetParams(FeatureOps param_type, void *payload); 247 DisplayError GetParams(FeatureOps param_type, void *payload); 248 249 private: 250 ColorFeatureCheckingImpl *obj_; 251 }; 252 253 class FeatureStateSerializedTrigger : public FeatureInterface { 254 public: 255 explicit FeatureStateSerializedTrigger(ColorFeatureCheckingImpl *obj); ~FeatureStateSerializedTrigger()256 virtual ~FeatureStateSerializedTrigger() {} 257 258 DisplayError Init(); 259 DisplayError Deinit(); 260 DisplayError SetParams(FeatureOps param_type, void *payload); 261 DisplayError GetParams(FeatureOps param_type, void *payload); 262 263 private: 264 ColorFeatureCheckingImpl *obj_; 265 }; 266 267 } // namespace sdm 268 269 #endif // __COLOR_MANAGER_H__ 270