| 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 "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) |
| 14 , fDstReadUsesMixedSamples(false) |
| 15 , fReadsCoverage(true) |
| 16 , fDstTextureOffset() { |
| 13 } | 17 } |
| 14 | 18 |
| 15 GrXferProcessor::GrXferProcessor(const DstTexture* dstTexture, bool willReadDstC
olor) | 19 GrXferProcessor::GrXferProcessor(const GrPipelineBuilder& builder, |
| 20 const DstTexture* dstTexture, |
| 21 bool willReadDstColor) |
| 16 : fWillReadDstColor(willReadDstColor) | 22 : fWillReadDstColor(willReadDstColor) |
| 23 , fDstReadUsesMixedSamples(willReadDstColor && builder.hasMixedSamples()) |
| 17 , fReadsCoverage(true) | 24 , fReadsCoverage(true) |
| 18 , fDstTextureOffset() { | 25 , fDstTextureOffset() { |
| 19 if (dstTexture && dstTexture->texture()) { | 26 if (dstTexture && dstTexture->texture()) { |
| 27 SkASSERT(willReadDstColor); |
| 20 fDstTexture.reset(dstTexture->texture()); | 28 fDstTexture.reset(dstTexture->texture()); |
| 21 fDstTextureOffset = dstTexture->offset(); | 29 fDstTextureOffset = dstTexture->offset(); |
| 22 this->addTextureAccess(&fDstTexture); | 30 this->addTextureAccess(&fDstTexture); |
| 23 this->setWillReadFragmentPosition(); | 31 this->setWillReadFragmentPosition(); |
| 24 } | 32 } |
| 25 } | 33 } |
| 26 | 34 |
| 27 GrXferProcessor::OptFlags GrXferProcessor::getOptimizations(const GrProcOptInfo&
colorPOI, | 35 GrXferProcessor::OptFlags GrXferProcessor::getOptimizations(const GrProcOptInfo&
colorPOI, |
| 28 const GrProcOptInfo&
coveragePOI, | 36 const GrProcOptInfo&
coveragePOI, |
| 29 bool doesStencilWrit
e, | 37 bool doesStencilWrit
e, |
| 30 GrColor* overrideCol
or, | 38 GrColor* overrideCol
or, |
| 31 const GrCaps& caps)
{ | 39 const GrCaps& caps)
{ |
| 32 GrXferProcessor::OptFlags flags = this->onGetOptimizations(colorPOI, | 40 GrXferProcessor::OptFlags flags = this->onGetOptimizations(colorPOI, |
| 33 coveragePOI, | 41 coveragePOI, |
| 34 doesStencilWrite, | 42 doesStencilWrite, |
| 35 overrideColor, | 43 overrideColor, |
| 36 caps); | 44 caps); |
| 37 | 45 |
| 38 if (flags & GrXferProcessor::kIgnoreCoverage_OptFlag) { | 46 if (flags & GrXferProcessor::kIgnoreCoverage_OptFlag) { |
| 39 fReadsCoverage = false; | 47 fReadsCoverage = false; |
| 40 } | 48 } |
| 41 return flags; | 49 return flags; |
| 42 } | 50 } |
| 43 | 51 |
| 52 bool GrXferProcessor::hasSecondaryOutput() const { |
| 53 if (!this->willReadDstColor()) { |
| 54 return this->onHasSecondaryOutput(); |
| 55 } |
| 56 return this->dstReadUsesMixedSamples(); |
| 57 } |
| 58 |
| 59 void GrXferProcessor::getBlendInfo(BlendInfo* blendInfo) const { |
| 60 blendInfo->reset(); |
| 61 if (!this->willReadDstColor()) { |
| 62 this->onGetBlendInfo(blendInfo); |
| 63 } else if (this->dstReadUsesMixedSamples()) { |
| 64 blendInfo->fDstBlend = kIS2A_GrBlendCoeff; |
| 65 } |
| 66 } |
| 67 |
| 44 void GrXferProcessor::getGLProcessorKey(const GrGLSLCaps& caps, GrProcessorKeyBu
ilder* b) const { | 68 void GrXferProcessor::getGLProcessorKey(const GrGLSLCaps& caps, GrProcessorKeyBu
ilder* b) const { |
| 45 uint32_t key = this->willReadDstColor() ? 0x1 : 0x0; | 69 uint32_t key = this->willReadDstColor() ? 0x1 : 0x0; |
| 46 if (this->getDstTexture() && | 70 if (this->getDstTexture() && |
| 47 kTopLeft_GrSurfaceOrigin == this->getDstTexture()->origin()) { | 71 kTopLeft_GrSurfaceOrigin == this->getDstTexture()->origin()) { |
| 48 key |= 0x2; | 72 key |= 0x2; |
| 49 } | 73 } |
| 74 if (this->dstReadUsesMixedSamples()) { |
| 75 key |= 0x4; |
| 76 } |
| 50 b->add32(key); | 77 b->add32(key); |
| 51 this->onGetGLProcessorKey(caps, b); | 78 this->onGetGLProcessorKey(caps, b); |
| 52 } | 79 } |
| 53 | 80 |
| 54 bool GrXferProcessor::willNeedXferBarrier(const GrRenderTarget* rt, | 81 bool GrXferProcessor::willNeedXferBarrier(const GrRenderTarget* rt, |
| 55 const GrCaps& caps, | 82 const GrCaps& caps, |
| 56 GrXferBarrierType* outBarrierType) con
st { | 83 GrXferBarrierType* outBarrierType) con
st { |
| 57 if (static_cast<const GrSurface*>(rt) == this->getDstTexture()) { | 84 if (static_cast<const GrSurface*>(rt) == this->getDstTexture()) { |
| 58 // Texture barriers are required when a shader reads and renders to the
same texture. | 85 // Texture barriers are required when a shader reads and renders to the
same texture. |
| 59 SkASSERT(rt); | 86 SkASSERT(rt); |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 153 SkString out; | 180 SkString out; |
| 154 out.printf("write_color(%d) equation(%s) src_coeff(%s) dst_coeff:(%s) const(
0x%08x)", | 181 out.printf("write_color(%d) equation(%s) src_coeff(%s) dst_coeff:(%s) const(
0x%08x)", |
| 155 fWriteColor, equation_string(fEquation), coeff_string(fSrcBlend), | 182 fWriteColor, equation_string(fEquation), coeff_string(fSrcBlend), |
| 156 coeff_string(fDstBlend), fBlendConstant); | 183 coeff_string(fDstBlend), fBlendConstant); |
| 157 return out; | 184 return out; |
| 158 } | 185 } |
| 159 #endif | 186 #endif |
| 160 | 187 |
| 161 /////////////////////////////////////////////////////////////////////////////// | 188 /////////////////////////////////////////////////////////////////////////////// |
| 162 | 189 |
| 163 GrXferProcessor* GrXPFactory::createXferProcessor(const GrProcOptInfo& colorPOI, | 190 GrXferProcessor* GrXPFactory::createXferProcessor(const GrPipelineBuilder& build
er, |
| 191 const GrProcOptInfo& colorPOI, |
| 164 const GrProcOptInfo& coverageP
OI, | 192 const GrProcOptInfo& coverageP
OI, |
| 165 const DstTexture* dstTexture, | 193 const DstTexture* dstTexture, |
| 166 const GrCaps& caps) const { | 194 const GrCaps& caps) const { |
| 167 #ifdef SK_DEBUG | 195 #ifdef SK_DEBUG |
| 168 if (this->willReadDstColor(caps, colorPOI, coveragePOI)) { | 196 if (this->willReadDstColor(caps, builder, colorPOI, coveragePOI)) { |
| 169 if (!caps.shaderCaps()->dstReadInShaderSupport()) { | 197 if (!caps.shaderCaps()->dstReadInShaderSupport()) { |
| 170 SkASSERT(dstTexture && dstTexture->texture()); | 198 SkASSERT(dstTexture && dstTexture->texture()); |
| 171 } else { | 199 } else { |
| 172 SkASSERT(!dstTexture || !dstTexture->texture()); | 200 SkASSERT(!dstTexture || !dstTexture->texture()); |
| 173 } | 201 } |
| 174 } else { | 202 } else { |
| 175 SkASSERT(!dstTexture || !dstTexture->texture()); | 203 SkASSERT(!dstTexture || !dstTexture->texture()); |
| 176 } | 204 } |
| 205 SkASSERT(!builder.hasMixedSamples() || caps.shaderCaps()->dualSourceBlending
Support()); |
| 177 #endif | 206 #endif |
| 178 return this->onCreateXferProcessor(caps, colorPOI, coveragePOI, dstTexture); | 207 return this->onCreateXferProcessor(caps, builder, colorPOI, coveragePOI, dst
Texture); |
| 179 } | 208 } |
| 180 | 209 |
| 181 bool GrXPFactory::willNeedDstTexture(const GrCaps& caps, const GrProcOptInfo& co
lorPOI, | 210 bool GrXPFactory::willNeedDstTexture(const GrCaps& caps, |
| 182 const GrProcOptInfo& coveragePOI) const { | 211 const GrPipelineBuilder& builder, |
| 183 return (this->willReadDstColor(caps, colorPOI, coveragePOI) | 212 const GrProcOptInfo& colorPOI, |
| 184 && !caps.shaderCaps()->dstReadInShaderSupport()); | 213 const GrProcOptInfo& coveragePOI) const { |
| 214 return (this->willReadDstColor(caps, builder, colorPOI, coveragePOI) && |
| 215 !caps.shaderCaps()->dstReadInShaderSupport()); |
| 185 } | 216 } |
| OLD | NEW |