From 9daf96afb34313842d8d2c4abca73d954d2e9005 Mon Sep 17 00:00:00 2001 From: "senorblanco@chromium.org" Date: Tue, 6 Nov 2012 20:29:39 +0000 Subject: [PATCH] Break out SkOffsetImageFilter into its own file, and derive it from SkSingleInputImageFilter, to make it DAG-friendly. Review URL: https://codereview.appspot.com/6822086 git-svn-id: http://skia.googlecode.com/svn/trunk@6315 2bbb7eff-a529-9590-31e7-b0007b416f81 --- gm/testimagefilters.cpp | 1 + gyp/effects.gypi | 2 ++ include/effects/SkOffsetImageFilter.h | 33 +++++++++++++++++++ include/effects/SkTestImageFilters.h | 22 ------------- src/effects/SkOffsetImageFilter.cpp | 49 ++++++++++++++++++++++++++++ src/effects/SkTestImageFilters.cpp | 32 ------------------ src/ports/SkGlobalInitialization_default.cpp | 1 + 7 files changed, 86 insertions(+), 54 deletions(-) create mode 100644 include/effects/SkOffsetImageFilter.h create mode 100644 src/effects/SkOffsetImageFilter.cpp diff --git a/gm/testimagefilters.cpp b/gm/testimagefilters.cpp index e046416..fdf47b9 100644 --- a/gm/testimagefilters.cpp +++ b/gm/testimagefilters.cpp @@ -13,6 +13,7 @@ #include "SkBlurImageFilter.h" #include "SkColorFilterImageFilter.h" +#include "SkOffsetImageFilter.h" #include "SkTestImageFilters.h" #define FILTER_WIDTH SkIntToScalar(150) diff --git a/gyp/effects.gypi b/gyp/effects.gypi index aef7f2c..f2a2214 100644 --- a/gyp/effects.gypi +++ b/gyp/effects.gypi @@ -33,6 +33,7 @@ '<(skia_src_path)/effects/SkLayerDrawLooper.cpp', '<(skia_src_path)/effects/SkLayerRasterizer.cpp', '<(skia_src_path)/effects/SkLightingImageFilter.cpp', + '<(skia_src_path)/effects/SkOffsetImageFilter.cpp', '<(skia_src_path)/effects/SkMatrixConvolutionImageFilter.cpp', '<(skia_src_path)/effects/SkMorphologyImageFilter.cpp', '<(skia_src_path)/effects/SkPaintFlagsDrawFilter.cpp', @@ -86,6 +87,7 @@ '<(skia_include_path)/effects/SkLayerDrawLooper.h', '<(skia_include_path)/effects/SkLayerRasterizer.h', '<(skia_include_path)/effects/SkLightingImageFilter.h', + '<(skia_include_path)/effects/SkOffsetImageFilter.h', '<(skia_include_path)/effects/SkMorphologyImageFilter.h', '<(skia_include_path)/effects/SkPaintFlagsDrawFilter.h', '<(skia_include_path)/effects/SkPixelXorXfermode.h', diff --git a/include/effects/SkOffsetImageFilter.h b/include/effects/SkOffsetImageFilter.h new file mode 100644 index 0000000..74d6ebc --- /dev/null +++ b/include/effects/SkOffsetImageFilter.h @@ -0,0 +1,33 @@ +/* + * 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 SkOffsetImageFilter_DEFINED +#define SkOffsetImageFilter_DEFINED + +#include "SkSingleInputImageFilter.h" +#include "SkPoint.h" + +class SK_API SkOffsetImageFilter : public SkSingleInputImageFilter { +public: + SkOffsetImageFilter(SkScalar dx, SkScalar dy, SkImageFilter* input = NULL); + SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkOffsetImageFilter) + +protected: + SkOffsetImageFilter(SkFlattenableReadBuffer& buffer); + virtual void flatten(SkFlattenableWriteBuffer&) const SK_OVERRIDE; + + virtual bool onFilterImage(Proxy*, const SkBitmap& src, const SkMatrix&, + SkBitmap* result, SkIPoint* loc) SK_OVERRIDE; + virtual bool onFilterBounds(const SkIRect&, const SkMatrix&, SkIRect*) SK_OVERRIDE; + +private: + SkVector fOffset; + + typedef SkSingleInputImageFilter INHERITED; +}; + +#endif diff --git a/include/effects/SkTestImageFilters.h b/include/effects/SkTestImageFilters.h index 7e2fb91..2a3178e 100755 --- a/include/effects/SkTestImageFilters.h +++ b/include/effects/SkTestImageFilters.h @@ -4,28 +4,6 @@ #include "SkImageFilter.h" #include "SkPoint.h" -class SK_API SkOffsetImageFilter : public SkImageFilter { -public: - SkOffsetImageFilter(SkScalar dx, SkScalar dy) : INHERITED(0) { - fOffset.set(dx, dy); - } - - SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkOffsetImageFilter) - -protected: - SkOffsetImageFilter(SkFlattenableReadBuffer& buffer); - virtual void flatten(SkFlattenableWriteBuffer&) const SK_OVERRIDE; - - virtual bool onFilterImage(Proxy*, const SkBitmap& src, const SkMatrix&, - SkBitmap* result, SkIPoint* loc) SK_OVERRIDE; - virtual bool onFilterBounds(const SkIRect&, const SkMatrix&, SkIRect*) SK_OVERRIDE; - -private: - SkVector fOffset; - - typedef SkImageFilter INHERITED; -}; - class SK_API SkComposeImageFilter : public SkImageFilter { public: SkComposeImageFilter(SkImageFilter* outer, SkImageFilter* inner) : INHERITED(outer, inner) {} diff --git a/src/effects/SkOffsetImageFilter.cpp b/src/effects/SkOffsetImageFilter.cpp new file mode 100644 index 0000000..fb39aa8 --- /dev/null +++ b/src/effects/SkOffsetImageFilter.cpp @@ -0,0 +1,49 @@ +/* + * 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 "SkOffsetImageFilter.h" +#include "SkBitmap.h" +#include "SkMatrix.h" +#include "SkFlattenableBuffers.h" + +bool SkOffsetImageFilter::onFilterImage(Proxy* proxy, const SkBitmap& source, + const SkMatrix& matrix, + SkBitmap* result, + SkIPoint* loc) { + SkBitmap src = this->getInputResult(proxy, source, matrix, loc); + SkVector vec; + matrix.mapVectors(&vec, &fOffset, 1); + + loc->fX += SkScalarRoundToInt(vec.fX); + loc->fY += SkScalarRoundToInt(vec.fY); + *result = src; + return true; +} + +bool SkOffsetImageFilter::onFilterBounds(const SkIRect& src, const SkMatrix& ctm, + SkIRect* dst) { + SkVector vec; + ctm.mapVectors(&vec, &fOffset, 1); + + *dst = src; + dst->offset(SkScalarRoundToInt(vec.fX), SkScalarRoundToInt(vec.fY)); + return true; +} + +void SkOffsetImageFilter::flatten(SkFlattenableWriteBuffer& buffer) const { + this->INHERITED::flatten(buffer); + buffer.writePoint(fOffset); +} + +SkOffsetImageFilter::SkOffsetImageFilter(SkScalar dx, SkScalar dy, + SkImageFilter* input) : INHERITED(input) { + fOffset.set(dx, dy); +} + +SkOffsetImageFilter::SkOffsetImageFilter(SkFlattenableReadBuffer& buffer) : INHERITED(buffer) { + buffer.readPoint(&fOffset); +} diff --git a/src/effects/SkTestImageFilters.cpp b/src/effects/SkTestImageFilters.cpp index 99c80d0..8857719 100755 --- a/src/effects/SkTestImageFilters.cpp +++ b/src/effects/SkTestImageFilters.cpp @@ -18,38 +18,6 @@ public: } }; -bool SkOffsetImageFilter::onFilterImage(Proxy* proxy, const SkBitmap& src, - const SkMatrix& matrix, - SkBitmap* result, - SkIPoint* loc) { - SkVector vec; - matrix.mapVectors(&vec, &fOffset, 1); - - loc->fX += SkScalarRoundToInt(vec.fX); - loc->fY += SkScalarRoundToInt(vec.fY); - *result = src; - return true; -} - -bool SkOffsetImageFilter::onFilterBounds(const SkIRect& src, const SkMatrix& ctm, - SkIRect* dst) { - SkVector vec; - ctm.mapVectors(&vec, &fOffset, 1); - - *dst = src; - dst->offset(SkScalarRoundToInt(vec.fX), SkScalarRoundToInt(vec.fY)); - return true; -} - -void SkOffsetImageFilter::flatten(SkFlattenableWriteBuffer& buffer) const { - this->INHERITED::flatten(buffer); - buffer.writePoint(fOffset); -} - -SkOffsetImageFilter::SkOffsetImageFilter(SkFlattenableReadBuffer& buffer) : INHERITED(buffer) { - buffer.readPoint(&fOffset); -} - /////////////////////////////////////////////////////////////////////////////// SkComposeImageFilter::~SkComposeImageFilter() { diff --git a/src/ports/SkGlobalInitialization_default.cpp b/src/ports/SkGlobalInitialization_default.cpp index a764dd1..6be95a1 100644 --- a/src/ports/SkGlobalInitialization_default.cpp +++ b/src/ports/SkGlobalInitialization_default.cpp @@ -39,6 +39,7 @@ #include "SkLayerDrawLooper.h" #include "SkLayerRasterizer.h" #include "SkLightingImageFilter.h" +#include "SkOffsetImageFilter.h" #include "SkMagnifierImageFilter.h" #include "SkMatrixConvolutionImageFilter.h" #include "SkMorphologyImageFilter.h" -- 2.7.4