SkSLSetting.h 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. /*
  2. * Copyright 2016 Google Inc.
  3. *
  4. * Use of this source code is governed by a BSD-style license that can be
  5. * found in the LICENSE file.
  6. */
  7. #ifndef SKSL_SETTING
  8. #define SKSL_SETTING
  9. #include "src/sksl/SkSLContext.h"
  10. #include "src/sksl/ir/SkSLExpression.h"
  11. namespace SkSL {
  12. /**
  13. * Represents a compile-time constant setting, such as sk_Caps.fbFetchSupport. These are generally
  14. * collapsed down to their constant representations during the compilation process.
  15. */
  16. struct Setting : public Expression {
  17. Setting(int offset, String name, std::unique_ptr<Expression> value)
  18. : INHERITED(offset, kSetting_Kind, value->fType)
  19. , fName(std::move(name))
  20. , fValue(std::move(value)) {
  21. SkASSERT(fValue->isConstant());
  22. }
  23. std::unique_ptr<Expression> constantPropagate(const IRGenerator& irGenerator,
  24. const DefinitionMap& definitions) override;
  25. std::unique_ptr<Expression> clone() const override {
  26. return std::unique_ptr<Expression>(new Setting(fOffset, fName, fValue->clone()));
  27. }
  28. String description() const override {
  29. return fName;
  30. }
  31. bool hasSideEffects() const override {
  32. return false;
  33. }
  34. bool isConstant() const override {
  35. return true;
  36. }
  37. const String fName;
  38. std::unique_ptr<Expression> fValue;
  39. typedef Expression INHERITED;
  40. };
  41. } // namespace
  42. #endif