blob: 293b72a2e5cb131e77137b0ba089c26d55e89ed5 [file] [log] [blame]
/*
* Copyright 2019 Google LLC
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#ifndef SKSL_EXTERNALFUNCTION
#define SKSL_EXTERNALFUNCTION
#include "include/private/SkSLSymbol.h"
#include "src/core/SkVM.h"
namespace SkSL {
class Type;
class ExternalFunction : public Symbol {
public:
inline static constexpr Kind kSymbolKind = Kind::kExternal;
ExternalFunction(const char* name, const Type& type)
: INHERITED(Position(), kSymbolKind, name, &type) {}
virtual int callParameterCount() const = 0;
/**
* Fills in the outTypes array with pointers to the parameter types. outTypes must be able to
* hold callParameterCount() pointers.
*/
virtual void getCallParameterTypes(const Type** outTypes) const = 0;
virtual void call(skvm::Builder* builder,
skvm::F32* arguments,
skvm::F32* outResult,
skvm::I32 mask) const = 0;
std::string description() const override {
return "external<" + std::string(this->name()) + ">";
}
// Disable IRNode pooling on external function nodes. ExternalFunction node lifetimes are
// controlled by the calling code; we can't guarantee that they will be destroyed before a
// Program is freed. (In fact, it's very unlikely that they would be.)
static void* operator new(const size_t size) {
return ::operator new(size);
}
static void operator delete(void* ptr) {
::operator delete(ptr);
}
private:
using INHERITED = Symbol;
};
} // namespace SkSL
#endif