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