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