1// Copyright 2013 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 CONTENT_COMMON_GPU_DEVTOOLS_GPU_INSTRUMENTATION_H_
6#define CONTENT_COMMON_GPU_DEVTOOLS_GPU_INSTRUMENTATION_H_
7
8#include <vector>
9
10#include "base/basictypes.h"
11#include "base/threading/non_thread_safe.h"
12
13namespace content {
14
15class DevToolsGpuAgent;
16class GpuChannel;
17
18class GpuEventsDispatcher : public base::NonThreadSafe {
19 public:
20  enum EventPhase {
21    kEventStart,
22    kEventFinish
23  };
24
25  GpuEventsDispatcher();
26  ~GpuEventsDispatcher();
27
28  void AddProcessor(DevToolsGpuAgent* processor);
29  void RemoveProcessor(DevToolsGpuAgent* processor);
30
31  static void FireEvent(EventPhase phase, GpuChannel* channel) {
32    if (!IsEnabled())
33      return;
34    DoFireEvent(phase, channel);
35  }
36
37private:
38  static bool IsEnabled() { return enabled_; }
39  static void DoFireEvent(EventPhase, GpuChannel* channel);
40
41  static bool enabled_;
42  std::vector<DevToolsGpuAgent*> processors_;
43};
44
45namespace devtools_gpu_instrumentation {
46
47class ScopedGpuTask {
48 public:
49  explicit ScopedGpuTask(GpuChannel* channel) :
50      channel_(channel) {
51    GpuEventsDispatcher::FireEvent(GpuEventsDispatcher::kEventStart, channel_);
52  }
53  ~ScopedGpuTask() {
54    GpuEventsDispatcher::FireEvent(GpuEventsDispatcher::kEventFinish, channel_);
55  }
56 private:
57  GpuChannel* channel_;
58  DISALLOW_COPY_AND_ASSIGN(ScopedGpuTask);
59};
60
61} // namespace devtools_gpu_instrumentation
62
63} // namespace content
64
65#endif  // CONTENT_COMMON_GPU_DEVTOOLS_GPU_INSTRUMENTATION_H_
66