rsScriptGroup.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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. #ifndef ANDROID_RS_SCRIPT_GROUP_H
  17. #define ANDROID_RS_SCRIPT_GROUP_H
  18. #include "rsScriptGroupBase.h"
  19. #include <vector>
  20. // ---------------------------------------------------------------------------
  21. namespace android {
  22. namespace renderscript {
  23. class Allocation;
  24. class Context;
  25. class ProgramVertex;
  26. class ProgramFragment;
  27. class ProgramRaster;
  28. class ProgramStore;
  29. class Script;
  30. class ScriptFieldID;
  31. class ScriptKernelID;
  32. class Type;
  33. class ScriptGroup : public ScriptGroupBase {
  34. public:
  35. virtual SG_API_Version getApiVersion() const { return SG_V1; }
  36. virtual void execute(Context *rsc);
  37. std::vector<ObjectBaseRef<ScriptKernelID> > mKernels;
  38. class Link {
  39. public:
  40. ObjectBaseRef<const ScriptKernelID> mSource;
  41. ObjectBaseRef<const ScriptKernelID> mDstKernel;
  42. ObjectBaseRef<const ScriptFieldID> mDstField;
  43. ObjectBaseRef<const Type> mType;
  44. ObjectBaseRef<Allocation> mAlloc;
  45. Link();
  46. ~Link();
  47. };
  48. class Node {
  49. public:
  50. explicit Node(Script *);
  51. std::vector<const ScriptKernelID *> mKernels;
  52. std::vector<Link *> mOutputs;
  53. std::vector<Link *> mInputs;
  54. bool mSeen;
  55. int mOrder;
  56. Script *mScript;
  57. };
  58. class IO {
  59. public:
  60. explicit IO(const ScriptKernelID *);
  61. const ScriptKernelID *mKernel;
  62. ObjectBaseRef<Allocation> mAlloc;
  63. };
  64. std::vector<Link *> mLinks;
  65. std::vector<Node *> mNodes;
  66. std::vector<IO *> mInputs;
  67. std::vector<IO *> mOutputs;
  68. static ScriptGroup * create(Context *rsc,
  69. ScriptKernelID ** kernels, size_t kernelsSize,
  70. ScriptKernelID ** src, size_t srcSize,
  71. ScriptKernelID ** dstK, size_t dstKSize,
  72. ScriptFieldID ** dstF, size_t dstFSize,
  73. const Type ** type, size_t typeSize);
  74. void setInput(Context *rsc, ScriptKernelID *kid, Allocation *a);
  75. void setOutput(Context *rsc, ScriptKernelID *kid, Allocation *a);
  76. protected:
  77. virtual ~ScriptGroup();
  78. bool mInitialized;
  79. private:
  80. bool calcOrderRecurse(Node *n, int depth);
  81. bool calcOrder();
  82. Node * findNode(Script *s) const;
  83. // Check if input/output Allocations are correctly set for a ScriptGroup.
  84. // Send any error back to the client (app). Called before the ScriptGroup
  85. // executes. Skips the exeuction if validation fails.
  86. bool validateInputAndOutput(Context *);
  87. explicit ScriptGroup(Context *);
  88. };
  89. } // namespace renderscript
  90. } // namespace android
  91. #endif