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 GPU_COMMAND_BUFFER_SERVICE_GPU_TIMING_H_ |
6 #define GPU_COMMAND_BUFFER_SERVICE_GPU_TIMING_H_ | 6 #define GPU_COMMAND_BUFFER_SERVICE_GPU_TIMING_H_ |
7 | 7 |
8 #include <vector> | |
9 | |
8 #include "base/callback.h" | 10 #include "base/callback.h" |
9 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
10 #include "gpu/gpu_export.h" | 12 #include "gpu/gpu_export.h" |
11 | 13 |
12 namespace gfx { | 14 namespace gfx { |
13 class GLContext; | 15 class GLContext; |
14 } | 16 } |
15 | 17 |
16 namespace gpu { | 18 namespace gpu { |
17 class GPUTiming; | 19 class GPUTiming; |
(...skipping 26 matching lines...) Expand all Loading... | |
44 // to a single GPUTimer. | 46 // to a single GPUTimer. |
45 class GPU_EXPORT GPUTiming { | 47 class GPU_EXPORT GPUTiming { |
46 public: | 48 public: |
47 enum TimerType { | 49 enum TimerType { |
48 kTimerTypeInvalid = -1, | 50 kTimerTypeInvalid = -1, |
49 | 51 |
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 GPUTiming(); | 56 GPUTiming(gfx::GLContext* gl_context = NULL); |
Daniele Castagna
2015/02/23 22:21:19
nit: explicit
Why do you pass the context here? A
| |
55 virtual ~GPUTiming(); | 57 virtual ~GPUTiming(); |
56 | 58 |
57 bool Initialize(gfx::GLContext* context); | 59 void Initialize(gfx::GLContext* gl_context); |
58 bool IsAvailable(); | 60 bool IsAvailable(); |
59 | 61 |
62 int CreateDisjointContextID(); | |
63 bool ReleaseDisjointContextID(int disjoint_context_id); | |
64 int GetDisjointContextIDCount() const; | |
65 | |
60 // CheckAndResetTimerErrors has to be called before reading timestamps | 66 // CheckAndResetTimerErrors has to be called before reading timestamps |
61 // from GPUTimers instances and after making sure all the timers | 67 // from GPUTimers instances and after making sure all the timers |
62 // were available. | 68 // were available. |
63 // If the returned value is false, all the previous timers should be | 69 // If the returned value is false, all the previous timers should be |
64 // discarded. | 70 // discarded. |
65 bool CheckAndResetTimerErrors(); | 71 bool CheckAndResetTimerErrors(int disjoint_context_id); |
Daniele Castagna
2015/02/23 22:21:19
Can you leave the previous method as well, so that
| |
66 | 72 |
73 TimerType GetTimerType() const { return timer_type_; } | |
67 const char* GetTimerTypeName() const; | 74 const char* GetTimerTypeName() const; |
68 | 75 |
69 // Returns the offset between the current gpu time and the cpu time. | 76 // Returns the offset between the current gpu time and the cpu time. |
70 int64 CalculateTimerOffset(); | 77 int64 CalculateTimerOffset(); |
71 void InvalidateTimerOffset(); | 78 void InvalidateTimerOffset(); |
72 | 79 |
73 void SetCpuTimeForTesting(const base::Callback<int64(void)>& cpu_time); | 80 void SetCpuTimeForTesting(const base::Callback<int64(void)>& cpu_time); |
74 void SetOffsetForTesting(int64 offset, bool cache_it); | |
75 void SetTimerTypeForTesting(TimerType type); | |
76 | 81 |
77 private: | 82 private: |
78 TimerType timer_type_ = kTimerTypeInvalid; | 83 TimerType timer_type_ = kTimerTypeInvalid; |
79 int64 offset_ = 0; // offset cache when timer_type_ == kTimerTypeARB | 84 int64 offset_ = 0; // offset cache when timer_type_ == kTimerTypeARB |
80 bool offset_valid_ = false; | 85 bool offset_valid_ = false; |
86 bool disjoint_occurred_ = false; | |
81 base::Callback<int64(void)> cpu_time_for_testing_; | 87 base::Callback<int64(void)> cpu_time_for_testing_; |
88 | |
89 struct DisjointContext { | |
90 DisjointContext(bool initial_value) | |
91 : valid_(true), | |
92 disjoint_value_(initial_value) { | |
93 } | |
94 bool valid_; | |
95 bool disjoint_value_; | |
96 }; | |
97 std::vector<DisjointContext> disjoint_contexts_; | |
Daniele Castagna
2015/02/23 22:21:19
You never shrink this vector when a context is rel
| |
98 | |
82 friend class GPUTimer; | 99 friend class GPUTimer; |
83 DISALLOW_COPY_AND_ASSIGN(GPUTiming); | 100 DISALLOW_COPY_AND_ASSIGN(GPUTiming); |
84 }; | 101 }; |
85 } // namespace gpu | 102 } // namespace gpu |
86 | 103 |
87 #endif // GPU_COMMAND_BUFFER_SERVICE_GPU_TIMING_H_ | 104 #endif // GPU_COMMAND_BUFFER_SERVICE_GPU_TIMING_H_ |
OLD | NEW |