Chris Dalton | 945ee65 | 2019-01-23 09:10:36 -0700 | [diff] [blame] | 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 | |
Ben Wagner | 9707a7e | 2019-05-06 17:17:19 -0400 | [diff] [blame] | 8 | #include "include/core/SkBlendMode.h" |
Robert Phillips | 6d344c3 | 2020-07-06 10:56:46 -0400 | [diff] [blame] | 9 | #include "include/gpu/GrDirectContext.h" |
Ben Wagner | 9707a7e | 2019-05-06 17:17:19 -0400 | [diff] [blame] | 10 | #include "include/private/GrTypesPriv.h" |
| 11 | #include "include/private/SkColorData.h" |
Brian Salomon | 096b091 | 2019-08-14 16:56:13 -0400 | [diff] [blame] | 12 | #include "src/gpu/GrBlend.h" |
Ben Wagner | 9707a7e | 2019-05-06 17:17:19 -0400 | [diff] [blame] | 13 | #include "src/gpu/GrCaps.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 14 | #include "src/gpu/GrContextPriv.h" |
| 15 | #include "src/gpu/GrPaint.h" |
Ben Wagner | 9707a7e | 2019-05-06 17:17:19 -0400 | [diff] [blame] | 16 | #include "src/gpu/GrProcessorAnalysis.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 17 | #include "src/gpu/GrProcessorSet.h" |
Ben Wagner | 9707a7e | 2019-05-06 17:17:19 -0400 | [diff] [blame] | 18 | #include "src/gpu/GrUserStencilSettings.h" |
| 19 | #include "src/gpu/GrXferProcessor.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 20 | #include "src/gpu/effects/GrCustomXfermode.h" |
Ben Wagner | 9707a7e | 2019-05-06 17:17:19 -0400 | [diff] [blame] | 21 | #include "tests/Test.h" |
| 22 | #include "tools/gpu/GrContextFactory.h" |
| 23 | |
| 24 | #include <utility> |
Chris Dalton | 945ee65 | 2019-01-23 09:10:36 -0700 | [diff] [blame] | 25 | |
| 26 | DEF_GPUTEST_FOR_RENDERING_CONTEXTS(AdvancedBlendTest, reporter, ctxInfo) { |
| 27 | static constexpr auto opaque = GrProcessorAnalysisColor::Opaque::kYes; |
| 28 | static constexpr auto coverage = GrProcessorAnalysisCoverage::kSingleChannel; |
Robert Phillips | 6d344c3 | 2020-07-06 10:56:46 -0400 | [diff] [blame] | 29 | const GrCaps& caps = *ctxInfo.directContext()->priv().caps(); |
Chris Dalton | 945ee65 | 2019-01-23 09:10:36 -0700 | [diff] [blame] | 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 = |
Brian Osman | 5ced0bf | 2019-03-15 10:15:29 -0400 | [diff] [blame] | 38 | GrXPFactory::GetAnalysisProperties(xpf, opaque, coverage, caps, GrClampType::kAuto); |
Chris Dalton | 945ee65 | 2019-01-23 09:10:36 -0700 | [diff] [blame] | 39 | |
| 40 | GrPaint paint; |
| 41 | paint.setXPFactory(xpf); |
| 42 | GrProcessorSet procs(std::move(paint)); |
Chris Dalton | 6ce447a | 2019-06-23 18:07:38 -0600 | [diff] [blame] | 43 | bool hasMixedSampledCoverage = false; |
Chris Dalton | 945ee65 | 2019-01-23 09:10:36 -0700 | [diff] [blame] | 44 | SkPMColor4f overrideColor; |
Chris Dalton | 6ce447a | 2019-06-23 18:07:38 -0600 | [diff] [blame] | 45 | GrProcessorSet::Analysis processorAnalysis = procs.finalize( |
| 46 | opaque, coverage, nullptr, &GrUserStencilSettings::kUnused, hasMixedSampledCoverage, |
| 47 | caps, GrClampType::kAuto, &overrideColor); |
Chris Dalton | 945ee65 | 2019-01-23 09:10:36 -0700 | [diff] [blame] | 48 | |
| 49 | if (caps.advancedBlendEquationSupport() && |
Jim Van Verth | 1bef979 | 2020-07-09 08:09:13 -0400 | [diff] [blame] | 50 | !caps.isAdvancedBlendEquationDisabled(blendEquation)) { |
Chris Dalton | 945ee65 | 2019-01-23 09:10:36 -0700 | [diff] [blame] | 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 | } |