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 "WebGLObjectModel.h"
13 class AvailabilityRunnable
;
16 virtual ~Task() = default;
17 virtual void operator()() const = 0;
21 struct FnTask
: public Task
{
24 explicit FnTask(F
&& fn
) : fn(std::move(fn
)) {}
26 virtual void operator()() const override
{ fn(); }
30 enum class ClientWaitSyncResult
: GLenum
{
31 WAIT_FAILED
= LOCAL_GL_WAIT_FAILED
,
32 TIMEOUT_EXPIRED
= LOCAL_GL_TIMEOUT_EXPIRED
,
33 CONDITION_SATISFIED
= LOCAL_GL_CONDITION_SATISFIED
,
34 ALREADY_SIGNALED
= LOCAL_GL_ALREADY_SIGNALED
,
37 class WebGLSync final
: public WebGLContextBoundObject
, public SupportsWeakPtr
{
38 friend class WebGL2Context
;
39 friend class webgl::AvailabilityRunnable
;
41 MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(WebGLSync
, override
)
44 const uint64_t mFenceId
;
45 bool mCanBeAvailable
= false;
47 std::optional
<std::vector
<std::unique_ptr
<webgl::Task
>>> mOnCompleteTasks
=
48 std::vector
<std::unique_ptr
<webgl::Task
>>{};
51 WebGLSync(WebGLContext
* webgl
, GLenum condition
, GLbitfield flags
);
53 ClientWaitSyncResult
ClientWaitSync(GLbitfield flags
, GLuint64 timeout
);
56 void OnCompleteTaskAdd(F
&& fn
) {
57 MOZ_RELEASE_ASSERT(mOnCompleteTasks
);
58 auto task
= std::make_unique
<webgl::FnTask
<F
>>(std::move(fn
));
59 mOnCompleteTasks
->push_back(std::move(task
));
62 bool IsKnownComplete() const { return !mOnCompleteTasks
; }
65 ~WebGLSync() override
;
68 } // namespace mozilla
70 #endif // WEBGL_SYNC_H_