2012-08-20 14:53:21 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2012 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "gm.h"
|
|
|
|
|
2013-10-24 01:46:11 +00:00
|
|
|
#include "SkArithmeticMode.h"
|
2012-08-20 14:53:21 +00:00
|
|
|
#include "SkBlurImageFilter.h"
|
2012-08-20 19:23:24 +00:00
|
|
|
#include "SkColorFilter.h"
|
|
|
|
#include "SkColorFilterImageFilter.h"
|
2013-11-20 21:32:10 +00:00
|
|
|
#include "SkColorMatrixFilter.h"
|
2015-09-15 18:26:13 +00:00
|
|
|
#include "SkImage.h"
|
|
|
|
#include "SkImageSource.h"
|
2016-01-26 16:41:02 +00:00
|
|
|
#include "SkMatrixConvolutionImageFilter.h"
|
2016-04-12 19:41:00 +00:00
|
|
|
#include "SkOffsetImageFilter.h"
|
2014-01-30 18:58:24 +00:00
|
|
|
#include "SkReadBuffer.h"
|
2016-04-04 19:07:47 +00:00
|
|
|
#include "SkSpecialImage.h"
|
|
|
|
#include "SkSpecialSurface.h"
|
2014-01-30 18:58:24 +00:00
|
|
|
#include "SkWriteBuffer.h"
|
2012-12-04 14:18:50 +00:00
|
|
|
#include "SkMergeImageFilter.h"
|
2012-08-20 14:53:21 +00:00
|
|
|
#include "SkMorphologyImageFilter.h"
|
2013-11-20 21:32:10 +00:00
|
|
|
#include "SkXfermodeImageFilter.h"
|
2012-08-20 14:53:21 +00:00
|
|
|
|
|
|
|
class ImageFiltersGraphGM : public skiagm::GM {
|
|
|
|
public:
|
2014-05-27 16:28:43 +00:00
|
|
|
ImageFiltersGraphGM() {}
|
2012-08-20 14:53:21 +00:00
|
|
|
|
|
|
|
protected:
|
2014-04-30 13:20:45 +00:00
|
|
|
|
2015-09-03 20:32:33 +00:00
|
|
|
SkString onShortName() override {
|
2012-08-20 14:53:21 +00:00
|
|
|
return SkString("imagefiltersgraph");
|
|
|
|
}
|
|
|
|
|
2016-01-26 16:41:02 +00:00
|
|
|
SkISize onISize() override { return SkISize::Make(600, 150); }
|
2012-08-20 14:53:21 +00:00
|
|
|
|
2015-09-03 20:32:33 +00:00
|
|
|
void onOnceBeforeDraw() override {
|
2016-03-17 17:51:11 +00:00
|
|
|
fImage = SkImage::MakeFromBitmap(
|
|
|
|
sk_tool_utils::create_string_bitmap(100, 100, SK_ColorWHITE, 20, 70, 96, "e"));
|
2014-05-27 16:28:43 +00:00
|
|
|
}
|
|
|
|
|
2015-09-03 20:32:33 +00:00
|
|
|
void onDraw(SkCanvas* canvas) override {
|
2015-03-27 19:33:46 +00:00
|
|
|
canvas->clear(SK_ColorBLACK);
|
2012-10-24 15:14:26 +00:00
|
|
|
{
|
2016-04-01 16:28:51 +00:00
|
|
|
sk_sp<SkImageFilter> bitmapSource(SkImageSource::Make(fImage));
|
2016-03-30 20:34:16 +00:00
|
|
|
sk_sp<SkColorFilter> cf(SkColorFilter::MakeModeFilter(SK_ColorRED,
|
|
|
|
SkXfermode::kSrcIn_Mode));
|
2016-04-04 11:31:25 +00:00
|
|
|
sk_sp<SkImageFilter> blur(SkBlurImageFilter::Make(4.0f, 4.0f, std::move(bitmapSource)));
|
2016-04-05 16:09:36 +00:00
|
|
|
sk_sp<SkImageFilter> erode(SkErodeImageFilter::Make(4, 4, blur));
|
2016-04-05 18:50:42 +00:00
|
|
|
sk_sp<SkImageFilter> color(SkColorFilterImageFilter::Make(std::move(cf),
|
|
|
|
std::move(erode)));
|
2016-03-30 20:34:16 +00:00
|
|
|
sk_sp<SkImageFilter> merge(SkMergeImageFilter::Make(blur, color));
|
2012-10-24 15:14:26 +00:00
|
|
|
|
|
|
|
SkPaint paint;
|
2016-03-30 20:34:16 +00:00
|
|
|
paint.setImageFilter(std::move(merge));
|
2012-10-24 15:14:26 +00:00
|
|
|
canvas->drawPaint(paint);
|
2013-10-24 15:59:31 +00:00
|
|
|
canvas->translate(SkIntToScalar(100), 0);
|
2012-10-24 15:14:26 +00:00
|
|
|
}
|
|
|
|
{
|
2016-04-05 16:09:36 +00:00
|
|
|
sk_sp<SkImageFilter> morph(SkDilateImageFilter::Make(5, 5, nullptr));
|
2012-08-23 18:19:56 +00:00
|
|
|
|
2012-10-24 15:14:26 +00:00
|
|
|
SkScalar matrix[20] = { SK_Scalar1, 0, 0, 0, 0,
|
|
|
|
0, SK_Scalar1, 0, 0, 0,
|
|
|
|
0, 0, SK_Scalar1, 0, 0,
|
2013-11-25 19:44:07 +00:00
|
|
|
0, 0, 0, 0.5f, 0 };
|
2012-08-20 14:53:21 +00:00
|
|
|
|
2016-04-04 12:05:11 +00:00
|
|
|
sk_sp<SkColorFilter> matrixFilter(SkColorFilter::MakeMatrixFilterRowMajor255(matrix));
|
2016-04-05 18:50:42 +00:00
|
|
|
sk_sp<SkImageFilter> colorMorph(SkColorFilterImageFilter::Make(std::move(matrixFilter),
|
|
|
|
std::move(morph)));
|
2012-10-24 15:14:26 +00:00
|
|
|
SkPaint paint;
|
2016-03-29 18:32:50 +00:00
|
|
|
paint.setImageFilter(SkXfermodeImageFilter::Make(
|
2016-04-04 12:05:11 +00:00
|
|
|
SkXfermode::Make(SkXfermode::kSrcOver_Mode),
|
2016-04-05 19:48:34 +00:00
|
|
|
std::move(colorMorph)));
|
2016-03-29 18:32:50 +00:00
|
|
|
|
2016-03-17 17:51:11 +00:00
|
|
|
DrawClippedImage(canvas, fImage.get(), paint);
|
2013-10-24 15:59:31 +00:00
|
|
|
canvas->translate(SkIntToScalar(100), 0);
|
2012-10-24 15:14:26 +00:00
|
|
|
}
|
2013-10-24 01:46:11 +00:00
|
|
|
{
|
|
|
|
SkScalar matrix[20] = { SK_Scalar1, 0, 0, 0, 0,
|
|
|
|
0, SK_Scalar1, 0, 0, 0,
|
|
|
|
0, 0, SK_Scalar1, 0, 0,
|
2013-11-25 19:44:07 +00:00
|
|
|
0, 0, 0, 0.5f, 0 };
|
2016-04-04 12:05:11 +00:00
|
|
|
sk_sp<SkColorFilter> matrixCF(SkColorFilter::MakeMatrixFilterRowMajor255(matrix));
|
2016-04-05 18:50:42 +00:00
|
|
|
sk_sp<SkImageFilter> matrixFilter(SkColorFilterImageFilter::Make(std::move(matrixCF),
|
|
|
|
nullptr));
|
2016-04-12 19:41:00 +00:00
|
|
|
sk_sp<SkImageFilter> offsetFilter(SkOffsetImageFilter::Make(10.0f, 10.f,
|
|
|
|
matrixFilter));
|
2013-10-24 01:46:11 +00:00
|
|
|
|
|
|
|
SkPaint paint;
|
2016-03-29 18:32:50 +00:00
|
|
|
paint.setImageFilter(
|
|
|
|
SkXfermodeImageFilter::Make(SkArithmeticMode::Make(0, SK_Scalar1, SK_Scalar1, 0),
|
2016-04-05 19:48:34 +00:00
|
|
|
std::move(matrixFilter),
|
|
|
|
std::move(offsetFilter),
|
|
|
|
nullptr));
|
2016-03-29 18:32:50 +00:00
|
|
|
|
2016-03-17 17:51:11 +00:00
|
|
|
DrawClippedImage(canvas, fImage.get(), paint);
|
2013-10-24 15:59:31 +00:00
|
|
|
canvas->translate(SkIntToScalar(100), 0);
|
|
|
|
}
|
|
|
|
{
|
2016-04-04 11:31:25 +00:00
|
|
|
sk_sp<SkImageFilter> blur(SkBlurImageFilter::Make(SkIntToScalar(10),
|
|
|
|
SkIntToScalar(10),
|
|
|
|
nullptr));
|
2013-10-24 15:59:31 +00:00
|
|
|
|
|
|
|
SkImageFilter::CropRect cropRect(SkRect::MakeWH(SkIntToScalar(95), SkIntToScalar(100)));
|
|
|
|
SkPaint paint;
|
2016-03-29 18:32:50 +00:00
|
|
|
paint.setImageFilter(
|
2016-04-05 19:48:34 +00:00
|
|
|
SkXfermodeImageFilter::Make(SkXfermode::Make(SkXfermode::kSrcIn_Mode),
|
|
|
|
std::move(blur),
|
2016-03-29 18:32:50 +00:00
|
|
|
nullptr, &cropRect));
|
2016-03-17 17:51:11 +00:00
|
|
|
DrawClippedImage(canvas, fImage.get(), paint);
|
2013-10-24 15:59:31 +00:00
|
|
|
canvas->translate(SkIntToScalar(100), 0);
|
2013-10-24 01:46:11 +00:00
|
|
|
}
|
2016-01-26 16:41:02 +00:00
|
|
|
{
|
|
|
|
// Dilate -> matrix convolution.
|
|
|
|
// This tests that a filter using asFragmentProcessor (matrix
|
|
|
|
// convolution) correctly handles a non-zero source offset
|
|
|
|
// (supplied by the dilate).
|
2016-04-05 16:09:36 +00:00
|
|
|
sk_sp<SkImageFilter> dilate(SkDilateImageFilter::Make(5, 5, nullptr));
|
2016-01-26 16:41:02 +00:00
|
|
|
|
|
|
|
SkScalar kernel[9] = {
|
|
|
|
SkIntToScalar(-1), SkIntToScalar( -1 ), SkIntToScalar(-1),
|
|
|
|
SkIntToScalar(-1), SkIntToScalar( 7 ), SkIntToScalar(-1),
|
|
|
|
SkIntToScalar(-1), SkIntToScalar( -1 ), SkIntToScalar(-1),
|
|
|
|
};
|
|
|
|
SkISize kernelSize = SkISize::Make(3, 3);
|
|
|
|
SkScalar gain = 1.0f, bias = SkIntToScalar(0);
|
|
|
|
SkIPoint kernelOffset = SkIPoint::Make(1, 1);
|
|
|
|
auto tileMode = SkMatrixConvolutionImageFilter::kClamp_TileMode;
|
|
|
|
bool convolveAlpha = false;
|
2016-04-08 15:01:20 +00:00
|
|
|
sk_sp<SkImageFilter> convolve(SkMatrixConvolutionImageFilter::Make(kernelSize,
|
|
|
|
kernel,
|
|
|
|
gain,
|
|
|
|
bias,
|
|
|
|
kernelOffset,
|
|
|
|
tileMode,
|
|
|
|
convolveAlpha,
|
|
|
|
std::move(dilate)));
|
2016-01-26 16:41:02 +00:00
|
|
|
|
|
|
|
SkPaint paint;
|
2016-04-05 16:09:36 +00:00
|
|
|
paint.setImageFilter(std::move(convolve));
|
2016-03-17 17:51:11 +00:00
|
|
|
DrawClippedImage(canvas, fImage.get(), paint);
|
2016-01-26 16:41:02 +00:00
|
|
|
canvas->translate(SkIntToScalar(100), 0);
|
|
|
|
}
|
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
|
|
|
{
|
|
|
|
// Test that crop offsets are absolute, not relative to the parent's crop rect.
|
2016-04-05 18:50:42 +00:00
|
|
|
sk_sp<SkColorFilter> cf1(SkColorFilter::MakeModeFilter(SK_ColorBLUE,
|
|
|
|
SkXfermode::kSrcIn_Mode));
|
|
|
|
sk_sp<SkColorFilter> cf2(SkColorFilter::MakeModeFilter(SK_ColorGREEN,
|
|
|
|
SkXfermode::kSrcIn_Mode));
|
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
|
|
|
SkImageFilter::CropRect outerRect(SkRect::MakeXYWH(SkIntToScalar(10), SkIntToScalar(10),
|
|
|
|
SkIntToScalar(80), SkIntToScalar(80)));
|
|
|
|
SkImageFilter::CropRect innerRect(SkRect::MakeXYWH(SkIntToScalar(20), SkIntToScalar(20),
|
|
|
|
SkIntToScalar(60), SkIntToScalar(60)));
|
2016-04-05 18:50:42 +00:00
|
|
|
sk_sp<SkImageFilter> color1(SkColorFilterImageFilter::Make(std::move(cf1),
|
|
|
|
nullptr,
|
|
|
|
&outerRect));
|
|
|
|
sk_sp<SkImageFilter> color2(SkColorFilterImageFilter::Make(std::move(cf2),
|
|
|
|
std::move(color1),
|
|
|
|
&innerRect));
|
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
|
|
|
|
|
|
|
SkPaint paint;
|
2016-04-05 16:09:36 +00:00
|
|
|
paint.setImageFilter(std::move(color2));
|
2015-03-27 19:33:46 +00:00
|
|
|
paint.setColor(SK_ColorRED);
|
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
|
|
|
canvas->drawRect(SkRect::MakeXYWH(0, 0, 100, 100), paint);
|
|
|
|
canvas->translate(SkIntToScalar(100), 0);
|
|
|
|
}
|
2012-08-20 14:53:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2015-09-15 18:26:13 +00:00
|
|
|
static void DrawClippedImage(SkCanvas* canvas, const SkImage* image, const SkPaint& paint) {
|
|
|
|
canvas->save();
|
|
|
|
canvas->clipRect(SkRect::MakeIWH(image->width(), image->height()));
|
|
|
|
canvas->drawImage(image, 0, 0, &paint);
|
|
|
|
canvas->restore();
|
|
|
|
}
|
|
|
|
|
2016-03-17 17:51:11 +00:00
|
|
|
sk_sp<SkImage> fImage;
|
2015-09-15 18:26:13 +00:00
|
|
|
|
2012-08-20 14:53:21 +00:00
|
|
|
typedef GM INHERITED;
|
|
|
|
};
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2015-09-03 20:32:33 +00:00
|
|
|
DEF_GM(return new ImageFiltersGraphGM;)
|