Home | History | Annotate | Download | only in core
      1 /*
      2 * Copyright (c) 2014-2017, The Linux Foundation. All rights reserved.
      3 *
      4 * Redistribution and use in source and binary forms, with or without modification, are permitted
      5 * provided that the following conditions are met:
      6 *    * Redistributions of source code must retain the above copyright notice, this list of
      7 *      conditions and the following disclaimer.
      8 *    * Redistributions in binary form must reproduce the above copyright notice, this list of
      9 *      conditions and the following disclaimer in the documentation and/or other materials provided
     10 *      with the distribution.
     11 *    * Neither the name of The Linux Foundation nor the names of its contributors may be used to
     12 *      endorse or promote products derived from this software without specific prior written
     13 *      permission.
     14 *
     15 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
     16 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
     17 * NON-INFRINGEMENT ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
     18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
     19 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
     20 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
     21 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
     22 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     23 */
     24 
     25 #ifndef __DISPLAY_BASE_H__
     26 #define __DISPLAY_BASE_H__
     27 
     28 #include <core/display_interface.h>
     29 #include <private/strategy_interface.h>
     30 #include <private/color_interface.h>
     31 
     32 #include <map>
     33 #include <mutex>
     34 #include <string>
     35 #include <vector>
     36 
     37 #include "hw_interface.h"
     38 #include "comp_manager.h"
     39 #include "color_manager.h"
     40 #include "hw_events_interface.h"
     41 
     42 namespace sdm {
     43 
     44 using std::recursive_mutex;
     45 using std::lock_guard;
     46 
     47 class DisplayBase : public DisplayInterface, DumpImpl {
     48  public:
     49   DisplayBase(DisplayType display_type, DisplayEventHandler *event_handler,
     50               HWDeviceType hw_device_type, BufferSyncHandler *buffer_sync_handler,
     51               CompManager *comp_manager, HWInfoInterface *hw_info_intf);
     52   virtual ~DisplayBase() { }
     53   virtual DisplayError Init();
     54   virtual DisplayError Deinit();
     55   DisplayError Prepare(LayerStack *layer_stack);
     56   DisplayError Commit(LayerStack *layer_stack);
     57   virtual DisplayError Flush();
     58   virtual DisplayError GetDisplayState(DisplayState *state);
     59   virtual DisplayError GetNumVariableInfoConfigs(uint32_t *count);
     60   virtual DisplayError GetConfig(uint32_t index, DisplayConfigVariableInfo *variable_info);
     61   virtual DisplayError GetConfig(DisplayConfigFixedInfo *variable_info);
     62   virtual DisplayError GetActiveConfig(uint32_t *index);
     63   virtual DisplayError GetVSyncState(bool *enabled);
     64   virtual DisplayError SetDisplayState(DisplayState state);
     65   virtual DisplayError SetActiveConfig(uint32_t index);
     66   virtual DisplayError SetActiveConfig(DisplayConfigVariableInfo *variable_info) {
     67     return kErrorNotSupported;
     68   }
     69   virtual DisplayError SetMaxMixerStages(uint32_t max_mixer_stages);
     70   virtual DisplayError ControlPartialUpdate(bool enable, uint32_t *pending) {
     71     return kErrorNotSupported;
     72   }
     73   virtual DisplayError DisablePartialUpdateOneFrame() {
     74     return kErrorNotSupported;
     75   }
     76   virtual DisplayError SetDisplayMode(uint32_t mode) {
     77     return kErrorNotSupported;
     78   }
     79   virtual bool IsUnderscanSupported() {
     80     return false;
     81   }
     82   virtual DisplayError SetPanelBrightness(int level) {
     83     return kErrorNotSupported;
     84   }
     85   virtual DisplayError CachePanelBrightness(int level) {
     86     return kErrorNotSupported;
     87   }
     88   virtual DisplayError OnMinHdcpEncryptionLevelChange(uint32_t min_enc_level) {
     89     return kErrorNotSupported;
     90   }
     91   virtual DisplayError ColorSVCRequestRoute(const PPDisplayAPIPayload &in_payload,
     92                                             PPDisplayAPIPayload *out_payload,
     93                                             PPPendingParams *pending_action);
     94   virtual DisplayError GetColorModeCount(uint32_t *mode_count);
     95   virtual DisplayError GetColorModes(uint32_t *mode_count, std::vector<std::string> *color_modes);
     96   virtual DisplayError GetColorModeAttr(const std::string &color_mode, AttrVal *attr);
     97   virtual DisplayError SetColorMode(const std::string &color_mode);
     98   virtual DisplayError SetColorModeById(int32_t color_mode_id);
     99   virtual DisplayError SetColorTransform(const uint32_t length, const double *color_transform);
    100   virtual DisplayError GetDefaultColorMode(std::string *color_mode);
    101   virtual DisplayError ApplyDefaultDisplayMode(void);
    102   virtual DisplayError SetCursorPosition(int x, int y);
    103   virtual DisplayError GetRefreshRateRange(uint32_t *min_refresh_rate, uint32_t *max_refresh_rate);
    104   virtual DisplayError GetPanelBrightness(int *level) {
    105     return kErrorNotSupported;
    106   }
    107   virtual DisplayError SetVSyncState(bool enable);
    108   virtual void SetIdleTimeoutMs(uint32_t active_ms) {}
    109   virtual DisplayError SetMixerResolution(uint32_t width, uint32_t height);
    110   virtual DisplayError GetMixerResolution(uint32_t *width, uint32_t *height);
    111   virtual DisplayError SetFrameBufferConfig(const DisplayConfigVariableInfo &variable_info);
    112   virtual DisplayError GetFrameBufferConfig(DisplayConfigVariableInfo *variable_info);
    113   virtual DisplayError SetDetailEnhancerData(const DisplayDetailEnhancerData &de_data);
    114   virtual DisplayError GetDisplayPort(DisplayPort *port);
    115   virtual bool IsPrimaryDisplay();
    116   virtual DisplayError SetCompositionState(LayerComposition composition_type, bool enable);
    117 
    118  protected:
    119   DisplayError BuildLayerStackStats(LayerStack *layer_stack);
    120   virtual DisplayError ValidateGPUTargetParams();
    121   void CommitLayerParams(LayerStack *layer_stack);
    122   void PostCommitLayerParams(LayerStack *layer_stack);
    123   DisplayError HandleHDR(LayerStack *layer_stack);
    124 
    125   // DumpImpl method
    126   void AppendDump(char *buffer, uint32_t length);
    127 
    128   const char *GetName(const LayerComposition &composition);
    129   DisplayError ReconfigureDisplay();
    130   bool NeedsMixerReconfiguration(LayerStack *layer_stack, uint32_t *new_mixer_width,
    131                                  uint32_t *new_mixer_height);
    132   DisplayError ReconfigureMixer(uint32_t width, uint32_t height);
    133   bool NeedsDownScale(const LayerRect &src_rect, const LayerRect &dst_rect, bool needs_rotation);
    134   DisplayError InitializeColorModes();
    135   DisplayError SetColorModeInternal(const std::string &color_mode);
    136   DisplayError GetValueOfModeAttribute(const AttrVal &attr, const std::string &type,
    137                                        std::string *value);
    138   DisplayError GetHdrColorMode(std::string *color_mode, bool *found_hdr);
    139   bool IsSupportColorModeAttribute(const std::string &color_mode);
    140 
    141   static std::bitset<kDisplayMax> needs_validate_;
    142   recursive_mutex recursive_mutex_;
    143   DisplayType display_type_;
    144   DisplayEventHandler *event_handler_ = NULL;
    145   HWDeviceType hw_device_type_;
    146   HWInterface *hw_intf_ = NULL;
    147   HWPanelInfo hw_panel_info_;
    148   BufferSyncHandler *buffer_sync_handler_ = NULL;
    149   CompManager *comp_manager_ = NULL;
    150   DisplayState state_ = kStateOff;
    151   bool active_ = false;
    152   Handle hw_device_ = 0;
    153   Handle display_comp_ctx_ = 0;
    154   HWLayers hw_layers_;
    155   bool vsync_enable_ = false;
    156   uint32_t max_mixer_stages_ = 0;
    157   HWInfoInterface *hw_info_intf_ = NULL;
    158   ColorManagerProxy *color_mgr_ = NULL;  // each display object owns its ColorManagerProxy
    159   bool partial_update_control_ = true;
    160   HWEventsInterface *hw_events_intf_ = NULL;
    161   bool disable_pu_one_frame_ = false;
    162   uint32_t num_color_modes_ = 0;
    163   std::vector<SDEDisplayMode> color_modes_;
    164   typedef std::map<std::string, SDEDisplayMode *> ColorModeMap;
    165   ColorModeMap color_mode_map_ = {};
    166   typedef std::map<std::string, AttrVal> ColorModeAttrMap;
    167   ColorModeAttrMap color_mode_attr_map_ = {};
    168   HWDisplayAttributes display_attributes_ = {};
    169   HWMixerAttributes mixer_attributes_ = {};
    170   DisplayConfigVariableInfo fb_config_ = {};
    171   uint32_t req_mixer_width_ = 0;
    172   uint32_t req_mixer_height_ = 0;
    173   std::string current_color_mode_ = "hal_native";
    174   bool hdr_playback_mode_ = false;
    175   int disable_hdr_lut_gen_ = 0;
    176 };
    177 
    178 }  // namespace sdm
    179 
    180 #endif  // __DISPLAY_BASE_H__
    181