Chromium Code Reviews| Index: src/gpu/GrTracing.h |
| diff --git a/src/gpu/GrTracing.h b/src/gpu/GrTracing.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..de5bfd0414a3a77ce1ec2b530219ab46e2ebc107 |
| --- /dev/null |
| +++ b/src/gpu/GrTracing.h |
| @@ -0,0 +1,100 @@ |
| +/* |
| + * Copyright 2014 Google Inc. |
| + * |
| + * Use of this source code is governed by a BSD-style license that can be |
| + * found in the LICENSE file. |
| + */ |
| + |
| +#ifndef GrTracing_DEFINED |
| +#define GrTracing_DEFINED |
| + |
| +#include "SkTraceEvent.h" |
| + |
| +class GrGpuTraceMarker { |
| +public: |
| + GrGpuTraceMarker(const char* marker, int idCounter) : fMarker(marker), fID(idCounter) {} |
| + |
| + bool operator<(const GrGpuTraceMarker& rhs) const { |
| + return this->fMarker < rhs.fMarker || (this->fMarker == rhs.fMarker && this->fID < rhs.fID); |
| + } |
| + |
| + bool operator==(const GrGpuTraceMarker& rhs) const { |
| + return (this->fID == rhs.fID && this->fMarker == rhs.fMarker); |
| + } |
| + |
| + const char* fMarker; |
| + int fID; |
| +}; |
| + |
| +template<typename T> |
| +class SkTDArray; |
| + |
| +class GrTraceMarkerSet { |
| +public: |
| + GrTraceMarkerSet() {} |
| + |
| + GrTraceMarkerSet(const GrTraceMarkerSet& other); |
| + |
| + // Adds marker to the set. |
| + void add(const GrGpuTraceMarker& marker); |
| + // Adds all markers from one set into this set. |
| + void addSet(const GrTraceMarkerSet& markerSet); |
| + |
| + void remove(const GrGpuTraceMarker& marker); |
| + |
| + int count() const; |
| + |
| + // First sorts fMarkerArray and returns a string of the format |
| + // MarkerName1(#,#,...)%MarkerName2(#,#,...):... where MarkerName is the |
| + // marker string used in the TraceMarker and the (#,#,..) is a list of instance |
| + // id's for the the given marker string |
| + SkString toString() const; |
| + |
| + class Iter; |
| + |
| + Iter begin() const; |
| + |
| + Iter end() const; |
| + |
| +private: |
| + mutable SkTDArray<GrGpuTraceMarker> fMarkerArray; |
| +}; |
| + |
| +class GrDrawTarget; |
| + |
| +/** |
| + * Marker generation class used for adding and removing markers around code blocks |
| + */ |
| +class GrGpuTraceMarkerGenerator : public ::SkNoncopyable { |
| +public: |
| + GrGpuTraceMarkerGenerator(const char* marker_str, int* marker_counter, GrDrawTarget* target); |
|
bsalomon
2014/03/20 16:32:53
I think these should be inlinable. Otherwise we ad
|
| + ~GrGpuTraceMarkerGenerator(); |
| + |
| +private: |
| + GrDrawTarget* fTarget; |
| + GrGpuTraceMarker fTraceMarker; |
| +}; |
| + |
| +////////// macros to place around the internal draw calls ////////////////// |
|
bsalomon
2014/03/20 16:32:53
Can we use the /** style comments?
|
| +// GR_CREATE_TRACE_MARKER will place begin and end trace markers for both |
| +// cpu and gpu (if gpu tracing enabled) for the current scope. |
| +// marker is of type const char* and target is of type GrDrawTarget* |
| + |
| +#define GR_CREATE_TRACE_MARKER(marker_str, target) \ |
|
bsalomon
2014/03/20 16:32:53
If we want to do tracing in SkGpuDevice.cpp we'll
|
| + static const char* static_str = marker_str; \ |
| + static int marker_counter = 0; \ |
|
bsalomon
2014/03/20 16:32:53
I think these statics need some mangling to make s
|
| + GR_CREATE_GPU_TRACE_MARKER(static_str, target, marker_counter) \ |
| + TRACE_EVENT1(TRACE_DISABLED_BY_DEFAULT("skia.gpu"), static_str, \ |
| + "id", marker_counter) \ |
| + sk_atomic_inc(&marker_counter); \ |
| + |
| +#define GR_CREATE_GPU_TRACE_MARKER(marker_str, target, marker_counter) \ |
| + GrGpuTraceMarkerGenerator SK_MACRO_APPEND_LINE(TMG)(static_str, \ |
| + &marker_counter, \ |
| + target); \ |
| + |
| +//////////////////////////////////////////////////////////////////////////// |
| + |
| + |
| +#endif |
| + |