File: gpu_timing_fake.h

package info (click to toggle)
chromium 138.0.7204.183-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 6,071,908 kB
  • sloc: cpp: 34,937,088; ansic: 7,176,967; javascript: 4,110,704; python: 1,419,953; asm: 946,768; xml: 739,971; pascal: 187,324; sh: 89,623; perl: 88,663; objc: 79,944; sql: 50,304; cs: 41,786; fortran: 24,137; makefile: 21,806; php: 13,980; tcl: 13,166; yacc: 8,925; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (90 lines) | stat: -rw-r--r-- 2,692 bytes parent folder | download | duplicates (11)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
// Copyright 2015 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef UI_GL_GPU_TIMING_FAKE_H_
#define UI_GL_GPU_TIMING_FAKE_H_

#include <stdint.h>

#include <map>
#include <set>

#include "ui/gl/gl_bindings.h"

namespace gl {
class MockGLInterface;

class GPUTimingFake {
 public:
  GPUTimingFake();
  ~GPUTimingFake();

  void Reset();

  // Used to set the current GPU time queries will return.
  static int64_t GetFakeCPUTime(); // Useful for binding for Fake CPU time.
  void SetCurrentCPUTime(int64_t current_time);
  void SetCurrentGLTime(GLint64 current_time);
  void SetCPUGLOffset(int64_t offset);

  // Used to signal a disjoint occurred for disjoint timer queries.
  void SetDisjoint();

  // GPUTimer fake queries which can be called multiple times.
  void ExpectGetErrorCalls(MockGLInterface& gl);
  void ExpectDisjointCalls(MockGLInterface& gl);
  void ExpectNoDisjointCalls(MockGLInterface& gl);

  // GPUTimer fake queries which can only be called once per setup.
  void ExpectGPUTimeStampQuery(MockGLInterface& gl, bool elapsed_query);
  void ExpectGPUTimerQuery(MockGLInterface& gl, bool elapsed_query);
  void ExpectOffsetCalculationQuery(MockGLInterface& gl);
  void ExpectNoOffsetCalculationQuery(MockGLInterface& gl);

  // Fake GL Functions.
  void FakeGLGenQueries(GLsizei n, GLuint* ids);
  void FakeGLDeleteQueries(GLsizei n, const GLuint* ids);
  void FakeGLBeginQuery(GLenum target, GLuint id);
  void FakeGLEndQuery(GLenum target);
  void FakeGLGetQueryObjectuiv(GLuint id, GLenum pname, GLuint* params);
  void FakeGLQueryCounter(GLuint id, GLenum target);
  void FakeGLGetInteger64v(GLenum pname, GLint64 * data);
  void FakeGLGetQueryObjectui64v(GLuint id, GLenum pname, GLuint64* params);
  void FakeGLGetIntegerv(GLenum pname, GLint* params);
  GLenum FakeGLGetError();

 protected:
  bool disjointed_ = false;
  static int64_t fake_cpu_time_;
  GLint64 current_gl_time_ = 0;
  int64_t gl_cpu_time_offset_ = 0;
  GLuint next_query_id_ = 0;
  std::set<GLuint> allocated_queries_;
  struct QueryResult {
    enum QueryResultType {
      kQueryResultType_Invalid,
      kQueryResultType_TimeStamp,
      kQueryResultType_Elapsed
    } type_ = kQueryResultType_Invalid;
    GLint64 begin_time_ = 0;
    GLint64 value_ = 0;
  };
  std::map<GLuint, QueryResult> query_results_;
  struct ElapsedQuery {
    bool active_ = false;
    GLuint query_id_ = 0;
    GLint64 begin_time_ = 0;

    void Reset() {
      active_ = false;
      query_id_ = 0;
      begin_time_ = 0;
    }
  };
  ElapsedQuery current_elapsed_query_;
};

}  // namespace gl

#endif  // UI_GL_GPU_TIMING_FAKE_H_