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