aboutsummaryrefslogtreecommitdiffhomepage
path: root/gm/morphology.cpp
diff options
context:
space:
mode:
authorGravatar senorblanco@chromium.org <senorblanco@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81>2013-09-17 13:41:43 +0000
committerGravatar senorblanco@chromium.org <senorblanco@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81>2013-09-17 13:41:43 +0000
commit8fcad9879173d627ee8638c52709d924034e34ce (patch)
treeef6f26ca87e39051d5ffe8749ee8b0eb7730b403 /gm/morphology.cpp
parentef45a646a730b779f419e8ea11df374adeec8206 (diff)
Implement crop rect for the dilate and erode (morphology) filters. This provoked some cleanup on the GPU side: apply_morphology() now deals with SkBitmaps, rather than GrTextures. There's still a clear opportunity for more refactoring between the two filters.
Note: this adds some test cases to the morphology GM, so it will require a rebaseline. R=bsalomon@google.com, reed@google.com Review URL: https://codereview.chromium.org/23892011 git-svn-id: http://skia.googlecode.com/svn/trunk@11313 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'gm/morphology.cpp')
-rw-r--r--gm/morphology.cpp39
1 files changed, 24 insertions, 15 deletions
diff --git a/gm/morphology.cpp b/gm/morphology.cpp
index 2d29fcd201..2150689b87 100644
--- a/gm/morphology.cpp
+++ b/gm/morphology.cpp
@@ -8,8 +8,8 @@
#include "gm.h"
#include "SkMorphologyImageFilter.h"
-#define WIDTH 640
-#define HEIGHT 480
+#define WIDTH 700
+#define HEIGHT 560
namespace skiagm {
@@ -44,6 +44,16 @@ protected:
virtual SkISize onISize() {
return make_isize(WIDTH, HEIGHT);
}
+
+ void drawClippedBitmap(SkCanvas* canvas, const SkPaint& paint, int x, int y) {
+ canvas->save();
+ canvas->translate(SkIntToScalar(x), SkIntToScalar(y));
+ canvas->clipRect(SkRect::MakeWH(
+ SkIntToScalar(fBitmap.width()), SkIntToScalar(fBitmap.height())));
+ canvas->drawBitmap(fBitmap, 0, 0, &paint);
+ canvas->restore();
+ }
+
virtual void onDraw(SkCanvas* canvas) {
if (!fOnce) {
make_bitmap();
@@ -60,26 +70,25 @@ protected:
{ 24, 24, 25, 25 },
};
SkPaint paint;
- for (unsigned j = 0; j < 2; ++j) {
+ SkIRect cropRect = SkIRect::MakeXYWH(25, 20, 100, 80);
+
+ for (unsigned j = 0; j < 4; ++j) {
for (unsigned i = 0; i < SK_ARRAY_COUNT(samples); ++i) {
- SkScalar x = SkIntToScalar(i * 140), y = SkIntToScalar(j * 140);
- if (j) {
+ const SkIRect* cr = j & 0x02 ? &cropRect : NULL;
+ if (j & 0x01) {
paint.setImageFilter(new SkErodeImageFilter(
samples[i].fRadiusX,
- samples[i].fRadiusY))->unref();
+ samples[i].fRadiusY,
+ NULL,
+ cr))->unref();
} else {
paint.setImageFilter(new SkDilateImageFilter(
samples[i].fRadiusX,
- samples[i].fRadiusY))->unref();
+ samples[i].fRadiusY,
+ NULL,
+ cr))->unref();
}
- SkRect bounds = SkRect::MakeXYWH(
- x,
- y,
- SkIntToScalar(samples[i].fWidth),
- SkIntToScalar(samples[i].fHeight));
- canvas->saveLayer(&bounds, &paint);
- canvas->drawBitmap(fBitmap, x, y);
- canvas->restore();
+ drawClippedBitmap(canvas, paint, i * 140, j * 140);
}
}
}