SkSLHCodeGenerator.h 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. /*
  2. * Copyright 2017 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_HCODEGENERATOR
  8. #define SKSL_HCODEGENERATOR
  9. #include "src/sksl/SkSLCodeGenerator.h"
  10. #include "src/sksl/SkSLSectionAndParameterHelper.h"
  11. #include "src/sksl/ir/SkSLType.h"
  12. #include "src/sksl/ir/SkSLVariable.h"
  13. #include <cctype>
  14. constexpr const char* kFragmentProcessorHeader =
  15. R"(
  16. /**************************************************************************************************
  17. *** This file was autogenerated from %s.fp; do not modify.
  18. **************************************************************************************************/
  19. )";
  20. namespace SkSL {
  21. class HCodeGenerator : public CodeGenerator {
  22. public:
  23. HCodeGenerator(const Context* context, const Program* program, ErrorReporter* errors,
  24. String name, OutputStream* out);
  25. bool generateCode() override;
  26. static String ParameterType(const Context& context, const Type& type, const Layout& layout);
  27. static Layout::CType ParameterCType(const Context& context, const Type& type,
  28. const Layout& layout);
  29. static String FieldType(const Context& context, const Type& type, const Layout& layout);
  30. // Either the field type, or a const reference of the field type if the field type is complex.
  31. static String AccessType(const Context& context, const Type& type, const Layout& layout);
  32. static String FieldName(const char* varName) {
  33. return String(varName);
  34. }
  35. static String CoordTransformName(const String& arg, int index) {
  36. if (arg.size()) {
  37. return HCodeGenerator::FieldName(arg.c_str()) + "CoordTransform";
  38. }
  39. return "fCoordTransform" + to_string(index);
  40. }
  41. static String GetHeader(const Program& program, ErrorReporter& errors);
  42. private:
  43. void writef(const char* s, va_list va) SKSL_PRINTF_LIKE(2, 0);
  44. void writef(const char* s, ...) SKSL_PRINTF_LIKE(2, 3);
  45. bool writeSection(const char* name, const char* prefix = "");
  46. // given a @constructorParams section of e.g. 'int x, float y', writes out "<separator>x, y".
  47. // Writes nothing (not even the separator) if there is no @constructorParams section.
  48. void writeExtraConstructorParams(const char* separator);
  49. void writeMake();
  50. void writeConstructor();
  51. void writeFields();
  52. void failOnSection(const char* section, const char* msg);
  53. const Context& fContext;
  54. String fName;
  55. String fFullName;
  56. SectionAndParameterHelper fSectionAndParameterHelper;
  57. typedef CodeGenerator INHERITED;
  58. };
  59. } // namespace SkSL
  60. #endif