• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2014 Google Inc.
3  *
4  * Use of this source code is governed by a BSD-style license that can be
5  * found in the LICENSE file.
6  */
7 
8 #include "SkTDArray.h"
9 
10 #ifndef GrTraceMarkerSet_DEFINED
11 #define GrTraceMarkerSet_DEFINED
12 
13 class GrGpuTraceMarker {
14 public:
GrGpuTraceMarker(const char * marker,int idCounter)15     GrGpuTraceMarker(const char* marker, int idCounter) : fMarker(marker), fID(idCounter) {}
16 
17     bool operator<(const GrGpuTraceMarker& rhs) const {
18         return this->fMarker < rhs.fMarker || (this->fMarker == rhs.fMarker && this->fID < rhs.fID);
19     }
20 
21     bool operator==(const GrGpuTraceMarker& rhs) const {
22         return (this->fID == rhs.fID && this->fMarker == rhs.fMarker);
23     }
24 
25     const char* fMarker;
26     int fID;
27 };
28 
29 ///////////////////////////////////////////////////////////////////////////////
30 
31 class SkString;
32 
33 class GrTraceMarkerSet {
34 public:
GrTraceMarkerSet()35     GrTraceMarkerSet() {}
36 
37     GrTraceMarkerSet(const GrTraceMarkerSet& other);
38 
39     // Adds marker to the set.
40     void add(const GrGpuTraceMarker& marker);
41     // Adds all markers from one set into this set.
42     void addSet(const GrTraceMarkerSet& markerSet);
43 
44     void remove(const GrGpuTraceMarker& marker);
45 
46     int count() const;
47 
48     /**
49      * First sorts fMarkerArray and returns a string of the format
50      * MarkerName1(#,#,...)%MarkerName2(#,#,...):... where MarkerName is the
51      * marker string used in the TraceMarker and the (#,#,..) is a list of instance
52      * id's for the the given marker string
53      */
54     SkString toString() const;
55 
56     SkString toStringLast() const;
57 
58     class Iter;
59 
60     Iter begin() const;
61 
62     Iter end() const;
63 
64 private:
65     mutable SkTDArray<GrGpuTraceMarker> fMarkerArray;
66 };
67 
68 class GrTraceMarkerSet::Iter {
69 public:
Iter()70     Iter() {}
71     Iter& operator=(const Iter& i) {
72         fCurrentIndex = i.fCurrentIndex;
73         fMarkers = i.fMarkers;
74         return *this;
75     }
76     bool operator==(const Iter& i) const {
77         return fCurrentIndex == i.fCurrentIndex && fMarkers == i.fMarkers;
78     }
79     bool operator!=(const Iter& i) const { return !(*this == i); }
80     const GrGpuTraceMarker& operator*() const { return fMarkers->fMarkerArray[fCurrentIndex]; }
81     Iter& operator++() {
82         SkASSERT(*this != fMarkers->end());
83         ++fCurrentIndex;
84         return *this;
85     }
86 
87 private:
88     friend class GrTraceMarkerSet;
Iter(const GrTraceMarkerSet * markers,int index)89     Iter(const GrTraceMarkerSet* markers, int index)
90             : fMarkers(markers), fCurrentIndex(index) {
91         SkASSERT(markers);
92     }
93 
94     const GrTraceMarkerSet* fMarkers;
95     int fCurrentIndex;
96 };
97 
98 #endif
99