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