OLD | NEW |
1 // Copyright (c) 2015 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef GPU_COMMAND_BUFFER_SERVICE_GPU_TIMING_H_ | 5 #ifndef UI_GL_GPU_TIMING_H_ |
6 #define GPU_COMMAND_BUFFER_SERVICE_GPU_TIMING_H_ | 6 #define UI_GL_GPU_TIMING_H_ |
7 | 7 |
8 #include "base/callback.h" | 8 #include "base/callback.h" |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "ui/gl/gl_export.h" | 10 #include "ui/gl/gl_export.h" |
11 | 11 |
12 // The gpu_timing classes handles the abstraction of GL GPU Timing extensions | 12 // The gpu_timing classes handles the abstraction of GL GPU Timing extensions |
13 // into a common set of functions. Currently the different timer extensions | 13 // into a common set of functions. Currently the different timer extensions that |
14 // that are supported are ARB_timer_query and EXT_disjoint_timer_query. | 14 // are supported are EXT_timer_query, ARB_timer_query and |
| 15 // EXT_disjoint_timer_query. |
15 // | 16 // |
16 // Explanation of Classes: | 17 // Explanation of Classes: |
17 // GPUTiming - GPU Timing is a private class which is only owned by the | 18 // GPUTiming - GPU Timing is a private class which is only owned by the |
18 // underlying GLContextReal class. This class handles any GL Context level | 19 // underlying GLContextReal class. This class handles any GL Context level |
19 // states which may need to be redistributed to users of GPUTiming. For | 20 // states which may need to be redistributed to users of GPUTiming. For |
20 // example, there exists only a single disjoint flag for each real GL | 21 // example, there exists only a single disjoint flag for each real GL |
21 // Context. Once the disjoint flag is checked, internally it is reset to | 22 // Context. Once the disjoint flag is checked, internally it is reset to |
22 // false. In order to support multiple virtual contexts each checking the | 23 // false. In order to support multiple virtual contexts each checking the |
23 // disjoint flag seperately, GPUTiming is in charge of checking the | 24 // disjoint flag seperately, GPUTiming is in charge of checking the |
24 // disjoint flag and broadcasting out the disjoint state to all the | 25 // disjoint flag and broadcasting out the disjoint state to all the |
25 // various users of GPUTiming (GPUTimingClient below). | 26 // various users of GPUTiming (GPUTimingClient below). |
26 // GPUTimingClient - The GLContextReal holds the GPUTiming class and is the | 27 // GPUTimingClient - The GLContextReal holds the GPUTiming class and is the |
27 // factory that creates GPUTimingClient objects. If a user would like to | 28 // factory that creates GPUTimingClient objects. If a user would like to |
28 // obtain various GPU times they would access CreateGPUTimingClient() from | 29 // obtain various GPU times they would access CreateGPUTimingClient() from |
29 // their GLContext and use the returned object for their timing calls. | 30 // their GLContext and use the returned object for their timing calls. |
30 // Each virtual context as well as any other classes which need GPU times | 31 // Each virtual context as well as any other classes which need GPU times |
31 // will hold one of these. When they want to time a GPU trace they will | 32 // will hold one of these. When they want to time a set of GL commands they |
32 // create GPUTimer objects. | 33 // will create GPUTimer objects. |
33 // GPUTimer - Once a user decides to trace something, the user creates a new | 34 // GPUTimer - Once a user decides to time something, the user creates a new |
34 // GPUTimer object from a GPUTimingClient and issue Start() and Stop() calls | 35 // GPUTimer object from a GPUTimingClient and issue Start() and Stop() calls |
35 // around various GL Calls. Once IsAvailable() returns true, the GPU times | 36 // around various GL calls. Once IsAvailable() returns true, the GPU times |
36 // will be available through the various time stamp related functions. | 37 // will be available through the various time stamp related functions. |
37 // The constructor and destructor of this object handles the actual | 38 // The constructor and destructor of this object handles the actual |
38 // creation and deletion of the GL Queries within GL. | 39 // creation and deletion of the GL Queries within GL. |
39 | 40 |
40 namespace gfx { | 41 namespace gfx { |
41 | 42 |
42 class GLContextReal; | 43 class GLContextReal; |
43 class GPUTimingClient; | 44 class GPUTimingClient; |
44 | 45 |
45 class GPUTiming { | 46 class GPUTiming { |
46 public: | 47 public: |
47 enum TimerType { | 48 enum TimerType { |
48 kTimerTypeInvalid = -1, | 49 kTimerTypeInvalid = -1, |
49 | 50 |
| 51 kTimerTypeEXT, // EXT_timer_query |
50 kTimerTypeARB, // ARB_timer_query | 52 kTimerTypeARB, // ARB_timer_query |
51 kTimerTypeDisjoint // EXT_disjoint_timer_query | 53 kTimerTypeDisjoint // EXT_disjoint_timer_query |
52 }; | 54 }; |
53 | 55 |
54 TimerType GetTimerType() const { return timer_type_; } | 56 TimerType GetTimerType() const { return timer_type_; } |
55 uint32_t GetDisjointCount(); | 57 uint32_t GetDisjointCount(); |
56 | 58 |
57 private: | 59 private: |
58 friend struct base::DefaultDeleter<GPUTiming>; | 60 friend struct base::DefaultDeleter<GPUTiming>; |
59 friend class GLContextReal; | 61 friend class GLContextReal; |
| 62 friend class GPUTimer; |
60 explicit GPUTiming(GLContextReal* context); | 63 explicit GPUTiming(GLContextReal* context); |
61 ~GPUTiming(); | 64 ~GPUTiming(); |
62 | 65 |
63 scoped_refptr<GPUTimingClient> CreateGPUTimingClient(); | 66 scoped_refptr<GPUTimingClient> CreateGPUTimingClient(); |
64 | 67 |
65 TimerType timer_type_ = kTimerTypeInvalid; | 68 TimerType timer_type_ = kTimerTypeInvalid; |
66 uint32_t disjoint_counter_ = 0; | 69 uint32_t disjoint_counter_ = 0; |
67 DISALLOW_COPY_AND_ASSIGN(GPUTiming); | 70 DISALLOW_COPY_AND_ASSIGN(GPUTiming); |
68 }; | 71 }; |
69 | 72 |
(...skipping 25 matching lines...) Expand all Loading... |
95 | 98 |
96 // GPUTimingClient contains all the gl timing logic that is not specific | 99 // GPUTimingClient contains all the gl timing logic that is not specific |
97 // to a single GPUTimer. | 100 // to a single GPUTimer. |
98 class GL_EXPORT GPUTimingClient | 101 class GL_EXPORT GPUTimingClient |
99 : public base::RefCounted<GPUTimingClient> { | 102 : public base::RefCounted<GPUTimingClient> { |
100 public: | 103 public: |
101 explicit GPUTimingClient(GPUTiming* gpu_timing = nullptr); | 104 explicit GPUTimingClient(GPUTiming* gpu_timing = nullptr); |
102 | 105 |
103 scoped_ptr<GPUTimer> CreateGPUTimer(); | 106 scoped_ptr<GPUTimer> CreateGPUTimer(); |
104 bool IsAvailable(); | 107 bool IsAvailable(); |
| 108 bool IsTimerOffsetAvailable(); |
| 109 |
105 const char* GetTimerTypeName() const; | 110 const char* GetTimerTypeName() const; |
106 | 111 |
107 // CheckAndResetTimerErrors has to be called before reading timestamps | 112 // CheckAndResetTimerErrors has to be called before reading timestamps |
108 // from GPUTimers instances and after making sure all the timers | 113 // from GPUTimers instances and after making sure all the timers |
109 // were available. | 114 // were available. |
110 // If the returned value is false, all the previous timers should be | 115 // If the returned value is false, all the previous timers should be |
111 // discarded. | 116 // discarded. |
112 bool CheckAndResetTimerErrors(); | 117 bool CheckAndResetTimerErrors(); |
113 | 118 |
114 // Returns the offset between the current gpu time and the cpu time. | 119 // Returns the offset between the current gpu time and the cpu time. |
(...skipping 14 matching lines...) Expand all Loading... |
129 int64 offset_ = 0; // offset cache when timer_type_ == kTimerTypeARB | 134 int64 offset_ = 0; // offset cache when timer_type_ == kTimerTypeARB |
130 uint32_t disjoint_counter_ = 0; | 135 uint32_t disjoint_counter_ = 0; |
131 bool offset_valid_ = false; | 136 bool offset_valid_ = false; |
132 base::Callback<int64(void)> cpu_time_for_testing_; | 137 base::Callback<int64(void)> cpu_time_for_testing_; |
133 | 138 |
134 DISALLOW_COPY_AND_ASSIGN(GPUTimingClient); | 139 DISALLOW_COPY_AND_ASSIGN(GPUTimingClient); |
135 }; | 140 }; |
136 | 141 |
137 } // namespace gfx | 142 } // namespace gfx |
138 | 143 |
139 #endif // GPU_COMMAND_BUFFER_SERVICE_GPU_TIMING_H_ | 144 #endif // UI_GL_GPU_TIMING_H_ |
OLD | NEW |