2020-06-30 17:39:35 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2020 Google LLC
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef SkSLSampleUsage_DEFINED
|
|
|
|
#define SkSLSampleUsage_DEFINED
|
|
|
|
|
2021-04-28 14:44:06 +00:00
|
|
|
#include "include/core/SkTypes.h"
|
|
|
|
|
2020-06-30 17:39:35 +00:00
|
|
|
#include <string>
|
|
|
|
|
|
|
|
namespace SkSL {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Represents all of the ways that a fragment processor is sampled by its parent.
|
|
|
|
*/
|
2021-08-02 16:37:14 +00:00
|
|
|
class SampleUsage {
|
|
|
|
public:
|
2020-06-30 17:39:35 +00:00
|
|
|
enum class Kind {
|
2021-04-28 14:44:06 +00:00
|
|
|
// Child is never sampled
|
2020-06-30 17:39:35 +00:00
|
|
|
kNone,
|
2021-04-28 14:44:06 +00:00
|
|
|
// Child is only sampled at the same coordinates as the parent
|
|
|
|
kPassThrough,
|
|
|
|
// Child is sampled with a matrix whose value is uniform
|
|
|
|
kUniformMatrix,
|
2021-08-02 17:04:04 +00:00
|
|
|
// Child is sampled with sk_FragCoord.xy
|
|
|
|
kFragCoord,
|
2021-04-28 14:44:06 +00:00
|
|
|
// Child is sampled using explicit coordinates
|
|
|
|
kExplicit,
|
2020-06-30 17:39:35 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// Make a SampleUsage that corresponds to no sampling of the child at all
|
|
|
|
SampleUsage() = default;
|
|
|
|
|
2021-08-02 16:37:14 +00:00
|
|
|
SampleUsage(Kind kind, bool hasPerspective) : fKind(kind), fHasPerspective(hasPerspective) {
|
|
|
|
if (kind != Kind::kUniformMatrix) {
|
|
|
|
SkASSERT(!fHasPerspective);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-21 16:03:51 +00:00
|
|
|
// Child is sampled with a matrix whose value is uniform. The name is fixed.
|
|
|
|
static SampleUsage UniformMatrix(bool hasPerspective) {
|
|
|
|
return SampleUsage(Kind::kUniformMatrix, hasPerspective);
|
2020-06-30 17:39:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static SampleUsage Explicit() {
|
2021-05-21 16:03:51 +00:00
|
|
|
return SampleUsage(Kind::kExplicit, false);
|
2020-06-30 17:39:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static SampleUsage PassThrough() {
|
2021-05-21 16:03:51 +00:00
|
|
|
return SampleUsage(Kind::kPassThrough, false);
|
2020-06-30 17:39:35 +00:00
|
|
|
}
|
|
|
|
|
2021-08-02 17:04:04 +00:00
|
|
|
static SampleUsage FragCoord() { return SampleUsage(Kind::kFragCoord, false); }
|
|
|
|
|
2021-08-02 16:37:14 +00:00
|
|
|
bool operator==(const SampleUsage& that) const {
|
|
|
|
return fKind == that.fKind && fHasPerspective == that.fHasPerspective;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool operator!=(const SampleUsage& that) const { return !(*this == that); }
|
|
|
|
|
|
|
|
// Arbitrary name used by all uniform sampling matrices
|
|
|
|
static const char* MatrixUniformName() { return "matrix"; }
|
|
|
|
|
2020-06-30 17:39:35 +00:00
|
|
|
SampleUsage merge(const SampleUsage& other);
|
|
|
|
|
2021-08-02 16:37:14 +00:00
|
|
|
Kind kind() const { return fKind; }
|
|
|
|
|
|
|
|
bool hasPerspective() const { return fHasPerspective; }
|
|
|
|
|
2021-04-28 14:44:06 +00:00
|
|
|
bool isSampled() const { return fKind != Kind::kNone; }
|
|
|
|
bool isPassThrough() const { return fKind == Kind::kPassThrough; }
|
|
|
|
bool isExplicit() const { return fKind == Kind::kExplicit; }
|
|
|
|
bool isUniformMatrix() const { return fKind == Kind::kUniformMatrix; }
|
2021-08-02 17:04:04 +00:00
|
|
|
bool isFragCoord() const { return fKind == Kind::kFragCoord; }
|
2020-06-30 17:39:35 +00:00
|
|
|
|
2021-08-02 16:37:14 +00:00
|
|
|
std::string constructor() const;
|
|
|
|
|
|
|
|
private:
|
2020-06-30 17:39:35 +00:00
|
|
|
Kind fKind = Kind::kNone;
|
2021-05-21 16:03:51 +00:00
|
|
|
bool fHasPerspective = false; // Only valid if fKind is kUniformMatrix
|
2020-06-30 17:39:35 +00:00
|
|
|
};
|
|
|
|
|
2020-08-06 18:11:56 +00:00
|
|
|
} // namespace SkSL
|
2020-06-30 17:39:35 +00:00
|
|
|
|
|
|
|
#endif
|