1 /* 2 * Copyright (C) 2009-2012 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #ifndef ANDROID_RS_SCRIPT_H 18 #define ANDROID_RS_SCRIPT_H 19 20 #include "rsAllocation.h" 21 #include "rsMap.h" 22 23 #include <utility> 24 25 // --------------------------------------------------------------------------- 26 namespace android { 27 namespace renderscript { 28 29 #ifndef RS_COMPATIBILITY_LIB 30 class ProgramVertex; 31 class ProgramFragment; 32 class ProgramRaster; 33 class ProgramStore; 34 #endif 35 36 class IDBase : public ObjectBase { 37 public: 38 IDBase(Context *rsc, Script *s, int slot) : 39 ObjectBase(rsc), mScript(s), mSlot(slot) {} 40 virtual ~IDBase() {} 41 42 virtual void serialize(Context *rsc, OStream *stream) const {} 43 virtual RsA3DClassID getClassId() const; 44 45 Script *mScript; 46 int mSlot; 47 }; 48 49 class ScriptKernelID : public IDBase { 50 public: 51 ScriptKernelID(Context *rsc, Script *s, int slot, int sig); 52 virtual ~ScriptKernelID() {} 53 54 virtual RsA3DClassID getClassId() const; 55 56 bool mHasKernelInput; 57 bool mHasKernelOutput; 58 }; 59 60 class ScriptInvokeID : public IDBase { 61 public: 62 ScriptInvokeID(Context *rsc, Script *s, int slot); 63 virtual ~ScriptInvokeID() {} 64 65 virtual RsA3DClassID getClassId() const; 66 }; 67 68 class ScriptFieldID : public IDBase { 69 public: 70 ScriptFieldID(Context *rsc, Script *s, int slot); 71 virtual ~ScriptFieldID() {} 72 73 virtual RsA3DClassID getClassId() const; 74 }; 75 76 class Script : public ObjectBase { 77 public: 78 79 struct Hal { 80 void * drv; 81 82 struct DriverInfo { 83 int mVersionMajor; 84 int mVersionMinor; 85 86 size_t exportedVariableCount; 87 size_t exportedFunctionCount; 88 size_t exportedPragmaCount; 89 char const **exportedPragmaKeyList; 90 char const **exportedPragmaValueList; 91 const Pair<const char *, uint32_t> *exportedForeachFuncList; 92 93 int (* root)(); 94 }; 95 DriverInfo info; 96 }; 97 Hal mHal; 98 99 Script(Context *); 100 virtual ~Script(); 101 102 struct Enviroment_t { 103 int64_t mStartTimeMillis; 104 mutable int64_t mLastDtTime; 105 106 #ifndef RS_COMPATIBILITY_LIB 107 ObjectBaseRef<ProgramVertex> mVertex; 108 ObjectBaseRef<ProgramFragment> mFragment; 109 ObjectBaseRef<ProgramRaster> mRaster; 110 ObjectBaseRef<ProgramStore> mFragmentStore; 111 #endif 112 }; 113 Enviroment_t mEnviroment; 114 115 void setSlot(uint32_t slot, Allocation *a); 116 void setVar(uint32_t slot, const void *val, size_t len); 117 void getVar(uint32_t slot, const void *val, size_t len); 118 void setVar(uint32_t slot, const void *val, size_t len, Element *e, 119 const uint32_t *dims, size_t dimLen); 120 void setVarObj(uint32_t slot, ObjectBase *val); 121 122 virtual bool freeChildren(); 123 124 virtual void runForEach(Context* rsc, 125 uint32_t slot, 126 const Allocation ** ains, 127 size_t inLen, 128 Allocation* aout, 129 const void* usr, 130 size_t usrBytes, 131 const RsScriptCall *sc = nullptr) = 0; 132 133 virtual void Invoke(Context *rsc, uint32_t slot, const void *data, size_t len) = 0; 134 virtual void setupScript(Context *rsc) = 0; 135 virtual uint32_t run(Context *) = 0; 136 virtual bool isIntrinsic() const { return false; } 137 138 bool hasObjectSlots() const { 139 return mHasObjectSlots; 140 } 141 virtual void callUpdateCacheObject(const Context *rsc, void *dstObj) const; 142 143 uint32_t getApiLevel() const { 144 return mApiLevel; 145 } 146 147 protected: 148 bool mInitialized; 149 bool mHasObjectSlots; 150 uint32_t mApiLevel; 151 ObjectBaseRef<Allocation> *mSlots; 152 ObjectBaseRef<const Type> *mTypes; 153 154 }; 155 156 157 } 158 } 159 #endif 160