commit-bot@chromium.org | 2a05de0 | 2014-03-25 15:17:32 +0000 | [diff] [blame] | 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 | |
commit-bot@chromium.org | 2a05de0 | 2014-03-25 15:17:32 +0000 | [diff] [blame] | 16 | //////////////////////////////////////////////////////////////////////////////// |
| 17 | |
| 18 | GrTraceMarkerSet::GrTraceMarkerSet(const GrTraceMarkerSet& other) { |
skia.committer@gmail.com | db35dab | 2014-03-27 03:02:48 +0000 | [diff] [blame] | 19 | this->addSet(other); |
commit-bot@chromium.org | 2a05de0 | 2014-03-25 15:17:32 +0000 | [diff] [blame] | 20 | } |
| 21 | |
| 22 | void GrTraceMarkerSet::add(const GrGpuTraceMarker& marker) { |
| 23 | this->fMarkerArray.push(marker); |
| 24 | } |
| 25 | |
| 26 | void GrTraceMarkerSet::addSet(const GrTraceMarkerSet& markerSet) { |
| 27 | for (Iter iter = markerSet.begin(); iter != markerSet.end(); ++iter) { |
| 28 | this->add(*iter); |
| 29 | } |
| 30 | } |
| 31 | |
| 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 | |
| 38 | int GrTraceMarkerSet::count() const { |
| 39 | return this->fMarkerArray.count(); |
| 40 | } |
| 41 | |
egdaniel | d78a168 | 2014-07-09 10:41:26 -0700 | [diff] [blame] | 42 | SkString 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.org | 2a05de0 | 2014-03-25 15:17:32 +0000 | [diff] [blame] | 57 | SkString 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 | |
bsalomon | 861e103 | 2014-12-16 07:33:49 -0800 | [diff] [blame] | 65 | // check used for GrGLGpu device after we've already collapsed all markers |
commit-bot@chromium.org | 2a05de0 | 2014-03-25 15:17:32 +0000 | [diff] [blame] | 66 | 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) { |
egdaniel | d78a168 | 2014-07-09 10:41:26 -0700 | [diff] [blame] | 75 | if (prevMarkerID != -1) { |
commit-bot@chromium.org | 2a05de0 | 2014-03-25 15:17:32 +0000 | [diff] [blame] | 76 | marker_string.append(") "); |
| 77 | } |
| 78 | marker_string.append(currCmd); |
egdaniel | d78a168 | 2014-07-09 10:41:26 -0700 | [diff] [blame] | 79 | if (currMarker.fID != -1) { |
| 80 | marker_string.append("("); |
| 81 | marker_string.appendS32(currMarker.fID); |
| 82 | } |
commit-bot@chromium.org | 2a05de0 | 2014-03-25 15:17:32 +0000 | [diff] [blame] | 83 | 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 | } |
egdaniel | d78a168 | 2014-07-09 10:41:26 -0700 | [diff] [blame] | 91 | if (counter > 0 && prevMarkerID != -1) { |
commit-bot@chromium.org | 2a05de0 | 2014-03-25 15:17:32 +0000 | [diff] [blame] | 92 | marker_string.append(")"); |
| 93 | } |
| 94 | return marker_string; |
| 95 | } |
| 96 | |
| 97 | GrTraceMarkerSet::Iter GrTraceMarkerSet::begin() const { |
| 98 | return Iter(this, 0); |
| 99 | } |
| 100 | |
| 101 | GrTraceMarkerSet::Iter GrTraceMarkerSet::end() const { |
| 102 | return Iter(this, this->fMarkerArray.count()); |
| 103 | } |
egdaniel | 3eee383 | 2014-06-18 13:09:11 -0700 | [diff] [blame] | 104 | |