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,const AttributeMap & attribs)21 Sync::Sync(rx::EGLImplFactory *factory, EGLenum type, const AttributeMap &attribs)
22 : mLabel(nullptr),
23 mType(type),
24 mCondition(EGL_SYNC_PRIOR_COMMANDS_COMPLETE_KHR),
25 mNativeFenceFD(
26 attribs.getAsInt(EGL_SYNC_NATIVE_FENCE_FD_ANDROID, EGL_NO_NATIVE_FENCE_FD_ANDROID))
27 {
28 switch (type)
29 {
30 case EGL_SYNC_FENCE:
31 case EGL_SYNC_NATIVE_FENCE_ANDROID:
32 mFence = std::unique_ptr<rx::EGLSyncImpl>(factory->createSync(attribs));
33 break;
34
35 case EGL_SYNC_REUSABLE_KHR:
36 mFence = std::unique_ptr<rx::EGLSyncImpl>(new rx::ReusableSync(attribs));
37 break;
38
39 default:
40 UNREACHABLE();
41 }
42
43 // Per extension spec: Signaling Condition.
44 // "If the EGL_SYNC_NATIVE_FENCE_FD_ANDROID attribute is not
45 // EGL_NO_NATIVE_FENCE_FD_ANDROID then the EGL_SYNC_CONDITION_KHR attribute
46 // is set to EGL_SYNC_NATIVE_FENCE_SIGNALED_ANDROID and the EGL_SYNC_STATUS_KHR
47 // attribute is set to reflect the signal status of the native fence object.
48 if ((mType == EGL_SYNC_NATIVE_FENCE_ANDROID) &&
49 (mNativeFenceFD != EGL_NO_NATIVE_FENCE_FD_ANDROID))
50 {
51 mCondition = EGL_SYNC_NATIVE_FENCE_SIGNALED_ANDROID;
52 }
53 }
54
onDestroy(const Display * display)55 void Sync::onDestroy(const Display *display)
56 {
57 ASSERT(mFence);
58 mFence->onDestroy(display);
59 mFence.reset();
60 }
61
~Sync()62 Sync::~Sync() {}
63
initialize(const Display * display,const gl::Context * context)64 Error Sync::initialize(const Display *display, const gl::Context *context)
65 {
66 return mFence->initialize(display, context, mType);
67 }
68
setLabel(EGLLabelKHR label)69 void Sync::setLabel(EGLLabelKHR label)
70 {
71 mLabel = label;
72 }
73
getLabel() const74 EGLLabelKHR Sync::getLabel() const
75 {
76 return mLabel;
77 }
78
clientWait(const Display * display,const gl::Context * context,EGLint flags,EGLTime timeout,EGLint * outResult)79 Error Sync::clientWait(const Display *display,
80 const gl::Context *context,
81 EGLint flags,
82 EGLTime timeout,
83 EGLint *outResult)
84 {
85 return mFence->clientWait(display, context, flags, timeout, outResult);
86 }
87
serverWait(const Display * display,const gl::Context * context,EGLint flags)88 Error Sync::serverWait(const Display *display, const gl::Context *context, EGLint flags)
89 {
90 return mFence->serverWait(display, context, flags);
91 }
92
signal(const Display * display,const gl::Context * context,EGLint mode)93 Error Sync::signal(const Display *display, const gl::Context *context, EGLint mode)
94 {
95 return mFence->signal(display, context, mode);
96 }
97
getStatus(const Display * display,EGLint * outStatus) const98 Error Sync::getStatus(const Display *display, EGLint *outStatus) const
99 {
100 return mFence->getStatus(display, outStatus);
101 }
102
dupNativeFenceFD(const Display * display,EGLint * result) const103 Error Sync::dupNativeFenceFD(const Display *display, EGLint *result) const
104 {
105 return mFence->dupNativeFenceFD(display, result);
106 }
107
108 } // namespace egl
109