gpu_timing_fake.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. // Copyright 2015 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #ifndef UI_GL_GPU_TIMING_FAKE_H_
  5. #define UI_GL_GPU_TIMING_FAKE_H_
  6. #include <stdint.h>
  7. #include <map>
  8. #include <set>
  9. #include "ui/gl/gl_bindings.h"
  10. namespace gl {
  11. class MockGLInterface;
  12. class GPUTimingFake {
  13. public:
  14. GPUTimingFake();
  15. ~GPUTimingFake();
  16. void Reset();
  17. // Used to set the current GPU time queries will return.
  18. static int64_t GetFakeCPUTime(); // Useful for binding for Fake CPU time.
  19. void SetCurrentCPUTime(int64_t current_time);
  20. void SetCurrentGLTime(GLint64 current_time);
  21. void SetCPUGLOffset(int64_t offset);
  22. // Used to signal a disjoint occurred for disjoint timer queries.
  23. void SetDisjoint();
  24. // GPUTimer fake queries which can be called multiple times.
  25. void ExpectGetErrorCalls(MockGLInterface& gl);
  26. void ExpectDisjointCalls(MockGLInterface& gl);
  27. void ExpectNoDisjointCalls(MockGLInterface& gl);
  28. // GPUTimer fake queries which can only be called once per setup.
  29. void ExpectGPUTimeStampQuery(MockGLInterface& gl, bool elapsed_query);
  30. void ExpectGPUTimerQuery(MockGLInterface& gl, bool elapsed_query);
  31. void ExpectOffsetCalculationQuery(MockGLInterface& gl);
  32. void ExpectNoOffsetCalculationQuery(MockGLInterface& gl);
  33. // Fake GL Functions.
  34. void FakeGLGenQueries(GLsizei n, GLuint* ids);
  35. void FakeGLDeleteQueries(GLsizei n, const GLuint* ids);
  36. void FakeGLBeginQuery(GLenum target, GLuint id);
  37. void FakeGLEndQuery(GLenum target);
  38. void FakeGLGetQueryObjectuiv(GLuint id, GLenum pname, GLuint* params);
  39. void FakeGLQueryCounter(GLuint id, GLenum target);
  40. void FakeGLGetInteger64v(GLenum pname, GLint64 * data);
  41. void FakeGLGetQueryObjectui64v(GLuint id, GLenum pname, GLuint64* params);
  42. void FakeGLGetIntegerv(GLenum pname, GLint* params);
  43. GLenum FakeGLGetError();
  44. protected:
  45. bool disjointed_ = false;
  46. static int64_t fake_cpu_time_;
  47. GLint64 current_gl_time_ = 0;
  48. int64_t gl_cpu_time_offset_ = 0;
  49. GLuint next_query_id_ = 0;
  50. std::set<GLuint> allocated_queries_;
  51. struct QueryResult {
  52. enum QueryResultType {
  53. kQueryResultType_Invalid,
  54. kQueryResultType_TimeStamp,
  55. kQueryResultType_Elapsed
  56. } type_ = kQueryResultType_Invalid;
  57. GLint64 begin_time_ = 0;
  58. GLint64 value_ = 0;
  59. };
  60. std::map<GLuint, QueryResult> query_results_;
  61. struct ElapsedQuery {
  62. bool active_ = false;
  63. GLuint query_id_ = 0;
  64. GLint64 begin_time_ = 0;
  65. void Reset() {
  66. active_ = false;
  67. query_id_ = 0;
  68. begin_time_ = 0;
  69. }
  70. };
  71. ElapsedQuery current_elapsed_query_;
  72. };
  73. } // namespace gl
  74. #endif // UI_GL_GPU_TIMING_FAKE_H_