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 GrXferProcessor_DEFINED
|
|
|
|
#define GrXferProcessor_DEFINED
|
|
|
|
|
2015-06-12 15:21:26 +00:00
|
|
|
#include "GrBlend.h"
|
2014-12-03 18:40:13 +00:00
|
|
|
#include "GrColor.h"
|
2014-12-11 21:15:13 +00:00
|
|
|
#include "GrProcessor.h"
|
2015-02-06 15:02:37 +00:00
|
|
|
#include "GrTexture.h"
|
2014-12-03 18:40:13 +00:00
|
|
|
#include "GrTypes.h"
|
|
|
|
#include "SkXfermode.h"
|
|
|
|
|
2015-04-29 18:18:05 +00:00
|
|
|
class GrShaderCaps;
|
|
|
|
class GrGLSLCaps;
|
2014-12-11 21:15:13 +00:00
|
|
|
class GrGLXferProcessor;
|
2014-12-09 19:15:43 +00:00
|
|
|
class GrProcOptInfo;
|
|
|
|
|
2015-04-29 21:17:00 +00:00
|
|
|
/**
|
|
|
|
* Barriers for blending. When a shader reads the dst directly, an Xfer barrier is sometimes
|
|
|
|
* required after a pixel has been written, before it can be safely read again.
|
|
|
|
*/
|
|
|
|
enum GrXferBarrierType {
|
|
|
|
kTexture_GrXferBarrierType, //<! Required when a shader reads and renders to the same texture.
|
2015-05-06 20:40:21 +00:00
|
|
|
kBlend_GrXferBarrierType, //<! Required by certain blend extensions.
|
2015-04-29 21:17:00 +00:00
|
|
|
};
|
|
|
|
|
2014-12-03 18:40:13 +00:00
|
|
|
/**
|
|
|
|
* GrXferProcessor is responsible for implementing the xfer mode that blends the src color and dst
|
2015-06-08 19:14:44 +00:00
|
|
|
* color, and for applying any coverage. It does this by emitting fragment shader code and
|
|
|
|
* controlling the fixed-function blend state. When dual-source blending is available, it may also
|
|
|
|
* write a seconday fragment shader output color. GrXferProcessor has two modes of operation:
|
|
|
|
*
|
|
|
|
* Dst read: When allowed by the backend API, or when supplied a texture of the destination, the
|
|
|
|
* GrXferProcessor may read the destination color. While operating in this mode, the subclass only
|
|
|
|
* provides shader code that blends the src and dst colors, and the base class applies coverage.
|
|
|
|
*
|
|
|
|
* No dst read: When not performing a dst read, the subclass is given full control of the fixed-
|
|
|
|
* function blend state and/or secondary output, and is responsible to apply coverage on its own.
|
2014-12-03 18:40:13 +00:00
|
|
|
*
|
|
|
|
* A GrXferProcessor is never installed directly into our draw state, but instead is created from a
|
|
|
|
* GrXPFactory once we have finalized the state of our draw.
|
|
|
|
*/
|
2014-12-11 21:15:13 +00:00
|
|
|
class GrXferProcessor : public GrProcessor {
|
2014-12-09 19:15:43 +00:00
|
|
|
public:
|
2015-05-26 16:49:05 +00:00
|
|
|
/**
|
|
|
|
* A texture that contains the dst pixel values and an integer coord offset from device space
|
|
|
|
* to the space of the texture. Depending on GPU capabilities a DstTexture may be used by a
|
|
|
|
* GrXferProcessor for blending in the fragment shader.
|
|
|
|
*/
|
|
|
|
class DstTexture {
|
|
|
|
public:
|
|
|
|
DstTexture() { fOffset.set(0, 0); }
|
|
|
|
|
|
|
|
DstTexture(const DstTexture& other) {
|
|
|
|
*this = other;
|
|
|
|
}
|
|
|
|
|
|
|
|
DstTexture(GrTexture* texture, const SkIPoint& offset)
|
|
|
|
: fTexture(SkSafeRef(texture))
|
|
|
|
, fOffset(offset) {
|
|
|
|
}
|
|
|
|
|
|
|
|
DstTexture& operator=(const DstTexture& other) {
|
|
|
|
fTexture.reset(SkSafeRef(other.fTexture.get()));
|
|
|
|
fOffset = other.fOffset;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
const SkIPoint& offset() const { return fOffset; }
|
|
|
|
|
|
|
|
void setOffset(const SkIPoint& offset) { fOffset = offset; }
|
|
|
|
void setOffset(int ox, int oy) { fOffset.set(ox, oy); }
|
|
|
|
|
|
|
|
GrTexture* texture() const { return fTexture.get(); }
|
|
|
|
|
|
|
|
GrTexture* setTexture(GrTexture* texture) {
|
|
|
|
fTexture.reset(SkSafeRef(texture));
|
|
|
|
return texture;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
SkAutoTUnref<GrTexture> fTexture;
|
|
|
|
SkIPoint fOffset;
|
|
|
|
};
|
|
|
|
|
2014-12-11 21:15:13 +00:00
|
|
|
/**
|
2015-02-06 15:02:37 +00:00
|
|
|
* Sets a unique key on the GrProcessorKeyBuilder calls onGetGLProcessorKey(...) to get the
|
|
|
|
* specific subclass's key.
|
|
|
|
*/
|
2015-04-28 15:48:20 +00:00
|
|
|
void getGLProcessorKey(const GrGLSLCaps& caps, GrProcessorKeyBuilder* b) const;
|
2014-12-11 21:15:13 +00:00
|
|
|
|
|
|
|
/** Returns a new instance of the appropriate *GL* implementation class
|
|
|
|
for the given GrXferProcessor; caller is responsible for deleting
|
|
|
|
the object. */
|
|
|
|
virtual GrGLXferProcessor* createGLInstance() const = 0;
|
|
|
|
|
2014-12-09 19:15:43 +00:00
|
|
|
/**
|
|
|
|
* Optimizations for blending / coverage that an OptDrawState should apply to itself.
|
|
|
|
*/
|
|
|
|
enum OptFlags {
|
|
|
|
/**
|
|
|
|
* The draw can be skipped completely.
|
|
|
|
*/
|
|
|
|
kSkipDraw_OptFlag = 0x1,
|
|
|
|
/**
|
2014-12-15 22:16:27 +00:00
|
|
|
* GrXferProcessor will ignore color, thus no need to provide
|
2014-12-09 19:15:43 +00:00
|
|
|
*/
|
2014-12-15 22:16:27 +00:00
|
|
|
kIgnoreColor_OptFlag = 0x2,
|
2014-12-09 19:15:43 +00:00
|
|
|
/**
|
2014-12-15 22:16:27 +00:00
|
|
|
* GrXferProcessor will ignore coverage, thus no need to provide
|
2014-12-09 19:15:43 +00:00
|
|
|
*/
|
2014-12-15 22:16:27 +00:00
|
|
|
kIgnoreCoverage_OptFlag = 0x4,
|
2014-12-15 20:38:53 +00:00
|
|
|
/**
|
|
|
|
* Clear color stages and override input color to that returned by getOptimizations
|
|
|
|
*/
|
|
|
|
kOverrideColor_OptFlag = 0x8,
|
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
|
|
|
/**
|
2015-02-13 20:11:00 +00:00
|
|
|
* Can tweak alpha for coverage. Currently this flag should only be used by a batch
|
|
|
|
*/
|
|
|
|
kCanTweakAlphaForCoverage_OptFlag = 0x20,
|
2014-12-09 19:15:43 +00:00
|
|
|
};
|
|
|
|
|
2015-07-08 18:26:37 +00:00
|
|
|
static const OptFlags kNone_OptFlags = (OptFlags)0;
|
|
|
|
|
2014-12-09 19:15:43 +00:00
|
|
|
GR_DECL_BITFIELD_OPS_FRIENDS(OptFlags);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Determines which optimizations (as described by the ptFlags above) can be performed by
|
|
|
|
* the draw with this xfer processor. If this function is called, the xfer processor may change
|
2014-12-15 20:38:53 +00:00
|
|
|
* its state to reflected the given blend optimizations. If the XP needs to see a specific input
|
|
|
|
* color to blend correctly, it will set the OverrideColor flag and the output parameter
|
|
|
|
* overrideColor will be the required value that should be passed into the XP.
|
2014-12-09 19:15:43 +00:00
|
|
|
* A caller who calls this function on a XP is required to honor the returned OptFlags
|
2014-12-15 20:38:53 +00:00
|
|
|
* and color values for its draw.
|
2014-12-09 19:15:43 +00:00
|
|
|
*/
|
2015-05-10 15:45:18 +00:00
|
|
|
OptFlags getOptimizations(const GrProcOptInfo& colorPOI,
|
|
|
|
const GrProcOptInfo& coveragePOI,
|
|
|
|
bool doesStencilWrite,
|
|
|
|
GrColor* overrideColor,
|
2015-05-19 16:29:46 +00:00
|
|
|
const GrCaps& caps);
|
2014-12-09 19:15:43 +00:00
|
|
|
|
2015-04-29 21:17:00 +00:00
|
|
|
/**
|
|
|
|
* Returns whether this XP will require an Xfer barrier on the given rt. If true, outBarrierType
|
|
|
|
* is updated to contain the type of barrier needed.
|
|
|
|
*/
|
|
|
|
bool willNeedXferBarrier(const GrRenderTarget* rt,
|
2015-05-19 16:29:46 +00:00
|
|
|
const GrCaps& caps,
|
2015-04-29 21:17:00 +00:00
|
|
|
GrXferBarrierType* outBarrierType) const;
|
|
|
|
|
2014-12-09 19:15:43 +00:00
|
|
|
struct BlendInfo {
|
2015-04-23 16:40:23 +00:00
|
|
|
void reset() {
|
2015-05-06 20:40:21 +00:00
|
|
|
fEquation = kAdd_GrBlendEquation;
|
2015-04-23 16:40:23 +00:00
|
|
|
fSrcBlend = kOne_GrBlendCoeff;
|
|
|
|
fDstBlend = kZero_GrBlendCoeff;
|
|
|
|
fBlendConstant = 0;
|
|
|
|
fWriteColor = true;
|
|
|
|
}
|
2014-12-22 15:35:52 +00:00
|
|
|
|
2015-05-11 18:21:14 +00:00
|
|
|
SkDEBUGCODE(SkString dump() const;)
|
|
|
|
|
2015-05-06 20:40:21 +00:00
|
|
|
GrBlendEquation fEquation;
|
|
|
|
GrBlendCoeff fSrcBlend;
|
|
|
|
GrBlendCoeff fDstBlend;
|
|
|
|
GrColor fBlendConstant;
|
|
|
|
bool fWriteColor;
|
2014-12-09 19:15:43 +00:00
|
|
|
};
|
|
|
|
|
2015-06-08 19:14:44 +00:00
|
|
|
void getBlendInfo(BlendInfo* blendInfo) const;
|
2014-12-09 19:15:43 +00:00
|
|
|
|
|
|
|
bool willReadDstColor() const { return fWillReadDstColor; }
|
|
|
|
|
2015-02-06 15:02:37 +00:00
|
|
|
/**
|
|
|
|
* Returns the texture to be used as the destination when reading the dst in the fragment
|
|
|
|
* shader. If the returned texture is NULL then the XP is either not reading the dst or we have
|
|
|
|
* extentions that support framebuffer fetching and thus don't need a copy of the dst texture.
|
|
|
|
*/
|
2015-05-26 16:49:05 +00:00
|
|
|
const GrTexture* getDstTexture() const { return fDstTexture.getTexture(); }
|
2015-02-06 15:02:37 +00:00
|
|
|
|
|
|
|
/**
|
2015-05-26 16:49:05 +00:00
|
|
|
* Returns the offset in device coords to use when accessing the dst texture to get the dst
|
|
|
|
* pixel color in the shader. This value is only valid if getDstTexture() != NULL.
|
2015-02-06 15:02:37 +00:00
|
|
|
*/
|
2015-05-26 16:49:05 +00:00
|
|
|
const SkIPoint& dstTextureOffset() const {
|
|
|
|
SkASSERT(this->getDstTexture());
|
|
|
|
return fDstTextureOffset;
|
2015-02-06 15:02:37 +00:00
|
|
|
}
|
|
|
|
|
2015-06-08 22:11:04 +00:00
|
|
|
/**
|
|
|
|
* If we are performing a dst read, returns whether the base class will use mixed samples to
|
|
|
|
* antialias the shader's final output. If not doing a dst read, the subclass is responsible
|
|
|
|
* for antialiasing and this returns false.
|
|
|
|
*/
|
|
|
|
bool dstReadUsesMixedSamples() const { return fDstReadUsesMixedSamples; }
|
|
|
|
|
2015-05-10 15:45:18 +00:00
|
|
|
/**
|
|
|
|
* Returns whether or not the XP will look at coverage when doing its blending.
|
|
|
|
*/
|
|
|
|
bool readsCoverage() const { return fReadsCoverage; }
|
|
|
|
|
2015-06-08 19:14:44 +00:00
|
|
|
/**
|
2014-12-11 21:15:13 +00:00
|
|
|
* Returns whether or not this xferProcossor will set a secondary output to be used with dual
|
|
|
|
* source blending.
|
|
|
|
*/
|
2015-06-08 19:14:44 +00:00
|
|
|
bool hasSecondaryOutput() const;
|
2014-12-11 21:15:13 +00:00
|
|
|
|
|
|
|
/** Returns true if this and other processor conservatively draw identically. It can only return
|
|
|
|
true when the two processor are of the same subclass (i.e. they return the same object from
|
|
|
|
from getFactory()).
|
|
|
|
|
|
|
|
A return value of true from isEqual() should not be used to test whether the processor would
|
|
|
|
generate the same shader code. To test for identical code generation use getGLProcessorKey*/
|
|
|
|
|
|
|
|
bool isEqual(const GrXferProcessor& that) const {
|
|
|
|
if (this->classID() != that.classID()) {
|
|
|
|
return false;
|
|
|
|
}
|
2015-02-06 15:02:37 +00:00
|
|
|
if (this->fWillReadDstColor != that.fWillReadDstColor) {
|
|
|
|
return false;
|
|
|
|
}
|
2015-05-10 15:45:18 +00:00
|
|
|
if (this->fReadsCoverage != that.fReadsCoverage) {
|
|
|
|
return false;
|
|
|
|
}
|
2015-05-26 16:49:05 +00:00
|
|
|
if (this->fDstTexture.getTexture() != that.fDstTexture.getTexture()) {
|
2015-02-06 15:02:37 +00:00
|
|
|
return false;
|
|
|
|
}
|
2015-05-26 16:49:05 +00:00
|
|
|
if (this->fDstTextureOffset != that.fDstTextureOffset) {
|
2015-02-06 15:02:37 +00:00
|
|
|
return false;
|
|
|
|
}
|
2015-06-08 22:11:04 +00:00
|
|
|
if (this->fDstReadUsesMixedSamples != that.fDstReadUsesMixedSamples) {
|
|
|
|
return false;
|
|
|
|
}
|
2014-12-11 21:15:13 +00:00
|
|
|
return this->onIsEqual(that);
|
|
|
|
}
|
|
|
|
|
2014-12-09 19:15:43 +00:00
|
|
|
protected:
|
2015-02-06 15:02:37 +00:00
|
|
|
GrXferProcessor();
|
2015-06-08 22:11:04 +00:00
|
|
|
GrXferProcessor(const DstTexture*, bool willReadDstColor, bool hasMixedSamples);
|
2014-12-09 19:15:43 +00:00
|
|
|
|
2015-02-06 15:02:37 +00:00
|
|
|
private:
|
2015-05-10 15:45:18 +00:00
|
|
|
virtual OptFlags onGetOptimizations(const GrProcOptInfo& colorPOI,
|
|
|
|
const GrProcOptInfo& coveragePOI,
|
|
|
|
bool doesStencilWrite,
|
|
|
|
GrColor* overrideColor,
|
2015-05-19 16:29:46 +00:00
|
|
|
const GrCaps& caps) = 0;
|
2015-05-10 15:45:18 +00:00
|
|
|
|
2014-12-09 19:15:43 +00:00
|
|
|
/**
|
2015-02-06 15:02:37 +00:00
|
|
|
* Sets a unique key on the GrProcessorKeyBuilder that is directly associated with this xfer
|
|
|
|
* processor's GL backend implementation.
|
2014-12-09 19:15:43 +00:00
|
|
|
*/
|
2015-04-28 15:48:20 +00:00
|
|
|
virtual void onGetGLProcessorKey(const GrGLSLCaps& caps,
|
2015-02-06 15:02:37 +00:00
|
|
|
GrProcessorKeyBuilder* b) const = 0;
|
2014-12-09 19:15:43 +00:00
|
|
|
|
2015-05-06 20:40:21 +00:00
|
|
|
/**
|
|
|
|
* If not using a texture barrier, retrieves whether the subclass will require a different type
|
|
|
|
* of barrier.
|
|
|
|
*/
|
|
|
|
virtual bool onWillNeedXferBarrier(const GrRenderTarget*,
|
2015-05-19 16:29:46 +00:00
|
|
|
const GrCaps&,
|
2015-05-06 20:40:21 +00:00
|
|
|
GrXferBarrierType* outBarrierType SK_UNUSED) const {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-04-23 16:40:23 +00:00
|
|
|
/**
|
2015-06-08 19:14:44 +00:00
|
|
|
* If we are not performing a dst read, returns whether the subclass will set a secondary
|
2015-06-08 22:11:04 +00:00
|
|
|
* output. When using dst reads, the base class controls the secondary output and this method
|
2015-06-08 19:14:44 +00:00
|
|
|
* will not be called.
|
|
|
|
*/
|
|
|
|
virtual bool onHasSecondaryOutput() const { return false; }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* If we are not performing a dst read, retrieves the fixed-function blend state required by the
|
2015-06-08 22:11:04 +00:00
|
|
|
* subclass. When using dst reads, the base class controls the fixed-function blend state and
|
|
|
|
* this method will not be called. The BlendInfo struct comes initialized to "no blending".
|
2015-04-23 16:40:23 +00:00
|
|
|
*/
|
|
|
|
virtual void onGetBlendInfo(BlendInfo*) const {}
|
|
|
|
|
2014-12-11 21:15:13 +00:00
|
|
|
virtual bool onIsEqual(const GrXferProcessor&) const = 0;
|
2014-12-03 18:40:13 +00:00
|
|
|
|
2015-02-06 15:02:37 +00:00
|
|
|
bool fWillReadDstColor;
|
2015-06-08 22:11:04 +00:00
|
|
|
bool fDstReadUsesMixedSamples;
|
2015-05-10 15:45:18 +00:00
|
|
|
bool fReadsCoverage;
|
2015-05-26 16:49:05 +00:00
|
|
|
SkIPoint fDstTextureOffset;
|
|
|
|
GrTextureAccess fDstTexture;
|
2014-12-09 19:15:43 +00:00
|
|
|
|
2014-12-03 18:40:13 +00:00
|
|
|
typedef GrFragmentProcessor INHERITED;
|
|
|
|
};
|
|
|
|
|
2014-12-09 19:15:43 +00:00
|
|
|
GR_MAKE_BITFIELD_OPS(GrXferProcessor::OptFlags);
|
|
|
|
|
2015-02-06 15:02:37 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2014-12-03 18:40:13 +00:00
|
|
|
/**
|
|
|
|
* We install a GrXPFactory (XPF) early on in the pipeline before all the final draw information is
|
|
|
|
* known (e.g. whether there is fractional pixel coverage, will coverage be 1 or 4 channel, is the
|
|
|
|
* draw opaque, etc.). Once the state of the draw is finalized, we use the XPF along with all the
|
|
|
|
* draw information to create a GrXferProcessor (XP) which can implement the desired blending for
|
|
|
|
* the draw.
|
|
|
|
*
|
|
|
|
* Before the XP is created, the XPF is able to answer queries about what functionality the XPs it
|
|
|
|
* creates will have. For example, can it create an XP that supports RGB coverage or will the XP
|
|
|
|
* blend with the destination color.
|
|
|
|
*/
|
2014-12-03 19:41:54 +00:00
|
|
|
class GrXPFactory : public SkRefCnt {
|
2014-12-03 18:40:13 +00:00
|
|
|
public:
|
2015-05-26 16:49:05 +00:00
|
|
|
typedef GrXferProcessor::DstTexture DstTexture;
|
2015-02-06 15:02:37 +00:00
|
|
|
GrXferProcessor* createXferProcessor(const GrProcOptInfo& colorPOI,
|
|
|
|
const GrProcOptInfo& coveragePOI,
|
2015-06-08 22:11:04 +00:00
|
|
|
bool hasMixedSamples,
|
2015-05-26 16:49:05 +00:00
|
|
|
const DstTexture*,
|
2015-05-19 16:29:46 +00:00
|
|
|
const GrCaps& caps) const;
|
2014-12-03 18:40:13 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* This function returns true if the GrXferProcessor generated from this factory will be able to
|
|
|
|
* correctly blend when using RGB coverage. The knownColor and knownColorFlags represent the
|
|
|
|
* final computed color from the color stages.
|
|
|
|
*/
|
|
|
|
virtual bool supportsRGBCoverage(GrColor knownColor, uint32_t knownColorFlags) const = 0;
|
|
|
|
|
2015-06-02 17:43:39 +00:00
|
|
|
/**
|
|
|
|
* Known color information after blending, but before accounting for any coverage.
|
|
|
|
*/
|
|
|
|
struct InvariantBlendedColor {
|
|
|
|
bool fWillBlendWithDst;
|
|
|
|
GrColor fKnownColor;
|
|
|
|
GrColorComponentFlags fKnownColorFlags;
|
2014-12-18 20:44:55 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2015-06-02 17:43:39 +00:00
|
|
|
* Returns information about the output color, produced by XPs from this factory, that will be
|
|
|
|
* known after blending. Note that we can conflate coverage and color, so the actual values
|
|
|
|
* written to pixels with partial coverage may not always seem consistent with the invariant
|
|
|
|
* information returned by this function.
|
2014-12-09 19:15:43 +00:00
|
|
|
*/
|
2015-06-02 17:43:39 +00:00
|
|
|
virtual void getInvariantBlendedColor(const GrProcOptInfo& colorPOI,
|
|
|
|
InvariantBlendedColor*) const = 0;
|
2014-12-09 19:15:43 +00:00
|
|
|
|
2015-05-26 16:49:05 +00:00
|
|
|
bool willNeedDstTexture(const GrCaps& caps, const GrProcOptInfo& colorPOI,
|
2015-06-08 22:11:04 +00:00
|
|
|
const GrProcOptInfo& coveragePOI, bool hasMixedSamples) const;
|
2014-12-22 15:35:52 +00:00
|
|
|
|
2014-12-05 20:58:28 +00:00
|
|
|
bool isEqual(const GrXPFactory& that) const {
|
|
|
|
if (this->classID() != that.classID()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return this->onIsEqual(that);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Helper for down-casting to a GrXPFactory subclass
|
|
|
|
*/
|
|
|
|
template <typename T> const T& cast() const { return *static_cast<const T*>(this); }
|
|
|
|
|
|
|
|
uint32_t classID() const { SkASSERT(kIllegalXPFClassID != fClassID); return fClassID; }
|
|
|
|
|
|
|
|
protected:
|
|
|
|
GrXPFactory() : fClassID(kIllegalXPFClassID) {}
|
|
|
|
|
|
|
|
template <typename XPF_SUBCLASS> void initClassID() {
|
|
|
|
static uint32_t kClassID = GenClassID();
|
|
|
|
fClassID = kClassID;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t fClassID;
|
|
|
|
|
2014-12-03 18:40:13 +00:00
|
|
|
private:
|
2015-05-19 16:29:46 +00:00
|
|
|
virtual 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-06-08 22:11:04 +00:00
|
|
|
bool hasMixedSamples,
|
2015-05-26 16:49:05 +00:00
|
|
|
const DstTexture*) const = 0;
|
2015-02-06 15:02:37 +00:00
|
|
|
/**
|
|
|
|
* Returns true if the XP generated by this factory will explicitly read dst in the fragment
|
|
|
|
* shader.
|
|
|
|
*/
|
2015-05-19 16:29:46 +00:00
|
|
|
virtual bool willReadDstColor(const GrCaps& caps,
|
2015-02-17 19:15:47 +00:00
|
|
|
const GrProcOptInfo& colorPOI,
|
2015-06-08 22:11:04 +00:00
|
|
|
const GrProcOptInfo& coveragePOI,
|
|
|
|
bool hasMixedSamples) const = 0;
|
2015-02-06 15:02:37 +00:00
|
|
|
|
2014-12-05 20:58:28 +00:00
|
|
|
virtual bool onIsEqual(const GrXPFactory&) const = 0;
|
|
|
|
|
|
|
|
static uint32_t GenClassID() {
|
|
|
|
// fCurrXPFactoryID has been initialized to kIllegalXPFactoryID. The
|
|
|
|
// atomic inc returns the old value not the incremented value. So we add
|
|
|
|
// 1 to the returned value.
|
|
|
|
uint32_t id = static_cast<uint32_t>(sk_atomic_inc(&gCurrXPFClassID)) + 1;
|
|
|
|
if (!id) {
|
|
|
|
SkFAIL("This should never wrap as it should only be called once for each GrXPFactory "
|
|
|
|
"subclass.");
|
|
|
|
}
|
|
|
|
return id;
|
|
|
|
}
|
|
|
|
|
|
|
|
enum {
|
|
|
|
kIllegalXPFClassID = 0,
|
|
|
|
};
|
|
|
|
static int32_t gCurrXPFClassID;
|
|
|
|
|
2014-12-03 18:40:13 +00:00
|
|
|
typedef GrProgramElement INHERITED;
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|