Coverage Report

Created: 2021-08-22 09:07

/src/skia/include/private/SkSLSampleUsage.h
Line
Count
Source (jump to first uncovered line)
1
/*
2
 * Copyright 2020 Google LLC
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 SkSLSampleUsage_DEFINED
9
#define SkSLSampleUsage_DEFINED
10
11
#include "include/core/SkTypes.h"
12
13
#include <string>
14
15
namespace SkSL {
16
17
/**
18
 * Represents all of the ways that a fragment processor is sampled by its parent.
19
 */
20
class SampleUsage {
21
public:
22
    enum class Kind {
23
        // Child is never sampled
24
        kNone,
25
        // Child is only sampled at the same coordinates as the parent
26
        kPassThrough,
27
        // Child is sampled with a matrix whose value is uniform
28
        kUniformMatrix,
29
        // Child is sampled with sk_FragCoord.xy
30
        kFragCoord,
31
        // Child is sampled using explicit coordinates
32
        kExplicit,
33
    };
34
35
    // Make a SampleUsage that corresponds to no sampling of the child at all
36
630k
    SampleUsage() = default;
37
38
505k
    SampleUsage(Kind kind, bool hasPerspective) : fKind(kind), fHasPerspective(hasPerspective) {
39
505k
        if (kind != Kind::kUniformMatrix) {
40
266k
            SkASSERT(!fHasPerspective);
41
266k
        }
42
505k
    }
43
44
    // Child is sampled with a matrix whose value is uniform. The name is fixed.
45
239k
    static SampleUsage UniformMatrix(bool hasPerspective) {
46
239k
        return SampleUsage(Kind::kUniformMatrix, hasPerspective);
47
239k
    }
48
49
83.3k
    static SampleUsage Explicit() {
50
83.3k
        return SampleUsage(Kind::kExplicit, false);
51
83.3k
    }
52
53
175k
    static SampleUsage PassThrough() {
54
175k
        return SampleUsage(Kind::kPassThrough, false);
55
175k
    }
56
57
7.60k
    static SampleUsage FragCoord() { return SampleUsage(Kind::kFragCoord, false); }
58
59
292k
    bool operator==(const SampleUsage& that) const {
60
292k
        return fKind == that.fKind && fHasPerspective == that.fHasPerspective;
61
292k
    }
62
63
292k
    bool operator!=(const SampleUsage& that) const { return !(*this == that); }
64
65
    // Arbitrary name used by all uniform sampling matrices
66
0
    static const char* MatrixUniformName() { return "matrix"; }
67
68
    SampleUsage merge(const SampleUsage& other);
69
70
0
    Kind kind() const { return fKind; }
71
72
0
    bool hasPerspective() const { return fHasPerspective; }
73
74
0
    bool isSampled()       const { return fKind != Kind::kNone; }
75
481k
    bool isPassThrough()   const { return fKind == Kind::kPassThrough; }
76
0
    bool isExplicit()      const { return fKind == Kind::kExplicit; }
77
342k
    bool isUniformMatrix() const { return fKind == Kind::kUniformMatrix; }
78
0
    bool isFragCoord()     const { return fKind == Kind::kFragCoord; }
79
80
    std::string constructor() const;
81
82
private:
83
    Kind fKind = Kind::kNone;
84
    bool fHasPerspective = false;  // Only valid if fKind is kUniformMatrix
85
};
86
87
}  // namespace SkSL
88
89
#endif