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.

88 lines
2.4 KiB

/*
* 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 <hardware/hwcomposer2.h>
#include <condition_variable>
#include <deque>
#include <mutex>
#include <thread>
#include <ui/Fence.h>
#include <sstream>
#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<int>(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<HwcLayerFence> {
public:
HwcLayerFence(const sp<Fence> &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<Fence> &GetFence();
std::string GetString() const;
hwc2_layer_t GetLayerId() const;
uint64_t GetSeq() const;
~HwcLayerFence();
void UpdateTimeStamp();
private:
friend class LightRefBase<HwcLayerFence>;
sp<Fence> 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<HwcLayerFence> &fence);
~FenceMonitor();
private:
void Loop();
void ThreadLoop();
std::string mName;
uint64_t mFencesQueued;
uint64_t mFencesSignaled;
std::deque<sp<HwcLayerFence>> 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<FenceMonitor> m_fenceMonior[(int)FENCE_TYPE_ENUM::FENCE_TYPE_NUM] = {nullptr};
};
}
#endif // FENCE_MONIOTR_H