Chromium Code Reviews| 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 #include "ui/gl/gl_bindings.h" | 13 #include "ui/gl/gl_bindings.h" |
| 12 | 14 |
| 13 namespace gpu { | 15 namespace gpu { |
| 14 | 16 |
| 15 class GPUTiming; | 17 class GPUTiming; |
| 16 | 18 |
| 17 // Class to compute the amount of time it takes to fully | 19 // Class to compute the amount of time it takes to fully |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 31 | 33 |
| 32 private: | 34 private: |
| 33 GLuint queries_[2]; | 35 GLuint queries_[2]; |
| 34 int64 offset_ = 0; | 36 int64 offset_ = 0; |
| 35 bool end_requested_ = false; | 37 bool end_requested_ = false; |
| 36 GPUTiming* gpu_timing_; | 38 GPUTiming* gpu_timing_; |
| 37 | 39 |
| 38 DISALLOW_COPY_AND_ASSIGN(GPUTimer); | 40 DISALLOW_COPY_AND_ASSIGN(GPUTimer); |
| 39 }; | 41 }; |
| 40 | 42 |
| 43 // DisjointContext keeps track of disjoint conditions which invalidate | |
| 44 // timing values. Each GPUTiming class can keep track of multiple | |
| 45 // DisjointContexts so that a single GL Context can support multiple | |
| 46 // tracings. | |
| 47 class GPU_EXPORT DisjointContext : public base::RefCounted<DisjointContext> { | |
| 48 public: | |
| 49 // CheckAndResetTimerErrors has to be called before reading timestamps | |
| 50 // from GPUTimers instances and after making sure all the timers | |
| 51 // were available. | |
| 52 // If the returned value is false, all the previous timers should be | |
| 53 // discarded. | |
| 54 bool CheckAndResetTimerErrors(); | |
| 55 | |
| 56 protected: | |
| 57 DisjointContext(GPUTiming* gpu_timing, bool disjoint_value); | |
| 58 virtual ~DisjointContext(); | |
| 59 friend class base::RefCounted<DisjointContext>; | |
| 60 | |
| 61 private: | |
| 62 void ResetParentGPUTiming(); | |
| 63 void SetDisjoint(); | |
| 64 | |
| 65 GPUTiming* gpu_timing_; | |
| 66 bool disjoint_value_; | |
| 67 friend class GPUTiming; | |
| 68 }; | |
| 69 | |
| 41 // GPUTiming contains all the gl timing logic that is not specific | 70 // GPUTiming contains all the gl timing logic that is not specific |
| 42 // to a single GPUTimer. | 71 // to a single GPUTimer. |
| 43 class GPU_EXPORT GPUTiming { | 72 class GPU_EXPORT GPUTiming { |
| 44 public: | 73 public: |
| 45 enum TimerType { | 74 enum TimerType { |
| 46 kTimerTypeInvalid = -1, | 75 kTimerTypeInvalid = -1, |
| 47 | 76 |
| 48 kTimerTypeARB, // ARB_timer_query | 77 kTimerTypeARB, // ARB_timer_query |
| 49 kTimerTypeDisjoint // EXT_disjoint_timer_query | 78 kTimerTypeDisjoint // EXT_disjoint_timer_query |
| 50 }; | 79 }; |
| 51 | 80 |
| 52 GPUTiming(); | 81 GPUTiming(); |
| 53 virtual ~GPUTiming(); | 82 virtual ~GPUTiming(); |
| 54 | 83 |
| 55 bool Initialize(gfx::GLContext* context); | 84 bool Initialize(gfx::GLContext* context); |
| 56 bool IsAvailable(); | 85 bool IsAvailable(); |
| 57 | 86 |
| 58 // CheckAndResetTimerErrors has to be called before reading timestamps | 87 scoped_refptr<DisjointContext> CreateDisjointContext(); |
| 59 // from GPUTimers instances and after making sure all the timers | 88 size_t GetDisjointContextsCount() { return disjoint_contexts_.size(); } |
| 60 // were available. | |
| 61 // If the returned value is false, all the previous timers should be | |
| 62 // discarded. | |
| 63 bool CheckAndResetTimerErrors(); | |
| 64 | 89 |
| 65 const char* GetTimerTypeName() const; | 90 const char* GetTimerTypeName() const; |
| 66 | 91 |
| 67 // Returns the offset between the current gpu time and the cpu time. | 92 // Returns the offset between the current gpu time and the cpu time. |
| 68 int64 CalculateTimerOffset(); | 93 int64 CalculateTimerOffset(); |
| 69 void InvalidateTimerOffset(); | 94 void InvalidateTimerOffset(); |
| 70 | 95 |
| 71 void SetCpuTimeForTesting(const base::Callback<int64(void)>& cpu_time); | 96 void SetCpuTimeForTesting(const base::Callback<int64(void)>& cpu_time); |
| 72 void SetOffsetForTesting(int64 offset, bool cache_it); | 97 void SetOffsetForTesting(int64 offset, bool cache_it); |
| 73 void SetTimerTypeForTesting(TimerType type); | 98 void SetTimerTypeForTesting(TimerType type); |
| 74 | 99 |
| 75 private: | 100 private: |
| 101 void UpdateDisjointContexts(); | |
| 102 void RemoveDisjointContext(DisjointContext* context); | |
| 103 | |
| 76 TimerType timer_type_ = kTimerTypeInvalid; | 104 TimerType timer_type_ = kTimerTypeInvalid; |
| 77 int64 offset_ = 0; // offset cache when timer_type_ == kTimerTypeARB | 105 int64 offset_ = 0; // offset cache when timer_type_ == kTimerTypeARB |
| 78 bool offset_valid_ = false; | 106 bool offset_valid_ = false; |
| 107 bool disjoint_occurred_ = false; | |
| 108 std::vector<DisjointContext*> disjoint_contexts_; | |
|
Daniele Castagna
2015/02/19 18:15:32
How many disjoint contexts do you think there are
David Yen
2015/02/19 19:00:47
Most likely only a few, but going from 2 to n does
| |
| 79 base::Callback<int64(void)> cpu_time_for_testing_; | 109 base::Callback<int64(void)> cpu_time_for_testing_; |
| 80 friend class GPUTimer; | 110 friend class GPUTimer; |
| 111 friend class DisjointContext; | |
| 81 DISALLOW_COPY_AND_ASSIGN(GPUTiming); | 112 DISALLOW_COPY_AND_ASSIGN(GPUTiming); |
| 82 }; | 113 }; |
| 83 } // namespace gpu | 114 } // namespace gpu |
| 84 | 115 |
| 85 #endif // GPU_COMMAND_BUFFER_SERVICE_GPU_TIMING_H_ | 116 #endif // GPU_COMMAND_BUFFER_SERVICE_GPU_TIMING_H_ |
| OLD | NEW |