• 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 "include/core/SkBlendMode.h"
9 #include "include/gpu/GrContext.h"
10 #include "include/private/GrTypesPriv.h"
11 #include "include/private/SkColorData.h"
12 #include "src/gpu/GrBlend.h"
13 #include "src/gpu/GrCaps.h"
14 #include "src/gpu/GrContextPriv.h"
15 #include "src/gpu/GrPaint.h"
16 #include "src/gpu/GrProcessorAnalysis.h"
17 #include "src/gpu/GrProcessorSet.h"
18 #include "src/gpu/GrUserStencilSettings.h"
19 #include "src/gpu/GrXferProcessor.h"
20 #include "src/gpu/effects/GrCustomXfermode.h"
21 #include "tests/Test.h"
22 #include "tools/gpu/GrContextFactory.h"
23 
24 #include <utility>
25 
DEF_GPUTEST_FOR_RENDERING_CONTEXTS(AdvancedBlendTest,reporter,ctxInfo)26 DEF_GPUTEST_FOR_RENDERING_CONTEXTS(AdvancedBlendTest, reporter, ctxInfo) {
27     static constexpr auto opaque = GrProcessorAnalysisColor::Opaque::kYes;
28     static constexpr auto coverage = GrProcessorAnalysisCoverage::kSingleChannel;
29     const GrCaps& caps = *ctxInfo.grContext()->priv().caps();
30 
31     for (int mode = (int)SkBlendMode::kLastMode; mode > (int)SkBlendMode::kLastCoeffMode; --mode) {
32         const SkBlendMode blendMode = (SkBlendMode)mode;
33         const GrBlendEquation blendEquation =
34                 (GrBlendEquation)(mode + (kOverlay_GrBlendEquation - (int)SkBlendMode::kOverlay));
35         const GrXPFactory* xpf = GrCustomXfermode::Get(blendMode);
36 
37         GrXPFactory::AnalysisProperties xpfAnalysis =
38                 GrXPFactory::GetAnalysisProperties(xpf, opaque, coverage, caps, GrClampType::kAuto);
39 
40         GrPaint paint;
41         paint.setXPFactory(xpf);
42         GrProcessorSet procs(std::move(paint));
43         bool hasMixedSampledCoverage = false;
44         SkPMColor4f overrideColor;
45         GrProcessorSet::Analysis processorAnalysis = procs.finalize(
46                 opaque, coverage, nullptr, &GrUserStencilSettings::kUnused, hasMixedSampledCoverage,
47                 caps, GrClampType::kAuto, &overrideColor);
48 
49         if (caps.advancedBlendEquationSupport() &&
50                 !caps.isAdvancedBlendEquationBlacklisted(blendEquation)) {
51             REPORTER_ASSERT(reporter,
52                             !(xpfAnalysis & GrXPFactory::AnalysisProperties::kReadsDstInShader));
53             if (GrCaps::kAdvancedCoherent_BlendEquationSupport == caps.blendEquationSupport()) {
54                 REPORTER_ASSERT(reporter, !processorAnalysis.requiresNonOverlappingDraws());
55             } else {
56                 REPORTER_ASSERT(reporter,
57                                 GrCaps::kAdvanced_BlendEquationSupport
58                                         == caps.blendEquationSupport());
59                 REPORTER_ASSERT(reporter, processorAnalysis.requiresNonOverlappingDraws());
60             }
61         } else {
62             REPORTER_ASSERT(reporter,
63                             (xpfAnalysis & GrXPFactory::AnalysisProperties::kReadsDstInShader));
64             if (xpfAnalysis & GrXPFactory::AnalysisProperties::kRequiresDstTexture) {
65                 REPORTER_ASSERT(reporter, processorAnalysis.requiresNonOverlappingDraws());
66             } else {
67                 REPORTER_ASSERT(reporter, !processorAnalysis.requiresNonOverlappingDraws());
68             }
69         }
70     }
71 }
72