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_2::ColorMode;
49 using android::hardware::graphics::common::V1_2::Dataspace;
50 using android::hardware::graphics::common::V1_1::RenderIntent;
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 using ClientTargetProperty = composer_V2_4::IComposerClient::ClientTargetProperty;
61
62 namespace sdm {
63
64 class HWCToneMapper;
65
66 // Subclasses set this to their type. This has to be different from DisplayType.
67 // This is to avoid RTTI and dynamic_cast
68 enum DisplayClass {
69 DISPLAY_CLASS_BUILTIN,
70 DISPLAY_CLASS_PLUGGABLE,
71 DISPLAY_CLASS_VIRTUAL,
72 DISPLAY_CLASS_NULL
73 };
74
75 enum {
76 INPUT_LAYER_DUMP,
77 OUTPUT_LAYER_DUMP,
78 };
79
80 enum SecureSessionType {
81 kSecureDisplay,
82 kSecureCamera,
83 kSecureMax,
84 };
85
86 // CWB client currently using the block
87 enum CWBClient {
88 kCWBClientNone, // No client connected
89 kCWBClientFrameDump, // Dump to file
90 kCWBClientColor, // Internal client i.e. Color Manager
91 kCWBClientExternal, // External client calling through private APIs
92 kCWBClientComposer, // Client to HWC i.e. SurfaceFlinger
93 };
94
95 struct TransientRefreshRateInfo {
96 uint32_t transient_vsync_period;
97 int64_t vsync_applied_time;
98 };
99
100 class HWCColorMode {
101 public:
102 explicit HWCColorMode(DisplayInterface *display_intf);
~HWCColorMode()103 ~HWCColorMode() {}
104 HWC2::Error Init();
105 HWC2::Error DeInit();
106 void Dump(std::ostringstream* os);
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, uint32_t inactive_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, bool is_active_secure_display);
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
SetHWDetailedEnhancerConfig(void * params)225 virtual DisplayError SetHWDetailedEnhancerConfig(void *params) {
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
VsyncEnablePending()254 virtual bool VsyncEnablePending() {
255 return false;
256 }
257
SetCpuPerfHintLargeCompCycle()258 virtual void SetCpuPerfHintLargeCompCycle() {};
259 // Display Configurations
GetThrottlingRefreshRate()260 static uint32_t GetThrottlingRefreshRate() { return HWCDisplay::throttling_refresh_rate_; }
SetThrottlingRefreshRate(uint32_t newRefreshRate)261 static void SetThrottlingRefreshRate(uint32_t newRefreshRate)
262 { HWCDisplay::throttling_refresh_rate_ = newRefreshRate; }
263 virtual int SetActiveDisplayConfig(uint32_t config);
264 virtual int GetActiveDisplayConfig(uint32_t *config);
265 virtual int GetDisplayConfigCount(uint32_t *count);
266 virtual int GetDisplayAttributesForConfig(int config,
267 DisplayConfigVariableInfo *display_attributes);
SetState(bool connected)268 virtual int SetState(bool connected) {
269 return kErrorNotSupported;
270 }
SetStandByMode(bool enable,bool is_twm)271 virtual DisplayError SetStandByMode(bool enable, bool is_twm) {
272 return kErrorNotSupported;
273 }
Flush()274 virtual DisplayError Flush() {
275 return kErrorNotSupported;
276 }
277
GetMaxRefreshRate()278 uint32_t GetMaxRefreshRate() { return max_refresh_rate_; }
279 int ToggleScreenUpdates(bool enable);
280 int ColorSVCRequestRoute(const PPDisplayAPIPayload &in_payload, PPDisplayAPIPayload *out_payload,
281 PPPendingParams *pending_action);
282 void SolidFillPrepare();
283 DisplayClass GetDisplayClass();
284 int GetVisibleDisplayRect(hwc_rect_t *rect);
285 void BuildLayerStack(void);
286 void BuildSolidFillStack(void);
287 HWCLayer *GetHWCLayer(hwc2_layer_t layer_id);
ResetValidation()288 void ResetValidation() { validated_ = false; }
GetGeometryChanges()289 uint32_t GetGeometryChanges() { return geometry_changes_; }
290 bool CanSkipValidate();
IsSkipValidateState()291 bool IsSkipValidateState() { return (validate_state_ == kSkipValidate); }
IsInternalValidateState()292 bool IsInternalValidateState() { return (validated_ && (validate_state_ == kInternalValidate)); }
SetValidationState(DisplayValidateState state)293 void SetValidationState(DisplayValidateState state) { validate_state_ = state; }
GetCurrentColorMode()294 ColorMode GetCurrentColorMode() {
295 return (color_mode_ ? color_mode_->GetCurrentColorMode() : ColorMode::SRGB);
296 }
HWCClientNeedsValidate()297 bool HWCClientNeedsValidate() {
298 return (has_client_composition_ || layer_stack_.flags.single_buffered_layer_present);
299 }
300 bool CheckResourceState();
SetFastPathComposition(bool enable)301 virtual void SetFastPathComposition(bool enable) { fast_path_composition_ = enable; }
SetColorModeFromClientApi(int32_t color_mode_id)302 virtual HWC2::Error SetColorModeFromClientApi(int32_t color_mode_id) {
303 return HWC2::Error::Unsupported;
304 }
IsFirstCommitDone()305 bool IsFirstCommitDone() { return !first_cycle_; }
306 virtual void ProcessActiveConfigChange();
307
308 // HWC2 APIs
309 virtual HWC2::Error AcceptDisplayChanges(void);
310 virtual HWC2::Error GetActiveConfig(hwc2_config_t *out_config);
311 virtual HWC2::Error SetActiveConfig(hwc2_config_t config);
SetPanelLuminanceAttributes(float min_lum,float max_lum)312 virtual HWC2::Error SetPanelLuminanceAttributes(float min_lum, float max_lum) {
313 return HWC2::Error::Unsupported;
314 }
315 virtual HWC2::Error SetClientTarget(buffer_handle_t target, shared_ptr<Fence> acquire_fence,
316 int32_t dataspace, hwc_region_t damage);
317 virtual HWC2::Error GetClientTarget(buffer_handle_t target, shared_ptr<Fence> acquire_fence,
318 int32_t dataspace, hwc_region_t damage);
SetColorMode(ColorMode mode)319 virtual HWC2::Error SetColorMode(ColorMode mode) { return HWC2::Error::Unsupported; }
SetColorModeWithRenderIntent(ColorMode mode,RenderIntent intent)320 virtual HWC2::Error SetColorModeWithRenderIntent(ColorMode mode, RenderIntent intent) {
321 return HWC2::Error::Unsupported;
322 }
SetColorModeById(int32_t color_mode_id)323 virtual HWC2::Error SetColorModeById(int32_t color_mode_id) {
324 return HWC2::Error::Unsupported;
325 }
RestoreColorTransform()326 virtual HWC2::Error RestoreColorTransform() {
327 return HWC2::Error::Unsupported;
328 }
SetColorTransform(const float * matrix,android_color_transform_t hint)329 virtual HWC2::Error SetColorTransform(const float *matrix, android_color_transform_t hint) {
330 return HWC2::Error::Unsupported;
331 }
HandleColorModeTransform(android_color_mode_t mode,android_color_transform_t hint,const double * matrix)332 virtual HWC2::Error HandleColorModeTransform(android_color_mode_t mode,
333 android_color_transform_t hint,
334 const double *matrix) {
335 return HWC2::Error::Unsupported;
336 }
SetDynamicDSIClock(uint64_t bitclk)337 virtual DisplayError SetDynamicDSIClock(uint64_t bitclk) {
338 return kErrorNotSupported;
339 }
GetDynamicDSIClock(uint64_t * bitclk)340 virtual DisplayError GetDynamicDSIClock(uint64_t *bitclk) {
341 return kErrorNotSupported;
342 }
GetSupportedDSIClock(std::vector<uint64_t> * bitclk)343 virtual DisplayError GetSupportedDSIClock(std::vector<uint64_t> *bitclk) {
344 return kErrorNotSupported;
345 }
UpdateDisplayId(hwc2_display_t id)346 virtual HWC2::Error UpdateDisplayId(hwc2_display_t id) {
347 return HWC2::Error::Unsupported;
348 }
SetPendingRefresh()349 virtual HWC2::Error SetPendingRefresh() {
350 return HWC2::Error::Unsupported;
351 }
SetPanelBrightness(float brightness)352 virtual HWC2::Error SetPanelBrightness(float brightness) {
353 return HWC2::Error::Unsupported;
354 }
GetPanelBrightness(float * brightness)355 virtual HWC2::Error GetPanelBrightness(float *brightness) {
356 return HWC2::Error::Unsupported;
357 }
GetPanelMaxBrightness(uint32_t * max_brightness_level)358 virtual HWC2::Error GetPanelMaxBrightness(uint32_t *max_brightness_level) {
359 return HWC2::Error::Unsupported;
360 }
361 virtual HWC2::Error GetDisplayConfigs(uint32_t *out_num_configs, hwc2_config_t *out_configs);
362 virtual HWC2::Error GetDisplayAttribute(hwc2_config_t config, HwcAttribute attribute,
363 int32_t *out_value);
364 virtual HWC2::Error GetClientTargetSupport(uint32_t width, uint32_t height, int32_t format,
365 int32_t dataspace);
366 virtual HWC2::Error GetColorModes(uint32_t *outNumModes, ColorMode *outModes);
367 virtual HWC2::Error GetRenderIntents(ColorMode mode, uint32_t *out_num_intents,
368 RenderIntent *out_intents);
369 virtual HWC2::Error GetChangedCompositionTypes(uint32_t *out_num_elements,
370 hwc2_layer_t *out_layers, int32_t *out_types);
371 virtual HWC2::Error GetDisplayRequests(int32_t *out_display_requests, uint32_t *out_num_elements,
372 hwc2_layer_t *out_layers, int32_t *out_layer_requests);
373 virtual HWC2::Error GetDisplayName(uint32_t *out_size, char *out_name);
374 virtual HWC2::Error GetDisplayType(int32_t *out_type);
375 virtual HWC2::Error SetCursorPosition(hwc2_layer_t layer, int x, int y);
376 virtual HWC2::Error SetVsyncEnabled(HWC2::Vsync enabled);
377 virtual HWC2::Error SetPowerMode(HWC2::PowerMode mode, bool teardown);
UpdatePowerMode(HWC2::PowerMode mode)378 virtual HWC2::Error UpdatePowerMode(HWC2::PowerMode mode) {
379 return HWC2::Error::None;
380 }
381 virtual HWC2::Error CreateLayer(hwc2_layer_t *out_layer_id);
382 virtual HWC2::Error DestroyLayer(hwc2_layer_t layer_id);
383 virtual HWC2::Error SetLayerZOrder(hwc2_layer_t layer_id, uint32_t z);
384 virtual HWC2::Error SetLayerType(hwc2_layer_t layer_id, IQtiComposerClient::LayerType type);
385 virtual HWC2::Error Validate(uint32_t *out_num_types, uint32_t *out_num_requests) = 0;
386 virtual HWC2::Error GetReleaseFences(uint32_t *out_num_elements, hwc2_layer_t *out_layers,
387 std::vector<shared_ptr<Fence>> *out_fences);
388 virtual HWC2::Error Present(shared_ptr<Fence> *out_retire_fence) = 0;
389 virtual HWC2::Error GetHdrCapabilities(uint32_t *out_num_types, int32_t* out_types,
390 float* out_max_luminance,
391 float* out_max_average_luminance,
392 float* out_min_luminance);
393 virtual HWC2::Error GetPerFrameMetadataKeys(uint32_t *out_num_keys,
394 PerFrameMetadataKey *out_keys);
SetDisplayAnimating(bool animating)395 virtual HWC2::Error SetDisplayAnimating(bool animating) {
396 animating_ = animating;
397 validated_ = false;
398 return HWC2::Error::None;
399 }
400 virtual HWC2::Error GetValidateDisplayOutput(uint32_t *out_num_types, uint32_t *out_num_requests);
401 virtual bool IsDisplayCommandMode();
SetQSyncMode(QSyncMode qsync_mode)402 virtual HWC2::Error SetQSyncMode(QSyncMode qsync_mode) {
403 return HWC2::Error::Unsupported;
404 }
ControlIdlePowerCollapse(bool enable,bool synchronous)405 virtual DisplayError ControlIdlePowerCollapse(bool enable, bool synchronous) {
406 return kErrorNone;
407 }
408 virtual HWC2::Error GetDisplayIdentificationData(uint8_t *out_port, uint32_t *out_data_size,
409 uint8_t *out_data);
SetBLScale(uint32_t level)410 virtual HWC2::Error SetBLScale(uint32_t level) {
411 return HWC2::Error::Unsupported;
412 }
413 virtual void GetLayerStack(HWCLayerStack *stack);
414 virtual void SetLayerStack(HWCLayerStack *stack);
415 virtual void PostPowerMode();
GetPendingPowerMode()416 virtual HWC2::PowerMode GetPendingPowerMode() {
417 return pending_power_mode_;
418 }
SetPendingPowerMode(HWC2::PowerMode mode)419 virtual void SetPendingPowerMode(HWC2::PowerMode mode) {
420 pending_power_mode_ = mode;
421 }
ClearPendingPowerMode()422 virtual void ClearPendingPowerMode() {
423 pending_power_mode_ = current_power_mode_;
424 }
NotifyClientStatus(bool connected)425 virtual void NotifyClientStatus(bool connected) { client_connected_ = connected; }
IsQsyncCallbackNeeded(bool * qsync_enabled,int32_t * refresh_rate,int32_t * qsync_refresh_rate)426 virtual bool IsQsyncCallbackNeeded(bool *qsync_enabled, int32_t *refresh_rate,
427 int32_t *qsync_refresh_rate) {
428 return false;
429 }
PostInit()430 virtual int PostInit() { return 0; }
431
432 virtual HWC2::Error SetDisplayedContentSamplingEnabledVndService(bool enabled);
433 virtual HWC2::Error SetDisplayedContentSamplingEnabled(int32_t enabled, uint8_t component_mask,
434 uint64_t max_frames);
435 virtual HWC2::Error GetDisplayedContentSamplingAttributes(int32_t *format, int32_t *dataspace,
436 uint8_t *supported_components);
437 virtual HWC2::Error GetDisplayedContentSample(
438 uint64_t max_frames, uint64_t timestamp, uint64_t *numFrames,
439 int32_t samples_size[NUM_HISTOGRAM_COLOR_COMPONENTS],
440 uint64_t *samples[NUM_HISTOGRAM_COLOR_COMPONENTS]);
441
442 virtual HWC2::Error GetDisplayVsyncPeriod(VsyncPeriodNanos *vsync_period);
SetDisplayVsyncPeriod(VsyncPeriodNanos vsync_period)443 virtual HWC2::Error SetDisplayVsyncPeriod(VsyncPeriodNanos vsync_period) {
444 return HWC2::Error::None;
445 }
446
447
448 virtual HWC2::Error SetActiveConfigWithConstraints(
449 hwc2_config_t config, const VsyncPeriodChangeConstraints *vsync_period_change_constraints,
450 VsyncPeriodChangeTimeline *out_timeline);
SetAutoLowLatencyMode(bool on)451 virtual HWC2::Error SetAutoLowLatencyMode(bool on) { return HWC2::Error::Unsupported; }
452 virtual HWC2::Error GetSupportedContentTypes(hidl_vec<HwcContentType> *types);
453 virtual HWC2::Error SetContentType(HwcContentType type);
454
455 HWC2::Error SetDisplayElapseTime(uint64_t time);
HasReadBackBufferSupport()456 virtual bool HasReadBackBufferSupport() { return false; }
IsDisplayIdle()457 virtual bool IsDisplayIdle() { return false; };
458 virtual HWC2::Error GetClientTargetProperty(ClientTargetProperty *out_client_target_property);
459
IsHbmSupported()460 virtual bool IsHbmSupported() { return false; }
SetHbm(HbmState state,HbmClient client)461 virtual HWC2::Error SetHbm(HbmState state, HbmClient client) { return HWC2::Error::None; }
GetHbm()462 virtual HbmState GetHbm() { return HbmState::OFF; }
463
464 protected:
465 static uint32_t throttling_refresh_rate_;
466 // Maximum number of layers supported by display manager.
467 static const uint32_t kMaxLayerCount = 32;
468 HWCDisplay(CoreInterface *core_intf, BufferAllocator *buffer_allocator, HWCCallbacks *callbacks,
469 HWCDisplayEventHandler *event_handler, qService::QService *qservice, DisplayType type,
470 hwc2_display_t id, int32_t sdm_id, DisplayClass display_class);
471
472 // DisplayEventHandler methods
473 virtual DisplayError VSync(const DisplayEventVSync &vsync);
474 virtual DisplayError Refresh();
475 virtual DisplayError CECMessage(char *message);
476 virtual DisplayError HistogramEvent(int source_fd, uint32_t blob_id);
477 virtual DisplayError HandleEvent(DisplayEvent event);
478 virtual void DumpOutputBuffer(const BufferInfo &buffer_info, void *base,
479 shared_ptr<Fence> &retire_fence);
480 virtual HWC2::Error PrepareLayerStack(uint32_t *out_num_types, uint32_t *out_num_requests);
481 virtual HWC2::Error CommitLayerStack(void);
482 virtual HWC2::Error PostCommitLayerStack(shared_ptr<Fence> *out_retire_fence);
DisablePartialUpdateOneFrame()483 virtual DisplayError DisablePartialUpdateOneFrame() {
484 return kErrorNotSupported;
485 }
486 const char *GetDisplayString();
487 void MarkLayersForGPUBypass(void);
488 void MarkLayersForClientComposition(void);
489 void UpdateConfigs();
490 virtual void ApplyScanAdjustment(hwc_rect_t *display_frame);
491 uint32_t GetUpdatingLayersCount(void);
492 bool IsLayerUpdating(HWCLayer *layer);
493 uint32_t SanitizeRefreshRate(uint32_t req_refresh_rate);
GetUnderScanConfig()494 virtual void GetUnderScanConfig() { }
495 int32_t SetClientTargetDataSpace(int32_t dataspace);
496 int SetFrameBufferConfig(uint32_t x_pixels, uint32_t y_pixels);
497 int32_t GetDisplayConfigGroup(DisplayConfigGroupInfo variable_config);
498 HWC2::Error GetVsyncPeriodByActiveConfig(VsyncPeriodNanos *vsync_period);
499 bool GetTransientVsyncPeriod(VsyncPeriodNanos *vsync_period);
500 std::tuple<int64_t, int64_t> RequestActiveConfigChange(hwc2_config_t config,
501 VsyncPeriodNanos current_vsync_period,
502 int64_t desired_time);
503 std::tuple<int64_t, int64_t> EstimateVsyncPeriodChangeTimeline(
504 VsyncPeriodNanos current_vsync_period, int64_t desired_time);
505 void SubmitActiveConfigChange(VsyncPeriodNanos current_vsync_period);
506 bool IsActiveConfigReadyToSubmit(int64_t time);
507 bool IsActiveConfigApplied(int64_t time, int64_t vsync_applied_time);
508 bool IsSameGroup(hwc2_config_t config_id1, hwc2_config_t config_id2);
509 bool AllowSeamless(hwc2_config_t request_config);
SetVsyncsApplyRateChange(uint32_t vsyncs)510 void SetVsyncsApplyRateChange(uint32_t vsyncs) { vsyncs_to_apply_rate_change_ = vsyncs; }
511 HWC2::Error SubmitDisplayConfig(hwc2_config_t config);
512 HWC2::Error GetCachedActiveConfig(hwc2_config_t *config);
513 void SetActiveConfigIndex(int active_config_index);
514 int GetActiveConfigIndex();
515
516 bool validated_ = false;
517 bool layer_stack_invalid_ = true;
518 CoreInterface *core_intf_ = nullptr;
519 HWCBufferAllocator *buffer_allocator_ = NULL;
520 HWCCallbacks *callbacks_ = nullptr;
521 HWCDisplayEventHandler *event_handler_ = nullptr;
522 DisplayType type_ = kDisplayTypeMax;
523 hwc2_display_t id_ = UINT64_MAX;
524 int32_t sdm_id_ = -1;
525 DisplayInterface *display_intf_ = NULL;
526 LayerStack layer_stack_;
527 HWCLayer *client_target_ = nullptr; // Also known as framebuffer target
528 std::map<hwc2_layer_t, HWCLayer *> layer_map_; // Look up by Id - TODO
529 std::multiset<HWCLayer *, SortLayersByZ> layer_set_; // Maintain a set sorted by Z
530 std::map<hwc2_layer_t, HWC2::Composition> layer_changes_;
531 std::map<hwc2_layer_t, HWC2::LayerRequest> layer_requests_;
532 bool flush_on_error_ = false;
533 bool flush_ = false;
534 uint32_t dump_frame_count_ = 0;
535 uint32_t dump_frame_index_ = 0;
536 bool dump_input_layers_ = false;
537 HWC2::PowerMode current_power_mode_ = HWC2::PowerMode::Off;
538 HWC2::PowerMode pending_power_mode_ = HWC2::PowerMode::Off;
539 bool swap_interval_zero_ = false;
540 bool display_paused_ = false;
541 uint32_t min_refresh_rate_ = 0;
542 uint32_t max_refresh_rate_ = 0;
543 uint32_t current_refresh_rate_ = 0;
544 bool use_metadata_refresh_rate_ = false;
545 uint32_t metadata_refresh_rate_ = 0;
546 uint32_t force_refresh_rate_ = 0;
547 bool boot_animation_completed_ = false;
548 bool shutdown_pending_ = false;
549 std::bitset<kSecureMax> active_secure_sessions_ = 0;
550 bool solid_fill_enable_ = false;
551 Layer *solid_fill_layer_ = NULL;
552 LayerRect solid_fill_rect_ = {};
553 LayerSolidFill solid_fill_color_ = {};
554 LayerRect display_rect_;
555 bool color_tranform_failed_ = false;
556 HWCColorMode *color_mode_ = NULL;
557 HWCToneMapper *tone_mapper_ = nullptr;
558 uint32_t num_configs_ = 0;
559 int disable_hdr_handling_ = 0; // disables HDR handling.
560 bool pending_commit_ = false;
561 bool is_cmd_mode_ = false;
562 bool partial_update_enabled_ = false;
563 bool fast_path_composition_ = false;
564 bool skip_commit_ = false;
565 std::map<uint32_t, DisplayConfigVariableInfo> variable_config_map_;
566 std::vector<uint32_t> hwc_config_map_;
567 bool client_connected_ = true;
568 bool pending_config_ = false;
569 bool has_client_composition_ = false;
570 bool smart_panel_config_ = false;
571 uint32_t vsyncs_to_apply_rate_change_ = 1;
572 hwc2_config_t pending_refresh_rate_config_ = UINT_MAX;
573 int64_t pending_refresh_rate_refresh_time_ = INT64_MAX;
574 int64_t pending_refresh_rate_applied_time_ = INT64_MAX;
575 std::deque<TransientRefreshRateInfo> transient_refresh_rate_info_;
576 std::mutex transient_refresh_rate_lock_;
577 std::mutex active_config_lock_;
578 int active_config_index_ = -1;
579 float hdr_largest_layer_px_ = 0.0f;
580 LayerRect window_rect_ = {};
581 bool windowed_display_ = false;
582 uint32_t active_refresh_rate_ = 0;
583 bool animating_ = false;
584 buffer_handle_t client_target_handle_ = 0;
585 shared_ptr<Fence> client_acquire_fence_ = nullptr;
586 int32_t client_dataspace_ = 0;
587 hwc_region_t client_damage_region_ = {};
588 bool display_idle_ = false;
589 bool enable_poms_during_doze_ = false;
590
591 private:
592 void DumpInputBuffers(void);
593 bool CanSkipSdmPrepare(uint32_t *num_types, uint32_t *num_requests);
594 void UpdateRefreshRate();
595 void WaitOnPreviousFence();
596 void UpdateActiveConfig();
597 qService::QService *qservice_ = NULL;
598 DisplayClass display_class_;
599 uint32_t geometry_changes_ = GeometryChanges::kNone;
600 uint32_t geometry_changes_on_doze_suspend_ = GeometryChanges::kNone;
601 int null_display_mode_ = 0;
602 DisplayValidateState validate_state_ = kNormalValidate;
603 bool fast_path_enabled_ = true;
604 bool first_cycle_ = true; // false if a display commit has succeeded on the device.
605 shared_ptr<Fence> fbt_release_fence_ = nullptr;
606 shared_ptr<Fence> release_fence_ = nullptr;
607 hwc2_config_t pending_config_index_ = 0;
608 bool pending_first_commit_config_ = false;
609 hwc2_config_t pending_first_commit_config_index_ = 0;
610 bool game_supported_ = false;
611 uint64_t elapse_timestamp_ = 0;
612 int async_power_mode_ = 0;
613 };
614
Perform(uint32_t operation,...)615 inline int HWCDisplay::Perform(uint32_t operation, ...) {
616 return 0;
617 }
618
619 } // namespace sdm
620
621 #endif // __HWC_DISPLAY_H__
622