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 #include <future> // NOLINT 32 33 #include "hwc_display_primary.h" 34 #include "hwc_display_external.h" 35 #include "hwc_display_virtual.h" 36 #include "hwc_color_manager.h" 37 #include "hwc_socket_handler.h" 38 39 namespace sdm { 40 41 class HWCSession : hwc_composer_device_1_t, public qClient::BnQClient { 42 public: 43 struct HWCModuleMethods : public hw_module_methods_t { 44 HWCModuleMethods() { 45 hw_module_methods_t::open = HWCSession::Open; 46 } 47 }; 48 49 explicit HWCSession(const hw_module_t *module); 50 int Init(); 51 int Deinit(); 52 53 private: 54 static const int kExternalConnectionTimeoutMs = 500; 55 static const int kPartialUpdateControlTimeoutMs = 100; 56 57 // hwc methods 58 static int Open(const hw_module_t *module, const char* name, hw_device_t **device); 59 static int Close(hw_device_t *device); 60 static int Prepare(hwc_composer_device_1 *device, size_t num_displays, 61 hwc_display_contents_1_t **displays); 62 static int Set(hwc_composer_device_1 *device, size_t num_displays, 63 hwc_display_contents_1_t **displays); 64 static int EventControl(hwc_composer_device_1 *device, int disp, int event, int enable); 65 static int SetPowerMode(hwc_composer_device_1 *device, int disp, int mode); 66 static int Query(hwc_composer_device_1 *device, int param, int *value); 67 static void RegisterProcs(hwc_composer_device_1 *device, hwc_procs_t const *procs); 68 static void Dump(hwc_composer_device_1 *device, char *buffer, int length); 69 // These config functions always return FB params, the actual display params may differ. 70 static int GetDisplayConfigs(hwc_composer_device_1 *device, int disp, uint32_t *configs, 71 size_t *numConfigs); 72 static int GetDisplayAttributes(hwc_composer_device_1 *device, int disp, uint32_t config, 73 const uint32_t *display_attributes, int32_t *values); 74 static int GetActiveConfig(hwc_composer_device_1 *device, int disp); 75 static int SetActiveConfig(hwc_composer_device_1 *device, int disp, int index); 76 static int SetCursorPositionAsync(hwc_composer_device_1 *device, int disp, int x, int y); 77 static void CloseAcquireFds(hwc_display_contents_1_t *content_list); 78 bool IsDisplayYUV(int disp); 79 80 // Uevent thread 81 static void* HWCUeventThread(void *context); 82 void* HWCUeventThreadHandler(); 83 int GetEventValue(const char *uevent_data, int length, const char *event_info); 84 int HotPlugHandler(bool connected); 85 void ResetPanel(); 86 int ConnectDisplay(int disp, hwc_display_contents_1_t *content_list); 87 int DisconnectDisplay(int disp); 88 void HandleSecureDisplaySession(hwc_display_contents_1_t **displays); 89 int GetVsyncPeriod(int disp); 90 int CreateExternalDisplay(int disp, uint32_t primary_width, uint32_t primary_height, 91 bool use_primary_res); 92 void AsyncRefresh(); 93 94 // QClient methods 95 virtual android::status_t notifyCallback(uint32_t command, const android::Parcel *input_parcel, 96 android::Parcel *output_parcel); 97 void DynamicDebug(const android::Parcel *input_parcel); 98 void SetFrameDumpConfig(const android::Parcel *input_parcel); 99 android::status_t SetMaxMixerStages(const android::Parcel *input_parcel); 100 android::status_t SetDisplayMode(const android::Parcel *input_parcel); 101 android::status_t SetSecondaryDisplayStatus(const android::Parcel *input_parcel, 102 android::Parcel *output_parcel); 103 android::status_t ToggleScreenUpdates(const android::Parcel *input_parcel, 104 android::Parcel *output_parcel); 105 android::status_t ConfigureRefreshRate(const android::Parcel *input_parcel); 106 android::status_t QdcmCMDHandler(const android::Parcel *input_parcel, 107 android::Parcel *output_parcel); 108 android::status_t ControlPartialUpdate(const android::Parcel *input_parcel, 109 android::Parcel *output_parcel); 110 android::status_t OnMinHdcpEncryptionLevelChange(const android::Parcel *input_parcel, 111 android::Parcel *output_parcel); 112 android::status_t SetPanelBrightness(const android::Parcel *input_parcel, 113 android::Parcel *output_parcel); 114 android::status_t GetPanelBrightness(const android::Parcel *input_parcel, 115 android::Parcel *output_parcel); 116 // These functions return the actual display config info as opposed to FB 117 android::status_t HandleSetActiveDisplayConfig(const android::Parcel *input_parcel, 118 android::Parcel *output_parcel); 119 android::status_t HandleGetActiveDisplayConfig(const android::Parcel *input_parcel, 120 android::Parcel *output_parcel); 121 android::status_t HandleGetDisplayConfigCount(const android::Parcel *input_parcel, 122 android::Parcel *output_parcel); 123 android::status_t HandleGetDisplayAttributesForConfig(const android::Parcel *input_parcel, 124 android::Parcel *output_parcel); 125 android::status_t GetVisibleDisplayRect(const android::Parcel *input_parcel, 126 android::Parcel *output_parcel); 127 128 android::status_t SetDynamicBWForCamera(const android::Parcel *input_parcel, 129 android::Parcel *output_parcel); 130 android::status_t GetBWTransactionStatus(const android::Parcel *input_parcel, 131 android::Parcel *output_parcel); 132 android::status_t SetMixerResolution(const android::Parcel *input_parcel); 133 android::status_t SetDisplayPort(DisplayPort sdm_disp_port, int *hwc_disp_port); 134 android::status_t GetHdrCapabilities(const android::Parcel *input_parcel, 135 android::Parcel *output_parcel); 136 137 static Locker locker_; 138 CoreInterface *core_intf_ = NULL; 139 hwc_procs_t hwc_procs_default_; 140 hwc_procs_t const *hwc_procs_ = &hwc_procs_default_; 141 HWCDisplay *hwc_display_[HWC_NUM_DISPLAY_TYPES] = { NULL }; 142 pthread_t uevent_thread_; 143 bool uevent_thread_exit_ = false; 144 const char *uevent_thread_name_ = "HWC_UeventThread"; 145 HWCBufferAllocator buffer_allocator_; 146 HWCBufferSyncHandler buffer_sync_handler_; 147 HWCColorManager *color_mgr_ = NULL; 148 bool reset_panel_ = false; 149 bool secure_display_active_ = false; 150 bool external_pending_connect_ = false; 151 bool new_bw_mode_ = false; 152 bool need_invalidate_ = false; 153 int bw_mode_release_fd_ = -1; 154 qService::QService *qservice_ = NULL; 155 bool is_hdmi_primary_ = false; 156 bool is_hdmi_yuv_ = false; 157 std::future<void> future_; 158 std::bitset<HWC_NUM_DISPLAY_TYPES> connected_displays_; // Bit mask of connected displays 159 HWCSocketHandler socket_handler_; 160 Locker uevent_locker_; 161 }; 162 163 } // namespace sdm 164 165 #endif // __HWC_SESSION_H__ 166 167