Use virtual method for slotCount.

Using a switch is overkill now that Types are implemented in subclasses.

Change-Id: If7874dfa9a5b02f168ac7c6c3f69a2bd6f9c2a80
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/463156
Commit-Queue: John Stiles <johnstiles@google.com>
Commit-Queue: Brian Osman <brianosman@google.com>
Auto-Submit: John Stiles <johnstiles@google.com>
Reviewed-by: Brian Osman <brianosman@google.com>
This commit is contained in:
John Stiles 2021-10-25 14:07:10 -04:00 committed by SkCQ
parent 52aee23ded
commit 2e20e7674c
2 changed files with 31 additions and 35 deletions

View File

@ -63,6 +63,11 @@ public:
return fComponentType.isAllowedInES2();
}
size_t slotCount() const override {
SkASSERT(fCount > 0);
return fCount * fComponentType.slotCount();
}
private:
using INHERITED = Type;
@ -129,6 +134,10 @@ public:
return true;
}
size_t slotCount() const override {
return 1;
}
private:
using INHERITED = Type;
@ -176,6 +185,10 @@ public:
return fNumberKind != NumberKind::kUnsigned;
}
size_t slotCount() const override {
return 1;
}
private:
using INHERITED = Type;
@ -222,6 +235,10 @@ public:
return fColumns == fRows;
}
size_t slotCount() const override {
return fColumns * fRows;
}
private:
using INHERITED = Type;
@ -339,6 +356,14 @@ public:
});
}
size_t slotCount() const override {
size_t slots = 0;
for (const Field& field : fFields) {
slots += field.fType->slotCount();
}
return slots;
}
private:
using INHERITED = Type;
@ -381,6 +406,10 @@ public:
return fComponentType.isAllowedInES2();
}
size_t slotCount() const override {
return fColumns;
}
private:
using INHERITED = Type;

View File

@ -387,41 +387,8 @@ public:
/**
* Returns the number of scalars needed to hold this type.
*/
size_t slotCount() const {
switch (this->typeKind()) {
case Type::TypeKind::kBlender:
case Type::TypeKind::kColorFilter:
case Type::TypeKind::kGeneric:
case Type::TypeKind::kOther:
case Type::TypeKind::kSampler:
case Type::TypeKind::kSeparateSampler:
case Type::TypeKind::kShader:
case Type::TypeKind::kTexture:
case Type::TypeKind::kVoid:
return 0;
case Type::TypeKind::kLiteral:
case Type::TypeKind::kScalar:
return 1;
case Type::TypeKind::kVector:
return this->columns();
case Type::TypeKind::kMatrix:
return this->columns() * this->rows();
case Type::TypeKind::kStruct: {
size_t slots = 0;
for (const Field& field : this->fields()) {
slots += field.fType->slotCount();
}
return slots;
}
case Type::TypeKind::kArray:
SkASSERT(this->columns() > 0);
return this->columns() * this->componentType().slotCount();
}
SkUNREACHABLE;
virtual size_t slotCount() const {
return 0;
}
virtual const std::vector<Field>& fields() const {