blob: 4ecda2c67ab4df830079601b76a15d739ce074b2 [file] [log] [blame]
commit-bot@chromium.org2a05de02014-03-25 15:17:32 +00001
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
14class GrGpuTraceMarker {
15public:
16 GrGpuTraceMarker() {};
17 GrGpuTraceMarker(const char* marker, int idCounter) : fMarker(marker), fID(idCounter) {}
18
19 bool operator<(const GrGpuTraceMarker& rhs) const {
20 return this->fMarker < rhs.fMarker || (this->fMarker == rhs.fMarker && this->fID < rhs.fID);
21 }
22
23 bool operator==(const GrGpuTraceMarker& rhs) const {
24 return (this->fID == rhs.fID && this->fMarker == rhs.fMarker);
25 }
26
27 const char* fMarker;
28 int fID;
29};
30
31///////////////////////////////////////////////////////////////////////////////
32
33class SkString;
34
35class GrTraceMarkerSet {
36public:
37 GrTraceMarkerSet() {}
38
39 GrTraceMarkerSet(const GrTraceMarkerSet& other);
40
41 // Adds marker to the set.
skia.committer@gmail.comdb35dab2014-03-27 03:02:48 +000042 void add(const GrGpuTraceMarker& marker);
commit-bot@chromium.org2a05de02014-03-25 15:17:32 +000043 // Adds all markers from one set into this set.
44 void addSet(const GrTraceMarkerSet& markerSet);
45
46 void remove(const GrGpuTraceMarker& marker);
47
48 int count() const;
49
50 /**
51 * First sorts fMarkerArray and returns a string of the format
52 * MarkerName1(#,#,...)%MarkerName2(#,#,...):... where MarkerName is the
53 * marker string used in the TraceMarker and the (#,#,..) is a list of instance
54 * id's for the the given marker string
55 */
skia.committer@gmail.comdb35dab2014-03-27 03:02:48 +000056 SkString toString() const;
commit-bot@chromium.org2a05de02014-03-25 15:17:32 +000057
egdanield78a1682014-07-09 10:41:26 -070058 SkString toStringLast() const;
59
commit-bot@chromium.org2a05de02014-03-25 15:17:32 +000060 class Iter;
61
62 Iter begin() const;
63
64 Iter end() const;
65
66private:
67 mutable SkTDArray<GrGpuTraceMarker> fMarkerArray;
68};
69
egdaniel3eee3832014-06-18 13:09:11 -070070class GrTraceMarkerSet::Iter {
71public:
72 Iter() {};
73 Iter& operator=(const Iter& i) {
74 fCurrentIndex = i.fCurrentIndex;
75 fMarkers = i.fMarkers;
76 return *this;
77 }
78 bool operator==(const Iter& i) const {
79 return fCurrentIndex == i.fCurrentIndex && fMarkers == i.fMarkers;
80 }
81 bool operator!=(const Iter& i) const { return !(*this == i); }
82 const GrGpuTraceMarker& operator*() const { return fMarkers->fMarkerArray[fCurrentIndex]; }
83 Iter& operator++() {
84 SkASSERT(*this != fMarkers->end());
85 ++fCurrentIndex;
86 return *this;
87 }
88
89private:
90 friend class GrTraceMarkerSet;
91 Iter(const GrTraceMarkerSet* markers, int index)
92 : fMarkers(markers), fCurrentIndex(index) {
93 SkASSERT(markers);
94 }
95
96 const GrTraceMarkerSet* fMarkers;
97 int fCurrentIndex;
98};
99
commit-bot@chromium.org2a05de02014-03-25 15:17:32 +0000100#endif