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