• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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()->contextPriv().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);
28 
29         GrPaint paint;
30         paint.setXPFactory(xpf);
31         GrProcessorSet procs(std::move(paint));
32         SkPMColor4f overrideColor;
33         GrProcessorSet::Analysis processorAnalysis =
34                 procs.finalize(opaque, coverage, nullptr, false, caps, &overrideColor);
35 
36         if (caps.advancedBlendEquationSupport() &&
37                 !caps.isAdvancedBlendEquationBlacklisted(blendEquation)) {
38             REPORTER_ASSERT(reporter,
39                             !(xpfAnalysis & GrXPFactory::AnalysisProperties::kReadsDstInShader));
40             if (GrCaps::kAdvancedCoherent_BlendEquationSupport == caps.blendEquationSupport()) {
41                 REPORTER_ASSERT(reporter, !processorAnalysis.requiresNonOverlappingDraws());
42             } else {
43                 REPORTER_ASSERT(reporter,
44                                 GrCaps::kAdvanced_BlendEquationSupport
45                                         == caps.blendEquationSupport());
46                 REPORTER_ASSERT(reporter, processorAnalysis.requiresNonOverlappingDraws());
47             }
48         } else {
49             REPORTER_ASSERT(reporter,
50                             (xpfAnalysis & GrXPFactory::AnalysisProperties::kReadsDstInShader));
51             if (xpfAnalysis & GrXPFactory::AnalysisProperties::kRequiresDstTexture) {
52                 REPORTER_ASSERT(reporter, processorAnalysis.requiresNonOverlappingDraws());
53             } else {
54                 REPORTER_ASSERT(reporter, !processorAnalysis.requiresNonOverlappingDraws());
55             }
56         }
57     }
58 }
59