Moving 4 SkImageFilter derived classes from blink to skia
There were 4 classes in blink that derived from SkImageFilter :
- TileImageFilter -> SkTileImageFilter
- OffsetImageFilter -> SkOffsetImageFilter (already existed)
- FloodImageFilter -> SkFloodImageFilter
- CompositeImageFilter -> SkCompositeImageFilter
All functions were copied as is, without modification (except for warnings fixes), except for the offset filter, which was merged into the existing SkOffsetImageFilter class, as a special case when a crop rect is provided. Since the names won't clash with the names in blink, it should be easy to integrate them in blink later and fix issues, if needed.
BUG=
R=senorblanco@google.com, senorblanco@chromium.org, bsalomon@google.com, reed@google.com, mtklein@google.com
Author: sugoi@chromium.org
Review URL: https://chromiumcodereview.appspot.com/24157005
git-svn-id: http://skia.googlecode.com/svn/trunk@11475 2bbb7eff-a529-9590-31e7-b0007b416f81
2013-09-26 16:09:28 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2013 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
2015-01-26 20:49:00 +00:00
|
|
|
#include "sk_tool_utils.h"
|
2015-09-15 18:26:13 +00:00
|
|
|
#include "SkImage.h"
|
|
|
|
#include "SkImageSource.h"
|
2015-01-26 19:24:32 +00:00
|
|
|
#include "SkOffsetImageFilter.h"
|
2015-09-15 18:26:13 +00:00
|
|
|
#include "SkSurface.h"
|
2015-01-26 19:24:32 +00:00
|
|
|
#include "gm.h"
|
Moving 4 SkImageFilter derived classes from blink to skia
There were 4 classes in blink that derived from SkImageFilter :
- TileImageFilter -> SkTileImageFilter
- OffsetImageFilter -> SkOffsetImageFilter (already existed)
- FloodImageFilter -> SkFloodImageFilter
- CompositeImageFilter -> SkCompositeImageFilter
All functions were copied as is, without modification (except for warnings fixes), except for the offset filter, which was merged into the existing SkOffsetImageFilter class, as a special case when a crop rect is provided. Since the names won't clash with the names in blink, it should be easy to integrate them in blink later and fix issues, if needed.
BUG=
R=senorblanco@google.com, senorblanco@chromium.org, bsalomon@google.com, reed@google.com, mtklein@google.com
Author: sugoi@chromium.org
Review URL: https://chromiumcodereview.appspot.com/24157005
git-svn-id: http://skia.googlecode.com/svn/trunk@11475 2bbb7eff-a529-9590-31e7-b0007b416f81
2013-09-26 16:09:28 +00:00
|
|
|
|
2014-03-04 19:05:25 +00:00
|
|
|
#define WIDTH 600
|
Moving 4 SkImageFilter derived classes from blink to skia
There were 4 classes in blink that derived from SkImageFilter :
- TileImageFilter -> SkTileImageFilter
- OffsetImageFilter -> SkOffsetImageFilter (already existed)
- FloodImageFilter -> SkFloodImageFilter
- CompositeImageFilter -> SkCompositeImageFilter
All functions were copied as is, without modification (except for warnings fixes), except for the offset filter, which was merged into the existing SkOffsetImageFilter class, as a special case when a crop rect is provided. Since the names won't clash with the names in blink, it should be easy to integrate them in blink later and fix issues, if needed.
BUG=
R=senorblanco@google.com, senorblanco@chromium.org, bsalomon@google.com, reed@google.com, mtklein@google.com
Author: sugoi@chromium.org
Review URL: https://chromiumcodereview.appspot.com/24157005
git-svn-id: http://skia.googlecode.com/svn/trunk@11475 2bbb7eff-a529-9590-31e7-b0007b416f81
2013-09-26 16:09:28 +00:00
|
|
|
#define HEIGHT 100
|
|
|
|
#define MARGIN 12
|
|
|
|
|
2015-06-22 16:10:14 +00:00
|
|
|
class OffsetImageFilterGM : public skiagm::GM {
|
Moving 4 SkImageFilter derived classes from blink to skia
There were 4 classes in blink that derived from SkImageFilter :
- TileImageFilter -> SkTileImageFilter
- OffsetImageFilter -> SkOffsetImageFilter (already existed)
- FloodImageFilter -> SkFloodImageFilter
- CompositeImageFilter -> SkCompositeImageFilter
All functions were copied as is, without modification (except for warnings fixes), except for the offset filter, which was merged into the existing SkOffsetImageFilter class, as a special case when a crop rect is provided. Since the names won't clash with the names in blink, it should be easy to integrate them in blink later and fix issues, if needed.
BUG=
R=senorblanco@google.com, senorblanco@chromium.org, bsalomon@google.com, reed@google.com, mtklein@google.com
Author: sugoi@chromium.org
Review URL: https://chromiumcodereview.appspot.com/24157005
git-svn-id: http://skia.googlecode.com/svn/trunk@11475 2bbb7eff-a529-9590-31e7-b0007b416f81
2013-09-26 16:09:28 +00:00
|
|
|
public:
|
2015-06-22 16:10:14 +00:00
|
|
|
OffsetImageFilterGM() {
|
Moving 4 SkImageFilter derived classes from blink to skia
There were 4 classes in blink that derived from SkImageFilter :
- TileImageFilter -> SkTileImageFilter
- OffsetImageFilter -> SkOffsetImageFilter (already existed)
- FloodImageFilter -> SkFloodImageFilter
- CompositeImageFilter -> SkCompositeImageFilter
All functions were copied as is, without modification (except for warnings fixes), except for the offset filter, which was merged into the existing SkOffsetImageFilter class, as a special case when a crop rect is provided. Since the names won't clash with the names in blink, it should be easy to integrate them in blink later and fix issues, if needed.
BUG=
R=senorblanco@google.com, senorblanco@chromium.org, bsalomon@google.com, reed@google.com, mtklein@google.com
Author: sugoi@chromium.org
Review URL: https://chromiumcodereview.appspot.com/24157005
git-svn-id: http://skia.googlecode.com/svn/trunk@11475 2bbb7eff-a529-9590-31e7-b0007b416f81
2013-09-26 16:09:28 +00:00
|
|
|
this->setBGColor(0xFF000000);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
2015-06-22 16:10:14 +00:00
|
|
|
SkString onShortName() override {
|
Moving 4 SkImageFilter derived classes from blink to skia
There were 4 classes in blink that derived from SkImageFilter :
- TileImageFilter -> SkTileImageFilter
- OffsetImageFilter -> SkOffsetImageFilter (already existed)
- FloodImageFilter -> SkFloodImageFilter
- CompositeImageFilter -> SkCompositeImageFilter
All functions were copied as is, without modification (except for warnings fixes), except for the offset filter, which was merged into the existing SkOffsetImageFilter class, as a special case when a crop rect is provided. Since the names won't clash with the names in blink, it should be easy to integrate them in blink later and fix issues, if needed.
BUG=
R=senorblanco@google.com, senorblanco@chromium.org, bsalomon@google.com, reed@google.com, mtklein@google.com
Author: sugoi@chromium.org
Review URL: https://chromiumcodereview.appspot.com/24157005
git-svn-id: http://skia.googlecode.com/svn/trunk@11475 2bbb7eff-a529-9590-31e7-b0007b416f81
2013-09-26 16:09:28 +00:00
|
|
|
return SkString("offsetimagefilter");
|
|
|
|
}
|
|
|
|
|
2015-06-22 16:10:14 +00:00
|
|
|
SkISize onISize() override {
|
2014-06-10 06:59:03 +00:00
|
|
|
return SkISize::Make(WIDTH, HEIGHT);
|
Moving 4 SkImageFilter derived classes from blink to skia
There were 4 classes in blink that derived from SkImageFilter :
- TileImageFilter -> SkTileImageFilter
- OffsetImageFilter -> SkOffsetImageFilter (already existed)
- FloodImageFilter -> SkFloodImageFilter
- CompositeImageFilter -> SkCompositeImageFilter
All functions were copied as is, without modification (except for warnings fixes), except for the offset filter, which was merged into the existing SkOffsetImageFilter class, as a special case when a crop rect is provided. Since the names won't clash with the names in blink, it should be easy to integrate them in blink later and fix issues, if needed.
BUG=
R=senorblanco@google.com, senorblanco@chromium.org, bsalomon@google.com, reed@google.com, mtklein@google.com
Author: sugoi@chromium.org
Review URL: https://chromiumcodereview.appspot.com/24157005
git-svn-id: http://skia.googlecode.com/svn/trunk@11475 2bbb7eff-a529-9590-31e7-b0007b416f81
2013-09-26 16:09:28 +00:00
|
|
|
}
|
|
|
|
|
2015-06-22 16:10:14 +00:00
|
|
|
void onOnceBeforeDraw() override {
|
2015-09-15 18:26:13 +00:00
|
|
|
fBitmap.reset(SkImage::NewFromBitmap(
|
|
|
|
sk_tool_utils::create_string_bitmap(80, 80, 0xD000D000, 15, 65, 96, "e")));
|
2015-06-22 16:10:14 +00:00
|
|
|
|
2015-09-15 18:26:13 +00:00
|
|
|
fCheckerboard.reset(SkImage::NewFromBitmap(
|
|
|
|
sk_tool_utils::create_checkerboard_bitmap(80, 80,
|
|
|
|
sk_tool_utils::color_to_565(0xFFA0A0A0),
|
|
|
|
sk_tool_utils::color_to_565(0xFF404040),
|
|
|
|
8)));
|
2015-06-22 16:10:14 +00:00
|
|
|
}
|
2015-01-26 19:24:32 +00:00
|
|
|
|
2015-06-22 16:10:14 +00:00
|
|
|
void onDraw(SkCanvas* canvas) override {
|
2015-04-09 18:13:24 +00:00
|
|
|
canvas->clear(SK_ColorBLACK);
|
Moving 4 SkImageFilter derived classes from blink to skia
There were 4 classes in blink that derived from SkImageFilter :
- TileImageFilter -> SkTileImageFilter
- OffsetImageFilter -> SkOffsetImageFilter (already existed)
- FloodImageFilter -> SkFloodImageFilter
- CompositeImageFilter -> SkCompositeImageFilter
All functions were copied as is, without modification (except for warnings fixes), except for the offset filter, which was merged into the existing SkOffsetImageFilter class, as a special case when a crop rect is provided. Since the names won't clash with the names in blink, it should be easy to integrate them in blink later and fix issues, if needed.
BUG=
R=senorblanco@google.com, senorblanco@chromium.org, bsalomon@google.com, reed@google.com, mtklein@google.com
Author: sugoi@chromium.org
Review URL: https://chromiumcodereview.appspot.com/24157005
git-svn-id: http://skia.googlecode.com/svn/trunk@11475 2bbb7eff-a529-9590-31e7-b0007b416f81
2013-09-26 16:09:28 +00:00
|
|
|
SkPaint paint;
|
|
|
|
|
2014-01-27 13:42:58 +00:00
|
|
|
for (int i = 0; i < 4; i++) {
|
2015-09-15 18:26:13 +00:00
|
|
|
const SkImage* image = (i & 0x01) ? fCheckerboard : fBitmap;
|
Make SkImageFilter crop rects relative to the primitive origin, instead of relative to their parent's crop rect. This is required by SVG semantics, and is more sane anyway.
To do this, this patch changes the "offset/loc" parameter in filterImage() / onFilterImage() from an inout-param to an out-param only, so that the calling filter can know how much the input filter wants its result offset (and doesn't include the original primitive position). This offset can then be applied to the current filter's crop rect. (I've renamed the parameter "offset" in all cases to make this clear.) This makes the call sites in SkCanvas/SkGpuDevice responsible for applying the resulting offset to the primitive's position, which is actually a fairly small change.
This change also fixes SkTileImageFilter and SkOffsetImageFilter to correctly handle an input offset, which they weren't before. This required modifying the GM's, since they assumed the broken behaviour.
NOTE: this will require rebaselining the imagefiltersgraph test, since it has a new test case.
NOTE: this will "break" the Blink layout tests css3/filters/effect-reference-subregion-chained-hw.html and css3/filters/effect-reference-subregion-hw.html, but it actually makes them give correct results. It should be suppressed on the skia roll, and I'll rebaseline it.
R=reed@google.com
Review URL: https://codereview.chromium.org/112803004
git-svn-id: http://skia.googlecode.com/svn/trunk@12895 2bbb7eff-a529-9590-31e7-b0007b416f81
2014-01-03 21:48:22 +00:00
|
|
|
SkIRect cropRect = SkIRect::MakeXYWH(i * 12,
|
|
|
|
i * 8,
|
2015-09-15 18:26:13 +00:00
|
|
|
image->width() - i * 8,
|
|
|
|
image->height() - i * 12);
|
2013-10-10 13:51:19 +00:00
|
|
|
SkImageFilter::CropRect rect(SkRect::Make(cropRect));
|
2015-09-15 18:26:13 +00:00
|
|
|
SkAutoTUnref<SkImageFilter> tileInput(SkImageSource::Create(image));
|
Moving 4 SkImageFilter derived classes from blink to skia
There were 4 classes in blink that derived from SkImageFilter :
- TileImageFilter -> SkTileImageFilter
- OffsetImageFilter -> SkOffsetImageFilter (already existed)
- FloodImageFilter -> SkFloodImageFilter
- CompositeImageFilter -> SkCompositeImageFilter
All functions were copied as is, without modification (except for warnings fixes), except for the offset filter, which was merged into the existing SkOffsetImageFilter class, as a special case when a crop rect is provided. Since the names won't clash with the names in blink, it should be easy to integrate them in blink later and fix issues, if needed.
BUG=
R=senorblanco@google.com, senorblanco@chromium.org, bsalomon@google.com, reed@google.com, mtklein@google.com
Author: sugoi@chromium.org
Review URL: https://chromiumcodereview.appspot.com/24157005
git-svn-id: http://skia.googlecode.com/svn/trunk@11475 2bbb7eff-a529-9590-31e7-b0007b416f81
2013-09-26 16:09:28 +00:00
|
|
|
SkScalar dx = SkIntToScalar(i*5);
|
|
|
|
SkScalar dy = SkIntToScalar(i*10);
|
2015-06-22 16:10:14 +00:00
|
|
|
SkAutoTUnref<SkImageFilter> filter(SkOffsetImageFilter::Create(dx, dy, tileInput,
|
|
|
|
&rect));
|
Moving 4 SkImageFilter derived classes from blink to skia
There were 4 classes in blink that derived from SkImageFilter :
- TileImageFilter -> SkTileImageFilter
- OffsetImageFilter -> SkOffsetImageFilter (already existed)
- FloodImageFilter -> SkFloodImageFilter
- CompositeImageFilter -> SkCompositeImageFilter
All functions were copied as is, without modification (except for warnings fixes), except for the offset filter, which was merged into the existing SkOffsetImageFilter class, as a special case when a crop rect is provided. Since the names won't clash with the names in blink, it should be easy to integrate them in blink later and fix issues, if needed.
BUG=
R=senorblanco@google.com, senorblanco@chromium.org, bsalomon@google.com, reed@google.com, mtklein@google.com
Author: sugoi@chromium.org
Review URL: https://chromiumcodereview.appspot.com/24157005
git-svn-id: http://skia.googlecode.com/svn/trunk@11475 2bbb7eff-a529-9590-31e7-b0007b416f81
2013-09-26 16:09:28 +00:00
|
|
|
paint.setImageFilter(filter);
|
2015-09-15 18:26:13 +00:00
|
|
|
DrawClippedImage(canvas, image, paint, 1, cropRect);
|
|
|
|
canvas->translate(SkIntToScalar(image->width() + MARGIN), 0);
|
Moving 4 SkImageFilter derived classes from blink to skia
There were 4 classes in blink that derived from SkImageFilter :
- TileImageFilter -> SkTileImageFilter
- OffsetImageFilter -> SkOffsetImageFilter (already existed)
- FloodImageFilter -> SkFloodImageFilter
- CompositeImageFilter -> SkCompositeImageFilter
All functions were copied as is, without modification (except for warnings fixes), except for the offset filter, which was merged into the existing SkOffsetImageFilter class, as a special case when a crop rect is provided. Since the names won't clash with the names in blink, it should be easy to integrate them in blink later and fix issues, if needed.
BUG=
R=senorblanco@google.com, senorblanco@chromium.org, bsalomon@google.com, reed@google.com, mtklein@google.com
Author: sugoi@chromium.org
Review URL: https://chromiumcodereview.appspot.com/24157005
git-svn-id: http://skia.googlecode.com/svn/trunk@11475 2bbb7eff-a529-9590-31e7-b0007b416f81
2013-09-26 16:09:28 +00:00
|
|
|
}
|
2014-03-04 19:05:25 +00:00
|
|
|
|
|
|
|
SkIRect cropRect = SkIRect::MakeXYWH(0, 0, 100, 100);
|
|
|
|
SkImageFilter::CropRect rect(SkRect::Make(cropRect));
|
2015-08-27 14:41:13 +00:00
|
|
|
SkAutoTUnref<SkImageFilter> filter(SkOffsetImageFilter::Create(-5, -10, nullptr, &rect));
|
2014-03-04 19:05:25 +00:00
|
|
|
paint.setImageFilter(filter);
|
2015-09-15 18:26:13 +00:00
|
|
|
DrawClippedImage(canvas, fBitmap, paint, 2, cropRect);
|
Moving 4 SkImageFilter derived classes from blink to skia
There were 4 classes in blink that derived from SkImageFilter :
- TileImageFilter -> SkTileImageFilter
- OffsetImageFilter -> SkOffsetImageFilter (already existed)
- FloodImageFilter -> SkFloodImageFilter
- CompositeImageFilter -> SkCompositeImageFilter
All functions were copied as is, without modification (except for warnings fixes), except for the offset filter, which was merged into the existing SkOffsetImageFilter class, as a special case when a crop rect is provided. Since the names won't clash with the names in blink, it should be easy to integrate them in blink later and fix issues, if needed.
BUG=
R=senorblanco@google.com, senorblanco@chromium.org, bsalomon@google.com, reed@google.com, mtklein@google.com
Author: sugoi@chromium.org
Review URL: https://chromiumcodereview.appspot.com/24157005
git-svn-id: http://skia.googlecode.com/svn/trunk@11475 2bbb7eff-a529-9590-31e7-b0007b416f81
2013-09-26 16:09:28 +00:00
|
|
|
}
|
|
|
|
private:
|
2015-09-15 18:26:13 +00:00
|
|
|
static void DrawClippedImage(SkCanvas* canvas, const SkImage* image, const SkPaint& paint,
|
|
|
|
SkScalar scale, const SkIRect& cropRect) {
|
|
|
|
SkRect clipRect = SkRect::MakeIWH(image->width(), image->height());
|
|
|
|
|
|
|
|
canvas->save();
|
|
|
|
canvas->clipRect(clipRect);
|
|
|
|
canvas->scale(scale, scale);
|
|
|
|
canvas->drawImage(image, 0, 0, &paint);
|
|
|
|
canvas->restore();
|
|
|
|
|
|
|
|
// Draw a boundary rect around the intersection of the clip rect and crop rect.
|
|
|
|
SkRect cropRectFloat;
|
|
|
|
SkMatrix::MakeScale(scale, scale).mapRect(&cropRectFloat, SkRect::Make(cropRect));
|
|
|
|
if (clipRect.intersect(cropRectFloat)) {
|
|
|
|
SkPaint strokePaint;
|
|
|
|
strokePaint.setStyle(SkPaint::kStroke_Style);
|
|
|
|
strokePaint.setStrokeWidth(2);
|
|
|
|
strokePaint.setColor(SK_ColorRED);
|
|
|
|
canvas->drawRect(clipRect, strokePaint);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
SkAutoTUnref<SkImage> fBitmap, fCheckerboard;
|
2015-09-03 20:32:33 +00:00
|
|
|
|
|
|
|
typedef skiagm::GM INHERITED;
|
Moving 4 SkImageFilter derived classes from blink to skia
There were 4 classes in blink that derived from SkImageFilter :
- TileImageFilter -> SkTileImageFilter
- OffsetImageFilter -> SkOffsetImageFilter (already existed)
- FloodImageFilter -> SkFloodImageFilter
- CompositeImageFilter -> SkCompositeImageFilter
All functions were copied as is, without modification (except for warnings fixes), except for the offset filter, which was merged into the existing SkOffsetImageFilter class, as a special case when a crop rect is provided. Since the names won't clash with the names in blink, it should be easy to integrate them in blink later and fix issues, if needed.
BUG=
R=senorblanco@google.com, senorblanco@chromium.org, bsalomon@google.com, reed@google.com, mtklein@google.com
Author: sugoi@chromium.org
Review URL: https://chromiumcodereview.appspot.com/24157005
git-svn-id: http://skia.googlecode.com/svn/trunk@11475 2bbb7eff-a529-9590-31e7-b0007b416f81
2013-09-26 16:09:28 +00:00
|
|
|
};
|
2015-06-22 16:10:14 +00:00
|
|
|
DEF_GM( return new OffsetImageFilterGM; )
|
Moving 4 SkImageFilter derived classes from blink to skia
There were 4 classes in blink that derived from SkImageFilter :
- TileImageFilter -> SkTileImageFilter
- OffsetImageFilter -> SkOffsetImageFilter (already existed)
- FloodImageFilter -> SkFloodImageFilter
- CompositeImageFilter -> SkCompositeImageFilter
All functions were copied as is, without modification (except for warnings fixes), except for the offset filter, which was merged into the existing SkOffsetImageFilter class, as a special case when a crop rect is provided. Since the names won't clash with the names in blink, it should be easy to integrate them in blink later and fix issues, if needed.
BUG=
R=senorblanco@google.com, senorblanco@chromium.org, bsalomon@google.com, reed@google.com, mtklein@google.com
Author: sugoi@chromium.org
Review URL: https://chromiumcodereview.appspot.com/24157005
git-svn-id: http://skia.googlecode.com/svn/trunk@11475 2bbb7eff-a529-9590-31e7-b0007b416f81
2013-09-26 16:09:28 +00:00
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2015-06-23 13:01:10 +00:00
|
|
|
class SimpleOffsetImageFilterGM : public skiagm::GM {
|
|
|
|
public:
|
|
|
|
SimpleOffsetImageFilterGM() {}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
SkString onShortName() override {
|
|
|
|
return SkString("simple-offsetimagefilter");
|
|
|
|
}
|
|
|
|
|
2015-06-23 21:34:58 +00:00
|
|
|
SkISize onISize() override { return SkISize::Make(640, 200); }
|
2015-06-23 13:01:10 +00:00
|
|
|
|
|
|
|
void doDraw(SkCanvas* canvas, const SkRect& r, SkImageFilter* imgf,
|
2015-08-27 14:41:13 +00:00
|
|
|
const SkRect* clipR = nullptr) {
|
2015-06-23 13:01:10 +00:00
|
|
|
SkPaint p;
|
|
|
|
|
|
|
|
if (clipR) {
|
|
|
|
p.setColor(0xFF00FF00);
|
|
|
|
p.setStyle(SkPaint::kStroke_Style);
|
|
|
|
canvas->drawRect(clipR->makeInset(SK_ScalarHalf, SK_ScalarHalf), p);
|
|
|
|
p.setStyle(SkPaint::kFill_Style);
|
|
|
|
}
|
|
|
|
|
2015-06-23 15:29:20 +00:00
|
|
|
if (imgf && imgf->cropRectIsSet()) {
|
|
|
|
SkImageFilter::CropRect cr = imgf->getCropRect();
|
|
|
|
|
|
|
|
p.setColor(0x66FF00FF);
|
|
|
|
p.setStyle(SkPaint::kStroke_Style);
|
|
|
|
canvas->drawRect(cr.rect().makeInset(SK_ScalarHalf, SK_ScalarHalf), p);
|
|
|
|
p.setStyle(SkPaint::kFill_Style);
|
|
|
|
}
|
|
|
|
|
|
|
|
p.setColor(0x660000FF);
|
2015-06-23 13:01:10 +00:00
|
|
|
canvas->drawRect(r, p);
|
|
|
|
|
|
|
|
if (clipR) {
|
|
|
|
canvas->save();
|
|
|
|
canvas->clipRect(*clipR);
|
|
|
|
}
|
2015-06-23 16:28:52 +00:00
|
|
|
if (imgf) {
|
|
|
|
p.setImageFilter(imgf)->unref();
|
|
|
|
}
|
2015-06-23 15:29:20 +00:00
|
|
|
p.setColor(0x66FF0000);
|
2015-06-23 13:01:10 +00:00
|
|
|
canvas->drawRect(r, p);
|
2015-06-23 15:29:20 +00:00
|
|
|
|
2015-06-23 13:01:10 +00:00
|
|
|
if (clipR) {
|
|
|
|
canvas->restore();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void onDraw(SkCanvas* canvas) override {
|
2015-06-23 21:34:58 +00:00
|
|
|
const SkRect r = SkRect::MakeWH(40, 40);
|
2015-06-23 13:01:10 +00:00
|
|
|
SkImageFilter::CropRect cr0(r);
|
2015-06-23 21:34:58 +00:00
|
|
|
SkImageFilter::CropRect cr1(SkRect::MakeWH(20, 20));
|
|
|
|
const SkRect r2 = SkRect::MakeXYWH(40, 0, 40, 40);
|
2015-06-23 15:29:20 +00:00
|
|
|
SkImageFilter::CropRect cr2(r2);
|
2015-06-23 13:01:10 +00:00
|
|
|
|
2015-06-23 21:34:58 +00:00
|
|
|
canvas->translate(40, 40);
|
2015-06-23 13:01:10 +00:00
|
|
|
|
2015-06-23 21:34:58 +00:00
|
|
|
canvas->save();
|
2015-08-27 14:41:13 +00:00
|
|
|
this->doDraw(canvas, r, nullptr);
|
2015-06-23 13:01:10 +00:00
|
|
|
|
2015-06-23 21:34:58 +00:00
|
|
|
canvas->translate(100, 0);
|
|
|
|
this->doDraw(canvas, r, SkOffsetImageFilter::Create(20, 20));
|
2015-06-23 13:01:10 +00:00
|
|
|
|
2015-06-23 21:34:58 +00:00
|
|
|
canvas->translate(100, 0);
|
2015-08-27 14:41:13 +00:00
|
|
|
this->doDraw(canvas, r, SkOffsetImageFilter::Create(20, 20, nullptr, &cr0));
|
2015-06-23 13:01:10 +00:00
|
|
|
|
2015-06-23 21:34:58 +00:00
|
|
|
canvas->translate(100, 0);
|
|
|
|
this->doDraw(canvas, r, SkOffsetImageFilter::Create(20, 20), &r);
|
2015-06-23 15:29:20 +00:00
|
|
|
|
2015-06-23 21:34:58 +00:00
|
|
|
canvas->translate(100, 0);
|
2015-08-27 14:41:13 +00:00
|
|
|
this->doDraw(canvas, r, SkOffsetImageFilter::Create(20, 20, nullptr, &cr1));
|
2015-06-23 15:29:20 +00:00
|
|
|
|
2015-06-23 21:34:58 +00:00
|
|
|
SkRect clipR = SkRect::MakeXYWH(40, 40, 40, 40);
|
|
|
|
canvas->translate(100, 0);
|
2015-08-27 14:41:13 +00:00
|
|
|
this->doDraw(canvas, r, SkOffsetImageFilter::Create(20, 20, nullptr, nullptr), &clipR);
|
2015-06-23 21:34:58 +00:00
|
|
|
canvas->restore();
|
|
|
|
|
|
|
|
// 2nd row
|
|
|
|
canvas->translate(0, 80);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* combos of clip and crop rects that align with src and dst
|
|
|
|
*/
|
|
|
|
|
|
|
|
// crop==clip==src
|
2015-08-27 14:41:13 +00:00
|
|
|
this->doDraw(canvas, r, SkOffsetImageFilter::Create(40, 0, nullptr, &cr0), &r);
|
2015-06-23 21:34:58 +00:00
|
|
|
|
|
|
|
// crop==src, clip==dst
|
|
|
|
canvas->translate(100, 0);
|
2015-08-27 14:41:13 +00:00
|
|
|
this->doDraw(canvas, r, SkOffsetImageFilter::Create(40, 0, nullptr, &cr0), &r2);
|
2015-06-23 21:34:58 +00:00
|
|
|
|
|
|
|
// crop==dst, clip==src
|
|
|
|
canvas->translate(100, 0);
|
2015-08-27 14:41:13 +00:00
|
|
|
this->doDraw(canvas, r, SkOffsetImageFilter::Create(40, 0, nullptr, &cr2), &r);
|
2015-06-23 21:34:58 +00:00
|
|
|
|
|
|
|
// crop==clip==dst
|
|
|
|
canvas->translate(100, 0);
|
2015-08-27 14:41:13 +00:00
|
|
|
this->doDraw(canvas, r, SkOffsetImageFilter::Create(40, 0, nullptr, &cr2), &r2);
|
2015-06-23 13:01:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
typedef skiagm::GM INHERITED;
|
|
|
|
};
|
|
|
|
DEF_GM( return new SimpleOffsetImageFilterGM; )
|