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