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