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 8 #ifndef SKSL_EXTERNALFUNCTION 9 #define SKSL_EXTERNALFUNCTION 10 11 #include "include/private/SkSLSymbol.h" 12 #include "src/core/SkVM.h" 13 14 namespace SkSL { 15 16 class Type; 17 18 class ExternalFunction : public Symbol { 19 public: 20 inline static constexpr Kind kSymbolKind = Kind::kExternal; 21 ExternalFunction(const char * name,const Type & type)22 ExternalFunction(const char* name, const Type& type) 23 : INHERITED(-1, kSymbolKind, name, &type) {} 24 25 virtual int callParameterCount() const = 0; 26 27 /** 28 * Fills in the outTypes array with pointers to the parameter types. outTypes must be able to 29 * hold callParameterCount() pointers. 30 */ 31 virtual void getCallParameterTypes(const Type** outTypes) const = 0; 32 33 virtual void call(skvm::Builder* builder, 34 skvm::F32* arguments, 35 skvm::F32* outResult, 36 skvm::I32 mask) const = 0; 37 description()38 std::string description() const override { 39 return "external<" + std::string(this->name()) + ">"; 40 } 41 42 // Disable IRNode pooling on external function nodes. ExternalFunction node lifetimes are 43 // controlled by the calling code; we can't guarantee that they will be destroyed before a 44 // Program is freed. (In fact, it's very unlikely that they would be.) new(const size_t size)45 static void* operator new(const size_t size) { 46 return ::operator new(size); 47 } 48 delete(void * ptr)49 static void operator delete(void* ptr) { 50 ::operator delete(ptr); 51 } 52 53 private: 54 using INHERITED = Symbol; 55 }; 56 57 } // namespace SkSL 58 59 #endif 60