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