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