8 #ifndef GrXferProcessor_DEFINED
9 #define GrXferProcessor_DEFINED
13 #include "GrProcessor.h"
14 #include "GrTexture.h"
16 #include "SkXfermode.h"
20 class GrGLSLXferProcessor;
22 struct GrPipelineOptimizations;
28 enum GrXferBarrierType {
29 kNone_GrXferBarrierType = 0,
30 kTexture_GrXferBarrierType,
31 kBlend_GrXferBarrierType,
34 GR_STATIC_ASSERT(
SkToBool(kNone_GrXferBarrierType) ==
false);
68 : fTexture(SkSafeRef(texture))
73 fTexture.reset(SkSafeRef(other.fTexture.get()));
74 fOffset = other.fOffset;
78 const SkIPoint& offset()
const {
return fOffset; }
80 void setOffset(
const SkIPoint& offset) { fOffset = offset; }
81 void setOffset(
int ox,
int oy) { fOffset.
set(ox, oy); }
83 GrTexture* texture()
const {
return fTexture.get(); }
86 fTexture.reset(SkSafeRef(texture));
134 GR_DECL_BITFIELD_OPS_FRIENDS(
OptFlags);
146 bool doesStencilWrite,
147 GrColor* overrideColor,
148 const GrCaps& caps)
const;
158 fEquation = kAdd_GrBlendEquation;
159 fSrcBlend = kOne_GrBlendCoeff;
160 fDstBlend = kZero_GrBlendCoeff;
167 GrBlendEquation fEquation;
168 GrBlendCoeff fSrcBlend;
169 GrBlendCoeff fDstBlend;
170 GrColor fBlendConstant;
174 void getBlendInfo(
BlendInfo* blendInfo)
const;
176 bool willReadDstColor()
const {
return fWillReadDstColor; }
191 return fDstTextureOffset;
216 if (this->classID() != that.classID()) {
219 if (this->fWillReadDstColor != that.fWillReadDstColor) {
222 if (this->fDstTexture.getTexture() != that.fDstTexture.getTexture()) {
225 if (this->fDstTextureOffset != that.fDstTextureOffset) {
228 if (this->fDstReadUsesMixedSamples != that.fDstReadUsesMixedSamples) {
231 return this->onIsEqual(that);
236 GrXferProcessor(
const DstTexture*,
bool willReadDstColor,
bool hasMixedSamples);
241 virtual OptFlags onGetOptimizations(
const GrPipelineOptimizations& optimizations,
242 bool doesStencilWrite,
243 GrColor* overrideColor,
244 const GrCaps& caps)
const = 0;
259 return kNone_GrXferBarrierType;
278 bool fWillReadDstColor;
279 bool fDstReadUsesMixedSamples;
304 GrXferProcessor* createXferProcessor(
const GrPipelineOptimizations& optimizations,
305 bool hasMixedSamples,
307 const GrCaps& caps)
const;
312 bool fWillBlendWithDst;
314 GrColorComponentFlags fKnownColorFlags;
326 bool willNeedDstTexture(
const GrCaps& caps,
const GrPipelineOptimizations& optimizations)
const;
329 if (this->classID() != that.classID()) {
332 return this->onIsEqual(that);
338 template <
typename T>
const T&
cast()
const {
return *
static_cast<const T*
>(
this); }
340 uint32_t classID()
const { SkASSERT(kIllegalXPFClassID != fClassID);
return fClassID; }
345 template <
typename XPF_SUBCLASS>
void initClassID() {
346 static uint32_t kClassID = GenClassID();
354 const GrPipelineOptimizations& optimizations,
355 bool hasMixedSamples,
356 const DstTexture*)
const = 0;
358 virtual bool onIsEqual(
const GrXPFactory&)
const = 0;
360 bool willReadDstColor(
const GrCaps&,
const GrPipelineOptimizations&)
const;
367 static uint32_t GenClassID() {
371 uint32_t
id =
static_cast<uint32_t
>(sk_atomic_inc(&gCurrXPFClassID)) + 1;
373 SkFAIL(
"This should never wrap as it should only be called once for each GrXPFactory "
380 kIllegalXPFClassID = 0,
382 static int32_t gCurrXPFClassID;
Used to represent a texture that is required by a GrProcessor.
Definition: GrTextureAccess.h:21
void notifyRefCntIsZero() const final
This will be called when the ref cnt is zero.
Definition: GrXferProcessor.h:239
const SkIPoint & dstTextureOffset() const
Returns the offset in device coords to use when accessing the dst texture to get the dst pixel color ...
Definition: GrXferProcessor.h:189
const GrTexture * getDstTexture() const
Returns the texture to be used as the destination when reading the dst in the fragment shader...
Definition: GrXferProcessor.h:183
Provides custom fragment shader code.
Definition: GrFragmentProcessor.h:24
Represents the capabilities of a GrContext.
Definition: GrCaps.h:130
Can tweak alpha for coverage.
Definition: GrXferProcessor.h:129
Clear color stages and override input color to that returned by getOptimizations. ...
Definition: GrXferProcessor.h:125
const T & cast() const
Helper for down-casting to a GrXPFactory subclass.
Definition: GrXferProcessor.h:338
GrXferProcessor is responsible for implementing the xfer mode that blends the src color and dst color...
Definition: GrXferProcessor.h:52
Used by processors to build their keys.
Definition: GrProcessor.h:28
virtual void onGetGLSLProcessorKey(const GrGLSLCaps &caps, GrProcessorKeyBuilder *b) const =0
Sets a unique key on the GrProcessorKeyBuilder that is directly associated with this xfer processor's...
OptFlags
Optimizations for blending / coverage that an OptDrawState should apply to itself.
Definition: GrXferProcessor.h:109
Definition: SkRefCnt.h:135
bool isEqual(const GrXferProcessor &that) const
Returns true if this and other processor conservatively draw identically.
Definition: GrXferProcessor.h:215
A texture that contains the dst pixel values and an integer coord offset from device space to the spa...
Definition: GrXferProcessor.h:59
The draw can be skipped completely.
Definition: GrXferProcessor.h:113
void getGLSLProcessorKey(const GrGLSLCaps &caps, GrProcessorKeyBuilder *b) const
Sets a unique key on the GrProcessorKeyBuilder calls onGetGLSLProcessorKey(...) to get the specific s...
OptFlags getOptimizations(const GrPipelineOptimizations &optimizations, bool doesStencilWrite, GrColor *overrideColor, const GrCaps &caps) const
Determines which optimizations (as described by the ptFlags above) can be performed by the draw with ...
#define SkToBool(cond)
Returns 0 or 1 based on the condition.
Definition: SkTypes.h:287
Known color information after blending, but before accounting for any coverage.
Definition: GrXferProcessor.h:311
virtual void getInvariantBlendedColor(const GrProcOptInfo &colorPOI, InvariantBlendedColor *) const =0
Returns information about the output color, produced by XPs from this factory, that will be known aft...
Base class for GrProcessor.
Definition: GrProgramElement.h:44
virtual GrXferBarrierType onXferBarrier(const GrRenderTarget *, const GrCaps &) const
Determines the type of barrier (if any) required by the subclass.
Definition: GrXferProcessor.h:258
bool dstReadUsesMixedSamples() const
If we are performing a dst read, returns whether the base class will use mixed samples to antialias t...
Definition: GrXferProcessor.h:199
virtual bool onHasSecondaryOutput() const
If we are not performing a dst read, returns whether the subclass will set a secondary output...
Definition: GrXferProcessor.h:267
virtual void onGetBlendInfo(BlendInfo *) const
If we are not performing a dst read, retrieves the fixed-function blend state required by the subclas...
Definition: GrXferProcessor.h:274
GrXferProcessor will ignore coverage, thus no need to provide.
Definition: GrXferProcessor.h:121
virtual GrGLSLXferProcessor * createGLSLInstance() const =0
Returns a new instance of the appropriate GL implementation class for the given GrXferProcessor; call...
virtual bool onWillReadDstColor(const GrCaps &, const GrPipelineOptimizations &) const =0
Returns true if the XP generated by this factory will explicitly read dst in the fragment shader...
GrXferBarrierType xferBarrierType(const GrRenderTarget *rt, const GrCaps &caps) const
Returns whether this XP will require an Xfer barrier on the given rt.
Provides custom shader code to the Ganesh shading pipeline.
Definition: GrProcessor.h:60
Definition: GrXferProcessor.h:156
GrRenderTarget represents a 2D buffer of pixels that can be rendered to.
Definition: GrRenderTarget.h:26
void set(int32_t x, int32_t y)
Set the x and y values of the point.
Definition: SkPoint.h:65
Definition: GrTexture.h:19
SkIPoint holds two 32 bit integer coordinates.
Definition: SkPoint.h:40
We install a GrXPFactory (XPF) early on in the pipeline before all the final draw information is know...
Definition: GrXferProcessor.h:301
Light weight class for managing strings.
Definition: SkString.h:121
bool hasSecondaryOutput() const
Returns whether or not this xferProcossor will set a secondary output to be used with dual source ble...
GrXferProcessor will ignore color, thus no need to provide.
Definition: GrXferProcessor.h:117