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 // ---------------------------------------------------------------------------
24 namespace android {
25 namespace renderscript {
26 
27 
28 /** This class represents a script compiled from an .rs file. */
29 class ScriptC : public Script {
30 public:
31     typedef int (*RunScript_t)();
32     typedef void (*VoidFunc_t)();
33 
34     ScriptC(Context *);
35     virtual ~ScriptC();
36 
37     void Invoke(Context *rsc, uint32_t slot, const void *data, size_t len) override;
38 
39     virtual uint32_t run(Context *);
40 
41     void runForEach(Context *rsc,
42                     uint32_t slot,
43                     const Allocation ** ains,
44                     size_t inLen,
45                     Allocation * aout,
46                     const void * usr,
47                     size_t usrBytes,
48                     const RsScriptCall *sc = nullptr) override;
49 
50     void runReduce(Context *rsc, uint32_t slot,
51                    const Allocation ** ains, size_t inLen,
52                    Allocation *aout, const RsScriptCall *sc) override;
53 
serialize(Context * rsc,OStream * stream)54     virtual void serialize(Context *rsc, OStream *stream) const {    }
getClassId()55     virtual RsA3DClassID getClassId() const { return RS_A3D_CLASS_ID_SCRIPT_C; }
createFromStream(Context * rsc,IStream * stream)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
68 };
69 
70 }
71 }
72 #endif
73