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 13 namespace content { 14 15 class DevToolsGpuAgent; 16 class GpuCommandBufferStub; 17 18 class 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, GpuCommandBufferStub* stub) { 32 if (!IsEnabled()) 33 return; 34 DoFireEvent(phase, stub); 35 } 36 37 private: 38 static bool IsEnabled() { return enabled_; } 39 static void DoFireEvent(EventPhase, GpuCommandBufferStub* stub); 40 41 static bool enabled_; 42 std::vector<DevToolsGpuAgent*> processors_; 43 }; 44 45 namespace devtools_gpu_instrumentation { 46 47 class ScopedGpuTask { 48 public: 49 explicit ScopedGpuTask(GpuCommandBufferStub* stub) : 50 stub_(stub) { 51 GpuEventsDispatcher::FireEvent(GpuEventsDispatcher::kEventStart, stub_); 52 } 53 ~ScopedGpuTask() { 54 GpuEventsDispatcher::FireEvent(GpuEventsDispatcher::kEventFinish, stub_); 55 } 56 private: 57 GpuCommandBufferStub* stub_; 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