blob: 2c74b5b3ef4e7f68a3c254a173d589603396925c [file] [log] [blame]
Jason Samsd19f10d2009-05-22 14:03:28 -07001/*
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 Sakhartchoukebd65bb2011-02-25 09:34:33 -080024struct BCCOpaqueScript;
Jack Palevichec5a20b2009-05-28 15:53:04 -070025
Jason Samsd19f10d2009-05-22 14:03:28 -070026// ---------------------------------------------------------------------------
27namespace android {
28namespace renderscript {
29
Jack Palevichec5a20b2009-05-28 15:53:04 -070030
Alex Sakhartchouked9f2102010-11-09 17:00:54 -080031class ScriptC : public Script {
Jason Samsd19f10d2009-05-22 14:03:28 -070032public:
Jason Sams4d339932010-05-11 14:03:58 -070033 typedef int (*RunScript_t)();
Jason Sams2525a812009-09-03 15:43:13 -070034 typedef void (*VoidFunc_t)();
Jason Samsd19f10d2009-05-22 14:03:28 -070035
Jason Samsa9e7a052009-09-25 14:51:22 -070036 ScriptC(Context *);
Jason Samsd19f10d2009-05-22 14:03:28 -070037 virtual ~ScriptC();
38
Jason Sams3a833d82009-06-08 15:20:31 -070039 struct Program_t {
Jason Sams928f5cf2009-06-08 18:50:13 -070040 int mVersionMajor;
41 int mVersionMinor;
Jason Samsd19f10d2009-05-22 14:03:28 -070042
Jason Sams4d339932010-05-11 14:03:58 -070043 RunScript_t mRoot;
Jason Sams2525a812009-09-03 15:43:13 -070044 VoidFunc_t mInit;
Jason Sams38f8d9d2011-01-27 00:14:13 -080045
46 uint32_t * mObjectSlotList;
47 uint32_t mObjectSlotCount;
Jason Sams3a833d82009-06-08 15:20:31 -070048 };
49
Jason Sams38f8d9d2011-01-27 00:14:13 -080050
Jason Sams3a833d82009-06-08 15:20:31 -070051 Program_t mProgram;
Jason Samsd19f10d2009-05-22 14:03:28 -070052
Alex Sakhartchoukebd65bb2011-02-25 09:34:33 -080053 BCCOpaqueScript *mBccScript;
Jason Samsd19f10d2009-05-22 14:03:28 -070054
Jason Sams1de0b872010-05-17 14:55:34 -070055 const Allocation *ptrToAllocation(const void *) const;
56
Jason Samsd79b2e92010-05-19 17:22:57 -070057
58 virtual void Invoke(Context *rsc, uint32_t slot, const void *data, uint32_t len);
59
Jason Samsf17bccc2010-05-28 18:23:22 -070060 virtual uint32_t run(Context *);
61
Jason Sams8f8a5722010-07-15 17:11:13 -070062 virtual void runForEach(Context *rsc,
63 const Allocation * ain,
64 Allocation * aout,
65 const void * usr,
66 const RsScriptCall *sc = NULL);
Jason Samsf17bccc2010-05-28 18:23:22 -070067
Alex Sakhartchoukaa7d2882010-05-21 12:53:13 -070068 virtual void serialize(OStream *stream) const { }
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -070069 virtual RsA3DClassID getClassId() const { return RS_A3D_CLASS_ID_SCRIPT_C; }
Alex Sakhartchoukaa7d2882010-05-21 12:53:13 -070070 static Type *createFromStream(Context *rsc, IStream *stream) { return NULL; }
Jason Samsf17bccc2010-05-28 18:23:22 -070071
72protected:
73 void setupScript(Context *);
74 void setupGLState(Context *);
75 Script * setTLS(Script *);
Jason Samsd19f10d2009-05-22 14:03:28 -070076};
77
Alex Sakhartchouked9f2102010-11-09 17:00:54 -080078class ScriptCState {
Jason Samsd19f10d2009-05-22 14:03:28 -070079public:
80 ScriptCState();
81 ~ScriptCState();
82
Jason Samsc55de662011-01-23 17:48:45 -080083 char * mScriptText;
84 size_t mScriptLen;
Jason Samsd19f10d2009-05-22 14:03:28 -070085
Jason Samsfdc54a92011-01-19 16:14:21 -080086 bool runCompiler(Context *rsc, ScriptC *s, const char *resName, const char *cacheDir);
Jason Sams54440a02009-07-16 15:08:06 -070087
88 struct SymbolTable_t {
89 const char * mName;
90 void * mPtr;
Jason Sams8f0adba2010-11-01 14:26:30 -070091 bool threadable;
Jason Sams54440a02009-07-16 15:08:06 -070092 };
Jason Sams54440a02009-07-16 15:08:06 -070093 static const SymbolTable_t * lookupSymbol(const char *);
Jason Sams536923d2010-05-18 13:35:45 -070094 static const SymbolTable_t * lookupSymbolCL(const char *);
95 static const SymbolTable_t * lookupSymbolGL(const char *);
Jason Samsd19f10d2009-05-22 14:03:28 -070096};
97
98
99}
100}
101#endif