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 mSyncObject = mFunctions->fenceSync(condition, flags);
40 ANGLE_CHECK(GetImplAs<ContextGL>(context), mSyncObject != 0,
41 "glFenceSync failed to create a GLsync object.", GL_OUT_OF_MEMORY);
42 return angle::Result::Continue;
43 }
44
clientWait(const gl::Context * context,GLbitfield flags,GLuint64 timeout,GLenum * outResult)45 angle::Result SyncGL::clientWait(const gl::Context *context,
46 GLbitfield flags,
47 GLuint64 timeout,
48 GLenum *outResult)
49 {
50 ASSERT(mSyncObject != 0);
51 *outResult = mFunctions->clientWaitSync(mSyncObject, flags, timeout);
52 return angle::Result::Continue;
53 }
54
serverWait(const gl::Context * context,GLbitfield flags,GLuint64 timeout)55 angle::Result SyncGL::serverWait(const gl::Context *context, GLbitfield flags, GLuint64 timeout)
56 {
57 ASSERT(mSyncObject != 0);
58 mFunctions->waitSync(mSyncObject, flags, timeout);
59 return angle::Result::Continue;
60 }
61
getStatus(const gl::Context * context,GLint * outResult)62 angle::Result SyncGL::getStatus(const gl::Context *context, GLint *outResult)
63 {
64 ASSERT(mSyncObject != 0);
65 mFunctions->getSynciv(mSyncObject, GL_SYNC_STATUS, 1, nullptr, outResult);
66 return angle::Result::Continue;
67 }
68 } // namespace rx
69