blob: 8afd3bcb1f85d7a2f42fd091f8870e6f07c3478b [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 Samsa0a1b6f2009-06-10 15:04:38 -070027class ProgramVertex;
28class ProgramFragment;
29class ProgramRaster;
Jason Samsccc010b2010-05-13 18:30:11 -070030class ProgramStore;
Jason Sams326e0dd2009-05-22 14:03:28 -070031
Jason Samsdbe66d62012-09-17 13:54:41 -070032class 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
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -080058class Script : public ObjectBase {
Jason Sams326e0dd2009-05-22 14:03:28 -070059public:
Jason Samsdbe66d62012-09-17 13:54:41 -070060
Jason Samsbad80742011-03-16 16:29:28 -070061 struct Hal {
62 void * drv;
63
Jason Samsbad80742011-03-16 16:29:28 -070064 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)();
Jason Samsbad80742011-03-16 16:29:28 -070075 };
76 DriverInfo info;
77 };
78 Hal mHal;
79
Jason Sams8c6bc692009-09-16 15:04:38 -070080 typedef void (* InvokeFunc_t)(void);
Jason Sams326e0dd2009-05-22 14:03:28 -070081
Jason Samse514b452009-09-25 14:51:22 -070082 Script(Context *);
Jason Sams326e0dd2009-05-22 14:03:28 -070083 virtual ~Script();
84
Jason Sams928b7342009-06-08 18:50:13 -070085 struct Enviroment_t {
Jason Samsef5867a2010-07-28 11:17:53 -070086 int64_t mStartTimeMillis;
Jason Sams709a0972012-11-15 18:18:04 -080087 mutable int64_t mLastDtTime;
Romain Guy98e10fd2009-07-30 18:45:01 -070088
Jason Samsa0a1b6f2009-06-10 15:04:38 -070089 ObjectBaseRef<ProgramVertex> mVertex;
90 ObjectBaseRef<ProgramFragment> mFragment;
Jason Samsb681c8a2009-09-28 18:12:56 -070091 ObjectBaseRef<ProgramRaster> mRaster;
Jason Samsccc010b2010-05-13 18:30:11 -070092 ObjectBaseRef<ProgramStore> mFragmentStore;
Jason Sams928b7342009-06-08 18:50:13 -070093 };
94 Enviroment_t mEnviroment;
Jason Sams326e0dd2009-05-22 14:03:28 -070095
Alex Sakhartchouk700ba382010-10-08 15:00:05 -070096 void setSlot(uint32_t slot, Allocation *a);
Alex Sakhartchoukb81a0eb2011-06-03 10:18:01 -070097 void setVar(uint32_t slot, const void *val, size_t len);
Stephen Hines2980f072012-04-09 18:26:29 -070098 void setVar(uint32_t slot, const void *val, size_t len, Element *e,
99 const size_t *dims, size_t dimLen);
Jason Samsa5eb6e12010-11-16 17:37:02 -0800100 void setVarObj(uint32_t slot, ObjectBase *val);
Jason Sams8c6bc692009-09-16 15:04:38 -0700101
Stephen Hines4ee16ff2011-08-31 17:41:39 -0700102 virtual bool freeChildren();
103
Jason Samsace3e012010-07-15 17:11:13 -0700104 virtual void runForEach(Context *rsc,
Stephen Hines44199772012-02-21 20:13:12 -0800105 uint32_t slot,
Jason Samsace3e012010-07-15 17:11:13 -0700106 const Allocation * ain,
107 Allocation * aout,
108 const void * usr,
Jason Sams87fe59a2011-04-20 15:09:01 -0700109 size_t usrBytes,
Jason Samsace3e012010-07-15 17:11:13 -0700110 const RsScriptCall *sc = NULL) = 0;
Jason Samsc61346b2010-05-28 18:23:22 -0700111
Alex Sakhartchoukb81a0eb2011-06-03 10:18:01 -0700112 virtual void Invoke(Context *rsc, uint32_t slot, const void *data, size_t len) = 0;
Jason Samsc61346b2010-05-28 18:23:22 -0700113 virtual void setupScript(Context *rsc) = 0;
114 virtual uint32_t run(Context *) = 0;
Alex Sakhartchouk700ba382010-10-08 15:00:05 -0700115protected:
Jason Sams77020c52011-11-22 12:49:11 -0800116 bool mInitialized;
Alex Sakhartchouk700ba382010-10-08 15:00:05 -0700117 ObjectBaseRef<Allocation> *mSlots;
118 ObjectBaseRef<const Type> *mTypes;
119
Jason Sams326e0dd2009-05-22 14:03:28 -0700120};
121
122
Jason Sams326e0dd2009-05-22 14:03:28 -0700123}
124}
125#endif
126