• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2014-2018, The Linux Foundation. All rights reserved.
3  * Not a Contribution.
4  *
5  * Copyright 2015 The Android Open Source Project
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  */
19 
20 #ifndef __HWC_DISPLAY_H__
21 #define __HWC_DISPLAY_H__
22 
23 #include <sys/stat.h>
24 #include <QService.h>
25 #include <core/core_interface.h>
26 #include <hardware/hwcomposer.h>
27 #include <private/color_params.h>
28 #include <qdMetaData.h>
29 #include <map>
30 #include <queue>
31 #include <set>
32 #include <string>
33 #include <utility>
34 #include <vector>
35 
36 #include "hwc_buffer_allocator.h"
37 #include "hwc_callbacks.h"
38 #include "hwc_layers.h"
39 
40 namespace sdm {
41 
42 class BlitEngine;
43 class HWCToneMapper;
44 
45 // Subclasses set this to their type. This has to be different from DisplayType.
46 // This is to avoid RTTI and dynamic_cast
47 enum DisplayClass {
48   DISPLAY_CLASS_PRIMARY,
49   DISPLAY_CLASS_EXTERNAL,
50   DISPLAY_CLASS_VIRTUAL,
51   DISPLAY_CLASS_NULL
52 };
53 
54 class HWCColorMode {
55  public:
56   explicit HWCColorMode(DisplayInterface *display_intf);
~HWCColorMode()57   ~HWCColorMode() {}
58   HWC2::Error Init();
59   HWC2::Error DeInit();
60   void Dump(std::ostringstream* os);
61   uint32_t GetColorModeCount();
62   HWC2::Error GetColorModes(uint32_t *out_num_modes, android_color_mode_t *out_modes);
63   HWC2::Error SetColorMode(android_color_mode_t mode);
64   HWC2::Error SetColorTransform(const float *matrix, android_color_transform_t hint);
65   HWC2::Error RestoreColorTransform();
66 
67  private:
68   static const uint32_t kColorTransformMatrixCount = 16;
69 
70   HWC2::Error HandleColorModeTransform(android_color_mode_t mode,
71                                        android_color_transform_t hint, const double *matrix);
72   void PopulateColorModes();
73   void PopulateTransform(const android_color_mode_t &mode,
74                          const std::string &color_mode, const std::string &color_transform);
75   template <class T>
CopyColorTransformMatrix(const T * input_matrix,double * output_matrix)76   void CopyColorTransformMatrix(const T *input_matrix, double *output_matrix) {
77     for (uint32_t i = 0; i < kColorTransformMatrixCount; i++) {
78       output_matrix[i] = static_cast<double>(input_matrix[i]);
79     }
80   }
81   HWC2::Error ApplyDefaultColorMode();
82 
83   DisplayInterface *display_intf_ = NULL;
84   android_color_mode_t current_color_mode_ = HAL_COLOR_MODE_NATIVE;
85   android_color_transform_t current_color_transform_ = HAL_COLOR_TRANSFORM_IDENTITY;
86   typedef std::map<android_color_transform_t, std::string> TransformMap;
87   std::map<android_color_mode_t, TransformMap> color_mode_transform_map_ = {};
88   double color_matrix_[kColorTransformMatrixCount] = { 1.0, 0.0, 0.0, 0.0, \
89                                                        0.0, 1.0, 0.0, 0.0, \
90                                                        0.0, 0.0, 1.0, 0.0, \
91                                                        0.0, 0.0, 0.0, 1.0 };
92 };
93 
94 class HWCDisplay : public DisplayEventHandler {
95  public:
96   enum DisplayStatus {
97     kDisplayStatusInvalid = -1,
98     kDisplayStatusOffline,
99     kDisplayStatusOnline,
100     kDisplayStatusPause,
101     kDisplayStatusResume,
102   };
103 
~HWCDisplay()104   virtual ~HWCDisplay() {}
105   virtual int Init();
106   virtual int Deinit();
107 
108   // Framebuffer configurations
109   virtual void SetIdleTimeoutMs(uint32_t timeout_ms);
110   virtual void SetFrameDumpConfig(uint32_t count, uint32_t bit_mask_layer_type);
111   virtual DisplayError SetMaxMixerStages(uint32_t max_mixer_stages);
ControlPartialUpdate(bool enable,uint32_t * pending)112   virtual DisplayError ControlPartialUpdate(bool enable, uint32_t *pending) {
113     return kErrorNotSupported;
114   }
115   virtual HWC2::PowerMode GetLastPowerMode();
116   virtual int SetFrameBufferResolution(uint32_t x_pixels, uint32_t y_pixels);
117   virtual void GetFrameBufferResolution(uint32_t *x_pixels, uint32_t *y_pixels);
118   virtual int SetDisplayStatus(DisplayStatus display_status);
119   virtual int OnMinHdcpEncryptionLevelChange(uint32_t min_enc_level);
120   virtual int Perform(uint32_t operation, ...);
121   virtual void SetSecureDisplay(bool secure_display_active);
122   virtual DisplayError SetMixerResolution(uint32_t width, uint32_t height);
123   virtual DisplayError GetMixerResolution(uint32_t *width, uint32_t *height);
124   virtual void GetPanelResolution(uint32_t *width, uint32_t *height);
125   virtual std::string Dump();
126 
127   // Captures frame output in the buffer specified by output_buffer_info. The API is
128   // non-blocking and the client is expected to check operation status later on.
129   // Returns -1 if the input is invalid.
FrameCaptureAsync(const BufferInfo & output_buffer_info,bool post_processed)130   virtual int FrameCaptureAsync(const BufferInfo &output_buffer_info, bool post_processed) {
131     return -1;
132   }
133   // Returns the status of frame capture operation requested with FrameCaptureAsync().
134   // -EAGAIN : No status obtain yet, call API again after another frame.
135   // < 0 : Operation happened but failed.
136   // 0 : Success.
GetFrameCaptureStatus()137   virtual int GetFrameCaptureStatus() { return -EAGAIN; }
138 
SetDetailEnhancerConfig(const DisplayDetailEnhancerData & de_data)139   virtual DisplayError SetDetailEnhancerConfig(const DisplayDetailEnhancerData &de_data) {
140     return kErrorNotSupported;
141   }
142 
143   // Display Configurations
144   virtual int SetActiveDisplayConfig(uint32_t config);
145   virtual int GetActiveDisplayConfig(uint32_t *config);
146   virtual int GetDisplayConfigCount(uint32_t *count);
147   virtual int GetDisplayAttributesForConfig(int config,
148                                             DisplayConfigVariableInfo *display_attributes);
SetState(bool connected)149   virtual int SetState(bool connected) {
150     return kErrorNotSupported;
151   }
152   int SetPanelBrightness(int level);
153   int GetPanelBrightness(int *level);
154   int ToggleScreenUpdates(bool enable);
155   int ColorSVCRequestRoute(const PPDisplayAPIPayload &in_payload, PPDisplayAPIPayload *out_payload,
156                            PPPendingParams *pending_action);
157   void SolidFillPrepare();
158   void SolidFillCommit();
159   DisplayClass GetDisplayClass();
160   int GetVisibleDisplayRect(hwc_rect_t *rect);
161   void BuildLayerStack(void);
162   void BuildSolidFillStack(void);
163   HWCLayer *GetHWCLayer(hwc2_layer_t layer);
ResetValidation()164   void ResetValidation() { validated_.reset(); }
GetGeometryChanges()165   uint32_t GetGeometryChanges() { return geometry_changes_; }
166 
167   // HWC2 APIs
168   virtual HWC2::Error AcceptDisplayChanges(void);
169   virtual HWC2::Error GetActiveConfig(hwc2_config_t *out_config);
170   virtual HWC2::Error SetActiveConfig(hwc2_config_t config);
171   virtual HWC2::Error SetClientTarget(buffer_handle_t target, int32_t acquire_fence,
172                                       int32_t dataspace, hwc_region_t damage);
SetColorMode(android_color_mode_t mode)173   virtual HWC2::Error SetColorMode(android_color_mode_t mode) {
174     return HWC2::Error::Unsupported;
175   }
RestoreColorTransform()176   virtual HWC2::Error RestoreColorTransform() {
177     return HWC2::Error::Unsupported;
178   }
SetColorTransform(const float * matrix,android_color_transform_t hint)179   virtual HWC2::Error SetColorTransform(const float *matrix, android_color_transform_t hint) {
180     return HWC2::Error::Unsupported;
181   }
HandleColorModeTransform(android_color_mode_t mode,android_color_transform_t hint,const double * matrix)182   virtual HWC2::Error HandleColorModeTransform(android_color_mode_t mode,
183                                                android_color_transform_t hint,
184                                                const double *matrix) {
185     return HWC2::Error::Unsupported;
186   }
187   virtual HWC2::Error GetDisplayConfigs(uint32_t *out_num_configs, hwc2_config_t *out_configs);
188   virtual HWC2::Error GetDisplayAttribute(hwc2_config_t config, HWC2::Attribute attribute,
189                                           int32_t *out_value);
190   virtual HWC2::Error GetClientTargetSupport(uint32_t width, uint32_t height, int32_t format,
191                                              int32_t dataspace);
192   virtual HWC2::Error GetColorModes(uint32_t *outNumModes, android_color_mode_t *outModes);
193   virtual HWC2::Error GetChangedCompositionTypes(uint32_t *out_num_elements,
194                                                  hwc2_layer_t *out_layers, int32_t *out_types);
195   virtual HWC2::Error GetDisplayRequests(int32_t *out_display_requests, uint32_t *out_num_elements,
196                                          hwc2_layer_t *out_layers, int32_t *out_layer_requests);
197   virtual HWC2::Error GetDisplayName(uint32_t *out_size, char *out_name);
198   virtual HWC2::Error GetDisplayType(int32_t *out_type);
199   virtual HWC2::Error SetCursorPosition(hwc2_layer_t layer, int x, int y);
200   virtual HWC2::Error SetVsyncEnabled(HWC2::Vsync enabled);
201   virtual HWC2::Error SetPowerMode(HWC2::PowerMode mode);
202   virtual HWC2::Error CreateLayer(hwc2_layer_t *out_layer_id);
203   virtual HWC2::Error DestroyLayer(hwc2_layer_t layer_id);
204   virtual HWC2::Error SetLayerZOrder(hwc2_layer_t layer_id, uint32_t z);
205   virtual HWC2::Error Validate(uint32_t *out_num_types, uint32_t *out_num_requests) = 0;
206   virtual HWC2::Error GetReleaseFences(uint32_t *out_num_elements, hwc2_layer_t *out_layers,
207                                        int32_t *out_fences);
208   virtual HWC2::Error Present(int32_t *out_retire_fence) = 0;
209   virtual HWC2::Error GetHdrCapabilities(uint32_t *out_num_types, int32_t* out_types,
210                                          float* out_max_luminance,
211                                          float* out_max_average_luminance,
212                                          float* out_min_luminance);
SetDisplayAnimating(bool animating)213   virtual HWC2::Error SetDisplayAnimating(bool animating) {
214     animating_ = animating;
215     validated_ = false;
216     return HWC2::Error::None;
217   }
218 
219  protected:
220   // Maximum number of layers supported by display manager.
221   static const uint32_t kMaxLayerCount = 32;
222 
223   HWCDisplay(CoreInterface *core_intf, HWCCallbacks *callbacks, DisplayType type, hwc2_display_t id,
224              bool needs_blit, qService::QService *qservice, DisplayClass display_class,
225              BufferAllocator *buffer_allocator);
226 
227   // DisplayEventHandler methods
228   virtual DisplayError VSync(const DisplayEventVSync &vsync);
229   virtual DisplayError Refresh();
230   virtual DisplayError CECMessage(char *message);
231   virtual DisplayError HandleEvent(DisplayEvent event);
232   virtual void DumpOutputBuffer(const BufferInfo &buffer_info, void *base, int fence);
233   virtual HWC2::Error PrepareLayerStack(uint32_t *out_num_types, uint32_t *out_num_requests);
234   virtual HWC2::Error CommitLayerStack(void);
235   virtual HWC2::Error PostCommitLayerStack(int32_t *out_retire_fence);
DisablePartialUpdateOneFrame()236   virtual DisplayError DisablePartialUpdateOneFrame() {
237     return kErrorNotSupported;
238   }
239   LayerBufferFormat GetSDMFormat(const int32_t &source, const int flags);
240   const char *GetDisplayString();
241   void MarkLayersForGPUBypass(void);
242   void MarkLayersForClientComposition(void);
243   virtual void ApplyScanAdjustment(hwc_rect_t *display_frame);
244   uint32_t GetUpdatingLayersCount(void);
245   bool IsSurfaceUpdated(const std::vector<LayerRect> &dirty_regions);
246   bool IsLayerUpdating(const Layer *layer);
247   uint32_t SanitizeRefreshRate(uint32_t req_refresh_rate);
248   virtual void CloseAcquireFds();
GetUnderScanConfig()249   virtual void GetUnderScanConfig() { }
250 
251   enum {
252     INPUT_LAYER_DUMP,
253     OUTPUT_LAYER_DUMP,
254   };
255 
256   static std::bitset<kDisplayMax> validated_;
257   bool layer_stack_invalid_ = true;
258   CoreInterface *core_intf_ = nullptr;
259   HWCCallbacks *callbacks_  = nullptr;
260   HWCBufferAllocator *buffer_allocator_ = NULL;
261   DisplayType type_;
262   hwc2_display_t id_;
263   bool needs_blit_ = false;
264   DisplayInterface *display_intf_ = NULL;
265   LayerStack layer_stack_;
266   HWCLayer *client_target_ = nullptr;                   // Also known as framebuffer target
267   std::map<hwc2_layer_t, HWCLayer *> layer_map_;        // Look up by Id - TODO
268   std::multiset<HWCLayer *, SortLayersByZ> layer_set_;  // Maintain a set sorted by Z
269   std::map<hwc2_layer_t, HWC2::Composition> layer_changes_;
270   std::map<hwc2_layer_t, HWC2::LayerRequest> layer_requests_;
271   bool flush_on_error_ = false;
272   bool flush_ = false;
273   uint32_t dump_frame_count_ = 0;
274   uint32_t dump_frame_index_ = 0;
275   bool dump_input_layers_ = false;
276   HWC2::PowerMode last_power_mode_;
277   bool swap_interval_zero_ = false;
278   bool display_paused_ = false;
279   uint32_t min_refresh_rate_ = 0;
280   uint32_t max_refresh_rate_ = 0;
281   uint32_t current_refresh_rate_ = 0;
282   bool use_metadata_refresh_rate_ = false;
283   uint32_t metadata_refresh_rate_ = 0;
284   uint32_t force_refresh_rate_ = 0;
285   bool boot_animation_completed_ = false;
286   bool shutdown_pending_ = false;
287   bool use_blit_comp_ = false;
288   bool secure_display_active_ = false;
289   bool skip_prepare_ = false;
290   bool solid_fill_enable_ = false;
291   Layer *solid_fill_layer_ = NULL;
292   LayerRect solid_fill_rect_ = {};
293   uint32_t solid_fill_color_ = 0;
294   LayerRect display_rect_;
295   bool color_tranform_failed_ = false;
296   HWCColorMode *color_mode_ = NULL;
297   HWCToneMapper *tone_mapper_ = nullptr;
298   uint32_t num_configs_ = 0;
299   int disable_hdr_handling_ = 0;  // disables HDR handling.
300 
301  private:
302   void DumpInputBuffers(void);
303   bool CanSkipValidate();
304   qService::QService *qservice_ = NULL;
305   DisplayClass display_class_;
306   uint32_t geometry_changes_ = GeometryChanges::kNone;
307   bool skip_validate_ = false;
308   bool animating_ = false;
309 };
310 
Perform(uint32_t operation,...)311 inline int HWCDisplay::Perform(uint32_t operation, ...) {
312   return 0;
313 }
314 
315 }  // namespace sdm
316 
317 #endif  // __HWC_DISPLAY_H__
318