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