blob: f54ab83b801e7572d522fd90fae43cdbbec06b59 [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 "GrTraceMarker.h"
10#include "GrTracing.h"
11#include "SkString.h"
12#include "SkTSort.h"
13
14////////////////////////////////////////////////////////////////////////////////
15
commit-bot@chromium.org2a05de02014-03-25 15:17:32 +000016////////////////////////////////////////////////////////////////////////////////
17
18GrTraceMarkerSet::GrTraceMarkerSet(const GrTraceMarkerSet& other) {
skia.committer@gmail.comdb35dab2014-03-27 03:02:48 +000019 this->addSet(other);
commit-bot@chromium.org2a05de02014-03-25 15:17:32 +000020}
21
22void GrTraceMarkerSet::add(const GrGpuTraceMarker& marker) {
23 this->fMarkerArray.push(marker);
24}
25
26void GrTraceMarkerSet::addSet(const GrTraceMarkerSet& markerSet) {
27 for (Iter iter = markerSet.begin(); iter != markerSet.end(); ++iter) {
28 this->add(*iter);
29 }
30}
31
32void 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
38int GrTraceMarkerSet::count() const {
39 return this->fMarkerArray.count();
40}
41
egdanield78a1682014-07-09 10:41:26 -070042SkString GrTraceMarkerSet::toStringLast() const {
43 const int numMarkers = this->fMarkerArray.count();
44 SkString marker_string;
45 if (numMarkers > 0) {
46 GrGpuTraceMarker& lastMarker = this->fMarkerArray[numMarkers - 1];
47 marker_string.append(lastMarker.fMarker);
48 if (lastMarker.fID != -1) {
49 marker_string.append("(");
50 marker_string.appendS32(lastMarker.fID);
51 marker_string.append(")");
52 }
53 }
54 return marker_string;
55}
56
commit-bot@chromium.org2a05de02014-03-25 15:17:32 +000057SkString GrTraceMarkerSet::toString() const {
58 SkTQSort<GrGpuTraceMarker>(this->fMarkerArray.begin(), this->fMarkerArray.end() - 1);
59 SkString marker_string;
60 const char* prevMarkerName = "";
61 int prevMarkerID = -1;
62 int counter = 0;
63 const int numMarkers = this->fMarkerArray.count();
64
bsalomon861e1032014-12-16 07:33:49 -080065 // check used for GrGLGpu device after we've already collapsed all markers
commit-bot@chromium.org2a05de02014-03-25 15:17:32 +000066 if (1 == numMarkers && -1 == this->fMarkerArray[0].fID) {
67 marker_string.append(this->fMarkerArray[0].fMarker);
68 return marker_string;
69 }
70
71 for (int i = 0; i < numMarkers; ++i ) {
72 GrGpuTraceMarker& currMarker = this->fMarkerArray[i];
73 const char* currCmd = currMarker.fMarker;
74 if (currCmd != prevMarkerName) {
egdanield78a1682014-07-09 10:41:26 -070075 if (prevMarkerID != -1) {
commit-bot@chromium.org2a05de02014-03-25 15:17:32 +000076 marker_string.append(") ");
77 }
78 marker_string.append(currCmd);
egdanield78a1682014-07-09 10:41:26 -070079 if (currMarker.fID != -1) {
80 marker_string.append("(");
81 marker_string.appendS32(currMarker.fID);
82 }
commit-bot@chromium.org2a05de02014-03-25 15:17:32 +000083 prevMarkerName = currCmd;
84 } else if (currMarker.fID != prevMarkerID) {
85 marker_string.append(", ");
86 marker_string.appendS32(currMarker.fID);
87 }
88 prevMarkerID = currMarker.fID;
89 ++counter;
90 }
egdanield78a1682014-07-09 10:41:26 -070091 if (counter > 0 && prevMarkerID != -1) {
commit-bot@chromium.org2a05de02014-03-25 15:17:32 +000092 marker_string.append(")");
93 }
94 return marker_string;
95}
96
97GrTraceMarkerSet::Iter GrTraceMarkerSet::begin() const {
98 return Iter(this, 0);
99}
100
101GrTraceMarkerSet::Iter GrTraceMarkerSet::end() const {
102 return Iter(this, this->fMarkerArray.count());
103}
egdaniel3eee3832014-06-18 13:09:11 -0700104