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_H
18#define ANDROID_RS_SCRIPT_H
19
20#include "rsAllocation.h"
21
22
23// ---------------------------------------------------------------------------
24namespace android {
25namespace renderscript {
26
27class ScriptKernelID : public ObjectBase {
28public:
29    ScriptKernelID(Context *rsc, Script *s, int slot, int sig);
30    virtual ~ScriptKernelID();
31
32    virtual void serialize(Context *rsc, OStream *stream) const;
33    virtual RsA3DClassID getClassId() const;
34
35    Script *mScript;
36    int mSlot;
37    bool mHasKernelInput;
38    bool mHasKernelOutput;
39};
40
41class ScriptFieldID : public ObjectBase {
42public:
43    ScriptFieldID(Context *rsc, Script *s, int slot);
44    virtual ~ScriptFieldID();
45
46    virtual void serialize(Context *rsc, OStream *stream) const;
47    virtual RsA3DClassID getClassId() const;
48
49    Script *mScript;
50    int mSlot;
51};
52
53class Script : public ObjectBase {
54public:
55
56    struct Hal {
57        void * drv;
58
59        struct DriverInfo {
60            int mVersionMajor;
61            int mVersionMinor;
62
63            size_t exportedVariableCount;
64            size_t exportedFunctionCount;
65            size_t exportedPragmaCount;
66            char const **exportedPragmaKeyList;
67            char const **exportedPragmaValueList;
68
69            int (* root)();
70            bool isThreadable;
71        };
72        DriverInfo info;
73    };
74    Hal mHal;
75
76    typedef void (* InvokeFunc_t)(void);
77
78    Script(Context *);
79    virtual ~Script();
80
81    struct Enviroment_t {
82        int64_t mStartTimeMillis;
83        int64_t mLastDtTime;
84    };
85    Enviroment_t mEnviroment;
86
87    void setSlot(uint32_t slot, Allocation *a);
88    void setVar(uint32_t slot, const void *val, size_t len);
89    void setVar(uint32_t slot, const void *val, size_t len, Element *e,
90                const size_t *dims, size_t dimLen);
91    void setVarObj(uint32_t slot, ObjectBase *val);
92
93    virtual bool freeChildren();
94
95    virtual void runForEach(Context *rsc,
96                            uint32_t slot,
97                            const Allocation * ain,
98                            Allocation * aout,
99                            const void * usr,
100                            size_t usrBytes,
101                            const RsScriptCall *sc = NULL) = 0;
102
103    virtual void Invoke(Context *rsc, uint32_t slot, const void *data, size_t len) = 0;
104    virtual void setupScript(Context *rsc) = 0;
105    virtual uint32_t run(Context *) = 0;
106protected:
107    bool mInitialized;
108    ObjectBaseRef<Allocation> *mSlots;
109    ObjectBaseRef<const Type> *mTypes;
110
111};
112
113
114}
115}
116#endif
117
118