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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
|
/*
* Copyright 2017 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include "GrProcessorSet.h"
#include "GrAppliedClip.h"
#include "GrCaps.h"
#include "GrPipelineAnalysis.h"
#include "GrXferProcessor.h"
GrProcessorSet::GrProcessorSet(GrPaint&& paint) {
fXPFactory = paint.fXPFactory;
fFlags = 0;
if (paint.numColorFragmentProcessors() <= kMaxColorProcessors) {
fColorFragmentProcessorCnt = paint.numColorFragmentProcessors();
fFragmentProcessors.reset(paint.numTotalFragmentProcessors());
int i = 0;
for (auto& fp : paint.fColorFragmentProcessors) {
fFragmentProcessors[i++] = fp.release();
}
for (auto& fp : paint.fCoverageFragmentProcessors) {
fFragmentProcessors[i++] = fp.release();
}
if (paint.usesDistanceVectorField()) {
fFlags |= kUseDistanceVectorField_Flag;
}
} else {
SkDebugf("Insane number of color fragment processors in paint. Dropping all processors.");
fColorFragmentProcessorCnt = 0;
}
if (paint.getDisableOutputConversionToSRGB()) {
fFlags |= kDisableOutputConversionToSRGB_Flag;
}
if (paint.getAllowSRGBInputs()) {
fFlags |= kAllowSRGBInputs_Flag;
}
}
GrProcessorSet::~GrProcessorSet() {
for (int i = fFragmentProcessorOffset; i < fFragmentProcessors.count(); ++i) {
if (this->isPendingExecution()) {
fFragmentProcessors[i]->completedExecution();
} else {
fFragmentProcessors[i]->unref();
}
}
}
void GrProcessorSet::makePendingExecution() {
SkASSERT(!(kPendingExecution_Flag & fFlags));
fFlags |= kPendingExecution_Flag;
for (int i = fFragmentProcessorOffset; i < fFragmentProcessors.count(); ++i) {
fFragmentProcessors[i]->addPendingExecution();
fFragmentProcessors[i]->unref();
}
}
bool GrProcessorSet::operator==(const GrProcessorSet& that) const {
int fpCount = this->numFragmentProcessors();
if (((fFlags ^ that.fFlags) & ~kPendingExecution_Flag) ||
fpCount != that.numFragmentProcessors() ||
fColorFragmentProcessorCnt != that.fColorFragmentProcessorCnt) {
return false;
}
for (int i = 0; i < fpCount; ++i) {
int a = i + fFragmentProcessorOffset;
int b = i + that.fFragmentProcessorOffset;
if (!fFragmentProcessors[a]->isEqual(*that.fFragmentProcessors[b])) {
return false;
}
}
if (fXPFactory != that.fXPFactory) {
return false;
}
return true;
}
//////////////////////////////////////////////////////////////////////////////
void GrProcessorSet::FragmentProcessorAnalysis::internalInit(
const GrPipelineAnalysisColor& colorInput,
const GrPipelineAnalysisCoverage coverageInput,
const GrProcessorSet& processors,
const GrFragmentProcessor* clipFP,
const GrCaps& caps) {
GrColorFragmentProcessorAnalysis colorInfo(colorInput);
fCompatibleWithCoverageAsAlpha = GrPipelineAnalysisCoverage::kLCD != coverageInput;
fValidInputColor = colorInput.isConstant(&fInputColor);
const GrFragmentProcessor* const* fps =
processors.fFragmentProcessors.get() + processors.fFragmentProcessorOffset;
colorInfo.analyzeProcessors(fps, processors.fColorFragmentProcessorCnt);
fCompatibleWithCoverageAsAlpha &= colorInfo.allProcessorsCompatibleWithCoverageAsAlpha();
fps += processors.fColorFragmentProcessorCnt;
int n = processors.numCoverageFragmentProcessors();
bool hasCoverageFP = n > 0;
bool coverageUsesLocalCoords = false;
for (int i = 0; i < n; ++i) {
if (!fps[i]->compatibleWithCoverageAsAlpha()) {
fCompatibleWithCoverageAsAlpha = false;
// Other than tests that exercise atypical behavior we expect all coverage FPs to be
// compatible with the coverage-as-alpha optimization.
GrCapsDebugf(&caps, "Coverage FP is not compatible with coverage as alpha.\n");
}
coverageUsesLocalCoords |= fps[i]->usesLocalCoords();
}
if (clipFP) {
fCompatibleWithCoverageAsAlpha &= clipFP->compatibleWithCoverageAsAlpha();
coverageUsesLocalCoords |= clipFP->usesLocalCoords();
hasCoverageFP = true;
}
fInitialColorProcessorsToEliminate = colorInfo.initialProcessorsToEliminate(&fInputColor);
fValidInputColor |= SkToBool(fInitialColorProcessorsToEliminate);
GrPipelineAnalysisColor outputColor = colorInfo.outputColor();
if (outputColor.isConstant(&fKnownOutputColor)) {
fOutputColorType = static_cast<unsigned>(outputColor.isOpaque() ? ColorType::kOpaqueConstant
: ColorType::kConstant);
} else if (outputColor.isOpaque()) {
fOutputColorType = static_cast<unsigned>(ColorType::kOpaque);
} else {
fOutputColorType = static_cast<unsigned>(ColorType::kUnknown);
}
GrPipelineAnalysisCoverage outputCoverage;
if (GrPipelineAnalysisCoverage::kLCD == coverageInput) {
outputCoverage = GrPipelineAnalysisCoverage::kLCD;
} else if (hasCoverageFP || GrPipelineAnalysisCoverage::kSingleChannel == coverageInput) {
outputCoverage = GrPipelineAnalysisCoverage::kSingleChannel;
} else {
outputCoverage = GrPipelineAnalysisCoverage::kNone;
}
fOutputCoverageType = static_cast<unsigned>(outputCoverage);
GrXPFactory::AnalysisProperties props = GrXPFactory::GetAnalysisProperties(
processors.fXPFactory, colorInfo.outputColor(), outputCoverage, caps);
if (!processors.numCoverageFragmentProcessors() &&
GrPipelineAnalysisCoverage::kNone == coverageInput) {
fCanCombineOverlappedStencilAndCover = SkToBool(
props & GrXPFactory::AnalysisProperties::kCanCombineOverlappedStencilAndCover);
} else {
// If we have non-clipping coverage processors we don't try to merge stencil steps as its
// unclear whether it will be correct. We don't expect this to happen in practice.
fCanCombineOverlappedStencilAndCover = false;
}
fRequiresDstTexture = SkToBool(props & GrXPFactory::AnalysisProperties::kRequiresDstTexture);
fIgnoresInputColor = SkToBool(props & GrXPFactory::AnalysisProperties::kIgnoresInputColor);
fCompatibleWithCoverageAsAlpha &=
SkToBool(props & GrXPFactory::AnalysisProperties::kCompatibleWithAlphaAsCoverage);
if (props & GrXPFactory::AnalysisProperties::kIgnoresInputColor) {
fInitialColorProcessorsToEliminate = processors.numColorFragmentProcessors();
// If the output of the last color stage is known then the kIgnoresInputColor optimization
// may depend upon it being the input to the xp.
if (!outputColor.isConstant(&fInputColor)) {
// Otherwise, the only property the XP factory could have relied upon to compute
// kIgnoresInputColor is opaqueness.
fInputColor = GrColor_WHITE;
}
fValidInputColor = true;
fUsesLocalCoords = coverageUsesLocalCoords;
} else {
fUsesLocalCoords = coverageUsesLocalCoords | colorInfo.usesLocalCoords();
}
}
void GrProcessorSet::FragmentProcessorAnalysis::init(const GrPipelineAnalysisColor& colorInput,
const GrPipelineAnalysisCoverage coverageInput,
const GrProcessorSet& processors,
const GrAppliedClip* appliedClip,
const GrCaps& caps) {
const GrFragmentProcessor* clipFP =
appliedClip ? appliedClip->clipCoverageFragmentProcessor() : nullptr;
this->internalInit(colorInput, coverageInput, processors, clipFP, caps);
fIsInitializedWithProcessorSet = true;
}
GrProcessorSet::FragmentProcessorAnalysis::FragmentProcessorAnalysis(
const GrPipelineAnalysisColor& colorInput,
const GrPipelineAnalysisCoverage coverageInput,
const GrXPFactory* factory,
const GrCaps& caps)
: FragmentProcessorAnalysis() {
GrPaint paint;
paint.setXPFactory(factory);
this->internalInit(colorInput, coverageInput, GrProcessorSet(std::move(paint)), nullptr, caps);
}
void GrProcessorSet::analyzeAndEliminateFragmentProcessors(
FragmentProcessorAnalysis* analysis,
const GrPipelineAnalysisColor& colorInput,
const GrPipelineAnalysisCoverage coverageInput,
const GrAppliedClip* clip,
const GrCaps& caps) {
analysis->init(colorInput, coverageInput, *this, clip, caps);
if (analysis->fInitialColorProcessorsToEliminate > 0) {
for (unsigned i = 0; i < analysis->fInitialColorProcessorsToEliminate; ++i) {
if (this->isPendingExecution()) {
fFragmentProcessors[i + fFragmentProcessorOffset]->completedExecution();
} else {
fFragmentProcessors[i + fFragmentProcessorOffset]->unref();
}
fFragmentProcessors[i + fFragmentProcessorOffset] = nullptr;
}
fFragmentProcessorOffset += analysis->fInitialColorProcessorsToEliminate;
fColorFragmentProcessorCnt -= analysis->fInitialColorProcessorsToEliminate;
SkASSERT(fFragmentProcessorOffset + fColorFragmentProcessorCnt <=
fFragmentProcessors.count());
analysis->fInitialColorProcessorsToEliminate = 0;
}
}
|