| 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 "GrProcOptInfo.h" |
| 9 #include "gl/GrGLCaps.h" | 10 #include "gl/GrGLCaps.h" |
| 10 | 11 |
| 11 GrXferProcessor::GrXferProcessor() | 12 GrXferProcessor::GrXferProcessor() |
| 12 : fWillReadDstColor(false), fReadsCoverage(true), fDstTextureOffset() { | 13 : fWillReadDstColor(false), fReadsCoverage(true), fDstTextureOffset() { |
| 13 } | 14 } |
| 14 | 15 |
| 15 GrXferProcessor::GrXferProcessor(const DstTexture* dstTexture, bool willReadDstC
olor) | 16 GrXferProcessor::GrXferProcessor(const DstTexture* dstTexture, bool willReadDstC
olor) |
| 16 : fWillReadDstColor(willReadDstColor) | 17 : fWillReadDstColor(willReadDstColor) |
| 17 , fReadsCoverage(true) | 18 , fReadsCoverage(true) |
| 18 , fDstTextureOffset() { | 19 , fDstTextureOffset() { |
| 19 if (dstTexture && dstTexture->texture()) { | 20 if (dstTexture && dstTexture->texture()) { |
| 21 SkASSERT(willReadDstColor); |
| 20 fDstTexture.reset(dstTexture->texture()); | 22 fDstTexture.reset(dstTexture->texture()); |
| 21 fDstTextureOffset = dstTexture->offset(); | 23 fDstTextureOffset = dstTexture->offset(); |
| 22 this->addTextureAccess(&fDstTexture); | 24 this->addTextureAccess(&fDstTexture); |
| 23 this->setWillReadFragmentPosition(); | 25 this->setWillReadFragmentPosition(); |
| 24 } | 26 } |
| 25 } | 27 } |
| 26 | 28 |
| 27 GrXferProcessor::OptFlags GrXferProcessor::getOptimizations(const GrProcOptInfo&
colorPOI, | 29 GrXferProcessor::OptFlags GrXferProcessor::getOptimizations(const GrProcOptInfo&
colorPOI, |
| 28 const GrProcOptInfo&
coveragePOI, | 30 const GrProcOptInfo&
coveragePOI, |
| 29 bool doesStencilWrit
e, | 31 bool doesStencilWrit
e, |
| 30 GrColor* overrideCol
or, | 32 GrColor* overrideCol
or, |
| 31 const GrCaps& caps)
{ | 33 const GrCaps& caps)
{ |
| 32 GrXferProcessor::OptFlags flags = this->onGetOptimizations(colorPOI, | 34 GrXferProcessor::OptFlags flags = this->onGetOptimizations(colorPOI, |
| 33 coveragePOI, | 35 coveragePOI, |
| 34 doesStencilWrite, | 36 doesStencilWrite, |
| 35 overrideColor, | 37 overrideColor, |
| 36 caps); | 38 caps); |
| 37 | 39 |
| 40 if (this->willReadDstColor()) { |
| 41 // When performing a dst read we handle coverage in the base class. |
| 42 SkASSERT(!(flags & GrXferProcessor::kIgnoreCoverage_OptFlag)); |
| 43 if (coveragePOI.isSolidWhite()) { |
| 44 flags |= GrXferProcessor::kIgnoreCoverage_OptFlag; |
| 45 } |
| 46 } |
| 38 if (flags & GrXferProcessor::kIgnoreCoverage_OptFlag) { | 47 if (flags & GrXferProcessor::kIgnoreCoverage_OptFlag) { |
| 39 fReadsCoverage = false; | 48 fReadsCoverage = false; |
| 40 } | 49 } |
| 41 return flags; | 50 return flags; |
| 42 } | 51 } |
| 43 | 52 |
| 53 bool GrXferProcessor::hasSecondaryOutput() const { |
| 54 if (!this->willReadDstColor()) { |
| 55 return this->onHasSecondaryOutput(); |
| 56 } |
| 57 return false; |
| 58 } |
| 59 |
| 60 void GrXferProcessor::getBlendInfo(BlendInfo* blendInfo) const { |
| 61 blendInfo->reset(); |
| 62 if (!this->willReadDstColor()) { |
| 63 this->onGetBlendInfo(blendInfo); |
| 64 } |
| 65 } |
| 66 |
| 44 void GrXferProcessor::getGLProcessorKey(const GrGLSLCaps& caps, GrProcessorKeyBu
ilder* b) const { | 67 void GrXferProcessor::getGLProcessorKey(const GrGLSLCaps& caps, GrProcessorKeyBu
ilder* b) const { |
| 45 uint32_t key = this->willReadDstColor() ? 0x1 : 0x0; | 68 uint32_t key = this->willReadDstColor() ? 0x1 : 0x0; |
| 46 if (this->getDstTexture() && | 69 if (key) { |
| 47 kTopLeft_GrSurfaceOrigin == this->getDstTexture()->origin()) { | 70 if (this->getDstTexture()) { |
| 48 key |= 0x2; | 71 key |= 0x2; |
| 72 } |
| 73 if (kTopLeft_GrSurfaceOrigin == this->getDstTexture()->origin()) { |
| 74 key |= 0x4; |
| 75 } |
| 76 if (this->readsCoverage()) { |
| 77 key |= 0x8; |
| 78 } |
| 49 } | 79 } |
| 50 b->add32(key); | 80 b->add32(key); |
| 51 this->onGetGLProcessorKey(caps, b); | 81 this->onGetGLProcessorKey(caps, b); |
| 52 } | 82 } |
| 53 | 83 |
| 54 bool GrXferProcessor::willNeedXferBarrier(const GrRenderTarget* rt, | 84 bool GrXferProcessor::willNeedXferBarrier(const GrRenderTarget* rt, |
| 55 const GrCaps& caps, | 85 const GrCaps& caps, |
| 56 GrXferBarrierType* outBarrierType) con
st { | 86 GrXferBarrierType* outBarrierType) con
st { |
| 57 if (static_cast<const GrSurface*>(rt) == this->getDstTexture()) { | 87 if (static_cast<const GrSurface*>(rt) == this->getDstTexture()) { |
| 58 // Texture barriers are required when a shader reads and renders to the
same texture. | 88 // Texture barriers are required when a shader reads and renders to the
same texture. |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 176 } | 206 } |
| 177 #endif | 207 #endif |
| 178 return this->onCreateXferProcessor(caps, colorPOI, coveragePOI, dstTexture); | 208 return this->onCreateXferProcessor(caps, colorPOI, coveragePOI, dstTexture); |
| 179 } | 209 } |
| 180 | 210 |
| 181 bool GrXPFactory::willNeedDstTexture(const GrCaps& caps, const GrProcOptInfo& co
lorPOI, | 211 bool GrXPFactory::willNeedDstTexture(const GrCaps& caps, const GrProcOptInfo& co
lorPOI, |
| 182 const GrProcOptInfo& coveragePOI) const { | 212 const GrProcOptInfo& coveragePOI) const { |
| 183 return (this->willReadDstColor(caps, colorPOI, coveragePOI) | 213 return (this->willReadDstColor(caps, colorPOI, coveragePOI) |
| 184 && !caps.shaderCaps()->dstReadInShaderSupport()); | 214 && !caps.shaderCaps()->dstReadInShaderSupport()); |
| 185 } | 215 } |
| OLD | NEW |