rsScript.h revision d2432b9691869b5b40a5b49c682c40d917ea9dcb
1/*
2 * Copyright (C) 2009 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 ProgramVertex;
28class ProgramFragment;
29class ProgramRaster;
30class ProgramStore;
31
32class Script : public ObjectBase {
33public:
34    struct Hal {
35        void * drv;
36
37        struct DriverInfo {
38            int mVersionMajor;
39            int mVersionMinor;
40
41            size_t exportedVariableCount;
42            size_t exportedFunctionCount;
43            size_t exportedPragmaCount;
44            char const **exportedPragmaKeyList;
45            char const **exportedPragmaValueList;
46
47            int (* root)();
48            bool isThreadable;
49        };
50        DriverInfo info;
51    };
52    Hal mHal;
53
54    typedef void (* InvokeFunc_t)(void);
55
56    Script(Context *);
57    virtual ~Script();
58
59    struct Enviroment_t {
60        int64_t mStartTimeMillis;
61        int64_t mLastDtTime;
62
63        ObjectBaseRef<ProgramVertex> mVertex;
64        ObjectBaseRef<ProgramFragment> mFragment;
65        ObjectBaseRef<ProgramRaster> mRaster;
66        ObjectBaseRef<ProgramStore> mFragmentStore;
67    };
68    Enviroment_t mEnviroment;
69
70    void initSlots();
71    void setSlot(uint32_t slot, Allocation *a);
72    void setVar(uint32_t slot, const void *val, size_t len);
73    void setVarObj(uint32_t slot, ObjectBase *val);
74
75    virtual bool freeChildren();
76
77    virtual void runForEach(Context *rsc,
78                            const Allocation * ain,
79                            Allocation * aout,
80                            const void * usr,
81                            size_t usrBytes,
82                            const RsScriptCall *sc = NULL) = 0;
83
84    virtual void Invoke(Context *rsc, uint32_t slot, const void *data, size_t len) = 0;
85    virtual void setupScript(Context *rsc) = 0;
86    virtual uint32_t run(Context *) = 0;
87protected:
88    ObjectBaseRef<Allocation> *mSlots;
89    ObjectBaseRef<const Type> *mTypes;
90
91};
92
93
94}
95}
96#endif
97
98