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 BufferAllocator *buffer_allocator, CompManager *comp_manager, 52 HWInfoInterface *hw_info_intf); 53 virtual ~DisplayBase() { } 54 virtual DisplayError Init(); 55 virtual DisplayError Deinit(); 56 DisplayError Prepare(LayerStack *layer_stack); 57 DisplayError Commit(LayerStack *layer_stack); 58 virtual DisplayError Flush(); 59 virtual DisplayError GetDisplayState(DisplayState *state); 60 virtual DisplayError GetNumVariableInfoConfigs(uint32_t *count); 61 virtual DisplayError GetConfig(uint32_t index, DisplayConfigVariableInfo *variable_info); 62 virtual DisplayError GetConfig(DisplayConfigFixedInfo *variable_info); 63 virtual DisplayError GetActiveConfig(uint32_t *index); 64 virtual DisplayError GetVSyncState(bool *enabled); 65 virtual DisplayError SetDisplayState(DisplayState state); 66 virtual DisplayError SetActiveConfig(uint32_t index); 67 virtual DisplayError SetActiveConfig(DisplayConfigVariableInfo *variable_info) { 68 return kErrorNotSupported; 69 } 70 virtual DisplayError SetMaxMixerStages(uint32_t max_mixer_stages); 71 virtual DisplayError ControlPartialUpdate(bool enable, uint32_t *pending) { 72 return kErrorNotSupported; 73 } 74 virtual DisplayError DisablePartialUpdateOneFrame() { 75 return kErrorNotSupported; 76 } 77 virtual DisplayError SetDisplayMode(uint32_t mode) { 78 return kErrorNotSupported; 79 } 80 virtual bool IsUnderscanSupported() { 81 return false; 82 } 83 virtual DisplayError SetPanelBrightness(int level) { 84 return kErrorNotSupported; 85 } 86 virtual DisplayError CachePanelBrightness(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 GetColorModeAttr(const std::string &color_mode, AttrVal *attr); 98 virtual DisplayError SetColorMode(const std::string &color_mode); 99 virtual DisplayError SetColorModeById(int32_t color_mode_id); 100 virtual DisplayError SetColorTransform(const uint32_t length, const double *color_transform); 101 virtual DisplayError GetDefaultColorMode(std::string *color_mode); 102 virtual DisplayError ApplyDefaultDisplayMode(void); 103 virtual DisplayError SetCursorPosition(int x, int y); 104 virtual DisplayError GetRefreshRateRange(uint32_t *min_refresh_rate, uint32_t *max_refresh_rate); 105 virtual DisplayError GetPanelBrightness(int *level) { 106 return kErrorNotSupported; 107 } 108 virtual DisplayError SetVSyncState(bool enable); 109 virtual void SetIdleTimeoutMs(uint32_t active_ms) {} 110 virtual DisplayError SetMixerResolution(uint32_t width, uint32_t height); 111 virtual DisplayError GetMixerResolution(uint32_t *width, uint32_t *height); 112 virtual DisplayError SetFrameBufferConfig(const DisplayConfigVariableInfo &variable_info); 113 virtual DisplayError GetFrameBufferConfig(DisplayConfigVariableInfo *variable_info); 114 virtual DisplayError SetDetailEnhancerData(const DisplayDetailEnhancerData &de_data); 115 virtual DisplayError GetDisplayPort(DisplayPort *port); 116 virtual bool IsPrimaryDisplay(); 117 virtual DisplayError SetCompositionState(LayerComposition composition_type, bool enable); 118 119 protected: 120 DisplayError BuildLayerStackStats(LayerStack *layer_stack); 121 virtual DisplayError ValidateGPUTargetParams(); 122 void CommitLayerParams(LayerStack *layer_stack); 123 void PostCommitLayerParams(LayerStack *layer_stack); 124 DisplayError HandleHDR(LayerStack *layer_stack); 125 126 // DumpImpl method 127 void AppendDump(char *buffer, uint32_t length); 128 129 const char *GetName(const LayerComposition &composition); 130 DisplayError ReconfigureDisplay(); 131 bool NeedsMixerReconfiguration(LayerStack *layer_stack, uint32_t *new_mixer_width, 132 uint32_t *new_mixer_height); 133 DisplayError ReconfigureMixer(uint32_t width, uint32_t height); 134 bool NeedsDownScale(const LayerRect &src_rect, const LayerRect &dst_rect, bool needs_rotation); 135 DisplayError InitializeColorModes(); 136 DisplayError SetColorModeInternal(const std::string &color_mode); 137 DisplayError GetValueOfModeAttribute(const AttrVal &attr, const std::string &type, 138 std::string *value); 139 DisplayError GetHdrColorMode(std::string *color_mode, bool *found_hdr); 140 bool IsSupportColorModeAttribute(const std::string &color_mode); 141 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 BufferAllocator *buffer_allocator_ {}; 150 CompManager *comp_manager_ = NULL; 151 DisplayState state_ = kStateOff; 152 bool active_ = false; 153 Handle hw_device_ = 0; 154 Handle display_comp_ctx_ = 0; 155 HWLayers hw_layers_; 156 bool pending_commit_ = false; 157 bool vsync_enable_ = false; 158 uint32_t max_mixer_stages_ = 0; 159 HWInfoInterface *hw_info_intf_ = NULL; 160 ColorManagerProxy *color_mgr_ = NULL; // each display object owns its ColorManagerProxy 161 bool partial_update_control_ = true; 162 HWEventsInterface *hw_events_intf_ = NULL; 163 bool disable_pu_one_frame_ = false; 164 uint32_t num_color_modes_ = 0; 165 std::vector<SDEDisplayMode> color_modes_; 166 typedef std::map<std::string, SDEDisplayMode *> ColorModeMap; 167 ColorModeMap color_mode_map_ = {}; 168 typedef std::map<std::string, AttrVal> ColorModeAttrMap; 169 ColorModeAttrMap color_mode_attr_map_ = {}; 170 HWDisplayAttributes display_attributes_ = {}; 171 HWMixerAttributes mixer_attributes_ = {}; 172 DisplayConfigVariableInfo fb_config_ = {}; 173 uint32_t req_mixer_width_ = 0; 174 uint32_t req_mixer_height_ = 0; 175 std::string current_color_mode_ = "hal_native"; 176 bool hdr_playback_mode_ = false; 177 int disable_hdr_lut_gen_ = 0; 178 }; 179 180 } // namespace sdm 181 182 #endif // __DISPLAY_BASE_H__ 183