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