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 "GrPipeline.h" | 9 #include "GrPipeline.h" |
10 #include "GrPipelineBuilder.h" | 10 #include "GrPipelineBuilder.h" |
11 #include "GrProcOptInfo.h" | 11 #include "GrProcOptInfo.h" |
12 #include "gl/GrGLCaps.h" | 12 #include "gl/GrGLCaps.h" |
13 | 13 |
14 GrXferProcessor::GrXferProcessor() | 14 GrXferProcessor::GrXferProcessor() |
15 : fWillReadDstColor(false) | 15 : fWillReadDstColor(false) |
16 , fDstReadUsesMixedSamples(false) | 16 , fDstReadUsesMixedSamples(false) |
17 , fReadsCoverage(true) | |
18 , fDstTextureOffset() { | 17 , fDstTextureOffset() { |
19 } | 18 } |
20 | 19 |
21 GrXferProcessor::GrXferProcessor(const DstTexture* dstTexture, | 20 GrXferProcessor::GrXferProcessor(const DstTexture* dstTexture, |
22 bool willReadDstColor, | 21 bool willReadDstColor, |
23 bool hasMixedSamples) | 22 bool hasMixedSamples) |
24 : fWillReadDstColor(willReadDstColor) | 23 : fWillReadDstColor(willReadDstColor) |
25 , fDstReadUsesMixedSamples(willReadDstColor && hasMixedSamples) | 24 , fDstReadUsesMixedSamples(willReadDstColor && hasMixedSamples) |
26 , fReadsCoverage(true) | |
27 , fDstTextureOffset() { | 25 , fDstTextureOffset() { |
28 if (dstTexture && dstTexture->texture()) { | 26 if (dstTexture && dstTexture->texture()) { |
29 SkASSERT(willReadDstColor); | 27 SkASSERT(willReadDstColor); |
30 fDstTexture.reset(dstTexture->texture()); | 28 fDstTexture.reset(dstTexture->texture()); |
31 fDstTextureOffset = dstTexture->offset(); | 29 fDstTextureOffset = dstTexture->offset(); |
32 this->addTextureAccess(&fDstTexture); | 30 this->addTextureAccess(&fDstTexture); |
33 this->setWillReadFragmentPosition(); | 31 this->setWillReadFragmentPosition(); |
34 } | 32 } |
35 } | 33 } |
36 | 34 |
37 GrXferProcessor::OptFlags GrXferProcessor::getOptimizations( | 35 GrXferProcessor::OptFlags GrXferProcessor::getOptimizations( |
38 const GrPipelineOptimizat
ions& optimizations, | 36 const GrPipelineOptimizat
ions& optimizations, |
39 bool doesStencilWrite, | 37 bool doesStencilWrite, |
40 GrColor* overrideColor, | 38 GrColor* overrideColor, |
41 const GrCaps& caps) { | 39 const GrCaps& caps) const
{ |
42 GrXferProcessor::OptFlags flags = this->onGetOptimizations(optimizations, | 40 GrXferProcessor::OptFlags flags = this->onGetOptimizations(optimizations, |
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 (optimizations.fCoveragePOI.isSolidWhite()) { | 48 if (optimizations.fCoveragePOI.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 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
218 #endif | 210 #endif |
219 return this->onCreateXferProcessor(caps, optimizations, hasMixedSamples, dst
Texture); | 211 return this->onCreateXferProcessor(caps, optimizations, hasMixedSamples, dst
Texture); |
220 } | 212 } |
221 | 213 |
222 bool GrXPFactory::willNeedDstTexture(const GrCaps& caps, | 214 bool GrXPFactory::willNeedDstTexture(const GrCaps& caps, |
223 const GrPipelineOptimizations& optimization
s, | 215 const GrPipelineOptimizations& optimization
s, |
224 bool hasMixedSamples) const { | 216 bool hasMixedSamples) const { |
225 return (this->willReadDstColor(caps, optimizations, hasMixedSamples) && | 217 return (this->willReadDstColor(caps, optimizations, hasMixedSamples) && |
226 !caps.shaderCaps()->dstReadInShaderSupport()); | 218 !caps.shaderCaps()->dstReadInShaderSupport()); |
227 } | 219 } |
OLD | NEW |