Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2717)

Unified Diff: ui/gl/gpu_timing.h

Issue 937263006: Refactored GLContext to own GPUTiming which spawn GPUTimingClients. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: ui/gl/gpu_timing.h
diff --git a/gpu/command_buffer/service/gpu_timing.h b/ui/gl/gpu_timing.h
similarity index 67%
rename from gpu/command_buffer/service/gpu_timing.h
rename to ui/gl/gpu_timing.h
index 726ac4e5f776a19a466276edd017a4a48cfc0446..4e87c9c9508c6a6d6f3774fda38d155492e5701b 100644
--- a/gpu/command_buffer/service/gpu_timing.h
+++ b/ui/gl/gpu_timing.h
@@ -7,21 +7,44 @@
#include "base/callback.h"
#include "base/memory/scoped_ptr.h"
-#include "gpu/gpu_export.h"
namespace gfx {
class GLContext;
}
namespace gpu {
-class GPUTiming;
+
+class GPUTimingClient;
+
+class GL_EXPORT GPUTiming {
+ public:
+ enum TimerType {
+ kTimerTypeInvalid = -1,
+
+ kTimerTypeARB, // ARB_timer_query
+ kTimerTypeDisjoint // EXT_disjoint_timer_query
+ };
+
+ explicit GPUTiming(gfx::GLContext* context = nullptr);
+ virtual ~GPUTiming();
+
+ void Initialize(gfx::GLContext* context);
+
+ TimerType GetTimerType() const { return timer_type_; }
+
+ scoped_refptr<GPUTimingClient> CreateGPUTimingClient();
+
+ private:
+ TimerType timer_type_ = kTimerTypeInvalid;
+ DISALLOW_COPY_AND_ASSIGN(GPUTiming);
+};
// Class to compute the amount of time it takes to fully
// complete a set of GL commands
-class GPU_EXPORT GPUTimer {
+class GL_EXPORT GPUTimer {
public:
- // gpu_timing must outlive GPUTimer instance we're creating.
- explicit GPUTimer(GPUTiming* gpu_timing);
+ // gpu_timing_client must outlive GPUTimer instance we're creating.
+ explicit GPUTimer(GPUTimingClient* gpu_timing_client);
~GPUTimer();
void Start();
@@ -35,27 +58,20 @@ class GPU_EXPORT GPUTimer {
unsigned int queries_[2];
int64 offset_ = 0;
bool end_requested_ = false;
- GPUTiming* gpu_timing_;
+ GPUTimingClient* gpu_timing_client_;
DISALLOW_COPY_AND_ASSIGN(GPUTimer);
};
-// GPUTiming contains all the gl timing logic that is not specific
+// GPUTimingClient contains all the gl timing logic that is not specific
// to a single GPUTimer.
-class GPU_EXPORT GPUTiming {
+class GL_EXPORT GPUTimingClient
+ : public base::RefCounted<GPUTimingClient> {
public:
- enum TimerType {
- kTimerTypeInvalid = -1,
-
- kTimerTypeARB, // ARB_timer_query
- kTimerTypeDisjoint // EXT_disjoint_timer_query
- };
+ explicit GPUTimingClient(GPUTiming* gpu_timing = nullptr);
- GPUTiming();
- virtual ~GPUTiming();
-
- bool Initialize(gfx::GLContext* context);
bool IsAvailable();
+ const char* GetTimerTypeName() const;
// CheckAndResetTimerErrors has to be called before reading timestamps
// from GPUTimers instances and after making sure all the timers
@@ -64,24 +80,27 @@ class GPU_EXPORT GPUTiming {
// discarded.
bool CheckAndResetTimerErrors();
- const char* GetTimerTypeName() const;
-
// Returns the offset between the current gpu time and the cpu time.
int64 CalculateTimerOffset();
void InvalidateTimerOffset();
void SetCpuTimeForTesting(const base::Callback<int64(void)>& cpu_time);
- void SetOffsetForTesting(int64 offset, bool cache_it);
- void SetTimerTypeForTesting(TimerType type);
- private:
- TimerType timer_type_ = kTimerTypeInvalid;
+ protected:
+ virtual ~GPUTimingClient();
+
+ GPUTiming* gpu_timing_;
+ GPUTiming::TimerType timer_type_ = GPUTiming::kTimerTypeInvalid;
int64 offset_ = 0; // offset cache when timer_type_ == kTimerTypeARB
bool offset_valid_ = false;
base::Callback<int64(void)> cpu_time_for_testing_;
+
+ friend class base::RefCounted<GPUTimingClient>;
friend class GPUTimer;
- DISALLOW_COPY_AND_ASSIGN(GPUTiming);
+ friend class GPUTiming;
+ DISALLOW_COPY_AND_ASSIGN(GPUTimingClient);
};
+
} // namespace gpu
#endif // GPU_COMMAND_BUFFER_SERVICE_GPU_TIMING_H_

Powered by Google App Engine
This is Rietveld 408576698