1 //
2 // Copyright 2015 The ANGLE Project Authors. All rights reserved.
3 // Use of this source code is governed by a BSD-style license that can be
4 // found in the LICENSE file.
5 //
6 
7 // QueryGL.h: Defines the class interface for QueryGL.
8 
9 #ifndef LIBANGLE_RENDERER_GL_QUERYGL_H_
10 #define LIBANGLE_RENDERER_GL_QUERYGL_H_
11 
12 #include <deque>
13 
14 #include "libANGLE/renderer/QueryImpl.h"
15 
16 namespace rx
17 {
18 
19 class FunctionsGL;
20 class StateManagerGL;
21 
22 class QueryGL : public QueryImpl
23 {
24   public:
25     QueryGL(gl::QueryType type);
26     ~QueryGL() override;
27 
28     // OpenGL is only allowed to have one query of each type active at any given time. Since ANGLE
29     // virtualizes contexts, queries need to be able to be paused and resumed.
30     // A query is "paused" by ending it and pushing the ID into a list of queries awaiting readback.
31     // When it is "resumed", a new query is generated and started.
32     // When a result is required, the queries are "flushed" by iterating over the list of pending
33     // queries and merging their results.
34     virtual angle::Result pause(const gl::Context *context)  = 0;
35     virtual angle::Result resume(const gl::Context *context) = 0;
36 };
37 
38 class StandardQueryGL : public QueryGL
39 {
40   public:
41     StandardQueryGL(gl::QueryType type, const FunctionsGL *functions, StateManagerGL *stateManager);
42     ~StandardQueryGL() override;
43 
44     angle::Result begin(const gl::Context *context) override;
45     angle::Result end(const gl::Context *context) override;
46     angle::Result queryCounter(const gl::Context *context) override;
47     angle::Result getResult(const gl::Context *context, GLint *params) override;
48     angle::Result getResult(const gl::Context *context, GLuint *params) override;
49     angle::Result getResult(const gl::Context *context, GLint64 *params) override;
50     angle::Result getResult(const gl::Context *context, GLuint64 *params) override;
51     angle::Result isResultAvailable(const gl::Context *context, bool *available) override;
52 
53     angle::Result pause(const gl::Context *context) override;
54     angle::Result resume(const gl::Context *context) override;
55 
56   private:
57     angle::Result flush(const gl::Context *context, bool force);
58 
59     template <typename T>
60     angle::Result getResultBase(const gl::Context *context, T *params);
61 
62     const FunctionsGL *mFunctions;
63     StateManagerGL *mStateManager;
64 
65     GLuint mActiveQuery;
66     std::deque<GLuint> mPendingQueries;
67     GLuint64 mResultSum;
68 };
69 
70 class SyncProviderGL;
71 class SyncQueryGL : public QueryGL
72 {
73   public:
74     SyncQueryGL(gl::QueryType type, const FunctionsGL *functions);
75     ~SyncQueryGL() override;
76 
77     static bool IsSupported(const FunctionsGL *functions);
78 
79     angle::Result begin(const gl::Context *context) override;
80     angle::Result end(const gl::Context *context) override;
81     angle::Result queryCounter(const gl::Context *context) override;
82     angle::Result getResult(const gl::Context *context, GLint *params) override;
83     angle::Result getResult(const gl::Context *context, GLuint *params) override;
84     angle::Result getResult(const gl::Context *context, GLint64 *params) override;
85     angle::Result getResult(const gl::Context *context, GLuint64 *params) override;
86     angle::Result isResultAvailable(const gl::Context *context, bool *available) override;
87 
88     angle::Result pause(const gl::Context *context) override;
89     angle::Result resume(const gl::Context *context) override;
90 
91   private:
92     angle::Result flush(const gl::Context *context, bool force);
93 
94     template <typename T>
95     angle::Result getResultBase(const gl::Context *context, T *params);
96 
97     const FunctionsGL *mFunctions;
98 
99     std::unique_ptr<SyncProviderGL> mSyncProvider;
100     bool mFinished;
101 };
102 }  // namespace rx
103 
104 #endif  // LIBANGLE_RENDERER_GL_QUERYGL_H_
105