Coverage Report

Created: 2021-08-22 09:07

/src/skia/src/gpu/GrWindowRectangles.h
Line
Count
Source (jump to first uncovered line)
1
/*
2
 * Copyright 2016 Google Inc.
3
 *
4
 * Use of this source code is governed by a BSD-style license that can be
5
 * found in the LICENSE file.
6
 */
7
8
#ifndef GrWindowRectangles_DEFINED
9
#define GrWindowRectangles_DEFINED
10
11
#include "include/core/SkRect.h"
12
#include "src/gpu/GrNonAtomicRef.h"
13
14
class GrWindowRectangles {
15
public:
16
    constexpr static int kMaxWindows = 8;
17
18
237k
    GrWindowRectangles() : fCount(0) {}
19
243k
    GrWindowRectangles(const GrWindowRectangles& that) : fCount(0) { *this = that; }
20
480k
    ~GrWindowRectangles() { SkSafeUnref(this->rec()); }
21
22
    GrWindowRectangles makeOffset(int dx, int dy) const;
23
24
92.9k
    bool empty() const { return !fCount; }
25
2.57k
    int count() const { return fCount; }
26
    const SkIRect* data() const;
27
28
    void reset();
29
    GrWindowRectangles& operator=(const GrWindowRectangles&);
30
31
0
    SkIRect& addWindow(const SkIRect& window) { return this->addWindow() = window; }
32
    SkIRect& addWindow();
33
34
0
    bool operator!=(const GrWindowRectangles& that) const { return !(*this == that); }
35
    bool operator==(const GrWindowRectangles&) const;
36
37
private:
38
    struct Rec;
39
40
723k
    const Rec* rec() const { return fCount <= 1 ? nullptr : fRec; }
41
42
    int fCount;
43
    union {
44
        SkIRect   fLocalWindow; // If fCount <= 1
45
        Rec*      fRec;         // If fCount >  1.
46
    };
47
};
48
49
struct GrWindowRectangles::Rec : public GrNonAtomicRef<Rec> {
50
0
    Rec(const SkIRect* windows, int numWindows) {
51
0
        SkASSERT(numWindows <= kMaxWindows);
52
0
        memcpy(fData, windows, sizeof(SkIRect) * numWindows);
53
0
    }
Unexecuted instantiation: GrWindowRectangles::Rec::Rec(SkIRect const*, int)
Unexecuted instantiation: GrWindowRectangles::Rec::Rec(SkIRect const*, int)
54
    Rec() = default;
55
56
    SkIRect fData[kMaxWindows];
57
};
58
59
0
inline const SkIRect* GrWindowRectangles::data() const {
60
0
    return fCount <= 1 ? &fLocalWindow : fRec->fData;
61
0
}
62
63
0
inline void GrWindowRectangles::reset() {
64
0
    SkSafeUnref(this->rec());
65
0
    fCount = 0;
66
0
}
67
68
243k
inline GrWindowRectangles& GrWindowRectangles::operator=(const GrWindowRectangles& that) {
69
243k
    SkSafeUnref(this->rec());
70
243k
    fCount = that.fCount;
71
243k
    if (fCount <= 1) {
72
243k
        fLocalWindow = that.fLocalWindow;
73
0
    } else {
74
0
        fRec = SkRef(that.fRec);
75
0
    }
76
243k
    return *this;
77
243k
}
78
79
0
inline GrWindowRectangles GrWindowRectangles::makeOffset(int dx, int dy) const {
80
0
    if (!dx && !dy) {
81
0
        return *this;
82
0
    }
83
0
    GrWindowRectangles result;
84
0
    result.fCount = fCount;
85
0
    SkIRect* windows;
86
0
    if (result.fCount > 1) {
87
0
        result.fRec = new Rec();
88
0
        windows = result.fRec->fData;
89
0
    } else {
90
0
        windows = &result.fLocalWindow;
91
0
    }
92
0
    for (int i = 0; i < fCount; ++i) {
93
0
        windows[i] = this->data()[i].makeOffset(dx, dy);
94
0
    }
95
0
    return result;
96
0
}
97
98
0
inline SkIRect& GrWindowRectangles::addWindow() {
99
0
    SkASSERT(fCount < kMaxWindows);
100
0
    if (fCount == 0) {
101
0
        fCount = 1;
102
0
        return fLocalWindow;
103
0
    }
104
0
    if (fCount == 1) {
105
0
        fRec = new Rec(&fLocalWindow, 1);
106
0
    } else if (!fRec->unique()) { // Simple copy-on-write.
107
0
        fRec->unref();
108
0
        fRec = new Rec(fRec->fData, fCount);
109
0
    }
110
0
    return fRec->fData[fCount++];
111
0
}
Unexecuted instantiation: GrWindowRectangles::addWindow()
Unexecuted instantiation: GrWindowRectangles::addWindow()
112
113
86.4k
inline bool GrWindowRectangles::operator==(const GrWindowRectangles& that) const {
114
86.4k
    if (fCount != that.fCount) {
115
0
        return false;
116
0
    }
117
86.4k
    if (fCount > 1 && fRec == that.fRec) {
118
0
        return true;
119
0
    }
120
86.4k
    return !fCount || !memcmp(this->data(), that.data(), sizeof(SkIRect) * fCount);
121
86.4k
}
122
123
#endif