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 // Fence.cpp: Implements the gl::FenceNV and gl::Sync classes.
8
9 #include "libANGLE/Fence.h"
10
11 #include "angle_gl.h"
12
13 #include "common/utilities.h"
14 #include "libANGLE/renderer/FenceNVImpl.h"
15 #include "libANGLE/renderer/GLImplFactory.h"
16 #include "libANGLE/renderer/SyncImpl.h"
17
18 namespace gl
19 {
20
FenceNV(rx::GLImplFactory * factory)21 FenceNV::FenceNV(rx::GLImplFactory *factory)
22 : mFence(factory->createFenceNV()), mIsSet(false), mStatus(GL_FALSE), mCondition(GL_NONE)
23 {}
24
~FenceNV()25 FenceNV::~FenceNV()
26 {
27 SafeDelete(mFence);
28 }
29
onDestroy(const gl::Context * context)30 void FenceNV::onDestroy(const gl::Context *context)
31 {
32 mFence->onDestroy(context);
33 }
34
set(const Context * context,GLenum condition)35 angle::Result FenceNV::set(const Context *context, GLenum condition)
36 {
37 ANGLE_TRY(mFence->set(context, condition));
38
39 mCondition = condition;
40 mStatus = GL_FALSE;
41 mIsSet = true;
42
43 return angle::Result::Continue;
44 }
45
test(const Context * context,GLboolean * outResult)46 angle::Result FenceNV::test(const Context *context, GLboolean *outResult)
47 {
48 // Flush the command buffer by default
49 ANGLE_TRY(mFence->test(context, &mStatus));
50
51 *outResult = mStatus;
52 return angle::Result::Continue;
53 }
54
finish(const Context * context)55 angle::Result FenceNV::finish(const Context *context)
56 {
57 ASSERT(mIsSet);
58
59 ANGLE_TRY(mFence->finish(context));
60
61 mStatus = GL_TRUE;
62
63 return angle::Result::Continue;
64 }
65
Sync(rx::GLImplFactory * factory,GLuint id)66 Sync::Sync(rx::GLImplFactory *factory, GLuint id)
67 : RefCountObject(factory->generateSerial(), id),
68 mFence(factory->createSync()),
69 mLabel(),
70 mCondition(GL_SYNC_GPU_COMMANDS_COMPLETE),
71 mFlags(0)
72 {}
73
onDestroy(const Context * context)74 void Sync::onDestroy(const Context *context)
75 {
76 ASSERT(mFence);
77 mFence->onDestroy(context);
78 }
79
~Sync()80 Sync::~Sync()
81 {
82 SafeDelete(mFence);
83 }
84
setLabel(const Context * context,const std::string & label)85 void Sync::setLabel(const Context *context, const std::string &label)
86 {
87 mLabel = label;
88 }
89
getLabel() const90 const std::string &Sync::getLabel() const
91 {
92 return mLabel;
93 }
94
set(const Context * context,GLenum condition,GLbitfield flags)95 angle::Result Sync::set(const Context *context, GLenum condition, GLbitfield flags)
96 {
97 ANGLE_TRY(mFence->set(context, condition, flags));
98
99 mCondition = condition;
100 mFlags = flags;
101 return angle::Result::Continue;
102 }
103
clientWait(const Context * context,GLbitfield flags,GLuint64 timeout,GLenum * outResult)104 angle::Result Sync::clientWait(const Context *context,
105 GLbitfield flags,
106 GLuint64 timeout,
107 GLenum *outResult)
108 {
109 ASSERT(mCondition != GL_NONE);
110 return mFence->clientWait(context, flags, timeout, outResult);
111 }
112
serverWait(const Context * context,GLbitfield flags,GLuint64 timeout)113 angle::Result Sync::serverWait(const Context *context, GLbitfield flags, GLuint64 timeout)
114 {
115 return mFence->serverWait(context, flags, timeout);
116 }
117
getStatus(const Context * context,GLint * outResult) const118 angle::Result Sync::getStatus(const Context *context, GLint *outResult) const
119 {
120 return mFence->getStatus(context, outResult);
121 }
122
123 } // namespace gl
124