rsScriptC.h revision e195a3f57ace3b66d313a6ee88c6e93d5c9d87f4
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 "rsEnv.h"
23
24#ifndef FAKE_ARM64_BUILD
25#ifndef RS_COMPATIBILITY_LIB
26#ifndef ANDROID_RS_SERIALIZE
27#include "bcinfo/BitcodeTranslator.h"
28#endif
29#endif
30#endif
31
32// ---------------------------------------------------------------------------
33namespace android {
34namespace renderscript {
35
36
37class ScriptC : public Script {
38public:
39    typedef int (*RunScript_t)();
40    typedef void (*VoidFunc_t)();
41
42    ScriptC(Context *);
43    virtual ~ScriptC();
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(Context *rsc, 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 *);
67private:
68#ifndef FAKE_ARM64_BUILD
69#ifndef RS_COMPATIBILITY_LIB
70#ifndef ANDROID_RS_SERIALIZE
71    bcinfo::BitcodeTranslator *BT;
72#endif
73
74    bool createCacheDir(const char *cacheDir);
75#endif
76#endif
77};
78
79class ScriptCState {
80public:
81    ScriptCState();
82    ~ScriptCState();
83
84    char * mScriptText;
85    size_t mScriptLen;
86
87    struct SymbolTable_t {
88        const char * mName;
89        void * mPtr;
90        bool threadable;
91    };
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