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