rsScriptC.h revision ce8a079bd4d296f9f1a24d7a5808d57f71dfc2e4
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
24namespace bcc {
25class BCCscript;
26}
27
28// ---------------------------------------------------------------------------
29namespace android {
30namespace renderscript {
31
32
33class ScriptC : public Script {
34public:
35    typedef int (*RunScript_t)();
36    typedef void (*VoidFunc_t)();
37
38    ScriptC(Context *);
39    virtual ~ScriptC();
40
41    struct Program_t {
42        int mVersionMajor;
43        int mVersionMinor;
44
45        RunScript_t mRoot;
46        VoidFunc_t mInit;
47    };
48
49    Program_t mProgram;
50
51    bcc::BCCscript* mBccScript;
52
53    const Allocation *ptrToAllocation(const void *) const;
54
55
56    virtual void Invoke(Context *rsc, uint32_t slot, const void *data, uint32_t len);
57
58    virtual uint32_t run(Context *);
59
60    virtual void runForEach(Context *rsc,
61                            const Allocation * ain,
62                            Allocation * aout,
63                            const void * usr,
64                            const RsScriptCall *sc = NULL);
65
66    virtual void serialize(OStream *stream) const {    }
67    virtual RsA3DClassID getClassId() const { return RS_A3D_CLASS_ID_SCRIPT_C; }
68    static Type *createFromStream(Context *rsc, IStream *stream) { return NULL; }
69
70protected:
71    void setupScript(Context *);
72    void setupGLState(Context *);
73    Script * setTLS(Script *);
74};
75
76class ScriptCState {
77public:
78    ScriptCState();
79    ~ScriptCState();
80
81    ObjectBaseRef<ScriptC> mScript;
82
83    void init(Context *rsc);
84
85    void clear(Context *rsc);
86    void runCompiler(Context *rsc, ScriptC *s, long modWhen, long crc32, const char *resName, const char *cacheDir);
87
88    struct SymbolTable_t {
89        const char * mName;
90        void * mPtr;
91        bool threadable;
92    };
93    //static SymbolTable_t gSyms[];
94    static const SymbolTable_t * lookupSymbol(const char *);
95    static const SymbolTable_t * lookupSymbolCL(const char *);
96    static const SymbolTable_t * lookupSymbolGL(const char *);
97};
98
99
100}
101}
102#endif
103