SkSLExternalValue.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. /*
  2. * Copyright 2019 Google LLC
  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_EXTERNALVALUE
  8. #define SKSL_EXTERNALVALUE
  9. #include "src/sksl/ir/SkSLSymbol.h"
  10. namespace SkSL {
  11. class String;
  12. class Type;
  13. class ExternalValue : public Symbol {
  14. public:
  15. ExternalValue(const char* name, const Type& type)
  16. : INHERITED(-1, kExternal_Kind, name)
  17. , fType(type) {}
  18. virtual bool canRead() const {
  19. return false;
  20. }
  21. virtual bool canWrite() const {
  22. return false;
  23. }
  24. virtual bool canCall() const {
  25. return false;
  26. }
  27. /**
  28. * Returns the type for purposes of read and write operations.
  29. */
  30. virtual const Type& type() const {
  31. return fType;
  32. }
  33. virtual int callParameterCount() const {
  34. return -1;
  35. }
  36. /**
  37. * Fills in the outTypes array with pointers to the parameter types. outTypes must be able to
  38. * hold callParameterCount() pointers.
  39. */
  40. virtual void getCallParameterTypes(const Type** outTypes) const {
  41. SkASSERT(false);
  42. }
  43. /**
  44. * Returns the return type resulting from a call operation.
  45. */
  46. virtual const Type& callReturnType() const {
  47. return fType;
  48. }
  49. /**
  50. * Reads the external value and stores the resulting data in target. The caller must ensure
  51. * that target is a valid pointer to a region of sufficient size to hold the data contained
  52. * in this external value.
  53. * 'index' is the element index ([0 .. N-1]) within a call to ByteCode::run()
  54. */
  55. virtual void read(int index, float* target) {
  56. SkASSERT(false);
  57. }
  58. /**
  59. * Copies the value in src into this external value. The caller must ensure that src is a
  60. * pointer to the type of data expected by this external value.
  61. * 'index' is the element index ([0 .. N-1]) within a call to ByteCode::run()
  62. */
  63. virtual void write(int index, float* src) {
  64. SkASSERT(false);
  65. }
  66. /**
  67. * Calls the value as a function with the specified parameters. arguments must be a pointer to
  68. * a structure containing the arguments expected by the external value in source order, and
  69. * outResult must be a pointer to a region of sufficient size to hold the function's return
  70. * value.
  71. * 'index' is the element index ([0 .. N-1]) within a call to ByteCode::run()
  72. */
  73. virtual void call(int index, float* arguments, float* outResult) {
  74. SkASSERT(false);
  75. }
  76. /**
  77. * Resolves 'name' within this context and returns an ExternalValue which represents it, or
  78. * null if no such child exists. If the implementation of this method creates new
  79. * ExternalValues and there isn't a more convenient place for ownership of the objects to
  80. * reside, the compiler's takeOwnership method may be useful.
  81. *
  82. * The 'name' string may not persist after this call; do not store this pointer.
  83. */
  84. virtual ExternalValue* getChild(const char* name) const {
  85. return nullptr;
  86. }
  87. String description() const override {
  88. return String("external<") + fName + ">";
  89. }
  90. private:
  91. typedef Symbol INHERITED;
  92. const Type& fType;
  93. };
  94. } // namespace
  95. #endif