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
42namespace sdm {
43
44using std::recursive_mutex;
45using std::lock_guard;
46
47class 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 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  recursive_mutex recursive_mutex_;
142  DisplayType display_type_;
143  DisplayEventHandler *event_handler_ = NULL;
144  HWDeviceType hw_device_type_;
145  HWInterface *hw_intf_ = NULL;
146  HWPanelInfo hw_panel_info_;
147  BufferSyncHandler *buffer_sync_handler_ = NULL;
148  BufferAllocator *buffer_allocator_ {};
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 needs_validate_ = true;
156  bool vsync_enable_ = false;
157  uint32_t max_mixer_stages_ = 0;
158  HWInfoInterface *hw_info_intf_ = NULL;
159  ColorManagerProxy *color_mgr_ = NULL;  // each display object owns its ColorManagerProxy
160  bool partial_update_control_ = true;
161  HWEventsInterface *hw_events_intf_ = NULL;
162  bool disable_pu_one_frame_ = false;
163  uint32_t num_color_modes_ = 0;
164  std::vector<SDEDisplayMode> color_modes_;
165  typedef std::map<std::string, SDEDisplayMode *> ColorModeMap;
166  ColorModeMap color_mode_map_ = {};
167  typedef std::map<std::string, AttrVal> ColorModeAttrMap;
168  ColorModeAttrMap color_mode_attr_map_ = {};
169  HWDisplayAttributes display_attributes_ = {};
170  HWMixerAttributes mixer_attributes_ = {};
171  DisplayConfigVariableInfo fb_config_ = {};
172  uint32_t req_mixer_width_ = 0;
173  uint32_t req_mixer_height_ = 0;
174  std::string current_color_mode_ = "hal_native";
175  bool hdr_playback_mode_ = false;
176  int disable_hdr_lut_gen_ = 0;
177};
178
179}  // namespace sdm
180
181#endif  // __DISPLAY_BASE_H__
182