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); |
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 | |
60 // CheckAndResetTimerErrors has to be called before reading timestamps | 65 // CheckAndResetTimerErrors has to be called before reading timestamps |
61 // from GPUTimers instances and after making sure all the timers | 66 // from GPUTimers instances and after making sure all the timers |
62 // were available. | 67 // were available. |
63 // If the returned value is false, all the previous timers should be | 68 // If the returned value is false, all the previous timers should be |
64 // discarded. | 69 // discarded. |
65 bool CheckAndResetTimerErrors(); | 70 bool CheckAndResetTimerErrors(int disjoint_context_id); |
66 | 71 |
72 TimerType GetTimerType() const { return timer_type_; } | |
67 const char* GetTimerTypeName() const; | 73 const char* GetTimerTypeName() const; |
68 | 74 |
69 // Returns the offset between the current gpu time and the cpu time. | 75 // Returns the offset between the current gpu time and the cpu time. |
70 int64 CalculateTimerOffset(); | 76 int64 CalculateTimerOffset(); |
71 void InvalidateTimerOffset(); | 77 void InvalidateTimerOffset(); |
72 | 78 |
73 void SetCpuTimeForTesting(const base::Callback<int64(void)>& cpu_time); | 79 void SetCpuTimeForTesting(const base::Callback<int64(void)>& cpu_time); |
74 void SetOffsetForTesting(int64 offset, bool cache_it); | |
75 void SetTimerTypeForTesting(TimerType type); | |
76 | 80 |
77 private: | 81 private: |
78 TimerType timer_type_ = kTimerTypeInvalid; | 82 TimerType timer_type_ = kTimerTypeInvalid; |
79 int64 offset_ = 0; // offset cache when timer_type_ == kTimerTypeARB | 83 int64 offset_ = 0; // offset cache when timer_type_ == kTimerTypeARB |
80 bool offset_valid_ = false; | 84 bool offset_valid_ = false; |
85 bool disjoint_occurred_ = false; | |
81 base::Callback<int64(void)> cpu_time_for_testing_; | 86 base::Callback<int64(void)> cpu_time_for_testing_; |
87 | |
88 struct DisjointContext { | |
89 DisjointContext(bool initial_value) | |
90 : valid_(true), | |
91 disjoint_value_(initial_value) { | |
92 } | |
93 bool valid_; | |
Daniele Castagna
2015/02/23 22:21:19
Do we need this? Can't we just keep valid context
| |
94 bool disjoint_value_; | |
95 }; | |
96 std::vector<DisjointContext> disjoint_contexts_; | |
97 | |
82 friend class GPUTimer; | 98 friend class GPUTimer; |
83 DISALLOW_COPY_AND_ASSIGN(GPUTiming); | 99 DISALLOW_COPY_AND_ASSIGN(GPUTiming); |
84 }; | 100 }; |
85 } // namespace gpu | 101 } // namespace gpu |
86 | 102 |
87 #endif // GPU_COMMAND_BUFFER_SERVICE_GPU_TIMING_H_ | 103 #endif // GPU_COMMAND_BUFFER_SERVICE_GPU_TIMING_H_ |
OLD | NEW |