1 /*
2 * Copyright (c) 2014-2019, 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 {
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   DisplayBase(int32_t display_id, DisplayType display_type, DisplayEventHandler *event_handler,
54               HWDeviceType hw_device_type, BufferSyncHandler *buffer_sync_handler,
55               BufferAllocator *buffer_allocator, CompManager *comp_manager,
56               HWInfoInterface *hw_info_intf);
~DisplayBase()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(LayerStack *layer_stack);
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 GetConfig(DisplayConfigFixedInfo *variable_info);
67   virtual DisplayError GetActiveConfig(uint32_t *index);
68   virtual DisplayError GetVSyncState(bool *enabled);
69   virtual DisplayError SetDisplayState(DisplayState state, bool teardown,
70                                        int *release_fence);
71   virtual DisplayError SetActiveConfig(uint32_t index);
SetActiveConfig(DisplayConfigVariableInfo * variable_info)72   virtual DisplayError SetActiveConfig(DisplayConfigVariableInfo *variable_info) {
73     return kErrorNotSupported;
74   }
75   virtual DisplayError SetMaxMixerStages(uint32_t max_mixer_stages);
ControlPartialUpdate(bool enable,uint32_t * pending)76   virtual DisplayError ControlPartialUpdate(bool enable, uint32_t *pending) {
77     return kErrorNotSupported;
78   }
DisablePartialUpdateOneFrame()79   virtual DisplayError DisablePartialUpdateOneFrame() {
80     return kErrorNotSupported;
81   }
SetDisplayMode(uint32_t mode)82   virtual DisplayError SetDisplayMode(uint32_t mode) {
83     return kErrorNotSupported;
84   }
IsUnderscanSupported()85   virtual bool IsUnderscanSupported() {
86     return false;
87   }
SetPanelBrightness(int level)88   virtual DisplayError SetPanelBrightness(int level) {
89     return kErrorNotSupported;
90   }
OnMinHdcpEncryptionLevelChange(uint32_t min_enc_level)91   virtual DisplayError OnMinHdcpEncryptionLevelChange(uint32_t min_enc_level) {
92     return kErrorNotSupported;
93   }
94   virtual DisplayError ColorSVCRequestRoute(const PPDisplayAPIPayload &in_payload,
95                                             PPDisplayAPIPayload *out_payload,
96                                             PPPendingParams *pending_action);
SetDynamicDSIClock(uint64_t bit_clk_rate)97   virtual DisplayError SetDynamicDSIClock(uint64_t bit_clk_rate) {
98     return kErrorNotSupported;
99   }
GetDynamicDSIClock(uint64_t * bit_clk_rate)100   virtual DisplayError GetDynamicDSIClock(uint64_t *bit_clk_rate) {
101     return kErrorNotSupported;
102   }
GetSupportedDSIClock(std::vector<uint64_t> * bitclk_rates)103   virtual DisplayError GetSupportedDSIClock(std::vector<uint64_t> *bitclk_rates) {
104     return kErrorNotSupported;
105   }
106   virtual DisplayError GetColorModeCount(uint32_t *mode_count);
107   virtual DisplayError GetColorModes(uint32_t *mode_count, std::vector<std::string> *color_modes);
108   virtual DisplayError GetColorModeAttr(const std::string &color_mode, AttrVal *attr);
109   virtual DisplayError SetColorMode(const std::string &color_mode);
110   virtual DisplayError SetColorModeById(int32_t color_mode_id);
111   virtual DisplayError GetColorModeName(int32_t mode_id, std::string *mode_name);
112   virtual DisplayError SetColorTransform(const uint32_t length, const double *color_transform);
113   virtual DisplayError GetDefaultColorMode(std::string *color_mode);
114   virtual DisplayError SetCursorPosition(int x, int y);
115   virtual DisplayError GetRefreshRateRange(uint32_t *min_refresh_rate, uint32_t *max_refresh_rate);
GetPanelBrightness(int * level)116   virtual DisplayError GetPanelBrightness(int *level) {
117     return kErrorNotSupported;
118   }
119   virtual DisplayError SetVSyncState(bool enable);
SetIdleTimeoutMs(uint32_t active_ms)120   virtual void SetIdleTimeoutMs(uint32_t active_ms) {}
121   virtual DisplayError SetMixerResolution(uint32_t width, uint32_t height);
122   virtual DisplayError GetMixerResolution(uint32_t *width, uint32_t *height);
123   virtual DisplayError SetFrameBufferConfig(const DisplayConfigVariableInfo &variable_info);
124   virtual DisplayError GetFrameBufferConfig(DisplayConfigVariableInfo *variable_info);
125   virtual DisplayError SetDetailEnhancerData(const DisplayDetailEnhancerData &de_data);
126   virtual DisplayError GetDisplayPort(DisplayPort *port);
127   virtual DisplayError GetDisplayId(int32_t *display_id);
128   virtual DisplayError GetDisplayType(DisplayType *display_type);
129   virtual bool IsPrimaryDisplay();
130   virtual DisplayError SetCompositionState(LayerComposition composition_type, bool enable);
131   virtual DisplayError GetClientTargetSupport(uint32_t width, uint32_t height,
132                                               LayerBufferFormat format,
133                                               const ColorMetaData &color_metadata);
HandleSecureEvent(SecureEvent secure_event,LayerStack * layer_stack)134   virtual DisplayError HandleSecureEvent(SecureEvent secure_event, LayerStack *layer_stack) {
135     return kErrorNotSupported;
136   }
SetDisplayDppsAdROI(void * payload)137   virtual DisplayError SetDisplayDppsAdROI(void *payload) {
138     return kErrorNotSupported;
139   }
SetQSyncMode(QSyncMode qsync_mode)140   virtual DisplayError SetQSyncMode(QSyncMode qsync_mode) { return kErrorNotSupported; }
141   virtual std::string Dump();
142   virtual DisplayError InitializeColorModes();
ControlIdlePowerCollapse(bool enable,bool synchronous)143   virtual DisplayError ControlIdlePowerCollapse(bool enable, bool synchronous) {
144     return kErrorNotSupported;
145   }
146   virtual bool IsSupportSsppTonemap();
147   virtual DisplayError GetDisplayIdentificationData(uint8_t *out_port, uint32_t *out_data_size,
148                                                     uint8_t *out_data);
149   virtual DisplayError colorSamplingOn();
150   virtual DisplayError colorSamplingOff();
151   virtual DisplayError ReconfigureDisplay();
152 
153  protected:
154   const char *kBt2020Pq = "bt2020_pq";
155   const char *kBt2020Hlg = "bt2020_hlg";
156   DisplayError BuildLayerStackStats(LayerStack *layer_stack);
157   virtual DisplayError ValidateGPUTargetParams();
158   void CommitLayerParams(LayerStack *layer_stack);
159   void PostCommitLayerParams(LayerStack *layer_stack);
160   DisplayError ValidateScaling(uint32_t width, uint32_t height);
161   DisplayError ValidateDataspace(const ColorMetaData &color_metadata);
162   void HwRecovery(const HWRecoveryEvent sdm_event_code);
163 
164   const char *GetName(const LayerComposition &composition);
165   bool NeedsMixerReconfiguration(LayerStack *layer_stack, uint32_t *new_mixer_width,
166                                  uint32_t *new_mixer_height);
167   DisplayError ReconfigureMixer(uint32_t width, uint32_t height);
168   bool NeedsDownScale(const LayerRect &src_rect, const LayerRect &dst_rect, bool needs_rotation);
169   void DeInitializeColorModes();
170   DisplayError SetColorModeInternal(const std::string &color_mode);
171   DisplayError GetValueOfModeAttribute(const AttrVal &attr, const std::string &type,
172                                        std::string *value);
173   bool IsSupportColorModeAttribute(const std::string &color_mode);
174   void SetPUonDestScaler();
175   void ClearColorInfo();
176   void GetColorPrimaryTransferFromAttributes(const AttrVal &attr,
177       std::vector<PrimariesTransfer> *supported_pt);
178   bool DisplayPowerResetPending();
179   bool SetHdrModeAtStart(LayerStack *layer_stack);
180   PrimariesTransfer GetBlendSpaceFromColorMode();
181   bool IsHdrMode(const AttrVal &attr);
182   void InsertBT2020PqHlgModes();
183 
184   recursive_mutex recursive_mutex_;
185   int32_t display_id_ = -1;
186   DisplayType display_type_;
187   DisplayEventHandler *event_handler_ = NULL;
188   HWDeviceType hw_device_type_;
189   HWInterface *hw_intf_ = NULL;
190   HWPanelInfo hw_panel_info_;
191   HWResourceInfo hw_resource_info_ = {};
192   BufferSyncHandler *buffer_sync_handler_ = NULL;
193   BufferAllocator *buffer_allocator_ {};
194   CompManager *comp_manager_ = NULL;
195   DisplayState state_ = kStateOff;
196   bool active_ = false;
197   Handle hw_device_ = 0;
198   Handle display_comp_ctx_ = 0;
199   HWLayers hw_layers_;
200   bool needs_validate_ = true;
201   bool vsync_enable_ = false;
202   uint32_t max_mixer_stages_ = 0;
203   HWInfoInterface *hw_info_intf_ = NULL;
204   ColorManagerProxy *color_mgr_ = NULL;  // each display object owns its ColorManagerProxy
205   bool partial_update_control_ = true;
206   HWEventsInterface *hw_events_intf_ = NULL;
207   bool disable_pu_one_frame_ = false;
208   // TODO(user): Temporary changes, to be removed when DRM driver supports
209   // Partial update with Destination scaler enabled.
210   bool disable_pu_on_dest_scaler_ = false;
211   uint32_t num_color_modes_ = 0;
212   std::vector<SDEDisplayMode> color_modes_;
213   typedef std::map<std::string, SDEDisplayMode *> ColorModeMap;
214   ColorModeMap color_mode_map_ = {};
215   typedef std::map<std::string, AttrVal> ColorModeAttrMap;
216   ColorModeAttrMap color_mode_attr_map_ = {};
217   std::vector<PrimariesTransfer> color_modes_cs_ = {};  // Gamut+Gamma(color space) of color mode
218   HWDisplayAttributes display_attributes_ = {};
219   HWMixerAttributes mixer_attributes_ = {};
220   DisplayConfigVariableInfo fb_config_ = {};
221   uint32_t req_mixer_width_ = 0;
222   uint32_t req_mixer_height_ = 0;
223   std::string current_color_mode_ = "hal_native";
224   int disable_hdr_lut_gen_ = 0;
225   bool hw_recovery_logs_captured_ = false;
226   int disable_hw_recovery_dump_ = 0;
227   HWQosData default_qos_data_;
228   bool drop_hw_vsync_ = false;
229   uint32_t current_refresh_rate_ = 0;
230   bool drop_skewed_vsync_ = false;
231   bool custom_mixer_resolution_ = false;
232 
233   static Locker display_power_reset_lock_;
234   static bool display_power_reset_pending_;
235 
236  private:
237   bool StartDisplayPowerReset();
238   void EndDisplayPowerReset();
239 };
240 
241 }  // namespace sdm
242 
243 #endif  // __DISPLAY_BASE_H__
244