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