1 //
2 // Copyright 2019 The ANGLE Project Authors. All rights reserved.
3 // Use of this source code is governed by a BSD-style license that can be
4 // found in the LICENSE file.
5 //
6 
7 // EGLSync.h: Defines the egl::Sync classes, which support the EGL_KHR_fence_sync,
8 // EGL_KHR_wait_sync and EGL 1.5 sync objects.
9 
10 #ifndef LIBANGLE_EGLSYNC_H_
11 #define LIBANGLE_EGLSYNC_H_
12 
13 #include "libANGLE/Debug.h"
14 #include "libANGLE/Error.h"
15 #include "libANGLE/RefCountObject.h"
16 
17 #include "common/angleutils.h"
18 
19 namespace rx
20 {
21 class EGLImplFactory;
22 class EGLSyncImpl;
23 }  // namespace rx
24 
25 namespace gl
26 {
27 class Context;
28 }  // namespace gl
29 
30 namespace egl
31 {
32 class Sync final : public angle::RefCountObject<Display, angle::Result>, public LabeledObject
33 {
34   public:
35     Sync(rx::EGLImplFactory *factory, EGLenum type, const AttributeMap &attribs);
36     ~Sync() override;
37 
38     void setLabel(EGLLabelKHR label) override;
39     EGLLabelKHR getLabel() const override;
40 
41     void onDestroy(const Display *display) override;
42 
43     Error initialize(const Display *display, const gl::Context *context);
44     Error clientWait(const Display *display,
45                      const gl::Context *context,
46                      EGLint flags,
47                      EGLTime timeout,
48                      EGLint *outResult);
49     Error serverWait(const Display *display, const gl::Context *context, EGLint flags);
50     Error getStatus(const Display *display, EGLint *outStatus) const;
51 
52     Error dupNativeFenceFD(const Display *display, EGLint *result) const;
53 
getType()54     EGLenum getType() const { return mType; }
getCondition()55     EGLint getCondition() const { return mCondition; }
getNativeFenceFD()56     EGLint getNativeFenceFD() const { return mNativeFenceFD; }
57 
58   private:
59     std::unique_ptr<rx::EGLSyncImpl> mFence;
60 
61     EGLLabelKHR mLabel;
62 
63     EGLenum mType;
64     static constexpr EGLint mCondition = EGL_SYNC_PRIOR_COMMANDS_COMPLETE_KHR;
65     EGLint mNativeFenceFD;
66 };
67 
68 }  // namespace egl
69 
70 #endif  // LIBANGLE_FENCE_H_
71