1 /*
2  * Copyright (c) 2014-2020, 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 <QService.h>
24 #include <android/hardware/graphics/common/1.1/types.h>
25 #include <core/core_interface.h>
26 #include <hardware/hwcomposer.h>
27 #include <private/color_params.h>
28 #include <qdMetaData.h>
29 #include <sys/stat.h>
30 #include <map>
31 #include <queue>
32 #include <set>
33 #include <string>
34 #include <utility>
35 #include <vector>
36 #include <bitset>
37 #include <algorithm>
38 #include "hwc_buffer_allocator.h"
39 #include "hwc_callbacks.h"
40 #include "hwc_layers.h"
41 #include "display_null.h"
42 #include "hwc_display_event_handler.h"
43 #include "histogram_collector.h"
44 
45 using android::hardware::graphics::common::V1_1::ColorMode;
46 using android::hardware::graphics::common::V1_1::Dataspace;
47 using android::hardware::graphics::common::V1_1::RenderIntent;
48 
49 namespace sdm {
50 
51 class BlitEngine;
52 class HWCToneMapper;
53 
54 // Subclasses set this to their type. This has to be different from DisplayType.
55 // This is to avoid RTTI and dynamic_cast
56 enum DisplayClass {
57   DISPLAY_CLASS_BUILTIN,
58   DISPLAY_CLASS_PLUGGABLE,
59   DISPLAY_CLASS_VIRTUAL,
60   DISPLAY_CLASS_NULL
61 };
62 
63 enum SecureSessionType {
64   kSecureDisplay,
65   kSecureCamera,
66   kSecureMax,
67 };
68 
69 struct TransientRefreshRateInfo {
70   uint32_t transient_vsync_period;
71   int64_t vsync_applied_time;
72 };
73 
74 class HWCColorMode {
75  public:
76   explicit HWCColorMode(DisplayInterface *display_intf);
~HWCColorMode()77   ~HWCColorMode() {}
78   HWC2::Error Init();
79   HWC2::Error DeInit();
80   void Dump(std::ostringstream* os);
81   uint32_t GetColorModeCount();
82   uint32_t GetRenderIntentCount(ColorMode mode);
83   HWC2::Error GetColorModes(uint32_t *out_num_modes, ColorMode *out_modes);
84   HWC2::Error GetRenderIntents(ColorMode mode, uint32_t *out_num_intents, RenderIntent *out_modes);
85   HWC2::Error SetColorModeWithRenderIntent(ColorMode mode, RenderIntent intent);
86   HWC2::Error SetColorModeById(int32_t color_mode_id);
87   HWC2::Error SetColorModeFromClientApi(std::string mode_string);
88   HWC2::Error SetColorTransform(const float *matrix, android_color_transform_t hint);
89   HWC2::Error RestoreColorTransform();
GetCurrentColorMode()90   ColorMode GetCurrentColorMode() { return current_color_mode_; }
91   HWC2::Error ApplyCurrentColorModeWithRenderIntent(bool hdr_present);
92   HWC2::Error CacheColorModeWithRenderIntent(ColorMode mode, RenderIntent intent);
GetCurrentRenderIntent()93   RenderIntent GetCurrentRenderIntent() { return current_render_intent_; }
94 
95  private:
96   static const uint32_t kColorTransformMatrixCount = 16;
97   void PopulateColorModes();
98   template <class T>
CopyColorTransformMatrix(const T * input_matrix,double * output_matrix)99   void CopyColorTransformMatrix(const T *input_matrix, double *output_matrix) {
100     for (uint32_t i = 0; i < kColorTransformMatrixCount; i++) {
101       output_matrix[i] = static_cast<double>(input_matrix[i]);
102     }
103   }
104   HWC2::Error ValidateColorModeWithRenderIntent(ColorMode mode, RenderIntent intent);
105   HWC2::Error SetPreferredColorModeInternal(const std::string &mode_string, bool from_client,
106     ColorMode *color_mode, DynamicRangeType *dynamic_range);
107 
108   DisplayInterface *display_intf_ = NULL;
109   bool apply_mode_ = false;
110   ColorMode current_color_mode_ = ColorMode::NATIVE;
111   RenderIntent current_render_intent_ = RenderIntent::COLORIMETRIC;
112   DynamicRangeType curr_dynamic_range_ = kSdrType;
113   typedef std::map<DynamicRangeType, std::string> DynamicRangeMap;
114   typedef std::map<RenderIntent, DynamicRangeMap> RenderIntentMap;
115   // Initialize supported mode/render intent/dynamic range combination
116   std::map<ColorMode, RenderIntentMap> color_mode_map_ = {};
117   double color_matrix_[kColorTransformMatrixCount] = { 1.0, 0.0, 0.0, 0.0, \
118                                                        0.0, 1.0, 0.0, 0.0, \
119                                                        0.0, 0.0, 1.0, 0.0, \
120                                                        0.0, 0.0, 0.0, 1.0 };
121   std::map<ColorMode, DynamicRangeMap> preferred_mode_ = {};
122 };
123 
124 class HWCDisplay : public DisplayEventHandler {
125  public:
126   enum DisplayStatus {
127     kDisplayStatusInvalid = -1,
128     kDisplayStatusOffline,
129     kDisplayStatusOnline,
130     kDisplayStatusPause,
131     kDisplayStatusResume,
132   };
133 
134   enum DisplayValidateState {
135     kNormalValidate,
136     kInternalValidate,
137     kSkipValidate,
138   };
139 
140   struct HWCLayerStack {
141     HWCLayer *client_target = nullptr;                   // Also known as framebuffer target
142     std::map<hwc2_layer_t, HWCLayer *> layer_map;        // Look up by Id - TODO
143     std::multiset<HWCLayer *, SortLayersByZ> layer_set;  // Maintain a set sorted by Z
144   };
145 
~HWCDisplay()146   virtual ~HWCDisplay() {}
147   virtual int Init();
148   virtual int Deinit();
149 
150   // Framebuffer configurations
151   virtual void SetIdleTimeoutMs(uint32_t timeout_ms);
152   virtual HWC2::Error SetFrameDumpConfig(uint32_t count, uint32_t bit_mask_layer_type,
153                                          int32_t format, bool post_processed);
154   virtual DisplayError SetMaxMixerStages(uint32_t max_mixer_stages);
ControlPartialUpdate(bool enable,uint32_t * pending)155   virtual DisplayError ControlPartialUpdate(bool enable, uint32_t *pending) {
156     return kErrorNotSupported;
157   }
158   virtual HWC2::PowerMode GetCurrentPowerMode();
159   virtual int SetFrameBufferResolution(uint32_t x_pixels, uint32_t y_pixels);
160   virtual void GetFrameBufferResolution(uint32_t *x_pixels, uint32_t *y_pixels);
161   virtual int SetDisplayStatus(DisplayStatus display_status);
162   virtual int OnMinHdcpEncryptionLevelChange(uint32_t min_enc_level);
163   virtual int Perform(uint32_t operation, ...);
164   virtual int HandleSecureSession(const std::bitset<kSecureMax> &secure_sessions,
165                                   bool *power_on_pending);
166   virtual int GetActiveSecureSession(std::bitset<kSecureMax> *secure_sessions);
167   virtual DisplayError SetMixerResolution(uint32_t width, uint32_t height);
168   virtual DisplayError GetMixerResolution(uint32_t *width, uint32_t *height);
169   virtual void GetPanelResolution(uint32_t *width, uint32_t *height);
170   virtual std::string Dump();
TeardownConcurrentWriteback(void)171   virtual DisplayError TeardownConcurrentWriteback(void) {
172     return kErrorNotSupported;
173   }
174 
175   // Captures frame output in the buffer specified by output_buffer_info. The API is
176   // non-blocking and the client is expected to check operation status later on.
177   // Returns -1 if the input is invalid.
FrameCaptureAsync(const BufferInfo & output_buffer_info,bool post_processed)178   virtual int FrameCaptureAsync(const BufferInfo &output_buffer_info, bool post_processed) {
179     return -1;
180   }
181   // Returns the status of frame capture operation requested with FrameCaptureAsync().
182   // -EAGAIN : No status obtain yet, call API again after another frame.
183   // < 0 : Operation happened but failed.
184   // 0 : Success.
GetFrameCaptureStatus()185   virtual int GetFrameCaptureStatus() { return -EAGAIN; }
186 
SetDetailEnhancerConfig(const DisplayDetailEnhancerData & de_data)187   virtual DisplayError SetDetailEnhancerConfig(const DisplayDetailEnhancerData &de_data) {
188     return kErrorNotSupported;
189   }
SetReadbackBuffer(const native_handle_t * buffer,int32_t acquire_fence,bool post_processed_output)190   virtual HWC2::Error SetReadbackBuffer(const native_handle_t *buffer, int32_t acquire_fence,
191                                         bool post_processed_output) {
192     return HWC2::Error::Unsupported;
193   }
GetReadbackBufferFence(int32_t * release_fence)194   virtual HWC2::Error GetReadbackBufferFence(int32_t *release_fence) {
195     return HWC2::Error::Unsupported;
196   }
197 
SetDisplayDppsAdROI(uint32_t h_start,uint32_t h_end,uint32_t v_start,uint32_t v_end,uint32_t factor_in,uint32_t factor_out)198   virtual HWC2::Error SetDisplayDppsAdROI(uint32_t h_start, uint32_t h_end,
199                                           uint32_t v_start, uint32_t v_end,
200                                           uint32_t factor_in, uint32_t factor_out) {
201     return HWC2::Error::Unsupported;
202   }
203 
204   // Display Configurations
GetThrottlingRefreshRate()205   static uint32_t GetThrottlingRefreshRate() { return HWCDisplay::throttling_refresh_rate_; }
SetThrottlingRefreshRate(uint32_t newRefreshRate)206   static void SetThrottlingRefreshRate(uint32_t newRefreshRate)
207               { HWCDisplay::throttling_refresh_rate_ = newRefreshRate; }
208   virtual int SetActiveDisplayConfig(uint32_t config);
209   virtual int GetActiveDisplayConfig(uint32_t *config);
210   virtual int GetDisplayConfigCount(uint32_t *count);
211   virtual int GetDisplayAttributesForConfig(int config,
212                                             DisplayConfigVariableInfo *display_attributes);
SetState(bool connected)213   virtual int SetState(bool connected) {
214     return kErrorNotSupported;
215   }
Flush()216   virtual DisplayError Flush() {
217     return kErrorNotSupported;
218   }
219 
GetMaxRefreshRate()220   uint32_t GetMaxRefreshRate() { return max_refresh_rate_; }
SetPanelBrightness(int32_t level)221   virtual HWC2::Error SetPanelBrightness(int32_t level) { return HWC2::Error::Unsupported; }
GetPanelBrightness(int32_t & level)222   virtual HWC2::Error GetPanelBrightness(int32_t &level) const { return HWC2::Error::Unsupported; }
GetPanelMaxBrightness(int32_t & max_brightness_level)223   virtual HWC2::Error GetPanelMaxBrightness(int32_t &max_brightness_level) const {
224     return HWC2::Error::Unsupported;
225   }
226   int ToggleScreenUpdates(bool enable);
227   int ColorSVCRequestRoute(const PPDisplayAPIPayload &in_payload, PPDisplayAPIPayload *out_payload,
228                            PPPendingParams *pending_action);
229   void SolidFillPrepare();
230   void SolidFillCommit();
231   DisplayClass GetDisplayClass();
232   int GetVisibleDisplayRect(hwc_rect_t *rect);
233   void BuildLayerStack(void);
234   void BuildSolidFillStack(void);
235   HWCLayer *GetHWCLayer(hwc2_layer_t layer_id);
ResetValidation()236   void ResetValidation() { validated_ = false; }
GetGeometryChanges()237   uint32_t GetGeometryChanges() { return geometry_changes_; }
238   bool CanSkipValidate();
IsSkipValidateState()239   bool IsSkipValidateState() { return (validate_state_ == kSkipValidate); }
IsInternalValidateState()240   bool IsInternalValidateState() { return (validated_ && (validate_state_ == kInternalValidate)); }
SetValidationState(DisplayValidateState state)241   void SetValidationState(DisplayValidateState state) { validate_state_ = state; }
GetCurrentColorMode()242   ColorMode GetCurrentColorMode() {
243     return (color_mode_ ? color_mode_->GetCurrentColorMode() : ColorMode::SRGB);
244   }
GetCurrentRenderIntent()245   RenderIntent GetCurrentRenderIntent() {
246     return (color_mode_ ? color_mode_->GetCurrentRenderIntent() : RenderIntent::COLORIMETRIC);
247   }
HasClientComposition()248   bool HasClientComposition() { return has_client_composition_; }
HasForceClientComposition()249   bool HasForceClientComposition() { return has_force_client_composition_; }
HWCClientNeedsValidate()250   bool HWCClientNeedsValidate() {
251     return (has_client_composition_ || layer_stack_.flags.single_buffered_layer_present);
252   }
SetFastPathComposition(bool enable)253   virtual void SetFastPathComposition(bool enable) { fast_path_composition_ = enable; }
SetColorModeFromClientApi(int32_t color_mode_id)254   virtual HWC2::Error SetColorModeFromClientApi(int32_t color_mode_id) {
255     return HWC2::Error::Unsupported;
256   }
IsFirstCommitDone()257   bool IsFirstCommitDone() { return !first_cycle_; }
258   virtual void ProcessActiveConfigChange(void);
259 
260   // HWC2 APIs
261   virtual HWC2::Error AcceptDisplayChanges(void);
262   virtual HWC2::Error GetActiveConfig(hwc2_config_t *out_config);
263   virtual HWC2::Error SetActiveConfig(hwc2_config_t config);
SetPanelLuminanceAttributes(float min_lum,float max_lum)264   virtual HWC2::Error SetPanelLuminanceAttributes(float min_lum, float max_lum) {
265     return HWC2::Error::Unsupported;
266   }
267   virtual HWC2::Error SetClientTarget(buffer_handle_t target, int32_t acquire_fence,
268                                       int32_t dataspace, hwc_region_t damage);
SetColorMode(ColorMode mode)269   virtual HWC2::Error SetColorMode(ColorMode mode) { return HWC2::Error::Unsupported; }
SetColorModeWithRenderIntent(ColorMode mode,RenderIntent intent)270   virtual HWC2::Error SetColorModeWithRenderIntent(ColorMode mode, RenderIntent intent) {
271     return HWC2::Error::Unsupported;
272   }
SetColorModeById(int32_t color_mode_id)273   virtual HWC2::Error SetColorModeById(int32_t color_mode_id) {
274     return HWC2::Error::Unsupported;
275   }
RestoreColorTransform()276   virtual HWC2::Error RestoreColorTransform() {
277     return HWC2::Error::Unsupported;
278   }
SetColorTransform(const float * matrix,android_color_transform_t hint)279   virtual HWC2::Error SetColorTransform(const float *matrix, android_color_transform_t hint) {
280     return HWC2::Error::Unsupported;
281   }
HandleColorModeTransform(android_color_mode_t mode,android_color_transform_t hint,const double * matrix)282   virtual HWC2::Error HandleColorModeTransform(android_color_mode_t mode,
283                                                android_color_transform_t hint,
284                                                const double *matrix) {
285     return HWC2::Error::Unsupported;
286   }
SetDynamicDSIClock(uint64_t bitclk)287   virtual DisplayError SetDynamicDSIClock(uint64_t bitclk) {
288     return kErrorNotSupported;
289   }
GetDynamicDSIClock(uint64_t * bitclk)290   virtual DisplayError GetDynamicDSIClock(uint64_t *bitclk) {
291     return kErrorNotSupported;
292   }
GetSupportedDSIClock(std::vector<uint64_t> * bitclk)293   virtual DisplayError GetSupportedDSIClock(std::vector<uint64_t> *bitclk) {
294     return kErrorNotSupported;
295   }
UpdateDisplayId(hwc2_display_t id)296   virtual HWC2::Error UpdateDisplayId(hwc2_display_t id) {
297     return HWC2::Error::Unsupported;
298   }
SetPendingRefresh()299   virtual HWC2::Error SetPendingRefresh() {
300     return HWC2::Error::Unsupported;
301   }
302   virtual HWC2::Error GetDisplayConfigs(uint32_t *out_num_configs, hwc2_config_t *out_configs);
303   virtual HWC2::Error GetDisplayVsyncPeriod(hwc2_vsync_period_t *out_vsync_period);
304   virtual HWC2::Error SetActiveConfigWithConstraints(
305       hwc2_config_t config, hwc_vsync_period_change_constraints_t *vsync_period_change_constraints,
306       hwc_vsync_period_change_timeline_t *out_timeline);
307   virtual HWC2::Error GetDisplayAttribute(hwc2_config_t config, HWC2::Attribute attribute,
308                                           int32_t *out_value);
309   virtual HWC2::Error GetClientTargetSupport(uint32_t width, uint32_t height, int32_t format,
310                                              int32_t dataspace);
311   virtual HWC2::Error GetColorModes(uint32_t *outNumModes, ColorMode *outModes);
312   virtual HWC2::Error GetRenderIntents(ColorMode mode, uint32_t *out_num_intents,
313                                        RenderIntent *out_intents);
314   virtual HWC2::Error GetChangedCompositionTypes(uint32_t *out_num_elements,
315                                                  hwc2_layer_t *out_layers, int32_t *out_types);
316   virtual HWC2::Error GetDisplayRequests(int32_t *out_display_requests, uint32_t *out_num_elements,
317                                          hwc2_layer_t *out_layers, int32_t *out_layer_requests);
318   virtual HWC2::Error GetDisplayName(uint32_t *out_size, char *out_name);
319   virtual HWC2::Error GetDisplayType(int32_t *out_type);
320   virtual HWC2::Error SetCursorPosition(hwc2_layer_t layer, int x, int y);
321   virtual HWC2::Error SetVsyncEnabled(HWC2::Vsync enabled);
322   virtual HWC2::Error SetPowerMode(HWC2::PowerMode mode, bool teardown);
UpdatePowerMode(HWC2::PowerMode mode)323   virtual HWC2::Error UpdatePowerMode(HWC2::PowerMode mode) {
324     return HWC2::Error::None;
325   }
326   virtual HWC2::Error CreateLayer(hwc2_layer_t *out_layer_id);
327   virtual HWC2::Error DestroyLayer(hwc2_layer_t layer_id);
328   virtual HWC2::Error SetLayerZOrder(hwc2_layer_t layer_id, uint32_t z);
329   virtual HWC2::Error Validate(uint32_t *out_num_types, uint32_t *out_num_requests) = 0;
330   virtual HWC2::Error GetReleaseFences(uint32_t *out_num_elements, hwc2_layer_t *out_layers,
331                                        int32_t *out_fences);
332   virtual HWC2::Error Present(int32_t *out_retire_fence) = 0;
333   virtual HWC2::Error GetHdrCapabilities(uint32_t *out_num_types, int32_t* out_types,
334                                          float* out_max_luminance,
335                                          float* out_max_average_luminance,
336                                          float* out_min_luminance);
337   virtual HWC2::Error GetPerFrameMetadataKeys(uint32_t *out_num_keys,
338                                               PerFrameMetadataKey *out_keys);
SetDisplayAnimating(bool animating)339   virtual HWC2::Error SetDisplayAnimating(bool animating) {
340     animating_ = animating;
341     validated_ = false;
342     return HWC2::Error::None;
343   }
344   virtual HWC2::Error GetValidateDisplayOutput(uint32_t *out_num_types, uint32_t *out_num_requests);
345   virtual bool IsDisplayCommandMode();
SetQSyncMode(QSyncMode qsync_mode)346   virtual HWC2::Error SetQSyncMode(QSyncMode qsync_mode) {
347     return HWC2::Error::Unsupported;
348   }
ControlIdlePowerCollapse(bool enable,bool synchronous)349   virtual DisplayError ControlIdlePowerCollapse(bool enable, bool synchronous) {
350     return kErrorNone;
351   }
352   virtual HWC2::Error GetDisplayIdentificationData(uint8_t *out_port, uint32_t *out_data_size,
353                                                    uint8_t *out_data);
354   virtual void GetLayerStack(HWCLayerStack *stack);
355   virtual void SetLayerStack(HWCLayerStack *stack);
356   virtual void PostPowerMode();
NotifyClientStatus(bool connected)357   virtual void NotifyClientStatus(bool connected) { client_connected_ = connected; }
358 
359   virtual HWC2::Error SetDisplayedContentSamplingEnabledVndService(bool enabled);
360   virtual HWC2::Error SetDisplayedContentSamplingEnabled(int32_t enabled, uint8_t component_mask, uint64_t max_frames);
361   virtual HWC2::Error GetDisplayedContentSamplingAttributes(int32_t* format,
362                                                             int32_t* dataspace,
363                                                             uint8_t* supported_components);
364   virtual HWC2::Error GetDisplayedContentSample(uint64_t max_frames,
365                                                 uint64_t timestamp,
366                                                 uint64_t* numFrames,
367                                                 int32_t samples_size[NUM_HISTOGRAM_COLOR_COMPONENTS],
368                                                 uint64_t* samples[NUM_HISTOGRAM_COLOR_COMPONENTS]);
369 
370   virtual HWC2::Error GetDisplayConnectionType(uint32_t *out_type);
371 
372   virtual HWC2::Error GetDisplayBrightnessSupport(bool *out_support);
373   virtual HWC2::Error GetProtectedContentsSupport(bool *out_support);
374 
375   virtual HWC2::Error GetAutoLowLatencyModeSupport(bool *out_support);
SetAutoLowLatencyMode(bool on)376   virtual HWC2::Error SetAutoLowLatencyMode(bool on) { return HWC2::Error::Unsupported; };
377   virtual HWC2::Error GetSupportedContentTypes(uint32_t *out_num_types, uint32_t *out_types);
378   virtual HWC2::Error SetContentType(int32_t content_type);
379 
380  protected:
381   static uint32_t throttling_refresh_rate_;
382   // Maximum number of layers supported by display manager.
383   static const uint32_t kMaxLayerCount = 32;
384   HWCDisplay(CoreInterface *core_intf, BufferAllocator *buffer_allocator, HWCCallbacks *callbacks,
385              HWCDisplayEventHandler *event_handler, qService::QService *qservice, DisplayType type,
386              hwc2_display_t id, int32_t sdm_id, bool needs_blit, DisplayClass display_class);
387 
388   // DisplayEventHandler methods
389   virtual DisplayError VSync(const DisplayEventVSync &vsync);
390   virtual DisplayError Refresh();
391   virtual DisplayError CECMessage(char *message);
392   virtual DisplayError HistogramEvent(int source_fd, uint32_t blob_id) override;
393   virtual DisplayError HandleEvent(DisplayEvent event);
394   virtual void DumpOutputBuffer(const BufferInfo &buffer_info, void *base, int fence);
395   virtual HWC2::Error PrepareLayerStack(uint32_t *out_num_types, uint32_t *out_num_requests);
396   virtual HWC2::Error CommitLayerStack(void);
397   virtual HWC2::Error PostCommitLayerStack(int32_t *out_retire_fence);
DisablePartialUpdateOneFrame()398   virtual DisplayError DisablePartialUpdateOneFrame() {
399     return kErrorNotSupported;
400   }
401 
402   HWC2::Error GetCurrentVsyncPeriod(uint32_t *period);
403   HWC2::Error GetCurrentVsyncPeriodByConfig(uint32_t *period);
404   bool GetTransientVsyncPeriod(uint32_t *period);
405   std::tuple<int64_t, int64_t> EstimateVsyncPeriodChangeTimeline(uint32_t current_vsync_period,
406                                                                  int64_t desired_time);
407   bool IsActiveConfigReadyToSubmit(int64_t time);
408   bool IsActiveConfigApplied(int64_t time, int64_t vsync_applied_time);
409   std::tuple<int64_t, int64_t> RequestActiveConfigChange(hwc2_config_t config,
410                                                          uint32_t current_vsync_period,
411                                                          int64_t desired_time);
412   void SubmitActiveConfigChange(uint32_t current_vsync_period);
413   int32_t GetDisplayGroupConfig(DisplayConfigVariableInfo variable_config);
414   bool IsSameGroup(hwc2_config_t configId1, hwc2_config_t configId2);
415   bool AllowSeamless(hwc2_config_t request_config);
SetVsyncsApplyRateChange(uint32_t vsyncs)416   void SetVsyncsApplyRateChange(uint32_t vsyncs) { vsyncs_to_apply_rate_change_ = vsyncs; }
417 
418   const char *GetDisplayString();
419   void MarkLayersForGPUBypass(void);
420   void MarkLayersForClientComposition(void);
421   void UpdateConfigs();
422   virtual void ApplyScanAdjustment(hwc_rect_t *display_frame);
423   uint32_t GetUpdatingLayersCount(void);
424   bool IsLayerUpdating(HWCLayer *layer);
425   uint32_t SanitizeRefreshRate(uint32_t req_refresh_rate);
GetUnderScanConfig()426   virtual void GetUnderScanConfig() { }
427   int32_t SetClientTargetDataSpace(int32_t dataspace);
428 
429   enum {
430     INPUT_LAYER_DUMP,
431     OUTPUT_LAYER_DUMP,
432   };
433 
434   bool validated_ = false;
435   bool layer_stack_invalid_ = true;
436   CoreInterface *core_intf_ = nullptr;
437   HWCBufferAllocator *buffer_allocator_ = NULL;
438   HWCCallbacks *callbacks_  = nullptr;
439   HWCDisplayEventHandler *event_handler_ = nullptr;
440   DisplayType type_ = kDisplayTypeMax;
441   hwc2_display_t id_ = UINT64_MAX;
442   int32_t sdm_id_ = -1;
443   bool needs_blit_ = false;
444   DisplayInterface *display_intf_ = NULL;
445   LayerStack layer_stack_;
446   HWCLayer *client_target_ = nullptr;                   // Also known as framebuffer target
447   std::map<hwc2_layer_t, HWCLayer *> layer_map_;        // Look up by Id - TODO
448   std::multiset<HWCLayer *, SortLayersByZ> layer_set_;  // Maintain a set sorted by Z
449   std::map<hwc2_layer_t, HWC2::Composition> layer_changes_;
450   std::map<hwc2_layer_t, HWC2::LayerRequest> layer_requests_;
451   bool flush_on_error_ = false;
452   bool flush_ = false;
453   uint32_t dump_frame_count_ = 0;
454   uint32_t dump_frame_index_ = 0;
455   bool dump_input_layers_ = false;
456   HWC2::PowerMode current_power_mode_ = HWC2::PowerMode::Off;
457   bool swap_interval_zero_ = false;
458   bool display_paused_ = false;
459   uint32_t min_refresh_rate_ = 0;
460   uint32_t max_refresh_rate_ = 0;
461   uint32_t current_refresh_rate_ = 0;
462   bool use_metadata_refresh_rate_ = false;
463   uint32_t metadata_refresh_rate_ = 0;
464   uint32_t force_refresh_rate_ = 0;
465   bool boot_animation_completed_ = false;
466   bool shutdown_pending_ = false;
467   bool use_blit_comp_ = false;
468   std::bitset<kSecureMax> active_secure_sessions_ = 0;
469   bool solid_fill_enable_ = false;
470   Layer *solid_fill_layer_ = NULL;
471   LayerRect solid_fill_rect_ = {};
472   LayerSolidFill solid_fill_color_ = {};
473   LayerRect display_rect_;
474   bool color_tranform_failed_ = false;
475   HWCColorMode *color_mode_ = NULL;
476   HWCToneMapper *tone_mapper_ = nullptr;
477   uint32_t num_configs_ = 0;
478   int disable_hdr_handling_ = 0;  // disables HDR handling.
479   bool pending_commit_ = false;
480   bool is_cmd_mode_ = false;
481   bool partial_update_enabled_ = false;
482   bool skip_commit_ = false;
483   std::map<uint32_t, DisplayConfigVariableInfo> variable_config_map_;
484   std::vector<uint32_t> hwc_config_map_;
485   float hdr_largest_layer_px_ = 0.0f;
486   bool fast_path_composition_ = false;
487   uint32_t vsyncs_to_apply_rate_change_ = 1;
488   hwc2_config_t pending_refresh_rate_config_ = UINT_MAX;
489   int64_t pending_refresh_rate_refresh_time_ = INT64_MAX;
490   int64_t pending_refresh_rate_applied_time_ = INT64_MAX;
491   std::deque<TransientRefreshRateInfo> transient_refresh_rate_info_;
492   std::mutex transient_refresh_rate_lock_;
493   bool client_connected_ = true;
494   bool pending_config_ = false;
495 
496  private:
497   void DumpInputBuffers(void);
498   bool CanSkipSdmPrepare(uint32_t *num_types, uint32_t *num_requests);
499   void UpdateRefreshRate();
500   void WaitOnPreviousFence();
501   void UpdateActiveConfig();
502   qService::QService *qservice_ = NULL;
503   DisplayClass display_class_;
504   uint32_t geometry_changes_ = GeometryChanges::kNone;
505   uint32_t geometry_changes_on_doze_suspend_ = GeometryChanges::kNone;
506   bool animating_ = false;
507   int null_display_mode_ = 0;
508   bool has_client_composition_ = false;
509   bool has_force_client_composition_ = false;
510   DisplayValidateState validate_state_ = kNormalValidate;
511   bool fast_path_enabled_ = true;
512   bool first_cycle_ = true;  // false if a display commit has succeeded on the device.
513   int fbt_release_fence_ = -1;
514   int release_fence_ = -1;
515   hwc2_config_t pending_config_index_ = 0;
516   int async_power_mode_ = 0;
517 };
518 
Perform(uint32_t operation,...)519 inline int HWCDisplay::Perform(uint32_t operation, ...) {
520   return 0;
521 }
522 
523 }  // namespace sdm
524 
525 #endif  // __HWC_DISPLAY_H__
526