AdvancedBlendTest.cpp 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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. #include "include/core/SkBlendMode.h"
  8. #include "include/gpu/GrBlend.h"
  9. #include "include/gpu/GrContext.h"
  10. #include "include/private/GrTypesPriv.h"
  11. #include "include/private/SkColorData.h"
  12. #include "src/gpu/GrCaps.h"
  13. #include "src/gpu/GrContextPriv.h"
  14. #include "src/gpu/GrPaint.h"
  15. #include "src/gpu/GrProcessorAnalysis.h"
  16. #include "src/gpu/GrProcessorSet.h"
  17. #include "src/gpu/GrUserStencilSettings.h"
  18. #include "src/gpu/GrXferProcessor.h"
  19. #include "src/gpu/effects/GrCustomXfermode.h"
  20. #include "tests/Test.h"
  21. #include "tools/gpu/GrContextFactory.h"
  22. #include <utility>
  23. DEF_GPUTEST_FOR_RENDERING_CONTEXTS(AdvancedBlendTest, reporter, ctxInfo) {
  24. static constexpr auto opaque = GrProcessorAnalysisColor::Opaque::kYes;
  25. static constexpr auto coverage = GrProcessorAnalysisCoverage::kSingleChannel;
  26. const GrCaps& caps = *ctxInfo.grContext()->priv().caps();
  27. for (int mode = (int)SkBlendMode::kLastMode; mode > (int)SkBlendMode::kLastCoeffMode; --mode) {
  28. const SkBlendMode blendMode = (SkBlendMode)mode;
  29. const GrBlendEquation blendEquation =
  30. (GrBlendEquation)(mode + (kOverlay_GrBlendEquation - (int)SkBlendMode::kOverlay));
  31. const GrXPFactory* xpf = GrCustomXfermode::Get(blendMode);
  32. GrXPFactory::AnalysisProperties xpfAnalysis =
  33. GrXPFactory::GetAnalysisProperties(xpf, opaque, coverage, caps, GrClampType::kAuto);
  34. GrPaint paint;
  35. paint.setXPFactory(xpf);
  36. GrProcessorSet procs(std::move(paint));
  37. bool hasMixedSampledCoverage = false;
  38. SkPMColor4f overrideColor;
  39. GrProcessorSet::Analysis processorAnalysis = procs.finalize(
  40. opaque, coverage, nullptr, &GrUserStencilSettings::kUnused, hasMixedSampledCoverage,
  41. caps, GrClampType::kAuto, &overrideColor);
  42. if (caps.advancedBlendEquationSupport() &&
  43. !caps.isAdvancedBlendEquationBlacklisted(blendEquation)) {
  44. REPORTER_ASSERT(reporter,
  45. !(xpfAnalysis & GrXPFactory::AnalysisProperties::kReadsDstInShader));
  46. if (GrCaps::kAdvancedCoherent_BlendEquationSupport == caps.blendEquationSupport()) {
  47. REPORTER_ASSERT(reporter, !processorAnalysis.requiresNonOverlappingDraws());
  48. } else {
  49. REPORTER_ASSERT(reporter,
  50. GrCaps::kAdvanced_BlendEquationSupport
  51. == caps.blendEquationSupport());
  52. REPORTER_ASSERT(reporter, processorAnalysis.requiresNonOverlappingDraws());
  53. }
  54. } else {
  55. REPORTER_ASSERT(reporter,
  56. (xpfAnalysis & GrXPFactory::AnalysisProperties::kReadsDstInShader));
  57. if (xpfAnalysis & GrXPFactory::AnalysisProperties::kRequiresDstTexture) {
  58. REPORTER_ASSERT(reporter, processorAnalysis.requiresNonOverlappingDraws());
  59. } else {
  60. REPORTER_ASSERT(reporter, !processorAnalysis.requiresNonOverlappingDraws());
  61. }
  62. }
  63. }
  64. }