You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

95 lines
4.1 KiB

/*
* Copyright (c) Hisilicon Technologies Co., Ltd.. 2016-2019. All rights reserved.
* Description: Initialize hardware devices and implement some interfaces of hal
* Author: Hisilicon
* Created: 2016.08.12
*/
#ifndef HWC_DEVICE_H
#define HWC_DEVICE_H
#include <hardware/hwcomposer2.h>
#include <hardware/hwcomposer_defs.h>
#include "gralloc_priv.h"
#include "HWCDisplay.h"
#include "HWCCommon.h"
namespace android {
constexpr uint32_t MAX_VIRTUAL_DISP_COUNT = 0; // hwc not support virtual display compose
constexpr uint32_t HWC_DUMP_SIZE = 8192; // The dump of hwc prints 8192 bytes at most
class HWCDevice : hwc2_device_t {
public:
struct HWCModuleMethods : public hw_module_methods_t {
HWCModuleMethods()
{
hw_module_methods_t::open = HWCDevice::Open;
}
};
explicit HWCDevice(const hw_module_t *module); // create default display, vsync ...
~HWCDevice();
int Init();
static int Open(const struct hw_module_t *module, const char *name, struct hw_device_t **device);
static int Close(struct hw_device_t *dev);
template<typename... Args>
static int32_t CallDisplayFunction(hwc2_device_t *device, hwc2_display_t display,
HWC2::Error (HWCDisplay::*member)(Args...), Args... args)
{
HWC_CHK_RETURN((device == nullptr), HWC2_ERROR_BAD_PARAMETER, ALOGE("CallDisplayFunction device is nullprt"));
HWC_CHK_RETURN((member == nullptr), HWC2_ERROR_BAD_PARAMETER, ALOGE("CallDisplayFunction member is nullptr"));
HWCDevice *hwcDevice = static_cast<HWCDevice *>(device);
auto status = HWC2::Error::BadDisplay;
if (hwcDevice->m_hwcDisplay[display] != nullptr) {
auto hwcDisplay = hwcDevice->m_hwcDisplay[display];
status = (hwcDisplay->*member)(std::forward<Args>(args)...);
}
return int32_t(status);
}
template<typename... Args>
static int32_t CallLayerFunction(hwc2_device_t *device, hwc2_display_t display, hwc2_layer_t layer,
HWC2::Error (HWCLayer::*member)(Args...), Args... args)
{
HWC_CHK_RETURN((device == nullptr), HWC2_ERROR_BAD_PARAMETER, ALOGE("CallLayerFunction device is nullprt"));
HWC_CHK_RETURN((member == nullptr), HWC2_ERROR_BAD_PARAMETER, ALOGE("CallLayerFunction member is nullptr"));
HWCDevice *hwcDevice = static_cast<HWCDevice *>(device);
auto status = HWC2::Error::BadDisplay;
if (hwcDevice->m_hwcDisplay[display] != nullptr) {
status = HWC2::Error::BadLayer;
auto hwcLayer = hwcDevice->m_hwcDisplay[display]->GetHWCLayer(layer);
if (hwcLayer != nullptr) {
status = (hwcLayer->*member)(std::forward<Args>(args)...);
}
}
return int32_t(status);
}
static int32_t CreateVirtualDisplay(hwc2_device_t *device, uint32_t width, uint32_t height,
int32_t *format, hwc2_display_t *outDisplayDid);
static int32_t DestroyVirtualDisplay(hwc2_device_t *device, hwc2_display_t display);
static int32_t RegisterCallback(hwc2_device_t *device, int32_t descriptor, hwc2_callback_data_t callbackData,
hwc2_function_pointer_t pointer);
static void Dump(hwc2_device_t *device, uint32_t *outSize, char *outBuffer);
HWC2::Error CreateVirtualDisplayObject(uint32_t width, uint32_t height, const int32_t *format);
static void GetCapabilities(struct hwc2_device *device, uint32_t *outCount, int32_t *outCapabilities);
static hwc2_function_pointer_t GetFunction(struct hwc2_device *device, int32_t intDescriptor);
void SignalHotplug(hwc2_display_t display, HWC2::Connection state);
void SignalRefresh(hwc2_display_t display);
void SignalVsync(hwc2_display_t display, int64_t timestamp);
HWC2::Error Register(HWC2::Callback desc, hwc2_callback_data_t callbackData, hwc2_function_pointer_t pointer);
private:
HWCCallbacks m_hwcCallbacks;
HWCDisplay *m_hwcDisplay[HWC_NUM_DISPLAY_TYPES] = { nullptr };
framebuffer_device_t *m_fbDevices[HWC_NUM_PHYSICAL_DISPLAY_TYPES] = { nullptr };
#ifdef EXT_DOUBLE_DISPLAY_SUPPORT
bool m_externalDisplayEnabled = false;
#endif
};
} // namespace android
#endif // HWC_DEVICE_H