Add getConstantBool as a sibling of getConstant(Int|Float).
This will be used in a followup CL to implement getBVecComponent. At present it's not called. Change-Id: Idd6f18314d0835af3946ea7458e6650384f505ea Bug: skia:11141 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/350703 Reviewed-by: Brian Osman <brianosman@google.com> Commit-Queue: John Stiles <johnstiles@google.com>
This commit is contained in:
parent
be0b3b7363
commit
f710147302
@ -57,6 +57,10 @@ public:
|
||||
: ComparisonResult::kNotEqual;
|
||||
}
|
||||
|
||||
bool getConstantBool() const override {
|
||||
return this->value();
|
||||
}
|
||||
|
||||
std::unique_ptr<Expression> clone() const override {
|
||||
return std::make_unique<BoolLiteral>(fOffset, this->value(), &this->type());
|
||||
}
|
||||
|
@ -238,10 +238,12 @@ SKSL_INT Constructor::getConstantInt() const {
|
||||
SkASSERT(this->type().columns() == 1);
|
||||
SkASSERT(this->type().isInteger());
|
||||
|
||||
// The inner argument might actually be a float! `int(1.0)` is a valid cast.
|
||||
// This might be a cast, meaning the inner argument would actually be a different scalar type.
|
||||
const Expression& expr = *this->arguments().front();
|
||||
SkASSERT(expr.type().isScalar());
|
||||
return expr.type().isInteger() ? expr.getConstantInt() : (SKSL_INT)expr.getConstantFloat();
|
||||
SkASSERT(expr.type().isInteger() || expr.type().isFloat() || expr.type().isBoolean());
|
||||
return expr.type().isInteger() ? expr.getConstantInt() :
|
||||
expr.type().isFloat() ? (SKSL_INT)expr.getConstantFloat() :
|
||||
(SKSL_INT)expr.getConstantBool();
|
||||
}
|
||||
|
||||
SKSL_FLOAT Constructor::getConstantFloat() const {
|
||||
@ -250,10 +252,26 @@ SKSL_FLOAT Constructor::getConstantFloat() const {
|
||||
SkASSERT(this->type().columns() == 1);
|
||||
SkASSERT(this->type().isFloat());
|
||||
|
||||
// The inner argument might actually be an integer! `float(1)` is a valid cast.
|
||||
// This might be a cast, meaning the inner argument would actually be a different scalar type.
|
||||
const Expression& expr = *this->arguments().front();
|
||||
SkASSERT(expr.type().isScalar());
|
||||
return expr.type().isFloat() ? expr.getConstantFloat() : (SKSL_FLOAT)expr.getConstantInt();
|
||||
SkASSERT(expr.type().isInteger() || expr.type().isFloat() || expr.type().isBoolean());
|
||||
return expr.type().isFloat() ? expr.getConstantFloat() :
|
||||
expr.type().isInteger() ? (SKSL_FLOAT)expr.getConstantInt() :
|
||||
(SKSL_FLOAT)expr.getConstantBool();
|
||||
}
|
||||
|
||||
bool Constructor::getConstantBool() const {
|
||||
// We're looking for scalar Boolean constructors only, i.e. `bool(true)`.
|
||||
SkASSERT(this->arguments().size() == 1);
|
||||
SkASSERT(this->type().columns() == 1);
|
||||
SkASSERT(this->type().isBoolean());
|
||||
|
||||
// This might be a cast, meaning the inner argument would actually be a different scalar type.
|
||||
const Expression& expr = *this->arguments().front();
|
||||
SkASSERT(expr.type().isInteger() || expr.type().isFloat() || expr.type().isBoolean());
|
||||
return expr.type().isBoolean() ? expr.getConstantBool() :
|
||||
expr.type().isInteger() ? (bool)expr.getConstantInt() :
|
||||
(bool)expr.getConstantFloat();
|
||||
}
|
||||
|
||||
} // namespace SkSL
|
||||
|
@ -132,6 +132,8 @@ public:
|
||||
|
||||
SKSL_FLOAT getConstantFloat() const override;
|
||||
|
||||
bool getConstantBool() const override;
|
||||
|
||||
private:
|
||||
ExpressionArray fArguments;
|
||||
|
||||
|
@ -134,6 +134,14 @@ public:
|
||||
ABORT("not a constant float");
|
||||
}
|
||||
|
||||
/**
|
||||
* For an expression which evaluates to a constant Boolean, returns the value. Otherwise calls
|
||||
* ABORT.
|
||||
*/
|
||||
virtual bool getConstantBool() const {
|
||||
ABORT("not a constant Boolean");
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if, given fixed values for uniforms, this expression always evaluates to the
|
||||
* same result with no side effects.
|
||||
|
@ -95,6 +95,12 @@ public:
|
||||
return -this->operand()->getConstantFloat();
|
||||
}
|
||||
|
||||
bool getConstantBool() const override {
|
||||
SkDEBUGFAIL("negation of boolean values is not allowed");
|
||||
SkASSERT(this->isNegationOfCompileTimeConstant());
|
||||
return this->operand()->getConstantBool();
|
||||
}
|
||||
|
||||
ComparisonResult compareConstant(const Context& context,
|
||||
const Expression& other) const override {
|
||||
if (!other.is<PrefixExpression>()) {
|
||||
|
Loading…
Reference in New Issue
Block a user