blob: 176bf83a7edcf56da13d32dc2d78f89e9e01bb67 [file] [log] [blame]
Chris Dalton945ee652019-01-23 09:10:36 -07001/*
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
Ben Wagner9707a7e2019-05-06 17:17:19 -04008#include "include/core/SkBlendMode.h"
Ben Wagner9707a7e2019-05-06 17:17:19 -04009#include "include/gpu/GrContext.h"
10#include "include/private/GrTypesPriv.h"
11#include "include/private/SkColorData.h"
Brian Salomon096b0912019-08-14 16:56:13 -040012#include "src/gpu/GrBlend.h"
Ben Wagner9707a7e2019-05-06 17:17:19 -040013#include "src/gpu/GrCaps.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050014#include "src/gpu/GrContextPriv.h"
15#include "src/gpu/GrPaint.h"
Ben Wagner9707a7e2019-05-06 17:17:19 -040016#include "src/gpu/GrProcessorAnalysis.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050017#include "src/gpu/GrProcessorSet.h"
Ben Wagner9707a7e2019-05-06 17:17:19 -040018#include "src/gpu/GrUserStencilSettings.h"
19#include "src/gpu/GrXferProcessor.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050020#include "src/gpu/effects/GrCustomXfermode.h"
Ben Wagner9707a7e2019-05-06 17:17:19 -040021#include "tests/Test.h"
22#include "tools/gpu/GrContextFactory.h"
23
24#include <utility>
Chris Dalton945ee652019-01-23 09:10:36 -070025
26DEF_GPUTEST_FOR_RENDERING_CONTEXTS(AdvancedBlendTest, reporter, ctxInfo) {
27 static constexpr auto opaque = GrProcessorAnalysisColor::Opaque::kYes;
28 static constexpr auto coverage = GrProcessorAnalysisCoverage::kSingleChannel;
Robert Phillips9da87e02019-02-04 13:26:26 -050029 const GrCaps& caps = *ctxInfo.grContext()->priv().caps();
Chris Dalton945ee652019-01-23 09:10:36 -070030
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 =
Brian Osman5ced0bf2019-03-15 10:15:29 -040038 GrXPFactory::GetAnalysisProperties(xpf, opaque, coverage, caps, GrClampType::kAuto);
Chris Dalton945ee652019-01-23 09:10:36 -070039
40 GrPaint paint;
41 paint.setXPFactory(xpf);
42 GrProcessorSet procs(std::move(paint));
Chris Dalton6ce447a2019-06-23 18:07:38 -060043 bool hasMixedSampledCoverage = false;
Chris Dalton945ee652019-01-23 09:10:36 -070044 SkPMColor4f overrideColor;
Chris Dalton6ce447a2019-06-23 18:07:38 -060045 GrProcessorSet::Analysis processorAnalysis = procs.finalize(
46 opaque, coverage, nullptr, &GrUserStencilSettings::kUnused, hasMixedSampledCoverage,
47 caps, GrClampType::kAuto, &overrideColor);
Chris Dalton945ee652019-01-23 09:10:36 -070048
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}