diff options
author | 2015-11-23 13:20:41 -0800 | |
---|---|---|
committer | 2015-11-23 13:20:42 -0800 | |
commit | c4b72720e75313079212e69e46a5ef7c474b2305 (patch) | |
tree | b0bf74db86503bd22684bb3107613db4e6625244 /include | |
parent | 60ce86d4718dab83f33488ec41710ad6763fc7f8 (diff) |
Don't create a GXPFactory when blend is SrcOver
BUG=skia:
Review URL: https://codereview.chromium.org/1471053002
Diffstat (limited to 'include')
-rw-r--r-- | include/core/SkXfermode.h | 26 | ||||
-rw-r--r-- | include/gpu/GrPaint.h | 9 | ||||
-rw-r--r-- | include/gpu/GrXferProcessor.h | 8 | ||||
-rw-r--r-- | include/gpu/effects/GrCoverageSetOpXP.h | 5 | ||||
-rw-r--r-- | include/gpu/effects/GrPorterDuffXferProcessor.h | 31 |
5 files changed, 47 insertions, 32 deletions
diff --git a/include/core/SkXfermode.h b/include/core/SkXfermode.h index cb9557f92c..91268ab5f1 100644 --- a/include/core/SkXfermode.h +++ b/include/core/SkXfermode.h @@ -204,18 +204,26 @@ public: const GrFragmentProcessor* dst) const; /** A subclass may implement this factory function to work with the GPU backend. It is legal - to call this with xpf NULL to simply test the return value. If xpf is non-NULL then the - xfermode may optionally allocate a factory to return to the caller as *xpf. The caller - will install it and own a ref to it. Since the xfermode may or may not assign *xpf, the - caller should set *xpf to NULL beforehand. XferProcessors cannot use a background texture. - */ + to call this with xpf NULL to simply test the return value. If xpf is non-NULL then the + xfermode may optionally allocate a factory to return to the caller as *xpf. The caller + will install it and own a ref to it. Since the xfermode may or may not assign *xpf, the + caller should set *xpf to NULL beforehand. XferProcessors cannot use a background texture. + */ virtual bool asXPFactory(GrXPFactory** xpf) const; /** Returns true if the xfermode can be expressed as an xfer processor factory (xpFactory). - This helper calls the asXPFactory() virtual. If the xfermode is NULL, it is treated as - kSrcOver_Mode. It is legal to call this with xpf param NULL to simply test the return value. - */ - static bool AsXPFactory(SkXfermode*, GrXPFactory**); + This helper calls the asXPFactory() virtual. If the xfermode is NULL, it is treated as + kSrcOver_Mode. It is legal to call this with xpf param NULL to simply test the return value. + */ + static inline bool AsXPFactory(SkXfermode* xfermode, GrXPFactory** xpf) { + if (nullptr == xfermode) { + if (xpf) { + *xpf = nullptr; + } + return true; + } + return xfermode->asXPFactory(xpf); + } SK_TO_STRING_PUREVIRT() SK_DECLARE_FLATTENABLE_REGISTRAR_GROUP() diff --git a/include/gpu/GrPaint.h b/include/gpu/GrPaint.h index 9d0fe5575e..152cb51d7e 100644 --- a/include/gpu/GrPaint.h +++ b/include/gpu/GrPaint.h @@ -57,7 +57,7 @@ public: bool isAntiAlias() const { return fAntiAlias; } const GrXPFactory* setXPFactory(const GrXPFactory* xpFactory) { - fXPFactory.reset(SkRef(xpFactory)); + fXPFactory.reset(SkSafeRef(xpFactory)); return xpFactory; } @@ -100,10 +100,7 @@ public: this->numCoverageFragmentProcessors(); } const GrXPFactory* getXPFactory() const { - if (!fXPFactory) { - fXPFactory.reset(GrPorterDuffXPFactory::Create(SkXfermode::kSrc_Mode)); - } - return fXPFactory.get(); + return fXPFactory; } const GrFragmentProcessor* getColorFragmentProcessor(int i) const { @@ -127,7 +124,7 @@ public: fCoverageFragmentProcessors[i]->ref(); } - fXPFactory.reset(SkRef(paint.getXPFactory())); + fXPFactory.reset(SkSafeRef(paint.getXPFactory())); return *this; } diff --git a/include/gpu/GrXferProcessor.h b/include/gpu/GrXferProcessor.h index 4accbc84fa..64a0e1ab55 100644 --- a/include/gpu/GrXferProcessor.h +++ b/include/gpu/GrXferProcessor.h @@ -316,14 +316,6 @@ public: bool hasMixedSamples, const DstTexture*, const GrCaps& caps) const; - - /** - * 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; - /** * Known color information after blending, but before accounting for any coverage. */ diff --git a/include/gpu/effects/GrCoverageSetOpXP.h b/include/gpu/effects/GrCoverageSetOpXP.h index 8511074cbd..a17cf81232 100644 --- a/include/gpu/effects/GrCoverageSetOpXP.h +++ b/include/gpu/effects/GrCoverageSetOpXP.h @@ -23,11 +23,6 @@ class GrCoverageSetOpXPFactory : public GrXPFactory { public: static GrXPFactory* Create(SkRegion::Op regionOp, bool invertCoverage = false); - bool supportsRGBCoverage(GrColor /*knownColor*/, - uint32_t /*knownColorFlags*/) const override { - return true; - } - void getInvariantBlendedColor(const GrProcOptInfo& colorPOI, GrXPFactory::InvariantBlendedColor*) const override; diff --git a/include/gpu/effects/GrPorterDuffXferProcessor.h b/include/gpu/effects/GrPorterDuffXferProcessor.h index d297e32908..3dc503305f 100644 --- a/include/gpu/effects/GrPorterDuffXferProcessor.h +++ b/include/gpu/effects/GrPorterDuffXferProcessor.h @@ -18,13 +18,36 @@ class GrPorterDuffXPFactory : public GrXPFactory { public: static GrXPFactory* Create(SkXfermode::Mode mode); - bool supportsRGBCoverage(GrColor /*knownColor*/, uint32_t /*knownColorFlags*/) const override { - return true; - } - void getInvariantBlendedColor(const GrProcOptInfo& colorPOI, GrXPFactory::InvariantBlendedColor*) const override; + static GrXferProcessor* CreateSrcOverXferProcessor(const GrCaps& caps, + const GrProcOptInfo& colorPOI, + const GrProcOptInfo& coveragePOI, + bool hasMixedSamples, + const GrXferProcessor::DstTexture*); + + static inline void SrcOverInvariantBlendedColor( + GrColor inputColor, + GrColorComponentFlags validColorFlags, + bool isOpaque, + GrXPFactory::InvariantBlendedColor* blendedColor) { + if (!isOpaque) { + blendedColor->fWillBlendWithDst = true; + blendedColor->fKnownColorFlags = kNone_GrColorComponentFlags; + return; + } + blendedColor->fWillBlendWithDst = false; + + blendedColor->fKnownColor = inputColor; + blendedColor->fKnownColorFlags = validColorFlags; + } + + static bool SrcOverWillNeedDstTexture(const GrCaps& caps, + const GrProcOptInfo& colorPOI, + const GrProcOptInfo& coveragePOI, + bool hasMixedSamples); + private: GrPorterDuffXPFactory(SkXfermode::Mode); |