blob: ce4878a5844b6953304cb17a9fdd337199fd4fd8 [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
Jason Samsdbe66d62012-09-17 13:54:41 -070035class ScriptKernelID : public ObjectBase {
36public:
37 ScriptKernelID(Context *rsc, Script *s, int slot, int sig);
38 virtual ~ScriptKernelID();
39
40 virtual void serialize(Context *rsc, OStream *stream) const;
41 virtual RsA3DClassID getClassId() const;
42
43 Script *mScript;
44 int mSlot;
45 bool mHasKernelInput;
46 bool mHasKernelOutput;
47};
48
49class ScriptFieldID : public ObjectBase {
50public:
51 ScriptFieldID(Context *rsc, Script *s, int slot);
52 virtual ~ScriptFieldID();
53
54 virtual void serialize(Context *rsc, OStream *stream) const;
55 virtual RsA3DClassID getClassId() const;
56
57 Script *mScript;
58 int mSlot;
59};
60
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -080061class Script : public ObjectBase {
Jason Sams326e0dd2009-05-22 14:03:28 -070062public:
Jason Samsdbe66d62012-09-17 13:54:41 -070063
Jason Samsbad80742011-03-16 16:29:28 -070064 struct Hal {
65 void * drv;
66
Jason Samsbad80742011-03-16 16:29:28 -070067 struct DriverInfo {
68 int mVersionMajor;
69 int mVersionMinor;
70
71 size_t exportedVariableCount;
72 size_t exportedFunctionCount;
73 size_t exportedPragmaCount;
74 char const **exportedPragmaKeyList;
75 char const **exportedPragmaValueList;
Tobias Grosser47935ac2013-06-17 11:47:26 -070076 const std::pair<const char *, uint32_t> *exportedForeachFuncList;
Jason Samsbad80742011-03-16 16:29:28 -070077
78 int (* root)();
Jason Samsbad80742011-03-16 16:29:28 -070079 };
80 DriverInfo info;
81 };
82 Hal mHal;
83
Jason Sams8c6bc692009-09-16 15:04:38 -070084 typedef void (* InvokeFunc_t)(void);
Jason Sams326e0dd2009-05-22 14:03:28 -070085
Jason Samse514b452009-09-25 14:51:22 -070086 Script(Context *);
Jason Sams326e0dd2009-05-22 14:03:28 -070087 virtual ~Script();
88
Jason Sams928b7342009-06-08 18:50:13 -070089 struct Enviroment_t {
Jason Samsef5867a2010-07-28 11:17:53 -070090 int64_t mStartTimeMillis;
Jason Sams709a0972012-11-15 18:18:04 -080091 mutable int64_t mLastDtTime;
Romain Guy98e10fd2009-07-30 18:45:01 -070092
Jason Sams93eacc72012-12-18 14:26:57 -080093#ifndef RS_COMPATIBILITY_LIB
Jason Samsa0a1b6f2009-06-10 15:04:38 -070094 ObjectBaseRef<ProgramVertex> mVertex;
95 ObjectBaseRef<ProgramFragment> mFragment;
Jason Samsb681c8a2009-09-28 18:12:56 -070096 ObjectBaseRef<ProgramRaster> mRaster;
Jason Samsccc010b2010-05-13 18:30:11 -070097 ObjectBaseRef<ProgramStore> mFragmentStore;
Jason Sams93eacc72012-12-18 14:26:57 -080098#endif
Jason Sams928b7342009-06-08 18:50:13 -070099 };
100 Enviroment_t mEnviroment;
Jason Sams326e0dd2009-05-22 14:03:28 -0700101
Alex Sakhartchouk700ba382010-10-08 15:00:05 -0700102 void setSlot(uint32_t slot, Allocation *a);
Alex Sakhartchoukb81a0eb2011-06-03 10:18:01 -0700103 void setVar(uint32_t slot, const void *val, size_t len);
Tim Murray9c642392013-04-11 13:29:59 -0700104 void getVar(uint32_t slot, const void *val, size_t len);
Stephen Hines2980f072012-04-09 18:26:29 -0700105 void setVar(uint32_t slot, const void *val, size_t len, Element *e,
106 const size_t *dims, size_t dimLen);
Jason Samsa5eb6e12010-11-16 17:37:02 -0800107 void setVarObj(uint32_t slot, ObjectBase *val);
Jason Sams8c6bc692009-09-16 15:04:38 -0700108
Stephen Hines4ee16ff2011-08-31 17:41:39 -0700109 virtual bool freeChildren();
110
Jason Samsace3e012010-07-15 17:11:13 -0700111 virtual void runForEach(Context *rsc,
Stephen Hines44199772012-02-21 20:13:12 -0800112 uint32_t slot,
Jason Samsace3e012010-07-15 17:11:13 -0700113 const Allocation * ain,
114 Allocation * aout,
115 const void * usr,
Jason Sams87fe59a2011-04-20 15:09:01 -0700116 size_t usrBytes,
Jason Samsace3e012010-07-15 17:11:13 -0700117 const RsScriptCall *sc = NULL) = 0;
Jason Samsc61346b2010-05-28 18:23:22 -0700118
Alex Sakhartchoukb81a0eb2011-06-03 10:18:01 -0700119 virtual void Invoke(Context *rsc, uint32_t slot, const void *data, size_t len) = 0;
Jason Samsc61346b2010-05-28 18:23:22 -0700120 virtual void setupScript(Context *rsc) = 0;
121 virtual uint32_t run(Context *) = 0;
Stephen Hinesc78839b2013-09-10 17:40:41 -0700122
123 bool hasObjectSlots() const {
124 return mHasObjectSlots;
125 }
Alex Sakhartchouk700ba382010-10-08 15:00:05 -0700126protected:
Jason Sams77020c52011-11-22 12:49:11 -0800127 bool mInitialized;
Stephen Hinesc78839b2013-09-10 17:40:41 -0700128 bool mHasObjectSlots;
Alex Sakhartchouk700ba382010-10-08 15:00:05 -0700129 ObjectBaseRef<Allocation> *mSlots;
130 ObjectBaseRef<const Type> *mTypes;
131
Jason Sams326e0dd2009-05-22 14:03:28 -0700132};
133
134
Jason Sams326e0dd2009-05-22 14:03:28 -0700135}
136}
137#endif
138