1 /* 2 * Copyright (c) 2014 - 2015, 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 <IQClient.h> 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 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 *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 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 static Locker locker_; 127 CoreInterface *core_intf_ = NULL; 128 hwc_procs_t hwc_procs_default_; 129 hwc_procs_t const *hwc_procs_ = &hwc_procs_default_; 130 HWCDisplay *hwc_display_[HWC_NUM_DISPLAY_TYPES] = { NULL }; 131 pthread_t uevent_thread_; 132 bool uevent_thread_exit_ = false; 133 const char *uevent_thread_name_ = "HWC_UeventThread"; 134 HWCBufferAllocator *buffer_allocator_ = NULL; 135 HWCBufferSyncHandler *buffer_sync_handler_ = NULL; 136 HWCColorManager *color_mgr_ = NULL; 137 bool reset_panel_ = false; 138 bool secure_display_active_ = false; 139 bool external_pending_connect_ = false; 140 bool new_bw_mode_ = false; 141 bool need_invalidate_ = false; 142 int bw_mode_release_fd_ = -1; 143 }; 144 145 } // namespace sdm 146 147 #endif // __HWC_SESSION_H__ 148 149