1 //
2 // Copyright 2015 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 // SyncGL.cpp: Implements the class methods for SyncGL.
8
9 #include "libANGLE/renderer/gl/SyncGL.h"
10
11 #include "common/debug.h"
12 #include "libANGLE/Context.h"
13 #include "libANGLE/renderer/gl/ContextGL.h"
14 #include "libANGLE/renderer/gl/FunctionsGL.h"
15
16 namespace rx
17 {
18
SyncGL(const FunctionsGL * functions)19 SyncGL::SyncGL(const FunctionsGL *functions) : SyncImpl(), mFunctions(functions), mSyncObject(0)
20 {
21 ASSERT(mFunctions);
22 }
23
~SyncGL()24 SyncGL::~SyncGL()
25 {
26 ASSERT(mSyncObject == 0);
27 }
28
onDestroy(const gl::Context * context)29 void SyncGL::onDestroy(const gl::Context *context)
30 {
31 ASSERT(mSyncObject != 0);
32 mFunctions->deleteSync(mSyncObject);
33 mSyncObject = 0;
34 }
35
set(const gl::Context * context,GLenum condition,GLbitfield flags)36 angle::Result SyncGL::set(const gl::Context *context, GLenum condition, GLbitfield flags)
37 {
38 ASSERT(condition == GL_SYNC_GPU_COMMANDS_COMPLETE && flags == 0);
39 ContextGL *contextGL = GetImplAs<ContextGL>(context);
40 mSyncObject = mFunctions->fenceSync(condition, flags);
41 ANGLE_CHECK(contextGL, mSyncObject != 0, "glFenceSync failed to create a GLsync object.",
42 GL_OUT_OF_MEMORY);
43 contextGL->markWorkSubmitted();
44 return angle::Result::Continue;
45 }
46
clientWait(const gl::Context * context,GLbitfield flags,GLuint64 timeout,GLenum * outResult)47 angle::Result SyncGL::clientWait(const gl::Context *context,
48 GLbitfield flags,
49 GLuint64 timeout,
50 GLenum *outResult)
51 {
52 ASSERT(mSyncObject != 0);
53 *outResult = mFunctions->clientWaitSync(mSyncObject, flags, timeout);
54 return angle::Result::Continue;
55 }
56
serverWait(const gl::Context * context,GLbitfield flags,GLuint64 timeout)57 angle::Result SyncGL::serverWait(const gl::Context *context, GLbitfield flags, GLuint64 timeout)
58 {
59 ASSERT(mSyncObject != 0);
60 mFunctions->waitSync(mSyncObject, flags, timeout);
61 return angle::Result::Continue;
62 }
63
getStatus(const gl::Context * context,GLint * outResult)64 angle::Result SyncGL::getStatus(const gl::Context *context, GLint *outResult)
65 {
66 ASSERT(mSyncObject != 0);
67 mFunctions->getSynciv(mSyncObject, GL_SYNC_STATUS, 1, nullptr, outResult);
68 return angle::Result::Continue;
69 }
70 } // namespace rx
71