blob: 19d1830a908161d758d89044b3bc15af8fb82eb5 [file] [log] [blame]
Jamie Gennisf25e1832012-06-13 16:31:43 -07001/*
2 * Copyright (C) 2012 The Android Open Source Project
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#ifndef ANDROID_FENCE_H
18#define ANDROID_FENCE_H
19
20#include <stdint.h>
21#include <limits.h>
22#include <sys/types.h>
23
24#include <ui/ANativeObjectBase.h>
25#include <ui/PixelFormat.h>
26#include <ui/Rect.h>
27#include <utils/Flattenable.h>
28#include <utils/String8.h>
29
30struct ANativeWindowBuffer;
31
32namespace android {
33
34// ===========================================================================
35// Fence
36// ===========================================================================
37
38class Fence
39 : public LightRefBase<Fence>, public Flattenable
40{
41public:
42
43 // Construct a new Fence object with an invalid file descriptor. This
44 // should be done when the Fence object will be set up by unflattening
45 // serialized data.
46 Fence();
47
48 // Construct a new Fence object to manage a given fence file descriptor.
49 // When the new Fence object is destructed the file descriptor will be
50 // closed.
51 Fence(int fenceFd);
52
53 // wait waits for up to timeout milliseconds for the fence to signal. If
54 // the fence signals then NO_ERROR is returned. If the timeout expires
55 // before the fence signals then -ETIME is returned. A timeout of
56 // TIMEOUT_NEVER may be used to indicate that the call should wait
57 // indefinitely for the fence to signal.
58 int wait(unsigned int timeout);
59
60 // TIMEOUT_NEVER may be passed to the wait method to indicate that it
61 // should wait indefinitely for the fence to signal.
62 enum { TIMEOUT_NEVER = UINT_MAX };
63
64 // merge combines two Fence objects, creating a new Fence object that
65 // becomes signaled when both f1 and f2 are signaled (even if f1 or f2 is
66 // destroyed before it becomes signaled). The name argument specifies the
67 // human-readable name to associated with the new Fence object.
68 static sp<Fence> merge(const String8& name, const sp<Fence>& f1,
69 const sp<Fence>& f2);
70
71 // Flattenable interface
72 size_t getFlattenedSize() const;
73 size_t getFdCount() const;
74 status_t flatten(void* buffer, size_t size,
75 int fds[], size_t count) const;
76 status_t unflatten(void const* buffer, size_t size,
77 int fds[], size_t count);
78
79private:
80 // Only allow instantiation using ref counting.
81 friend class LightRefBase<Fence>;
82 virtual ~Fence();
83
84 // Disallow copying
85 Fence(const Fence& rhs);
86 Fence& operator = (const Fence& rhs);
87 const Fence& operator = (const Fence& rhs) const;
88
89 int mFenceFd;
90};
91
92}; // namespace android
93
94#endif // ANDROID_FENCE_H