Bug 1936278 - Prevent search mode chiclet from being dismissed when clicking in page...
[gecko.git] / dom / canvas / WebGLSync.h
blob48ed2ee58f565eeec85711217c976256a096e1b4
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 #ifndef WEBGL_SYNC_H_
7 #define WEBGL_SYNC_H_
9 #include "WebGLObjectModel.h"
11 namespace mozilla {
12 namespace webgl {
13 class AvailabilityRunnable;
15 struct Task {
16 virtual ~Task() = default;
17 virtual void operator()() const = 0;
20 template <class F>
21 struct FnTask : public Task {
22 const F fn;
24 explicit FnTask(F&& fn) : fn(std::move(fn)) {}
26 virtual void operator()() const override { fn(); }
28 } // namespace webgl
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)
43 const GLsync mGLName;
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>>{};
50 public:
51 WebGLSync(WebGLContext* webgl, GLenum condition, GLbitfield flags);
53 ClientWaitSyncResult ClientWaitSync(GLbitfield flags, GLuint64 timeout);
55 template <class F>
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; }
64 private:
65 ~WebGLSync() override;
68 } // namespace mozilla
70 #endif // WEBGL_SYNC_H_