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