| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2015 Google Inc. | 2 * Copyright 2015 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 #include "GrXferProcessor.h" | 8 #include "GrXferProcessor.h" |
| 9 #include "GrPipelineBuilder.h" | 9 #include "GrPipelineBuilder.h" |
| 10 #include "GrProcOptInfo.h" | 10 #include "GrProcOptInfo.h" |
| 11 #include "gl/GrGLCaps.h" | 11 #include "gl/GrGLCaps.h" |
| 12 | 12 |
| 13 GrXferProcessor::GrXferProcessor() | 13 GrXferProcessor::GrXferProcessor() |
| 14 : fWillReadDstColor(false) | 14 : fWillReadDstColor(false) |
| 15 , fDstReadUsesMixedSamples(false) | 15 , fDstReadUsesMixedSamples(false) |
| 16 , fReadsCoverage(true) | |
| 17 , fDstTextureOffset() { | 16 , fDstTextureOffset() { |
| 18 } | 17 } |
| 19 | 18 |
| 20 GrXferProcessor::GrXferProcessor(const DstTexture* dstTexture, | 19 GrXferProcessor::GrXferProcessor(const DstTexture* dstTexture, |
| 21 bool willReadDstColor, | 20 bool willReadDstColor, |
| 22 bool hasMixedSamples) | 21 bool hasMixedSamples) |
| 23 : fWillReadDstColor(willReadDstColor) | 22 : fWillReadDstColor(willReadDstColor) |
| 24 , fDstReadUsesMixedSamples(willReadDstColor && hasMixedSamples) | 23 , fDstReadUsesMixedSamples(willReadDstColor && hasMixedSamples) |
| 25 , fReadsCoverage(true) | |
| 26 , fDstTextureOffset() { | 24 , fDstTextureOffset() { |
| 27 if (dstTexture && dstTexture->texture()) { | 25 if (dstTexture && dstTexture->texture()) { |
| 28 SkASSERT(willReadDstColor); | 26 SkASSERT(willReadDstColor); |
| 29 fDstTexture.reset(dstTexture->texture()); | 27 fDstTexture.reset(dstTexture->texture()); |
| 30 fDstTextureOffset = dstTexture->offset(); | 28 fDstTextureOffset = dstTexture->offset(); |
| 31 this->addTextureAccess(&fDstTexture); | 29 this->addTextureAccess(&fDstTexture); |
| 32 this->setWillReadFragmentPosition(); | 30 this->setWillReadFragmentPosition(); |
| 33 } | 31 } |
| 34 } | 32 } |
| 35 | 33 |
| 36 GrXferProcessor::OptFlags GrXferProcessor::getOptimizations(const GrProcOptInfo&
colorPOI, | 34 GrXferProcessor::OptFlags GrXferProcessor::getOptimizations(const GrProcOptInfo&
colorPOI, |
| 37 const GrProcOptInfo&
coveragePOI, | 35 const GrProcOptInfo&
coveragePOI, |
| 38 bool doesStencilWrit
e, | 36 bool doesStencilWrit
e, |
| 39 GrColor* overrideCol
or, | 37 GrColor* overrideCol
or, |
| 40 const GrCaps& caps)
{ | 38 const GrCaps& caps)
const { |
| 41 GrXferProcessor::OptFlags flags = this->onGetOptimizations(colorPOI, | 39 GrXferProcessor::OptFlags flags = this->onGetOptimizations(colorPOI, |
| 42 coveragePOI, | 40 coveragePOI, |
| 43 doesStencilWrite, | 41 doesStencilWrite, |
| 44 overrideColor, | 42 overrideColor, |
| 45 caps); | 43 caps); |
| 46 | 44 |
| 47 if (this->willReadDstColor()) { | 45 if (this->willReadDstColor()) { |
| 48 // When performing a dst read we handle coverage in the base class. | 46 // When performing a dst read we handle coverage in the base class. |
| 49 SkASSERT(!(flags & GrXferProcessor::kIgnoreCoverage_OptFlag)); | 47 SkASSERT(!(flags & GrXferProcessor::kIgnoreCoverage_OptFlag)); |
| 50 if (coveragePOI.isSolidWhite()) { | 48 if (coveragePOI.isSolidWhite()) { |
| 51 flags |= GrXferProcessor::kIgnoreCoverage_OptFlag; | 49 flags |= GrXferProcessor::kIgnoreCoverage_OptFlag; |
| 52 } | 50 } |
| 53 } | 51 } |
| 54 if (flags & GrXferProcessor::kIgnoreCoverage_OptFlag) { | |
| 55 fReadsCoverage = false; | |
| 56 } | |
| 57 return flags; | 52 return flags; |
| 58 } | 53 } |
| 59 | 54 |
| 60 bool GrXferProcessor::hasSecondaryOutput() const { | 55 bool GrXferProcessor::hasSecondaryOutput() const { |
| 61 if (!this->willReadDstColor()) { | 56 if (!this->willReadDstColor()) { |
| 62 return this->onHasSecondaryOutput(); | 57 return this->onHasSecondaryOutput(); |
| 63 } | 58 } |
| 64 return this->dstReadUsesMixedSamples(); | 59 return this->dstReadUsesMixedSamples(); |
| 65 } | 60 } |
| 66 | 61 |
| 67 void GrXferProcessor::getBlendInfo(BlendInfo* blendInfo) const { | 62 void GrXferProcessor::getBlendInfo(BlendInfo* blendInfo) const { |
| 68 blendInfo->reset(); | 63 blendInfo->reset(); |
| 69 if (!this->willReadDstColor()) { | 64 if (!this->willReadDstColor()) { |
| 70 this->onGetBlendInfo(blendInfo); | 65 this->onGetBlendInfo(blendInfo); |
| 71 } else if (this->dstReadUsesMixedSamples()) { | 66 } else if (this->dstReadUsesMixedSamples()) { |
| 72 blendInfo->fDstBlend = kIS2A_GrBlendCoeff; | 67 blendInfo->fDstBlend = kIS2A_GrBlendCoeff; |
| 73 } | 68 } |
| 74 } | 69 } |
| 75 | 70 |
| 76 void GrXferProcessor::getGLSLProcessorKey(const GrGLSLCaps& caps, GrProcessorKey
Builder* b) const { | 71 void GrXferProcessor::getGLSLProcessorKey(const GrGLSLCaps& caps, GrProcessorKey
Builder* b) const { |
| 77 uint32_t key = this->willReadDstColor() ? 0x1 : 0x0; | 72 uint32_t key = this->willReadDstColor() ? 0x1 : 0x0; |
| 78 if (key) { | 73 if (key) { |
| 79 if (const GrTexture* dstTexture = this->getDstTexture()) { | 74 if (const GrTexture* dstTexture = this->getDstTexture()) { |
| 80 key |= 0x2; | 75 key |= 0x2; |
| 81 if (kTopLeft_GrSurfaceOrigin == dstTexture->origin()) { | 76 if (kTopLeft_GrSurfaceOrigin == dstTexture->origin()) { |
| 82 key |= 0x4; | 77 key |= 0x4; |
| 83 } | 78 } |
| 84 } | 79 } |
| 85 if (this->readsCoverage()) { | 80 if (this->dstReadUsesMixedSamples()) { |
| 86 key |= 0x8; | 81 key |= 0x8; |
| 87 } | 82 } |
| 88 if (this->dstReadUsesMixedSamples()) { | |
| 89 key |= 0x10; | |
| 90 } | |
| 91 } | 83 } |
| 92 b->add32(key); | 84 b->add32(key); |
| 93 this->onGetGLSLProcessorKey(caps, b); | 85 this->onGetGLSLProcessorKey(caps, b); |
| 94 } | 86 } |
| 95 | 87 |
| 96 GrXferBarrierType GrXferProcessor::xferBarrierType(const GrRenderTarget* rt, | 88 GrXferBarrierType GrXferProcessor::xferBarrierType(const GrRenderTarget* rt, |
| 97 const GrCaps& caps) const { | 89 const GrCaps& caps) const { |
| 98 SkASSERT(rt); | 90 SkASSERT(rt); |
| 99 if (static_cast<const GrSurface*>(rt) == this->getDstTexture()) { | 91 if (static_cast<const GrSurface*>(rt) == this->getDstTexture()) { |
| 100 // Texture barriers are required when a shader reads and renders to the
same texture. | 92 // Texture barriers are required when a shader reads and renders to the
same texture. |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 220 return this->onCreateXferProcessor(caps, colorPOI, coveragePOI, hasMixedSamp
les, dstTexture); | 212 return this->onCreateXferProcessor(caps, colorPOI, coveragePOI, hasMixedSamp
les, dstTexture); |
| 221 } | 213 } |
| 222 | 214 |
| 223 bool GrXPFactory::willNeedDstTexture(const GrCaps& caps, | 215 bool GrXPFactory::willNeedDstTexture(const GrCaps& caps, |
| 224 const GrProcOptInfo& colorPOI, | 216 const GrProcOptInfo& colorPOI, |
| 225 const GrProcOptInfo& coveragePOI, | 217 const GrProcOptInfo& coveragePOI, |
| 226 bool hasMixedSamples) const { | 218 bool hasMixedSamples) const { |
| 227 return (this->willReadDstColor(caps, colorPOI, coveragePOI, hasMixedSamples)
&& | 219 return (this->willReadDstColor(caps, colorPOI, coveragePOI, hasMixedSamples)
&& |
| 228 !caps.shaderCaps()->dstReadInShaderSupport()); | 220 !caps.shaderCaps()->dstReadInShaderSupport()); |
| 229 } | 221 } |
| OLD | NEW |