1 //
2 // Copyright 2002 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.cpp: Implements the egl::Sync class.
8
9 #include "libANGLE/EGLSync.h"
10
11 #include "angle_gl.h"
12
13 #include "common/utilities.h"
14 #include "libANGLE/renderer/EGLImplFactory.h"
15 #include "libANGLE/renderer/EGLReusableSync.h"
16 #include "libANGLE/renderer/EGLSyncImpl.h"
17
18 namespace egl
19 {
20
Sync(rx::EGLImplFactory * factory,EGLenum type)21 Sync::Sync(rx::EGLImplFactory *factory, EGLenum type)
22 : mLabel(nullptr), mId({0}), mType(type), mCondition(0), mNativeFenceFD(0)
23 {
24 switch (mType)
25 {
26 case EGL_SYNC_FENCE:
27 case EGL_SYNC_GLOBAL_FENCE_ANGLE:
28 case EGL_SYNC_NATIVE_FENCE_ANDROID:
29 case EGL_SYNC_METAL_SHARED_EVENT_ANGLE:
30 mFence = std::unique_ptr<rx::EGLSyncImpl>(factory->createSync());
31 break;
32
33 case EGL_SYNC_REUSABLE_KHR:
34 mFence = std::unique_ptr<rx::EGLSyncImpl>(new rx::ReusableSync());
35 break;
36
37 default:
38 UNREACHABLE();
39 }
40 }
41
onDestroy(const Display * display)42 void Sync::onDestroy(const Display *display)
43 {
44 ASSERT(mFence);
45 mFence->onDestroy(display);
46 }
47
~Sync()48 Sync::~Sync() {}
49
initialize(const Display * display,const gl::Context * context,const SyncID & id,const AttributeMap & attribs)50 Error Sync::initialize(const Display *display,
51 const gl::Context *context,
52 const SyncID &id,
53 const AttributeMap &attribs)
54 {
55 mId = id;
56 mAttributeMap = attribs;
57 mNativeFenceFD =
58 attribs.getAsInt(EGL_SYNC_NATIVE_FENCE_FD_ANDROID, EGL_NO_NATIVE_FENCE_FD_ANDROID);
59 mCondition = EGL_SYNC_PRIOR_COMMANDS_COMPLETE_KHR;
60
61 // Per extension spec: Signaling Condition.
62 // "If the EGL_SYNC_NATIVE_FENCE_FD_ANDROID attribute is not
63 // EGL_NO_NATIVE_FENCE_FD_ANDROID then the EGL_SYNC_CONDITION_KHR attribute
64 // is set to EGL_SYNC_NATIVE_FENCE_SIGNALED_ANDROID and the EGL_SYNC_STATUS_KHR
65 // attribute is set to reflect the signal status of the native fence object.
66 if ((mType == EGL_SYNC_NATIVE_FENCE_ANDROID) &&
67 (mNativeFenceFD != EGL_NO_NATIVE_FENCE_FD_ANDROID))
68 {
69 mCondition = EGL_SYNC_NATIVE_FENCE_SIGNALED_ANDROID;
70 }
71
72 // Per extension spec: Signaling Condition.
73 if (mType == EGL_SYNC_METAL_SHARED_EVENT_ANGLE)
74 {
75 mCondition = attribs.getAsInt(EGL_SYNC_CONDITION, EGL_SYNC_PRIOR_COMMANDS_COMPLETE_KHR);
76 }
77
78 return mFence->initialize(display, context, mType, mAttributeMap);
79 }
80
setLabel(EGLLabelKHR label)81 void Sync::setLabel(EGLLabelKHR label)
82 {
83 mLabel = label;
84 }
85
getLabel() const86 EGLLabelKHR Sync::getLabel() const
87 {
88 return mLabel;
89 }
90
clientWait(const Display * display,const gl::Context * context,EGLint flags,EGLTime timeout,EGLint * outResult)91 Error Sync::clientWait(const Display *display,
92 const gl::Context *context,
93 EGLint flags,
94 EGLTime timeout,
95 EGLint *outResult)
96 {
97 return mFence->clientWait(display, context, flags, timeout, outResult);
98 }
99
serverWait(const Display * display,const gl::Context * context,EGLint flags)100 Error Sync::serverWait(const Display *display, const gl::Context *context, EGLint flags)
101 {
102 return mFence->serverWait(display, context, flags);
103 }
104
signal(const Display * display,const gl::Context * context,EGLint mode)105 Error Sync::signal(const Display *display, const gl::Context *context, EGLint mode)
106 {
107 return mFence->signal(display, context, mode);
108 }
109
getStatus(const Display * display,EGLint * outStatus) const110 Error Sync::getStatus(const Display *display, EGLint *outStatus) const
111 {
112 return mFence->getStatus(display, outStatus);
113 }
114
copyMetalSharedEventANGLE(const Display * display,void ** result) const115 Error Sync::copyMetalSharedEventANGLE(const Display *display, void **result) const
116 {
117 return mFence->copyMetalSharedEventANGLE(display, result);
118 }
119
dupNativeFenceFD(const Display * display,EGLint * result) const120 Error Sync::dupNativeFenceFD(const Display *display, EGLint *result) const
121 {
122 return mFence->dupNativeFenceFD(display, result);
123 }
124
125 } // namespace egl
126