Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 1 | /* |
Stephen Hines | 4419977 | 2012-02-21 20:13:12 -0800 | [diff] [blame] | 2 | * Copyright (C) 2009-2012 The Android Open Source Project |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 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 | |
Tobias Grosser | 47935ac | 2013-06-17 11:47:26 -0700 | [diff] [blame] | 22 | #include <utility> |
Jason Sams | a0a1b6f | 2009-06-10 15:04:38 -0700 | [diff] [blame] | 23 | |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 24 | // --------------------------------------------------------------------------- |
| 25 | namespace android { |
| 26 | namespace renderscript { |
| 27 | |
Jason Sams | 93eacc7 | 2012-12-18 14:26:57 -0800 | [diff] [blame] | 28 | #ifndef RS_COMPATIBILITY_LIB |
Jason Sams | a0a1b6f | 2009-06-10 15:04:38 -0700 | [diff] [blame] | 29 | class ProgramVertex; |
| 30 | class ProgramFragment; |
| 31 | class ProgramRaster; |
Jason Sams | ccc010b | 2010-05-13 18:30:11 -0700 | [diff] [blame] | 32 | class ProgramStore; |
Jason Sams | 93eacc7 | 2012-12-18 14:26:57 -0800 | [diff] [blame] | 33 | #endif |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 34 | |
Jason Sams | dbe66d6 | 2012-09-17 13:54:41 -0700 | [diff] [blame] | 35 | class ScriptKernelID : public ObjectBase { |
| 36 | public: |
| 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 | |
| 49 | class ScriptFieldID : public ObjectBase { |
| 50 | public: |
| 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 Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 61 | class Script : public ObjectBase { |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 62 | public: |
Jason Sams | dbe66d6 | 2012-09-17 13:54:41 -0700 | [diff] [blame] | 63 | |
Jason Sams | bad8074 | 2011-03-16 16:29:28 -0700 | [diff] [blame] | 64 | struct Hal { |
| 65 | void * drv; |
| 66 | |
Jason Sams | bad8074 | 2011-03-16 16:29:28 -0700 | [diff] [blame] | 67 | 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 Grosser | 47935ac | 2013-06-17 11:47:26 -0700 | [diff] [blame] | 76 | const std::pair<const char *, uint32_t> *exportedForeachFuncList; |
Jason Sams | bad8074 | 2011-03-16 16:29:28 -0700 | [diff] [blame] | 77 | |
| 78 | int (* root)(); |
Jason Sams | bad8074 | 2011-03-16 16:29:28 -0700 | [diff] [blame] | 79 | }; |
| 80 | DriverInfo info; |
| 81 | }; |
| 82 | Hal mHal; |
| 83 | |
Jason Sams | 8c6bc69 | 2009-09-16 15:04:38 -0700 | [diff] [blame] | 84 | typedef void (* InvokeFunc_t)(void); |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 85 | |
Jason Sams | e514b45 | 2009-09-25 14:51:22 -0700 | [diff] [blame] | 86 | Script(Context *); |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 87 | virtual ~Script(); |
| 88 | |
Jason Sams | 928b734 | 2009-06-08 18:50:13 -0700 | [diff] [blame] | 89 | struct Enviroment_t { |
Jason Sams | ef5867a | 2010-07-28 11:17:53 -0700 | [diff] [blame] | 90 | int64_t mStartTimeMillis; |
Jason Sams | 709a097 | 2012-11-15 18:18:04 -0800 | [diff] [blame] | 91 | mutable int64_t mLastDtTime; |
Romain Guy | 98e10fd | 2009-07-30 18:45:01 -0700 | [diff] [blame] | 92 | |
Jason Sams | 93eacc7 | 2012-12-18 14:26:57 -0800 | [diff] [blame] | 93 | #ifndef RS_COMPATIBILITY_LIB |
Jason Sams | a0a1b6f | 2009-06-10 15:04:38 -0700 | [diff] [blame] | 94 | ObjectBaseRef<ProgramVertex> mVertex; |
| 95 | ObjectBaseRef<ProgramFragment> mFragment; |
Jason Sams | b681c8a | 2009-09-28 18:12:56 -0700 | [diff] [blame] | 96 | ObjectBaseRef<ProgramRaster> mRaster; |
Jason Sams | ccc010b | 2010-05-13 18:30:11 -0700 | [diff] [blame] | 97 | ObjectBaseRef<ProgramStore> mFragmentStore; |
Jason Sams | 93eacc7 | 2012-12-18 14:26:57 -0800 | [diff] [blame] | 98 | #endif |
Jason Sams | 928b734 | 2009-06-08 18:50:13 -0700 | [diff] [blame] | 99 | }; |
| 100 | Enviroment_t mEnviroment; |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 101 | |
Alex Sakhartchouk | 700ba38 | 2010-10-08 15:00:05 -0700 | [diff] [blame] | 102 | void setSlot(uint32_t slot, Allocation *a); |
Alex Sakhartchouk | b81a0eb | 2011-06-03 10:18:01 -0700 | [diff] [blame] | 103 | void setVar(uint32_t slot, const void *val, size_t len); |
Tim Murray | 9c64239 | 2013-04-11 13:29:59 -0700 | [diff] [blame] | 104 | void getVar(uint32_t slot, const void *val, size_t len); |
Stephen Hines | 2980f07 | 2012-04-09 18:26:29 -0700 | [diff] [blame] | 105 | void setVar(uint32_t slot, const void *val, size_t len, Element *e, |
Stephen Hines | f0a5078 | 2014-06-25 13:41:10 -0700 | [diff] [blame] | 106 | const uint32_t *dims, size_t dimLen); |
Jason Sams | a5eb6e1 | 2010-11-16 17:37:02 -0800 | [diff] [blame] | 107 | void setVarObj(uint32_t slot, ObjectBase *val); |
Jason Sams | 8c6bc69 | 2009-09-16 15:04:38 -0700 | [diff] [blame] | 108 | |
Stephen Hines | 4ee16ff | 2011-08-31 17:41:39 -0700 | [diff] [blame] | 109 | virtual bool freeChildren(); |
| 110 | |
Jason Sams | ace3e01 | 2010-07-15 17:11:13 -0700 | [diff] [blame] | 111 | virtual void runForEach(Context *rsc, |
Stephen Hines | 4419977 | 2012-02-21 20:13:12 -0800 | [diff] [blame] | 112 | uint32_t slot, |
Jason Sams | ace3e01 | 2010-07-15 17:11:13 -0700 | [diff] [blame] | 113 | const Allocation * ain, |
| 114 | Allocation * aout, |
| 115 | const void * usr, |
Jason Sams | 87fe59a | 2011-04-20 15:09:01 -0700 | [diff] [blame] | 116 | size_t usrBytes, |
Jason Sams | ace3e01 | 2010-07-15 17:11:13 -0700 | [diff] [blame] | 117 | const RsScriptCall *sc = NULL) = 0; |
Jason Sams | c61346b | 2010-05-28 18:23:22 -0700 | [diff] [blame] | 118 | |
Alex Sakhartchouk | b81a0eb | 2011-06-03 10:18:01 -0700 | [diff] [blame] | 119 | virtual void Invoke(Context *rsc, uint32_t slot, const void *data, size_t len) = 0; |
Jason Sams | c61346b | 2010-05-28 18:23:22 -0700 | [diff] [blame] | 120 | virtual void setupScript(Context *rsc) = 0; |
| 121 | virtual uint32_t run(Context *) = 0; |
Stephen Hines | c78839b | 2013-09-10 17:40:41 -0700 | [diff] [blame] | 122 | |
| 123 | bool hasObjectSlots() const { |
| 124 | return mHasObjectSlots; |
| 125 | } |
Alex Sakhartchouk | 700ba38 | 2010-10-08 15:00:05 -0700 | [diff] [blame] | 126 | protected: |
Jason Sams | 77020c5 | 2011-11-22 12:49:11 -0800 | [diff] [blame] | 127 | bool mInitialized; |
Stephen Hines | c78839b | 2013-09-10 17:40:41 -0700 | [diff] [blame] | 128 | bool mHasObjectSlots; |
Alex Sakhartchouk | 700ba38 | 2010-10-08 15:00:05 -0700 | [diff] [blame] | 129 | ObjectBaseRef<Allocation> *mSlots; |
| 130 | ObjectBaseRef<const Type> *mTypes; |
| 131 | |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 132 | }; |
| 133 | |
| 134 | |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 135 | } |
| 136 | } |
| 137 | #endif |
| 138 | |