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