blob: ba98ef7fa2f7c5d231f2efc29bcfebbd57a024b5 [file] [log] [blame]
Naseer Ahmedb92e73f2016-03-12 02:03:48 -05001/*
Gousemoodhin Nadaf087c3102019-01-07 19:34:56 +05302 * Copyright (c) 2014-2019, The Linux Foundation. All rights reserved.
Naseer Ahmedb92e73f2016-03-12 02:03:48 -05003 * 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
Naseer Ahmedb92e73f2016-03-12 02:03:48 -050023#include <QService.h>
Gousemoodhin Nadaf0e566872019-05-13 16:14:54 +053024#include <android/hardware/graphics/common/1.2/types.h>
Arun Kumar K.R29cd6582016-05-10 19:12:45 -070025#include <core/core_interface.h>
26#include <hardware/hwcomposer.h>
Naseer Ahmedb92e73f2016-03-12 02:03:48 -050027#include <private/color_params.h>
Arun Kumar K.R29cd6582016-05-10 19:12:45 -070028#include <qdMetaData.h>
Naseer Ahmede7a77982018-06-04 10:56:04 -040029#include <sys/stat.h>
Naseer Ahmedb92e73f2016-03-12 02:03:48 -050030#include <map>
Arun Kumar K.R29cd6582016-05-10 19:12:45 -070031#include <queue>
Naseer Ahmedb92e73f2016-03-12 02:03:48 -050032#include <set>
Naseer Ahmed2a3c7d92016-05-17 18:38:54 -040033#include <string>
Naseer Ahmedb92e73f2016-03-12 02:03:48 -050034#include <utility>
Arun Kumar K.R29cd6582016-05-10 19:12:45 -070035#include <vector>
Ramkumar Radhakrishnana38b7602018-03-15 14:49:52 -070036#include <bitset>
Mahesh Aiaf3a1f992019-01-16 13:07:42 -080037#include <algorithm>
Naseer Ahmed42752212017-01-27 17:32:21 -050038#include "hwc_buffer_allocator.h"
Naseer Ahmedb92e73f2016-03-12 02:03:48 -050039#include "hwc_callbacks.h"
40#include "hwc_layers.h"
Varun Arora465c1f72018-02-08 16:18:50 -080041#include "display_null.h"
Varun Arora7c8ee542018-05-01 20:58:16 -070042#include "hwc_display_event_handler.h"
Naseer Ahmedb92e73f2016-03-12 02:03:48 -050043
Gousemoodhin Nadaf0e566872019-05-13 16:14:54 +053044using android::hardware::graphics::common::V1_2::ColorMode;
Naseer Ahmede7a77982018-06-04 10:56:04 -040045using android::hardware::graphics::common::V1_1::Dataspace;
46using android::hardware::graphics::common::V1_1::RenderIntent;
47
Naseer Ahmedb92e73f2016-03-12 02:03:48 -050048namespace sdm {
49
Arun Kumar K.R51be3d12017-03-31 19:54:38 -070050class HWCToneMapper;
Naseer Ahmedb92e73f2016-03-12 02:03:48 -050051
Xu Yang47f44092019-02-13 14:09:53 +080052/* max customer extended render intent */
53#define MAX_EXTENDED_RENDER_INTENT 0x1ff
54
Naseer Ahmedb92e73f2016-03-12 02:03:48 -050055// Subclasses set this to their type. This has to be different from DisplayType.
56// This is to avoid RTTI and dynamic_cast
57enum DisplayClass {
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +053058 DISPLAY_CLASS_BUILTIN,
59 DISPLAY_CLASS_PLUGGABLE,
Naseer Ahmedb92e73f2016-03-12 02:03:48 -050060 DISPLAY_CLASS_VIRTUAL,
61 DISPLAY_CLASS_NULL
62};
63
Sushil Chauhan0a1b15d2019-08-23 12:58:18 -070064enum {
65 INPUT_LAYER_DUMP,
66 OUTPUT_LAYER_DUMP,
67};
68
Ramkumar Radhakrishnana38b7602018-03-15 14:49:52 -070069enum SecureSessionType {
70 kSecureDisplay,
71 kSecureCamera,
72 kSecureMax,
73};
74
Dileep Marchyacb2a3a92019-06-21 17:30:50 +053075// CWB client currently using the block
76enum CWBClient {
77 kCWBClientNone, // No client connected
78 kCWBClientFrameDump, // Dump to file
79 kCWBClientColor, // Internal client i.e. Color Manager
80 kCWBClientExternal, // External client calling through private APIs
81 kCWBClientComposer, // Client to HWC i.e. SurfaceFlinger
82};
83
Arun Kumar K.R29cd6582016-05-10 19:12:45 -070084class HWCColorMode {
85 public:
86 explicit HWCColorMode(DisplayInterface *display_intf);
87 ~HWCColorMode() {}
88 HWC2::Error Init();
89 HWC2::Error DeInit();
Naseer Ahmed913502b2017-04-18 16:05:05 -040090 void Dump(std::ostringstream* os);
Arun Kumar K.R29cd6582016-05-10 19:12:45 -070091 uint32_t GetColorModeCount();
Naseer Ahmede7a77982018-06-04 10:56:04 -040092 uint32_t GetRenderIntentCount(ColorMode mode);
93 HWC2::Error GetColorModes(uint32_t *out_num_modes, ColorMode *out_modes);
94 HWC2::Error GetRenderIntents(ColorMode mode, uint32_t *out_num_intents, RenderIntent *out_modes);
95 HWC2::Error SetColorModeWithRenderIntent(ColorMode mode, RenderIntent intent);
Naseer Ahmed6776dae2017-05-09 11:49:41 -040096 HWC2::Error SetColorModeById(int32_t color_mode_id);
Xu Yang84e61412018-12-06 14:52:16 +080097 HWC2::Error SetColorModeFromClientApi(std::string mode_string);
Arun Kumar K.R29cd6582016-05-10 19:12:45 -070098 HWC2::Error SetColorTransform(const float *matrix, android_color_transform_t hint);
Ch Ganesh Kumar5d43ff62017-10-13 19:01:47 +053099 HWC2::Error RestoreColorTransform();
Gousemoodhin Nadaf839f29d2018-06-04 10:56:04 -0400100 ColorMode GetCurrentColorMode() { return current_color_mode_; }
Xu Yang84e61412018-12-06 14:52:16 +0800101 HWC2::Error ApplyCurrentColorModeWithRenderIntent(bool hdr_present);
Sushil Chauhan8008d602018-09-04 14:43:27 -0700102 HWC2::Error CacheColorModeWithRenderIntent(ColorMode mode, RenderIntent intent);
Arun Kumar K.R29cd6582016-05-10 19:12:45 -0700103
104 private:
105 static const uint32_t kColorTransformMatrixCount = 16;
Arun Kumar K.R29cd6582016-05-10 19:12:45 -0700106 void PopulateColorModes();
Arun Kumar K.R29cd6582016-05-10 19:12:45 -0700107 template <class T>
108 void CopyColorTransformMatrix(const T *input_matrix, double *output_matrix) {
109 for (uint32_t i = 0; i < kColorTransformMatrixCount; i++) {
110 output_matrix[i] = static_cast<double>(input_matrix[i]);
111 }
112 }
Qing Huang3f21afb2017-04-19 15:11:49 +0800113 HWC2::Error ApplyDefaultColorMode();
Sushil Chauhan8008d602018-09-04 14:43:27 -0700114 HWC2::Error ValidateColorModeWithRenderIntent(ColorMode mode, RenderIntent intent);
Xu Yang84e61412018-12-06 14:52:16 +0800115 HWC2::Error SetPreferredColorModeInternal(const std::string &mode_string, bool from_client,
116 ColorMode *color_mode, DynamicRangeType *dynamic_range);
Arun Kumar K.R29cd6582016-05-10 19:12:45 -0700117
118 DisplayInterface *display_intf_ = NULL;
Sushil Chauhan7cd110d2018-08-24 17:17:55 -0700119 bool apply_mode_ = false;
Naseer Ahmede7a77982018-06-04 10:56:04 -0400120 ColorMode current_color_mode_ = ColorMode::NATIVE;
121 RenderIntent current_render_intent_ = RenderIntent::COLORIMETRIC;
Xu Yang84e61412018-12-06 14:52:16 +0800122 DynamicRangeType curr_dynamic_range_ = kSdrType;
123 typedef std::map<DynamicRangeType, std::string> DynamicRangeMap;
124 typedef std::map<RenderIntent, DynamicRangeMap> RenderIntentMap;
125 // Initialize supported mode/render intent/dynamic range combination
Naseer Ahmede7a77982018-06-04 10:56:04 -0400126 std::map<ColorMode, RenderIntentMap> color_mode_map_ = {};
Naseer Ahmed7dcd1372017-05-19 18:06:51 -0400127 double color_matrix_[kColorTransformMatrixCount] = { 1.0, 0.0, 0.0, 0.0, \
128 0.0, 1.0, 0.0, 0.0, \
129 0.0, 0.0, 1.0, 0.0, \
130 0.0, 0.0, 0.0, 1.0 };
Xu Yang84e61412018-12-06 14:52:16 +0800131 std::map<ColorMode, DynamicRangeMap> preferred_mode_ = {};
Arun Kumar K.R29cd6582016-05-10 19:12:45 -0700132};
133
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500134class HWCDisplay : public DisplayEventHandler {
135 public:
Dileep Marchya6860b2b2017-04-07 15:56:47 +0530136 enum DisplayStatus {
137 kDisplayStatusInvalid = -1,
138 kDisplayStatusOffline,
139 kDisplayStatusOnline,
140 kDisplayStatusPause,
141 kDisplayStatusResume,
142 };
143
Sushil Chauhane3a9fd02017-10-12 18:00:05 -0700144 enum DisplayValidateState {
145 kNormalValidate,
146 kInternalValidate,
147 kSkipValidate,
148 };
149
Srinivas Pullakavi3c4337f2019-07-03 11:24:31 +0530150 struct HWCLayerStack {
151 HWCLayer *client_target = nullptr; // Also known as framebuffer target
152 std::map<hwc2_layer_t, HWCLayer *> layer_map; // Look up by Id - TODO
153 std::multiset<HWCLayer *, SortLayersByZ> layer_set; // Maintain a set sorted by Z
154 };
155
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500156 virtual ~HWCDisplay() {}
157 virtual int Init();
158 virtual int Deinit();
159
160 // Framebuffer configurations
161 virtual void SetIdleTimeoutMs(uint32_t timeout_ms);
Sushil Chauhan267a6192018-06-06 18:41:47 -0700162 virtual HWC2::Error SetFrameDumpConfig(uint32_t count, uint32_t bit_mask_layer_type,
163 int32_t format, bool post_processed);
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500164 virtual DisplayError SetMaxMixerStages(uint32_t max_mixer_stages);
Arun Kumar K.R17bbd042016-06-07 17:38:02 -0700165 virtual DisplayError ControlPartialUpdate(bool enable, uint32_t *pending) {
166 return kErrorNotSupported;
167 }
Varun Aroraf027a222018-11-14 17:38:16 -0800168 virtual HWC2::PowerMode GetCurrentPowerMode();
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500169 virtual int SetFrameBufferResolution(uint32_t x_pixels, uint32_t y_pixels);
170 virtual void GetFrameBufferResolution(uint32_t *x_pixels, uint32_t *y_pixels);
Dileep Marchya6860b2b2017-04-07 15:56:47 +0530171 virtual int SetDisplayStatus(DisplayStatus display_status);
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500172 virtual int OnMinHdcpEncryptionLevelChange(uint32_t min_enc_level);
173 virtual int Perform(uint32_t operation, ...);
Ramkumar Radhakrishnana38b7602018-03-15 14:49:52 -0700174 virtual int HandleSecureSession(const std::bitset<kSecureMax> &secure_sessions,
175 bool *power_on_pending);
176 virtual int GetActiveSecureSession(std::bitset<kSecureMax> *secure_sessions);
Arun Kumar K.R8da7f502016-06-07 17:45:50 -0700177 virtual DisplayError SetMixerResolution(uint32_t width, uint32_t height);
178 virtual DisplayError GetMixerResolution(uint32_t *width, uint32_t *height);
179 virtual void GetPanelResolution(uint32_t *width, uint32_t *height);
Saurabh Shah9c224a32017-11-09 12:17:44 -0800180 virtual std::string Dump();
Gurpreet Singh Dhami1207e462018-12-27 20:02:02 -0500181 virtual DisplayError TeardownConcurrentWriteback(void) {
182 return kErrorNotSupported;
183 }
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500184
185 // Captures frame output in the buffer specified by output_buffer_info. The API is
186 // non-blocking and the client is expected to check operation status later on.
187 // Returns -1 if the input is invalid.
188 virtual int FrameCaptureAsync(const BufferInfo &output_buffer_info, bool post_processed) {
189 return -1;
190 }
Sushil Chauhan1d3b90c2018-12-11 16:52:35 -0800191 // Returns the status of frame capture operation requested with FrameCaptureAsync().
192 // -EAGAIN : No status obtain yet, call API again after another frame.
193 // < 0 : Operation happened but failed.
194 // 0 : Success.
195 virtual int GetFrameCaptureStatus() { return -EAGAIN; }
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500196
Alan Kwong2e136332016-08-16 07:50:16 -0400197 virtual DisplayError SetDetailEnhancerConfig(const DisplayDetailEnhancerData &de_data) {
198 return kErrorNotSupported;
199 }
Sushil Chauhan06521582018-03-19 14:00:23 -0700200 virtual HWC2::Error SetReadbackBuffer(const native_handle_t *buffer, int32_t acquire_fence,
Dileep Marchyacb2a3a92019-06-21 17:30:50 +0530201 bool post_processed_output, CWBClient client) {
Sushil Chauhan06521582018-03-19 14:00:23 -0700202 return HWC2::Error::Unsupported;
203 }
204 virtual HWC2::Error GetReadbackBufferFence(int32_t *release_fence) {
205 return HWC2::Error::Unsupported;
206 }
Alan Kwong2e136332016-08-16 07:50:16 -0400207
Yuchao Ma577f0f72018-07-09 11:20:00 +0800208 virtual HWC2::Error SetDisplayDppsAdROI(uint32_t h_start, uint32_t h_end,
209 uint32_t v_start, uint32_t v_end,
210 uint32_t factor_in, uint32_t factor_out) {
211 return HWC2::Error::Unsupported;
212 }
Xu Yang9dacc872018-12-25 11:04:28 +0800213 virtual HWC2::Error SetFrameTriggerMode(uint32_t mode) {
214 return HWC2::Error::Unsupported;
215 }
Yuchao Ma577f0f72018-07-09 11:20:00 +0800216
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500217 // Display Configurations
Mahesh Aiaf3a1f992019-01-16 13:07:42 -0800218 static uint32_t GetThrottlingRefreshRate() { return HWCDisplay::throttling_refresh_rate_; }
219 static void SetThrottlingRefreshRate(uint32_t newRefreshRate)
220 { HWCDisplay::throttling_refresh_rate_ = newRefreshRate; }
Dileep Marchya6860b2b2017-04-07 15:56:47 +0530221 virtual int SetActiveDisplayConfig(uint32_t config);
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500222 virtual int GetActiveDisplayConfig(uint32_t *config);
223 virtual int GetDisplayConfigCount(uint32_t *count);
Arun Kumar K.R8da7f502016-06-07 17:45:50 -0700224 virtual int GetDisplayAttributesForConfig(int config,
225 DisplayConfigVariableInfo *display_attributes);
Dileep Marchyad16da3e2017-05-20 01:56:21 +0530226 virtual int SetState(bool connected) {
227 return kErrorNotSupported;
228 }
Rajavenu Kyatham0987b0e2018-02-14 18:59:26 +0530229 virtual DisplayError Flush() {
230 return kErrorNotSupported;
231 }
232
Mahesh Aiaf3a1f992019-01-16 13:07:42 -0800233 uint32_t GetMaxRefreshRate() { return max_refresh_rate_; }
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500234 int ToggleScreenUpdates(bool enable);
235 int ColorSVCRequestRoute(const PPDisplayAPIPayload &in_payload, PPDisplayAPIPayload *out_payload,
236 PPPendingParams *pending_action);
Arun Kumar K.R536c7d62016-06-14 18:47:39 -0700237 void SolidFillPrepare();
238 void SolidFillCommit();
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500239 DisplayClass GetDisplayClass();
240 int GetVisibleDisplayRect(hwc_rect_t *rect);
241 void BuildLayerStack(void);
Arun Kumar K.R536c7d62016-06-14 18:47:39 -0700242 void BuildSolidFillStack(void);
Varun Arora2c23e582017-10-10 15:07:13 -0700243 HWCLayer *GetHWCLayer(hwc2_layer_t layer_id);
Saurabh Shaha307e8c2017-09-28 18:05:40 -0700244 void ResetValidation() { validated_ = false; }
Sushil Chauhan409e8442017-06-12 17:43:25 -0700245 uint32_t GetGeometryChanges() { return geometry_changes_; }
Sushil Chauhane3a9fd02017-10-12 18:00:05 -0700246 bool CanSkipValidate();
Sushil Chauhane3a9fd02017-10-12 18:00:05 -0700247 bool IsSkipValidateState() { return (validate_state_ == kSkipValidate); }
248 bool IsInternalValidateState() { return (validated_ && (validate_state_ == kInternalValidate)); }
249 void SetValidationState(DisplayValidateState state) { validate_state_ = state; }
Sushil Chauhanfea3e902018-07-31 15:34:48 -0700250 ColorMode GetCurrentColorMode() {
251 return (color_mode_ ? color_mode_->GetCurrentColorMode() : ColorMode::SRGB);
252 }
Sushil Chauhan181d9502018-12-13 16:40:58 -0800253 bool HWCClientNeedsValidate() {
254 return (has_client_composition_ || layer_stack_.flags.single_buffered_layer_present);
255 }
Sushil Chauhan9c07ad02019-02-28 12:07:35 -0800256 virtual void SetFastPathComposition(bool enable) { fast_path_composition_ = enable; }
Xu Yang84e61412018-12-06 14:52:16 +0800257 virtual HWC2::Error SetColorModeFromClientApi(int32_t color_mode_id) {
258 return HWC2::Error::Unsupported;
259 }
Mathew Joseph Karimpanalabe3b3d2018-11-27 17:25:40 +0530260 bool IsFirstCommitDone() { return !first_cycle_; }
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500261
262 // HWC2 APIs
263 virtual HWC2::Error AcceptDisplayChanges(void);
264 virtual HWC2::Error GetActiveConfig(hwc2_config_t *out_config);
265 virtual HWC2::Error SetActiveConfig(hwc2_config_t config);
Archit Srivastavaa59c4ff2019-05-20 10:54:22 +0530266 virtual HWC2::Error SetPanelLuminanceAttributes(float min_lum, float max_lum) {
267 return HWC2::Error::Unsupported;
268 }
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500269 virtual HWC2::Error SetClientTarget(buffer_handle_t target, int32_t acquire_fence,
Naseer Ahmeda20c4c02016-06-03 17:48:28 -0400270 int32_t dataspace, hwc_region_t damage);
Naseer Ahmede7a77982018-06-04 10:56:04 -0400271 virtual HWC2::Error SetColorMode(ColorMode mode) { return HWC2::Error::Unsupported; }
272 virtual HWC2::Error SetColorModeWithRenderIntent(ColorMode mode, RenderIntent intent) {
Arun Kumar K.R29cd6582016-05-10 19:12:45 -0700273 return HWC2::Error::Unsupported;
274 }
Naseer Ahmed6776dae2017-05-09 11:49:41 -0400275 virtual HWC2::Error SetColorModeById(int32_t color_mode_id) {
276 return HWC2::Error::Unsupported;
277 }
Ch Ganesh Kumar5d43ff62017-10-13 19:01:47 +0530278 virtual HWC2::Error RestoreColorTransform() {
279 return HWC2::Error::Unsupported;
280 }
Arun Kumar K.R29cd6582016-05-10 19:12:45 -0700281 virtual HWC2::Error SetColorTransform(const float *matrix, android_color_transform_t hint) {
282 return HWC2::Error::Unsupported;
283 }
Naseer Ahmedeae28122016-06-27 15:47:05 -0400284 virtual HWC2::Error HandleColorModeTransform(android_color_mode_t mode,
Arun Kumar K.R29cd6582016-05-10 19:12:45 -0700285 android_color_transform_t hint,
286 const double *matrix) {
287 return HWC2::Error::Unsupported;
288 }
Pullakavi Srinivas9189e602018-12-19 16:58:07 +0530289 virtual DisplayError SetDynamicDSIClock(uint64_t bitclk) {
290 return kErrorNotSupported;
291 }
292 virtual DisplayError GetDynamicDSIClock(uint64_t *bitclk) {
293 return kErrorNotSupported;
294 }
295 virtual DisplayError GetSupportedDSIClock(std::vector<uint64_t> *bitclk) {
296 return kErrorNotSupported;
297 }
Padmanabhan Komandurue74cf4f2019-04-25 17:38:43 -0700298 virtual HWC2::Error UpdateDisplayId(hwc2_display_t id) {
299 return HWC2::Error::Unsupported;
300 }
301 virtual HWC2::Error SetPendingRefresh() {
302 return HWC2::Error::Unsupported;
303 }
Varun Arora75c05f02019-05-14 14:53:37 -0700304 virtual HWC2::Error SetPanelBrightness(float brightness) {
305 return HWC2::Error::Unsupported;
306 }
307 virtual HWC2::Error GetPanelBrightness(float *brightness) {
308 return HWC2::Error::Unsupported;
309 }
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500310 virtual HWC2::Error GetDisplayConfigs(uint32_t *out_num_configs, hwc2_config_t *out_configs);
311 virtual HWC2::Error GetDisplayAttribute(hwc2_config_t config, HWC2::Attribute attribute,
312 int32_t *out_value);
313 virtual HWC2::Error GetClientTargetSupport(uint32_t width, uint32_t height, int32_t format,
314 int32_t dataspace);
Naseer Ahmede7a77982018-06-04 10:56:04 -0400315 virtual HWC2::Error GetColorModes(uint32_t *outNumModes, ColorMode *outModes);
316 virtual HWC2::Error GetRenderIntents(ColorMode mode, uint32_t *out_num_intents,
317 RenderIntent *out_intents);
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500318 virtual HWC2::Error GetChangedCompositionTypes(uint32_t *out_num_elements,
319 hwc2_layer_t *out_layers, int32_t *out_types);
320 virtual HWC2::Error GetDisplayRequests(int32_t *out_display_requests, uint32_t *out_num_elements,
321 hwc2_layer_t *out_layers, int32_t *out_layer_requests);
322 virtual HWC2::Error GetDisplayName(uint32_t *out_size, char *out_name);
323 virtual HWC2::Error GetDisplayType(int32_t *out_type);
324 virtual HWC2::Error SetCursorPosition(hwc2_layer_t layer, int x, int y);
325 virtual HWC2::Error SetVsyncEnabled(HWC2::Vsync enabled);
Varun Arora78580b82018-09-10 13:59:57 -0700326 virtual HWC2::Error SetPowerMode(HWC2::PowerMode mode, bool teardown);
Srinivas Pullakavi3c4337f2019-07-03 11:24:31 +0530327 virtual HWC2::Error UpdatePowerMode(HWC2::PowerMode mode) {
328 return HWC2::Error::None;
329 }
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500330 virtual HWC2::Error CreateLayer(hwc2_layer_t *out_layer_id);
331 virtual HWC2::Error DestroyLayer(hwc2_layer_t layer_id);
332 virtual HWC2::Error SetLayerZOrder(hwc2_layer_t layer_id, uint32_t z);
333 virtual HWC2::Error Validate(uint32_t *out_num_types, uint32_t *out_num_requests) = 0;
334 virtual HWC2::Error GetReleaseFences(uint32_t *out_num_elements, hwc2_layer_t *out_layers,
335 int32_t *out_fences);
336 virtual HWC2::Error Present(int32_t *out_retire_fence) = 0;
Arun Kumar K.Rf28957a2017-01-10 17:36:52 -0800337 virtual HWC2::Error GetHdrCapabilities(uint32_t *out_num_types, int32_t* out_types,
338 float* out_max_luminance,
339 float* out_max_average_luminance,
340 float* out_min_luminance);
Naseer Ahmeda6782e42018-06-04 10:56:04 -0400341 virtual HWC2::Error GetPerFrameMetadataKeys(uint32_t *out_num_keys,
342 PerFrameMetadataKey *out_keys);
Naseer Ahmeda699e792017-11-09 15:08:31 -0500343 virtual HWC2::Error SetDisplayAnimating(bool animating) {
344 animating_ = animating;
Ramkumar Radhakrishnanae338ae2017-11-27 21:27:25 -0800345 validated_ = false;
Naseer Ahmeda699e792017-11-09 15:08:31 -0500346 return HWC2::Error::None;
347 }
Sushil Chauhane3a9fd02017-10-12 18:00:05 -0700348 virtual HWC2::Error GetValidateDisplayOutput(uint32_t *out_num_types, uint32_t *out_num_requests);
Ramkumar Radhakrishnana38b7602018-03-15 14:49:52 -0700349 virtual bool IsDisplayCommandMode();
Sushil Chauhan380a59d2018-03-19 15:47:50 -0700350 virtual HWC2::Error SetQSyncMode(QSyncMode qsync_mode) {
351 return HWC2::Error::Unsupported;
352 }
Ramkumar Radhakrishnan4faf8a62018-11-15 17:15:37 -0800353 virtual DisplayError ControlIdlePowerCollapse(bool enable, bool synchronous) {
354 return kErrorNone;
Ramkumar Radhakrishnanf985d482018-07-23 18:10:41 -0700355 }
Varun Arora6ba9eda2019-02-07 17:59:32 -0800356 virtual HWC2::Error GetDisplayIdentificationData(uint8_t *out_port, uint32_t *out_data_size,
357 uint8_t *out_data);
Xu Yang45d0abf2019-07-05 11:34:06 +0800358 virtual HWC2::Error SetBLScale(uint32_t level) {
359 return HWC2::Error::Unsupported;
360 }
Srinivas Pullakavi3c4337f2019-07-03 11:24:31 +0530361 virtual void GetLayerStack(HWCLayerStack *stack);
362 virtual void SetLayerStack(HWCLayerStack *stack);
363 virtual void PostPowerMode();
Mathew Joseph Karimpanalb1c15862019-07-04 11:14:24 +0530364 virtual HWC2::PowerMode GetPendingPowerMode() {
365 return pending_power_mode_;
366 };
367 virtual void ClearPendingPowerMode() {
368 pending_power_mode_ = current_power_mode_;
369 };
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500370
371 protected:
Mahesh Aiaf3a1f992019-01-16 13:07:42 -0800372 static uint32_t throttling_refresh_rate_;
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500373 // Maximum number of layers supported by display manager.
374 static const uint32_t kMaxLayerCount = 32;
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +0530375 HWCDisplay(CoreInterface *core_intf, BufferAllocator *buffer_allocator, HWCCallbacks *callbacks,
376 HWCDisplayEventHandler *event_handler, qService::QService *qservice, DisplayType type,
Gousemoodhin Nadaf087c3102019-01-07 19:34:56 +0530377 hwc2_display_t id, int32_t sdm_id, DisplayClass display_class);
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500378
379 // DisplayEventHandler methods
380 virtual DisplayError VSync(const DisplayEventVSync &vsync);
381 virtual DisplayError Refresh();
382 virtual DisplayError CECMessage(char *message);
Sushil Chauhan409e8442017-06-12 17:43:25 -0700383 virtual DisplayError HandleEvent(DisplayEvent event);
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500384 virtual void DumpOutputBuffer(const BufferInfo &buffer_info, void *base, int fence);
385 virtual HWC2::Error PrepareLayerStack(uint32_t *out_num_types, uint32_t *out_num_requests);
386 virtual HWC2::Error CommitLayerStack(void);
387 virtual HWC2::Error PostCommitLayerStack(int32_t *out_retire_fence);
Arun Kumar K.R17bbd042016-06-07 17:38:02 -0700388 virtual DisplayError DisablePartialUpdateOneFrame() {
389 return kErrorNotSupported;
390 }
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500391 const char *GetDisplayString();
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500392 void MarkLayersForGPUBypass(void);
Arun Kumar K.R29cd6582016-05-10 19:12:45 -0700393 void MarkLayersForClientComposition(void);
Pullakavi Srinivas9189e602018-12-19 16:58:07 +0530394 void UpdateConfigs();
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500395 virtual void ApplyScanAdjustment(hwc_rect_t *display_frame);
Ramakant Singh5db0dfb2017-08-23 12:34:57 +0530396 uint32_t GetUpdatingLayersCount(void);
Sushil Chauhan9735cf82018-07-10 12:06:01 -0700397 bool IsLayerUpdating(HWCLayer *layer);
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500398 uint32_t SanitizeRefreshRate(uint32_t req_refresh_rate);
Sushil Chauhan409e8442017-06-12 17:43:25 -0700399 virtual void GetUnderScanConfig() { }
Arun Kumar K.R5b821552018-12-07 08:00:15 +0530400 int32_t SetClientTargetDataSpace(int32_t dataspace);
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500401
Saurabh Shaha307e8c2017-09-28 18:05:40 -0700402 bool validated_ = false;
Saurabh Shahdccc0f42018-01-15 15:59:56 -0800403 bool layer_stack_invalid_ = true;
Naseer Ahmed72dea242016-05-03 19:13:07 -0400404 CoreInterface *core_intf_ = nullptr;
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +0530405 HWCBufferAllocator *buffer_allocator_ = NULL;
Naseer Ahmed72dea242016-05-03 19:13:07 -0400406 HWCCallbacks *callbacks_ = nullptr;
Varun Arora7c8ee542018-05-01 20:58:16 -0700407 HWCDisplayEventHandler *event_handler_ = nullptr;
Dileep Marchyaf3ce11f2018-04-30 23:35:46 +0530408 DisplayType type_ = kDisplayTypeMax;
409 hwc2_display_t id_ = UINT64_MAX;
410 int32_t sdm_id_ = -1;
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500411 DisplayInterface *display_intf_ = NULL;
412 LayerStack layer_stack_;
Naseer Ahmed72dea242016-05-03 19:13:07 -0400413 HWCLayer *client_target_ = nullptr; // Also known as framebuffer target
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500414 std::map<hwc2_layer_t, HWCLayer *> layer_map_; // Look up by Id - TODO
415 std::multiset<HWCLayer *, SortLayersByZ> layer_set_; // Maintain a set sorted by Z
416 std::map<hwc2_layer_t, HWC2::Composition> layer_changes_;
417 std::map<hwc2_layer_t, HWC2::LayerRequest> layer_requests_;
418 bool flush_on_error_ = false;
419 bool flush_ = false;
420 uint32_t dump_frame_count_ = 0;
421 uint32_t dump_frame_index_ = 0;
422 bool dump_input_layers_ = false;
Varun Aroraf027a222018-11-14 17:38:16 -0800423 HWC2::PowerMode current_power_mode_ = HWC2::PowerMode::Off;
Mathew Joseph Karimpanalb1c15862019-07-04 11:14:24 +0530424 HWC2::PowerMode pending_power_mode_ = HWC2::PowerMode::Off;
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500425 bool swap_interval_zero_ = false;
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500426 bool display_paused_ = false;
427 uint32_t min_refresh_rate_ = 0;
428 uint32_t max_refresh_rate_ = 0;
429 uint32_t current_refresh_rate_ = 0;
430 bool use_metadata_refresh_rate_ = false;
431 uint32_t metadata_refresh_rate_ = 0;
432 uint32_t force_refresh_rate_ = 0;
433 bool boot_animation_completed_ = false;
434 bool shutdown_pending_ = false;
Ramkumar Radhakrishnana38b7602018-03-15 14:49:52 -0700435 std::bitset<kSecureMax> active_secure_sessions_ = 0;
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500436 bool solid_fill_enable_ = false;
Arun Kumar K.R536c7d62016-06-14 18:47:39 -0700437 Layer *solid_fill_layer_ = NULL;
438 LayerRect solid_fill_rect_ = {};
Gopikrishnaiah Anandancc123062017-07-31 17:21:03 -0700439 LayerSolidFill solid_fill_color_ = {};
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500440 LayerRect display_rect_;
Arun Kumar K.R29cd6582016-05-10 19:12:45 -0700441 bool color_tranform_failed_ = false;
442 HWCColorMode *color_mode_ = NULL;
Arun Kumar K.R51be3d12017-03-31 19:54:38 -0700443 HWCToneMapper *tone_mapper_ = nullptr;
Rajavenu Kyatham40fc5382017-07-12 18:36:55 +0530444 uint32_t num_configs_ = 0;
Arun Kumar K.R2be0bf82017-05-24 15:14:41 +0530445 int disable_hdr_handling_ = 0; // disables HDR handling.
Namit Solanki5b428dc2018-02-27 11:39:05 +0530446 bool pending_commit_ = false;
Tharaga Balachandran04192a62018-08-29 16:23:25 -0400447 bool is_cmd_mode_ = false;
448 bool partial_update_enabled_ = false;
Sushil Chauhan7bd20662018-08-20 17:51:32 -0700449 bool fast_path_composition_ = false;
Padmanabhan Komandurue74cf4f2019-04-25 17:38:43 -0700450 bool skip_commit_ = false;
Pullakavi Srinivas9189e602018-12-19 16:58:07 +0530451 std::map<uint32_t, DisplayConfigVariableInfo> variable_config_map_;
452 std::vector<uint32_t> hwc_config_map_;
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500453
454 private:
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500455 void DumpInputBuffers(void);
Sushil Chauhan36c059a2018-06-28 11:39:01 -0700456 bool CanSkipSdmPrepare(uint32_t *num_types, uint32_t *num_requests);
Pullakavi Srinivas3dbb0d92018-03-07 15:15:14 +0530457 void UpdateRefreshRate();
Rajavenu Kyathamaf26f402019-02-13 15:04:03 +0530458 void WaitOnPreviousFence();
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500459 qService::QService *qservice_ = NULL;
460 DisplayClass display_class_;
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500461 uint32_t geometry_changes_ = GeometryChanges::kNone;
Naseer Ahmeda699e792017-11-09 15:08:31 -0500462 bool animating_ = false;
Varun Arora465c1f72018-02-08 16:18:50 -0800463 int null_display_mode_ = 0;
Sushil Chauhane3a9fd02017-10-12 18:00:05 -0700464 bool has_client_composition_ = false;
465 DisplayValidateState validate_state_ = kNormalValidate;
Sushil Chauhan7bd20662018-08-20 17:51:32 -0700466 bool fast_path_enabled_ = true;
Mathew Joseph Karimpanalabe3b3d2018-11-27 17:25:40 +0530467 bool first_cycle_ = true; // false if a display commit has succeeded on the device.
Rajavenu Kyatham9d509582019-02-13 15:29:55 +0530468 int fbt_release_fence_ = -1;
Srinivas Pullakavi3c4337f2019-07-03 11:24:31 +0530469 int release_fence_ = -1;
Naseer Ahmedb92e73f2016-03-12 02:03:48 -0500470};
471
472inline int HWCDisplay::Perform(uint32_t operation, ...) {
473 return 0;
474}
475
476} // namespace sdm
477
478#endif // __HWC_DISPLAY_H__