1 /* 2 * Copyright (c) 2019, The Linux Foundation. All rights reserved. 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions are 6 * met: 7 * * Redistributions of source code must retain the above copyright 8 * notice, this list of conditions and the following disclaimer. 9 * * Redistributions in binary form must reproduce the above 10 * copyright notice, this list of conditions and the following 11 * disclaimer in the documentation and/or other materials provided 12 * with the distribution. 13 * * Neither the name of The Linux Foundation nor the names of its 14 * contributors may be used to endorse or promote products derived 15 * from this software without specific prior written permission. 16 * 17 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED 18 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 19 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT 20 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS 21 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 23 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 24 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 25 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 26 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN 27 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 */ 29 30 #ifndef __SNAPDRAGON_COLOR_INTF_H__ 31 #define __SNAPDRAGON_COLOR_INTF_H__ 32 33 #include <vector> 34 #include <array> 35 #include <tuple> 36 #include <functional> 37 #include <memory> 38 #include <string> 39 #include "display_color_processing.h" 40 #include "color_metadata.h" 41 42 namespace snapdragoncolor { 43 44 //<! Hardware assets strings 45 const std::string kPbGamut = "PostBlendGamut"; 46 const std::string kPbIgc = "PostBlendIGC"; 47 const std::string kPbGC = "PostBlendGC"; 48 49 enum ScProperty { 50 //<! Make value of zero as invalid. 51 kInvalid = 0, 52 //<! GetProperty - For client to Get list of supported ColorModes. 53 //<! Payload -struct ColorModeList 54 kModeList, 55 //<! GetProperty - For client to check if Mode needs to be updated due to listener updates. 56 //<! Payload - bool 57 kNeedsUpdate, 58 //<! ScOps - Prop for passing ModeRenderInputParams payload 59 //<! Payload - ModeRenderInputParams 60 kModeRenderInputParams, 61 //<! ScOps - Prop for passing HwConfigOutputParams payload 62 //<! Payload - HwConfigOutputParams 63 kHwConfigPayloadParam, 64 //<! SetProperty - Property to pass the ColorTransform matrix for display 65 //<! Payload - struct ColorTransform 66 kSetColorTransform, 67 //<! SetProperty - Client will set the Gamut hw config data 68 //<! Payload - PostBlendGamutHwConfig 69 kPostBlendGamutHwConfig, 70 //<! SetProperty - Client will set the Gamma hw config data 71 //<! Payload - PostBlendGammaHwConfig 72 kPostBlendGammaHwConfig, 73 //<! SetProperty - Client will set the Inverse Gamma hw config data 74 //<! Payload - PostBlendInverseGammaHwConfig 75 kPostBlendInverseGammaHwConfig, 76 //<! GetProperty - For client to check if library supports hdr tone-mapping. 77 //<! Payload - bool 78 kSupportToneMap, 79 //<! Max value of public properties 80 kPropertyMax = 511, 81 //<! Custom Properties 82 kCustomPropertyStart = 512, 83 kCustomPropertyEnd = 1024, 84 }; 85 86 enum ScOps { 87 //<! Client will pass blend-space, render intent and color primaries along with hardware 88 //<! assets that interface can use for generating the mode (ModeRenderInputParams). 89 //<! Interface ProcessOps implementation will consume ModeRenderInputParams and generate 90 //<! required mode and will update the OpsOutParams with HW asset configuration. 91 kScModeRenderIntent, 92 kScOpsMax, 93 }; 94 95 static const uint32_t kMatrixSize = 4 * 4; 96 struct ColorTransform { 97 const uint32_t version = sizeof(struct ColorTransform); 98 std::array<float, kMatrixSize> coeff_array; 99 }; 100 101 struct ScPayload { 102 uint32_t version = sizeof(ScPayload); 103 //<! len of the payload 104 uint32_t len = 0; 105 //<! ScProperty for the payload 106 ScProperty prop = kInvalid; 107 //<! payload pointer, has been made as uint64_t to support 32/64 bit platforms 108 uint64_t payload = reinterpret_cast<uint64_t>(nullptr); 109 }; 110 111 112 class ScPostBlendInterface { 113 public: ~ScPostBlendInterface()114 virtual ~ScPostBlendInterface() {} 115 //<! Initialization related functions 116 virtual int Init(const std::string &panel_name) = 0; 117 virtual int DeInit() = 0; 118 119 // Property functions 120 virtual int SetProperty(const ScPayload &payload) = 0; 121 virtual int GetProperty(ScPayload *payload) = 0; 122 123 // ProcessOps functions 124 virtual int ProcessOps(ScOps op, const ScPayload &input, ScPayload *output) = 0; 125 }; 126 127 extern "C" ScPostBlendInterface* GetScPostBlendInterface(uint32_t major_version, 128 uint32_t minor_version); 129 130 enum RenderIntent { 131 //<! Colors with vendor defined gamut 132 kNative, 133 //<! Colors with in gamut are left untouched, out side the gamut are hard clipped 134 kColorimetric, 135 //<! Colors with in gamut are ehanced, out side the gamuat are hard clipped 136 kEnhance, 137 //<! Tone map hdr colors to display's dynamic range, mapping to display gamut is 138 //<! defined in colormertic. 139 kToneMapColorimetric, 140 //<! Tone map hdr colors to display's dynamic range, mapping to display gamut is 141 //<! defined in enhance. 142 kToneMapEnhance, 143 //<! Custom render intents range 144 kOemCustomStart = 0x100, 145 kOemCustomEnd = 0x1ff, 146 kMaxRenderIntent = 0xffff 147 }; 148 149 struct ColorMode { 150 //<! Blend-Space gamut 151 ColorPrimaries gamut; 152 //<! Blend-space Gamma 153 GammaTransfer gamma; 154 //<! Intent of the mode 155 RenderIntent intent; 156 //<! Hardware assets needed for the mode 157 std::vector<std::string> hw_assets; 158 }; 159 160 struct ColorModeList { 161 const uint32_t version = sizeof(struct ColorModeList) + sizeof(struct ColorMode); 162 //<! List of the color modes 163 std::vector<ColorMode> list; 164 }; 165 166 struct GamutConfig { 167 const uint32_t version = sizeof(struct GamutConfig); 168 bool enabled = false; 169 //<! Gamut table config 170 lut3d_info gamut_info; 171 }; 172 173 struct GammaPostBlendConfig { 174 const uint32_t version = sizeof(struct GammaPostBlendConfig); 175 bool enabled = false; 176 //<! GC/IGC tables for each color component 177 std::vector<uint32_t> r; 178 std::vector<uint32_t> g; 179 std::vector<uint32_t> b; GammaPostBlendConfigGammaPostBlendConfig180 explicit GammaPostBlendConfig(uint32_t len) { 181 r.reserve(len); 182 b.reserve(len); 183 g.reserve(len); 184 } 185 }; 186 187 struct PostBlendGamutHwConfig { 188 uint32_t gamut_version = sizeof(struct GamutConfig); 189 uint32_t num_of_grid_entires = 17; 190 uint32_t grid_entries_width = 10; 191 }; 192 193 struct PostBlendGammaHwConfig { 194 uint32_t gamma_version = sizeof(struct GammaPostBlendConfig); 195 uint32_t num_of_entries = 1024; 196 uint32_t entries_width = 10; 197 }; 198 199 struct PostBlendInverseGammaHwConfig { 200 uint32_t inverse_gamma_version = sizeof(struct GammaPostBlendConfig); 201 uint32_t num_of_entries = 256; 202 uint32_t entries_width = 12; 203 }; 204 205 struct HwConfigPayload { 206 const uint32_t version = sizeof(struct HwConfigPayload); 207 //<! Memory for HW assets will be allocated by client 208 //<! Hw asset 209 std::string hw_asset; 210 //<! payload for hw_asset 211 std::shared_ptr<void> hw_payload; 212 //<! payload len 213 uint32_t hw_payload_len; 214 }; 215 216 struct ModeRenderInputParams { 217 const uint32_t version = sizeof(struct ModeRenderInputParams); 218 //<! hw assets that shall be used for generating mode. 219 //<! Optional parameter for now, added for future expansion. 220 std::vector<std::string> hw_assets_for_mode; 221 //<! Client will pass current blend space and render intent information. 222 ColorMode color_mode; 223 //<! flag will be true if we have valid color metadata(Ex: HDR10 playback) 224 bool valid_meta_data; 225 //<! if valid_meta_data is true, meta_data needs to be parsed. 226 ColorMetaData meta_data; 227 //<! QDCM color mode id. 228 int32_t mode_id; 229 }; 230 231 struct HwConfigOutputParams { 232 const uint32_t version = sizeof(HwConfigOutputParams); 233 //<! HW asset configurations that imp updates for kScModeRenderIntent ProcessOps call. 234 std::vector<HwConfigPayload> payload; 235 }; 236 237 } // namespace snapdragoncolor 238 #endif // __SNAPDRAGON_COLOR_INTF_H__ 239