summaryrefslogtreecommitdiff
path: root/content/common/gpu/devtools_gpu_instrumentation.cc
blob: 0167cf8547af4365c8708a4895dc034edd1c6c30 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
// Copyright 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "content/common/gpu/devtools_gpu_instrumentation.h"

#include "base/logging.h"
#include "base/time/time.h"
#include "content/common/gpu/devtools_gpu_agent.h"
#include "content/common/gpu/gpu_channel.h"
#include "content/common/gpu/gpu_channel_manager.h"

namespace content {

bool GpuEventsDispatcher::enabled_ = false;

GpuEventsDispatcher::GpuEventsDispatcher() {
}

GpuEventsDispatcher::~GpuEventsDispatcher() {
}

void GpuEventsDispatcher::AddProcessor(DevToolsGpuAgent* processor) {
  DCHECK(CalledOnValidThread());
  processors_.push_back(processor);
  enabled_ = !processors_.empty();
}

void GpuEventsDispatcher::RemoveProcessor(DevToolsGpuAgent* processor) {
  DCHECK(CalledOnValidThread());
  processors_.erase(
      std::remove(processors_.begin(), processors_.end(), processor),
      processors_.end());
  enabled_ = !processors_.empty();
}

// static
void GpuEventsDispatcher::DoFireEvent(EventPhase phase,
                                      GpuChannel* channel) {
  TimeTicks timestamp = base::TimeTicks::NowFromSystemTraceTime();
  GpuEventsDispatcher* self =
      channel->gpu_channel_manager()->gpu_devtools_events_dispatcher();
  DCHECK(self->CalledOnValidThread());
  std::vector<DevToolsGpuAgent*>::iterator it;
  for (it = self->processors_.begin(); it != self->processors_.end(); ++it) {
    (*it)->ProcessEvent(timestamp, phase, channel);
  }
}

} // namespace