Sort SkSL gencode enums by value, not name.

Change-Id: Iff707ae968b84609acde89ba94dec7a5d53c7525
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/328576
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 2020-10-20 10:33:56 -04:00 committed by Skia Commit-Bot
parent 3ed7cb5a8b
commit 727f0cd54a
2 changed files with 8 additions and 6 deletions

View File

@ -22,7 +22,7 @@
class GrTwoPointConicalGradientLayout : public GrFragmentProcessor { class GrTwoPointConicalGradientLayout : public GrFragmentProcessor {
public: public:
enum class Type { kFocal = 2, kRadial = 0, kStrip = 1 }; enum class Type { kRadial = 0, kStrip = 1, kFocal = 2 };
static std::unique_ptr<GrFragmentProcessor> Make(const SkTwoPointConicalGradient& gradient, static std::unique_ptr<GrFragmentProcessor> Make(const SkTwoPointConicalGradient& gradient,
const GrFPArgs& args); const GrFPArgs& args);

View File

@ -54,11 +54,9 @@ public:
sortedSymbols.push_back(symbol); sortedSymbols.push_back(symbol);
}); });
std::sort(sortedSymbols.begin(), sortedSymbols.end(), std::sort(sortedSymbols.begin(), sortedSymbols.end(),
[](const Symbol* a, const Symbol* b) { return a->name() < b->name(); }); [](const Symbol* a, const Symbol* b) { return EnumValue(a) < EnumValue(b); });
for (const auto& s : sortedSymbols) { for (const Symbol* s : sortedSymbols) {
const Expression& initialValue = *s->as<Variable>().initialValue(); result += separator + " " + s->name() + " = " + to_string(EnumValue(s));
result += separator + " " + s->name() + " = " +
to_string(initialValue.as<IntLiteral>().value());
separator = ",\n"; separator = ",\n";
} }
result += "\n};"; result += "\n};";
@ -70,6 +68,10 @@ public:
} }
private: private:
static int EnumValue(const Symbol* symbol) {
return symbol->as<Variable>().initialValue()->as<IntLiteral>().value();
}
using INHERITED = ProgramElement; using INHERITED = ProgramElement;
}; };