blob: c1e3301eeb5e51727132d41b40c90b701bd3786d [file] [log] [blame]
Jason Sams326e0dd2009-05-22 14:03:28 -07001/*
Stephen Hines44199772012-02-21 20:13:12 -08002 * Copyright (C) 2009-2012 The Android Open Source Project
Jason Sams326e0dd2009-05-22 14:03:28 -07003 *
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 Sams3715b002012-02-16 16:07:49 -080022#include "rsEnv.h"
Jason Sams326e0dd2009-05-22 14:03:28 -070023
Jason Sams93eacc72012-12-18 14:26:57 -080024#ifndef RS_COMPATIBILITY_LIB
Stephen Hinescbb0b8a2011-08-01 15:02:34 -070025#ifndef ANDROID_RS_SERIALIZE
26#include "bcinfo/BitcodeTranslator.h"
27#endif
Jason Sams93eacc72012-12-18 14:26:57 -080028#endif
Jack Palevich1ef8b802009-05-28 15:53:04 -070029
Jason Sams326e0dd2009-05-22 14:03:28 -070030// ---------------------------------------------------------------------------
31namespace android {
32namespace renderscript {
33
Jack Palevich1ef8b802009-05-28 15:53:04 -070034
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -080035class ScriptC : public Script {
Jason Sams326e0dd2009-05-22 14:03:28 -070036public:
Jason Samsbe36bf32010-05-11 14:03:58 -070037 typedef int (*RunScript_t)();
Jason Sams1d54f102009-09-03 15:43:13 -070038 typedef void (*VoidFunc_t)();
Jason Sams326e0dd2009-05-22 14:03:28 -070039
Jason Samse514b452009-09-25 14:51:22 -070040 ScriptC(Context *);
Jason Sams326e0dd2009-05-22 14:03:28 -070041 virtual ~ScriptC();
42
Alex Sakhartchoukb81a0eb2011-06-03 10:18:01 -070043 virtual void Invoke(Context *rsc, uint32_t slot, const void *data, size_t len);
Jason Sams22fa3712010-05-19 17:22:57 -070044
Jason Samsc61346b2010-05-28 18:23:22 -070045 virtual uint32_t run(Context *);
46
Jason Samsace3e012010-07-15 17:11:13 -070047 virtual void runForEach(Context *rsc,
Stephen Hines44199772012-02-21 20:13:12 -080048 uint32_t slot,
Jason Samsace3e012010-07-15 17:11:13 -070049 const Allocation * ain,
50 Allocation * aout,
51 const void * usr,
Jason Sams87fe59a2011-04-20 15:09:01 -070052 size_t usrBytes,
Jason Samsace3e012010-07-15 17:11:13 -070053 const RsScriptCall *sc = NULL);
Jason Samsc61346b2010-05-28 18:23:22 -070054
Jason Samse3150cf2012-07-24 18:10:20 -070055 virtual void serialize(Context *rsc, OStream *stream) const { }
Alex Sakhartchoukb825f672010-06-04 10:06:50 -070056 virtual RsA3DClassID getClassId() const { return RS_A3D_CLASS_ID_SCRIPT_C; }
Alex Sakhartchoukfb6b6142010-05-21 12:53:13 -070057 static Type *createFromStream(Context *rsc, IStream *stream) { return NULL; }
Jason Samsc61346b2010-05-28 18:23:22 -070058
Jason Samsbad80742011-03-16 16:29:28 -070059 bool runCompiler(Context *rsc, const char *resName, const char *cacheDir,
60 const uint8_t *bitcode, size_t bitcodeLen);
61
Jason Samscdfdb8f2011-03-17 16:12:47 -070062//protected:
Jason Samsc61346b2010-05-28 18:23:22 -070063 void setupScript(Context *);
64 void setupGLState(Context *);
Jason Sams709a0972012-11-15 18:18:04 -080065private:
Jason Sams93eacc72012-12-18 14:26:57 -080066#ifndef RS_COMPATIBILITY_LIB
Stephen Hinescbb0b8a2011-08-01 15:02:34 -070067#ifndef ANDROID_RS_SERIALIZE
68 bcinfo::BitcodeTranslator *BT;
69#endif
Jason Sams93eacc72012-12-18 14:26:57 -080070
Tim Murraye78c14b2012-10-01 15:27:18 -070071 bool createCacheDir(const char *cacheDir);
Jason Sams93eacc72012-12-18 14:26:57 -080072#endif
Jason Sams326e0dd2009-05-22 14:03:28 -070073};
74
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -080075class ScriptCState {
Jason Sams326e0dd2009-05-22 14:03:28 -070076public:
77 ScriptCState();
78 ~ScriptCState();
79
Jason Sams249d4532011-01-23 17:48:45 -080080 char * mScriptText;
81 size_t mScriptLen;
Jason Sams326e0dd2009-05-22 14:03:28 -070082
Jason Sams29df66f2009-07-16 15:08:06 -070083 struct SymbolTable_t {
84 const char * mName;
85 void * mPtr;
Jason Sams6bfc1b92010-11-01 14:26:30 -070086 bool threadable;
Jason Sams29df66f2009-07-16 15:08:06 -070087 };
Jason Sams29df66f2009-07-16 15:08:06 -070088 static const SymbolTable_t * lookupSymbol(const char *);
Jason Samsaeb094b2010-05-18 13:35:45 -070089 static const SymbolTable_t * lookupSymbolCL(const char *);
90 static const SymbolTable_t * lookupSymbolGL(const char *);
Jason Sams326e0dd2009-05-22 14:03:28 -070091};
92
93
94}
95}
96#endif