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" |
Adlai Holler | a069304 | 2020-10-14 11:23:11 -0400 | [diff] [blame] | 14 | #include "src/gpu/GrDirectContextPriv.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 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 = |
Chris Dalton | 57ab06c | 2021-04-22 12:57:28 -0600 | [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)); |
| 43 | SkPMColor4f overrideColor; |
Chris Dalton | 6ce447a | 2019-06-23 18:07:38 -0600 | [diff] [blame] | 44 | GrProcessorSet::Analysis processorAnalysis = procs.finalize( |
Chris Dalton | 57ab06c | 2021-04-22 12:57:28 -0600 | [diff] [blame] | 45 | opaque, coverage, nullptr, &GrUserStencilSettings::kUnused, caps, |
| 46 | GrClampType::kAuto, &overrideColor); |
Chris Dalton | 945ee65 | 2019-01-23 09:10:36 -0700 | [diff] [blame] | 47 | |
| 48 | if (caps.advancedBlendEquationSupport() && |
Jim Van Verth | 1bef979 | 2020-07-09 08:09:13 -0400 | [diff] [blame] | 49 | !caps.isAdvancedBlendEquationDisabled(blendEquation)) { |
Chris Dalton | 945ee65 | 2019-01-23 09:10:36 -0700 | [diff] [blame] | 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 | } |