blob: a1360b5ac7b593eca130d10907c7f605bf2ef79c [file] [log] [blame]
Jason Sams326e0dd2009-05-22 14:03:28 -07001/*
Stephen Hines44199772012-02-21 20:13:12 -08002 * Copyright (C) 2009-2012 The Android Open Source Project
Jason Sams326e0dd2009-05-22 14:03:28 -07003 *
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
Jason Samsa0a1b6f2009-06-10 15:04:38 -070022
Jason Sams326e0dd2009-05-22 14:03:28 -070023// ---------------------------------------------------------------------------
24namespace android {
25namespace renderscript {
26
Jason Sams93eacc72012-12-18 14:26:57 -080027#ifndef RS_COMPATIBILITY_LIB
Jason Samsa0a1b6f2009-06-10 15:04:38 -070028class ProgramVertex;
29class ProgramFragment;
30class ProgramRaster;
Jason Samsccc010b2010-05-13 18:30:11 -070031class ProgramStore;
Jason Sams93eacc72012-12-18 14:26:57 -080032#endif
Jason Sams326e0dd2009-05-22 14:03:28 -070033
Jason Samsdbe66d62012-09-17 13:54:41 -070034class ScriptKernelID : public ObjectBase {
35public:
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
48class ScriptFieldID : public ObjectBase {
49public:
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
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -080060class Script : public ObjectBase {
Jason Sams326e0dd2009-05-22 14:03:28 -070061public:
Jason Samsdbe66d62012-09-17 13:54:41 -070062
Jason Samsbad80742011-03-16 16:29:28 -070063 struct Hal {
64 void * drv;
65
Jason Samsbad80742011-03-16 16:29:28 -070066 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)();
Jason Samsbad80742011-03-16 16:29:28 -070077 };
78 DriverInfo info;
79 };
80 Hal mHal;
81
Jason Sams8c6bc692009-09-16 15:04:38 -070082 typedef void (* InvokeFunc_t)(void);
Jason Sams326e0dd2009-05-22 14:03:28 -070083
Jason Samse514b452009-09-25 14:51:22 -070084 Script(Context *);
Jason Sams326e0dd2009-05-22 14:03:28 -070085 virtual ~Script();
86
Jason Sams928b7342009-06-08 18:50:13 -070087 struct Enviroment_t {
Jason Samsef5867a2010-07-28 11:17:53 -070088 int64_t mStartTimeMillis;
Jason Sams709a0972012-11-15 18:18:04 -080089 mutable int64_t mLastDtTime;
Romain Guy98e10fd2009-07-30 18:45:01 -070090
Jason Sams93eacc72012-12-18 14:26:57 -080091#ifndef RS_COMPATIBILITY_LIB
Jason Samsa0a1b6f2009-06-10 15:04:38 -070092 ObjectBaseRef<ProgramVertex> mVertex;
93 ObjectBaseRef<ProgramFragment> mFragment;
Jason Samsb681c8a2009-09-28 18:12:56 -070094 ObjectBaseRef<ProgramRaster> mRaster;
Jason Samsccc010b2010-05-13 18:30:11 -070095 ObjectBaseRef<ProgramStore> mFragmentStore;
Jason Sams93eacc72012-12-18 14:26:57 -080096#endif
Jason Sams928b7342009-06-08 18:50:13 -070097 };
98 Enviroment_t mEnviroment;
Jason Sams326e0dd2009-05-22 14:03:28 -070099
Alex Sakhartchouk700ba382010-10-08 15:00:05 -0700100 void setSlot(uint32_t slot, Allocation *a);
Alex Sakhartchoukb81a0eb2011-06-03 10:18:01 -0700101 void setVar(uint32_t slot, const void *val, size_t len);
Tim Murray9c642392013-04-11 13:29:59 -0700102 void getVar(uint32_t slot, const void *val, size_t len);
Stephen Hines2980f072012-04-09 18:26:29 -0700103 void setVar(uint32_t slot, const void *val, size_t len, Element *e,
104 const size_t *dims, size_t dimLen);
Jason Samsa5eb6e12010-11-16 17:37:02 -0800105 void setVarObj(uint32_t slot, ObjectBase *val);
Jason Sams8c6bc692009-09-16 15:04:38 -0700106
Stephen Hines4ee16ff2011-08-31 17:41:39 -0700107 virtual bool freeChildren();
108
Jason Samsace3e012010-07-15 17:11:13 -0700109 virtual void runForEach(Context *rsc,
Stephen Hines44199772012-02-21 20:13:12 -0800110 uint32_t slot,
Jason Samsace3e012010-07-15 17:11:13 -0700111 const Allocation * ain,
112 Allocation * aout,
113 const void * usr,
Jason Sams87fe59a2011-04-20 15:09:01 -0700114 size_t usrBytes,
Jason Samsace3e012010-07-15 17:11:13 -0700115 const RsScriptCall *sc = NULL) = 0;
Jason Samsc61346b2010-05-28 18:23:22 -0700116
Alex Sakhartchoukb81a0eb2011-06-03 10:18:01 -0700117 virtual void Invoke(Context *rsc, uint32_t slot, const void *data, size_t len) = 0;
Jason Samsc61346b2010-05-28 18:23:22 -0700118 virtual void setupScript(Context *rsc) = 0;
119 virtual uint32_t run(Context *) = 0;
Alex Sakhartchouk700ba382010-10-08 15:00:05 -0700120protected:
Jason Sams77020c52011-11-22 12:49:11 -0800121 bool mInitialized;
Alex Sakhartchouk700ba382010-10-08 15:00:05 -0700122 ObjectBaseRef<Allocation> *mSlots;
123 ObjectBaseRef<const Type> *mTypes;
124
Jason Sams326e0dd2009-05-22 14:03:28 -0700125};
126
127
Jason Sams326e0dd2009-05-22 14:03:28 -0700128}
129}
130#endif
131