Sanitizing source files in Housekeeper-Nightly
authorskia.committer@gmail.com <skia.committer@gmail.com@2bbb7eff-a529-9590-31e7-b0007b416f81>
Thu, 23 Jan 2014 18:48:56 +0000 (18:48 +0000)
committerskia.committer@gmail.com <skia.committer@gmail.com@2bbb7eff-a529-9590-31e7-b0007b416f81>
Thu, 23 Jan 2014 18:48:56 +0000 (18:48 +0000)
git-svn-id: http://skia.googlecode.com/svn/trunk@13155 2bbb7eff-a529-9590-31e7-b0007b416f81

gyp/opts.gyp
include/effects/SkMorphologyImageFilter.h
src/effects/SkMorphologyImageFilter.cpp
src/opts/SkMorphology_opts.h
src/opts/SkMorphology_opts_none.cpp
src/opts/opts_check_SSE2.cpp
src/opts/opts_check_arm.cpp

index 9c63766..bd072cb 100644 (file)
@@ -25,7 +25,6 @@
       'standalone_static_library': 1,
       'dependencies': [
         'core.gyp:*',
-        'effects.gyp:*'
       ],
       'include_dirs': [
         '../src/core',
       'standalone_static_library': 1,
       'dependencies': [
         'core.gyp:*',
-        'effects.gyp:*'
       ],
       'include_dirs': [
         '../src/core',
       'standalone_static_library': 1,
       'dependencies': [
         'core.gyp:*',
-        'effects.gyp:*'
       ],
       'include_dirs': [
         '../src/core',
index 3a55199..880fc2e 100644 (file)
@@ -9,7 +9,6 @@
 #ifndef SkMorphologyImageFilter_DEFINED
 #define SkMorphologyImageFilter_DEFINED
 
-#include "SkColor.h"
 #include "SkImageFilter.h"
 #include "SkSize.h"
 
@@ -17,27 +16,11 @@ class SK_API SkMorphologyImageFilter : public SkImageFilter {
 public:
     SkMorphologyImageFilter(int radiusX, int radiusY, SkImageFilter* input, const CropRect* cropRect);
 
-    /**
-     * All morphology procs have the same signature: src is the source buffer, dst the
-     * destination buffer, radius is the morphology radius, width and height are the bounds
-     * of the destination buffer (in pixels), and srcStride and dstStride are the
-     * number of pixels per row in each buffer. All buffers are 8888.
-     */
-
-    typedef void (*Proc)(const SkPMColor* src, SkPMColor* dst, int radius,
-                         int width, int height, int srcStride, int dstStride);
-
 protected:
-    bool filterImageGeneric(Proc procX, Proc procY,
-                            Proxy*, const SkBitmap& src, const SkMatrix&,
-                            SkBitmap* result, SkIPoint* offset);
     SkMorphologyImageFilter(SkFlattenableReadBuffer& buffer);
     virtual void flatten(SkFlattenableWriteBuffer&) const SK_OVERRIDE;
 #if SK_SUPPORT_GPU
     virtual bool canFilterImageGPU() const SK_OVERRIDE { return true; }
-    bool filterImageGPUGeneric(bool dilate, Proxy* proxy, const SkBitmap& src,
-                               const SkMatrix& ctm, SkBitmap* result,
-                               SkIPoint* offset);
 #endif
 
     SkISize    radius() const { return fRadius; }
index af45c0d..09d9f5d 100644 (file)
@@ -84,6 +84,28 @@ static void erode(const SkPMColor* src, SkPMColor* dst,
     }
 }
 
+static void erodeX(const SkBitmap& src, SkBitmap* dst, int radiusX, const SkIRect& bounds)
+{
+    SkMorphologyProc erodeXProc = SkMorphologyGetPlatformProc(kErodeX_SkMorphologyProcType);
+    if (!erodeXProc) {
+        erodeXProc = erode<kX>;
+    }
+    erodeXProc(src.getAddr32(bounds.left(), bounds.top()), dst->getAddr32(0, 0),
+               radiusX, bounds.width(), bounds.height(),
+               src.rowBytesAsPixels(), dst->rowBytesAsPixels());
+}
+
+static void erodeY(const SkBitmap& src, SkBitmap* dst, int radiusY, const SkIRect& bounds)
+{
+    SkMorphologyProc erodeYProc = SkMorphologyGetPlatformProc(kErodeY_SkMorphologyProcType);
+    if (!erodeYProc) {
+        erodeYProc = erode<kY>;
+    }
+    erodeYProc(src.getAddr32(bounds.left(), bounds.top()), dst->getAddr32(0, 0),
+               radiusY, bounds.height(), bounds.width(),
+               src.rowBytesAsPixels(), dst->rowBytesAsPixels());
+}
+
 template<MorphDirection direction>
 static void dilate(const SkPMColor* src, SkPMColor* dst,
                    int radius, int width, int height,
@@ -122,27 +144,31 @@ static void dilate(const SkPMColor* src, SkPMColor* dst,
     }
 }
 
-static void callProcX(SkMorphologyImageFilter::Proc procX, const SkBitmap& src, SkBitmap* dst, int radiusX, const SkIRect& bounds)
+static void dilateX(const SkBitmap& src, SkBitmap* dst, int radiusX, const SkIRect& bounds)
 {
-    procX(src.getAddr32(bounds.left(), bounds.top()), dst->getAddr32(0, 0),
-          radiusX, bounds.width(), bounds.height(),
-          src.rowBytesAsPixels(), dst->rowBytesAsPixels());
+    SkMorphologyProc dilateXProc = SkMorphologyGetPlatformProc(kDilateX_SkMorphologyProcType);
+    if (!dilateXProc) {
+        dilateXProc = dilate<kX>;
+    }
+    dilateXProc(src.getAddr32(bounds.left(), bounds.top()), dst->getAddr32(0, 0),
+                radiusX, bounds.width(), bounds.height(),
+                src.rowBytesAsPixels(), dst->rowBytesAsPixels());
 }
 
-static void callProcY(SkMorphologyImageFilter::Proc procY, const SkBitmap& src, SkBitmap* dst, int radiusY, const SkIRect& bounds)
+static void dilateY(const SkBitmap& src, SkBitmap* dst, int radiusY, const SkIRect& bounds)
 {
-    procY(src.getAddr32(bounds.left(), bounds.top()), dst->getAddr32(0, 0),
-          radiusY, bounds.height(), bounds.width(),
-          src.rowBytesAsPixels(), dst->rowBytesAsPixels());
+    SkMorphologyProc dilateYProc = SkMorphologyGetPlatformProc(kDilateY_SkMorphologyProcType);
+    if (!dilateYProc) {
+        dilateYProc = dilate<kY>;
+    }
+    dilateYProc(src.getAddr32(bounds.left(), bounds.top()), dst->getAddr32(0, 0),
+                radiusY, bounds.height(), bounds.width(),
+                src.rowBytesAsPixels(), dst->rowBytesAsPixels());
 }
 
-bool SkMorphologyImageFilter::filterImageGeneric(SkMorphologyImageFilter::Proc procX,
-                                                 SkMorphologyImageFilter::Proc procY,
-                                                 Proxy* proxy,
-                                                 const SkBitmap& source,
-                                                 const SkMatrix& ctm,
-                                                 SkBitmap* dst,
-                                                 SkIPoint* offset) {
+bool SkErodeImageFilter::onFilterImage(Proxy* proxy,
+                                       const SkBitmap& source, const SkMatrix& ctm,
+                                       SkBitmap* dst, SkIPoint* offset) {
     SkBitmap src = source;
     SkIPoint srcOffset = SkIPoint::Make(0, 0);
     if (getInput(0) && !getInput(0)->filterImage(proxy, source, ctm, &src, &srcOffset)) {
@@ -198,45 +224,87 @@ bool SkMorphologyImageFilter::filterImageGeneric(SkMorphologyImageFilter::Proc p
     }
 
     if (width > 0 && height > 0) {
-        callProcX(procX, src, &temp, width, srcBounds);
+        erodeX(src, &temp, width, srcBounds);
         SkIRect tmpBounds = SkIRect::MakeWH(srcBounds.width(), srcBounds.height());
-        callProcY(procY, temp, dst, height, tmpBounds);
+        erodeY(temp, dst, height, tmpBounds);
     } else if (width > 0) {
-        callProcX(procX, src, dst, width, srcBounds);
+        erodeX(src, dst, width, srcBounds);
     } else if (height > 0) {
-        callProcY(procY, src, dst, height, srcBounds);
+        erodeY(src, dst, height, srcBounds);
     }
     offset->fX = bounds.left();
     offset->fY = bounds.top();
     return true;
 }
 
-bool SkErodeImageFilter::onFilterImage(Proxy* proxy,
-                                       const SkBitmap& source, const SkMatrix& ctm,
-                                       SkBitmap* dst, SkIPoint* offset) {
-    Proc erodeXProc = SkMorphologyGetPlatformProc(kErodeX_SkMorphologyProcType);
-    if (!erodeXProc) {
-        erodeXProc = erode<kX>;
-    }
-    Proc erodeYProc = SkMorphologyGetPlatformProc(kErodeY_SkMorphologyProcType);
-    if (!erodeYProc) {
-        erodeYProc = erode<kY>;
-    }
-    return this->filterImageGeneric(erodeXProc, erodeYProc, proxy, source, ctm, dst, offset);
-}
-
 bool SkDilateImageFilter::onFilterImage(Proxy* proxy,
                                         const SkBitmap& source, const SkMatrix& ctm,
                                         SkBitmap* dst, SkIPoint* offset) {
-    Proc dilateXProc = SkMorphologyGetPlatformProc(kDilateX_SkMorphologyProcType);
-    if (!dilateXProc) {
-        dilateXProc = dilate<kX>;
+    SkBitmap src = source;
+    SkIPoint srcOffset = SkIPoint::Make(0, 0);
+    if (getInput(0) && !getInput(0)->filterImage(proxy, source, ctm, &src, &srcOffset)) {
+        return false;
     }
-    Proc dilateYProc = SkMorphologyGetPlatformProc(kDilateY_SkMorphologyProcType);
-    if (!dilateYProc) {
-        dilateYProc = dilate<kY>;
+    if (src.config() != SkBitmap::kARGB_8888_Config) {
+        return false;
+    }
+
+    SkIRect bounds;
+    src.getBounds(&bounds);
+    bounds.offset(srcOffset);
+    if (!this->applyCropRect(&bounds, ctm)) {
+        return false;
+    }
+
+    SkAutoLockPixels alp(src);
+    if (!src.getPixels()) {
+        return false;
     }
-    return this->filterImageGeneric(dilateXProc, dilateYProc, proxy, source, ctm, dst, offset);
+
+    dst->setConfig(src.config(), bounds.width(), bounds.height());
+    dst->allocPixels();
+    if (!dst->getPixels()) {
+        return false;
+    }
+
+    SkVector radius = SkVector::Make(SkIntToScalar(this->radius().width()),
+                                     SkIntToScalar(this->radius().height()));
+    ctm.mapVectors(&radius, 1);
+    int width = SkScalarFloorToInt(radius.fX);
+    int height = SkScalarFloorToInt(radius.fY);
+
+    if (width < 0 || height < 0) {
+        return false;
+    }
+
+    SkIRect srcBounds = bounds;
+    srcBounds.offset(-srcOffset);
+
+    if (width == 0 && height == 0) {
+        src.extractSubset(dst, srcBounds);
+        offset->fX = bounds.left();
+        offset->fY = bounds.top();
+        return true;
+    }
+
+    SkBitmap temp;
+    temp.setConfig(dst->config(), dst->width(), dst->height());
+    if (!temp.allocPixels()) {
+        return false;
+    }
+
+    if (width > 0 && height > 0) {
+        dilateX(src, &temp, width, srcBounds);
+        SkIRect tmpBounds = SkIRect::MakeWH(srcBounds.width(), srcBounds.height());
+        dilateY(temp, dst, height, tmpBounds);
+    } else if (width > 0) {
+        dilateX(src, dst, width, srcBounds);
+    } else if (height > 0) {
+        dilateY(src, dst, height, srcBounds);
+    }
+    offset->fX = bounds.left();
+    offset->fY = bounds.top();
+    return true;
 }
 
 #if SK_SUPPORT_GPU
@@ -511,12 +579,8 @@ bool apply_morphology(const SkBitmap& input,
 
 };
 
-bool SkMorphologyImageFilter::filterImageGPUGeneric(bool dilate,
-                                                    Proxy* proxy,
-                                                    const SkBitmap& src,
-                                                    const SkMatrix& ctm,
-                                                    SkBitmap* result,
-                                                    SkIPoint* offset) {
+bool SkDilateImageFilter::filterImageGPU(Proxy* proxy, const SkBitmap& src, const SkMatrix& ctm,
+                                         SkBitmap* result, SkIPoint* offset) {
     SkBitmap input;
     SkIPoint srcOffset = SkIPoint::Make(0, 0);
     if (!SkImageFilterUtils::GetInputResultGPU(getInput(0), proxy, src, ctm, &input, &srcOffset)) {
@@ -547,8 +611,7 @@ bool SkMorphologyImageFilter::filterImageGPUGeneric(bool dilate,
         return true;
     }
 
-    GrMorphologyEffect::MorphologyType type = dilate ? GrMorphologyEffect::kDilate_MorphologyType : GrMorphologyEffect::kErode_MorphologyType;
-    if (!apply_morphology(input, srcBounds, type,
+    if (!apply_morphology(input, srcBounds, GrMorphologyEffect::kDilate_MorphologyType,
                           SkISize::Make(width, height), result)) {
         return false;
     }
@@ -557,14 +620,46 @@ bool SkMorphologyImageFilter::filterImageGPUGeneric(bool dilate,
     return true;
 }
 
-bool SkDilateImageFilter::filterImageGPU(Proxy* proxy, const SkBitmap& src, const SkMatrix& ctm,
-                                         SkBitmap* result, SkIPoint* offset) {
-    return this->filterImageGPUGeneric(true, proxy, src, ctm, result, offset);
-}
-
 bool SkErodeImageFilter::filterImageGPU(Proxy* proxy, const SkBitmap& src, const SkMatrix& ctm,
                                         SkBitmap* result, SkIPoint* offset) {
-    return this->filterImageGPUGeneric(false, proxy, src, ctm, result, offset);
+    SkBitmap input;
+    SkIPoint srcOffset = SkIPoint::Make(0, 0);
+    if (!SkImageFilterUtils::GetInputResultGPU(getInput(0), proxy, src, ctm, &input, &srcOffset)) {
+        return false;
+    }
+    SkIRect bounds;
+    input.getBounds(&bounds);
+    bounds.offset(srcOffset);
+    if (!this->applyCropRect(&bounds, ctm)) {
+        return false;
+    }
+    SkVector radius = SkVector::Make(SkIntToScalar(this->radius().width()),
+                                     SkIntToScalar(this->radius().height()));
+    ctm.mapVectors(&radius, 1);
+    int width = SkScalarFloorToInt(radius.fX);
+    int height = SkScalarFloorToInt(radius.fY);
+
+    if (width < 0 || height < 0) {
+        return false;
+    }
+
+    SkIRect srcBounds = bounds;
+    srcBounds.offset(-srcOffset);
+
+    if (width == 0 && height == 0) {
+        input.extractSubset(result, srcBounds);
+        offset->fX = bounds.left();
+        offset->fY = bounds.top();
+        return true;
+    }
+
+    if (!apply_morphology(input, srcBounds, GrMorphologyEffect::kErode_MorphologyType,
+        SkISize::Make(width, height), result)) {
+        return false;
+    }
+    offset->fX = bounds.left();
+    offset->fY = bounds.top();
+    return true;
 }
 
 #endif
index 7ea7c54..e3ad853 100644 (file)
@@ -5,10 +5,17 @@
  * found in the LICENSE file.
  */
 
-#ifndef SkMorphology_opts_DEFINED
-#define SkMorphology_opts_DEFINED
+#include <SkColor.h>
 
-#include <SkMorphologyImageFilter.h>
+/**
+ * All morphology procs have the same signature: src is the source buffer, dst the
+ * destination buffer, radius is the morphology radius, width and height are the bounds
+ * of the destination buffer (in pixels), and srcStride and dstStride are the
+ * number of pixels per row in each buffer. All buffers are 8888.
+ */
+
+typedef void (*SkMorphologyProc)(const SkPMColor* src, SkPMColor* dst, int radius,
+                                 int width, int height, int srcStride, int dstStride);
 
 enum SkMorphologyProcType {
     kDilateX_SkMorphologyProcType,
@@ -17,6 +24,4 @@ enum SkMorphologyProcType {
     kErodeY_SkMorphologyProcType
 };
 
-SkMorphologyImageFilter::Proc SkMorphologyGetPlatformProc(SkMorphologyProcType type);
-
-#endif
+SkMorphologyProc SkMorphologyGetPlatformProc(SkMorphologyProcType type);
index ade261f..66d58ba 100644 (file)
@@ -7,6 +7,6 @@
 
 #include "SkMorphology_opts.h"
 
-SkMorphologyImageFilter::Proc SkMorphologyGetPlatformProc(SkMorphologyProcType) {
+SkMorphologyProc SkMorphologyGetPlatformProc(SkMorphologyProcType) {
     return NULL;
 }
index d0d88fe..aaf6b2e 100644 (file)
@@ -251,7 +251,7 @@ SkMemset32Proc SkMemset32GetPlatformProc() {
     }
 }
 
-SkMorphologyImageFilter::Proc SkMorphologyGetPlatformProc(SkMorphologyProcType type) {
+SkMorphologyProc SkMorphologyGetPlatformProc(SkMorphologyProcType type) {
     if (!cachedHasSSE2()) {
         return NULL;
     }
index 9e8b472..3a322aa 100644 (file)
@@ -69,7 +69,7 @@ SkBlitRow::ColorRectProc PlatformColorRectProcFactory() {
     return NULL;
 }
 
-SkMorphologyImageFilter::Proc SkMorphologyGetPlatformProc(SkMorphologyProcType type) {
+SkMorphologyProc SkMorphologyGetPlatformProc(SkMorphologyProcType type) {
 #if SK_ARM_NEON_IS_NONE
     return NULL;
 #else