rsScriptC.h revision 4b3c34e6833e39bc89c2128002806b654b8e623d
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 "rsEnv.h"
21#include "rsScript.h"
22
23#if !defined(RS_COMPATIBILITY_LIB) && !defined(ANDROID_RS_SERIALIZE)
24#include "bcinfo/BitcodeTranslator.h"
25#endif
26
27// ---------------------------------------------------------------------------
28namespace android {
29namespace renderscript {
30
31
32/** This class represents a script compiled from an .rs file. */
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 runForEach(Context *rsc,
54                            uint32_t slot,
55                            const Allocation ** ains,
56                            size_t inLen,
57                            Allocation * aout,
58                            const void * usr,
59                            size_t usrBytes,
60                            const RsScriptCall *sc = NULL);
61
62    virtual void serialize(Context *rsc, OStream *stream) const {    }
63    virtual RsA3DClassID getClassId() const { return RS_A3D_CLASS_ID_SCRIPT_C; }
64    static Type *createFromStream(Context *rsc, IStream *stream) { return NULL; }
65
66    bool runCompiler(Context *rsc, const char *resName, const char *cacheDir,
67                     const uint8_t *bitcode, size_t bitcodeLen);
68
69//protected:
70    void setupScript(Context *);
71    void setupGLState(Context *);
72private:
73#if !defined(RS_COMPATIBILITY_LIB) && !defined(ANDROID_RS_SERIALIZE)
74    bcinfo::BitcodeTranslator *BT;
75#endif
76
77#if !defined(RS_COMPATIBILITY_LIB)
78    bool createCacheDir(const char *cacheDir);
79#endif
80};
81
82}
83}
84#endif
85