1 /* 2 * Copyright (c) 2014-2017, 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 #ifndef __HWC_SESSION_H__ 21 #define __HWC_SESSION_H__ 22 23 #include <core/core_interface.h> 24 #include <utils/locker.h> 25 26 #include "hwc_callbacks.h" 27 #include "hwc_layers.h" 28 #include "hwc_display.h" 29 #include "hwc_display_primary.h" 30 #include "hwc_display_external.h" 31 #include "hwc_display_virtual.h" 32 #include "hwc_color_manager.h" 33 #include "hwc_socket_handler.h" 34 35 namespace sdm { 36 37 class HWCSession : hwc2_device_t, public qClient::BnQClient { 38 public: 39 struct HWCModuleMethods : public hw_module_methods_t { 40 HWCModuleMethods() { hw_module_methods_t::open = HWCSession::Open; } 41 }; 42 43 explicit HWCSession(const hw_module_t *module); 44 int Init(); 45 int Deinit(); 46 HWC2::Error CreateVirtualDisplayObject(uint32_t width, uint32_t height, int32_t *format); 47 48 template <typename... Args> 49 static int32_t CallDisplayFunction(hwc2_device_t *device, hwc2_display_t display, 50 HWC2::Error (HWCDisplay::*member)(Args...), Args... args) { 51 if (!device) { 52 return HWC2_ERROR_BAD_DISPLAY; 53 } 54 55 HWCSession *hwc_session = static_cast<HWCSession *>(device); 56 auto status = HWC2::Error::BadDisplay; 57 if (hwc_session->hwc_display_[display]) { 58 auto hwc_display = hwc_session->hwc_display_[display]; 59 status = (hwc_display->*member)(std::forward<Args>(args)...); 60 } 61 return INT32(status); 62 } 63 64 template <typename... Args> 65 static int32_t CallLayerFunction(hwc2_device_t *device, hwc2_display_t display, 66 hwc2_layer_t layer, HWC2::Error (HWCLayer::*member)(Args...), 67 Args... args) { 68 if (!device) { 69 return HWC2_ERROR_BAD_DISPLAY; 70 } 71 72 HWCSession *hwc_session = static_cast<HWCSession *>(device); 73 int32_t status = INT32(HWC2::Error::BadDisplay); 74 if (hwc_session->hwc_display_[display]) { 75 status = hwc_session->hwc_display_[display]->CallLayerFunction(layer, member, args...); 76 } 77 return status; 78 } 79 80 // HWC2 Functions that require a concrete implementation in hwc session 81 // and hence need to be member functions 82 static int32_t AcceptDisplayChanges(hwc2_device_t *device, hwc2_display_t display); 83 static int32_t CreateLayer(hwc2_device_t *device, hwc2_display_t display, 84 hwc2_layer_t *out_layer_id); 85 static int32_t CreateVirtualDisplay(hwc2_device_t *device, uint32_t width, uint32_t height, 86 int32_t *format, hwc2_display_t *out_display_id); 87 static int32_t DestroyLayer(hwc2_device_t *device, hwc2_display_t display, hwc2_layer_t layer); 88 static int32_t DestroyVirtualDisplay(hwc2_device_t *device, hwc2_display_t display); 89 static void Dump(hwc2_device_t *device, uint32_t *out_size, char *out_buffer); 90 static int32_t PresentDisplay(hwc2_device_t *device, hwc2_display_t display, 91 int32_t *out_retire_fence); 92 static int32_t RegisterCallback(hwc2_device_t *device, int32_t descriptor, 93 hwc2_callback_data_t callback_data, 94 hwc2_function_pointer_t pointer); 95 static int32_t SetOutputBuffer(hwc2_device_t *device, hwc2_display_t display, 96 buffer_handle_t buffer, int32_t releaseFence); 97 static int32_t SetLayerZOrder(hwc2_device_t *device, hwc2_display_t display, hwc2_layer_t layer, 98 uint32_t z); 99 static int32_t SetPowerMode(hwc2_device_t *device, hwc2_display_t display, int32_t int_mode); 100 static int32_t ValidateDisplay(hwc2_device_t *device, hwc2_display_t display, 101 uint32_t *out_num_types, uint32_t *out_num_requests); 102 static int32_t SetColorMode(hwc2_device_t *device, hwc2_display_t display, 103 int32_t /*android_color_mode_t*/ int_mode); 104 static int32_t SetColorTransform(hwc2_device_t *device, hwc2_display_t display, 105 const float *matrix, int32_t /*android_color_transform_t*/ hint); 106 107 private: 108 static const int kExternalConnectionTimeoutMs = 500; 109 static const int kPartialUpdateControlTimeoutMs = 100; 110 111 // hwc methods 112 static int Open(const hw_module_t *module, const char *name, hw_device_t **device); 113 static int Close(hw_device_t *device); 114 static void GetCapabilities(struct hwc2_device *device, uint32_t *outCount, 115 int32_t *outCapabilities); 116 static hwc2_function_pointer_t GetFunction(struct hwc2_device *device, int32_t descriptor); 117 118 // Uevent thread 119 static void *HWCUeventThread(void *context); 120 void *HWCUeventThreadHandler(); 121 int GetEventValue(const char *uevent_data, int length, const char *event_info); 122 int HotPlugHandler(bool connected); 123 void ResetPanel(); 124 int32_t ConnectDisplay(int disp); 125 int DisconnectDisplay(int disp); 126 int GetVsyncPeriod(int disp); 127 128 // QClient methods 129 virtual android::status_t notifyCallback(uint32_t command, const android::Parcel *input_parcel, 130 android::Parcel *output_parcel); 131 void DynamicDebug(const android::Parcel *input_parcel); 132 void SetFrameDumpConfig(const android::Parcel *input_parcel); 133 android::status_t SetMaxMixerStages(const android::Parcel *input_parcel); 134 android::status_t SetDisplayMode(const android::Parcel *input_parcel); 135 android::status_t SetSecondaryDisplayStatus(const android::Parcel *input_parcel, 136 android::Parcel *output_parcel); 137 android::status_t ToggleScreenUpdates(const android::Parcel *input_parcel, 138 android::Parcel *output_parcel); 139 android::status_t ConfigureRefreshRate(const android::Parcel *input_parcel); 140 android::status_t QdcmCMDHandler(const android::Parcel *input_parcel, 141 android::Parcel *output_parcel); 142 android::status_t ControlPartialUpdate(const android::Parcel *input_parcel, android::Parcel *out); 143 android::status_t OnMinHdcpEncryptionLevelChange(const android::Parcel *input_parcel, 144 android::Parcel *output_parcel); 145 android::status_t SetPanelBrightness(const android::Parcel *input_parcel, 146 android::Parcel *output_parcel); 147 android::status_t GetPanelBrightness(const android::Parcel *input_parcel, 148 android::Parcel *output_parcel); 149 // These functions return the actual display config info as opposed to FB 150 android::status_t HandleSetActiveDisplayConfig(const android::Parcel *input_parcel, 151 android::Parcel *output_parcel); 152 android::status_t HandleGetActiveDisplayConfig(const android::Parcel *input_parcel, 153 android::Parcel *output_parcel); 154 android::status_t HandleGetDisplayConfigCount(const android::Parcel *input_parcel, 155 android::Parcel *output_parcel); 156 android::status_t HandleGetDisplayAttributesForConfig(const android::Parcel *input_parcel, 157 android::Parcel *output_parcel); 158 android::status_t GetVisibleDisplayRect(const android::Parcel *input_parcel, 159 android::Parcel *output_parcel); 160 161 android::status_t SetDynamicBWForCamera(const android::Parcel *input_parcel, 162 android::Parcel *output_parcel); 163 android::status_t GetBWTransactionStatus(const android::Parcel *input_parcel, 164 android::Parcel *output_parcel); 165 android::status_t SetMixerResolution(const android::Parcel *input_parcel); 166 167 android::status_t SetColorModeOverride(const android::Parcel *input_parcel); 168 169 android::status_t SetColorModeById(const android::Parcel *input_parcel); 170 171 static Locker locker_; 172 CoreInterface *core_intf_ = NULL; 173 HWCDisplay *hwc_display_[HWC_NUM_DISPLAY_TYPES] = {NULL}; 174 HWCCallbacks callbacks_; 175 pthread_t uevent_thread_; 176 bool uevent_thread_exit_ = false; 177 const char *uevent_thread_name_ = "HWC_UeventThread"; 178 HWCBufferAllocator *buffer_allocator_; 179 HWCBufferSyncHandler buffer_sync_handler_; 180 HWCColorManager *color_mgr_ = NULL; 181 bool reset_panel_ = false; 182 bool secure_display_active_ = false; 183 bool external_pending_connect_ = false; 184 bool new_bw_mode_ = false; 185 bool need_invalidate_ = false; 186 int bw_mode_release_fd_ = -1; 187 qService::QService *qservice_ = NULL; 188 HWCSocketHandler socket_handler_; 189 }; 190 191 } // namespace sdm 192 193 #endif // __HWC_SESSION_H__ 194