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