aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar junov@chromium.org <junov@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81>2013-08-07 20:00:55 +0000
committerGravatar junov@chromium.org <junov@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81>2013-08-07 20:00:55 +0000
commitf44fcdca01722959c3be335f44e88b59dbb33a10 (patch)
tree857f937694f49e6a5d08f337036e4e42e02394bb
parentd79277f67824392876b82cf5635cc11f819e64df (diff)
Upstreaming DropShadowImageFilter into skia, from Blink
GM imagefiltersbase will need rebaselining after this change R=senorblanco@chromium.org Committed: https://code.google.com/p/skia/source/detail?r=10583 Review URL: https://codereview.chromium.org/22258005 git-svn-id: http://skia.googlecode.com/svn/trunk@10626 2bbb7eff-a529-9590-31e7-b0007b416f81
-rw-r--r--gm/imagefiltersbase.cpp4
-rw-r--r--gyp/effects.gypi2
-rw-r--r--include/effects/SkDropShadowImageFilter.h26
-rw-r--r--src/effects/SkDropShadowImageFilter.cpp63
-rw-r--r--src/ports/SkGlobalInitialization_default.cpp2
5 files changed, 96 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 05ce569e26..84d38acf2d 100644
--- a/gyp/effects.gypi
+++ b/gyp/effects.gypi
@@ -27,6 +27,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',
@@ -90,6 +91,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..c9cfd6029e
--- /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) : INHERITED(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;
+}
+
diff --git a/src/ports/SkGlobalInitialization_default.cpp b/src/ports/SkGlobalInitialization_default.cpp
index a85fb6d1e3..24edd31e65 100644
--- a/src/ports/SkGlobalInitialization_default.cpp
+++ b/src/ports/SkGlobalInitialization_default.cpp
@@ -36,6 +36,7 @@
#include "SkDataSet.h"
#include "SkDiscretePathEffect.h"
#include "SkDisplacementMapEffect.h"
+#include "SkDropShadowImageFilter.h"
#include "SkEmptyShader.h"
#include "SkEmbossMaskFilter.h"
#include "SkFlattenable.h"
@@ -78,6 +79,7 @@ void SkFlattenable::InitializeFlattenables() {
SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkDilateImageFilter)
SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkDiscretePathEffect)
SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkDisplacementMapEffect)
+ SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkDropShadowImageFilter)
SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkEmbossMaskFilter)
SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkEmptyShader)
SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkErodeImageFilter)