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