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

Unified Diff: gm/imagefilterscropped.cpp

Issue 19775006: Implement crop rect for SkImageFilter (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Fix comments Created 7 years, 5 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 | « no previous file | gyp/gmslides.gypi » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: gm/imagefilterscropped.cpp
diff --git a/gm/imagefiltersbase.cpp b/gm/imagefilterscropped.cpp
similarity index 59%
copy from gm/imagefiltersbase.cpp
copy to gm/imagefilterscropped.cpp
index 6879e796b1aa0a30b1d7d30024ef6d8bd01ca8c3..f6045f61a4453d02f78df0bd3fc13ee175201573 100644
--- a/gm/imagefiltersbase.cpp
+++ b/gm/imagefilterscropped.cpp
@@ -15,100 +15,44 @@
#include "SkColorFilterImageFilter.h"
#include "SkTestImageFilters.h"
-class FailImageFilter : public SkImageFilter {
-public:
- FailImageFilter() : INHERITED(0) {}
-
- SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(FailImageFilter)
-protected:
- virtual bool onFilterImage(Proxy*, const SkBitmap& src, const SkMatrix&,
- SkBitmap* result, SkIPoint* offset) {
- return false;
- }
-
- FailImageFilter(SkFlattenableReadBuffer& buffer) : INHERITED(buffer) {}
-
-private:
- typedef SkImageFilter INHERITED;
-};
-
-// register the filter with the flattenable registry
-static SkFlattenable::Registrar gFailImageFilterReg("FailImageFilter",
- FailImageFilter::CreateProc);
-
-class IdentityImageFilter : public SkImageFilter {
-public:
- IdentityImageFilter() : INHERITED(0) {}
-
- SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(IdentityImageFilter)
-protected:
- virtual bool onFilterImage(Proxy*, const SkBitmap& src, const SkMatrix&,
- SkBitmap* result, SkIPoint* offset) {
- *result = src;
- return true;
- }
-
- IdentityImageFilter(SkFlattenableReadBuffer& buffer) : INHERITED(buffer) {}
-
-private:
- typedef SkImageFilter INHERITED;
-};
-
-// register the filter with the flattenable registry
-static SkFlattenable::Registrar gIdentityImageFilterReg("IdentityImageFilter",
- IdentityImageFilter::CreateProc);
-
-
///////////////////////////////////////////////////////////////////////////////
static void draw_paint(SkCanvas* canvas, const SkRect& r, SkImageFilter* imf) {
SkPaint paint;
paint.setImageFilter(imf);
- paint.setColor(SK_ColorGREEN);
+ paint.setColor(SK_ColorBLACK);
canvas->save();
canvas->clipRect(r);
canvas->drawPaint(paint);
canvas->restore();
}
-static void draw_line(SkCanvas* canvas, const SkRect& r, SkImageFilter* imf) {
- SkPaint paint;
- paint.setColor(SK_ColorBLUE);
- paint.setImageFilter(imf);
- paint.setStrokeWidth(r.width()/10);
- canvas->drawLine(r.fLeft, r.fTop, r.fRight, r.fBottom, paint);
-}
-
-static void draw_rect(SkCanvas* canvas, const SkRect& r, SkImageFilter* imf) {
- SkPaint paint;
- paint.setColor(SK_ColorYELLOW);
- paint.setImageFilter(imf);
- SkRect rr(r);
- rr.inset(r.width()/10, r.height()/10);
- canvas->drawRect(rr, paint);
-}
-
static void draw_path(SkCanvas* canvas, const SkRect& r, SkImageFilter* imf) {
SkPaint paint;
paint.setColor(SK_ColorMAGENTA);
paint.setImageFilter(imf);
paint.setAntiAlias(true);
+ canvas->save();
+ canvas->clipRect(r);
canvas->drawCircle(r.centerX(), r.centerY(), r.width()*2/5, paint);
+ canvas->restore();
}
static void draw_text(SkCanvas* canvas, const SkRect& r, SkImageFilter* imf) {
SkPaint paint;
paint.setImageFilter(imf);
- paint.setColor(SK_ColorCYAN);
+ paint.setColor(SK_ColorGREEN);
paint.setAntiAlias(true);
paint.setTextSize(r.height()/2);
paint.setTextAlign(SkPaint::kCenter_Align);
+ canvas->save();
+ canvas->clipRect(r);
canvas->drawText("Text", 4, r.centerX(), r.centerY(), paint);
+ canvas->restore();
}
static void draw_bitmap(SkCanvas* canvas, const SkRect& r, SkImageFilter* imf) {
SkPaint paint;
- paint.setImageFilter(imf);
SkIRect bounds;
r.roundOut(&bounds);
@@ -120,12 +64,15 @@ static void draw_bitmap(SkCanvas* canvas, const SkRect& r, SkImageFilter* imf) {
SkCanvas c(bm);
draw_path(&c, r, NULL);
+ paint.setImageFilter(imf);
+ canvas->save();
+ canvas->clipRect(r);
canvas->drawBitmap(bm, 0, 0, &paint);
+ canvas->restore();
}
static void draw_sprite(SkCanvas* canvas, const SkRect& r, SkImageFilter* imf) {
SkPaint paint;
- paint.setImageFilter(imf);
SkIRect bounds;
r.roundOut(&bounds);
@@ -133,10 +80,14 @@ static void draw_sprite(SkCanvas* canvas, const SkRect& r, SkImageFilter* imf) {
SkBitmap bm;
bm.setConfig(SkBitmap::kARGB_8888_Config, bounds.width(), bounds.height());
bm.allocPixels();
- bm.eraseColor(SK_ColorTRANSPARENT);
+ bm.eraseColor(SK_ColorRED);
SkCanvas c(bm);
- draw_path(&c, r, NULL);
+ SkIRect cropRect = SkIRect::MakeXYWH(10, 10, 44, 44);
+ paint.setColor(SK_ColorGREEN);
+ c.drawRect(SkRect::Make(cropRect), paint);
+
+ paint.setImageFilter(imf);
SkPoint loc = { r.fLeft, r.fTop };
canvas->getTotalMatrix().mapPoints(&loc, 1);
canvas->drawSprite(bm,
@@ -146,14 +97,14 @@ static void draw_sprite(SkCanvas* canvas, const SkRect& r, SkImageFilter* imf) {
///////////////////////////////////////////////////////////////////////////////
-class ImageFiltersBaseGM : public skiagm::GM {
+class ImageFiltersCroppedGM : public skiagm::GM {
public:
- ImageFiltersBaseGM () {}
+ ImageFiltersCroppedGM () {}
protected:
virtual SkString onShortName() {
- return SkString("imagefiltersbase");
+ return SkString("imagefilterscropped");
}
virtual SkISize onISize() { return SkISize::Make(700, 460); }
@@ -175,20 +126,22 @@ protected:
virtual void onDraw(SkCanvas* canvas) {
void (*drawProc[])(SkCanvas*, const SkRect&, SkImageFilter*) = {
- draw_paint,
- draw_line, draw_rect, draw_path, draw_text,
- draw_bitmap,
- draw_sprite
+ draw_sprite, draw_bitmap, draw_path, draw_paint, draw_text
};
SkColorFilter* cf = SkColorFilter::CreateModeFilter(SK_ColorRED,
SkXfermode::kSrcIn_Mode);
+ SkIRect cropRect = SkIRect::MakeXYWH(10, 10, 44, 44);
+ SkIRect bogusRect = SkIRect::MakeXYWH(-100, -100, 10, 10);
+
SkImageFilter* filters[] = {
NULL,
- new IdentityImageFilter,
- new FailImageFilter,
- SkColorFilterImageFilter::Create(cf),
- new SkBlurImageFilter(12.0f, 0.0f),
+ SkColorFilterImageFilter::Create(cf, NULL, &cropRect),
+ new SkBlurImageFilter(8.0f, 0.0f, NULL, &cropRect),
+ new SkBlurImageFilter(0.0f, 8.0f, NULL, &cropRect),
+ new SkBlurImageFilter(8.0f, 8.0f, NULL, &cropRect),
+ new SkBlurImageFilter(8.0f, 8.0f, NULL, &bogusRect),
+ SkColorFilterImageFilter::Create(cf, NULL, &bogusRect),
};
cf->unref();
@@ -198,12 +151,10 @@ protected:
SkScalar DY = r.height() + MARGIN;
canvas->translate(MARGIN, MARGIN);
- for (size_t i = 0; i < SK_ARRAY_COUNT(drawProc); ++i) {
+ for (size_t i = 0; i < SK_ARRAY_COUNT(filters); ++i) {
canvas->save();
- for (size_t j = 0; j < SK_ARRAY_COUNT(filters); ++j) {
- drawProc[i](canvas, r, filters[j]);
-
- draw_frame(canvas, r);
+ for (size_t j = 0; j < SK_ARRAY_COUNT(drawProc); ++j) {
+ drawProc[j](canvas, r, filters[i]);
canvas->translate(0, DY);
}
canvas->restore();
@@ -221,5 +172,5 @@ private:
///////////////////////////////////////////////////////////////////////////////
-static skiagm::GM* MyFactory(void*) { return new ImageFiltersBaseGM; }
+static skiagm::GM* MyFactory(void*) { return new ImageFiltersCroppedGM; }
static skiagm::GMRegistry reg(MyFactory);
« no previous file with comments | « no previous file | gyp/gmslides.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698