blob: 76c2a60cddb11f70f27e9adad34833f7e1fea8d7 [file] [log] [blame]
Jason Samsdbe66d62012-09-17 13:54:41 -07001/*
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 Ni1ffd86b2015-01-07 09:16:40 -080020#include "rsScriptGroupBase.h"
Jason Samsdbe66d62012-09-17 13:54:41 -070021
Yang Ni1ffd86b2015-01-07 09:16:40 -080022#include <vector>
Jason Samsdbe66d62012-09-17 13:54:41 -070023
24// ---------------------------------------------------------------------------
25namespace android {
26namespace renderscript {
27
Yang Ni1ffd86b2015-01-07 09:16:40 -080028class Allocation;
29class Context;
Jason Samsdbe66d62012-09-17 13:54:41 -070030class ProgramVertex;
31class ProgramFragment;
32class ProgramRaster;
33class ProgramStore;
Yang Ni1ffd86b2015-01-07 09:16:40 -080034class Script;
35class ScriptFieldID;
36class ScriptKernelID;
37class Type;
Jason Samsdbe66d62012-09-17 13:54:41 -070038
Yang Ni1ffd86b2015-01-07 09:16:40 -080039class ScriptGroup : public ScriptGroupBase {
Jason Samsdbe66d62012-09-17 13:54:41 -070040public:
Yang Ni1ffd86b2015-01-07 09:16:40 -080041 virtual SG_API_Version getApiVersion() const { return SG_V1; }
42 virtual void execute(Context *rsc);
43
Miao Wang82e135c2017-02-27 23:35:35 -080044 std::vector<ObjectBaseRef<ScriptKernelID> > mKernels;
Jason Samsdbe66d62012-09-17 13:54:41 -070045
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 Hsieh10ab8bb2016-07-01 12:20:20 -070059 explicit Node(Script *);
Jason Samsdbe66d62012-09-17 13:54:41 -070060
Miao Wang82e135c2017-02-27 23:35:35 -080061 std::vector<const ScriptKernelID *> mKernels;
62 std::vector<Link *> mOutputs;
63 std::vector<Link *> mInputs;
Jason Samsdbe66d62012-09-17 13:54:41 -070064 bool mSeen;
65 int mOrder;
66 Script *mScript;
67 };
68
69 class IO {
70 public:
Chih-Hung Hsieh10ab8bb2016-07-01 12:20:20 -070071 explicit IO(const ScriptKernelID *);
Jason Samsdbe66d62012-09-17 13:54:41 -070072
73 const ScriptKernelID *mKernel;
74 ObjectBaseRef<Allocation> mAlloc;
75 };
76
Miao Wang82e135c2017-02-27 23:35:35 -080077 std::vector<Link *> mLinks;
78 std::vector<Node *> mNodes;
79 std::vector<IO *> mInputs;
80 std::vector<IO *> mOutputs;
Jason Samsdbe66d62012-09-17 13:54:41 -070081
Jason Samsdbe66d62012-09-17 13:54:41 -070082 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 Samsdbe66d62012-09-17 13:54:41 -070089 void setInput(Context *rsc, ScriptKernelID *kid, Allocation *a);
90 void setOutput(Context *rsc, ScriptKernelID *kid, Allocation *a);
91
Jason Samsdbe66d62012-09-17 13:54:41 -070092protected:
93 virtual ~ScriptGroup();
94 bool mInitialized;
95
96
97private:
98 bool calcOrderRecurse(Node *n, int depth);
99 bool calcOrder();
100 Node * findNode(Script *s) const;
Yang Ni5f6f16f2014-07-25 13:51:09 -0700101 // 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 Samsdbe66d62012-09-17 13:54:41 -0700105
Chih-Hung Hsieh10ab8bb2016-07-01 12:20:20 -0700106 explicit ScriptGroup(Context *);
Jason Samsdbe66d62012-09-17 13:54:41 -0700107};
108
109
Rahul Chaudhry7974fc02017-02-09 12:33:28 -0800110} // namespace renderscript
111} // namespace android
Jason Samsdbe66d62012-09-17 13:54:41 -0700112#endif
Yang Nib8353c52015-02-14 18:00:59 -0800113