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.

168 lines
6.5 KiB

/*
* Copyright (c) Hisilicon Technologies Co., Ltd.. 2016-2019. All rights reserved.
* Description: On behalf of a display device, hwcomposer is called for composition and sent for display
* Author: Hisilicon
* Created: 2016.08.12
*/
#ifndef HWC_DISPLAY_H
#define HWC_DISPLAY_H
#include <atomic>
#include <map>
#include <mutex>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <system/graphics.h>
#include <hardware/hwcomposer2.h>
#include <hardware/hwcomposer_defs.h>
#include <hardware/fb.h>
#ifdef EXT_GFX2D_SUPPORT
#endif
#include "gralloc_priv.h"
#include "HWCLayer.h"
#include "HWCCallbacks.h"
#include "HWCCommon.h"
#ifdef OVERLAY
#include "OverlayAdapter.h"
#endif
#include "ui/GraphicBufferAllocator.h"
#include "gfbg.h"
#include "FenceMonitor.h"
namespace android {
using namespace HwcCommon;
enum class DisplayType {
DISPLAY_ID_INVALID = -1,
DISPLAY_PRIMARY = HWC_DISPLAY_PRIMARY,
DISPLAY_EXTERNAL = HWC_DISPLAY_EXTERNAL,
DISPLAY_VIRTUAL = HWC_DISPLAY_VIRTUAL,
NUM_BUILTIN_DISPLAY_TYPES = HWC_NUM_PHYSICAL_DISPLAY_TYPES,
};
class HWCDisplay {
public:
HWCDisplay(const DisplayType type, const hwc2_display_t displayId, const framebuffer_device_t *fbDevice,
const bool gfx2dCompose, const HWCCallbacks* callback);
HWCDisplay(const DisplayType type, const hwc2_display_t displayId, DisplayConfigInfo& displayConfigInfo);
~HWCDisplay();
HWCLayer* GetHWCLayer(hwc2_layer_t layer);
// HWC2 APIs
HWC2::Error AcceptDisplayChanges(void);
HWC2::Error CreateLayer(hwc2_layer_t *outLayerId);
HWC2::Error DestroyLayer(hwc2_layer_t layerId);
HWC2::Error GetActiveConfig(hwc2_config_t *outConfig);
HWC2::Error GetChangedCompositionTypes(uint32_t *outNumElements, hwc2_layer_t *outLayers, int32_t *outTypes);
HWC2::Error GetClientTargetSupport(uint32_t width, uint32_t height, int32_t format, int32_t dataSpace);
HWC2::Error GetColorModes(uint32_t *outNumModes, int32_t *outModes);
HWC2::Error GetDisplayAttribute(hwc2_config_t config, HWC2::Attribute attribute, int32_t *outValue);
HWC2::Error GetDisplayConfigs(uint32_t *outNumConfigs, hwc2_config_t *outConfigs);
HWC2::Error GetDisplayName(uint32_t *outSize, char *outName);
HWC2::Error GetDisplayRequests(int32_t *outDisplayRequests, uint32_t *outNumElements, hwc2_layer_t *outLayers,
int32_t *outLayerRequests);
HWC2::Error GetDisplayType(int32_t *outType);
HWC2::Error GetReleaseFences(uint32_t *outNumElements, hwc2_layer_t *outLayers, int32_t *outFences);
int GetFrameBufferFd() const;
HWC2::Error SetLayerZOrder(hwc2_layer_t layerId, uint32_t z);
HWC2::Error SetOutputBuffer(buffer_handle_t buf, int32_t releaseFence);
HWC2::Error SetPowerMode(HWC2::PowerMode mode);
HWC2::Error SetVsyncEnabled(HWC2::Vsync enabled);
bool Vsync(int64_t timestamp, unsigned int freshRate);
HWC2::Error ValidateDisplay(uint32_t *outNumTypes, uint32_t *outNumRequests);
HWC2::Error PresentDisplay(int32_t *outRetireFence);
HWC2::Error SetActiveConfig(hwc2_config_t config);
HWC2::Error SetClientTarget(buffer_handle_t target, int32_t acquireFence, int32_t dataSpace, hwc_region_t damage);
HWC2::Error SetColorMode(int32_t mode);
HWC2::Error SetColorTransform(const float *matrix, android_color_transform_t hint)
{
UNUSED(matrix);
UNUSED(hint);
return HWC2::Error::Unsupported;
}
HWC2::Error SetCursorPosition(hwc2_layer_t layer, int x, int y);
HWC2::Error GetHdrCapabilities(uint32_t *outNumTypes, int32_t *outTypes, float *outMaxLuminance,
float *outMaxAverageLuminance, float *outMinLuminance);
std::string Dump();
void Init();
private:
DisplayType m_displayType;
const framebuffer_device_t *m_displayFbDevice;
std::map<hwc2_layer_t, HWC2::Composition> m_layerChanges;
std::map<hwc2_layer_t, HWC2::LayerRequest> m_layerRequests;
HWC2::DisplayRequest m_displayRequests;
const hwc2_display_t m_displayId;
std::set<int32_t> m_colorModes;
std::string m_displayName;
HWC2::PowerMode m_powerMode;
HWC2::Vsync m_vsyncEnabled;
HWCBuffer m_clientTarget; // fb buffer
HWCBuffer m_outputBuffer;
int32_t m_retireFenceId;
int32_t m_lastRetireFenceId;
std::multiset<HWCLayer *, SortLayersByZ> m_layers;
std::unordered_map<hwc2_layer_t, HWCLayer *> m_layerMap;
const HWCCallbacks *m_hwcCallbacks;
bool m_validated;
mutable std::recursive_mutex m_stateMutex;
DisplayConfigs m_displayConfigs;
unsigned int m_activeConfig;
DisplayConfigInfo m_activeDisplayConfig;
bool m_hwcCompose;
bool m_hwcCompress;
bool m_hwcAsyncCompose;
gfbg_capability_info fbCapabilityInfo;
#ifdef EXT_GFX2D_SUPPORT
struct FbReleaseFenceMap {
unsigned int phyAddr;
int releaseFenceid;
} m_fbReleaseFenceMap[FENCE_MAP_SIZE];
void AddFbReleaseFence(const unsigned int phyAddr, const int fbReleaseFd);
void QueryFbReleaseFence(const unsigned int phyAddr, int &fbReleaseFd);
#endif
bool CanPresentDirectly() const;
int GetComposeType() const;
void WaitFenceBeforeSyncCompose() const;
int HwcGfx2DComposer();
void CaptureLayerIfNecessary() const;
void WaitIfNecessary() const;
void HwcMediaFresh();
int HwcFbFresh();
int HwcDirectFresh();
void UpdateRequestAndComposeType();
void UpdateVirtualScreenByConfig();
// fence monitor debug
void AddFenceToMonitor(int fd, FENCE_TYPE type, hwc2_layer_t layerId);
// fb pixel check debug
void CheckFbPresentPixel();
void RefreshFb(const HWC2::PowerMode mode);
uint32_t ReadFbPixel(private_handle_t &fbHandle, const int x, const int y);
void SaveFbRgbFile(const std::string &filename, const private_handle_t &fbHandle);
// The standby process will send repeated frames to FB, which requires special processing at this time
unsigned int m_lastIonPhyAddr;
int m_composeType;
bool m_codeStateFlag;
int m_frameBufferFd;
std::mutex m_vsyncMutex;
std::condition_variable m_vsyncCondition;
unsigned int m_freshRate;
uint64_t m_vsyncCount;
// support present layer buffer directly without validate
bool m_supportdirectPresent;
std::unique_ptr<FenceMonitorMng> m_fenceMonitorMng = nullptr;
bool m_fenceMonitorDebug = false;
uint64_t m_seq = 0; // present sequence number
// fb pixel check debug
void* m_fbAddr = nullptr;
bool m_fbPixelDebug = false;
const std::string m_lockFb = "vendor.prop.gfx.hwc.lock.fb";
bool m_couldDisplay = true;
};
} // namespace android
#endif // HWC_DISPLAY_H