c799fd5d3a8e3817def0ba70b23dc47e604530bc
[platform/framework/web/crosswalk.git] / src / gpu / command_buffer / service / gpu_tracer.h
1 // Copyright (c) 2012 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 // This file contains the GPUTrace class.
6 #ifndef GPU_COMMAND_BUFFER_SERVICE_GPU_TRACER_H_
7 #define GPU_COMMAND_BUFFER_SERVICE_GPU_TRACER_H_
8
9 #include <string>
10
11 #include "base/basictypes.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "base/memory/weak_ptr.h"
14 #include "base/threading/thread.h"
15 #include "gpu/command_buffer/service/gles2_cmd_decoder.h"
16 #include "gpu/gpu_export.h"
17 #include "ui/gl/gl_bindings.h"
18
19 namespace gpu {
20 namespace gles2 {
21
22 // Id used to keep trace namespaces separate
23 enum GpuTracerSource {
24   kTraceGroupMarker = 0,
25   kTraceCHROMIUM = 1,
26   kTraceDecoder = 2,
27 };
28
29 // Traces GPU Commands.
30 class GPUTracer {
31  public:
32   static scoped_ptr<GPUTracer> Create(gles2::GLES2Decoder* decoder);
33
34   GPUTracer();
35   virtual ~GPUTracer();
36
37   // Scheduled processing in decoder begins.
38   virtual bool BeginDecoding() = 0;
39
40   // Scheduled processing in decoder ends.
41   virtual bool EndDecoding() = 0;
42
43   // Begin a trace marker.
44   virtual bool Begin(const std::string& name, GpuTracerSource source) = 0;
45
46   // End the last started trace marker.
47   virtual bool End(GpuTracerSource source) = 0;
48
49   virtual bool IsTracing() = 0;
50
51   // Retrieve the name of the current open trace.
52   // Returns empty string if no current open trace.
53   virtual const std::string& CurrentName() const = 0;
54
55  private:
56   DISALLOW_COPY_AND_ASSIGN(GPUTracer);
57 };
58
59 class Outputter : public base::RefCounted<Outputter> {
60  public:
61   virtual void Trace(const std::string& name,
62                      int64 start_time,
63                      int64 end_time) = 0;
64
65  protected:
66   virtual ~Outputter() {}
67   friend class base::RefCounted<Outputter>;
68 };
69
70 class TraceOutputter : public Outputter {
71  public:
72   static scoped_refptr<TraceOutputter> Create(const std::string& name);
73   virtual void Trace(const std::string& name,
74                      int64 start_time,
75                      int64 end_time) OVERRIDE;
76
77  protected:
78   friend class base::RefCounted<Outputter>;
79   explicit TraceOutputter(const std::string& name);
80   virtual ~TraceOutputter();
81
82   base::Thread named_thread_;
83   uint64 local_trace_id_;
84
85   DISALLOW_COPY_AND_ASSIGN(TraceOutputter);
86 };
87
88 class GPU_EXPORT GPUTrace
89     : public base::RefCounted<GPUTrace> {
90  public:
91   explicit GPUTrace(const std::string& name);
92   GPUTrace(scoped_refptr<Outputter> outputter,
93            const std::string& name,
94            int64 offset);
95
96   bool IsEnabled() { return enabled_; }
97   const std::string& name() { return name_; }
98
99   void Start();
100   void End();
101   bool IsAvailable();
102   void Process();
103
104  private:
105   ~GPUTrace();
106
107   void Output();
108
109   friend class base::RefCounted<GPUTrace>;
110
111   std::string name_;
112   scoped_refptr<Outputter> outputter_;
113
114   int64 offset_;
115   int64 start_time_;
116   int64 end_time_;
117   bool end_requested_;
118   bool enabled_;
119
120   GLuint queries_[2];
121
122   DISALLOW_COPY_AND_ASSIGN(GPUTrace);
123 };
124
125 }  // namespace gles2
126 }  // namespace gpu
127
128 #endif  // GPU_COMMAND_BUFFER_SERVICE_GPU_TRACER_H_