summaryrefslogtreecommitdiff
path: root/hwc2/include/HwcFenceControl.h (plain)
blob: 1a3274979ef3a66bd500aaf01bc0ad81d84af1b0
1/*
2// Copyright(c) 2016 Amlogic Corporation
3*/
4
5#ifndef HWC_FENCE_H
6#define HWC_FENCE_H
7
8#include <stdint.h>
9#include <sys/types.h>
10
11#include <utils/String8.h>
12#include <utils/Timers.h>
13#include <utils/StrongPointer.h>
14#include <utils/RefBase.h>
15
16
17namespace android {
18namespace amlogic {
19
20
21// ===========================================================================
22// HwcFenceControl
23// ===========================================================================
24
25class HwcFenceControl
26 : public LightRefBase<HwcFenceControl>
27{
28public:
29 static const sp<HwcFenceControl> NO_FENCE;
30
31 // TIMEOUT_NEVER may be passed to the wait method to indicate that it
32 // should wait indefinitely for the fence to signal.
33 enum { TIMEOUT_NEVER = -1 };
34
35 // Construct a new Fence object with an invalid file descriptor. This
36 // should be done when the Fence object will be set up by unflattening
37 // serialized data.
38 HwcFenceControl();
39
40 // Construct a new Fence object to manage a given fence file descriptor.
41 // When the new Fence object is destructed the file descriptor will be
42 // closed.
43 HwcFenceControl(int32_t fenceFd);
44
45 // Check whether the Fence has an open fence file descriptor. Most Fence
46 // methods treat an invalid file descriptor just like a valid fence that
47 // is already signalled, so using this is usually not necessary.
48 bool isValid() const { return mFenceFd != -1; }
49
50 // wait waits for up to timeout milliseconds for the fence to signal. If
51 // the fence signals then NO_ERROR is returned. If the timeout expires
52 // before the fence signals then -ETIME is returned. A timeout of
53 // TIMEOUT_NEVER may be used to indicate that the call should wait
54 // indefinitely for the fence to signal.
55 static status_t wait(int32_t fence, int32_t timeout);
56
57 // waitForever is a convenience function for waiting forever for a fence to
58 // signal (just like wait(TIMEOUT_NEVER)), but issuing an error to the
59 // system log and fence state to the kernel log if the wait lasts longer
60 // than a warning timeout.
61 // The logname argument should be a string identifying
62 // the caller and will be included in the log message.
63 status_t waitForever(const char* logname);
64
65 // fence.
66 static int32_t createFenceTimeline();
67 static int32_t createFence(int32_t syncTimelineFd,char* str, uint32_t val);
68 static status_t syncTimelineInc(int32_t syncTimelineFd);
69 static status_t traceFenceInfo(int32_t fence);
70
71 static inline void closeFd(int32_t fence) {
72 if (fence > -1) {
73 close(fence);
74 }
75 }
76 static inline void waitAndCloseFd(int32_t fence, int32_t timeout) {
77 if (fence > -1) {
78 wait(fence, timeout);
79 close(fence);
80 }
81 }
82
83 // merge combines two Fence objects, creating a new Fence object that
84 // becomes signaled when both f1 and f2 are signaled (even if f1 or f2 is
85 // destroyed before it becomes signaled). The name argument specifies the
86 // human-readable name to associated with the new Fence object.
87 static int32_t merge(const String8& name, const int32_t& f1,
88 const int32_t& f2);
89
90 static int32_t dupFence(int32_t fence);
91
92private:
93 // Only allow instantiation using ref counting.
94 friend class LightRefBase<HwcFenceControl>;
95 ~HwcFenceControl();
96
97 // Disallow copying
98 HwcFenceControl(const HwcFenceControl& rhs);
99 HwcFenceControl& operator = (const HwcFenceControl& rhs);
100 const HwcFenceControl& operator = (const HwcFenceControl& rhs) const;
101
102 int32_t mFenceFd;
103};
104
105}; // namespace amlogic
106}; // namespace android
107
108
109#endif // ANDROID_FENCE_H
110