Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2009 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_C_H |
| 18 | #define ANDROID_RS_SCRIPT_C_H |
| 19 | |
| 20 | #include "rsScript.h" |
| 21 | |
| 22 | #include "RenderScriptEnv.h" |
| 23 | |
Stephen Hines | 4382467a | 2011-08-01 15:02:34 -0700 | [diff] [blame] | 24 | #ifndef ANDROID_RS_SERIALIZE |
| 25 | #include "bcinfo/BitcodeTranslator.h" |
| 26 | #endif |
Jack Palevich | ec5a20b | 2009-05-28 15:53:04 -0700 | [diff] [blame] | 27 | |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 28 | // --------------------------------------------------------------------------- |
| 29 | namespace android { |
| 30 | namespace renderscript { |
| 31 | |
Jack Palevich | ec5a20b | 2009-05-28 15:53:04 -0700 | [diff] [blame] | 32 | |
Alex Sakhartchouk | ed9f210 | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 33 | class ScriptC : public Script { |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 34 | public: |
Jason Sams | 4d33993 | 2010-05-11 14:03:58 -0700 | [diff] [blame] | 35 | typedef int (*RunScript_t)(); |
Jason Sams | 2525a81 | 2009-09-03 15:43:13 -0700 | [diff] [blame] | 36 | typedef void (*VoidFunc_t)(); |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 37 | |
Jason Sams | a9e7a05 | 2009-09-25 14:51:22 -0700 | [diff] [blame] | 38 | ScriptC(Context *); |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 39 | virtual ~ScriptC(); |
| 40 | |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 41 | |
Jason Sams | 1de0b87 | 2010-05-17 14:55:34 -0700 | [diff] [blame] | 42 | const Allocation *ptrToAllocation(const void *) const; |
| 43 | |
Jason Sams | d79b2e9 | 2010-05-19 17:22:57 -0700 | [diff] [blame] | 44 | |
Alex Sakhartchouk | 17a8a19 | 2011-06-03 10:18:01 -0700 | [diff] [blame] | 45 | virtual void Invoke(Context *rsc, uint32_t slot, const void *data, size_t len); |
Jason Sams | d79b2e9 | 2010-05-19 17:22:57 -0700 | [diff] [blame] | 46 | |
Jason Sams | f17bccc | 2010-05-28 18:23:22 -0700 | [diff] [blame] | 47 | virtual uint32_t run(Context *); |
| 48 | |
Jason Sams | 8f8a572 | 2010-07-15 17:11:13 -0700 | [diff] [blame] | 49 | virtual void runForEach(Context *rsc, |
| 50 | const Allocation * ain, |
| 51 | Allocation * aout, |
| 52 | const void * usr, |
Jason Sams | fcf7231 | 2011-04-20 15:09:01 -0700 | [diff] [blame] | 53 | size_t usrBytes, |
Jason Sams | 8f8a572 | 2010-07-15 17:11:13 -0700 | [diff] [blame] | 54 | const RsScriptCall *sc = NULL); |
Jason Sams | f17bccc | 2010-05-28 18:23:22 -0700 | [diff] [blame] | 55 | |
Alex Sakhartchouk | aa7d288 | 2010-05-21 12:53:13 -0700 | [diff] [blame] | 56 | virtual void serialize(OStream *stream) const { } |
Alex Sakhartchouk | aae74ad | 2010-06-04 10:06:50 -0700 | [diff] [blame] | 57 | virtual RsA3DClassID getClassId() const { return RS_A3D_CLASS_ID_SCRIPT_C; } |
Alex Sakhartchouk | aa7d288 | 2010-05-21 12:53:13 -0700 | [diff] [blame] | 58 | static Type *createFromStream(Context *rsc, IStream *stream) { return NULL; } |
Jason Sams | f17bccc | 2010-05-28 18:23:22 -0700 | [diff] [blame] | 59 | |
Jason Sams | e4a06c5 | 2011-03-16 16:29:28 -0700 | [diff] [blame] | 60 | bool runCompiler(Context *rsc, const char *resName, const char *cacheDir, |
| 61 | const uint8_t *bitcode, size_t bitcodeLen); |
| 62 | |
Jason Sams | 55d2a25 | 2011-03-17 16:12:47 -0700 | [diff] [blame] | 63 | //protected: |
Jason Sams | f17bccc | 2010-05-28 18:23:22 -0700 | [diff] [blame] | 64 | void setupScript(Context *); |
| 65 | void setupGLState(Context *); |
| 66 | Script * setTLS(Script *); |
Stephen Hines | 4382467a | 2011-08-01 15:02:34 -0700 | [diff] [blame] | 67 | private: |
| 68 | #ifndef ANDROID_RS_SERIALIZE |
| 69 | bcinfo::BitcodeTranslator *BT; |
| 70 | #endif |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 71 | }; |
| 72 | |
Alex Sakhartchouk | ed9f210 | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 73 | class ScriptCState { |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 74 | public: |
| 75 | ScriptCState(); |
| 76 | ~ScriptCState(); |
| 77 | |
Jason Sams | c55de66 | 2011-01-23 17:48:45 -0800 | [diff] [blame] | 78 | char * mScriptText; |
| 79 | size_t mScriptLen; |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 80 | |
Jason Sams | 54440a0 | 2009-07-16 15:08:06 -0700 | [diff] [blame] | 81 | struct SymbolTable_t { |
| 82 | const char * mName; |
| 83 | void * mPtr; |
Jason Sams | 8f0adba | 2010-11-01 14:26:30 -0700 | [diff] [blame] | 84 | bool threadable; |
Jason Sams | 54440a0 | 2009-07-16 15:08:06 -0700 | [diff] [blame] | 85 | }; |
Jason Sams | 54440a0 | 2009-07-16 15:08:06 -0700 | [diff] [blame] | 86 | static const SymbolTable_t * lookupSymbol(const char *); |
Jason Sams | 536923d | 2010-05-18 13:35:45 -0700 | [diff] [blame] | 87 | static const SymbolTable_t * lookupSymbolCL(const char *); |
| 88 | static const SymbolTable_t * lookupSymbolGL(const char *); |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 89 | }; |
| 90 | |
| 91 | |
| 92 | } |
| 93 | } |
| 94 | #endif |