/src/mozilla-central/dom/canvas/WebGL2ContextSync.cpp
Line | Count | Source (jump to first uncovered line) |
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 | | WebGL2Context::FenceSync(GLenum condition, GLbitfield flags) |
18 | 0 | { |
19 | 0 | const FuncScope funcScope(*this, "fenceSync"); |
20 | 0 | if (IsContextLost()) |
21 | 0 | return nullptr; |
22 | 0 | |
23 | 0 | if (condition != LOCAL_GL_SYNC_GPU_COMMANDS_COMPLETE) { |
24 | 0 | ErrorInvalidEnum("condition must be SYNC_GPU_COMMANDS_COMPLETE"); |
25 | 0 | return nullptr; |
26 | 0 | } |
27 | 0 | |
28 | 0 | if (flags != 0) { |
29 | 0 | ErrorInvalidValue("flags must be 0"); |
30 | 0 | return nullptr; |
31 | 0 | } |
32 | 0 | |
33 | 0 | RefPtr<WebGLSync> globj = new WebGLSync(this, condition, flags); |
34 | 0 |
|
35 | 0 | const auto& availRunnable = EnsureAvailabilityRunnable(); |
36 | 0 | availRunnable->mSyncs.push_back(globj); |
37 | 0 |
|
38 | 0 | return globj.forget(); |
39 | 0 | } |
40 | | |
41 | | bool |
42 | | WebGL2Context::IsSync(const WebGLSync* const sync) |
43 | 0 | { |
44 | 0 | const FuncScope funcScope(*this, "isSync"); |
45 | 0 | return ValidateIsObject(sync); |
46 | 0 | } |
47 | | |
48 | | void |
49 | | WebGL2Context::DeleteSync(WebGLSync* sync) |
50 | 0 | { |
51 | 0 | const FuncScope funcScope(*this, "deleteSync"); |
52 | 0 | if (!ValidateDeleteObject(sync)) |
53 | 0 | return; |
54 | 0 | |
55 | 0 | sync->RequestDelete(); |
56 | 0 | } |
57 | | |
58 | | GLenum |
59 | | WebGL2Context::ClientWaitSync(const WebGLSync& sync, GLbitfield flags, GLuint64 timeout) |
60 | 0 | { |
61 | 0 | const FuncScope funcScope(*this, "clientWaitSync"); |
62 | 0 | if (IsContextLost()) |
63 | 0 | return LOCAL_GL_WAIT_FAILED; |
64 | 0 | |
65 | 0 | if (!ValidateObject("sync", sync)) |
66 | 0 | return LOCAL_GL_WAIT_FAILED; |
67 | 0 | |
68 | 0 | if (flags != 0 && flags != LOCAL_GL_SYNC_FLUSH_COMMANDS_BIT) { |
69 | 0 | ErrorInvalidValue("`flags` must be SYNC_FLUSH_COMMANDS_BIT or 0."); |
70 | 0 | return LOCAL_GL_WAIT_FAILED; |
71 | 0 | } |
72 | 0 |
|
73 | 0 | if (timeout > kMaxClientWaitSyncTimeoutNS) { |
74 | 0 | ErrorInvalidOperation("`timeout` must not exceed %s nanoseconds.", |
75 | 0 | "MAX_CLIENT_WAIT_TIMEOUT_WEBGL"); |
76 | 0 | return LOCAL_GL_WAIT_FAILED; |
77 | 0 | } |
78 | 0 |
|
79 | 0 | const bool canBeAvailable = (sync.mCanBeAvailable || |
80 | 0 | gfxPrefs::WebGLImmediateQueries()); |
81 | 0 | if (!canBeAvailable) { |
82 | 0 | if (timeout) { |
83 | 0 | GenerateWarning("Sync object not yet queryable. Please wait for the event" |
84 | 0 | " loop."); |
85 | 0 | } |
86 | 0 | return LOCAL_GL_WAIT_FAILED; |
87 | 0 | } |
88 | 0 |
|
89 | 0 | const auto ret = gl->fClientWaitSync(sync.mGLName, flags, timeout); |
90 | 0 |
|
91 | 0 | if (ret == LOCAL_GL_CONDITION_SATISFIED || |
92 | 0 | ret == LOCAL_GL_ALREADY_SIGNALED) |
93 | 0 | { |
94 | 0 | sync.MarkSignaled(); |
95 | 0 | } |
96 | 0 |
|
97 | 0 | return ret; |
98 | 0 | } |
99 | | |
100 | | void |
101 | | WebGL2Context::WaitSync(const WebGLSync& sync, GLbitfield flags, GLint64 timeout) |
102 | 0 | { |
103 | 0 | const FuncScope funcScope(*this, "waitSync"); |
104 | 0 | if (IsContextLost()) |
105 | 0 | return; |
106 | 0 | |
107 | 0 | if (!ValidateObject("sync", sync)) |
108 | 0 | return; |
109 | 0 | |
110 | 0 | if (flags != 0) { |
111 | 0 | ErrorInvalidValue("`flags` must be 0."); |
112 | 0 | return; |
113 | 0 | } |
114 | 0 | |
115 | 0 | if (timeout != -1) { |
116 | 0 | ErrorInvalidValue("`timeout` must be TIMEOUT_IGNORED."); |
117 | 0 | return; |
118 | 0 | } |
119 | 0 | |
120 | 0 | gl->fWaitSync(sync.mGLName, flags, LOCAL_GL_TIMEOUT_IGNORED); |
121 | 0 | } |
122 | | |
123 | | void |
124 | | WebGL2Context::GetSyncParameter(JSContext*, const WebGLSync& sync, GLenum pname, |
125 | | JS::MutableHandleValue retval) |
126 | 0 | { |
127 | 0 | const FuncScope funcScope(*this, "getSyncParameter"); |
128 | 0 | retval.setNull(); |
129 | 0 | if (IsContextLost()) |
130 | 0 | return; |
131 | 0 | |
132 | 0 | if (!ValidateObject("sync", sync)) |
133 | 0 | return; |
134 | 0 | |
135 | 0 | //// |
136 | 0 | |
137 | 0 | const bool canBeAvailable = (sync.mCanBeAvailable || |
138 | 0 | gfxPrefs::WebGLImmediateQueries()); |
139 | 0 | if (!canBeAvailable && pname == LOCAL_GL_SYNC_STATUS) { |
140 | 0 | retval.set(JS::Int32Value(LOCAL_GL_UNSIGNALED)); |
141 | 0 | return; |
142 | 0 | } |
143 | 0 |
|
144 | 0 | GLint result = 0; |
145 | 0 | switch (pname) { |
146 | 0 | case LOCAL_GL_OBJECT_TYPE: |
147 | 0 | case LOCAL_GL_SYNC_STATUS: |
148 | 0 | case LOCAL_GL_SYNC_CONDITION: |
149 | 0 | case LOCAL_GL_SYNC_FLAGS: |
150 | 0 | gl->fGetSynciv(sync.mGLName, pname, 1, nullptr, &result); |
151 | 0 |
|
152 | 0 | if (pname == LOCAL_GL_SYNC_STATUS && |
153 | 0 | result == LOCAL_GL_SIGNALED) |
154 | 0 | { |
155 | 0 | sync.MarkSignaled(); |
156 | 0 | } |
157 | 0 |
|
158 | 0 | retval.set(JS::Int32Value(result)); |
159 | 0 | return; |
160 | 0 |
|
161 | 0 | default: |
162 | 0 | ErrorInvalidEnumInfo("pname", pname); |
163 | 0 | return; |
164 | 0 | } |
165 | 0 | } |
166 | | |
167 | | } // namespace mozilla |