• 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/GrDirectContext.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/GrDirectContextPriv.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.directContext()->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         SkPMColor4f overrideColor;
44         GrProcessorSet::Analysis processorAnalysis = procs.finalize(
45                 opaque, coverage, nullptr, &GrUserStencilSettings::kUnused, caps,
46                 GrClampType::kAuto, &overrideColor);
47 
48         if (caps.advancedBlendEquationSupport() &&
49                 !caps.isAdvancedBlendEquationDisabled(blendEquation)) {
50             REPORTER_ASSERT(reporter,
51                             !(xpfAnalysis & GrXPFactory::AnalysisProperties::kReadsDstInShader));
52             if (GrCaps::kAdvancedCoherent_BlendEquationSupport == caps.blendEquationSupport()) {
53                 REPORTER_ASSERT(reporter, !processorAnalysis.requiresNonOverlappingDraws());
54             } else {
55                 REPORTER_ASSERT(reporter,
56                                 GrCaps::kAdvanced_BlendEquationSupport
57                                         == caps.blendEquationSupport());
58                 REPORTER_ASSERT(reporter, processorAnalysis.requiresNonOverlappingDraws());
59             }
60         } else {
61             REPORTER_ASSERT(reporter,
62                             (xpfAnalysis & GrXPFactory::AnalysisProperties::kReadsDstInShader));
63             if (xpfAnalysis & GrXPFactory::AnalysisProperties::kRequiresDstTexture) {
64                 REPORTER_ASSERT(reporter, processorAnalysis.requiresNonOverlappingDraws());
65             } else {
66                 REPORTER_ASSERT(reporter, !processorAnalysis.requiresNonOverlappingDraws());
67             }
68         }
69     }
70 }
71