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 20#include "rsScriptGroupBase.h" 21 22#include <vector> 23 24// --------------------------------------------------------------------------- 25namespace android { 26namespace renderscript { 27 28class Allocation; 29class Context; 30class ProgramVertex; 31class ProgramFragment; 32class ProgramRaster; 33class ProgramStore; 34class Script; 35class ScriptFieldID; 36class ScriptKernelID; 37class Type; 38 39class ScriptGroup : public ScriptGroupBase { 40public: 41 virtual SG_API_Version getApiVersion() const { return SG_V1; } 42 virtual void execute(Context *rsc); 43 44 Vector<ObjectBaseRef<ScriptKernelID> > mKernels; 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: 59 Node(Script *); 60 61 Vector<const ScriptKernelID *> mKernels; 62 Vector<Link *> mOutputs; 63 Vector<Link *> mInputs; 64 bool mSeen; 65 int mOrder; 66 Script *mScript; 67 }; 68 69 class IO { 70 public: 71 IO(const ScriptKernelID *); 72 73 const ScriptKernelID *mKernel; 74 ObjectBaseRef<Allocation> mAlloc; 75 }; 76 77 Vector<Link *> mLinks; 78 Vector<Node *> mNodes; 79 Vector<IO *> mInputs; 80 Vector<IO *> mOutputs; 81 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 89 void setInput(Context *rsc, ScriptKernelID *kid, Allocation *a); 90 void setOutput(Context *rsc, ScriptKernelID *kid, Allocation *a); 91 92protected: 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; 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 *); 105 106 ScriptGroup(Context *); 107}; 108 109 110} 111} 112#endif 113 114