GrPipeline.cpp 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. /*
  2. * Copyright 2015 Google Inc.
  3. *
  4. * Use of this source code is governed by a BSD-style license that can be
  5. * found in the LICENSE file.
  6. */
  7. #include "src/gpu/GrPipeline.h"
  8. #include "src/gpu/GrAppliedClip.h"
  9. #include "src/gpu/GrCaps.h"
  10. #include "src/gpu/GrGpu.h"
  11. #include "src/gpu/GrRenderTargetContext.h"
  12. #include "src/gpu/GrRenderTargetOpList.h"
  13. #include "src/gpu/GrXferProcessor.h"
  14. #include "src/gpu/ops/GrOp.h"
  15. GrPipeline::GrPipeline(const InitArgs& args,
  16. GrProcessorSet&& processors,
  17. GrAppliedClip&& appliedClip)
  18. : fOutputSwizzle(args.fOutputSwizzle) {
  19. SkASSERT(processors.isFinalized());
  20. fFlags = (Flags)args.fInputFlags;
  21. if (appliedClip.hasStencilClip()) {
  22. fFlags |= Flags::kHasStencilClip;
  23. }
  24. if (appliedClip.scissorState().enabled()) {
  25. fFlags |= Flags::kScissorEnabled;
  26. }
  27. fWindowRectsState = appliedClip.windowRectsState();
  28. if (!args.fUserStencil->isDisabled(fFlags & Flags::kHasStencilClip)) {
  29. fFlags |= Flags::kStencilEnabled;
  30. }
  31. fUserStencilSettings = args.fUserStencil;
  32. fXferProcessor = processors.refXferProcessor();
  33. if (args.fDstProxy.proxy()) {
  34. SkASSERT(args.fDstProxy.proxy()->isInstantiated());
  35. fDstTextureProxy.reset(args.fDstProxy.proxy());
  36. fDstTextureOffset = args.fDstProxy.offset();
  37. }
  38. // Copy GrFragmentProcessors from GrProcessorSet to Pipeline
  39. fNumColorProcessors = processors.numColorFragmentProcessors();
  40. int numTotalProcessors = fNumColorProcessors +
  41. processors.numCoverageFragmentProcessors() +
  42. appliedClip.numClipCoverageFragmentProcessors();
  43. fFragmentProcessors.reset(numTotalProcessors);
  44. int currFPIdx = 0;
  45. for (int i = 0; i < processors.numColorFragmentProcessors(); ++i, ++currFPIdx) {
  46. fFragmentProcessors[currFPIdx] = processors.detachColorFragmentProcessor(i);
  47. }
  48. for (int i = 0; i < processors.numCoverageFragmentProcessors(); ++i, ++currFPIdx) {
  49. fFragmentProcessors[currFPIdx] = processors.detachCoverageFragmentProcessor(i);
  50. }
  51. for (int i = 0; i < appliedClip.numClipCoverageFragmentProcessors(); ++i, ++currFPIdx) {
  52. fFragmentProcessors[currFPIdx] = appliedClip.detachClipCoverageFragmentProcessor(i);
  53. }
  54. #ifdef SK_DEBUG
  55. for (int i = 0; i < numTotalProcessors; ++i) {
  56. if (!fFragmentProcessors[i]->isInstantiated()) {
  57. this->markAsBad();
  58. break;
  59. }
  60. }
  61. #endif
  62. }
  63. void GrPipeline::addDependenciesTo(GrOpList* opList, const GrCaps& caps) const {
  64. for (int i = 0; i < fFragmentProcessors.count(); ++i) {
  65. GrFragmentProcessor::TextureAccessIter iter(fFragmentProcessors[i].get());
  66. while (const GrFragmentProcessor::TextureSampler* sampler = iter.next()) {
  67. opList->addDependency(sampler->proxy(), caps);
  68. }
  69. }
  70. if (fDstTextureProxy) {
  71. opList->addDependency(fDstTextureProxy.get(), caps);
  72. }
  73. }
  74. GrXferBarrierType GrPipeline::xferBarrierType(GrTexture* texture, const GrCaps& caps) const {
  75. if (fDstTextureProxy.get() && fDstTextureProxy.get()->peekTexture() == texture) {
  76. return kTexture_GrXferBarrierType;
  77. }
  78. return this->getXferProcessor().xferBarrierType(caps);
  79. }
  80. GrPipeline::GrPipeline(GrScissorTest scissorTest, sk_sp<const GrXferProcessor> xp,
  81. const GrSwizzle& outputSwizzle, InputFlags inputFlags,
  82. const GrUserStencilSettings* userStencil)
  83. : fWindowRectsState()
  84. , fUserStencilSettings(userStencil)
  85. , fFlags((Flags)inputFlags)
  86. , fXferProcessor(std::move(xp))
  87. , fFragmentProcessors()
  88. , fNumColorProcessors(0)
  89. , fOutputSwizzle(outputSwizzle) {
  90. if (GrScissorTest::kEnabled == scissorTest) {
  91. fFlags |= Flags::kScissorEnabled;
  92. }
  93. if (!userStencil->isDisabled(false)) {
  94. fFlags |= Flags::kStencilEnabled;
  95. }
  96. }
  97. uint32_t GrPipeline::getBlendInfoKey() const {
  98. const GrXferProcessor::BlendInfo& blendInfo = this->getXferProcessor().getBlendInfo();
  99. static const uint32_t kBlendWriteShift = 1;
  100. static const uint32_t kBlendCoeffShift = 5;
  101. GR_STATIC_ASSERT(kLast_GrBlendCoeff < (1 << kBlendCoeffShift));
  102. GR_STATIC_ASSERT(kFirstAdvancedGrBlendEquation - 1 < 4);
  103. uint32_t key = blendInfo.fWriteColor;
  104. key |= (blendInfo.fSrcBlend << kBlendWriteShift);
  105. key |= (blendInfo.fDstBlend << (kBlendWriteShift + kBlendCoeffShift));
  106. key |= (blendInfo.fEquation << (kBlendWriteShift + 2 * kBlendCoeffShift));
  107. return key;
  108. }