1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
|
/*
* Copyright 2015 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include "GrXferProcessor.h"
#include "gl/GrGLCaps.h"
GrXferProcessor::GrXferProcessor()
: fWillReadDstColor(false), fReadsCoverage(true), fDstCopyTextureOffset() {
}
GrXferProcessor::GrXferProcessor(const GrDeviceCoordTexture* dstCopy, bool willReadDstColor)
: fWillReadDstColor(willReadDstColor)
, fReadsCoverage(true)
, fDstCopyTextureOffset() {
if (dstCopy && dstCopy->texture()) {
fDstCopy.reset(dstCopy->texture());
fDstCopyTextureOffset = dstCopy->offset();
this->addTextureAccess(&fDstCopy);
this->setWillReadFragmentPosition();
}
}
GrXferProcessor::OptFlags GrXferProcessor::getOptimizations(const GrProcOptInfo& colorPOI,
const GrProcOptInfo& coveragePOI,
bool doesStencilWrite,
GrColor* overrideColor,
const GrDrawTargetCaps& caps) {
GrXferProcessor::OptFlags flags = this->onGetOptimizations(colorPOI,
coveragePOI,
doesStencilWrite,
overrideColor,
caps);
if (flags & GrXferProcessor::kIgnoreCoverage_OptFlag) {
fReadsCoverage = false;
}
return flags;
}
void GrXferProcessor::getGLProcessorKey(const GrGLSLCaps& caps, GrProcessorKeyBuilder* b) const {
uint32_t key = this->willReadDstColor() ? 0x1 : 0x0;
if (this->getDstCopyTexture() &&
kTopLeft_GrSurfaceOrigin == this->getDstCopyTexture()->origin()) {
key |= 0x2;
}
b->add32(key);
this->onGetGLProcessorKey(caps, b);
}
bool GrXferProcessor::willNeedXferBarrier(const GrRenderTarget* rt,
const GrDrawTargetCaps& caps,
GrXferBarrierType* outBarrierType) const {
if (static_cast<const GrSurface*>(rt) == this->getDstCopyTexture()) {
// Texture barriers are required when a shader reads and renders to the same texture.
SkASSERT(rt);
SkASSERT(caps.textureBarrierSupport());
*outBarrierType = kTexture_GrXferBarrierType;
return true;
}
return this->onWillNeedXferBarrier(rt, caps, outBarrierType);
}
///////////////////////////////////////////////////////////////////////////////
GrXferProcessor* GrXPFactory::createXferProcessor(const GrProcOptInfo& colorPOI,
const GrProcOptInfo& coveragePOI,
const GrDeviceCoordTexture* dstCopy,
const GrDrawTargetCaps& caps) const {
#ifdef SK_DEBUG
if (this->willReadDstColor(caps, colorPOI, coveragePOI)) {
if (!caps.shaderCaps()->dstReadInShaderSupport()) {
SkASSERT(dstCopy && dstCopy->texture());
} else {
SkASSERT(!dstCopy || !dstCopy->texture());
}
} else {
SkASSERT(!dstCopy || !dstCopy->texture());
}
#endif
return this->onCreateXferProcessor(caps, colorPOI, coveragePOI, dstCopy);
}
bool GrXPFactory::willNeedDstCopy(const GrDrawTargetCaps& caps, const GrProcOptInfo& colorPOI,
const GrProcOptInfo& coveragePOI) const {
return (this->willReadDstColor(caps, colorPOI, coveragePOI)
&& !caps.shaderCaps()->dstReadInShaderSupport());
}
|