/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 | | namespace SkSL { |
14 | | |
15 | | /** |
16 | | * Represents all of the ways that a fragment processor is sampled by its parent. |
17 | | */ |
18 | | class SampleUsage { |
19 | | public: |
20 | | enum class Kind { |
21 | | // Child is never sampled |
22 | | kNone, |
23 | | // Child is only sampled at the same coordinates as the parent |
24 | | kPassThrough, |
25 | | // Child is sampled with a matrix whose value is uniform |
26 | | kUniformMatrix, |
27 | | // Child is sampled with sk_FragCoord.xy |
28 | | kFragCoord, |
29 | | // Child is sampled using explicit coordinates |
30 | | kExplicit, |
31 | | }; |
32 | | |
33 | | // Make a SampleUsage that corresponds to no sampling of the child at all |
34 | 606k | SampleUsage() = default; |
35 | | |
36 | 428k | SampleUsage(Kind kind, bool hasPerspective) : fKind(kind), fHasPerspective(hasPerspective) { |
37 | 428k | if (kind != Kind::kUniformMatrix) { |
38 | 199k | SkASSERT(!fHasPerspective); |
39 | 199k | } |
40 | 428k | } |
41 | | |
42 | | // Child is sampled with a matrix whose value is uniform. The name is fixed. |
43 | 229k | static SampleUsage UniformMatrix(bool hasPerspective) { |
44 | 229k | return SampleUsage(Kind::kUniformMatrix, hasPerspective); |
45 | 229k | } |
46 | | |
47 | 65.6k | static SampleUsage Explicit() { |
48 | 65.6k | return SampleUsage(Kind::kExplicit, false); |
49 | 65.6k | } |
50 | | |
51 | 133k | static SampleUsage PassThrough() { |
52 | 133k | return SampleUsage(Kind::kPassThrough, false); |
53 | 133k | } |
54 | | |
55 | 1.00k | static SampleUsage FragCoord() { return SampleUsage(Kind::kFragCoord, false); } |
56 | | |
57 | 153k | bool operator==(const SampleUsage& that) const { |
58 | 153k | return fKind == that.fKind && fHasPerspective == that.fHasPerspective; |
59 | 153k | } |
60 | | |
61 | 153k | bool operator!=(const SampleUsage& that) const { return !(*this == that); } |
62 | | |
63 | | // Arbitrary name used by all uniform sampling matrices |
64 | 0 | static const char* MatrixUniformName() { return "matrix"; } |
65 | | |
66 | | SampleUsage merge(const SampleUsage& other); |
67 | | |
68 | 0 | Kind kind() const { return fKind; } |
69 | | |
70 | 0 | bool hasPerspective() const { return fHasPerspective; } |
71 | | |
72 | 77 | bool isSampled() const { return fKind != Kind::kNone; } |
73 | 503k | bool isPassThrough() const { return fKind == Kind::kPassThrough; } |
74 | 0 | bool isExplicit() const { return fKind == Kind::kExplicit; } |
75 | 330k | bool isUniformMatrix() const { return fKind == Kind::kUniformMatrix; } |
76 | 0 | bool isFragCoord() const { return fKind == Kind::kFragCoord; } |
77 | | |
78 | | private: |
79 | | Kind fKind = Kind::kNone; |
80 | | bool fHasPerspective = false; // Only valid if fKind is kUniformMatrix |
81 | | }; |
82 | | |
83 | | } // namespace SkSL |
84 | | |
85 | | #endif |