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 | |
Alex Sakhartchouk | ebd65bb | 2011-02-25 09:34:33 -0800 | [diff] [blame] | 24 | struct BCCOpaqueScript; |
Jack Palevich | ec5a20b | 2009-05-28 15:53:04 -0700 | [diff] [blame] | 25 | |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 26 | // --------------------------------------------------------------------------- |
| 27 | namespace android { |
| 28 | namespace renderscript { |
| 29 | |
Jack Palevich | ec5a20b | 2009-05-28 15:53:04 -0700 | [diff] [blame] | 30 | |
Alex Sakhartchouk | ed9f210 | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 31 | class ScriptC : public Script { |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 32 | public: |
Jason Sams | 4d33993 | 2010-05-11 14:03:58 -0700 | [diff] [blame] | 33 | typedef int (*RunScript_t)(); |
Jason Sams | 2525a81 | 2009-09-03 15:43:13 -0700 | [diff] [blame] | 34 | typedef void (*VoidFunc_t)(); |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 35 | |
Jason Sams | a9e7a05 | 2009-09-25 14:51:22 -0700 | [diff] [blame] | 36 | ScriptC(Context *); |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 37 | virtual ~ScriptC(); |
| 38 | |
Jason Sams | 3a833d8 | 2009-06-08 15:20:31 -0700 | [diff] [blame] | 39 | struct Program_t { |
Jason Sams | 928f5cf | 2009-06-08 18:50:13 -0700 | [diff] [blame] | 40 | int mVersionMajor; |
| 41 | int mVersionMinor; |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 42 | |
Jason Sams | 4d33993 | 2010-05-11 14:03:58 -0700 | [diff] [blame] | 43 | RunScript_t mRoot; |
Jason Sams | 2525a81 | 2009-09-03 15:43:13 -0700 | [diff] [blame] | 44 | VoidFunc_t mInit; |
Jason Sams | 38f8d9d | 2011-01-27 00:14:13 -0800 | [diff] [blame] | 45 | |
| 46 | uint32_t * mObjectSlotList; |
| 47 | uint32_t mObjectSlotCount; |
Jason Sams | 3a833d8 | 2009-06-08 15:20:31 -0700 | [diff] [blame] | 48 | }; |
| 49 | |
Jason Sams | 38f8d9d | 2011-01-27 00:14:13 -0800 | [diff] [blame] | 50 | |
Jason Sams | 3a833d8 | 2009-06-08 15:20:31 -0700 | [diff] [blame] | 51 | Program_t mProgram; |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 52 | |
Alex Sakhartchouk | ebd65bb | 2011-02-25 09:34:33 -0800 | [diff] [blame] | 53 | BCCOpaqueScript *mBccScript; |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 54 | |
Jason Sams | 1de0b87 | 2010-05-17 14:55:34 -0700 | [diff] [blame] | 55 | const Allocation *ptrToAllocation(const void *) const; |
| 56 | |
Jason Sams | d79b2e9 | 2010-05-19 17:22:57 -0700 | [diff] [blame] | 57 | |
| 58 | virtual void Invoke(Context *rsc, uint32_t slot, const void *data, uint32_t len); |
| 59 | |
Jason Sams | f17bccc | 2010-05-28 18:23:22 -0700 | [diff] [blame] | 60 | virtual uint32_t run(Context *); |
| 61 | |
Jason Sams | 8f8a572 | 2010-07-15 17:11:13 -0700 | [diff] [blame] | 62 | virtual void runForEach(Context *rsc, |
| 63 | const Allocation * ain, |
| 64 | Allocation * aout, |
| 65 | const void * usr, |
| 66 | const RsScriptCall *sc = NULL); |
Jason Sams | f17bccc | 2010-05-28 18:23:22 -0700 | [diff] [blame] | 67 | |
Alex Sakhartchouk | aa7d288 | 2010-05-21 12:53:13 -0700 | [diff] [blame] | 68 | virtual void serialize(OStream *stream) const { } |
Alex Sakhartchouk | aae74ad | 2010-06-04 10:06:50 -0700 | [diff] [blame] | 69 | virtual RsA3DClassID getClassId() const { return RS_A3D_CLASS_ID_SCRIPT_C; } |
Alex Sakhartchouk | aa7d288 | 2010-05-21 12:53:13 -0700 | [diff] [blame] | 70 | static Type *createFromStream(Context *rsc, IStream *stream) { return NULL; } |
Jason Sams | f17bccc | 2010-05-28 18:23:22 -0700 | [diff] [blame] | 71 | |
| 72 | protected: |
| 73 | void setupScript(Context *); |
| 74 | void setupGLState(Context *); |
| 75 | Script * setTLS(Script *); |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 76 | }; |
| 77 | |
Alex Sakhartchouk | ed9f210 | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 78 | class ScriptCState { |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 79 | public: |
| 80 | ScriptCState(); |
| 81 | ~ScriptCState(); |
| 82 | |
Jason Sams | c55de66 | 2011-01-23 17:48:45 -0800 | [diff] [blame] | 83 | char * mScriptText; |
| 84 | size_t mScriptLen; |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 85 | |
Jason Sams | fdc54a9 | 2011-01-19 16:14:21 -0800 | [diff] [blame] | 86 | bool runCompiler(Context *rsc, ScriptC *s, const char *resName, const char *cacheDir); |
Jason Sams | 54440a0 | 2009-07-16 15:08:06 -0700 | [diff] [blame] | 87 | |
| 88 | struct SymbolTable_t { |
| 89 | const char * mName; |
| 90 | void * mPtr; |
Jason Sams | 8f0adba | 2010-11-01 14:26:30 -0700 | [diff] [blame] | 91 | bool threadable; |
Jason Sams | 54440a0 | 2009-07-16 15:08:06 -0700 | [diff] [blame] | 92 | }; |
Jason Sams | 54440a0 | 2009-07-16 15:08:06 -0700 | [diff] [blame] | 93 | static const SymbolTable_t * lookupSymbol(const char *); |
Jason Sams | 536923d | 2010-05-18 13:35:45 -0700 | [diff] [blame] | 94 | static const SymbolTable_t * lookupSymbolCL(const char *); |
| 95 | static const SymbolTable_t * lookupSymbolGL(const char *); |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 96 | }; |
| 97 | |
| 98 | |
| 99 | } |
| 100 | } |
| 101 | #endif |