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 __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 <private/color_params.h>
32 #include <map>
33 
34 namespace sdm {
35 
36 class BlitEngine;
37 
38 class HWCDisplay : public DisplayEventHandler {
39  public:
~HWCDisplay()40   virtual ~HWCDisplay() { }
41   virtual int Init();
42   virtual int Deinit();
43   virtual int Prepare(hwc_display_contents_1_t *content_list) = 0;
44   virtual int Commit(hwc_display_contents_1_t *content_list) = 0;
45   virtual int EventControl(int event, int enable);
46   virtual int SetPowerMode(int mode);
47 
48   // Framebuffer configurations
49   virtual int GetDisplayConfigs(uint32_t *configs, size_t *num_configs);
50   virtual int GetDisplayAttributes(uint32_t config, const uint32_t *attributes, int32_t *values);
51   virtual int GetActiveConfig();
52   virtual int SetActiveConfig(int index);
53 
54   virtual void SetIdleTimeoutMs(uint32_t timeout_ms);
55   virtual void SetFrameDumpConfig(uint32_t count, uint32_t bit_mask_layer_type);
56   virtual DisplayError SetMaxMixerStages(uint32_t max_mixer_stages);
57   virtual DisplayError ControlPartialUpdate(bool enable, uint32_t *pending);
58   virtual uint32_t GetLastPowerMode();
59   virtual int SetFrameBufferResolution(uint32_t x_pixels, uint32_t y_pixels);
60   virtual void GetFrameBufferResolution(uint32_t *x_pixels, uint32_t *y_pixels);
61   virtual void GetPanelResolution(uint32_t *x_pixels, uint32_t *y_pixels);
62   virtual int SetDisplayStatus(uint32_t display_status);
63   virtual int OnMinHdcpEncryptionLevelChange(uint32_t min_enc_level);
64   virtual int Perform(uint32_t operation, ...);
65   virtual int SetCursorPosition(int x, int y);
66   virtual void SetSecureDisplay(bool secure_display_active);
67 
68   // Display Configurations
69   virtual int SetActiveDisplayConfig(int config);
70   virtual int GetActiveDisplayConfig(uint32_t *config);
71   virtual int GetDisplayConfigCount(uint32_t *count);
72   virtual int GetDisplayAttributesForConfig(int config, DisplayConfigVariableInfo *attributes);
73 
74   int SetPanelBrightness(int level);
75   int GetPanelBrightness(int *level);
76   int ToggleScreenUpdates(bool enable);
77   int ColorSVCRequestRoute(const PPDisplayAPIPayload &in_payload,
78                            PPDisplayAPIPayload *out_payload,
79                            PPPendingParams *pending_action);
80   int GetVisibleDisplayRect(hwc_rect_t* rect);
81 
82  protected:
83   enum DisplayStatus {
84     kDisplayStatusOffline = 0,
85     kDisplayStatusOnline,
86     kDisplayStatusPause,
87     kDisplayStatusResume,
88   };
89 
90   // Dim layer flag set by SurfaceFlinger service.
91   static const uint32_t kDimLayer = 0x80000000;
92 
93   // Maximum number of layers supported by display manager.
94   static const uint32_t kMaxLayerCount = 32;
95 
96   // Structure to track memory allocation for layer stack (layers, rectangles) object.
97   struct LayerStackMemory {
98     static const size_t kSizeSteps = 4096;  // Default memory allocation.
99     uint8_t *raw;  // Pointer to byte array.
100     size_t size;  // Current number of allocated bytes.
101 
LayerStackMemoryLayerStackMemory102     LayerStackMemory() : raw(NULL), size(0) { }
103   };
104 
105   struct LayerCache {
106     buffer_handle_t handle;
107     uint8_t plane_alpha;
108     LayerComposition composition;
109 
LayerCacheLayerCache110     LayerCache() : handle(NULL), plane_alpha(0xff), composition(kCompositionGPU) { }
111   };
112 
113   struct LayerStackCache {
114     LayerCache layer_cache[kMaxLayerCount];
115     uint32_t layer_count;
116     bool animating;
117     bool in_use;
118 
LayerStackCacheLayerStackCache119     LayerStackCache() : layer_count(0), animating(false), in_use(false) { }
120   };
121 
122   HWCDisplay(CoreInterface *core_intf, hwc_procs_t const **hwc_procs, DisplayType type, int id,
123              bool needs_blit);
124 
125   // DisplayEventHandler methods
126   virtual DisplayError VSync(const DisplayEventVSync &vsync);
127   virtual DisplayError Refresh();
128 
129   virtual int AllocateLayerStack(hwc_display_contents_1_t *content_list);
130   virtual int PrePrepareLayerStack(hwc_display_contents_1_t *content_list);
131   virtual int PrepareLayerStack(hwc_display_contents_1_t *content_list);
132   virtual int CommitLayerStack(hwc_display_contents_1_t *content_list);
133   virtual int PostCommitLayerStack(hwc_display_contents_1_t *content_list);
134   inline void SetRect(const hwc_rect_t &source, LayerRect *target);
135   inline void SetRect(const hwc_frect_t &source, LayerRect *target);
136   inline void SetComposition(const int32_t &source, LayerComposition *target);
137   inline void SetComposition(const LayerComposition &source, int32_t *target);
138   inline void SetBlending(const int32_t &source, LayerBlending *target);
139   int SetFormat(const int32_t &source, const int flags, LayerBufferFormat *target);
140   LayerBufferFormat GetSDMFormat(const int32_t &source, const int flags);
141   const char *GetHALPixelFormatString(int format);
142   const char *GetDisplayString();
143   void ScaleDisplayFrame(hwc_rect_t *display_frame);
144   void MarkLayersForGPUBypass(hwc_display_contents_1_t *content_list);
145   uint32_t RoundToStandardFPS(uint32_t fps);
146   virtual void ApplyScanAdjustment(hwc_rect_t *display_frame);
147   DisplayError SetCSC(ColorSpace_t source, LayerCSC *target);
148   DisplayError SetIGC(IGC_t source, LayerIGC *target);
149   DisplayError SetMetaData(const private_handle_t *pvt_handle, Layer *layer);
150   bool NeedsFrameBufferRefresh(hwc_display_contents_1_t *content_list);
151   void CacheLayerStackInfo(hwc_display_contents_1_t *content_list);
152   bool IsLayerUpdating(hwc_display_contents_1_t *content_list, int layer_index);
153   bool SingleLayerUpdating(uint32_t app_layer_count);
154   uint32_t SanitizeRefreshRate(uint32_t req_refresh_rate);
155 
156   enum {
157     INPUT_LAYER_DUMP,
158     OUTPUT_LAYER_DUMP,
159   };
160 
161   CoreInterface *core_intf_;
162   hwc_procs_t const **hwc_procs_;
163   DisplayType type_;
164   int id_;
165   bool needs_blit_;
166   DisplayInterface *display_intf_ = NULL;
167   LayerStackMemory layer_stack_memory_;
168   LayerStack layer_stack_;
169   LayerStackCache layer_stack_cache_;
170   bool flush_on_error_ = false;
171   bool flush_ = false;
172   uint32_t dump_frame_count_ = 0;
173   uint32_t dump_frame_index_ = 0;
174   bool dump_input_layers_ = false;
175   uint32_t last_power_mode_;
176   bool swap_interval_zero_ = false;
177   DisplayConfigVariableInfo *framebuffer_config_ = NULL;
178   bool display_paused_ = false;
179   uint32_t min_refresh_rate_ = 0;
180   uint32_t max_refresh_rate_ = 0;
181   uint32_t current_refresh_rate_ = 0;
182   bool use_metadata_refresh_rate_ = false;
183   uint32_t metadata_refresh_rate_ = 0;
184   uint32_t force_refresh_rate_ = 0;
185   bool boot_animation_completed_ = false;
186   bool shutdown_pending_ = false;
187   bool use_blit_comp_ = false;
188   bool secure_display_active_ = false;
189   bool skip_prepare_ = false;
190   bool solid_fill_enable_ = false;
191   uint32_t solid_fill_color_ = 0;
192   LayerRect display_rect_;
193   std::map<int, LayerBufferS3DFormat> s3d_format_hwc_to_sdm_;
194 
195  private:
196   bool IsFrameBufferScaled();
197   void DumpInputBuffers(hwc_display_contents_1_t *content_list);
198   int PrepareLayerParams(hwc_layer_1_t *hwc_layer, Layer *layer);
199   void CommitLayerParams(hwc_layer_1_t *hwc_layer, Layer *layer);
200   void ResetLayerCacheStack();
201   BlitEngine *blit_engine_ = NULL;
202 };
203 
Perform(uint32_t operation,...)204 inline int HWCDisplay::Perform(uint32_t operation, ...) {
205   return 0;
206 }
207 
208 }  // namespace sdm
209 
210 #endif  // __HWC_DISPLAY_H__
211 
212