Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | Static Public Attributes | List of all members
SkSL::ConstructorSplat Class Referencefinal

#include <SkSLConstructorSplat.h>

Inheritance diagram for SkSL::ConstructorSplat:
SkSL::SingleArgumentConstructor SkSL::AnyConstructor SkSL::Expression SkSL::IRNode SkSL::Poolable

Public Member Functions

 ConstructorSplat (Position pos, const Type &type, std::unique_ptr< Expression > arg)
 
std::unique_ptr< Expressionclone (Position pos) const override
 
bool supportsConstantValues () const override
 
std::optional< double > getConstantValue (int n) const override
 
- Public Member Functions inherited from SkSL::SingleArgumentConstructor
 SingleArgumentConstructor (Position pos, Kind kind, const Type *type, std::unique_ptr< Expression > argument)
 
std::unique_ptr< Expression > & argument ()
 
const std::unique_ptr< Expression > & argument () const
 
SkSpan< std::unique_ptr< Expression > > argumentSpan () final
 
SkSpan< const std::unique_ptr< Expression > > argumentSpan () const final
 
- Public Member Functions inherited from SkSL::AnyConstructor
 AnyConstructor (Position pos, Kind kind, const Type *type)
 
std::string description (OperatorPrecedence) const override
 
const TypecomponentType () const
 
ComparisonResult compareConstant (const Expression &other) const override
 
- Public Member Functions inherited from SkSL::Expression
 Expression (Position pos, Kind kind, const Type *type)
 
Kind kind () const
 
virtual const Typetype () const
 
bool isAnyConstructor () const
 
bool isIntLiteral () const
 
bool isFloatLiteral () const
 
bool isBoolLiteral () const
 
AnyConstructorasAnyConstructor ()
 
const AnyConstructorasAnyConstructor () const
 
bool isIncomplete (const Context &context) const
 
CoercionCost coercionCost (const Type &target) const
 
std::unique_ptr< Expressionclone () const
 
std::string description () const final
 
- Public Member Functions inherited from SkSL::IRNode
virtual ~IRNode ()
 
 IRNode (const IRNode &)=delete
 
IRNodeoperator= (const IRNode &)=delete
 
Position position () const
 
void setPosition (Position p)
 
template<typename T >
bool is () const
 
template<typename T >
const Tas () const
 
template<typename T >
Tas ()
 

Static Public Member Functions

static std::unique_ptr< ExpressionMake (const Context &context, Position pos, const Type &type, std::unique_ptr< Expression > arg)
 
- Static Public Member Functions inherited from SkSL::Poolable
static void * operator new (const size_t size)
 
static void operator delete (void *ptr)
 

Static Public Attributes

static constexpr Kind kIRNodeKind = Kind::kConstructorSplat
 

Additional Inherited Members

- Public Types inherited from SkSL::Expression
enum class  ComparisonResult { kUnknown = -1 , kNotEqual , kEqual }
 
using Kind = ExpressionKind
 
- Public Attributes inherited from SkSL::IRNode
Position fPosition
 
- Protected Member Functions inherited from SkSL::IRNode
 IRNode (Position position, int kind)
 
- Protected Attributes inherited from SkSL::IRNode
int fKind
 

Detailed Description

Represents the construction of a vector splat, such as half3(n).

These always contain exactly 1 scalar.

Definition at line 31 of file SkSLConstructorSplat.h.

Constructor & Destructor Documentation

◆ ConstructorSplat()

SkSL::ConstructorSplat::ConstructorSplat ( Position  pos,
const Type type,
std::unique_ptr< Expression arg 
)
inline

Definition at line 35 of file SkSLConstructorSplat.h.

36 : INHERITED(pos, kIRNodeKind, &type, std::move(arg)) {}
SkPoint pos
static constexpr Kind kIRNodeKind
virtual const Type & type() const

Member Function Documentation

◆ clone()

std::unique_ptr< Expression > SkSL::ConstructorSplat::clone ( Position  pos) const
inlineoverridevirtual

Implements SkSL::Expression.

Definition at line 44 of file SkSLConstructorSplat.h.

44 {
45 return std::make_unique<ConstructorSplat>(pos, this->type(), argument()->clone());
46 }
std::unique_ptr< Expression > clone() const
std::unique_ptr< Expression > & argument()

◆ getConstantValue()

std::optional< double > SkSL::ConstructorSplat::getConstantValue ( int  n) const
inlineoverridevirtual

Returns the n'th compile-time constant value within a literal or constructor. Use Type::slotCount to determine the number of slots within an expression. Slots which do not contain compile-time constant values will return nullopt. vec4(1, vec2(2), 3) contains four compile-time constants: (1, 2, 2, 3) mat2(f) contains four slots, and two are constant: (nullopt, 0, 0, nullopt) All classes which override this function must also implement supportsConstantValues.

Reimplemented from SkSL::AnyConstructor.

Definition at line 52 of file SkSLConstructorSplat.h.

52 {
53 SkASSERT(n >= 0 && n < this->type().columns());
54 return this->argument()->getConstantValue(0);
55 }
#define SkASSERT(cond)
Definition SkAssert.h:116

◆ Make()

std::unique_ptr< Expression > SkSL::ConstructorSplat::Make ( const Context context,
Position  pos,
const Type type,
std::unique_ptr< Expression arg 
)
static

Definition at line 14 of file SkSLConstructorSplat.cpp.

17 {
20 SkASSERT(arg->type().scalarTypeForLiteral().matches(
22 SkASSERT(arg->type().isScalar());
23
24 // A "splat" to a scalar type is a no-op and can be eliminated.
25 if (type.isScalar()) {
26 arg->fPosition = pos;
27 return arg;
28 }
29
30 // Replace constant variables with their corresponding values, so `float3(five)` can compile
31 // down to `float3(5.0)` (the latter is a compile-time constant).
33
35 return std::make_unique<ConstructorSplat>(pos, type, std::move(arg));
36}
static std::unique_ptr< Expression > MakeConstantValueForVariable(Position pos, std::unique_ptr< Expression > expr)
virtual bool isVector() const
Definition SkSLType.h:524
bool isAllowedInES2(const Context &context) const
virtual const Type & componentType() const
Definition SkSLType.h:404
virtual bool isScalar() const
Definition SkSLType.h:512
virtual const Type & scalarTypeForLiteral() const
Definition SkSLType.h:520

◆ supportsConstantValues()

bool SkSL::ConstructorSplat::supportsConstantValues ( ) const
inlineoverridevirtual

Returns true if this expression type supports getConstantValue. (This particular expression may or may not actually contain a constant value.) It's harmless to call getConstantValue on expressions which don't support constant values or don't contain any constant values, but if supportsConstantValues returns false, you can assume that getConstantValue will return nullopt for every slot of this expression. This allows for early-out opportunities in some cases. (Some expressions have tons of slots but never hold a constant value; e.g. a variable holding a very large array.)

Reimplemented from SkSL::AnyConstructor.

Definition at line 48 of file SkSLConstructorSplat.h.

48 {
49 return true;
50 }

Member Data Documentation

◆ kIRNodeKind

constexpr Kind SkSL::ConstructorSplat::kIRNodeKind = Kind::kConstructorSplat
inlinestaticconstexpr

Definition at line 33 of file SkSLConstructorSplat.h.


The documentation for this class was generated from the following files: