aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/gpu/GrTraceMarker.h
blob: a0e9625a51d55dc3535f62316fb7d16b283226f9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
/*
 * Copyright 2014 Google Inc.
 *
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 */

#include "SkTDArray.h"

#ifndef GrTraceMarkerSet_DEFINED
#define GrTraceMarkerSet_DEFINED

class GrGpuTraceMarker {
public:
    GrGpuTraceMarker(const char* marker, int idCounter) : fMarker(marker), fID(idCounter) {}

    bool operator<(const GrGpuTraceMarker& rhs) const {
        return this->fMarker < rhs.fMarker || (this->fMarker == rhs.fMarker && this->fID < rhs.fID);
    }

    bool operator==(const GrGpuTraceMarker& rhs) const {
        return (this->fID == rhs.fID && this->fMarker == rhs.fMarker);
    }

    const char* fMarker;
    int fID;
};

///////////////////////////////////////////////////////////////////////////////

class SkString;

class GrTraceMarkerSet {
public:
    GrTraceMarkerSet() {}

    GrTraceMarkerSet(const GrTraceMarkerSet& other);

    // Adds marker to the set.
    void add(const GrGpuTraceMarker& marker);
    // Adds all markers from one set into this set.
    void addSet(const GrTraceMarkerSet& markerSet);

    void remove(const GrGpuTraceMarker& marker);

    int count() const;

    /**
     * First sorts fMarkerArray and returns a string of the format
     * MarkerName1(#,#,...)%MarkerName2(#,#,...):... where MarkerName is the
     * marker string used in the TraceMarker and the (#,#,..) is a list of instance
     * id's for the the given marker string
     */
    SkString toString() const;

    SkString toStringLast() const;

    class Iter;

    Iter begin() const;

    Iter end() const;

private:
    mutable SkTDArray<GrGpuTraceMarker> fMarkerArray;
};

class GrTraceMarkerSet::Iter {
public:
    Iter() {};
    Iter& operator=(const Iter& i) {
        fCurrentIndex = i.fCurrentIndex;
        fMarkers = i.fMarkers;
        return *this;
    }
    bool operator==(const Iter& i) const {
        return fCurrentIndex == i.fCurrentIndex && fMarkers == i.fMarkers;
    }
    bool operator!=(const Iter& i) const { return !(*this == i); }
    const GrGpuTraceMarker& operator*() const { return fMarkers->fMarkerArray[fCurrentIndex]; }
    Iter& operator++() {
        SkASSERT(*this != fMarkers->end());
        ++fCurrentIndex;
        return *this;
    }

private:
    friend class GrTraceMarkerSet;
    Iter(const GrTraceMarkerSet* markers, int index)
            : fMarkers(markers), fCurrentIndex(index) {
        SkASSERT(markers);
    }

    const GrTraceMarkerSet* fMarkers;
    int fCurrentIndex;
};

#endif