blob: 22120322b81ff5b42c8a0a0b0c5961c16a034963 [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
Tobias Grosser47935ac2013-06-17 11:47:26 -070022#include <utility>
Jason Samsa0a1b6f2009-06-10 15:04:38 -070023
Jason Sams326e0dd2009-05-22 14:03:28 -070024// ---------------------------------------------------------------------------
25namespace android {
26namespace renderscript {
27
Jason Sams93eacc72012-12-18 14:26:57 -080028#ifndef RS_COMPATIBILITY_LIB
Jason Samsa0a1b6f2009-06-10 15:04:38 -070029class ProgramVertex;
30class ProgramFragment;
31class ProgramRaster;
Jason Samsccc010b2010-05-13 18:30:11 -070032class ProgramStore;
Jason Sams93eacc72012-12-18 14:26:57 -080033#endif
Jason Sams326e0dd2009-05-22 14:03:28 -070034
Yang Nieb9aa672015-01-27 14:32:25 -080035class IDBase : public ObjectBase {
Jason Samsdbe66d62012-09-17 13:54:41 -070036public:
Yang Nieb9aa672015-01-27 14:32:25 -080037 IDBase(Context *rsc, Script *s, int slot) :
38 ObjectBase(rsc), mScript(s), mSlot(slot) {}
39 virtual ~IDBase() {}
Jason Samsdbe66d62012-09-17 13:54:41 -070040
Yang Nieb9aa672015-01-27 14:32:25 -080041 virtual void serialize(Context *rsc, OStream *stream) const {}
Jason Samsdbe66d62012-09-17 13:54:41 -070042 virtual RsA3DClassID getClassId() const;
43
44 Script *mScript;
45 int mSlot;
Yang Nieb9aa672015-01-27 14:32:25 -080046};
47
48class ScriptKernelID : public IDBase {
49public:
50 ScriptKernelID(Context *rsc, Script *s, int slot, int sig);
51 virtual ~ScriptKernelID() {}
52
53 virtual RsA3DClassID getClassId() const;
54
Jason Samsdbe66d62012-09-17 13:54:41 -070055 bool mHasKernelInput;
56 bool mHasKernelOutput;
57};
58
Yang Nieb9aa672015-01-27 14:32:25 -080059class ScriptInvokeID : public IDBase {
60public:
61 ScriptInvokeID(Context *rsc, Script *s, int slot);
62 virtual ~ScriptInvokeID() {}
63
64 virtual RsA3DClassID getClassId() const;
65};
66
67class ScriptFieldID : public IDBase {
Jason Samsdbe66d62012-09-17 13:54:41 -070068public:
69 ScriptFieldID(Context *rsc, Script *s, int slot);
Yang Nieb9aa672015-01-27 14:32:25 -080070 virtual ~ScriptFieldID() {}
Jason Samsdbe66d62012-09-17 13:54:41 -070071
Jason Samsdbe66d62012-09-17 13:54:41 -070072 virtual RsA3DClassID getClassId() const;
Jason Samsdbe66d62012-09-17 13:54:41 -070073};
74
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -080075class Script : public ObjectBase {
Jason Sams326e0dd2009-05-22 14:03:28 -070076public:
Jason Samsdbe66d62012-09-17 13:54:41 -070077
Jason Samsbad80742011-03-16 16:29:28 -070078 struct Hal {
79 void * drv;
80
Jason Samsbad80742011-03-16 16:29:28 -070081 struct DriverInfo {
82 int mVersionMajor;
83 int mVersionMinor;
84
85 size_t exportedVariableCount;
86 size_t exportedFunctionCount;
87 size_t exportedPragmaCount;
88 char const **exportedPragmaKeyList;
89 char const **exportedPragmaValueList;
Tobias Grosser47935ac2013-06-17 11:47:26 -070090 const std::pair<const char *, uint32_t> *exportedForeachFuncList;
Jason Samsbad80742011-03-16 16:29:28 -070091
92 int (* root)();
Jason Samsbad80742011-03-16 16:29:28 -070093 };
94 DriverInfo info;
95 };
96 Hal mHal;
97
Jason Sams8c6bc692009-09-16 15:04:38 -070098 typedef void (* InvokeFunc_t)(void);
Jason Sams326e0dd2009-05-22 14:03:28 -070099
Jason Samse514b452009-09-25 14:51:22 -0700100 Script(Context *);
Jason Sams326e0dd2009-05-22 14:03:28 -0700101 virtual ~Script();
102
Jason Sams928b7342009-06-08 18:50:13 -0700103 struct Enviroment_t {
Jason Samsef5867a2010-07-28 11:17:53 -0700104 int64_t mStartTimeMillis;
Jason Sams709a0972012-11-15 18:18:04 -0800105 mutable int64_t mLastDtTime;
Romain Guy98e10fd2009-07-30 18:45:01 -0700106
Jason Sams93eacc72012-12-18 14:26:57 -0800107#ifndef RS_COMPATIBILITY_LIB
Jason Samsa0a1b6f2009-06-10 15:04:38 -0700108 ObjectBaseRef<ProgramVertex> mVertex;
109 ObjectBaseRef<ProgramFragment> mFragment;
Jason Samsb681c8a2009-09-28 18:12:56 -0700110 ObjectBaseRef<ProgramRaster> mRaster;
Jason Samsccc010b2010-05-13 18:30:11 -0700111 ObjectBaseRef<ProgramStore> mFragmentStore;
Jason Sams93eacc72012-12-18 14:26:57 -0800112#endif
Jason Sams928b7342009-06-08 18:50:13 -0700113 };
114 Enviroment_t mEnviroment;
Jason Sams326e0dd2009-05-22 14:03:28 -0700115
Alex Sakhartchouk700ba382010-10-08 15:00:05 -0700116 void setSlot(uint32_t slot, Allocation *a);
Alex Sakhartchoukb81a0eb2011-06-03 10:18:01 -0700117 void setVar(uint32_t slot, const void *val, size_t len);
Tim Murray9c642392013-04-11 13:29:59 -0700118 void getVar(uint32_t slot, const void *val, size_t len);
Stephen Hines2980f072012-04-09 18:26:29 -0700119 void setVar(uint32_t slot, const void *val, size_t len, Element *e,
Stephen Hinesf0a50782014-06-25 13:41:10 -0700120 const uint32_t *dims, size_t dimLen);
Jason Samsa5eb6e12010-11-16 17:37:02 -0800121 void setVarObj(uint32_t slot, ObjectBase *val);
Jason Sams8c6bc692009-09-16 15:04:38 -0700122
Stephen Hines4ee16ff2011-08-31 17:41:39 -0700123 virtual bool freeChildren();
124
Chris Wailes4b3c34e2014-06-11 12:00:29 -0700125 virtual void runForEach(Context* rsc,
126 uint32_t slot,
Chris Wailesf3712132014-07-16 15:18:30 -0700127 const Allocation ** ains,
Chris Wailes4b3c34e2014-06-11 12:00:29 -0700128 size_t inLen,
129 Allocation* aout,
130 const void* usr,
131 size_t usrBytes,
Chris Wailes44bef6f2014-08-12 13:51:10 -0700132 const RsScriptCall *sc = nullptr) = 0;
Chris Wailes4b3c34e2014-06-11 12:00:29 -0700133
Alex Sakhartchoukb81a0eb2011-06-03 10:18:01 -0700134 virtual void Invoke(Context *rsc, uint32_t slot, const void *data, size_t len) = 0;
Jason Samsc61346b2010-05-28 18:23:22 -0700135 virtual void setupScript(Context *rsc) = 0;
136 virtual uint32_t run(Context *) = 0;
Yang Nida0f0692015-01-12 13:03:40 -0800137 virtual bool isIntrinsic() const { return false; }
Stephen Hinesc78839b2013-09-10 17:40:41 -0700138
139 bool hasObjectSlots() const {
140 return mHasObjectSlots;
141 }
Jason Samsa36c50a2014-06-17 12:06:06 -0700142 virtual void callUpdateCacheObject(const Context *rsc, void *dstObj) const;
143
Alex Sakhartchouk700ba382010-10-08 15:00:05 -0700144protected:
Jason Sams77020c52011-11-22 12:49:11 -0800145 bool mInitialized;
Stephen Hinesc78839b2013-09-10 17:40:41 -0700146 bool mHasObjectSlots;
Alex Sakhartchouk700ba382010-10-08 15:00:05 -0700147 ObjectBaseRef<Allocation> *mSlots;
148 ObjectBaseRef<const Type> *mTypes;
149
Jason Sams326e0dd2009-05-22 14:03:28 -0700150};
151
152
Jason Sams326e0dd2009-05-22 14:03:28 -0700153}
154}
155#endif