2011-12-20 16:19:00 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2011 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"
|
|
|
|
#include "SkCanvas.h"
|
|
|
|
#include "SkColorFilter.h"
|
|
|
|
#include "SkColorPriv.h"
|
|
|
|
#include "SkShader.h"
|
2012-01-05 21:15:07 +00:00
|
|
|
|
|
|
|
#include "SkBlurImageFilter.h"
|
2012-08-20 19:23:24 +00:00
|
|
|
#include "SkColorFilterImageFilter.h"
|
2013-08-07 00:07:51 +00:00
|
|
|
#include "SkComposeImageFilter.h"
|
2012-12-04 14:18:50 +00:00
|
|
|
#include "SkMergeImageFilter.h"
|
2012-11-06 20:29:39 +00:00
|
|
|
#include "SkOffsetImageFilter.h"
|
2011-12-20 16:19:00 +00:00
|
|
|
#include "SkTestImageFilters.h"
|
|
|
|
|
|
|
|
#define FILTER_WIDTH SkIntToScalar(150)
|
|
|
|
#define FILTER_HEIGHT SkIntToScalar(200)
|
|
|
|
|
2016-03-31 16:05:49 +00:00
|
|
|
static sk_sp<SkImageFilter> make0() {
|
2016-04-06 14:44:01 +00:00
|
|
|
return SkDownSampleImageFilter::Make(SK_Scalar1 / 5, nullptr);
|
2016-03-30 19:32:58 +00:00
|
|
|
}
|
|
|
|
|
2016-03-31 16:05:49 +00:00
|
|
|
static sk_sp<SkImageFilter> make1() {
|
|
|
|
return SkOffsetImageFilter::Make(SkIntToScalar(16), SkIntToScalar(16), nullptr);
|
2016-03-30 19:32:58 +00:00
|
|
|
}
|
|
|
|
|
2016-03-31 16:05:49 +00:00
|
|
|
static sk_sp<SkImageFilter> make2() {
|
2016-03-30 19:32:58 +00:00
|
|
|
sk_sp<SkColorFilter> cf(SkColorFilter::MakeModeFilter(SK_ColorBLUE, SkXfermode::kSrcIn_Mode));
|
2016-04-05 18:50:42 +00:00
|
|
|
return SkColorFilterImageFilter::Make(std::move(cf), nullptr);
|
2011-12-20 16:19:00 +00:00
|
|
|
}
|
2016-03-30 19:32:58 +00:00
|
|
|
|
2016-03-31 16:05:49 +00:00
|
|
|
static sk_sp<SkImageFilter> make3() {
|
2016-04-04 11:31:25 +00:00
|
|
|
return SkBlurImageFilter::Make(8, 0, nullptr);
|
2012-01-05 21:15:07 +00:00
|
|
|
}
|
|
|
|
|
2016-03-31 16:05:49 +00:00
|
|
|
static sk_sp<SkImageFilter> make4() {
|
|
|
|
sk_sp<SkImageFilter> outer(SkOffsetImageFilter::Make(SkIntToScalar(16),
|
|
|
|
SkIntToScalar(16),
|
|
|
|
nullptr));
|
2016-04-06 14:44:01 +00:00
|
|
|
sk_sp<SkImageFilter> inner(SkDownSampleImageFilter::Make(SK_Scalar1 / 5, nullptr));
|
2016-03-31 16:05:49 +00:00
|
|
|
return SkComposeImageFilter::Make(std::move(outer), std::move(inner));
|
2011-12-20 16:19:00 +00:00
|
|
|
}
|
2016-03-30 19:32:58 +00:00
|
|
|
|
2016-03-31 16:05:49 +00:00
|
|
|
static sk_sp<SkImageFilter> make5() {
|
|
|
|
sk_sp<SkImageFilter> first(SkOffsetImageFilter::Make(SkIntToScalar(16),
|
|
|
|
SkIntToScalar(16),
|
|
|
|
nullptr));
|
2016-04-06 14:44:01 +00:00
|
|
|
sk_sp<SkImageFilter> second(SkDownSampleImageFilter::Make(SK_Scalar1 / 5, nullptr));
|
2016-03-31 16:05:49 +00:00
|
|
|
return SkMergeImageFilter::Make(std::move(first), std::move(second));
|
2011-12-20 16:19:00 +00:00
|
|
|
}
|
|
|
|
|
2016-03-31 16:05:49 +00:00
|
|
|
static sk_sp<SkImageFilter> make6() {
|
|
|
|
sk_sp<SkImageFilter> outer(SkOffsetImageFilter::Make(SkIntToScalar(16),
|
|
|
|
SkIntToScalar(16),
|
|
|
|
nullptr));
|
2016-04-06 14:44:01 +00:00
|
|
|
sk_sp<SkImageFilter> inner(SkDownSampleImageFilter::Make(SK_Scalar1 / 5, nullptr));
|
2016-03-30 19:32:58 +00:00
|
|
|
sk_sp<SkImageFilter> compose(SkComposeImageFilter::Make(std::move(outer), std::move(inner)));
|
|
|
|
|
|
|
|
sk_sp<SkColorFilter> cf(SkColorFilter::MakeModeFilter(0x880000FF, SkXfermode::kSrcIn_Mode));
|
2016-04-05 18:50:42 +00:00
|
|
|
sk_sp<SkImageFilter> blue(SkColorFilterImageFilter::Make(std::move(cf), nullptr));
|
2016-03-30 19:32:58 +00:00
|
|
|
|
2016-03-31 16:05:49 +00:00
|
|
|
return SkMergeImageFilter::Make(std::move(compose), std::move(blue));
|
2012-01-05 21:15:07 +00:00
|
|
|
}
|
2011-12-20 16:19:00 +00:00
|
|
|
|
2016-03-31 16:05:49 +00:00
|
|
|
static sk_sp<SkImageFilter> make7() {
|
|
|
|
sk_sp<SkImageFilter> outer(SkOffsetImageFilter::Make(SkIntToScalar(16),
|
|
|
|
SkIntToScalar(16),
|
|
|
|
nullptr));
|
2016-03-30 19:32:58 +00:00
|
|
|
sk_sp<SkImageFilter> inner(make3());
|
|
|
|
sk_sp<SkImageFilter> compose(SkComposeImageFilter::Make(std::move(outer), std::move(inner)));
|
|
|
|
|
|
|
|
sk_sp<SkColorFilter> cf(SkColorFilter::MakeModeFilter(0x880000FF, SkXfermode::kSrcIn_Mode));
|
2016-04-05 18:50:42 +00:00
|
|
|
sk_sp<SkImageFilter> blue(SkColorFilterImageFilter::Make(std::move(cf), nullptr));
|
2016-03-30 19:32:58 +00:00
|
|
|
|
2016-03-31 16:05:49 +00:00
|
|
|
return SkMergeImageFilter::Make(std::move(compose), std::move(blue));
|
2011-12-20 16:19:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void draw0(SkCanvas* canvas) {
|
|
|
|
SkPaint p;
|
|
|
|
p.setAntiAlias(true);
|
|
|
|
SkRect r = SkRect::MakeWH(FILTER_WIDTH, FILTER_HEIGHT);
|
2012-01-05 21:15:07 +00:00
|
|
|
r.inset(SK_Scalar1 * 12, SK_Scalar1 * 12);
|
2011-12-20 16:19:00 +00:00
|
|
|
p.setColor(SK_ColorRED);
|
|
|
|
canvas->drawOval(r, p);
|
|
|
|
}
|
|
|
|
|
|
|
|
class TestImageFiltersGM : public skiagm::GM {
|
|
|
|
public:
|
|
|
|
TestImageFiltersGM () {}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
SkString onShortName() override {
|
2011-12-20 16:19:00 +00:00
|
|
|
return SkString("testimagefilters");
|
|
|
|
}
|
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
SkISize onISize() override { return SkISize::Make(700, 460); }
|
2011-12-20 16:19:00 +00:00
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
void onDraw(SkCanvas* canvas) override {
|
2012-01-05 21:15:07 +00:00
|
|
|
// this->drawSizeBounds(canvas, 0xFFCCCCCC);
|
|
|
|
|
2016-03-31 16:05:49 +00:00
|
|
|
static sk_sp<SkImageFilter> (*gFilterProc[])() = {
|
2012-01-05 21:15:07 +00:00
|
|
|
make0, make1, make2, make3, make4, make5, make6, make7
|
2011-12-20 16:19:00 +00:00
|
|
|
};
|
2012-08-23 18:14:13 +00:00
|
|
|
|
2011-12-20 16:19:00 +00:00
|
|
|
const SkRect bounds = SkRect::MakeWH(FILTER_WIDTH, FILTER_HEIGHT);
|
2012-08-23 18:14:13 +00:00
|
|
|
|
2011-12-20 16:19:00 +00:00
|
|
|
const SkScalar dx = bounds.width() * 8 / 7;
|
|
|
|
const SkScalar dy = bounds.height() * 8 / 7;
|
|
|
|
|
2012-01-05 21:15:07 +00:00
|
|
|
canvas->translate(SkIntToScalar(8), SkIntToScalar(8));
|
2011-12-20 16:19:00 +00:00
|
|
|
|
2014-01-27 13:42:58 +00:00
|
|
|
for (int i = 0; i < (int)SK_ARRAY_COUNT(gFilterProc); ++i) {
|
2012-01-05 21:15:07 +00:00
|
|
|
int ix = i % 4;
|
|
|
|
int iy = i / 4;
|
2011-12-20 16:19:00 +00:00
|
|
|
|
|
|
|
SkAutoCanvasRestore acr(canvas, true);
|
|
|
|
canvas->translate(ix * dx, iy * dy);
|
|
|
|
|
|
|
|
SkPaint p;
|
2012-01-05 21:15:07 +00:00
|
|
|
p.setStyle(SkPaint::kStroke_Style);
|
2011-12-20 16:19:00 +00:00
|
|
|
canvas->drawRect(bounds, p);
|
2012-08-23 18:14:13 +00:00
|
|
|
|
2012-01-05 21:15:07 +00:00
|
|
|
SkPaint paint;
|
2016-03-31 16:05:49 +00:00
|
|
|
paint.setImageFilter(gFilterProc[i]());
|
2011-12-20 16:19:00 +00:00
|
|
|
canvas->saveLayer(&bounds, &paint);
|
|
|
|
draw0(canvas);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
typedef GM INHERITED;
|
|
|
|
};
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2015-12-10 21:31:59 +00:00
|
|
|
DEF_GM( return new TestImageFiltersGM; )
|