OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef GPU_COMMAND_BUFFER_SERVICE_GPU_TIMING_H_ | |
6 #define GPU_COMMAND_BUFFER_SERVICE_GPU_TIMING_H_ | |
7 | |
8 #include "base/callback.h" | |
9 #include "base/memory/scoped_ptr.h" | |
10 #include "gpu/gpu_export.h" | |
11 | |
12 namespace gfx { | |
13 class GLContext; | |
14 } | |
15 | |
16 namespace gpu { | |
17 class GPUTiming; | |
18 | |
19 // Class to compute the amount of time it takes to fully | |
20 // complete a set of GL commands | |
21 class GPU_EXPORT GPUTimer { | |
22 public: | |
23 // gpu_timing must outlive GPUTimer instance we're creating. | |
24 explicit GPUTimer(GPUTiming* gpu_timing); | |
25 ~GPUTimer(); | |
26 | |
27 void Start(); | |
28 void End(); | |
29 bool IsAvailable(); | |
30 | |
31 void GetStartEndTimestamps(int64* start, int64* end); | |
32 int64 GetDeltaElapsed(); | |
33 | |
34 private: | |
35 unsigned int queries_[2]; | |
36 int64 offset_ = 0; | |
37 bool end_requested_ = false; | |
38 GPUTiming* gpu_timing_; | |
39 | |
40 DISALLOW_COPY_AND_ASSIGN(GPUTimer); | |
41 }; | |
42 | |
43 // GPUTiming contains all the gl timing logic that is not specific | |
44 // to a single GPUTimer. | |
45 class GPU_EXPORT GPUTiming { | |
46 public: | |
47 enum TimerType { | |
48 kTimerTypeInvalid = -1, | |
49 | |
50 kTimerTypeARB, // ARB_timer_query | |
51 kTimerTypeDisjoint // EXT_disjoint_timer_query | |
52 }; | |
53 | |
54 GPUTiming(); | |
55 virtual ~GPUTiming(); | |
56 | |
57 bool Initialize(gfx::GLContext* context); | |
58 bool IsAvailable(); | |
59 | |
60 // CheckAndResetTimerErrors has to be called before reading timestamps | |
61 // from GPUTimers instances and after making sure all the timers | |
62 // were available. | |
63 // If the returned value is false, all the previous timers should be | |
64 // discarded. | |
65 bool CheckAndResetTimerErrors(); | |
66 | |
67 const char* GetTimerTypeName() const; | |
68 | |
69 // Returns the offset between the current gpu time and the cpu time. | |
70 int64 CalculateTimerOffset(); | |
71 void InvalidateTimerOffset(); | |
72 | |
73 void SetCpuTimeForTesting(const base::Callback<int64(void)>& cpu_time); | |
74 void SetOffsetForTesting(int64 offset, bool cache_it); | |
75 void SetTimerTypeForTesting(TimerType type); | |
76 | |
77 private: | |
78 TimerType timer_type_ = kTimerTypeInvalid; | |
79 int64 offset_ = 0; // offset cache when timer_type_ == kTimerTypeARB | |
80 bool offset_valid_ = false; | |
81 base::Callback<int64(void)> cpu_time_for_testing_; | |
82 friend class GPUTimer; | |
83 DISALLOW_COPY_AND_ASSIGN(GPUTiming); | |
84 }; | |
85 } // namespace gpu | |
86 | |
87 #endif // GPU_COMMAND_BUFFER_SERVICE_GPU_TIMING_H_ | |
OLD | NEW |