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