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_QUERY_H_
7 #define WEBGL_QUERY_H_
8 
9 #include "WebGLObjectModel.h"
10 #include "nsThreadUtils.h"
11 
12 namespace mozilla {
13 namespace webgl {
14 class AvailabilityRunnable;
15 }  // namespace webgl
16 
17 class WebGLQuery final : public WebGLContextBoundObject {
18   friend class webgl::AvailabilityRunnable;
19 
20   MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(WebGLQuery, override)
21 
22  public:
23   const GLuint mGLName;
24 
25  private:
26   GLenum mTarget;
27   RefPtr<WebGLQuery>* mActiveSlot;
28 
29   bool mCanBeAvailable = false;  // Track whether the event loop has spun
30 
31   ////
32  public:
Target()33   GLenum Target() const { return mTarget; }
IsActive()34   bool IsActive() const { return bool(mActiveSlot); }
35 
36   ////
37 
38   explicit WebGLQuery(WebGLContext* webgl);
39 
40  private:
41   ~WebGLQuery() override;
42 
43  public:
44   ////
45 
46   void BeginQuery(GLenum target, RefPtr<WebGLQuery>& slot);
47   void EndQuery();
48   Maybe<double> GetQueryParameter(GLenum pname) const;
49   void QueryCounter();
50 };
51 
52 }  // namespace mozilla
53 
54 #endif  // WEBGL_QUERY_H_
55