experimental -- add SkImageFilter to paint. Not called yet.



git-svn-id: http://skia.googlecode.com/svn/trunk@2599 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/include/core/SkImageFilter.h b/include/core/SkImageFilter.h
index 945e69f..c59b2cd 100644
--- a/include/core/SkImageFilter.h
+++ b/include/core/SkImageFilter.h
@@ -10,7 +10,22 @@
 
 #include "SkFlattenable.h"
 
-class SkImageFilter : public SkFlattenable {
+class SkBitmap;
+class SkMatrix;
+struct SkPoint;
+
+/**
+ *  Experimental.
+ *
+ *  Base class for image filters. If one is installed in the paint, then
+ *  all drawing occurs as usual, but it is as if the drawing happened into an
+ *  offscreen (before the xfermode is applied). This offscreen bitmap will
+ *  then be handed to the imagefilter, who in turn creates a new bitmap which
+ *  is what will finally be drawn to the device (using the original xfermode).
+ *
+ *  If the imagefilter returns false, nothing is drawn.
+ */
+class SK_API SkImageFilter : public SkRefCnt /*SkFlattenable*/ {
 public:
 
     /**
@@ -27,14 +42,22 @@
      *  the result and offset parameters will be ignored by the caller.
      */
     bool filterImage(const SkBitmap& src, const SkMatrix&,
-                     SkBitmap* result, SkPoint* offset);
+                     SkBitmap* result, SkIPoint* offset);
+
+    /**
+     *  Experimental.
+     *
+     *  If the filter can be expressed as a gaussian-blur, return true and
+     *  set the sigma to the values for horizontal and vertical.
+     */
+    virtual bool asABlur(SkSize* sigma) const;
 
 protected:
-    virtual bool onFilterImage(const SkBitmap& src, const SkMatrix&
-                               SkBitmap* result, SkPoint* offset) = 0;
+    virtual bool onFilterImage(const SkBitmap& src, const SkMatrix&,
+                               SkBitmap* result, SkIPoint* offset);
 
 private:
-    typedef SkFlattenable INHERITED;
+    typedef SkRefCnt INHERITED;
 };
 
 #endif
diff --git a/include/core/SkPaint.h b/include/core/SkPaint.h
index 5e3e26b..ee9b65c 100644
--- a/include/core/SkPaint.h
+++ b/include/core/SkPaint.h
@@ -21,6 +21,7 @@
 struct SkGlyph;
 struct SkRect;
 class SkGlyphCache;
+class SkImageFilter;
 class SkMaskFilter;
 class SkMatrix;
 class SkPath;
@@ -595,6 +596,9 @@
     */
     SkRasterizer* setRasterizer(SkRasterizer* rasterizer);
 
+    SkImageFilter* getImageFilter() const { return fImageFilter; }
+    SkImageFilter* setImageFilter(SkImageFilter*);
+
     /**
      *  Return the paint's SkDrawLooper (if any). Does not affect the looper's
      *  reference count.
@@ -838,6 +842,7 @@
     SkColorFilter*  fColorFilter;
     SkRasterizer*   fRasterizer;
     SkDrawLooper*   fLooper;
+    SkImageFilter*  fImageFilter;
 
     SkColor         fColor;
     SkScalar        fWidth;
diff --git a/src/core/SkPaint.cpp b/src/core/SkPaint.cpp
index 0c7cb33..ce08e0b 100644
--- a/src/core/SkPaint.cpp
+++ b/src/core/SkPaint.cpp
@@ -11,6 +11,7 @@
 #include "SkColorFilter.h"
 #include "SkDrawLooper.h"
 #include "SkFontHost.h"
+#include "SkImageFilter.h"
 #include "SkMaskFilter.h"
 #include "SkPathEffect.h"
 #include "SkRasterizer.h"
@@ -55,6 +56,7 @@
     fColorFilter = NULL;
     fRasterizer  = NULL;
     fLooper      = NULL;
+    fImageFilter = NULL;
     fWidth      = 0;
 #endif
 
@@ -85,6 +87,7 @@
     SkSafeRef(fColorFilter);
     SkSafeRef(fRasterizer);
     SkSafeRef(fLooper);
+    SkSafeRef(fImageFilter);
 }
 
 SkPaint::~SkPaint() {
@@ -96,6 +99,7 @@
     SkSafeUnref(fColorFilter);
     SkSafeUnref(fRasterizer);
     SkSafeUnref(fLooper);
+    SkSafeUnref(fImageFilter);
 }
 
 SkPaint& SkPaint::operator=(const SkPaint& src) {
@@ -109,6 +113,7 @@
     SkSafeRef(src.fColorFilter);
     SkSafeRef(src.fRasterizer);
     SkSafeRef(src.fLooper);
+    SkSafeRef(src.fImageFilter);
 
     SkSafeUnref(fTypeface);
     SkSafeUnref(fPathEffect);
@@ -118,6 +123,7 @@
     SkSafeUnref(fColorFilter);
     SkSafeUnref(fRasterizer);
     SkSafeUnref(fLooper);
+    SkSafeUnref(fImageFilter);
 
 #ifdef ANDROID
     uint32_t oldGenerationID = fGenerationID;
@@ -356,6 +362,12 @@
     return looper;
 }
 
+SkImageFilter* SkPaint::setImageFilter(SkImageFilter* imageFilter) {
+    SkRefCnt_SafeAssign(fImageFilter, imageFilter);
+    GEN_ID_INC;
+    return imageFilter;
+}
+
 ///////////////////////////////////////////////////////////////////////////////
 
 #include "SkGlyphCache.h"
@@ -1859,3 +1871,21 @@
 }
 
 
+//////////// Move these to their own file soon.
+
+bool SkImageFilter::filterImage(const SkBitmap& src, const SkMatrix& matrix,
+                                SkBitmap* result, SkIPoint* offset) {
+    SkASSERT(result);
+    SkASSERT(offset);
+    return this->onFilterImage(src, matrix, result, offset);
+}
+
+bool SkImageFilter::onFilterImage(const SkBitmap& src, const SkMatrix&,
+                                  SkBitmap* result, SkIPoint* offset) {
+    return false;
+}
+
+bool SkImageFilter::asABlur(SkSize* sigma) const {
+    return false;
+}
+