Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 1 | /* |
Stephen Hines | 4419977 | 2012-02-21 20:13:12 -0800 | [diff] [blame] | 2 | * Copyright (C) 2009-2012 The Android Open Source Project |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 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 | |
Jason Sams | 3715b00 | 2012-02-16 16:07:49 -0800 | [diff] [blame] | 22 | #include "rsEnv.h" |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 23 | |
Jason Sams | 93eacc7 | 2012-12-18 14:26:57 -0800 | [diff] [blame] | 24 | #ifndef RS_COMPATIBILITY_LIB |
Stephen Hines | cbb0b8a | 2011-08-01 15:02:34 -0700 | [diff] [blame] | 25 | #ifndef ANDROID_RS_SERIALIZE |
| 26 | #include "bcinfo/BitcodeTranslator.h" |
| 27 | #endif |
Jason Sams | 93eacc7 | 2012-12-18 14:26:57 -0800 | [diff] [blame] | 28 | #endif |
Jack Palevich | 1ef8b80 | 2009-05-28 15:53:04 -0700 | [diff] [blame] | 29 | |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 30 | // --------------------------------------------------------------------------- |
| 31 | namespace android { |
| 32 | namespace renderscript { |
| 33 | |
Jack Palevich | 1ef8b80 | 2009-05-28 15:53:04 -0700 | [diff] [blame] | 34 | |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 35 | class ScriptC : public Script { |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 36 | public: |
Jason Sams | be36bf3 | 2010-05-11 14:03:58 -0700 | [diff] [blame] | 37 | typedef int (*RunScript_t)(); |
Jason Sams | 1d54f10 | 2009-09-03 15:43:13 -0700 | [diff] [blame] | 38 | typedef void (*VoidFunc_t)(); |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 39 | |
Jason Sams | e514b45 | 2009-09-25 14:51:22 -0700 | [diff] [blame] | 40 | ScriptC(Context *); |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 41 | virtual ~ScriptC(); |
| 42 | |
Alex Sakhartchouk | b81a0eb | 2011-06-03 10:18:01 -0700 | [diff] [blame] | 43 | virtual void Invoke(Context *rsc, uint32_t slot, const void *data, size_t len); |
Jason Sams | 22fa371 | 2010-05-19 17:22:57 -0700 | [diff] [blame] | 44 | |
Jason Sams | c61346b | 2010-05-28 18:23:22 -0700 | [diff] [blame] | 45 | virtual uint32_t run(Context *); |
| 46 | |
Jason Sams | ace3e01 | 2010-07-15 17:11:13 -0700 | [diff] [blame] | 47 | virtual void runForEach(Context *rsc, |
Stephen Hines | 4419977 | 2012-02-21 20:13:12 -0800 | [diff] [blame] | 48 | uint32_t slot, |
Jason Sams | ace3e01 | 2010-07-15 17:11:13 -0700 | [diff] [blame] | 49 | const Allocation * ain, |
| 50 | Allocation * aout, |
| 51 | const void * usr, |
Jason Sams | 87fe59a | 2011-04-20 15:09:01 -0700 | [diff] [blame] | 52 | size_t usrBytes, |
Jason Sams | ace3e01 | 2010-07-15 17:11:13 -0700 | [diff] [blame] | 53 | const RsScriptCall *sc = NULL); |
Jason Sams | c61346b | 2010-05-28 18:23:22 -0700 | [diff] [blame] | 54 | |
Jason Sams | e3150cf | 2012-07-24 18:10:20 -0700 | [diff] [blame] | 55 | virtual void serialize(Context *rsc, OStream *stream) const { } |
Alex Sakhartchouk | b825f67 | 2010-06-04 10:06:50 -0700 | [diff] [blame] | 56 | virtual RsA3DClassID getClassId() const { return RS_A3D_CLASS_ID_SCRIPT_C; } |
Alex Sakhartchouk | fb6b614 | 2010-05-21 12:53:13 -0700 | [diff] [blame] | 57 | static Type *createFromStream(Context *rsc, IStream *stream) { return NULL; } |
Jason Sams | c61346b | 2010-05-28 18:23:22 -0700 | [diff] [blame] | 58 | |
Jason Sams | bad8074 | 2011-03-16 16:29:28 -0700 | [diff] [blame] | 59 | bool runCompiler(Context *rsc, const char *resName, const char *cacheDir, |
| 60 | const uint8_t *bitcode, size_t bitcodeLen); |
| 61 | |
Jason Sams | cdfdb8f | 2011-03-17 16:12:47 -0700 | [diff] [blame] | 62 | //protected: |
Jason Sams | c61346b | 2010-05-28 18:23:22 -0700 | [diff] [blame] | 63 | void setupScript(Context *); |
| 64 | void setupGLState(Context *); |
Jason Sams | 709a097 | 2012-11-15 18:18:04 -0800 | [diff] [blame] | 65 | private: |
Jason Sams | 93eacc7 | 2012-12-18 14:26:57 -0800 | [diff] [blame] | 66 | #ifndef RS_COMPATIBILITY_LIB |
Stephen Hines | cbb0b8a | 2011-08-01 15:02:34 -0700 | [diff] [blame] | 67 | #ifndef ANDROID_RS_SERIALIZE |
| 68 | bcinfo::BitcodeTranslator *BT; |
| 69 | #endif |
Jason Sams | 93eacc7 | 2012-12-18 14:26:57 -0800 | [diff] [blame] | 70 | |
Tim Murray | e78c14b | 2012-10-01 15:27:18 -0700 | [diff] [blame] | 71 | bool createCacheDir(const char *cacheDir); |
Jason Sams | 93eacc7 | 2012-12-18 14:26:57 -0800 | [diff] [blame] | 72 | #endif |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 73 | }; |
| 74 | |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 75 | class ScriptCState { |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 76 | public: |
| 77 | ScriptCState(); |
| 78 | ~ScriptCState(); |
| 79 | |
Jason Sams | 249d453 | 2011-01-23 17:48:45 -0800 | [diff] [blame] | 80 | char * mScriptText; |
| 81 | size_t mScriptLen; |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 82 | |
Jason Sams | 29df66f | 2009-07-16 15:08:06 -0700 | [diff] [blame] | 83 | struct SymbolTable_t { |
| 84 | const char * mName; |
| 85 | void * mPtr; |
Jason Sams | 6bfc1b9 | 2010-11-01 14:26:30 -0700 | [diff] [blame] | 86 | bool threadable; |
Jason Sams | 29df66f | 2009-07-16 15:08:06 -0700 | [diff] [blame] | 87 | }; |
Jason Sams | 29df66f | 2009-07-16 15:08:06 -0700 | [diff] [blame] | 88 | static const SymbolTable_t * lookupSymbol(const char *); |
Jason Sams | aeb094b | 2010-05-18 13:35:45 -0700 | [diff] [blame] | 89 | static const SymbolTable_t * lookupSymbolCL(const char *); |
| 90 | static const SymbolTable_t * lookupSymbolGL(const char *); |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 91 | }; |
| 92 | |
| 93 | |
| 94 | } |
| 95 | } |
| 96 | #endif |