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 ** ains,
48                            size_t inLen,
49                            Allocation * aout,
50                            const void * usr,
51                            size_t usrBytes,
52                            const RsScriptCall *sc = nullptr);
53
54    virtual void serialize(Context *rsc, OStream *stream) const {    }
55    virtual RsA3DClassID getClassId() const { return RS_A3D_CLASS_ID_SCRIPT_C; }
56    static Type *createFromStream(Context *rsc, IStream *stream) { return nullptr; }
57
58    bool runCompiler(Context *rsc, const char *resName, const char *cacheDir,
59                     const uint8_t *bitcode, size_t bitcodeLen);
60
61//protected:
62    void setupScript(Context *);
63    void setupGLState(Context *);
64
65#if !defined(RS_COMPATIBILITY_LIB)
66    static bool createCacheDir(const char *cacheDir);
67#endif
68private:
69#if !defined(RS_COMPATIBILITY_LIB) && !defined(ANDROID_RS_SERIALIZE)
70    bcinfo::BitcodeTranslator *BT;
71#endif
72};
73
74}
75}
76#endif
77