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 __HWC_DISPLAY_H__
26 #define __HWC_DISPLAY_H__
27 
28 #include <hardware/hwcomposer.h>
29 #include <core/core_interface.h>
30 #include <qdMetaData.h>
31 #include <QService.h>
32 #include <private/color_params.h>
33 #include <map>
34 #include <vector>
35 #include <string>
36 
37 namespace sdm {
38 
39 class BlitEngine;
40 class HWCToneMapper;
41 
42 // Subclasses set this to their type. This has to be different from DisplayType.
43 // This is to avoid RTTI and dynamic_cast
44 enum DisplayClass {
45   DISPLAY_CLASS_PRIMARY,
46   DISPLAY_CLASS_EXTERNAL,
47   DISPLAY_CLASS_VIRTUAL,
48   DISPLAY_CLASS_NULL
49 };
50 
51 class HWCColorMode {
52  public:
HWCColorMode(DisplayInterface * display_intf)53   explicit HWCColorMode(DisplayInterface *display_intf) : display_intf_(display_intf) {}
~HWCColorMode()54   ~HWCColorMode() {}
55   void Init();
DeInit()56   void DeInit() {}
57   int SetColorMode(const std::string &color_mode);
58   const std::vector<std::string> &GetColorModes();
59   int SetColorTransform(uint32_t matrix_count, const float *matrix);
60 
61  private:
62   static const uint32_t kColorTransformMatrixCount = 16;
63   template <class T>
CopyColorTransformMatrix(const T * input_matrix,double * output_matrix)64   void CopyColorTransformMatrix(const T *input_matrix, double *output_matrix) {
65     for (uint32_t i = 0; i < kColorTransformMatrixCount; i++) {
66       output_matrix[i] = static_cast<double>(input_matrix[i]);
67     }
68   }
69   int PopulateColorModes();
70   DisplayInterface *display_intf_ = NULL;
71   std::vector<std::string> color_modes_ = {};
72   std::string current_color_mode_ = {};
73 };
74 
75 class HWCDisplay : public DisplayEventHandler {
76  public:
77   enum {
78     SET_METADATA_DYN_REFRESH_RATE,
79     SET_BINDER_DYN_REFRESH_RATE,
80     SET_DISPLAY_MODE,
81     SET_QDCM_SOLID_FILL_INFO,
82     UNSET_QDCM_SOLID_FILL_INFO,
83   };
84 
~HWCDisplay()85   virtual ~HWCDisplay() { }
86   virtual int Init();
87   virtual int Deinit();
88   virtual int Prepare(hwc_display_contents_1_t *content_list) = 0;
89   virtual int Commit(hwc_display_contents_1_t *content_list) = 0;
90   virtual int EventControl(int event, int enable);
91   virtual int SetPowerMode(int mode);
92 
93   // Framebuffer configurations
94   virtual int GetDisplayConfigs(uint32_t *configs, size_t *num_configs);
95   virtual int GetDisplayAttributes(uint32_t config, const uint32_t *display_attributes,
96                                    int32_t *values);
97   virtual int GetActiveConfig();
98   virtual int SetActiveConfig(int index);
99 
100   virtual void SetIdleTimeoutMs(uint32_t timeout_ms);
101   virtual void SetFrameDumpConfig(uint32_t count, uint32_t bit_mask_layer_type);
102   virtual DisplayError SetMaxMixerStages(uint32_t max_mixer_stages);
ControlPartialUpdate(bool enable,uint32_t * pending)103   virtual DisplayError ControlPartialUpdate(bool enable, uint32_t *pending) {
104     return kErrorNotSupported;
105   }
106   virtual uint32_t GetLastPowerMode();
107   virtual int SetFrameBufferResolution(uint32_t x_pixels, uint32_t y_pixels);
108   virtual void GetFrameBufferResolution(uint32_t *x_pixels, uint32_t *y_pixels);
109   virtual int SetDisplayStatus(uint32_t display_status);
110   virtual int OnMinHdcpEncryptionLevelChange(uint32_t min_enc_level);
111   virtual int Perform(uint32_t operation, ...);
112   virtual int SetCursorPosition(int x, int y);
113   virtual void SetSecureDisplay(bool secure_display_active, bool force_flush);
114   virtual DisplayError SetMixerResolution(uint32_t width, uint32_t height);
115   virtual DisplayError GetMixerResolution(uint32_t *width, uint32_t *height);
116   virtual void GetPanelResolution(uint32_t *width, uint32_t *height);
117 
118   // Captures frame output in the buffer specified by output_buffer_info. The API is
119   // non-blocking and the client is expected to check operation status later on.
120   // Returns -1 if the input is invalid.
FrameCaptureAsync(const BufferInfo & output_buffer_info,bool post_processed)121   virtual int FrameCaptureAsync(const BufferInfo& output_buffer_info, bool post_processed) {
122     return -1;
123   }
124   // Returns the status of frame capture operation requested with FrameCaptureAsync().
125   // -EAGAIN : No status obtain yet, call API again after another frame.
126   // < 0 : Operation happened but failed.
127   // 0 : Success.
GetFrameCaptureStatus()128   virtual int GetFrameCaptureStatus() { return -EAGAIN; }
129 
SetDetailEnhancerConfig(const DisplayDetailEnhancerData & de_data)130   virtual DisplayError SetDetailEnhancerConfig(const DisplayDetailEnhancerData &de_data) {
131     return kErrorNotSupported;
132   }
133 
134   // Display Configurations
135   virtual int SetActiveDisplayConfig(int config);
136   virtual int GetActiveDisplayConfig(uint32_t *config);
137   virtual int GetDisplayConfigCount(uint32_t *count);
138   virtual int GetDisplayAttributesForConfig(int config,
139                                             DisplayConfigVariableInfo *display_attributes);
140   virtual int GetDisplayFixedConfig(DisplayConfigFixedInfo *fixed_info);
141 
142   int SetPanelBrightness(int level);
143   int GetPanelBrightness(int *level);
144   int ToggleScreenUpdates(bool enable);
145   int ColorSVCRequestRoute(const PPDisplayAPIPayload &in_payload,
146                            PPDisplayAPIPayload *out_payload,
147                            PPPendingParams *pending_action);
148   int GetVisibleDisplayRect(hwc_rect_t* rect);
149   DisplayClass GetDisplayClass();
150   int GetDisplayPort(DisplayPort *port);
151 
152  protected:
153   enum DisplayStatus {
154     kDisplayStatusOffline = 0,
155     kDisplayStatusOnline,
156     kDisplayStatusPause,
157     kDisplayStatusResume,
158   };
159 
160   // Dim layer flag set by SurfaceFlinger service.
161   static const uint32_t kDimLayer = 0x80000000;
162 
163   // Maximum number of layers supported by display manager.
164   static const uint32_t kMaxLayerCount = 32;
165 
166   HWCDisplay(CoreInterface *core_intf, hwc_procs_t const **hwc_procs, DisplayType type, int id,
167              bool needs_blit, qService::QService *qservice, DisplayClass display_class);
168 
169   // DisplayEventHandler methods
170   virtual DisplayError VSync(const DisplayEventVSync &vsync);
171   virtual DisplayError Refresh();
172   virtual DisplayError CECMessage(char *message);
173 
174   int AllocateLayerStack(hwc_display_contents_1_t *content_list);
175   void FreeLayerStack();
176   virtual int PrePrepareLayerStack(hwc_display_contents_1_t *content_list);
177   virtual int PrepareLayerStack(hwc_display_contents_1_t *content_list);
178   virtual int CommitLayerStack(hwc_display_contents_1_t *content_list);
179   virtual int PostCommitLayerStack(hwc_display_contents_1_t *content_list);
180   virtual void DumpOutputBuffer(const BufferInfo& buffer_info, void *base, int fence);
181   virtual uint32_t RoundToStandardFPS(float fps);
182   virtual uint32_t SanitizeRefreshRate(uint32_t req_refresh_rate);
183   virtual void PrepareDynamicRefreshRate(Layer *layer);
DisablePartialUpdateOneFrame()184   virtual DisplayError DisablePartialUpdateOneFrame() {
185     return kErrorNotSupported;
186   }
187   inline void SetRect(const hwc_rect_t &source, LayerRect *target);
188   inline void SetRect(const hwc_frect_t &source, LayerRect *target);
189   inline void SetComposition(const int32_t &source, LayerComposition *target);
190   inline void SetComposition(const LayerComposition &source, int32_t *target);
191   inline void SetBlending(const int32_t &source, LayerBlending *target);
192   int SetFormat(const int32_t &source, const int flags, LayerBufferFormat *target);
193   void SetLayerS3DMode(const LayerBufferS3DFormat &source, uint32_t *target);
194   LayerBufferFormat GetSDMFormat(const int32_t &source, const int flags);
195   const char *GetDisplayString();
196   void MarkLayersForGPUBypass(hwc_display_contents_1_t *content_list);
197   virtual void ApplyScanAdjustment(hwc_rect_t *display_frame);
198   DisplayError SetCSC(const MetaData_t *meta_data, ColorMetaData *color_metadata);
199   DisplayError SetIGC(IGC_t source, LayerIGC *target);
200   DisplayError SetMetaData(const private_handle_t *pvt_handle, Layer *layer);
201   bool NeedsFrameBufferRefresh(hwc_display_contents_1_t *content_list);
202   bool IsLayerUpdating(hwc_display_contents_1_t *content_list, const Layer *layer);
203   bool IsNonIntegralSourceCrop(const hwc_frect_t &source);
204   uint32_t GetUpdatingLayersCount(uint32_t app_layer_count);
205   bool SingleVideoLayerUpdating(uint32_t app_layer_count);
206   bool IsSurfaceUpdated(const std::vector<LayerRect> &dirty_regions);
207 
208   enum {
209     INPUT_LAYER_DUMP,
210     OUTPUT_LAYER_DUMP,
211   };
212 
213   CoreInterface *core_intf_;
214   hwc_procs_t const **hwc_procs_;
215   DisplayType type_;
216   int id_;
217   bool needs_blit_ = false;
218   DisplayInterface *display_intf_ = NULL;
219   LayerStack layer_stack_;
220   bool flush_on_error_ = false;
221   bool flush_ = false;
222   uint32_t dump_frame_count_ = 0;
223   uint32_t dump_frame_index_ = 0;
224   bool dump_input_layers_ = false;
225   uint32_t last_power_mode_;
226   bool swap_interval_zero_ = false;
227   bool display_paused_ = false;
228   uint32_t min_refresh_rate_ = 0;
229   uint32_t max_refresh_rate_ = 0;
230   uint32_t current_refresh_rate_ = 0;
231   bool use_metadata_refresh_rate_ = false;
232   uint32_t metadata_refresh_rate_ = 0;
233   uint32_t force_refresh_rate_ = 0;
234   bool boot_animation_completed_ = false;
235   bool shutdown_pending_ = false;
236   bool use_blit_comp_ = false;
237   bool secure_display_active_ = false;
238   uint32_t skip_prepare_cnt = 0;
239   bool solid_fill_enable_ = false;
240   bool disable_animation_ = false;
241   uint32_t solid_fill_color_ = 0;
242   LayerRect display_rect_;
243   std::map<int, LayerBufferS3DFormat> s3d_format_hwc_to_sdm_;
244   bool animating_ = false;
245   HWCToneMapper *tone_mapper_ = NULL;
246   HWCColorMode *color_mode_ = NULL;
247   int disable_hdr_handling_ = 0;  // disables HDR handling.
248 
249  private:
250   void DumpInputBuffers(hwc_display_contents_1_t *content_list);
251   int PrepareLayerParams(hwc_layer_1_t *hwc_layer, Layer *layer);
252   void CommitLayerParams(hwc_layer_1_t *hwc_layer, Layer *layer);
253   BlitEngine *blit_engine_ = NULL;
254   qService::QService *qservice_ = NULL;
255   DisplayClass display_class_;
256 };
257 
Perform(uint32_t operation,...)258 inline int HWCDisplay::Perform(uint32_t operation, ...) {
259   return 0;
260 }
261 
262 }  // namespace sdm
263 
264 #endif  // __HWC_DISPLAY_H__
265 
266