diff options
author | junov@chromium.org <junov@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2013-08-06 20:01:40 +0000 |
---|---|---|
committer | junov@chromium.org <junov@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2013-08-06 20:01:40 +0000 |
commit | d8e4024719aeb49564880741faf48360ffcddf3b (patch) | |
tree | f237abbd58a35c630da322b554d94fb6ea35a94d | |
parent | 84d0bbe125bdb6cf8ab909ecf1f177fe0c85f21f (diff) |
Upstreaming DropShadowImageFilter into skia, from Blink
GM imagefiltersbase will need rebaselining after this change
R=senorblanco@chromium.org
Review URL: https://codereview.chromium.org/22258005
git-svn-id: http://skia.googlecode.com/svn/trunk@10583 2bbb7eff-a529-9590-31e7-b0007b416f81
-rw-r--r-- | gm/imagefiltersbase.cpp | 4 | ||||
-rw-r--r-- | gyp/effects.gypi | 2 | ||||
-rw-r--r-- | include/effects/SkDropShadowImageFilter.h | 26 | ||||
-rw-r--r-- | src/effects/SkDropShadowImageFilter.cpp | 63 |
4 files changed, 94 insertions, 1 deletions
diff --git a/gm/imagefiltersbase.cpp b/gm/imagefiltersbase.cpp index 6879e796b1..ca45eafe93 100644 --- a/gm/imagefiltersbase.cpp +++ b/gm/imagefiltersbase.cpp @@ -13,6 +13,7 @@ #include "SkBlurImageFilter.h" #include "SkColorFilterImageFilter.h" +#include "SkDropShadowImageFilter.h" #include "SkTestImageFilters.h" class FailImageFilter : public SkImageFilter { @@ -156,7 +157,7 @@ protected: return SkString("imagefiltersbase"); } - virtual SkISize onISize() { return SkISize::Make(700, 460); } + virtual SkISize onISize() { return SkISize::Make(700, 500); } void draw_frame(SkCanvas* canvas, const SkRect& r) { SkPaint paint; @@ -189,6 +190,7 @@ protected: new FailImageFilter, SkColorFilterImageFilter::Create(cf), new SkBlurImageFilter(12.0f, 0.0f), + new SkDropShadowImageFilter(10.0f, 5.0f, 3.0f, SK_ColorBLUE), }; cf->unref(); diff --git a/gyp/effects.gypi b/gyp/effects.gypi index 63857c9903..e55cbc7ab0 100644 --- a/gyp/effects.gypi +++ b/gyp/effects.gypi @@ -26,6 +26,7 @@ '<(skia_src_path)/effects/SkDashPathEffect.cpp', '<(skia_src_path)/effects/SkDiscretePathEffect.cpp', '<(skia_src_path)/effects/SkDisplacementMapEffect.cpp', + '<(skia_src_path)/effects/SkDropShadowImageFilter.cpp', '<(skia_src_path)/effects/SkEmbossMask.cpp', '<(skia_src_path)/effects/SkEmbossMask.h', '<(skia_src_path)/effects/SkEmbossMask_Table.h', @@ -89,6 +90,7 @@ '<(skia_include_path)/effects/SkDiscretePathEffect.h', '<(skia_include_path)/effects/SkDisplacementMapEffect.h', '<(skia_include_path)/effects/SkDrawExtraPathEffect.h', + '<(skia_include_path)/effects/SkDropShadowImageFilter.h', '<(skia_include_path)/effects/SkEmbossMaskFilter.h', '<(skia_include_path)/effects/SkGradientShader.h', '<(skia_include_path)/effects/SkKernel33MaskFilter.h', diff --git a/include/effects/SkDropShadowImageFilter.h b/include/effects/SkDropShadowImageFilter.h new file mode 100644 index 0000000000..501df7cf7f --- /dev/null +++ b/include/effects/SkDropShadowImageFilter.h @@ -0,0 +1,26 @@ +/* + * 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 "SkColor.h" +#include "SkImageFilter.h" +#include "SkScalar.h" + +class SK_API SkDropShadowImageFilter : public SkImageFilter { +public: + SkDropShadowImageFilter(SkScalar dx, SkScalar dy, SkScalar sigma, SkColor, SkImageFilter* input = NULL); + SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkDropShadowImageFilter) + +protected: + explicit SkDropShadowImageFilter(SkFlattenableReadBuffer&); + virtual void flatten(SkFlattenableWriteBuffer&) const SK_OVERRIDE; + virtual bool onFilterImage(Proxy*, const SkBitmap& source, const SkMatrix&, SkBitmap* result, SkIPoint* loc) SK_OVERRIDE; + +private: + SkScalar fDx, fDy, fSigma; + SkColor fColor; + typedef SkImageFilter INHERITED; +}; diff --git a/src/effects/SkDropShadowImageFilter.cpp b/src/effects/SkDropShadowImageFilter.cpp new file mode 100644 index 0000000000..ef43a30061 --- /dev/null +++ b/src/effects/SkDropShadowImageFilter.cpp @@ -0,0 +1,63 @@ +/* + * 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 "SkDropShadowImageFilter.h" + +#include "SkBitmap.h" +#include "SkBlurImageFilter.h" +#include "SkCanvas.h" +#include "SkColorMatrixFilter.h" +#include "SkDevice.h" +#include "SkFlattenableBuffers.h" + +SkDropShadowImageFilter::SkDropShadowImageFilter(SkScalar dx, SkScalar dy, SkScalar sigma, SkColor color, SkImageFilter* input) + : SkImageFilter(input) + , fDx(dx) + , fDy(dy) + , fSigma(sigma) + , fColor(color) +{ +} + +SkDropShadowImageFilter::SkDropShadowImageFilter(SkFlattenableReadBuffer& buffer) : SkImageFilter(buffer) +{ + fDx = buffer.readScalar(); + fDy = buffer.readScalar(); + fSigma = buffer.readScalar(); + fColor = buffer.readColor(); +} + +void SkDropShadowImageFilter::flatten(SkFlattenableWriteBuffer& buffer) const +{ + this->INHERITED::flatten(buffer); + buffer.writeScalar(fDx); + buffer.writeScalar(fDy); + buffer.writeScalar(fSigma); + buffer.writeColor(fColor); +} + +bool SkDropShadowImageFilter::onFilterImage(Proxy* proxy, const SkBitmap& source, const SkMatrix& matrix, SkBitmap* result, SkIPoint* loc) +{ + SkBitmap src = source; + if (getInput(0) && !getInput(0)->filterImage(proxy, source, matrix, &src, loc)) + return false; + + SkAutoTUnref<SkDevice> device(proxy->createDevice(src.width(), src.height())); + SkCanvas canvas(device.get()); + + SkAutoTUnref<SkImageFilter> blurFilter(new SkBlurImageFilter(fSigma, fSigma)); + SkAutoTUnref<SkColorFilter> colorFilter(SkColorFilter::CreateModeFilter(fColor, SkXfermode::kSrcIn_Mode)); + SkPaint paint; + paint.setImageFilter(blurFilter.get()); + paint.setColorFilter(colorFilter.get()); + paint.setXfermodeMode(SkXfermode::kSrcOver_Mode); + canvas.drawBitmap(src, fDx, fDy, &paint); + canvas.drawBitmap(src, 0, 0); + *result = device->accessBitmap(false); + return true; +} + |