Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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/. */
5 :
6 : #include "WebGL2Context.h"
7 :
8 : #include "GLContext.h"
9 : #include "WebGLSync.h"
10 :
11 : namespace mozilla {
12 :
13 : // -------------------------------------------------------------------------
14 : // Sync objects
15 :
16 : already_AddRefed<WebGLSync>
17 0 : WebGL2Context::FenceSync(GLenum condition, GLbitfield flags)
18 : {
19 0 : if (IsContextLost())
20 0 : return nullptr;
21 :
22 0 : if (condition != LOCAL_GL_SYNC_GPU_COMMANDS_COMPLETE) {
23 0 : ErrorInvalidEnum("fenceSync: condition must be SYNC_GPU_COMMANDS_COMPLETE");
24 0 : return nullptr;
25 : }
26 :
27 0 : if (flags != 0) {
28 0 : ErrorInvalidValue("fenceSync: flags must be 0");
29 0 : return nullptr;
30 : }
31 :
32 0 : MakeContextCurrent();
33 0 : RefPtr<WebGLSync> globj = new WebGLSync(this, condition, flags);
34 0 : return globj.forget();
35 : }
36 :
37 : bool
38 0 : WebGL2Context::IsSync(const WebGLSync* sync)
39 : {
40 0 : if (!ValidateIsObject("isSync", sync))
41 0 : return false;
42 :
43 0 : return true;
44 : }
45 :
46 : void
47 0 : WebGL2Context::DeleteSync(WebGLSync* sync)
48 : {
49 0 : if (!ValidateDeleteObject("deleteSync", sync))
50 0 : return;
51 :
52 0 : sync->RequestDelete();
53 : }
54 :
55 : GLenum
56 0 : WebGL2Context::ClientWaitSync(const WebGLSync& sync, GLbitfield flags, GLuint64 timeout)
57 : {
58 0 : const char funcName[] = "clientWaitSync";
59 0 : if (IsContextLost())
60 0 : return LOCAL_GL_WAIT_FAILED;
61 :
62 0 : if (!ValidateObject(funcName, sync))
63 0 : return LOCAL_GL_WAIT_FAILED;
64 :
65 0 : if (flags != 0 && flags != LOCAL_GL_SYNC_FLUSH_COMMANDS_BIT) {
66 0 : ErrorInvalidValue("%s: `flags` must be SYNC_FLUSH_COMMANDS_BIT or 0.", funcName);
67 0 : return LOCAL_GL_WAIT_FAILED;
68 : }
69 :
70 0 : if (timeout > kMaxClientWaitSyncTimeoutNS) {
71 0 : ErrorInvalidOperation("%s: `timeout` must not exceed %s nanoseconds.", funcName,
72 0 : "MAX_CLIENT_WAIT_TIMEOUT_WEBGL");
73 0 : return LOCAL_GL_WAIT_FAILED;
74 : }
75 :
76 0 : MakeContextCurrent();
77 0 : return gl->fClientWaitSync(sync.mGLName, flags, timeout);
78 : }
79 :
80 : void
81 0 : WebGL2Context::WaitSync(const WebGLSync& sync, GLbitfield flags, GLint64 timeout)
82 : {
83 0 : const char funcName[] = "waitSync";
84 0 : if (IsContextLost())
85 0 : return;
86 :
87 0 : if (!ValidateObject(funcName, sync))
88 0 : return;
89 :
90 0 : if (flags != 0) {
91 0 : ErrorInvalidValue("%s: `flags` must be 0.", funcName);
92 0 : return;
93 : }
94 :
95 0 : if (timeout != -1) {
96 0 : ErrorInvalidValue("%s: `timeout` must be TIMEOUT_IGNORED.", funcName);
97 0 : return;
98 : }
99 :
100 0 : MakeContextCurrent();
101 0 : gl->fWaitSync(sync.mGLName, flags, LOCAL_GL_TIMEOUT_IGNORED);
102 : }
103 :
104 : void
105 0 : WebGL2Context::GetSyncParameter(JSContext*, const WebGLSync& sync, GLenum pname,
106 : JS::MutableHandleValue retval)
107 : {
108 0 : const char funcName[] = "getSyncParameter";
109 0 : retval.setNull();
110 0 : if (IsContextLost())
111 0 : return;
112 :
113 0 : if (!ValidateObject(funcName, sync))
114 0 : return;
115 :
116 : ////
117 :
118 0 : gl->MakeCurrent();
119 :
120 0 : GLint result = 0;
121 0 : switch (pname) {
122 : case LOCAL_GL_OBJECT_TYPE:
123 : case LOCAL_GL_SYNC_STATUS:
124 : case LOCAL_GL_SYNC_CONDITION:
125 : case LOCAL_GL_SYNC_FLAGS:
126 0 : gl->fGetSynciv(sync.mGLName, pname, 1, nullptr, &result);
127 0 : retval.set(JS::Int32Value(result));
128 0 : return;
129 :
130 : default:
131 0 : ErrorInvalidEnum("%s: Invalid pname 0x%04x", funcName, pname);
132 0 : return;
133 : }
134 : }
135 :
136 : } // namespace mozilla
|