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.
|
|
|
|
*/
|
|
|
|
struct SampleUsage {
|
|
|
|
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,
|
|
|
|
// 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-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
|
|
|
}
|
|
|
|
|
2021-05-21 16:03:51 +00:00
|
|
|
// Arbitrary name used by all uniform sampling matrices
|
|
|
|
static const char* MatrixUniformName() { return "matrix"; }
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
SampleUsage merge(const SampleUsage& other);
|
|
|
|
|
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; }
|
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
|
|
|
|
|
|
|
|
SampleUsage(Kind kind, bool hasPerspective) : fKind(kind), fHasPerspective(hasPerspective) {
|
|
|
|
if (kind != Kind::kUniformMatrix) {
|
|
|
|
SkASSERT(!fHasPerspective);
|
2021-04-28 14:44:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string constructor() const;
|
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
|