1 /*
2 * Copyright 2019 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8 #include "Test.h"
9
10 #include "GrContextPriv.h"
11 #include "GrPaint.h"
12 #include "GrProcessorSet.h"
13 #include "effects/GrCustomXfermode.h"
14
DEF_GPUTEST_FOR_RENDERING_CONTEXTS(AdvancedBlendTest,reporter,ctxInfo)15 DEF_GPUTEST_FOR_RENDERING_CONTEXTS(AdvancedBlendTest, reporter, ctxInfo) {
16 static constexpr auto opaque = GrProcessorAnalysisColor::Opaque::kYes;
17 static constexpr auto coverage = GrProcessorAnalysisCoverage::kSingleChannel;
18 const GrCaps& caps = *ctxInfo.grContext()->priv().caps();
19
20 for (int mode = (int)SkBlendMode::kLastMode; mode > (int)SkBlendMode::kLastCoeffMode; --mode) {
21 const SkBlendMode blendMode = (SkBlendMode)mode;
22 const GrBlendEquation blendEquation =
23 (GrBlendEquation)(mode + (kOverlay_GrBlendEquation - (int)SkBlendMode::kOverlay));
24 const GrXPFactory* xpf = GrCustomXfermode::Get(blendMode);
25
26 GrXPFactory::AnalysisProperties xpfAnalysis =
27 GrXPFactory::GetAnalysisProperties(xpf, opaque, coverage, caps, GrClampType::kAuto);
28
29 GrPaint paint;
30 paint.setXPFactory(xpf);
31 GrProcessorSet procs(std::move(paint));
32 SkPMColor4f overrideColor;
33 GrProcessorSet::Analysis processorAnalysis =
34 procs.finalize(
35 opaque, coverage, nullptr, &GrUserStencilSettings::kUnused,
36 GrFSAAType::kNone, caps, GrClampType::kAuto, &overrideColor);
37
38 if (caps.advancedBlendEquationSupport() &&
39 !caps.isAdvancedBlendEquationBlacklisted(blendEquation)) {
40 REPORTER_ASSERT(reporter,
41 !(xpfAnalysis & GrXPFactory::AnalysisProperties::kReadsDstInShader));
42 if (GrCaps::kAdvancedCoherent_BlendEquationSupport == caps.blendEquationSupport()) {
43 REPORTER_ASSERT(reporter, !processorAnalysis.requiresNonOverlappingDraws());
44 } else {
45 REPORTER_ASSERT(reporter,
46 GrCaps::kAdvanced_BlendEquationSupport
47 == caps.blendEquationSupport());
48 REPORTER_ASSERT(reporter, processorAnalysis.requiresNonOverlappingDraws());
49 }
50 } else {
51 REPORTER_ASSERT(reporter,
52 (xpfAnalysis & GrXPFactory::AnalysisProperties::kReadsDstInShader));
53 if (xpfAnalysis & GrXPFactory::AnalysisProperties::kRequiresDstTexture) {
54 REPORTER_ASSERT(reporter, processorAnalysis.requiresNonOverlappingDraws());
55 } else {
56 REPORTER_ASSERT(reporter, !processorAnalysis.requiresNonOverlappingDraws());
57 }
58 }
59 }
60 }
61