1 /* Copyright (c) 2015-2016, 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_PARAMS_H__ 31 #define __COLOR_PARAMS_H__ 32 33 #include <stdio.h> 34 #include <string.h> 35 #include <utils/locker.h> 36 #include <utils/constants.h> 37 #include <core/sdm_types.h> 38 #include <core/display_interface.h> 39 #include "hw_info_types.h" 40 41 namespace sdm { 42 43 // Bitmap Pending action to indicate to the caller what's pending to be taken care of. 44 enum PendingAction { 45 kInvalidating = BITMAP(0), 46 kApplySolidFill = BITMAP(1), 47 kDisableSolidFill = BITMAP(2), 48 kEnterQDCMMode = BITMAP(3), 49 kExitQDCMMode = BITMAP(4), 50 kSetPanelBrightness = BITMAP(5), 51 kEnableFrameCapture = BITMAP(6), 52 kDisableFrameCapture = BITMAP(7), 53 kConfigureDetailedEnhancer = BITMAP(8), 54 kNoAction = BITMAP(31), 55 }; 56 57 // ENUM to identify different Postprocessing feature block to program. 58 // Note: For each new entry added here, also need update hw_interface::GetPPFeaturesVersion<> 59 // AND HWPrimary::SetPPFeatures<>. 60 enum PPGlobalColorFeatureID { 61 kGlobalColorFeaturePcc, 62 kGlobalColorFeatureIgc, 63 kGlobalColorFeaturePgc, 64 kMixerColorFeatureGc, 65 kGlobalColorFeaturePaV2, 66 kGlobalColorFeatureDither, 67 kGlobalColorFeatureGamut, 68 kGlobalColorFeaturePADither, 69 kMaxNumPPFeatures, 70 }; 71 72 struct PPPendingParams { 73 PendingAction action = kNoAction; 74 void *params = NULL; 75 }; 76 77 struct PPColorInfo { 78 uint32_t r_bitdepth = 0; 79 uint32_t r = 0; 80 uint32_t g_bitdepth = 0; 81 uint32_t g = 0; 82 uint32_t b_bitdepth = 0; 83 uint32_t b = 0; 84 }; 85 86 struct PPColorFillParams { 87 uint32_t flags = 0; 88 struct { 89 uint32_t width = 0; 90 uint32_t height = 0; 91 int32_t x = 0; 92 int32_t y = 0; 93 } rect; 94 95 PPColorInfo color; 96 }; 97 98 struct PPFeatureVersion { 99 // SDE ASIC versioning its PP block at each specific feature level. 100 static const uint32_t kSDEIgcV17 = 1; 101 static const uint32_t kSDEPgcV17 = 5; 102 static const uint32_t kSDEDitherV17 = 7; 103 static const uint32_t kSDEGamutV17 = 9; 104 static const uint32_t kSDEPaV17 = 11; 105 static const uint32_t kSDEPccV17 = 13; 106 static const uint32_t kSDELegacyPP = 15; 107 static const uint32_t kSDEPADitherV17 = 16; 108 static const uint32_t kSDEIgcV30 = 17; 109 110 uint32_t version[kMaxNumPPFeatures]; 111 PPFeatureVersion() { memset(version, 0, sizeof(version)); } 112 }; 113 114 struct PPHWAttributes : HWResourceInfo, HWPanelInfo, DisplayConfigVariableInfo { 115 char panel_name[256] = "generic_panel"; 116 PPFeatureVersion version; 117 int panel_max_brightness = 0; 118 119 void Set(const HWResourceInfo &hw_res, const HWPanelInfo &panel_info, 120 const DisplayConfigVariableInfo &attr, const PPFeatureVersion &feature_ver); 121 }; 122 123 struct PPDisplayAPIPayload { 124 bool own_payload = false; // to indicate if *payload is owned by this or just a reference. 125 uint32_t size = 0; 126 uint8_t *payload = NULL; 127 128 PPDisplayAPIPayload() = default; 129 PPDisplayAPIPayload(uint32_t size, uint8_t *param) 130 : size(size), payload(param) {} 131 132 template <typename T> 133 DisplayError CreatePayload(T *&output) { 134 DisplayError ret = kErrorNone; 135 136 payload = new uint8_t[sizeof(T)](); 137 if (!payload) { 138 ret = kErrorMemory; 139 output = NULL; 140 } else { 141 this->size = sizeof(T); 142 output = reinterpret_cast<T *>(payload); 143 own_payload = true; 144 } 145 return ret; 146 } 147 148 DisplayError CreatePayloadBytes(uint32_t size_in_bytes, uint8_t **output) { 149 DisplayError ret = kErrorNone; 150 151 payload = new uint8_t[size_in_bytes](); 152 if (!payload) { 153 ret = kErrorMemory; 154 *output = NULL; 155 } else { 156 this->size = size_in_bytes; 157 *output = payload; 158 own_payload = true; 159 } 160 return ret; 161 } 162 163 inline void DestroyPayload() { 164 if (payload && own_payload) { 165 delete[] payload; 166 payload = NULL; 167 size = 0; 168 } else { 169 payload = NULL; 170 size = 0; 171 } 172 } 173 }; 174 175 struct PPRectInfo { 176 uint32_t width; 177 uint32_t height; 178 int32_t x; 179 int32_t y; 180 }; 181 182 typedef enum { 183 PP_PIXEL_FORMAT_NONE = 0, 184 PP_PIXEL_FORMAT_RGB_888, 185 PP_PIXEL_FORMAT_RGB_2101010, 186 PP_PIXEL_FORMAT_MAX, 187 PP_PIXEL_FORMAT_FORCE32BIT = 0x7FFFFFFF, 188 } PPPixelFormats; 189 190 struct PPFrameCaptureInputParams { 191 PPRectInfo rect; 192 PPPixelFormats out_pix_format; 193 uint32_t flags; 194 }; 195 196 struct PPFrameCaptureData { 197 PPFrameCaptureInputParams input_params; 198 uint8_t *buffer; 199 uint32_t buffer_stride; 200 uint32_t buffer_size; 201 }; 202 203 static const uint32_t kDeTuningFlagSharpFactor = 0x01; 204 static const uint32_t kDeTuningFlagClip = 0x02; 205 static const uint32_t kDeTuningFlagThrQuiet = 0x04; 206 static const uint32_t kDeTuningFlagThrDieout = 0x08; 207 static const uint32_t kDeTuningFlagThrLow = 0x10; 208 static const uint32_t kDeTuningFlagThrHigh = 0x20; 209 static const uint32_t kDeTuningFlagContentQualLevel = 0x40; 210 211 typedef enum { 212 kDeContentQualUnknown, 213 kDeContentQualLow, 214 kDeContentQualMedium, 215 kDeContentQualHigh, 216 kDeContentQualMax, 217 } PPDEContentQualLevel; 218 219 typedef enum { 220 kDeContentTypeUnknown, 221 kDeContentTypeVideo, 222 kDeContentTypeGraphics, 223 kDeContentTypeMax, 224 } PPDEContentType; 225 226 struct PPDETuningCfg { 227 uint32_t flags = 0; 228 int32_t sharp_factor = 0; 229 uint16_t thr_quiet = 0; 230 uint16_t thr_dieout = 0; 231 uint16_t thr_low = 0; 232 uint16_t thr_high = 0; 233 uint16_t clip = 0; 234 PPDEContentQualLevel quality = kDeContentQualUnknown; 235 PPDEContentType content_type = kDeContentTypeUnknown; 236 }; 237 238 struct PPDETuningCfgData { 239 uint32_t cfg_en = 0; 240 PPDETuningCfg params; 241 }; 242 243 struct SDEGamutCfg { 244 static const int kGamutTableNum = 4; 245 static const int kGamutScaleoffTableNum = 3; 246 static const int kGamutTableSize = 1229; 247 static const int kGamutTableCoarseSize = 32; 248 static const int kGamutScaleoffSize = 16; 249 uint32_t mode; 250 uint32_t map_en; 251 uint32_t tbl_size[kGamutTableNum]; 252 uint32_t *c0_data[kGamutTableNum]; 253 uint32_t *c1_c2_data[kGamutTableNum]; 254 uint32_t tbl_scale_off_sz[kGamutScaleoffTableNum]; 255 uint32_t *scale_off_data[kGamutScaleoffTableNum]; 256 }; 257 258 struct SDEPccCoeff { 259 uint32_t c = 0; 260 uint32_t r = 0; 261 uint32_t g = 0; 262 uint32_t b = 0; 263 uint32_t rg = 0; 264 uint32_t gb = 0; 265 uint32_t rb = 0; 266 uint32_t rgb = 0; 267 }; 268 269 struct SDEPccCfg { 270 SDEPccCoeff red; 271 SDEPccCoeff green; 272 SDEPccCoeff blue; 273 274 static SDEPccCfg *Init(uint32_t arg __attribute__((__unused__))); 275 SDEPccCfg *GetConfig() { return this; } 276 }; 277 278 struct SDEDitherCfg { 279 uint32_t g_y_depth; 280 uint32_t r_cr_depth; 281 uint32_t b_cb_depth; 282 uint32_t length; 283 uint32_t dither_matrix[16]; 284 uint32_t temporal_en; 285 286 static SDEDitherCfg *Init(uint32_t arg __attribute__((__unused__))); 287 SDEDitherCfg *GetConfig() { return this; } 288 }; 289 290 struct SDEPADitherData { 291 uint64_t data_flags; 292 uint32_t matrix_size; 293 uint64_t matrix_data_addr; 294 uint32_t strength; 295 uint32_t offset_en; 296 }; 297 298 class SDEPADitherWrapper : private SDEPADitherData { 299 public: 300 static SDEPADitherWrapper *Init(uint32_t arg __attribute__((__unused__))); 301 ~SDEPADitherWrapper() { 302 if (buffer_) 303 delete[] buffer_; 304 } 305 inline SDEPADitherData *GetConfig(void) { return this; } 306 307 private: 308 SDEPADitherWrapper() {} 309 uint32_t *buffer_ = NULL; 310 }; 311 312 struct SDEPaMemColorData { 313 uint32_t adjust_p0 = 0; 314 uint32_t adjust_p1 = 0; 315 uint32_t adjust_p2 = 0; 316 uint32_t blend_gain = 0; 317 uint8_t sat_hold = 0; 318 uint8_t val_hold = 0; 319 uint32_t hue_region = 0; 320 uint32_t sat_region = 0; 321 uint32_t val_region = 0; 322 }; 323 324 struct SDEPaData { 325 static const int kSixZoneLUTSize = 384; 326 uint32_t mode = 0; 327 uint32_t hue_adj = 0; 328 uint32_t sat_adj = 0; 329 uint32_t val_adj = 0; 330 uint32_t cont_adj; 331 SDEPaMemColorData skin; 332 SDEPaMemColorData sky; 333 SDEPaMemColorData foliage; 334 uint32_t six_zone_thresh = 0; 335 uint32_t six_zone_adj_p0 = 0; 336 uint32_t six_zone_adj_p1 = 0; 337 uint8_t six_zone_sat_hold = 0; 338 uint8_t six_zone_val_hold = 0; 339 uint32_t six_zone_len = 0; 340 uint32_t *six_zone_curve_p0 = NULL; 341 uint32_t *six_zone_curve_p1 = NULL; 342 }; 343 344 struct SDEIgcLUTData { 345 static const int kMaxIgcLUTEntries = 256; 346 uint32_t table_fmt = 0; 347 uint32_t len = 0; 348 uint32_t *c0_c1_data = NULL; 349 uint32_t *c2_data = NULL; 350 }; 351 352 struct SDEIgcV30LUTData { 353 static const int kMaxIgcLUTEntries = 256; 354 uint32_t table_fmt = 0; 355 uint32_t len = 0; 356 uint64_t c0_c1_data = 0; 357 uint64_t c2_data = 0; 358 uint32_t strength = 0; 359 }; 360 361 struct SDEPgcLUTData { 362 static const int kPgcLUTEntries = 1024; 363 uint32_t len = 0; 364 uint32_t *c0_data = NULL; 365 uint32_t *c1_data = NULL; 366 uint32_t *c2_data = NULL; 367 }; 368 369 struct SDEDisplayMode { 370 static const int kMaxModeNameSize = 256; 371 int32_t id = -1; 372 uint32_t type = 0; 373 char name[kMaxModeNameSize] = {0}; 374 }; 375 376 // Wrapper on HW block config data structure to encapsulate the details of allocating 377 // and destroying from the caller. 378 class SDEGamutCfgWrapper : private SDEGamutCfg { 379 public: 380 enum GamutMode { 381 GAMUT_FINE_MODE = 0x01, 382 GAMUT_COARSE_MODE, 383 }; 384 385 // This factory method will be used by libsdm-color.so data producer to be populated with 386 // converted config values for SDE feature blocks. 387 static SDEGamutCfgWrapper *Init(uint32_t arg); 388 389 // Data consumer<Commit thread> will be responsible to destroy it once the feature is commited. 390 ~SDEGamutCfgWrapper() { 391 if (buffer_) 392 delete[] buffer_; 393 } 394 395 // Data consumer will use this method to retrieve contained feature configuration. 396 inline SDEGamutCfg *GetConfig(void) { return this; } 397 398 private: 399 SDEGamutCfgWrapper() {} 400 uint32_t *buffer_ = NULL; 401 }; 402 403 class SDEPaCfgWrapper : private SDEPaData { 404 public: 405 static SDEPaCfgWrapper *Init(uint32_t arg = 0); 406 ~SDEPaCfgWrapper() { 407 if (buffer_) 408 delete[] buffer_; 409 } 410 inline SDEPaData *GetConfig(void) { return this; } 411 412 private: 413 SDEPaCfgWrapper() {} 414 uint32_t *buffer_ = NULL; 415 }; 416 417 class SDEIgcLUTWrapper : private SDEIgcLUTData { 418 public: 419 static SDEIgcLUTWrapper *Init(uint32_t arg __attribute__((__unused__))); 420 ~SDEIgcLUTWrapper() { 421 if (buffer_) 422 delete[] buffer_; 423 } 424 inline SDEIgcLUTData *GetConfig(void) { return this; } 425 426 private: 427 SDEIgcLUTWrapper() {} 428 uint32_t *buffer_ = NULL; 429 }; 430 431 class SDEIgcV30LUTWrapper : private SDEIgcV30LUTData { 432 public: 433 static SDEIgcV30LUTWrapper *Init(uint32_t arg __attribute__((__unused__))); 434 ~SDEIgcV30LUTWrapper() { 435 if (buffer_) 436 delete[] buffer_; 437 } 438 inline SDEIgcV30LUTData *GetConfig(void) { return this; } 439 440 private: 441 SDEIgcV30LUTWrapper(const SDEIgcV30LUTWrapper& src) { /* do not create copies */ } 442 SDEIgcV30LUTWrapper& operator=(const SDEIgcV30LUTWrapper&) { return *this; } 443 SDEIgcV30LUTWrapper() {} 444 uint32_t *buffer_ = NULL; 445 }; 446 447 class SDEPgcLUTWrapper : private SDEPgcLUTData { 448 public: 449 static SDEPgcLUTWrapper *Init(uint32_t arg __attribute__((__unused__))); 450 ~SDEPgcLUTWrapper() { 451 if (buffer_) 452 delete[] buffer_; 453 } 454 inline SDEPgcLUTData *GetConfig(void) { return this; } 455 456 private: 457 SDEPgcLUTWrapper() {} 458 uint32_t *buffer_ = NULL; 459 }; 460 461 // Base Postprocessing features information. 462 class PPFeatureInfo { 463 public: 464 uint32_t enable_flags_ = 0; // bitmap to indicate subset of parameters enabling or not. 465 uint32_t feature_version_ = 0; 466 uint32_t feature_id_ = 0; 467 uint32_t disp_id_ = 0; 468 uint32_t pipe_id_ = 0; 469 470 virtual ~PPFeatureInfo() {} 471 virtual void *GetConfigData(void) const = 0; 472 }; 473 474 // Individual Postprocessing feature representing physical attributes and information 475 // This template class wrapping around abstract data type representing different 476 // post-processing features. It will take output from ColorManager converting from raw metadata. 477 // The configuration will directly pass into HWInterface to program the hardware accordingly. 478 template <typename T> 479 class TPPFeatureInfo : public PPFeatureInfo { 480 public: 481 virtual ~TPPFeatureInfo() { 482 if (params_) 483 delete params_; 484 } 485 486 // API for data consumer to get underlying data configs to program into pp hardware block. 487 virtual void *GetConfigData(void) const { return params_->GetConfig(); } 488 489 // API for data producer to get access to underlying data configs to populate it. 490 T *GetParamsReference(void) { return params_; } 491 492 // API for create this template object. 493 static TPPFeatureInfo *Init(uint32_t arg = 0) { 494 TPPFeatureInfo *info = new TPPFeatureInfo(); 495 if (info) { 496 info->params_ = T::Init(arg); 497 if (!info->params_) { 498 delete info; 499 info = NULL; 500 } 501 } 502 503 return info; 504 } 505 506 protected: 507 TPPFeatureInfo() = default; 508 509 private: 510 T *params_ = NULL; 511 }; 512 513 // This singleton class serves as data exchanging central between data producer 514 // <libsdm-color.so> and data consumer<SDM and HWC.> 515 // This class defines PP pending features to be programmed, which generated from 516 // ColorManager. Dirty flag indicates some features are available to be programmed. 517 // () Lock is needed since the object wil be accessed from 2 tasks. 518 // All API exposed are not threadsafe, it's caller's responsiblity to acquire the locker. 519 class PPFeaturesConfig { 520 public: 521 PPFeaturesConfig() { memset(feature_, 0, sizeof(feature_)); } 522 ~PPFeaturesConfig() { Reset(); } 523 524 // ColorManager installs one TFeatureInfo<T> to take the output configs computed 525 // from ColorManager, containing all physical features to be programmed and also compute 526 // metadata/populate into T. 527 inline DisplayError AddFeature(uint32_t feature_id, PPFeatureInfo *feature) { 528 if (feature_id < kMaxNumPPFeatures) 529 feature_[feature_id] = feature; 530 531 return kErrorNone; 532 } 533 534 inline Locker &GetLocker(void) { return locker_; } 535 inline PPFrameCaptureData *GetFrameCaptureData(void) { return &frame_capture_data; } 536 inline PPDETuningCfgData *GetDETuningCfgData(void) { return &de_tuning_data_; } 537 // Once all features are consumed, destroy/release all TFeatureInfo<T> on the list, 538 // then clear dirty_ flag and return the lock to the TFeatureInfo<T> producer. 539 void Reset(); 540 541 // Consumer to call this to retrieve all the TFeatureInfo<T> on the list to be programmed. 542 DisplayError RetrieveNextFeature(PPFeatureInfo **feature); 543 544 inline bool IsDirty() { return dirty_; } 545 inline void MarkAsDirty() { dirty_ = true; } 546 547 private: 548 bool dirty_ = 0; 549 Locker locker_; 550 PPFeatureInfo *feature_[kMaxNumPPFeatures]; // reference to TFeatureInfo<T>. 551 uint32_t next_idx_ = 0; 552 PPFrameCaptureData frame_capture_data; 553 PPDETuningCfgData de_tuning_data_; 554 }; 555 556 } // namespace sdm 557 558 #endif // __COLOR_PARAMS_H__ 559