Jason Sams | dbe66d6 | 2012-09-17 13:54:41 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2012 The Android Open Source Project |
| 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_GROUP_H |
| 18 | #define ANDROID_RS_SCRIPT_GROUP_H |
| 19 | |
Yang Ni | 1ffd86b | 2015-01-07 09:16:40 -0800 | [diff] [blame] | 20 | #include "rsScriptGroupBase.h" |
Jason Sams | dbe66d6 | 2012-09-17 13:54:41 -0700 | [diff] [blame] | 21 | |
Yang Ni | 1ffd86b | 2015-01-07 09:16:40 -0800 | [diff] [blame] | 22 | #include <vector> |
Jason Sams | dbe66d6 | 2012-09-17 13:54:41 -0700 | [diff] [blame] | 23 | |
| 24 | // --------------------------------------------------------------------------- |
| 25 | namespace android { |
| 26 | namespace renderscript { |
| 27 | |
Yang Ni | 1ffd86b | 2015-01-07 09:16:40 -0800 | [diff] [blame] | 28 | class Allocation; |
| 29 | class Context; |
Jason Sams | dbe66d6 | 2012-09-17 13:54:41 -0700 | [diff] [blame] | 30 | class ProgramVertex; |
| 31 | class ProgramFragment; |
| 32 | class ProgramRaster; |
| 33 | class ProgramStore; |
Yang Ni | 1ffd86b | 2015-01-07 09:16:40 -0800 | [diff] [blame] | 34 | class Script; |
| 35 | class ScriptFieldID; |
| 36 | class ScriptKernelID; |
| 37 | class Type; |
Jason Sams | dbe66d6 | 2012-09-17 13:54:41 -0700 | [diff] [blame] | 38 | |
Yang Ni | 1ffd86b | 2015-01-07 09:16:40 -0800 | [diff] [blame] | 39 | class ScriptGroup : public ScriptGroupBase { |
Jason Sams | dbe66d6 | 2012-09-17 13:54:41 -0700 | [diff] [blame] | 40 | public: |
Yang Ni | 1ffd86b | 2015-01-07 09:16:40 -0800 | [diff] [blame] | 41 | virtual SG_API_Version getApiVersion() const { return SG_V1; } |
| 42 | virtual void execute(Context *rsc); |
| 43 | |
Yang Ni | b8353c5 | 2015-02-14 18:00:59 -0800 | [diff] [blame] | 44 | Vector<ObjectBaseRef<ScriptKernelID> > mKernels; |
Jason Sams | dbe66d6 | 2012-09-17 13:54:41 -0700 | [diff] [blame] | 45 | |
| 46 | class Link { |
| 47 | public: |
| 48 | ObjectBaseRef<const ScriptKernelID> mSource; |
| 49 | ObjectBaseRef<const ScriptKernelID> mDstKernel; |
| 50 | ObjectBaseRef<const ScriptFieldID> mDstField; |
| 51 | ObjectBaseRef<const Type> mType; |
| 52 | ObjectBaseRef<Allocation> mAlloc; |
| 53 | Link(); |
| 54 | ~Link(); |
| 55 | }; |
| 56 | |
| 57 | class Node { |
| 58 | public: |
Chih-Hung Hsieh | 10ab8bb | 2016-07-01 12:20:20 -0700 | [diff] [blame] | 59 | explicit Node(Script *); |
Jason Sams | dbe66d6 | 2012-09-17 13:54:41 -0700 | [diff] [blame] | 60 | |
Yang Ni | b8353c5 | 2015-02-14 18:00:59 -0800 | [diff] [blame] | 61 | Vector<const ScriptKernelID *> mKernels; |
| 62 | Vector<Link *> mOutputs; |
| 63 | Vector<Link *> mInputs; |
Jason Sams | dbe66d6 | 2012-09-17 13:54:41 -0700 | [diff] [blame] | 64 | bool mSeen; |
| 65 | int mOrder; |
| 66 | Script *mScript; |
| 67 | }; |
| 68 | |
| 69 | class IO { |
| 70 | public: |
Chih-Hung Hsieh | 10ab8bb | 2016-07-01 12:20:20 -0700 | [diff] [blame] | 71 | explicit IO(const ScriptKernelID *); |
Jason Sams | dbe66d6 | 2012-09-17 13:54:41 -0700 | [diff] [blame] | 72 | |
| 73 | const ScriptKernelID *mKernel; |
| 74 | ObjectBaseRef<Allocation> mAlloc; |
| 75 | }; |
| 76 | |
Yang Ni | b8353c5 | 2015-02-14 18:00:59 -0800 | [diff] [blame] | 77 | Vector<Link *> mLinks; |
| 78 | Vector<Node *> mNodes; |
| 79 | Vector<IO *> mInputs; |
| 80 | Vector<IO *> mOutputs; |
Jason Sams | dbe66d6 | 2012-09-17 13:54:41 -0700 | [diff] [blame] | 81 | |
Jason Sams | dbe66d6 | 2012-09-17 13:54:41 -0700 | [diff] [blame] | 82 | static ScriptGroup * create(Context *rsc, |
| 83 | ScriptKernelID ** kernels, size_t kernelsSize, |
| 84 | ScriptKernelID ** src, size_t srcSize, |
| 85 | ScriptKernelID ** dstK, size_t dstKSize, |
| 86 | ScriptFieldID ** dstF, size_t dstFSize, |
| 87 | const Type ** type, size_t typeSize); |
| 88 | |
Jason Sams | dbe66d6 | 2012-09-17 13:54:41 -0700 | [diff] [blame] | 89 | void setInput(Context *rsc, ScriptKernelID *kid, Allocation *a); |
| 90 | void setOutput(Context *rsc, ScriptKernelID *kid, Allocation *a); |
| 91 | |
Jason Sams | dbe66d6 | 2012-09-17 13:54:41 -0700 | [diff] [blame] | 92 | protected: |
| 93 | virtual ~ScriptGroup(); |
| 94 | bool mInitialized; |
| 95 | |
| 96 | |
| 97 | private: |
| 98 | bool calcOrderRecurse(Node *n, int depth); |
| 99 | bool calcOrder(); |
| 100 | Node * findNode(Script *s) const; |
Yang Ni | 5f6f16f | 2014-07-25 13:51:09 -0700 | [diff] [blame] | 101 | // Check if input/output Allocations are correctly set for a ScriptGroup. |
| 102 | // Send any error back to the client (app). Called before the ScriptGroup |
| 103 | // executes. Skips the exeuction if validation fails. |
| 104 | bool validateInputAndOutput(Context *); |
Jason Sams | dbe66d6 | 2012-09-17 13:54:41 -0700 | [diff] [blame] | 105 | |
Chih-Hung Hsieh | 10ab8bb | 2016-07-01 12:20:20 -0700 | [diff] [blame] | 106 | explicit ScriptGroup(Context *); |
Jason Sams | dbe66d6 | 2012-09-17 13:54:41 -0700 | [diff] [blame] | 107 | }; |
| 108 | |
| 109 | |
Rahul Chaudhry | 7974fc0 | 2017-02-09 12:33:28 -0800 | [diff] [blame] | 110 | } // namespace renderscript |
| 111 | } // namespace android |
Jason Sams | dbe66d6 | 2012-09-17 13:54:41 -0700 | [diff] [blame] | 112 | #endif |
Yang Ni | b8353c5 | 2015-02-14 18:00:59 -0800 | [diff] [blame] | 113 | |