rsScriptC.h revision 4419977d78018a9933c7f455fe001f644f2d638b
1/*
2 * Copyright (C) 2009-2012 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#ifndef ANDROID_RS_SERIALIZE
25#include "bcinfo/BitcodeTranslator.h"
26#endif
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
42    const Allocation *ptrToAllocation(const void *) const;
43
44
45    virtual void Invoke(Context *rsc, uint32_t slot, const void *data, size_t len);
46
47    virtual uint32_t run(Context *);
48
49    virtual void runForEach(Context *rsc,
50                            uint32_t slot,
51                            const Allocation * ain,
52                            Allocation * aout,
53                            const void * usr,
54                            size_t usrBytes,
55                            const RsScriptCall *sc = NULL);
56
57    virtual void serialize(OStream *stream) const {    }
58    virtual RsA3DClassID getClassId() const { return RS_A3D_CLASS_ID_SCRIPT_C; }
59    static Type *createFromStream(Context *rsc, IStream *stream) { return NULL; }
60
61    bool runCompiler(Context *rsc, const char *resName, const char *cacheDir,
62                     const uint8_t *bitcode, size_t bitcodeLen);
63
64//protected:
65    void setupScript(Context *);
66    void setupGLState(Context *);
67    Script * setTLS(Script *);
68  private:
69#ifndef ANDROID_RS_SERIALIZE
70    bcinfo::BitcodeTranslator *BT;
71#endif
72};
73
74class ScriptCState {
75public:
76    ScriptCState();
77    ~ScriptCState();
78
79    char * mScriptText;
80    size_t mScriptLen;
81
82    struct SymbolTable_t {
83        const char * mName;
84        void * mPtr;
85        bool threadable;
86    };
87    static const SymbolTable_t * lookupSymbol(const char *);
88    static const SymbolTable_t * lookupSymbolCL(const char *);
89    static const SymbolTable_t * lookupSymbolGL(const char *);
90};
91
92
93}
94}
95#endif
96