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 void clearInternalQueries(); 59 60 template <typename T> 61 angle::Result getResultBase(const gl::Context *context, T *params); 62 63 const FunctionsGL *mFunctions; 64 StateManagerGL *mStateManager; 65 66 GLuint mActiveQuery; 67 std::deque<GLuint> mPendingQueries; 68 GLuint64 mResultSum; 69 }; 70 71 class SyncProviderGL; 72 class SyncQueryGL : public QueryGL 73 { 74 public: 75 SyncQueryGL(gl::QueryType type, const FunctionsGL *functions); 76 ~SyncQueryGL() override; 77 78 static bool IsSupported(const FunctionsGL *functions); 79 80 angle::Result begin(const gl::Context *context) override; 81 angle::Result end(const gl::Context *context) override; 82 angle::Result queryCounter(const gl::Context *context) override; 83 angle::Result getResult(const gl::Context *context, GLint *params) override; 84 angle::Result getResult(const gl::Context *context, GLuint *params) override; 85 angle::Result getResult(const gl::Context *context, GLint64 *params) override; 86 angle::Result getResult(const gl::Context *context, GLuint64 *params) override; 87 angle::Result isResultAvailable(const gl::Context *context, bool *available) override; 88 89 angle::Result pause(const gl::Context *context) override; 90 angle::Result resume(const gl::Context *context) override; 91 92 private: 93 angle::Result flush(const gl::Context *context, bool force); 94 95 template <typename T> 96 angle::Result getResultBase(const gl::Context *context, T *params); 97 98 const FunctionsGL *mFunctions; 99 100 std::unique_ptr<SyncProviderGL> mSyncProvider; 101 bool mFinished; 102 }; 103 } // namespace rx 104 105 #endif // LIBANGLE_RENDERER_GL_QUERYGL_H_ 106