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_SESSION_H__
21 #define __HWC_SESSION_H__
22 
23 #include <vendor/qti/hardware/display/composer/3.0/IQtiComposerClient.h>
24 #include <config/device_interface.h>
25 
26 #include <core/core_interface.h>
27 #include <utils/locker.h>
28 #include <qd_utils.h>
29 #include <display_config.h>
30 #include <vector>
31 #include <queue>
32 #include <utility>
33 #include <future>   // NOLINT
34 #include <map>
35 #include <string>
36 
37 #include "hwc_callbacks.h"
38 #include "hwc_layers.h"
39 #include "hwc_display.h"
40 #include "hwc_display_builtin.h"
41 #include "hwc_display_pluggable.h"
42 #include "hwc_display_dummy.h"
43 #include "hwc_display_virtual.h"
44 #include "hwc_display_pluggable_test.h"
45 #include "hwc_color_manager.h"
46 #include "hwc_socket_handler.h"
47 #include "hwc_display_event_handler.h"
48 #include "hwc_buffer_sync_handler.h"
49 #include "hwc_display_virtual_factory.h"
50 
51 using ::android::hardware::Return;
52 using ::android::hardware::hidl_string;
53 using android::hardware::hidl_handle;
54 using ::android::sp;
55 using ::android::hardware::Void;
56 namespace composer_V2_4 = ::android::hardware::graphics::composer::V2_4;
57 using HwcDisplayCapability = composer_V2_4::IComposerClient::DisplayCapability;
58 using HwcDisplayConnectionType = composer_V2_4::IComposerClient::DisplayConnectionType;
59 
60 namespace sdm {
61 
62 using vendor::qti::hardware::display::composer::V3_0::IQtiComposerClient;
63 int32_t GetDataspaceFromColorMode(ColorMode mode);
64 
65 typedef DisplayConfig::DisplayType DispType;
66 #ifdef DISPLAY_CONFIG_CAMERA_SMOOTH_APIs_1_0
67 typedef DisplayConfig::CameraSmoothOp CameraSmoothOp;
68 #endif
69 
70 // Create a singleton uevent listener thread valid for life of hardware composer process.
71 // This thread blocks on uevents poll inside uevent library implementation. This poll exits
72 // only when there is a valid uevent, it can not be interrupted otherwise. Tieing life cycle
73 // of this thread with HWC session cause HWC deinitialization to wait infinitely for the
74 // thread to exit.
75 class HWCUEventListener {
76  public:
~HWCUEventListener()77   virtual ~HWCUEventListener() {}
78   virtual void UEventHandler(const char *uevent_data, int length) = 0;
79 };
80 
81 class HWCUEvent {
82  public:
83   HWCUEvent();
84   static void UEventThread(HWCUEvent *hwc_event);
85   void Register(HWCUEventListener *uevent_listener);
InitDone()86   inline bool InitDone() { return init_done_; }
87 
88  private:
89   std::mutex mutex_;
90   std::condition_variable caller_cv_;
91   HWCUEventListener *uevent_listener_ = nullptr;
92   bool init_done_ = false;
93 };
94 
95 constexpr int32_t kDataspaceSaturationMatrixCount = 16;
96 constexpr int32_t kDataspaceSaturationPropertyElements = 9;
97 constexpr int32_t kPropertyMax = 256;
98 
99 class HWCSession : hwc2_device_t, HWCUEventListener, public qClient::BnQClient,
100                    public HWCDisplayEventHandler, public DisplayConfig::ClientContext {
101  public:
102   enum HotPlugEvent {
103     kHotPlugNone,
104     kHotPlugEvent,
105   };
106 
107   HWCSession();
108   int Init();
109   int Deinit();
110   HWC2::Error CreateVirtualDisplayObj(uint32_t width, uint32_t height, int32_t *format,
111                                       hwc2_display_t *out_display_id);
112 
113   template <typename... Args>
CallDisplayFunction(hwc2_display_t display,HWC2::Error (HWCDisplay::* member)(Args...),Args...args)114   int32_t CallDisplayFunction(hwc2_display_t display, HWC2::Error (HWCDisplay::*member)(Args...),
115                               Args... args) {
116     if (display >= HWCCallbacks::kNumDisplays) {
117       return HWC2_ERROR_BAD_DISPLAY;
118     }
119 
120     {
121       // Power state transition start.
122       SCOPE_LOCK(power_state_[display]);
123       if (power_state_transition_[display]) {
124         display = map_hwc_display_.find(display)->second;
125       }
126     }
127 
128     SCOPE_LOCK(locker_[display]);
129     auto status = HWC2::Error::BadDisplay;
130     if (hwc_display_[display]) {
131       auto hwc_display = hwc_display_[display];
132       status = (hwc_display->*member)(std::forward<Args>(args)...);
133     }
134     return INT32(status);
135   }
136 
137   template <typename... Args>
CallLayerFunction(hwc2_display_t display,hwc2_layer_t layer,HWC2::Error (HWCLayer::* member)(Args...),Args...args)138   int32_t CallLayerFunction(hwc2_display_t display, hwc2_layer_t layer,
139                             HWC2::Error (HWCLayer::*member)(Args...), Args... args) {
140     if (display >= HWCCallbacks::kNumDisplays) {
141       return HWC2_ERROR_BAD_DISPLAY;
142     }
143 
144     {
145       // Power state transition start.
146       SCOPE_LOCK(power_state_[display]);
147       if (power_state_transition_[display]) {
148         display = map_hwc_display_.find(display)->second;
149       }
150     }
151 
152     SCOPE_LOCK(locker_[display]);
153     auto status = HWC2::Error::BadDisplay;
154     if (hwc_display_[display]) {
155       status = HWC2::Error::BadLayer;
156       auto hwc_layer = hwc_display_[display]->GetHWCLayer(layer);
157       if (hwc_layer != nullptr) {
158         status = (hwc_layer->*member)(std::forward<Args>(args)...);
159         if (hwc_display_[display]->GetGeometryChanges()) {
160           hwc_display_[display]->ResetValidation();
161         }
162       }
163     }
164     return INT32(status);
165   }
166 
167   // HWC2 Functions that require a concrete implementation in hwc session
168   // and hence need to be member functions
169   static HWCSession *GetInstance();
170   void GetCapabilities(uint32_t *outCount, int32_t *outCapabilities);
171   void Dump(uint32_t *out_size, char *out_buffer);
172 
173   int32_t AcceptDisplayChanges(hwc2_display_t display);
174   int32_t CreateLayer(hwc2_display_t display, hwc2_layer_t *out_layer_id);
175   int32_t CreateVirtualDisplay(uint32_t width, uint32_t height, int32_t *format,
176                                hwc2_display_t *out_display_id);
177   int32_t DestroyLayer(hwc2_display_t display, hwc2_layer_t layer);
178   int32_t DestroyVirtualDisplay(hwc2_display_t display);
179   int32_t PresentDisplay(hwc2_display_t display, shared_ptr<Fence> *out_retire_fence);
180   void RegisterCallback(int32_t descriptor, hwc2_callback_data_t callback_data,
181                         hwc2_function_pointer_t pointer);
182   int32_t SetOutputBuffer(hwc2_display_t display, buffer_handle_t buffer,
183                           const shared_ptr<Fence> &release_fence);
184   int32_t SetPowerMode(hwc2_display_t display, int32_t int_mode);
185   int32_t ValidateDisplay(hwc2_display_t display, uint32_t *out_num_types,
186                           uint32_t *out_num_requests);
187   int32_t SetColorMode(hwc2_display_t display, int32_t /*ColorMode*/ int_mode);
188   int32_t SetColorModeWithRenderIntent(hwc2_display_t display, int32_t /*ColorMode*/ int_mode,
189                                        int32_t /*RenderIntent*/ int_render_intent);
190   int32_t SetColorTransform(hwc2_display_t display, const float *matrix,
191                             int32_t /*android_color_transform_t*/ hint);
192   int32_t GetReadbackBufferAttributes(hwc2_display_t display,
193                                       int32_t *format, int32_t *dataspace);
194   int32_t SetReadbackBuffer(hwc2_display_t display, const native_handle_t *buffer,
195                             const shared_ptr<Fence> &acquire_fence);
196   int32_t GetReadbackBufferFence(hwc2_display_t display, shared_ptr<Fence> *release_fence);
197   uint32_t GetMaxVirtualDisplayCount();
198   int32_t GetDisplayIdentificationData(hwc2_display_t display, uint8_t *outPort,
199                                        uint32_t *outDataSize, uint8_t *outData);
200   int32_t GetDisplayCapabilities(hwc2_display_t display, uint32_t *outNumCapabilities,
201                                  uint32_t *capabilities);
202   int32_t GetDisplayCapabilities_2_4(hwc2_display_t display, uint32_t *outNumCapabilities,
203                                      uint32_t *capabilities);
204   int32_t GetDisplayCapabilities(hwc2_display_t display,
205                                  hidl_vec<HwcDisplayCapability> *capabilities);
206   int32_t GetDisplayCapabilities2_3(hwc2_display_t display,
207                                     uint32_t *outNumCapabilities, uint32_t *outCapabilities);
208   int32_t GetDisplayBrightnessSupport(hwc2_display_t display, bool *outSupport);
209   int32_t SetDisplayBrightness(hwc2_display_t display, float brightness);
210   void WaitForResources(bool wait_for_resources, hwc2_display_t active_builtin_id,
211                         hwc2_display_t display_id);
212 
213   // newly added
214   int32_t GetDisplayType(hwc2_display_t display, int32_t *out_type);
215   int32_t GetDisplayAttribute(hwc2_display_t display, hwc2_config_t config, HwcAttribute attribute,
216                               int32_t *out_value);
217   int32_t GetActiveConfig(hwc2_display_t display, hwc2_config_t *out_config);
218   int32_t GetColorModes(hwc2_display_t display, uint32_t *out_num_modes,
219                         int32_t /*ColorMode*/ *int_out_modes);
220   int32_t GetRenderIntents(hwc2_display_t display, int32_t /*ColorMode*/ int_mode,
221                            uint32_t *out_num_intents, int32_t /*RenderIntent*/ *int_out_intents);
222   int32_t GetHdrCapabilities(hwc2_display_t display, uint32_t* out_num_types, int32_t* out_types,
223                              float* out_max_luminance, float* out_max_average_luminance,
224                              float* out_min_luminance);
225   int32_t GetPerFrameMetadataKeys(hwc2_display_t display, uint32_t *out_num_keys,
226                                   int32_t *int_out_keys);
227   int32_t GetClientTargetSupport(hwc2_display_t display, uint32_t width, uint32_t height,
228                                  int32_t format, int32_t dataspace);
229   int32_t GetDisplayName(hwc2_display_t display, uint32_t *out_size, char *out_name);
230   int32_t SetActiveConfig(hwc2_display_t display, hwc2_config_t config);
231   int32_t GetChangedCompositionTypes(hwc2_display_t display, uint32_t *out_num_elements,
232                                      hwc2_layer_t *out_layers, int32_t *out_types);
233   int32_t GetDisplayRequests(hwc2_display_t display, int32_t *out_display_requests,
234                              uint32_t *out_num_elements, hwc2_layer_t *out_layers,
235                              int32_t *out_layer_requests);
236   int32_t GetReleaseFences(hwc2_display_t display, uint32_t *out_num_elements,
237                            hwc2_layer_t *out_layers, std::vector<shared_ptr<Fence>> *out_fences);
238   int32_t SetClientTarget(hwc2_display_t display, buffer_handle_t target,
239                           shared_ptr<Fence> acquire_fence,
240                           int32_t dataspace, hwc_region_t damage);
241   int32_t SetCursorPosition(hwc2_display_t display, hwc2_layer_t layer, int32_t x, int32_t y);
242   int32_t GetDataspaceSaturationMatrix(int32_t /*Dataspace*/ int_dataspace, float *out_matrix);
243   int32_t SetDisplayBrightnessScale(const android::Parcel *input_parcel);
244   int32_t GetDisplayConnectionType(hwc2_display_t display, HwcDisplayConnectionType *type);
245 
246   // Layer functions
247   int32_t SetLayerBuffer(hwc2_display_t display, hwc2_layer_t layer, buffer_handle_t buffer,
248                          const shared_ptr<Fence> &acquire_fence);
249   int32_t SetLayerBlendMode(hwc2_display_t display, hwc2_layer_t layer, int32_t int_mode);
250   int32_t SetLayerDisplayFrame(hwc2_display_t display, hwc2_layer_t layer, hwc_rect_t frame);
251   int32_t SetLayerPlaneAlpha(hwc2_display_t display, hwc2_layer_t layer, float alpha);
252   int32_t SetLayerSourceCrop(hwc2_display_t display, hwc2_layer_t layer, hwc_frect_t crop);
253   int32_t SetLayerTransform(hwc2_display_t display, hwc2_layer_t layer, int32_t int_transform);
254   int32_t SetLayerZOrder(hwc2_display_t display, hwc2_layer_t layer, uint32_t z);
255   int32_t SetLayerType(hwc2_display_t display, hwc2_layer_t layer,
256                        IQtiComposerClient::LayerType type);
257   int32_t SetLayerSurfaceDamage(hwc2_display_t display, hwc2_layer_t layer, hwc_region_t damage);
258   int32_t SetLayerVisibleRegion(hwc2_display_t display, hwc2_layer_t layer, hwc_region_t damage);
259   int32_t SetLayerCompositionType(hwc2_display_t display, hwc2_layer_t layer, int32_t int_type);
260   int32_t SetLayerColor(hwc2_display_t display, hwc2_layer_t layer, hwc_color_t color);
261   int32_t SetLayerDataspace(hwc2_display_t display, hwc2_layer_t layer, int32_t dataspace);
262   int32_t SetLayerPerFrameMetadata(hwc2_display_t display, hwc2_layer_t layer,
263                                    uint32_t num_elements, const int32_t *int_keys,
264                                    const float *metadata);
265   int32_t SetLayerColorTransform(hwc2_display_t display, hwc2_layer_t layer, const float *matrix);
266   int32_t SetLayerPerFrameMetadataBlobs(hwc2_display_t display, hwc2_layer_t layer,
267                                         uint32_t num_elements, const int32_t *int_keys,
268                                         const uint32_t *sizes, const uint8_t *metadata);
269   int32_t SetDisplayedContentSamplingEnabled(hwc2_display_t display, int32_t enabled,
270                                              uint8_t component_mask, uint64_t max_frames);
271   int32_t GetDisplayedContentSamplingAttributes(hwc2_display_t display, int32_t *format,
272                                                 int32_t *dataspace, uint8_t *supported_components);
273   int32_t GetDisplayedContentSample(hwc2_display_t display, uint64_t max_frames, uint64_t timestamp,
274                                     uint64_t *numFrames,
275                                     int32_t samples_size[NUM_HISTOGRAM_COLOR_COMPONENTS],
276                                     uint64_t *samples[NUM_HISTOGRAM_COLOR_COMPONENTS]);
277   int32_t SetDisplayElapseTime(hwc2_display_t display, uint64_t time);
278 
279 
280   virtual int RegisterClientContext(std::shared_ptr<DisplayConfig::ConfigCallback> callback,
281                                     DisplayConfig::ConfigInterface **intf);
282   virtual void UnRegisterClientContext(DisplayConfig::ConfigInterface *intf);
283 
284   // HWCDisplayEventHandler
285   virtual void DisplayPowerReset();
286 
287   int32_t SetVsyncEnabled(hwc2_display_t display, int32_t int_enabled);
288   int32_t GetDozeSupport(hwc2_display_t display, int32_t *out_support);
289   int32_t GetDisplayConfigs(hwc2_display_t display, uint32_t *out_num_configs,
290                             hwc2_config_t *out_configs);
291   int32_t GetVsyncPeriod(hwc2_display_t disp, uint32_t *vsync_period);
292   void Refresh(hwc2_display_t display);
293 
294   int32_t GetDisplayVsyncPeriod(hwc2_display_t display, VsyncPeriodNanos *out_vsync_period);
295   int32_t SetActiveConfigWithConstraints(
296       hwc2_display_t display, hwc2_config_t config,
297       const VsyncPeriodChangeConstraints *vsync_period_change_constraints,
298       VsyncPeriodChangeTimeline *out_timeline);
299 
300   int32_t SetAutoLowLatencyMode(hwc2_display_t display, bool on);
301   int32_t GetSupportedContentTypes(hwc2_display_t display, hidl_vec<HwcContentType> *types);
302   int32_t SetContentType(hwc2_display_t display, HwcContentType type);
303 
304   static Locker locker_[HWCCallbacks::kNumDisplays];
305   static Locker power_state_[HWCCallbacks::kNumDisplays];
306   static Locker hdr_locker_[HWCCallbacks::kNumDisplays];
307   static Locker display_config_locker_;
308   static Locker system_locker_;
309 
310   void RegisterDisplayCallback();
311   bool IsHbmSupported();
312   void SetHbmState(HbmState state);
313   HbmState GetHbmState();
314   bool IsLbeSupported();
315   void SetLbeState(LbeState state);
316   void SetLbeAmbientLight(int value);
317   LbeState GetLbeState();
318 
319  private:
320   class CWB {
321    public:
CWB(HWCSession * hwc_session)322     explicit CWB(HWCSession *hwc_session) : hwc_session_(hwc_session) { }
323     void PresentDisplayDone(hwc2_display_t disp_id);
324 
325     int32_t PostBuffer(std::weak_ptr<DisplayConfig::ConfigCallback> callback, bool post_processed,
326                        const native_handle_t *buffer);
327 
328    private:
329     struct QueueNode {
QueueNodeQueueNode330       QueueNode(std::weak_ptr<DisplayConfig::ConfigCallback> cb, bool pp, const hidl_handle& buf)
331         : callback(cb), post_processed(pp), buffer(buf) { }
332 
333       std::weak_ptr<DisplayConfig::ConfigCallback> callback;
334       bool post_processed = false;
335       const native_handle_t *buffer;
336     };
337 
338     void ProcessRequests();
339     static void AsyncTask(CWB *cwb);
340 
341     std::queue<QueueNode *> queue_;
342 
343     std::future<void> future_;
344     Locker queue_lock_;
345     std::mutex mutex_;
346     std::condition_variable cv_;
347     HWCSession *hwc_session_ = nullptr;
348   };
349 
350   class DisplayConfigImpl: public DisplayConfig::ConfigInterface {
351    public:
352     explicit DisplayConfigImpl(std::weak_ptr<DisplayConfig::ConfigCallback> callback,
353                                HWCSession *hwc_session);
354 
355    private:
356     virtual int IsDisplayConnected(DispType dpy, bool *connected);
357     virtual int SetDisplayStatus(DispType dpy, DisplayConfig::ExternalStatus status);
358     virtual int ConfigureDynRefreshRate(DisplayConfig::DynRefreshRateOp op, uint32_t refresh_rate);
359     virtual int GetConfigCount(DispType dpy, uint32_t *count);
360     virtual int GetActiveConfig(DispType dpy, uint32_t *config);
361     virtual int SetActiveConfig(DispType dpy, uint32_t config);
362     virtual int GetDisplayAttributes(uint32_t config_index, DispType dpy,
363                                      DisplayConfig::Attributes *attributes);
364     virtual int SetPanelBrightness(uint32_t level);
365     virtual int GetPanelBrightness(uint32_t *level);
366     virtual int MinHdcpEncryptionLevelChanged(DispType dpy, uint32_t min_enc_level);
367     virtual int RefreshScreen();
368     virtual int ControlPartialUpdate(DispType dpy, bool enable);
369     virtual int ToggleScreenUpdate(bool on);
370     virtual int SetIdleTimeout(uint32_t value);
371     virtual int GetHDRCapabilities(DispType dpy, DisplayConfig::HDRCapsParams *caps);
372     virtual int SetCameraLaunchStatus(uint32_t on);
373     virtual int DisplayBWTransactionPending(bool *status);
374     virtual int SetDisplayAnimating(uint64_t display_id, bool animating);
375     virtual int ControlIdlePowerCollapse(bool enable, bool synchronous);
376     virtual int GetWriteBackCapabilities(bool *is_wb_ubwc_supported);
377     virtual int SetDisplayDppsAdROI(uint32_t display_id, uint32_t h_start, uint32_t h_end,
378                                     uint32_t v_start, uint32_t v_end, uint32_t factor_in,
379                                     uint32_t factor_out);
380     virtual int UpdateVSyncSourceOnPowerModeOff();
381     virtual int UpdateVSyncSourceOnPowerModeDoze();
382     virtual int SetPowerMode(uint32_t disp_id, DisplayConfig::PowerMode power_mode);
383     virtual int IsPowerModeOverrideSupported(uint32_t disp_id, bool *supported);
384     virtual int IsHDRSupported(uint32_t disp_id, bool *supported);
385     virtual int IsWCGSupported(uint32_t disp_id, bool *supported);
386     virtual int SetLayerAsMask(uint32_t disp_id, uint64_t layer_id);
GetDebugProperty(const std::string prop_name,std::string value)387     virtual int GetDebugProperty(const std::string prop_name, std::string value) {return -EINVAL;}
388     virtual int GetDebugProperty(const std::string prop_name, std::string *value);
389     virtual int GetActiveBuiltinDisplayAttributes(DisplayConfig::Attributes *attr);
390     virtual int SetPanelLuminanceAttributes(uint32_t disp_id, float min_lum, float max_lum);
391     virtual int IsBuiltInDisplay(uint32_t disp_id, bool *is_builtin);
392     virtual int IsAsyncVDSCreationSupported(bool *supported);
393     virtual int CreateVirtualDisplay(uint32_t width, uint32_t height, int format);
GetSupportedDSIBitClks(uint32_t disp_id,std::vector<uint64_t> bit_clks)394     virtual int GetSupportedDSIBitClks(uint32_t disp_id,
395                                        std::vector<uint64_t> bit_clks) {return -EINVAL;}
396     virtual int GetSupportedDSIBitClks(uint32_t disp_id, std::vector<uint64_t> *bit_clks);
397     virtual int GetDSIClk(uint32_t disp_id, uint64_t *bit_clk);
398     virtual int SetDSIClk(uint32_t disp_id, uint64_t bit_clk);
399     virtual int SetCWBOutputBuffer(uint32_t disp_id, const DisplayConfig::Rect rect,
400                                    bool post_processed, const native_handle_t *buffer);
401     virtual int SetQsyncMode(uint32_t disp_id, DisplayConfig::QsyncMode mode);
402     virtual int IsSmartPanelConfig(uint32_t disp_id, uint32_t config_id, bool *is_smart);
403     virtual int IsRotatorSupportedFormat(int hal_format, bool ubwc, bool *supported);
404     virtual int ControlQsyncCallback(bool enable);
405     virtual int ControlIdleStatusCallback(bool enable);
406 #ifdef DISPLAY_CONFIG_CAMERA_SMOOTH_APIs_1_0
407     virtual int SetCameraSmoothInfo(CameraSmoothOp op, uint32_t fps);
408     virtual int ControlCameraSmoothCallback(bool enable);
409 #endif
410     std::weak_ptr<DisplayConfig::ConfigCallback> callback_;
411     HWCSession *hwc_session_ = nullptr;
412   };
413 
414   struct DisplayMapInfo {
415     hwc2_display_t client_id = HWCCallbacks::kNumDisplays;        // mapped sf id for this display
416     int32_t sdm_id = -1;                                         // sdm id for this display
417     sdm:: DisplayType disp_type = kDisplayTypeMax;              // sdm display type
418     bool test_pattern = false;                                 // display will show test pattern
ResetDisplayMapInfo419     void Reset() {
420       // Do not clear client id
421       sdm_id = -1;
422       disp_type = kDisplayTypeMax;
423       test_pattern = false;
424     }
425   };
426 
427   static const int kExternalConnectionTimeoutMs = 500;
428   static const int kCommitDoneTimeoutMs = 100;
429   uint32_t throttling_refresh_rate_ = 60;
430   std::mutex hotplug_mutex_;
431   std::condition_variable hotplug_cv_;
432   void UpdateThrottlingRate();
433   void SetNewThrottlingRate(uint32_t new_rate);
434 
435   void ResetPanel();
436   void InitSupportedDisplaySlots();
437   void InitSupportedNullDisplaySlots();
438   int GetDisplayIndex(int dpy);
439   int CreatePrimaryDisplay();
440   void CreateDummyDisplay(hwc2_display_t client_id);
441   int HandleBuiltInDisplays();
442   int HandlePluggableDisplays(bool delay_hotplug);
443   int HandleConnectedDisplays(HWDisplaysInfo *hw_displays_info, bool delay_hotplug);
444   int HandleDisconnectedDisplays(HWDisplaysInfo *hw_displays_info);
445   void DestroyDisplay(DisplayMapInfo *map_info);
446   void DestroyPluggableDisplay(DisplayMapInfo *map_info);
447   void DestroyNonPluggableDisplay(DisplayMapInfo *map_info);
448   int GetConfigCount(int disp_id, uint32_t *count);
449   int GetActiveConfigIndex(int disp_id, uint32_t *config);
450   int SetActiveConfigIndex(int disp_id, uint32_t config);
451   int ControlPartialUpdate(int dpy, bool enable);
452   int DisplayBWTransactionPending(bool *status);
453   int SetDisplayStatus(int disp_id, HWCDisplay::DisplayStatus status);
454   int MinHdcpEncryptionLevelChanged(int disp_id, uint32_t min_enc_level);
455   int IsWbUbwcSupported(bool *value);
456   int SetIdleTimeout(uint32_t value);
457   int ToggleScreenUpdate(bool on);
458   int SetCameraLaunchStatus(uint32_t on);
459   int SetDisplayDppsAdROI(uint32_t display_id, uint32_t h_start, uint32_t h_end,
460                           uint32_t v_start, uint32_t v_end, uint32_t factor_in,
461                           uint32_t factor_out);
462   int ControlIdlePowerCollapse(bool enable, bool synchronous);
463   int32_t SetDynamicDSIClock(int64_t disp_id, uint32_t bitrate);
464   int32_t getDisplayBrightness(uint32_t display, float *brightness);
465   int32_t setDisplayBrightness(uint32_t display, float brightness);
466   int32_t getDisplayMaxBrightness(uint32_t display, uint32_t *max_brightness_level);
467   bool HasHDRSupport(HWCDisplay *hwc_display);
468   void PostInit();
469 
470   // Uevent handler
471   virtual void UEventHandler(const char *uevent_data, int length);
472 
473   // service methods
474   void StartServices();
475 
476   // QClient methods
477   virtual android::status_t notifyCallback(uint32_t command, const android::Parcel *input_parcel,
478                                            android::Parcel *output_parcel);
479   void DynamicDebug(const android::Parcel *input_parcel);
480   android::status_t SetFrameDumpConfig(const android::Parcel *input_parcel);
481   android::status_t SetMaxMixerStages(const android::Parcel *input_parcel);
482   android::status_t SetDisplayMode(const android::Parcel *input_parcel);
483   android::status_t ConfigureRefreshRate(const android::Parcel *input_parcel);
484   android::status_t QdcmCMDHandler(const android::Parcel *input_parcel,
485                                    android::Parcel *output_parcel);
486   android::status_t QdcmCMDDispatch(uint32_t display_id,
487                                     const PPDisplayAPIPayload &req_payload,
488                                     PPDisplayAPIPayload *resp_payload,
489                                     PPPendingParams *pending_action);
490   android::status_t GetDisplayAttributesForConfig(const android::Parcel *input_parcel,
491                                                   android::Parcel *output_parcel);
492   android::status_t GetVisibleDisplayRect(const android::Parcel *input_parcel,
493                                           android::Parcel *output_parcel);
494   android::status_t SetMixerResolution(const android::Parcel *input_parcel);
495   android::status_t SetColorModeOverride(const android::Parcel *input_parcel);
496   android::status_t SetColorModeWithRenderIntentOverride(const android::Parcel *input_parcel);
497 
498   android::status_t SetColorModeById(const android::Parcel *input_parcel);
499   android::status_t SetColorModeFromClient(const android::Parcel *input_parcel);
500   android::status_t getComposerStatus();
501   android::status_t SetStandByMode(const android::Parcel *input_parcel);
502   android::status_t SetQSyncMode(const android::Parcel *input_parcel);
503   android::status_t SetIdlePC(const android::Parcel *input_parcel);
504   android::status_t SetDisplayDeviceStatus(const android::Parcel *input_parcel);
505   android::status_t SetPanelGammaTableSource(const android::Parcel *input_parcel);
506   android::status_t RefreshScreen(const android::Parcel *input_parcel);
507   android::status_t SetAd4RoiConfig(const android::Parcel *input_parcel);
508   android::status_t SetDsiClk(const android::Parcel *input_parcel);
509   android::status_t GetDsiClk(const android::Parcel *input_parcel, android::Parcel *output_parcel);
510   android::status_t GetSupportedDsiClk(const android::Parcel *input_parcel,
511                                        android::Parcel *output_parcel);
512   android::status_t SetFrameTriggerMode(const android::Parcel *input_parcel);
513   android::status_t SetPanelLuminanceAttributes(const android::Parcel *input_parcel);
514   android::status_t setColorSamplingEnabled(const android::Parcel *input_parcel);
515 
516   // Internal methods
517   HWC2::Error ValidateDisplayInternal(hwc2_display_t display, uint32_t *out_num_types,
518                                       uint32_t *out_num_requests);
519   HWC2::Error PresentDisplayInternal(hwc2_display_t display);
520   void HandleSecureSession();
521   void HandlePendingPowerMode(hwc2_display_t display, const shared_ptr<Fence> &retire_fence);
522   void HandlePendingHotplug(hwc2_display_t disp_id, const shared_ptr<Fence> &retire_fence);
523   bool IsPluggableDisplayConnected();
524   hwc2_display_t GetActiveBuiltinDisplay();
525   void HandlePendingRefresh();
526   void NotifyClientStatus(bool connected);
527   int32_t GetVirtualDisplayId();
528   void PerformQsyncCallback(hwc2_display_t display);
529   bool isSmartPanelConfig(uint32_t disp_id, uint32_t config_id);
530   void PerformIdleStatusCallback(hwc2_display_t display);
531 
532   int SendLTMCommand(const char *cmd);
533 
534   CoreInterface *core_intf_ = nullptr;
535   HWCDisplay *hwc_display_[HWCCallbacks::kNumDisplays] = {nullptr};
536   HWCCallbacks callbacks_;
537   HWCBufferAllocator buffer_allocator_;
538   HWCVirtualDisplayFactory virtual_display_factory_;
539   HWCColorManager *color_mgr_ = nullptr;
540   DisplayMapInfo map_info_primary_;                 // Primary display (either builtin or pluggable)
541   std::vector<DisplayMapInfo> map_info_builtin_;    // Builtin displays excluding primary
542   std::vector<DisplayMapInfo> map_info_pluggable_;  // Pluggable displays excluding primary
543   std::vector<DisplayMapInfo> map_info_virtual_;    // Virtual displays
544   bool update_vsync_on_power_off_ = false;
545   bool update_vsync_on_doze_ = false;
546   std::vector<bool> is_hdr_display_;    // info on HDR supported
547   std::map <hwc2_display_t, hwc2_display_t> map_hwc_display_;  // Real and dummy display pairs.
548   bool reset_panel_ = false;
549   bool client_connected_ = false;
550   bool new_bw_mode_ = false;
551   bool need_invalidate_ = false;
552   int bw_mode_release_fd_ = -1;
553   qService::QService *qservice_ = nullptr;
554   HWCSocketHandler socket_handler_;
555   bool hdmi_is_primary_ = false;
556   bool is_composer_up_ = false;
557   std::mutex mutex_lum_;
558   int hpd_bpp_ = 0;
559   int hpd_pattern_ = 0;
560   static bool pending_power_mode_[HWCCallbacks::kNumDisplays];
561   static int null_display_mode_;
562   HotPlugEvent pending_hotplug_event_ = kHotPlugNone;
563   hwc2_display_t virtual_id_ = HWCCallbacks::kNumDisplays;
564   Locker pluggable_handler_lock_;
565   bool destroy_virtual_disp_pending_ = false;
566   uint32_t idle_pc_ref_cnt_ = 0;
567   int32_t disable_hotplug_bwcheck_ = 0;
568   int32_t disable_mask_layer_hint_ = 0;
569   float set_max_lum_ = -1.0;
570   float set_min_lum_ = -1.0;
571   std::bitset<HWCCallbacks::kNumDisplays> pending_refresh_;
572   CWB cwb_;
573   std::weak_ptr<DisplayConfig::ConfigCallback> qsync_callback_;
574   std::weak_ptr<DisplayConfig::ConfigCallback> idle_callback_;
575 #ifdef DISPLAY_CONFIG_CAMERA_SMOOTH_APIs_1_0
576   std::weak_ptr<DisplayConfig::ConfigCallback> camera_callback_;
577 #endif
578   bool async_powermode_ = false;
579   bool async_power_mode_triggered_ = false;
580   bool async_vds_creation_ = false;
581   bool power_state_transition_[HWCCallbacks::kNumDisplays] = {};
582   std::bitset<HWCCallbacks::kNumDisplays> display_ready_;
583   bool secure_session_active_ = false;
584 
585   int32_t is_lbe_supported_ = 0;
586   LbeState lbe_cur_state_ = LbeState::OFF;
587   int pps_socket_ = -1;
588   int8_t pps_retry = 5;
589   static constexpr const char *ltm_on_cmd_ = "Ltm:On:Primary:Auto";
590   static constexpr const char *ltm_off_cmd_ = "Ltm:Off:Primary";
591   static constexpr const char *ltm_lux_cmd_ = "Ltm:Als:Primary:";
592   static constexpr const char *ltm_default_mode_cmd_ = "Ltm:UserMode:Primary:default";
593   static constexpr const char *ltm_hbm_mode_cmd_ = "Ltm:UserMode:Primary:hbm";
594   static constexpr const char *ltm_power_save_mode_cmd_ = "Ltm:UserMode:Primary:power_save";
595   static constexpr const char *ltm_get_mode_cmd_ = "Ltm:GetUserMode:Primary";
596 };
597 }  // namespace sdm
598 
599 #endif  // __HWC_SESSION_H__
600