Home | History | Annotate | Download | only in gpu
      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 
     18 GrTraceMarkerSet::GrTraceMarkerSet(const GrTraceMarkerSet& other) {
     19    this->addSet(other);
     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 
     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 
     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 
     65     // check used for GrGLGpu device after we've already collapsed all markers
     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) {
     75             if (prevMarkerID != -1) {
     76                 marker_string.append(") ");
     77             }
     78             marker_string.append(currCmd);
     79             if (currMarker.fID != -1) {
     80                 marker_string.append("(");
     81                 marker_string.appendS32(currMarker.fID);
     82             }
     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     }
     91     if (counter > 0 && prevMarkerID != -1) {
     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 }
    104 
    105