1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
9 #include "mozilla/dom/WebGL2RenderingContextBinding.h"
10 #include "WebGLContext.h"
14 WebGLSync::WebGLSync(WebGLContext
* webgl
, GLenum condition
, GLbitfield flags
)
15 : WebGLContextBoundObject(webgl
),
16 mGLName(mContext
->gl
->fFenceSync(condition
, flags
)),
17 mFenceId(mContext
->mNextFenceId
) {
18 mContext
->mNextFenceId
+= 1;
21 WebGLSync::~WebGLSync() {
22 if (!mContext
) return;
23 mContext
->gl
->fDeleteSync(mGLName
);
26 ClientWaitSyncResult
WebGLSync::ClientWaitSync(const GLbitfield flags
,
27 const GLuint64 timeout
) {
28 if (!mContext
) return ClientWaitSyncResult::WAIT_FAILED
;
29 if (IsKnownComplete()) return ClientWaitSyncResult::ALREADY_SIGNALED
;
31 auto ret
= ClientWaitSyncResult::WAIT_FAILED
;
32 bool newlyComplete
= false;
33 const auto status
= static_cast<ClientWaitSyncResult
>(
34 mContext
->gl
->fClientWaitSync(mGLName
, 0, 0));
36 case ClientWaitSyncResult::TIMEOUT_EXPIRED
: // Poll() -> false
37 case ClientWaitSyncResult::WAIT_FAILED
: // Error
40 case ClientWaitSyncResult::CONDITION_SATISFIED
: // Should never happen, but
42 case ClientWaitSyncResult::ALREADY_SIGNALED
: // Poll() -> true
49 if (mContext
->mCompletedFenceId
< mFenceId
) {
50 mContext
->mCompletedFenceId
= mFenceId
;
52 MOZ_RELEASE_ASSERT(mOnCompleteTasks
);
53 for (const auto& task
: *mOnCompleteTasks
) {
56 mOnCompleteTasks
= {};
61 } // namespace mozilla