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