tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

WebGLSync.h (1900B)


      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/. */
      5 
      6 #ifndef WEBGL_SYNC_H_
      7 #define WEBGL_SYNC_H_
      8 
      9 #include "WebGLObjectModel.h"
     10 
     11 namespace mozilla {
     12 namespace webgl {
     13 class AvailabilityRunnable;
     14 
     15 struct Task {
     16  virtual ~Task() = default;
     17  virtual void operator()() const = 0;
     18 };
     19 
     20 template <class F>
     21 struct FnTask : public Task {
     22  const F fn;
     23 
     24  explicit FnTask(F&& fn) : fn(std::move(fn)) {}
     25 
     26  virtual void operator()() const override { fn(); }
     27 };
     28 }  // namespace webgl
     29 
     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,
     35 };
     36 
     37 class WebGLSync final : public WebGLContextBoundObject, public SupportsWeakPtr {
     38  friend class WebGL2Context;
     39  friend class webgl::AvailabilityRunnable;
     40 
     41  MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(WebGLSync, override)
     42 
     43  GLsync mGLName = 0;
     44  const uint64_t mFenceId;
     45  bool mCanBeAvailable = false;
     46 
     47  std::optional<std::vector<std::unique_ptr<webgl::Task>>> mOnCompleteTasks =
     48      std::vector<std::unique_ptr<webgl::Task>>{};
     49 
     50 public:
     51  WebGLSync(WebGLContext* webgl, GLenum condition, GLbitfield flags);
     52 
     53  ClientWaitSyncResult ClientWaitSync(GLbitfield flags, GLuint64 timeout);
     54 
     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));
     60  }
     61 
     62  bool IsKnownComplete() const { return !mOnCompleteTasks; }
     63 
     64 private:
     65  ~WebGLSync() override;
     66 };
     67 
     68 }  // namespace mozilla
     69 
     70 #endif  // WEBGL_SYNC_H_