Remove SkBlendImageFilter, and all tests. Its functionality has been subsumed by SkXfermodeImageFilter.

R=robertphillips@google.com

Review URL: https://codereview.chromium.org/21404002

git-svn-id: http://skia.googlecode.com/svn/trunk@10482 2bbb7eff-a529-9590-31e7-b0007b416f81
This commit is contained in:
senorblanco@chromium.org 2013-08-01 14:59:05 +00:00
parent 8743b8f2a5
commit 350b4d50ea
9 changed files with 3 additions and 710 deletions

View File

@ -1,196 +0,0 @@
/*
* Copyright 2013 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include "SkBenchmark.h"
#include "SkBitmapSource.h"
#include "SkBlendImageFilter.h"
#include "SkCanvas.h"
#include "SkDevice.h"
#define FILTER_WIDTH 256
#define FILTER_HEIGHT 256
class BlendBaseBench : public SkBenchmark {
public:
BlendBaseBench(void* param) : INHERITED(param), fInitialized(false) {
}
protected:
virtual void onPreDraw() SK_OVERRIDE {
if (!fInitialized) {
make_bitmap();
make_checkerboard();
fInitialized = true;
}
}
void drawClippedBitmap(SkCanvas* canvas, const SkPaint& paint, int x) {
canvas->save();
canvas->clipRect(SkRect::MakeXYWH(SkIntToScalar(x), 0,
SkIntToScalar(fBitmap.width()), SkIntToScalar(fBitmap.height())));
canvas->drawBitmap(fBitmap, SkIntToScalar(x), 0, &paint);
canvas->restore();
}
void make_bitmap() {
fBitmap.setConfig(SkBitmap::kARGB_8888_Config, FILTER_WIDTH, FILTER_HEIGHT);
fBitmap.allocPixels();
SkDevice device(fBitmap);
SkCanvas canvas(&device);
canvas.clear(0x00000000);
SkPaint paint;
paint.setAntiAlias(true);
paint.setColor(0xD000D000);
paint.setTextSize(SkIntToScalar(96));
const char* str = "e";
canvas.drawText(str, strlen(str), SkIntToScalar(15), SkIntToScalar(65), paint);
}
void make_checkerboard() {
fCheckerboard.setConfig(SkBitmap::kARGB_8888_Config, FILTER_WIDTH, FILTER_HEIGHT);
fCheckerboard.allocPixels();
SkDevice device(fCheckerboard);
SkCanvas canvas(&device);
canvas.clear(0x00000000);
SkPaint darkPaint;
darkPaint.setColor(0xFF404040);
SkPaint lightPaint;
lightPaint.setColor(0xFFA0A0A0);
for (int y = 0; y < FILTER_HEIGHT; y += 16) {
for (int x = 0; x < FILTER_WIDTH; x += 16) {
canvas.save();
canvas.translate(SkIntToScalar(x), SkIntToScalar(y));
canvas.drawRect(SkRect::MakeXYWH(0, 0, 8, 8), darkPaint);
canvas.drawRect(SkRect::MakeXYWH(8, 0, 8, 8), lightPaint);
canvas.drawRect(SkRect::MakeXYWH(0, 8, 8, 8), lightPaint);
canvas.drawRect(SkRect::MakeXYWH(8, 8, 8, 8), darkPaint);
canvas.restore();
}
}
}
typedef SkBenchmark INHERITED;
SkBitmap fBitmap, fCheckerboard;
bool fInitialized;
};
class BlendNormalBench : public BlendBaseBench {
public:
BlendNormalBench(void* param) : INHERITED(param) {
}
protected:
virtual const char* onGetName() SK_OVERRIDE {
return "blend_normal";
}
virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE {
SkPaint paint;
SkAutoTUnref<SkImageFilter> background(SkNEW_ARGS(SkBitmapSource, (fCheckerboard)));
paint.setImageFilter(SkNEW_ARGS(SkBlendImageFilter,
(SkBlendImageFilter::kNormal_Mode, background)))->unref();
drawClippedBitmap(canvas, paint, 0);
}
private:
typedef BlendBaseBench INHERITED;
};
class BlendMultiplyBench : public BlendBaseBench {
public:
BlendMultiplyBench(void* param) : INHERITED(param) {
}
protected:
virtual const char* onGetName() SK_OVERRIDE {
return "blend_multiply";
}
virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE {
SkPaint paint;
SkAutoTUnref<SkImageFilter> background(SkNEW_ARGS(SkBitmapSource, (fCheckerboard)));
paint.setImageFilter(SkNEW_ARGS(SkBlendImageFilter,
(SkBlendImageFilter::kMultiply_Mode, background)))->unref();
drawClippedBitmap(canvas, paint, 100);
}
private:
typedef BlendBaseBench INHERITED;
};
class BlendScreenBench : public BlendBaseBench {
public:
BlendScreenBench(void* param) : INHERITED(param) {
}
protected:
virtual const char* onGetName() SK_OVERRIDE {
return "blend_screen";
}
virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE {
SkPaint paint;
SkAutoTUnref<SkImageFilter> background(SkNEW_ARGS(SkBitmapSource, (fCheckerboard)));
paint.setImageFilter(SkNEW_ARGS(SkBlendImageFilter,
(SkBlendImageFilter::kScreen_Mode, background)))->unref();
drawClippedBitmap(canvas, paint, 200);
}
private:
typedef BlendBaseBench INHERITED;
};
class BlendDarkenBench : public BlendBaseBench {
public:
BlendDarkenBench(void* param) : INHERITED(param) {
}
protected:
virtual const char* onGetName() SK_OVERRIDE {
return "blend_darken";
}
virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE {
SkPaint paint;
SkAutoTUnref<SkImageFilter> background(SkNEW_ARGS(SkBitmapSource, (fCheckerboard)));
paint.setImageFilter(SkNEW_ARGS(SkBlendImageFilter,
(SkBlendImageFilter::kDarken_Mode, background)))->unref();
drawClippedBitmap(canvas, paint, 300);
}
private:
typedef BlendBaseBench INHERITED;
};
class BlendLightenBench : public BlendBaseBench {
public:
BlendLightenBench(void* param) : INHERITED(param) {
}
protected:
virtual const char* onGetName() SK_OVERRIDE {
return "blend_lighten";
}
virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE {
SkPaint paint;
SkAutoTUnref<SkImageFilter> background(SkNEW_ARGS(SkBitmapSource, (fCheckerboard)));
paint.setImageFilter(SkNEW_ARGS(SkBlendImageFilter,
(SkBlendImageFilter::kLighten_Mode, background)))->unref();
drawClippedBitmap(canvas, paint, 400);
}
private:
typedef BlendBaseBench INHERITED;
};
///////////////////////////////////////////////////////////////////////////////
DEF_BENCH( return new BlendNormalBench(p); )
DEF_BENCH( return new BlendMultiplyBench(p); )
DEF_BENCH( return new BlendScreenBench(p); )
DEF_BENCH( return new BlendDarkenBench(p); )
DEF_BENCH( return new BlendLightenBench(p); )

View File

@ -1,106 +0,0 @@
/*
* Copyright 2012 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include "gm.h"
#include "SkBlendImageFilter.h"
#include "SkBitmapSource.h"
namespace skiagm {
class ImageBlendGM : public GM {
public:
ImageBlendGM() : fInitialized(false) {
this->setBGColor(0xFF000000);
}
protected:
virtual SkString onShortName() {
return SkString("blend");
}
void make_bitmap() {
fBitmap.setConfig(SkBitmap::kARGB_8888_Config, 80, 80);
fBitmap.allocPixels();
SkDevice device(fBitmap);
SkCanvas canvas(&device);
canvas.clear(0x00000000);
SkPaint paint;
paint.setAntiAlias(true);
paint.setColor(0xD000D000);
paint.setTextSize(SkIntToScalar(96));
const char* str = "e";
canvas.drawText(str, strlen(str), SkIntToScalar(15), SkIntToScalar(65), paint);
}
void make_checkerboard() {
fCheckerboard.setConfig(SkBitmap::kARGB_8888_Config, 80, 80);
fCheckerboard.allocPixels();
SkDevice device(fCheckerboard);
SkCanvas canvas(&device);
canvas.clear(0x00000000);
SkPaint darkPaint;
darkPaint.setColor(0xFF404040);
SkPaint lightPaint;
lightPaint.setColor(0xFFA0A0A0);
for (int y = 0; y < 80; y += 16) {
for (int x = 0; x < 80; x += 16) {
canvas.save();
canvas.translate(SkIntToScalar(x), SkIntToScalar(y));
canvas.drawRect(SkRect::MakeXYWH(0, 0, 8, 8), darkPaint);
canvas.drawRect(SkRect::MakeXYWH(8, 0, 8, 8), lightPaint);
canvas.drawRect(SkRect::MakeXYWH(0, 8, 8, 8), lightPaint);
canvas.drawRect(SkRect::MakeXYWH(8, 8, 8, 8), darkPaint);
canvas.restore();
}
}
}
virtual SkISize onISize() {
return make_isize(500, 100);
}
void drawClippedBitmap(SkCanvas* canvas, const SkPaint& paint, int x) {
canvas->save();
canvas->clipRect(SkRect::MakeXYWH(SkIntToScalar(x), 0,
SkIntToScalar(fBitmap.width()), SkIntToScalar(fBitmap.height())));
canvas->drawBitmap(fBitmap, SkIntToScalar(x), 0, &paint);
canvas->restore();
}
virtual void onDraw(SkCanvas* canvas) {
if (!fInitialized) {
make_bitmap();
make_checkerboard();
fInitialized = true;
}
canvas->clear(0x00000000);
SkPaint paint;
SkAutoTUnref<SkImageFilter> background(SkNEW_ARGS(SkBitmapSource, (fCheckerboard)));
paint.setImageFilter(SkNEW_ARGS(SkBlendImageFilter, (SkBlendImageFilter::kNormal_Mode, background)))->unref();
drawClippedBitmap(canvas, paint, 0);
paint.setImageFilter(SkNEW_ARGS(SkBlendImageFilter, (SkBlendImageFilter::kMultiply_Mode, background)))->unref();
drawClippedBitmap(canvas, paint, 100);
paint.setImageFilter(SkNEW_ARGS(SkBlendImageFilter, (SkBlendImageFilter::kScreen_Mode, background)))->unref();
drawClippedBitmap(canvas, paint, 200);
paint.setImageFilter(SkNEW_ARGS(SkBlendImageFilter, (SkBlendImageFilter::kDarken_Mode, background)))->unref();
drawClippedBitmap(canvas, paint, 300);
paint.setImageFilter(SkNEW_ARGS(SkBlendImageFilter, (SkBlendImageFilter::kLighten_Mode, background)))->unref();
drawClippedBitmap(canvas, paint, 400);
}
private:
typedef GM INHERITED;
SkBitmap fBitmap, fCheckerboard;
bool fInitialized;
};
//////////////////////////////////////////////////////////////////////////////
static GM* MyFactory(void*) { return new ImageBlendGM; }
static GMRegistry reg(MyFactory);
}

View File

@ -8,13 +8,13 @@
#include "gm.h"
#include "SkBitmapSource.h"
#include "SkBlendImageFilter.h"
#include "SkBlurImageFilter.h"
#include "SkColorFilter.h"
#include "SkColorMatrixFilter.h"
#include "SkColorFilterImageFilter.h"
#include "SkMergeImageFilter.h"
#include "SkMorphologyImageFilter.h"
#include "SkXfermodeImageFilter.h"
#include "SkTestImageFilters.h"
@ -74,7 +74,8 @@ protected:
SkAutoTUnref<SkColorFilter> matrixFilter(new SkColorMatrixFilter(matrix));
SkAutoTUnref<SkImageFilter> colorMorph(SkColorFilterImageFilter::Create(matrixFilter, morph));
SkAutoTUnref<SkImageFilter> blendColor(new SkBlendImageFilter(SkBlendImageFilter::kNormal_Mode, colorMorph));
SkAutoTUnref<SkXfermode> mode(SkXfermode::Create(SkXfermode::kSrcOver_Mode));
SkAutoTUnref<SkImageFilter> blendColor(new SkXfermodeImageFilter(mode, colorMorph));
SkPaint paint;
paint.setImageFilter(blendColor);

View File

@ -10,7 +10,6 @@
'../bench/BitmapBench.cpp',
'../bench/BitmapRectBench.cpp',
'../bench/BitmapScaleBench.cpp',
'../bench/BlendBench.cpp',
'../bench/BlurBench.cpp',
'../bench/BlurImageFilterBench.cpp',
'../bench/BlurRectBench.cpp',

View File

@ -13,7 +13,6 @@
'<(skia_src_path)/effects/SkAvoidXfermode.cpp',
'<(skia_src_path)/effects/SkBicubicImageFilter.cpp',
'<(skia_src_path)/effects/SkBitmapSource.cpp',
'<(skia_src_path)/effects/SkBlendImageFilter.cpp',
'<(skia_src_path)/effects/SkBlurDrawLooper.cpp',
'<(skia_src_path)/effects/SkBlurMask.cpp',
'<(skia_src_path)/effects/SkBlurMask.h',
@ -79,7 +78,6 @@
'<(skia_include_path)/effects/SkArithmeticMode.h',
'<(skia_include_path)/effects/SkAvoidXfermode.h',
'<(skia_include_path)/effects/SkBitmapSource.h',
'<(skia_include_path)/effects/SkBlendImageFilter.h',
'<(skia_include_path)/effects/SkBlurDrawLooper.h',
'<(skia_include_path)/effects/SkBlurImageFilter.h',
'<(skia_include_path)/effects/SkBlurMaskFilter.h',

View File

@ -16,7 +16,6 @@
'../gm/bitmaprecttest.cpp',
'../gm/bitmapscroll.cpp',
'../gm/bleed.cpp',
'../gm/blend.cpp',
'../gm/blurs.cpp',
'../gm/blurquickreject.cpp',
'../gm/blurrect.cpp',

View File

@ -1,51 +0,0 @@
/*
* Copyright 2012 The Android Open Source Project
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#ifndef SkBlendImageFilter_DEFINED
#define SkBlendImageFilter_DEFINED
#include "SkImageFilter.h"
#include "SkBitmap.h"
class SK_API SkBlendImageFilter : public SkImageFilter {
public:
enum Mode {
kNormal_Mode,
kMultiply_Mode,
kScreen_Mode,
kDarken_Mode,
kLighten_Mode,
};
SkBlendImageFilter(Mode mode, SkImageFilter* background, SkImageFilter* foreground = NULL);
~SkBlendImageFilter();
SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkBlendImageFilter)
virtual bool onFilterImage(Proxy* proxy,
const SkBitmap& src,
const SkMatrix& ctm,
SkBitmap* dst,
SkIPoint* offset) SK_OVERRIDE;
#if SK_SUPPORT_GPU
virtual bool canFilterImageGPU() const SK_OVERRIDE { return true; }
virtual bool filterImageGPU(Proxy* proxy, const SkBitmap& src, SkBitmap* result,
SkIPoint* offset) SK_OVERRIDE;
#endif
protected:
explicit SkBlendImageFilter(SkFlattenableReadBuffer& buffer);
virtual void flatten(SkFlattenableWriteBuffer&) const SK_OVERRIDE;
private:
Mode fMode;
typedef SkImageFilter INHERITED;
SkImageFilter* getBackgroundInput() { return getInput(0); }
SkImageFilter* getForegroundInput() { return getInput(1); }
};
#endif

View File

@ -1,349 +0,0 @@
/*
* Copyright 2012 The Android Open Source Project
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include "SkBlendImageFilter.h"
#include "SkCanvas.h"
#include "SkColorPriv.h"
#include "SkFlattenableBuffers.h"
#if SK_SUPPORT_GPU
#include "GrContext.h"
#include "gl/GrGLEffect.h"
#include "gl/GrGLEffectMatrix.h"
#include "GrTBackendEffectFactory.h"
#include "SkImageFilterUtils.h"
#endif
namespace {
SkXfermode::Mode modeToXfermode(SkBlendImageFilter::Mode mode) {
switch (mode) {
case SkBlendImageFilter::kNormal_Mode:
return SkXfermode::kSrcOver_Mode;
case SkBlendImageFilter::kMultiply_Mode:
return SkXfermode::kMultiply_Mode;
case SkBlendImageFilter::kScreen_Mode:
return SkXfermode::kScreen_Mode;
case SkBlendImageFilter::kDarken_Mode:
return SkXfermode::kDarken_Mode;
case SkBlendImageFilter::kLighten_Mode:
return SkXfermode::kLighten_Mode;
}
SkASSERT(0);
return SkXfermode::kSrcOver_Mode;
}
};
///////////////////////////////////////////////////////////////////////////////
SkBlendImageFilter::SkBlendImageFilter(SkBlendImageFilter::Mode mode, SkImageFilter* background, SkImageFilter* foreground)
: INHERITED(background, foreground), fMode(mode)
{
}
SkBlendImageFilter::~SkBlendImageFilter() {
}
SkBlendImageFilter::SkBlendImageFilter(SkFlattenableReadBuffer& buffer)
: INHERITED(buffer)
{
fMode = (SkBlendImageFilter::Mode) buffer.readInt();
}
void SkBlendImageFilter::flatten(SkFlattenableWriteBuffer& buffer) const {
this->INHERITED::flatten(buffer);
buffer.writeInt((int) fMode);
}
bool SkBlendImageFilter::onFilterImage(Proxy* proxy,
const SkBitmap& src,
const SkMatrix& ctm,
SkBitmap* dst,
SkIPoint* offset) {
SkBitmap background, foreground = src;
SkImageFilter* backgroundInput = getBackgroundInput();
SkImageFilter* foregroundInput = getForegroundInput();
SkASSERT(NULL != backgroundInput);
SkIPoint backgroundOffset = SkIPoint::Make(0, 0);
if (!backgroundInput->filterImage(proxy, src, ctm, &background, &backgroundOffset)) {
return false;
}
SkIPoint foregroundOffset = SkIPoint::Make(0, 0);
if (foregroundInput &&
!foregroundInput->filterImage(proxy, src, ctm, &foreground, &foregroundOffset)) {
return false;
}
SkAutoLockPixels alp_foreground(foreground), alp_background(background);
if (!foreground.getPixels() || !background.getPixels()) {
return false;
}
dst->setConfig(background.config(), background.width(), background.height());
dst->allocPixels();
SkCanvas canvas(*dst);
SkPaint paint;
paint.setXfermodeMode(SkXfermode::kSrc_Mode);
canvas.drawBitmap(background, SkIntToScalar(backgroundOffset.fX),
SkIntToScalar(backgroundOffset.fY), &paint);
paint.setXfermodeMode(modeToXfermode(fMode));
canvas.drawBitmap(foreground, SkIntToScalar(foregroundOffset.fX),
SkIntToScalar(foregroundOffset.fY), &paint);
return true;
}
///////////////////////////////////////////////////////////////////////////////
#if SK_SUPPORT_GPU
class GrGLBlendEffect : public GrGLEffect {
public:
GrGLBlendEffect(const GrBackendEffectFactory&, const GrDrawEffect&);
virtual ~GrGLBlendEffect();
virtual void emitCode(GrGLShaderBuilder*,
const GrDrawEffect&,
EffectKey,
const char* outputColor,
const char* inputColor,
const TextureSamplerArray&) SK_OVERRIDE;
static inline EffectKey GenKey(const GrDrawEffect&, const GrGLCaps&);
virtual void setData(const GrGLUniformManager&, const GrDrawEffect&) SK_OVERRIDE;
private:
static const GrEffect::CoordsType kCoordsType = GrEffect::kLocal_CoordsType;
SkBlendImageFilter::Mode fMode;
GrGLEffectMatrix fForegroundEffectMatrix;
GrGLEffectMatrix fBackgroundEffectMatrix;
typedef GrGLEffect INHERITED;
};
///////////////////////////////////////////////////////////////////////////////
class GrBlendEffect : public GrEffect {
public:
static GrEffectRef* Create(SkBlendImageFilter::Mode mode,
GrTexture* foreground,
const SkIPoint& foregroundOffset,
GrTexture* background,
const SkIPoint& backgroundOffset) {
AutoEffectUnref effect(SkNEW_ARGS(GrBlendEffect, (mode, foreground, foregroundOffset,
background, backgroundOffset)));
return CreateEffectRef(effect);
}
virtual ~GrBlendEffect();
virtual const GrBackendEffectFactory& getFactory() const SK_OVERRIDE;
SkBlendImageFilter::Mode mode() const { return fMode; }
const SkMatrix& foregroundMatrix() const { return fForegroundMatrix; }
const SkMatrix& backgroundMatrix() const { return fBackgroundMatrix; }
typedef GrGLBlendEffect GLEffect;
static const char* Name() { return "Blend"; }
virtual void getConstantColorComponents(GrColor* color, uint32_t* validFlags) const SK_OVERRIDE;
private:
virtual bool onIsEqual(const GrEffect&) const SK_OVERRIDE;
GrBlendEffect(SkBlendImageFilter::Mode mode,
GrTexture* foreground, const SkIPoint& foregroundOffset,
GrTexture* background, const SkIPoint& backgroundOffset);
GrTextureAccess fForegroundAccess;
SkMatrix fForegroundMatrix;
GrTextureAccess fBackgroundAccess;
SkMatrix fBackgroundMatrix;
SkBlendImageFilter::Mode fMode;
typedef GrEffect INHERITED;
};
bool SkBlendImageFilter::filterImageGPU(Proxy* proxy, const SkBitmap& src, SkBitmap* result,
SkIPoint* offset) {
SkBitmap backgroundBM;
SkIPoint backgroundOffset = SkIPoint::Make(0, 0);
if (!SkImageFilterUtils::GetInputResultGPU(getBackgroundInput(), proxy, src, &backgroundBM,
&backgroundOffset)) {
return false;
}
GrTexture* background = backgroundBM.getTexture();
SkBitmap foregroundBM;
SkIPoint foregroundOffset = SkIPoint::Make(0, 0);
if (!SkImageFilterUtils::GetInputResultGPU(getForegroundInput(), proxy, src, &foregroundBM,
&foregroundOffset)) {
return false;
}
GrTexture* foreground = foregroundBM.getTexture();
GrContext* context = foreground->getContext();
GrTextureDesc desc;
desc.fFlags = kRenderTarget_GrTextureFlagBit | kNoStencil_GrTextureFlagBit;
desc.fWidth = src.width();
desc.fHeight = src.height();
desc.fConfig = kSkia8888_GrPixelConfig;
GrAutoScratchTexture ast(context, desc);
SkAutoTUnref<GrTexture> dst(ast.detach());
GrContext::AutoRenderTarget art(context, dst->asRenderTarget());
GrPaint paint;
paint.addColorEffect(GrBlendEffect::Create(fMode,
foreground, foregroundOffset,
background, backgroundOffset))->unref();
SkRect srcRect;
src.getBounds(&srcRect);
context->drawRect(paint, srcRect);
return SkImageFilterUtils::WrapTexture(dst, src.width(), src.height(), result);
}
///////////////////////////////////////////////////////////////////////////////
GrBlendEffect::GrBlendEffect(SkBlendImageFilter::Mode mode,
GrTexture* foreground,
const SkIPoint& foregroundOffset,
GrTexture* background,
const SkIPoint& backgroundOffset)
: fForegroundAccess(foreground)
, fBackgroundAccess(background)
, fMode(mode) {
this->addTextureAccess(&fForegroundAccess);
this->addTextureAccess(&fBackgroundAccess);
fForegroundMatrix = GrEffect::MakeDivByTextureWHMatrix(foreground);
fForegroundMatrix.preTranslate(SkIntToScalar(-foregroundOffset.fX),
SkIntToScalar(-foregroundOffset.fY));
fBackgroundMatrix = GrEffect::MakeDivByTextureWHMatrix(background);
fBackgroundMatrix.preTranslate(SkIntToScalar(-backgroundOffset.fX),
SkIntToScalar(-backgroundOffset.fY));
}
GrBlendEffect::~GrBlendEffect() {
}
bool GrBlendEffect::onIsEqual(const GrEffect& sBase) const {
const GrBlendEffect& s = CastEffect<GrBlendEffect>(sBase);
return fForegroundAccess.getTexture() == s.fForegroundAccess.getTexture() &&
fBackgroundAccess.getTexture() == s.fBackgroundAccess.getTexture() &&
fMode == s.fMode;
}
const GrBackendEffectFactory& GrBlendEffect::getFactory() const {
return GrTBackendEffectFactory<GrBlendEffect>::getInstance();
}
void GrBlendEffect::getConstantColorComponents(GrColor* color, uint32_t* validFlags) const {
// The output alpha is always 1 - (1 - FGa) * (1 - BGa). So if either FGa or BGa is known to
// be one then the output alpha is one. (This effect ignores its input. We should have a way to
// communicate this.)
if (GrPixelConfigIsOpaque(fForegroundAccess.getTexture()->config()) ||
GrPixelConfigIsOpaque(fBackgroundAccess.getTexture()->config())) {
*validFlags = kA_GrColorComponentFlag;
*color = GrColorPackRGBA(0, 0, 0, 0xff);
} else {
*validFlags = 0;
}
}
///////////////////////////////////////////////////////////////////////////////
GrGLBlendEffect::GrGLBlendEffect(const GrBackendEffectFactory& factory,
const GrDrawEffect& drawEffect)
: INHERITED(factory)
, fMode(drawEffect.castEffect<GrBlendEffect>().mode())
, fForegroundEffectMatrix(kCoordsType)
, fBackgroundEffectMatrix(kCoordsType) {
}
GrGLBlendEffect::~GrGLBlendEffect() {
}
void GrGLBlendEffect::emitCode(GrGLShaderBuilder* builder,
const GrDrawEffect&,
EffectKey key,
const char* outputColor,
const char* inputColor,
const TextureSamplerArray& samplers) {
const char* fgCoords;
const char* bgCoords;
GrSLType fgCoordsType = fForegroundEffectMatrix.emitCode(builder, key, &fgCoords, NULL, "FG");
GrSLType bgCoordsType = fBackgroundEffectMatrix.emitCode(builder, key, &bgCoords, NULL, "BG");
const char* bgColor = "bgColor";
const char* fgColor = "fgColor";
builder->fsCodeAppendf("\t\tvec4 %s = ", fgColor);
builder->appendTextureLookup(GrGLShaderBuilder::kFragment_ShaderType,
samplers[0],
fgCoords,
fgCoordsType);
builder->fsCodeAppend(";\n");
builder->fsCodeAppendf("\t\tvec4 %s = ", bgColor);
builder->appendTextureLookup(GrGLShaderBuilder::kFragment_ShaderType,
samplers[1],
bgCoords,
bgCoordsType);
builder->fsCodeAppendf(";\n");
builder->fsCodeAppendf("\t\t%s.a = 1.0 - (1.0 - %s.a) * (1.0 - %s.b);\n", outputColor, bgColor, fgColor);
switch (fMode) {
case SkBlendImageFilter::kNormal_Mode:
builder->fsCodeAppendf("\t\t%s.rgb = (1.0 - %s.a) * %s.rgb + %s.rgb;\n", outputColor, fgColor, bgColor, fgColor);
break;
case SkBlendImageFilter::kMultiply_Mode:
builder->fsCodeAppendf("\t\t%s.rgb = (1.0 - %s.a) * %s.rgb + (1.0 - %s.a) * %s.rgb + %s.rgb * %s.rgb;\n", outputColor, fgColor, bgColor, bgColor, fgColor, fgColor, bgColor);
break;
case SkBlendImageFilter::kScreen_Mode:
builder->fsCodeAppendf("\t\t%s.rgb = %s.rgb + %s.rgb - %s.rgb * %s.rgb;\n", outputColor, bgColor, fgColor, fgColor, bgColor);
break;
case SkBlendImageFilter::kDarken_Mode:
builder->fsCodeAppendf("\t\t%s.rgb = min((1.0 - %s.a) * %s.rgb + %s.rgb, (1.0 - %s.a) * %s.rgb + %s.rgb);\n", outputColor, fgColor, bgColor, fgColor, bgColor, fgColor, bgColor);
break;
case SkBlendImageFilter::kLighten_Mode:
builder->fsCodeAppendf("\t\t%s.rgb = max((1.0 - %s.a) * %s.rgb + %s.rgb, (1.0 - %s.a) * %s.rgb + %s.rgb);\n", outputColor, fgColor, bgColor, fgColor, bgColor, fgColor, bgColor);
break;
}
}
void GrGLBlendEffect::setData(const GrGLUniformManager& uman, const GrDrawEffect& drawEffect) {
const GrBlendEffect& blend = drawEffect.castEffect<GrBlendEffect>();
GrTexture* fgTex = blend.texture(0);
GrTexture* bgTex = blend.texture(1);
fForegroundEffectMatrix.setData(uman,
blend.foregroundMatrix(),
drawEffect,
fgTex);
fBackgroundEffectMatrix.setData(uman,
blend.backgroundMatrix(),
drawEffect,
bgTex);
}
GrGLEffect::EffectKey GrGLBlendEffect::GenKey(const GrDrawEffect& drawEffect, const GrGLCaps&) {
const GrBlendEffect& blend = drawEffect.castEffect<GrBlendEffect>();
GrTexture* fgTex = blend.texture(0);
GrTexture* bgTex = blend.texture(1);
EffectKey fgKey = GrGLEffectMatrix::GenKey(GrEffect::MakeDivByTextureWHMatrix(fgTex),
drawEffect,
kCoordsType,
fgTex);
EffectKey bgKey = GrGLEffectMatrix::GenKey(GrEffect::MakeDivByTextureWHMatrix(bgTex),
drawEffect,
kCoordsType,
bgTex);
bgKey <<= GrGLEffectMatrix::kKeyBits;
EffectKey modeKey = blend.mode() << (2 * GrGLEffectMatrix::kKeyBits);
return modeKey | bgKey | fgKey;
}
#endif

View File

@ -20,7 +20,6 @@
#include "SkAvoidXfermode.h"
#include "SkBicubicImageFilter.h"
#include "SkBitmapSource.h"
#include "SkBlendImageFilter.h"
#include "SkBlurDrawLooper.h"
#include "SkBlurImageFilter.h"
#include "SkBlurMaskFilter.h"
@ -64,7 +63,6 @@ void SkFlattenable::InitializeFlattenables() {
SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkBicubicImageFilter)
SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkBitmapProcShader)
SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkBitmapSource)
SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkBlendImageFilter)
SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkBlurDrawLooper)
SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkBlurImageFilter)
SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkColorMatrixFilter)