/* * Copyright (c) Hisilicon Technologies Co., Ltd.. 2020-2020. All rights reserved. * Description: On behalf of a display device, hwcomposer is called for composition and sent for display * Author: Hisilicon * Created: 2020.08.04 */ #ifndef FENCE_MONIOTR_H #define FENCE_MONIOTR_H #include #include #include #include #include #include #include #include "HWCCommon.h" namespace android { using namespace HwcCommon; enum class FENCE_TYPE_ENUM { FENCE_LAYER_ACQUIRE = 0, FENCE_LAYER_RELEASE, FENCE_FB_ACQUIRE, FENCE_FB_RELEASE, FENCE_DIRECT_ACQUIRE, FENCE_DIRECT_RELEASE, FENCE_TYPE_NUM }; using FENCE_TYPE = enum FENCE_TYPE_ENUM; const std::string G_FENCE_TYPE_NMAE[static_cast(FENCE_TYPE_ENUM::FENCE_TYPE_NUM)] = {{"layer acquire fence"}, {"layer release fence"}, {"fb acquire fence"}, {"fb release fence"}, {"direct acquire fence"}, {"direct release fence"}}; class HwcLayerFence : public LightRefBase { public: HwcLayerFence(const sp &fence, hwc2_layer_t layerId, uint64_t seq); nsecs_t GetSignalTime() const; status_t WaitForever(std::string msg); int Get() const; bool HasSignaled() const; const sp &GetFence(); std::string GetString() const; hwc2_layer_t GetLayerId() const; uint64_t GetSeq() const; ~HwcLayerFence(); void UpdateTimeStamp(); private: friend class LightRefBase; sp m_fence = nullptr; hwc2_layer_t m_layerid = 0; uint64_t m_seq = 0; nsecs_t m_timestamp = 0; }; class FenceMonitor { public: explicit FenceMonitor(const std::string &name); std::string Dump(); void QueueFence(const sp &fence); ~FenceMonitor(); private: void Loop(); void ThreadLoop(); std::string mName; uint64_t mFencesQueued; uint64_t mFencesSignaled; std::deque> mQueue; std::condition_variable mCondition; std::mutex mMutex; }; class FenceMonitorMng { public: FenceMonitorMng(); ~FenceMonitorMng(); std::string Dump() const; void AddFence(int fd, FENCE_TYPE type, hwc2_layer_t layerid, uint64_t seq); private: std::unique_ptr m_fenceMonior[(int)FENCE_TYPE_ENUM::FENCE_TYPE_NUM] = {nullptr}; }; } #endif // FENCE_MONIOTR_H