1 /*
2 * Copyright (c) 2014 - 2017, The Linux Foundation. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without modification, are permitted
5 * provided that the following conditions are met:
6 *    * Redistributions of source code must retain the above copyright notice, this list of
7 *      conditions and the following disclaimer.
8 *    * Redistributions in binary form must reproduce the above copyright notice, this list of
9 *      conditions and the following disclaimer in the documentation and/or other materials provided
10 *      with the distribution.
11 *    * Neither the name of The Linux Foundation nor the names of its contributors may be used to
12 *      endorse or promote products derived from this software without specific prior written
13 *      permission.
14 *
15 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
16 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17 * NON-INFRINGEMENT ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
19 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
20 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
21 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
22 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23 */
24 
25 #ifndef __HWC_SESSION_H__
26 #define __HWC_SESSION_H__
27 
28 #include <hardware/hwcomposer.h>
29 #include <core/core_interface.h>
30 #include <utils/locker.h>
31 
32 #include "hwc_display_primary.h"
33 #include "hwc_display_external.h"
34 #include "hwc_display_virtual.h"
35 #include "hwc_color_manager.h"
36 #include "hwc_socket_handler.h"
37 
38 namespace sdm {
39 
40 class HWCSession : hwc_composer_device_1_t, public qClient::BnQClient {
41  public:
42   struct HWCModuleMethods : public hw_module_methods_t {
HWCModuleMethodsHWCModuleMethods43     HWCModuleMethods() {
44       hw_module_methods_t::open = HWCSession::Open;
45     }
46   };
47 
48   explicit HWCSession(const hw_module_t *module);
49   int Init();
50   int Deinit();
51 
52  private:
53   static const int kExternalConnectionTimeoutMs = 500;
54   static const int kPartialUpdateControlTimeoutMs = 100;
55 
56   // hwc methods
57   static int Open(const hw_module_t *module, const char* name, hw_device_t **device);
58   static int Close(hw_device_t *device);
59   static int Prepare(hwc_composer_device_1 *device, size_t num_displays,
60                      hwc_display_contents_1_t **displays);
61   static int Set(hwc_composer_device_1 *device, size_t num_displays,
62                  hwc_display_contents_1_t **displays);
63   static int EventControl(hwc_composer_device_1 *device, int disp, int event, int enable);
64   static int SetPowerMode(hwc_composer_device_1 *device, int disp, int mode);
65   static int Query(hwc_composer_device_1 *device, int param, int *value);
66   static void RegisterProcs(hwc_composer_device_1 *device, hwc_procs_t const *procs);
67   static void Dump(hwc_composer_device_1 *device, char *buffer, int length);
68   // These config functions always return FB params, the actual display params may differ.
69   static int GetDisplayConfigs(hwc_composer_device_1 *device, int disp, uint32_t *configs,
70                                size_t *numConfigs);
71   static int GetDisplayAttributes(hwc_composer_device_1 *device, int disp, uint32_t config,
72                                   const uint32_t *display_attributes, int32_t *values);
73   static int GetActiveConfig(hwc_composer_device_1 *device, int disp);
74   static int SetActiveConfig(hwc_composer_device_1 *device, int disp, int index);
75   static int SetCursorPositionAsync(hwc_composer_device_1 *device, int disp, int x, int y);
76   static void CloseAcquireFds(hwc_display_contents_1_t *content_list);
77   bool IsDisplayYUV(int disp);
78 
79   // Uevent thread
80   static void* HWCUeventThread(void *context);
81   void* HWCUeventThreadHandler();
82   int GetEventValue(const char *uevent_data, int length, const char *event_info);
83   int HotPlugHandler(bool connected);
84   void ResetPanel();
85   int ConnectDisplay(int disp, hwc_display_contents_1_t *content_list);
86   int DisconnectDisplay(int disp);
87   void HandleSecureDisplaySession(hwc_display_contents_1_t **displays);
88   int GetVsyncPeriod(int disp);
89   int CreateExternalDisplay(int disp, uint32_t primary_width, uint32_t primary_height,
90                             bool use_primary_res);
91 
92   // QClient methods
93   virtual android::status_t notifyCallback(uint32_t command, const android::Parcel *input_parcel,
94                                            android::Parcel *output_parcel);
95   void DynamicDebug(const android::Parcel *input_parcel);
96   void SetFrameDumpConfig(const android::Parcel *input_parcel);
97   android::status_t SetMaxMixerStages(const android::Parcel *input_parcel);
98   android::status_t SetDisplayMode(const android::Parcel *input_parcel);
99   android::status_t SetSecondaryDisplayStatus(const android::Parcel *input_parcel,
100                                               android::Parcel *output_parcel);
101   android::status_t ToggleScreenUpdates(const android::Parcel *input_parcel,
102                                         android::Parcel *output_parcel);
103   android::status_t ConfigureRefreshRate(const android::Parcel *input_parcel);
104   android::status_t QdcmCMDHandler(const android::Parcel *input_parcel,
105                                    android::Parcel *output_parcel);
106   android::status_t ControlPartialUpdate(const android::Parcel *input_parcel, android::Parcel *out);
107   android::status_t OnMinHdcpEncryptionLevelChange(const android::Parcel *input_parcel,
108                                                    android::Parcel *output_parcel);
109   android::status_t SetPanelBrightness(const android::Parcel *input_parcel,
110                                        android::Parcel *output_parcel);
111   android::status_t GetPanelBrightness(const android::Parcel *input_parcel,
112                                        android::Parcel *output_parcel);
113   // These functions return the actual display config info as opposed to FB
114   android::status_t HandleSetActiveDisplayConfig(const android::Parcel *input_parcel,
115                                                  android::Parcel *output_parcel);
116   android::status_t HandleGetActiveDisplayConfig(const android::Parcel *input_parcel,
117                                                  android::Parcel *output_parcel);
118   android::status_t HandleGetDisplayConfigCount(const android::Parcel *input_parcel,
119                                                 android::Parcel *output_parcel);
120   android::status_t HandleGetDisplayAttributesForConfig(const android::Parcel *input_parcel,
121                                                         android::Parcel *output_parcel);
122   android::status_t GetVisibleDisplayRect(const android::Parcel *input_parcel,
123                                           android::Parcel *output_parcel);
124 
125   android::status_t SetDynamicBWForCamera(const android::Parcel *input_parcel,
126                                           android::Parcel *output_parcel);
127   android::status_t GetBWTransactionStatus(const android::Parcel *input_parcel,
128                                           android::Parcel *output_parcel);
129   android::status_t SetMixerResolution(const android::Parcel *input_parcel);
130   android::status_t SetDisplayPort(DisplayPort sdm_disp_port, int *hwc_disp_port);
131   android::status_t GetHdrCapabilities(const android::Parcel *input_parcel,
132                                        android::Parcel *output_parcel);
133 
134   static Locker locker_;
135   CoreInterface *core_intf_ = NULL;
136   hwc_procs_t hwc_procs_default_;
137   hwc_procs_t const *hwc_procs_ = &hwc_procs_default_;
138   HWCDisplay *hwc_display_[HWC_NUM_DISPLAY_TYPES] = { NULL };
139   pthread_t uevent_thread_;
140   bool uevent_thread_exit_ = false;
141   const char *uevent_thread_name_ = "HWC_UeventThread";
142   HWCBufferAllocator buffer_allocator_;
143   HWCBufferSyncHandler buffer_sync_handler_;
144   HWCColorManager *color_mgr_ = NULL;
145   bool reset_panel_ = false;
146   bool secure_display_active_ = false;
147   bool external_pending_connect_ = false;
148   bool new_bw_mode_ = false;
149   bool need_invalidate_ = false;
150   int bw_mode_release_fd_ = -1;
151   qService::QService *qservice_ = NULL;
152   bool is_hdmi_primary_ = false;
153   bool is_hdmi_yuv_ = false;
154   std::bitset<HWC_NUM_DISPLAY_TYPES> connected_displays_;  // Bit mask of connected displays
155   HWCSocketHandler socket_handler_;
156   Locker uevent_locker_;
157 };
158 
159 }  // namespace sdm
160 
161 #endif  // __HWC_SESSION_H__
162 
163