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 "base/callback.h" | 8 #include "base/callback.h" |
| 9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "gpu/gpu_export.h" | 10 #include "ui/gl/gl_export.h" |
| 11 | 11 |
| 12 namespace gfx { | 12 namespace gfx { |
| 13 class GLContext; | 13 class GLContext; |
| 14 } | 14 } |
| 15 | 15 |
| 16 namespace gpu { | 16 namespace gpu { |
|
piman
2015/02/25 01:00:53
nit: probably should be namespace gfx for consiste
David Yen
2015/02/25 01:47:36
Done.
| |
| 17 class GPUTiming; | 17 |
| 18 class GPUTimingClient; | |
| 19 | |
| 20 class GL_EXPORT GPUTiming { | |
|
piman
2015/02/25 01:00:53
nit: it's not clear what is GPUTiming vs GPUTimer.
David Yen
2015/02/25 01:47:35
Let me discuss this with dcastagna since he was th
Daniele Castagna
2015/02/25 17:42:02
Do we still need to keep this class? Now that the
David Yen
2015/02/25 17:48:53
You are correct that currently it does almost noth
Daniele Castagna
2015/02/25 19:46:24
It could be nice to have a comment explaining what
David Yen
2015/02/25 23:02:31
I can't think of anything better either. I have ad
| |
| 21 public: | |
| 22 enum TimerType { | |
| 23 kTimerTypeInvalid = -1, | |
| 24 | |
| 25 kTimerTypeARB, // ARB_timer_query | |
| 26 kTimerTypeDisjoint // EXT_disjoint_timer_query | |
| 27 }; | |
| 28 | |
| 29 explicit GPUTiming(gfx::GLContext* context = nullptr); | |
| 30 virtual ~GPUTiming(); | |
| 31 | |
| 32 void Initialize(gfx::GLContext* context); | |
| 33 | |
| 34 TimerType GetTimerType() const { return timer_type_; } | |
| 35 | |
| 36 scoped_refptr<GPUTimingClient> CreateGPUTimingClient(); | |
| 37 | |
| 38 private: | |
| 39 TimerType timer_type_ = kTimerTypeInvalid; | |
| 40 DISALLOW_COPY_AND_ASSIGN(GPUTiming); | |
| 41 }; | |
| 18 | 42 |
| 19 // Class to compute the amount of time it takes to fully | 43 // Class to compute the amount of time it takes to fully |
| 20 // complete a set of GL commands | 44 // complete a set of GL commands |
| 21 class GPU_EXPORT GPUTimer { | 45 class GL_EXPORT GPUTimer { |
| 22 public: | 46 public: |
| 23 // gpu_timing must outlive GPUTimer instance we're creating. | |
| 24 explicit GPUTimer(GPUTiming* gpu_timing); | |
| 25 ~GPUTimer(); | 47 ~GPUTimer(); |
| 26 | 48 |
| 27 void Start(); | 49 void Start(); |
| 28 void End(); | 50 void End(); |
| 29 bool IsAvailable(); | 51 bool IsAvailable(); |
| 30 | 52 |
| 31 void GetStartEndTimestamps(int64* start, int64* end); | 53 void GetStartEndTimestamps(int64* start, int64* end); |
| 32 int64 GetDeltaElapsed(); | 54 int64 GetDeltaElapsed(); |
| 33 | 55 |
| 34 private: | 56 private: |
| 57 // gpu_timing_client must outlive GPUTimer instance we're creating. | |
|
piman
2015/02/25 01:00:53
Should you just take a reference then?
David Yen
2015/02/25 01:47:35
Possibly, although in practice I don't think that
Daniele Castagna
2015/02/25 17:42:02
I think a reference would be nicer but according t
David Yen
2015/02/25 17:48:53
I interpreted piman's comment as making this a sco
Daniele Castagna
2015/02/25 19:46:24
GPUTimingClient already extends base::RefCounted,
David Yen
2015/02/25 23:02:31
Done.
| |
| 58 explicit GPUTimer(GPUTimingClient* gpu_timing_client); | |
| 59 | |
| 35 unsigned int queries_[2]; | 60 unsigned int queries_[2]; |
| 36 int64 offset_ = 0; | 61 int64 offset_ = 0; |
| 37 bool end_requested_ = false; | 62 bool end_requested_ = false; |
| 38 GPUTiming* gpu_timing_; | 63 GPUTimingClient* gpu_timing_client_; |
| 39 | 64 |
| 65 friend class GPUTimingClient; | |
|
piman
2015/02/25 01:00:53
nit: friend declaration should be first in the pri
David Yen
2015/02/25 01:47:35
Done.
| |
| 40 DISALLOW_COPY_AND_ASSIGN(GPUTimer); | 66 DISALLOW_COPY_AND_ASSIGN(GPUTimer); |
| 41 }; | 67 }; |
| 42 | 68 |
| 43 // GPUTiming contains all the gl timing logic that is not specific | 69 // GPUTimingClient contains all the gl timing logic that is not specific |
| 44 // to a single GPUTimer. | 70 // to a single GPUTimer. |
| 45 class GPU_EXPORT GPUTiming { | 71 class GL_EXPORT GPUTimingClient |
|
Ken Russell (switch to Gerrit)
2015/02/25 00:55:17
I thought the design was going to be more of this
David Yen
2015/02/25 01:47:35
Almost, as you said GPUTiming should be hidden ins
| |
| 72 : public base::RefCounted<GPUTimingClient> { | |
| 46 public: | 73 public: |
| 47 enum TimerType { | 74 explicit GPUTimingClient(GPUTiming* gpu_timing = nullptr); |
| 48 kTimerTypeInvalid = -1, | |
| 49 | 75 |
| 50 kTimerTypeARB, // ARB_timer_query | 76 scoped_ptr<GPUTimer> CreateGPUTimer(); |
| 51 kTimerTypeDisjoint // EXT_disjoint_timer_query | |
| 52 }; | |
| 53 | |
| 54 GPUTiming(); | |
| 55 virtual ~GPUTiming(); | |
| 56 | |
| 57 bool Initialize(gfx::GLContext* context); | |
| 58 bool IsAvailable(); | 77 bool IsAvailable(); |
| 78 const char* GetTimerTypeName() const; | |
| 59 | 79 |
| 60 // CheckAndResetTimerErrors has to be called before reading timestamps | 80 // CheckAndResetTimerErrors has to be called before reading timestamps |
| 61 // from GPUTimers instances and after making sure all the timers | 81 // from GPUTimers instances and after making sure all the timers |
| 62 // were available. | 82 // were available. |
| 63 // If the returned value is false, all the previous timers should be | 83 // If the returned value is false, all the previous timers should be |
| 64 // discarded. | 84 // discarded. |
| 65 bool CheckAndResetTimerErrors(); | 85 bool CheckAndResetTimerErrors(); |
| 66 | 86 |
| 67 const char* GetTimerTypeName() const; | |
| 68 | |
| 69 // Returns the offset between the current gpu time and the cpu time. | 87 // Returns the offset between the current gpu time and the cpu time. |
| 70 int64 CalculateTimerOffset(); | 88 int64 CalculateTimerOffset(); |
| 71 void InvalidateTimerOffset(); | 89 void InvalidateTimerOffset(); |
| 72 | 90 |
| 73 void SetCpuTimeForTesting(const base::Callback<int64(void)>& cpu_time); | 91 void SetCpuTimeForTesting(const base::Callback<int64(void)>& cpu_time); |
| 74 void SetOffsetForTesting(int64 offset, bool cache_it); | |
| 75 void SetTimerTypeForTesting(TimerType type); | |
| 76 | 92 |
| 77 private: | 93 protected: |
| 78 TimerType timer_type_ = kTimerTypeInvalid; | 94 virtual ~GPUTimingClient(); |
| 95 | |
| 96 GPUTiming* gpu_timing_; | |
| 97 GPUTiming::TimerType timer_type_ = GPUTiming::kTimerTypeInvalid; | |
| 79 int64 offset_ = 0; // offset cache when timer_type_ == kTimerTypeARB | 98 int64 offset_ = 0; // offset cache when timer_type_ == kTimerTypeARB |
| 80 bool offset_valid_ = false; | 99 bool offset_valid_ = false; |
| 81 base::Callback<int64(void)> cpu_time_for_testing_; | 100 base::Callback<int64(void)> cpu_time_for_testing_; |
| 101 | |
| 102 friend class base::RefCounted<GPUTimingClient>; | |
| 82 friend class GPUTimer; | 103 friend class GPUTimer; |
| 83 DISALLOW_COPY_AND_ASSIGN(GPUTiming); | 104 friend class GPUTiming; |
| 105 DISALLOW_COPY_AND_ASSIGN(GPUTimingClient); | |
| 84 }; | 106 }; |
| 107 | |
| 85 } // namespace gpu | 108 } // namespace gpu |
| 86 | 109 |
| 87 #endif // GPU_COMMAND_BUFFER_SERVICE_GPU_TIMING_H_ | 110 #endif // GPU_COMMAND_BUFFER_SERVICE_GPU_TIMING_H_ |
| OLD | NEW |