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