From 58136167fc596fb945b58b34f500cf370c0dec7c Mon Sep 17 00:00:00 2001 From: egdaniel Date: Tue, 20 Jan 2015 10:19:22 -0800 Subject: [PATCH] Do more cleanup from xp changes BUG=skia: Review URL: https://codereview.chromium.org/811903004 --- include/core/SkXfermode.h | 11 ++++------- src/core/SkXfermode.cpp | 32 ++++++++++++++------------------ src/gpu/SkGr.cpp | 9 +-------- 3 files changed, 19 insertions(+), 33 deletions(-) diff --git a/include/core/SkXfermode.h b/include/core/SkXfermode.h index 9d72cef..fc9ae21 100644 --- a/include/core/SkXfermode.h +++ b/include/core/SkXfermode.h @@ -207,14 +207,11 @@ public: */ virtual bool asXPFactory(GrXPFactory** xpf) const; - /** Returns true if the xfermode can be expressed as an xfer processor factory (xpFactory), - or a fragment processor. This helper calls the asCoeff(), asXPFactory(), - and asFragmentProcessor() virtuals. If the xfermode is NULL, it is treated as kSrcOver_Mode. - It is legal to call this with all params NULL to simply test the return value. - fp and xpf must both be NULL or all non-NULL. + /** 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 AsFragmentProcessorOrXPFactory(SkXfermode*, GrFragmentProcessor**, - GrXPFactory**); + static bool AsXPFactory(SkXfermode*, GrXPFactory**); SK_TO_STRING_PUREVIRT() SK_DECLARE_FLATTENABLE_REGISTRAR_GROUP() diff --git a/src/core/SkXfermode.cpp b/src/core/SkXfermode.cpp index 37dbd0d..ac1ebcc 100644 --- a/src/core/SkXfermode.cpp +++ b/src/core/SkXfermode.cpp @@ -687,30 +687,18 @@ bool SkXfermode::asXPFactory(GrXPFactory**) const { #if SK_SUPPORT_GPU #include "effects/GrPorterDuffXferProcessor.h" -bool SkXfermode::AsFragmentProcessorOrXPFactory(SkXfermode* xfermode, - GrFragmentProcessor** fp, - GrXPFactory** xpf) { - Coeff src, dst; - Mode mode; +bool SkXfermode::AsXPFactory(SkXfermode* xfermode, GrXPFactory** xpf) { if (NULL == xfermode) { - *xpf = GrPorterDuffXPFactory::Create(kSrcOver_Mode); - return true; - } else if (xfermode->asMode(&mode) && mode <= kLastCoeffMode) { - *xpf = GrPorterDuffXPFactory::Create(mode); - return true; - } else if (xfermode->asCoeff(&src, &dst)) { - *xpf = GrPorterDuffXPFactory::Create(src, dst); - return true; - } else if (xfermode->asXPFactory(xpf)) { + if (xpf) { + *xpf = GrPorterDuffXPFactory::Create(kSrcOver_Mode); + } return true; } else { - return xfermode->asFragmentProcessor(fp, NULL); + return xfermode->asXPFactory(xpf); } } #else -bool SkXfermode::AsFragmentProcessorOrXPFactory(SkXfermode* xfermode, - GrFragmentProcessor** fp, - GrXPFactory** xpf) { +bool SkXfermode::AsXPFactory(SkXfermode* xfermode, GrXPFactory** xpf) { return false; } #endif @@ -934,6 +922,14 @@ bool SkProcCoeffXfermode::asFragmentProcessor(GrFragmentProcessor** fp, } bool SkProcCoeffXfermode::asXPFactory(GrXPFactory** xp) const { + if (CANNOT_USE_COEFF != fSrcCoeff) { + if (xp) { + *xp = GrPorterDuffXPFactory::Create(fMode); + SkASSERT(*xp); + } + return true; + } + if (GrCustomXfermode::IsSupportedMode(fMode)) { if (xp) { *xp = GrCustomXfermode::CreateXPFactory(fMode); diff --git a/src/gpu/SkGr.cpp b/src/gpu/SkGr.cpp index 64142fe..a397280 100644 --- a/src/gpu/SkGr.cpp +++ b/src/gpu/SkGr.cpp @@ -514,15 +514,8 @@ void SkPaint2GrPaintNoShader(GrContext* context, const SkPaint& skPaint, GrColor grPaint->setAntiAlias(skPaint.isAntiAlias()); SkXfermode* mode = skPaint.getXfermode(); - GrFragmentProcessor* fragmentProcessor = NULL; GrXPFactory* xpFactory = NULL; - if (SkXfermode::AsFragmentProcessorOrXPFactory(mode, &fragmentProcessor, &xpFactory)) { - if (fragmentProcessor) { - SkASSERT(NULL == xpFactory); - grPaint->addColorProcessor(fragmentProcessor)->unref(); - xpFactory = GrPorterDuffXPFactory::Create(SkXfermode::kSrc_Mode); - } - } else { + if (!SkXfermode::AsXPFactory(mode, &xpFactory)) { // Fall back to src-over xpFactory = GrPorterDuffXPFactory::Create(SkXfermode::kSrcOver_Mode); } -- 2.7.4