2014-12-03 18:40:13 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2014 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef GrPorterDuffXferProcessor_DEFINED
|
|
|
|
#define GrPorterDuffXferProcessor_DEFINED
|
|
|
|
|
|
|
|
#include "GrTypes.h"
|
|
|
|
#include "GrXferProcessor.h"
|
|
|
|
#include "SkXfermode.h"
|
|
|
|
|
2014-12-17 21:37:13 +00:00
|
|
|
class GrProcOptInfo;
|
2014-12-03 18:40:13 +00:00
|
|
|
|
|
|
|
class GrPorterDuffXPFactory : public GrXPFactory {
|
|
|
|
public:
|
2014-12-03 19:41:54 +00:00
|
|
|
static GrXPFactory* Create(SkXfermode::Mode mode);
|
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
bool supportsRGBCoverage(GrColor knownColor, uint32_t knownColorFlags) const override;
|
2014-12-03 18:40:13 +00:00
|
|
|
|
2014-12-18 20:44:55 +00:00
|
|
|
void getInvariantOutput(const GrProcOptInfo& colorPOI, const GrProcOptInfo& coveragePOI,
|
2015-03-26 01:17:31 +00:00
|
|
|
GrXPFactory::InvariantOutput*) const override;
|
2014-12-09 19:15:43 +00:00
|
|
|
|
2014-12-03 18:40:13 +00:00
|
|
|
private:
|
Revert of Implement Porter Duff XP with a blend table (patchset #12 id:220001 of https://codereview.chromium.org/1124373002/)
Reason for revert:
Blocking DEPS roll into Chromium. Crashing virtual/gpu/fast/canvas/canvas-composite-*.html tests with the assert
../../third_party/skia/src/gpu/gl/builders/GrGLFragmentShaderBuilder.cpp:281: failed assertion "k110_GrGLSLGeneration != gpu->glslGeneration() || fOutputs.empty()"
Original issue's description:
> Implement Porter Duff XP with a blend table
>
> Removes the runtime logic used by PorterDuffXferProcessor to decide
> blend coeffs and shader outputs, and instead uses a compile-time
> constant table of pre-selected blend formulas.
>
> Introduces a new blend strategy for srcCoeff=0 that can apply coverage
> with a reverse subtract blend equation instead of dual source
> blending.
>
> Adds new macros in GrBlend.h to analyze blend formulas both runtime.
>
> Removes kSetCoverageDrawing_OptFlag and GrSimplifyBlend as they are no
> longer used.
>
> Adds a GM that verifies all xfermodes, including arithmetic, with the
> color/coverage invariants used by Porter Duff.
>
> Adds a unit test that verifies each Porter Duff formula with every
> color/coverage invariant.
>
> Major changes:
>
> * Uses a reverse subtract blend equation for coverage when srcCoeff=0
> (clear, dst-out [Sa=1], dst-in, modulate). Platforms that don't
> support dual source blending no longer require a dst copy for
> dst-in and modulate.
>
> * Sets BlendInfo::fWriteColor to false when the blend does not modify
> the dst. GrGLGpu will now use glColorMask instead of blending for
> these modes (dst, dst-in [Sa=1], modulate ignored for [Sc=1]).
>
> * Converts all SA blend coeffs to One for opaque inputs, and ISA to
> Zero if there is also no coverage. (We keep ISA around when there
> is coverage because we use it to tweak alpha for coverage.)
>
> * Abandons solid white optimizations for the sake of simplicity
> (screen was the only mode that previous had solid white opts).
>
> Minor differences:
>
> * Inconsequential differences in opt flags (e.g. we now return
> kCanTweakAlphaForCoverage_OptFlag even when there is no coverage).
>
> * Src coeffs when the shader outputs 0.
>
> * IS2C vs IS2A when the secondary output is scalar.
>
> BUG=skia:
>
> Committed: https://skia.googlesource.com/skia/+/9a70920db22b6309c671f8e5d519bb95570e4414
TBR=egdaniel@google.com,bsalomon@google.com,cdalton@nvidia.com
NOPRESUBMIT=true
NOTREECHECKS=true
NOTRY=true
BUG=skia:
Review URL: https://codereview.chromium.org/1153993002
2015-05-23 00:55:26 +00:00
|
|
|
GrPorterDuffXPFactory(GrBlendCoeff src, GrBlendCoeff dst);
|
2014-12-05 20:58:28 +00:00
|
|
|
|
2015-05-19 16:29:46 +00:00
|
|
|
GrXferProcessor* onCreateXferProcessor(const GrCaps& caps,
|
2015-02-17 19:15:47 +00:00
|
|
|
const GrProcOptInfo& colorPOI,
|
2015-02-06 15:02:37 +00:00
|
|
|
const GrProcOptInfo& coveragePOI,
|
2015-05-22 22:22:48 +00:00
|
|
|
const GrDeviceCoordTexture* dstCopy) const override;
|
2015-02-06 15:02:37 +00:00
|
|
|
|
2015-05-19 16:29:46 +00:00
|
|
|
bool willReadDstColor(const GrCaps& caps,
|
2015-02-17 19:15:47 +00:00
|
|
|
const GrProcOptInfo& colorPOI,
|
2015-03-26 01:17:31 +00:00
|
|
|
const GrProcOptInfo& coveragePOI) const override;
|
2015-02-06 15:02:37 +00:00
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
bool onIsEqual(const GrXPFactory& xpfBase) const override {
|
2014-12-05 20:58:28 +00:00
|
|
|
const GrPorterDuffXPFactory& xpf = xpfBase.cast<GrPorterDuffXPFactory>();
|
Revert of Implement Porter Duff XP with a blend table (patchset #12 id:220001 of https://codereview.chromium.org/1124373002/)
Reason for revert:
Blocking DEPS roll into Chromium. Crashing virtual/gpu/fast/canvas/canvas-composite-*.html tests with the assert
../../third_party/skia/src/gpu/gl/builders/GrGLFragmentShaderBuilder.cpp:281: failed assertion "k110_GrGLSLGeneration != gpu->glslGeneration() || fOutputs.empty()"
Original issue's description:
> Implement Porter Duff XP with a blend table
>
> Removes the runtime logic used by PorterDuffXferProcessor to decide
> blend coeffs and shader outputs, and instead uses a compile-time
> constant table of pre-selected blend formulas.
>
> Introduces a new blend strategy for srcCoeff=0 that can apply coverage
> with a reverse subtract blend equation instead of dual source
> blending.
>
> Adds new macros in GrBlend.h to analyze blend formulas both runtime.
>
> Removes kSetCoverageDrawing_OptFlag and GrSimplifyBlend as they are no
> longer used.
>
> Adds a GM that verifies all xfermodes, including arithmetic, with the
> color/coverage invariants used by Porter Duff.
>
> Adds a unit test that verifies each Porter Duff formula with every
> color/coverage invariant.
>
> Major changes:
>
> * Uses a reverse subtract blend equation for coverage when srcCoeff=0
> (clear, dst-out [Sa=1], dst-in, modulate). Platforms that don't
> support dual source blending no longer require a dst copy for
> dst-in and modulate.
>
> * Sets BlendInfo::fWriteColor to false when the blend does not modify
> the dst. GrGLGpu will now use glColorMask instead of blending for
> these modes (dst, dst-in [Sa=1], modulate ignored for [Sc=1]).
>
> * Converts all SA blend coeffs to One for opaque inputs, and ISA to
> Zero if there is also no coverage. (We keep ISA around when there
> is coverage because we use it to tweak alpha for coverage.)
>
> * Abandons solid white optimizations for the sake of simplicity
> (screen was the only mode that previous had solid white opts).
>
> Minor differences:
>
> * Inconsequential differences in opt flags (e.g. we now return
> kCanTweakAlphaForCoverage_OptFlag even when there is no coverage).
>
> * Src coeffs when the shader outputs 0.
>
> * IS2C vs IS2A when the secondary output is scalar.
>
> BUG=skia:
>
> Committed: https://skia.googlesource.com/skia/+/9a70920db22b6309c671f8e5d519bb95570e4414
TBR=egdaniel@google.com,bsalomon@google.com,cdalton@nvidia.com
NOPRESUBMIT=true
NOTREECHECKS=true
NOTRY=true
BUG=skia:
Review URL: https://codereview.chromium.org/1153993002
2015-05-23 00:55:26 +00:00
|
|
|
return (fSrcCoeff == xpf.fSrcCoeff && fDstCoeff == xpf.fDstCoeff);
|
2014-12-05 20:58:28 +00:00
|
|
|
}
|
2014-12-03 18:40:13 +00:00
|
|
|
|
2014-12-11 21:15:13 +00:00
|
|
|
GR_DECLARE_XP_FACTORY_TEST;
|
|
|
|
|
Revert of Implement Porter Duff XP with a blend table (patchset #12 id:220001 of https://codereview.chromium.org/1124373002/)
Reason for revert:
Blocking DEPS roll into Chromium. Crashing virtual/gpu/fast/canvas/canvas-composite-*.html tests with the assert
../../third_party/skia/src/gpu/gl/builders/GrGLFragmentShaderBuilder.cpp:281: failed assertion "k110_GrGLSLGeneration != gpu->glslGeneration() || fOutputs.empty()"
Original issue's description:
> Implement Porter Duff XP with a blend table
>
> Removes the runtime logic used by PorterDuffXferProcessor to decide
> blend coeffs and shader outputs, and instead uses a compile-time
> constant table of pre-selected blend formulas.
>
> Introduces a new blend strategy for srcCoeff=0 that can apply coverage
> with a reverse subtract blend equation instead of dual source
> blending.
>
> Adds new macros in GrBlend.h to analyze blend formulas both runtime.
>
> Removes kSetCoverageDrawing_OptFlag and GrSimplifyBlend as they are no
> longer used.
>
> Adds a GM that verifies all xfermodes, including arithmetic, with the
> color/coverage invariants used by Porter Duff.
>
> Adds a unit test that verifies each Porter Duff formula with every
> color/coverage invariant.
>
> Major changes:
>
> * Uses a reverse subtract blend equation for coverage when srcCoeff=0
> (clear, dst-out [Sa=1], dst-in, modulate). Platforms that don't
> support dual source blending no longer require a dst copy for
> dst-in and modulate.
>
> * Sets BlendInfo::fWriteColor to false when the blend does not modify
> the dst. GrGLGpu will now use glColorMask instead of blending for
> these modes (dst, dst-in [Sa=1], modulate ignored for [Sc=1]).
>
> * Converts all SA blend coeffs to One for opaque inputs, and ISA to
> Zero if there is also no coverage. (We keep ISA around when there
> is coverage because we use it to tweak alpha for coverage.)
>
> * Abandons solid white optimizations for the sake of simplicity
> (screen was the only mode that previous had solid white opts).
>
> Minor differences:
>
> * Inconsequential differences in opt flags (e.g. we now return
> kCanTweakAlphaForCoverage_OptFlag even when there is no coverage).
>
> * Src coeffs when the shader outputs 0.
>
> * IS2C vs IS2A when the secondary output is scalar.
>
> BUG=skia:
>
> Committed: https://skia.googlesource.com/skia/+/9a70920db22b6309c671f8e5d519bb95570e4414
TBR=egdaniel@google.com,bsalomon@google.com,cdalton@nvidia.com
NOPRESUBMIT=true
NOTREECHECKS=true
NOTRY=true
BUG=skia:
Review URL: https://codereview.chromium.org/1153993002
2015-05-23 00:55:26 +00:00
|
|
|
GrBlendCoeff fSrcCoeff;
|
|
|
|
GrBlendCoeff fDstCoeff;
|
2014-12-03 18:40:13 +00:00
|
|
|
|
|
|
|
typedef GrXPFactory INHERITED;
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|