Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(325)

Unified Diff: src/effects/SkMorphologyImageFilter.cpp

Issue 135013004: Refactor SkMorphologyImageFilter, CPU and GPU paths. This required making opts/ dependent on effect… (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Fix android build Created 6 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « include/effects/SkMorphologyImageFilter.h ('k') | src/opts/SkMorphology_opts.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/effects/SkMorphologyImageFilter.cpp
diff --git a/src/effects/SkMorphologyImageFilter.cpp b/src/effects/SkMorphologyImageFilter.cpp
index 09d9f5de4ae1762a01229e19532034c777bb61ab..af45c0d3a109febeb2e93c7cbba03001df75ce2c 100644
--- a/src/effects/SkMorphologyImageFilter.cpp
+++ b/src/effects/SkMorphologyImageFilter.cpp
@@ -84,28 +84,6 @@ 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,
@@ -144,31 +122,27 @@ static void dilate(const SkPMColor* src, SkPMColor* dst,
}
}
-static void dilateX(const SkBitmap& src, SkBitmap* dst, int radiusX, const SkIRect& bounds)
+static void callProcX(SkMorphologyImageFilter::Proc procX, const SkBitmap& src, SkBitmap* dst, int radiusX, const SkIRect& bounds)
{
- 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());
+ procX(src.getAddr32(bounds.left(), bounds.top()), dst->getAddr32(0, 0),
+ radiusX, bounds.width(), bounds.height(),
+ src.rowBytesAsPixels(), dst->rowBytesAsPixels());
}
-static void dilateY(const SkBitmap& src, SkBitmap* dst, int radiusY, const SkIRect& bounds)
+static void callProcY(SkMorphologyImageFilter::Proc procY, const SkBitmap& src, SkBitmap* dst, int radiusY, const SkIRect& bounds)
{
- 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());
+ procY(src.getAddr32(bounds.left(), bounds.top()), dst->getAddr32(0, 0),
+ radiusY, bounds.height(), bounds.width(),
+ src.rowBytesAsPixels(), dst->rowBytesAsPixels());
}
-bool SkErodeImageFilter::onFilterImage(Proxy* proxy,
- const SkBitmap& source, const SkMatrix& ctm,
- SkBitmap* dst, SkIPoint* offset) {
+bool SkMorphologyImageFilter::filterImageGeneric(SkMorphologyImageFilter::Proc procX,
+ SkMorphologyImageFilter::Proc procY,
+ 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)) {
@@ -224,87 +198,45 @@ bool SkErodeImageFilter::onFilterImage(Proxy* proxy,
}
if (width > 0 && height > 0) {
- erodeX(src, &temp, width, srcBounds);
+ callProcX(procX, src, &temp, width, srcBounds);
SkIRect tmpBounds = SkIRect::MakeWH(srcBounds.width(), srcBounds.height());
- erodeY(temp, dst, height, tmpBounds);
+ callProcY(procY, temp, dst, height, tmpBounds);
} else if (width > 0) {
- erodeX(src, dst, width, srcBounds);
+ callProcX(procX, src, dst, width, srcBounds);
} else if (height > 0) {
- erodeY(src, dst, height, srcBounds);
+ callProcY(procY, src, dst, height, srcBounds);
}
offset->fX = bounds.left();
offset->fY = bounds.top();
return true;
}
-bool SkDilateImageFilter::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)) {
- return false;
- }
- 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;
- }
-
- 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;
+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>;
}
-
- 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;
+ Proc erodeYProc = SkMorphologyGetPlatformProc(kErodeY_SkMorphologyProcType);
+ if (!erodeYProc) {
+ erodeYProc = erode<kY>;
}
+ return this->filterImageGeneric(erodeXProc, erodeYProc, proxy, source, ctm, dst, offset);
+}
- SkBitmap temp;
- temp.setConfig(dst->config(), dst->width(), dst->height());
- if (!temp.allocPixels()) {
- return false;
+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>;
}
-
- 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);
+ Proc dilateYProc = SkMorphologyGetPlatformProc(kDilateY_SkMorphologyProcType);
+ if (!dilateYProc) {
+ dilateYProc = dilate<kY>;
}
- offset->fX = bounds.left();
- offset->fY = bounds.top();
- return true;
+ return this->filterImageGeneric(dilateXProc, dilateYProc, proxy, source, ctm, dst, offset);
}
#if SK_SUPPORT_GPU
@@ -579,8 +511,12 @@ bool apply_morphology(const SkBitmap& input,
};
-bool SkDilateImageFilter::filterImageGPU(Proxy* proxy, const SkBitmap& src, const SkMatrix& ctm,
- SkBitmap* result, SkIPoint* offset) {
+bool SkMorphologyImageFilter::filterImageGPUGeneric(bool dilate,
+ 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)) {
@@ -611,7 +547,8 @@ bool SkDilateImageFilter::filterImageGPU(Proxy* proxy, const SkBitmap& src, cons
return true;
}
- if (!apply_morphology(input, srcBounds, GrMorphologyEffect::kDilate_MorphologyType,
+ GrMorphologyEffect::MorphologyType type = dilate ? GrMorphologyEffect::kDilate_MorphologyType : GrMorphologyEffect::kErode_MorphologyType;
+ if (!apply_morphology(input, srcBounds, type,
SkISize::Make(width, height), result)) {
return false;
}
@@ -620,46 +557,14 @@ bool SkDilateImageFilter::filterImageGPU(Proxy* proxy, const SkBitmap& src, cons
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) {
- 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;
+ return this->filterImageGPUGeneric(false, proxy, src, ctm, result, offset);
}
#endif
« no previous file with comments | « include/effects/SkMorphologyImageFilter.h ('k') | src/opts/SkMorphology_opts.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698