1 /* 2 * Copyright (C) 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 RSD_CPU_H 18 #define RSD_CPU_H 19 20 #include "rsAllocation.h" 21 22 #ifndef RS_COMPATIBILITY_LIB 23 namespace llvm { 24 25 class Module; 26 27 } // end namespace llvm 28 29 namespace bcc { 30 31 class RSScript; 32 typedef llvm::Module* (*RSLinkRuntimeCallback) (bcc::RSScript *, llvm::Module *, llvm::Module *); 33 34 } // end namespace bcc; 35 36 typedef const char* (*RSSelectRTCallback) (const char*, size_t); 37 #endif 38 39 namespace android { 40 namespace renderscript { 41 42 class ScriptC; 43 class Script; 44 class ScriptGroup; 45 class ScriptKernelID; 46 47 48 class RsdCpuReference { 49 public: 50 struct CpuSymbol { 51 const char * name; 52 void * fnPtr; 53 bool threadable; 54 }; 55 56 typedef const CpuSymbol * (* sym_lookup_t)(Context *, const char *name); 57 58 struct CpuTls { 59 Context *rsc; 60 const ScriptC * sc; 61 }; 62 63 class CpuScript { 64 public: 65 virtual void populateScript(Script *) = 0; 66 virtual void invokeFunction(uint32_t slot, const void *params, size_t paramLength) = 0; 67 virtual int invokeRoot() = 0; 68 virtual void invokeForEach(uint32_t slot, 69 const Allocation * ain, 70 Allocation * aout, 71 const void * usr, 72 uint32_t usrLen, 73 const RsScriptCall *sc) = 0; 74 virtual void invokeInit() = 0; 75 virtual void invokeFreeChildren() = 0; 76 77 virtual void setGlobalVar(uint32_t slot, const void *data, size_t dataLength) = 0; 78 virtual void getGlobalVar(uint32_t slot, void *data, size_t dataLength) = 0; 79 virtual void setGlobalVarWithElemDims(uint32_t slot, const void *data, size_t dataLength, 80 const Element *e, const size_t *dims, size_t dimLength) = 0; 81 virtual void setGlobalBind(uint32_t slot, Allocation *data) = 0; 82 virtual void setGlobalObj(uint32_t slot, ObjectBase *obj) = 0; 83 84 virtual Allocation * getAllocationForPointer(const void *ptr) const = 0; 85 virtual ~CpuScript() {} 86 87 #ifndef RS_COMPATIBILITY_LIB 88 virtual void * getRSExecutable() = 0; 89 #endif 90 }; 91 typedef CpuScript * (* script_lookup_t)(Context *, const Script *s); 92 93 class CpuScriptGroup { 94 public: 95 virtual void setInput(const ScriptKernelID *kid, Allocation *) = 0; 96 virtual void setOutput(const ScriptKernelID *kid, Allocation *) = 0; 97 virtual void execute() = 0; 98 virtual ~CpuScriptGroup() {}; 99 }; 100 101 static Context * getTlsContext(); 102 static const Script * getTlsScript(); 103 static pthread_key_t getThreadTLSKey(); 104 105 static RsdCpuReference * create(Context *c, uint32_t version_major, 106 uint32_t version_minor, sym_lookup_t lfn, script_lookup_t slfn 107 #ifndef RS_COMPATIBILITY_LIB 108 , bcc::RSLinkRuntimeCallback pLinkRuntimeCallback = NULL, 109 RSSelectRTCallback pSelectRTCallback = NULL 110 #endif 111 ); 112 virtual ~RsdCpuReference(); 113 virtual void setPriority(int32_t priority) = 0; 114 115 virtual CpuScript * createScript(const ScriptC *s, char const *resName, char const *cacheDir, 116 uint8_t const *bitcode, size_t bitcodeSize, 117 uint32_t flags) = 0; 118 virtual CpuScript * createIntrinsic(const Script *s, RsScriptIntrinsicID iid, Element *e) = 0; 119 virtual CpuScriptGroup * createScriptGroup(const ScriptGroup *sg) = 0; 120 virtual bool getInForEach() = 0; 121 122 }; 123 124 125 } 126 } 127 128 #endif 129