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