• 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 "GrTraceMarker.h"
9 #include "GrTracing.h"
10 #include "SkString.h"
11 #include "SkTSort.h"
12 
13 ////////////////////////////////////////////////////////////////////////////////
14 
15 ////////////////////////////////////////////////////////////////////////////////
16 
GrTraceMarkerSet(const GrTraceMarkerSet & other)17 GrTraceMarkerSet::GrTraceMarkerSet(const GrTraceMarkerSet& other) {
18    this->addSet(other);
19 }
20 
add(const GrGpuTraceMarker & marker)21 void GrTraceMarkerSet::add(const GrGpuTraceMarker& marker) {
22     this->fMarkerArray.push(marker);
23 }
24 
addSet(const GrTraceMarkerSet & markerSet)25 void GrTraceMarkerSet::addSet(const GrTraceMarkerSet& markerSet) {
26     for (Iter iter = markerSet.begin(); iter != markerSet.end(); ++iter) {
27         this->add(*iter);
28     }
29 }
30 
remove(const GrGpuTraceMarker & marker)31 void GrTraceMarkerSet::remove(const GrGpuTraceMarker& marker) {
32     SkASSERT(-1 != fMarkerArray.find(marker));
33     int index = this->fMarkerArray.find(marker);
34     this->fMarkerArray.remove(index);
35 }
36 
count() const37 int GrTraceMarkerSet::count() const {
38     return this->fMarkerArray.count();
39 }
40 
toStringLast() const41 SkString GrTraceMarkerSet::toStringLast() const {
42     const int numMarkers = this->fMarkerArray.count();
43     SkString marker_string;
44     if (numMarkers > 0) {
45         GrGpuTraceMarker& lastMarker = this->fMarkerArray[numMarkers - 1];
46         marker_string.append(lastMarker.fMarker);
47         if (lastMarker.fID != -1) {
48             marker_string.append("(");
49             marker_string.appendS32(lastMarker.fID);
50             marker_string.append(")");
51         }
52     }
53     return marker_string;
54 }
55 
toString() const56 SkString GrTraceMarkerSet::toString() const {
57     SkTQSort<GrGpuTraceMarker>(this->fMarkerArray.begin(), this->fMarkerArray.end() - 1);
58     SkString marker_string;
59     const char* prevMarkerName = "";
60     int prevMarkerID = -1;
61     int counter = 0;
62     const int numMarkers = this->fMarkerArray.count();
63 
64     // check used for GrGLGpu device after we've already collapsed all markers
65     if (1 == numMarkers && -1 == this->fMarkerArray[0].fID) {
66         marker_string.append(this->fMarkerArray[0].fMarker);
67         return marker_string;
68     }
69 
70     for (int i = 0; i < numMarkers; ++i ) {
71         GrGpuTraceMarker& currMarker = this->fMarkerArray[i];
72         const char* currCmd = currMarker.fMarker;
73         if (currCmd != prevMarkerName) {
74             if (prevMarkerID != -1) {
75                 marker_string.append(") ");
76             }
77             marker_string.append(currCmd);
78             if (currMarker.fID != -1) {
79                 marker_string.append("(");
80                 marker_string.appendS32(currMarker.fID);
81             }
82             prevMarkerName = currCmd;
83         } else if (currMarker.fID != prevMarkerID) {
84             marker_string.append(", ");
85             marker_string.appendS32(currMarker.fID);
86         }
87         prevMarkerID = currMarker.fID;
88         ++counter;
89     }
90     if (counter > 0 && prevMarkerID != -1) {
91         marker_string.append(")");
92     }
93     return marker_string;
94 }
95 
begin() const96 GrTraceMarkerSet::Iter GrTraceMarkerSet::begin() const {
97     return Iter(this, 0);
98 }
99 
end() const100 GrTraceMarkerSet::Iter GrTraceMarkerSet::end() const {
101     return Iter(this, this->fMarkerArray.count());
102 }
103