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