1/* 2* Copyright (c) 2014-2016, 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/rotator_interface.h> 31#include <private/color_interface.h> 32 33#include <map> 34#include <mutex> 35#include <string> 36#include <vector> 37 38#include "hw_interface.h" 39#include "comp_manager.h" 40#include "color_manager.h" 41#include "hw_events_interface.h" 42 43namespace sdm { 44 45using std::recursive_mutex; 46using std::lock_guard; 47 48class RotatorCtrl; 49class HWInfoInterface; 50 51class DisplayBase : public DisplayInterface, DumpImpl { 52 public: 53 DisplayBase(DisplayType display_type, DisplayEventHandler *event_handler, 54 HWDeviceType hw_device_type, BufferSyncHandler *buffer_sync_handler, 55 CompManager *comp_manager, RotatorInterface *rotator_intf, 56 HWInfoInterface *hw_info_intf); 57 virtual ~DisplayBase() { } 58 virtual DisplayError Init(); 59 virtual DisplayError Deinit(); 60 DisplayError Prepare(LayerStack *layer_stack); 61 DisplayError Commit(LayerStack *layer_stack); 62 virtual DisplayError Flush(); 63 virtual DisplayError GetDisplayState(DisplayState *state); 64 virtual DisplayError GetNumVariableInfoConfigs(uint32_t *count); 65 virtual DisplayError GetConfig(uint32_t index, DisplayConfigVariableInfo *variable_info); 66 virtual DisplayError GetActiveConfig(uint32_t *index); 67 virtual DisplayError GetVSyncState(bool *enabled); 68 virtual DisplayError SetDisplayState(DisplayState state); 69 virtual DisplayError SetActiveConfig(uint32_t index); 70 virtual DisplayError SetActiveConfig(DisplayConfigVariableInfo *variable_info) { 71 return kErrorNotSupported; 72 } 73 virtual DisplayError SetMaxMixerStages(uint32_t max_mixer_stages); 74 virtual DisplayError ControlPartialUpdate(bool enable, uint32_t *pending) { 75 return kErrorNotSupported; 76 } 77 virtual DisplayError DisablePartialUpdateOneFrame() { 78 return kErrorNotSupported; 79 } 80 virtual DisplayError SetDisplayMode(uint32_t mode) { 81 return kErrorNotSupported; 82 } 83 virtual bool IsUnderscanSupported() { 84 return false; 85 } 86 virtual DisplayError SetPanelBrightness(int level) { 87 return kErrorNotSupported; 88 } 89 virtual DisplayError OnMinHdcpEncryptionLevelChange(uint32_t min_enc_level) { 90 return kErrorNotSupported; 91 } 92 virtual DisplayError ColorSVCRequestRoute(const PPDisplayAPIPayload &in_payload, 93 PPDisplayAPIPayload *out_payload, 94 PPPendingParams *pending_action); 95 virtual DisplayError GetColorModeCount(uint32_t *mode_count); 96 virtual DisplayError GetColorModes(uint32_t *mode_count, std::vector<std::string> *color_modes); 97 virtual DisplayError SetColorMode(const std::string &color_mode); 98 virtual DisplayError SetColorTransform(const uint32_t length, const double *color_transform); 99 virtual DisplayError ApplyDefaultDisplayMode(void); 100 virtual DisplayError SetCursorPosition(int x, int y); 101 virtual DisplayError GetRefreshRateRange(uint32_t *min_refresh_rate, uint32_t *max_refresh_rate); 102 virtual DisplayError GetPanelBrightness(int *level) { 103 return kErrorNotSupported; 104 } 105 virtual DisplayError SetVSyncState(bool enable); 106 virtual void SetIdleTimeoutMs(uint32_t timeout_ms) {} 107 virtual DisplayError SetMixerResolution(uint32_t width, uint32_t height); 108 virtual DisplayError GetMixerResolution(uint32_t *width, uint32_t *height); 109 virtual DisplayError SetFrameBufferConfig(const DisplayConfigVariableInfo &variable_info); 110 virtual DisplayError GetFrameBufferConfig(DisplayConfigVariableInfo *variable_info); 111 virtual DisplayError SetDetailEnhancerData(const DisplayDetailEnhancerData &de_data); 112 113 protected: 114 // DumpImpl method 115 void AppendDump(char *buffer, uint32_t length); 116 117 bool IsRotationRequired(HWLayers *hw_layers); 118 const char *GetName(const LayerComposition &composition); 119 DisplayError ValidateGPUTarget(LayerStack *layer_stack); 120 DisplayError ReconfigureDisplay(); 121 bool NeedsMixerReconfiguration(LayerStack *layer_stack, uint32_t *new_mixer_width, 122 uint32_t *new_mixer_height); 123 DisplayError ReconfigureMixer(uint32_t width, uint32_t height); 124 void AllDisplaysNeedValidate(); 125 126 static std::bitset<kDisplayMax> registered_displays_; 127 static std::bitset<kDisplayMax> needs_validate_; 128 recursive_mutex recursive_mutex_; 129 DisplayType display_type_; 130 DisplayEventHandler *event_handler_ = NULL; 131 HWDeviceType hw_device_type_; 132 HWInterface *hw_intf_ = NULL; 133 HWPanelInfo hw_panel_info_; 134 BufferSyncHandler *buffer_sync_handler_ = NULL; 135 CompManager *comp_manager_ = NULL; 136 RotatorInterface *rotator_intf_ = NULL; 137 DisplayState state_ = kStateOff; 138 bool active_ = false; 139 Handle hw_device_ = 0; 140 Handle display_comp_ctx_ = 0; 141 Handle display_rotator_ctx_ = 0; 142 HWLayers hw_layers_; 143 bool pending_commit_ = false; 144 bool vsync_enable_ = false; 145 uint32_t max_mixer_stages_ = 0; 146 HWInfoInterface *hw_info_intf_ = NULL; 147 ColorManagerProxy *color_mgr_ = NULL; // each display object owns its ColorManagerProxy 148 bool partial_update_control_ = true; 149 HWEventsInterface *hw_events_intf_ = NULL; 150 bool disable_pu_one_frame_ = false; 151 uint32_t num_color_modes_ = 0; 152 std::vector<SDEDisplayMode> color_modes_; 153 typedef std::map<std::string, SDEDisplayMode *> ColorModeMap; 154 ColorModeMap color_mode_map_ = {}; 155 HWDisplayAttributes display_attributes_ = {}; 156 HWMixerAttributes mixer_attributes_ = {}; 157 DisplayConfigVariableInfo fb_config_ = {}; 158 159 private: 160 // Unused 161 virtual DisplayError GetConfig(DisplayConfigFixedInfo *variable_info) { 162 return kErrorNone; 163 } 164}; 165 166} // namespace sdm 167 168#endif // __DISPLAY_BASE_H__ 169