• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include "content/common/gpu/devtools_gpu_instrumentation.h"
6 
7 #include "base/logging.h"
8 #include "base/time/time.h"
9 #include "content/common/gpu/devtools_gpu_agent.h"
10 #include "content/common/gpu/gpu_channel.h"
11 #include "content/common/gpu/gpu_channel_manager.h"
12 
13 namespace content {
14 
15 bool GpuEventsDispatcher::enabled_ = false;
16 
GpuEventsDispatcher()17 GpuEventsDispatcher::GpuEventsDispatcher() {
18 }
19 
~GpuEventsDispatcher()20 GpuEventsDispatcher::~GpuEventsDispatcher() {
21 }
22 
AddProcessor(DevToolsGpuAgent * processor)23 void GpuEventsDispatcher::AddProcessor(DevToolsGpuAgent* processor) {
24   DCHECK(CalledOnValidThread());
25   processors_.push_back(processor);
26   enabled_ = !processors_.empty();
27 }
28 
RemoveProcessor(DevToolsGpuAgent * processor)29 void GpuEventsDispatcher::RemoveProcessor(DevToolsGpuAgent* processor) {
30   DCHECK(CalledOnValidThread());
31   processors_.erase(
32       std::remove(processors_.begin(), processors_.end(), processor),
33       processors_.end());
34   enabled_ = !processors_.empty();
35 }
36 
37 // static
DoFireEvent(EventPhase phase,GpuCommandBufferStub * stub)38 void GpuEventsDispatcher::DoFireEvent(EventPhase phase,
39                                       GpuCommandBufferStub* stub) {
40   TimeTicks timestamp = base::TimeTicks::NowFromSystemTraceTime();
41   GpuEventsDispatcher* self =
42       stub->channel()->gpu_channel_manager()->gpu_devtools_events_dispatcher();
43   DCHECK(self->CalledOnValidThread());
44   std::vector<DevToolsGpuAgent*>::iterator it;
45   for (it = self->processors_.begin(); it != self->processors_.end(); ++it) {
46     (*it)->ProcessEvent(timestamp, phase, stub);
47   }
48 }
49 
50 } // namespace
51