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

Side by Side 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: Added GPUTiming descriptions for all 3 classes, refptr in GPUTimer Created 5 years, 9 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 unified diff | Download patch
« no previous file with comments | « ui/gl/gl_context.cc ('k') | ui/gl/gpu_timing.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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 "ui/gl/gl_export.h"
11
12 // The gpu_timing classes handles the abstraction of GL GPU Timing extensions
13 // into a common set of functions. Currently the different timer extensions
14 // that are supported are ARB_timer_query and EXT_disjoint_timer_query.
15 //
16 // Explanation of Classes:
17 // GPUTiming - GPU Timing is a private class which is only owned by the
18 // underlying GLContextReal class. This class handles any GL Context level
19 // states which may need to be redistributed to users of GPUTiming. For
20 // example, there exists only a single disjoint flag for each real GL
21 // Context. Once the disjoint flag is checked, internally it is reset to
22 // false. In order to support multiple virtual contexts each checking the
23 // disjoint flag seperately, GPUTiming is in charge of checking the
24 // disjoint flag and broadcasting out the disjoint state to all the
25 // various users of GPUTiming (GPUTimingClient below).
26 // GPUTimingClient - The GLContextReal holds the GPUTiming class and is the
27 // factory that creates GPUTimingClient objects. If a user would like to
28 // obtain various GPU times they would access CreateGPUTimingClient() from
29 // their GLContext and use the returned object for their timing calls.
30 // Each virtual context as well as any other classes which need GPU times
31 // will hold one of these. When they want to time a GPU trace they will
32 // create GPUTimer objects.
33 // GPUTimer - Once a user decides to trace something, the user creates a new
34 // GPUTimer object from a GPUTimingClient and issue Start() and Stop() calls
35 // around various GL Calls. Once IsAvailable() returns true, the GPU times
36 // will be available through the various time stamp related functions.
37 // The constructor and destructor of this object handles the actual
38 // creation and deletion of the GL Queries within GL.
39
40 namespace gfx {
41
42 class GLContextReal;
43 class GPUTimingClient;
44
45 class GPUTiming {
46 public:
47 enum TimerType {
48 kTimerTypeInvalid = -1,
49
50 kTimerTypeARB, // ARB_timer_query
51 kTimerTypeDisjoint // EXT_disjoint_timer_query
52 };
53
54 TimerType GetTimerType() const { return timer_type_; }
55
56 private:
57 friend struct base::DefaultDeleter<GPUTiming>;
58 friend class GLContextReal;
59 explicit GPUTiming(GLContextReal* context);
60 ~GPUTiming();
61
62 scoped_refptr<GPUTimingClient> CreateGPUTimingClient();
63
64 TimerType timer_type_ = kTimerTypeInvalid;
65 DISALLOW_COPY_AND_ASSIGN(GPUTiming);
66 };
67
68 // Class to compute the amount of time it takes to fully
69 // complete a set of GL commands
70 class GL_EXPORT GPUTimer {
71 public:
72 ~GPUTimer();
73
74 void Start();
75 void End();
76 bool IsAvailable();
77
78 void GetStartEndTimestamps(int64* start, int64* end);
79 int64 GetDeltaElapsed();
80
81 private:
82 friend class GPUTimingClient;
83
84 explicit GPUTimer(scoped_refptr<GPUTimingClient> gpu_timing_client);
85
86 unsigned int queries_[2];
87 int64 offset_ = 0;
88 bool end_requested_ = false;
89 scoped_refptr<GPUTimingClient> gpu_timing_client_;
90
91 DISALLOW_COPY_AND_ASSIGN(GPUTimer);
92 };
93
94 // GPUTimingClient contains all the gl timing logic that is not specific
95 // to a single GPUTimer.
96 class GL_EXPORT GPUTimingClient
97 : public base::RefCounted<GPUTimingClient> {
98 public:
99 explicit GPUTimingClient(GPUTiming* gpu_timing = nullptr);
100
101 scoped_ptr<GPUTimer> CreateGPUTimer();
102 bool IsAvailable();
103 const char* GetTimerTypeName() const;
104
105 // CheckAndResetTimerErrors has to be called before reading timestamps
106 // from GPUTimers instances and after making sure all the timers
107 // were available.
108 // If the returned value is false, all the previous timers should be
109 // discarded.
110 bool CheckAndResetTimerErrors();
111
112 // Returns the offset between the current gpu time and the cpu time.
113 int64 CalculateTimerOffset();
114 void InvalidateTimerOffset();
115
116 void SetCpuTimeForTesting(const base::Callback<int64(void)>& cpu_time);
117
118 private:
119 friend class base::RefCounted<GPUTimingClient>;
120 friend class GPUTimer;
121 friend class GPUTiming;
122
123 virtual ~GPUTimingClient();
124
125 GPUTiming* gpu_timing_;
126 GPUTiming::TimerType timer_type_ = GPUTiming::kTimerTypeInvalid;
127 int64 offset_ = 0; // offset cache when timer_type_ == kTimerTypeARB
128 bool offset_valid_ = false;
129 base::Callback<int64(void)> cpu_time_for_testing_;
130
131 DISALLOW_COPY_AND_ASSIGN(GPUTimingClient);
132 };
133
134 } // namespace gfx
135
136 #endif // GPU_COMMAND_BUFFER_SERVICE_GPU_TIMING_H_
OLDNEW
« no previous file with comments | « ui/gl/gl_context.cc ('k') | ui/gl/gpu_timing.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698