Bug 1839170 - Refactor Snap pulling, Add Firefox Snap Core22 and GNOME 42 SDK symbols...
[gecko.git] / dom / canvas / WebGL2ContextSync.cpp
blobb0092ca682475713ee7034493e7fe5e20408f57d
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/. */
6 #include "WebGL2Context.h"
8 #include "GLContext.h"
9 #include "WebGLSync.h"
10 #include "mozilla/StaticPrefs_webgl.h"
12 namespace mozilla {
14 // -------------------------------------------------------------------------
15 // Sync objects
17 RefPtr<WebGLSync> WebGL2Context::FenceSync(GLenum condition, GLbitfield flags) {
18 const FuncScope funcScope(*this, "fenceSync");
19 if (IsContextLost()) return nullptr;
21 if (condition != LOCAL_GL_SYNC_GPU_COMMANDS_COMPLETE) {
22 ErrorInvalidEnum("condition must be SYNC_GPU_COMMANDS_COMPLETE");
23 return nullptr;
26 if (flags != 0) {
27 ErrorInvalidValue("flags must be 0");
28 return nullptr;
31 RefPtr<WebGLSync> globj = new WebGLSync(this, condition, flags);
32 return globj;
35 GLenum WebGL2Context::ClientWaitSync(const WebGLSync& sync, GLbitfield flags,
36 GLuint64 timeout) {
37 const FuncScope funcScope(*this, "clientWaitSync");
38 if (IsContextLost()) return LOCAL_GL_WAIT_FAILED;
40 if (!ValidateObject("sync", sync)) return LOCAL_GL_WAIT_FAILED;
42 if (flags != 0 && flags != LOCAL_GL_SYNC_FLUSH_COMMANDS_BIT) {
43 ErrorInvalidValue("`flags` must be SYNC_FLUSH_COMMANDS_BIT or 0.");
44 return LOCAL_GL_WAIT_FAILED;
47 if (timeout > kMaxClientWaitSyncTimeoutNS) {
48 ErrorInvalidOperation("`timeout` must not exceed %s nanoseconds.",
49 "MAX_CLIENT_WAIT_TIMEOUT_WEBGL");
50 return LOCAL_GL_WAIT_FAILED;
53 const auto ret = gl->fClientWaitSync(sync.mGLName, flags, timeout);
55 if (ret == LOCAL_GL_CONDITION_SATISFIED || ret == LOCAL_GL_ALREADY_SIGNALED) {
56 sync.MarkSignaled();
59 return ret;
62 } // namespace mozilla