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)
|
|
|
|
|
2014-03-10 10:51:58 +00:00
|
|
|
static SkImageFilter* make0() { return SkDownSampleImageFilter::Create(SK_Scalar1 / 5); }
|
|
|
|
static SkImageFilter* make1() { return SkOffsetImageFilter::Create(SkIntToScalar(16), SkIntToScalar(16)); }
|
2011-12-20 16:19:00 +00:00
|
|
|
static SkImageFilter* make2() {
|
|
|
|
SkColorFilter* cf = SkColorFilter::CreateModeFilter(SK_ColorBLUE,
|
|
|
|
SkXfermode::kSrcIn_Mode);
|
|
|
|
SkAutoUnref aur(cf);
|
2012-10-26 19:37:00 +00:00
|
|
|
return SkColorFilterImageFilter::Create(cf);
|
2011-12-20 16:19:00 +00:00
|
|
|
}
|
|
|
|
static SkImageFilter* make3() {
|
2014-03-10 10:51:58 +00:00
|
|
|
return SkBlurImageFilter::Create(8, 0);
|
2012-01-05 21:15:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static SkImageFilter* make4() {
|
2014-03-10 10:51:58 +00:00
|
|
|
SkImageFilter* outer = SkOffsetImageFilter::Create(SkIntToScalar(16), SkIntToScalar(16));
|
|
|
|
SkImageFilter* inner = SkDownSampleImageFilter::Create(SK_Scalar1 / 5);
|
2011-12-20 16:19:00 +00:00
|
|
|
SkAutoUnref aur0(outer);
|
|
|
|
SkAutoUnref aur1(inner);
|
2014-03-10 10:51:58 +00:00
|
|
|
return SkComposeImageFilter::Create(outer, inner);
|
2011-12-20 16:19:00 +00:00
|
|
|
}
|
2012-01-05 21:15:07 +00:00
|
|
|
static SkImageFilter* make5() {
|
2014-03-10 10:51:58 +00:00
|
|
|
SkImageFilter* first = SkOffsetImageFilter::Create(SkIntToScalar(16), SkIntToScalar(16));
|
|
|
|
SkImageFilter* second = SkDownSampleImageFilter::Create(SK_Scalar1 / 5);
|
2011-12-20 16:19:00 +00:00
|
|
|
SkAutoUnref aur0(first);
|
|
|
|
SkAutoUnref aur1(second);
|
2014-03-10 10:51:58 +00:00
|
|
|
return SkMergeImageFilter::Create(first, second);
|
2011-12-20 16:19:00 +00:00
|
|
|
}
|
|
|
|
|
2012-01-05 21:15:07 +00:00
|
|
|
static SkImageFilter* make6() {
|
2014-03-10 10:51:58 +00:00
|
|
|
SkImageFilter* outer = SkOffsetImageFilter::Create(SkIntToScalar(16), SkIntToScalar(16));
|
|
|
|
SkImageFilter* inner = SkDownSampleImageFilter::Create(SK_Scalar1 / 5);
|
2011-12-20 16:19:00 +00:00
|
|
|
SkAutoUnref aur0(outer);
|
|
|
|
SkAutoUnref aur1(inner);
|
2014-03-10 10:51:58 +00:00
|
|
|
SkImageFilter* compose = SkComposeImageFilter::Create(outer, inner);
|
2011-12-20 16:19:00 +00:00
|
|
|
SkAutoUnref aur2(compose);
|
2012-08-23 18:14:13 +00:00
|
|
|
|
2011-12-20 16:19:00 +00:00
|
|
|
SkColorFilter* cf = SkColorFilter::CreateModeFilter(0x880000FF,
|
|
|
|
SkXfermode::kSrcIn_Mode);
|
|
|
|
SkAutoUnref aur3(cf);
|
2012-10-26 19:37:00 +00:00
|
|
|
SkImageFilter* blue = SkColorFilterImageFilter::Create(cf);
|
2011-12-20 16:19:00 +00:00
|
|
|
SkAutoUnref aur4(blue);
|
2012-08-23 18:14:13 +00:00
|
|
|
|
2014-03-10 10:51:58 +00:00
|
|
|
return SkMergeImageFilter::Create(compose, blue);
|
2012-01-05 21:15:07 +00:00
|
|
|
}
|
2011-12-20 16:19:00 +00:00
|
|
|
|
2012-01-05 21:15:07 +00:00
|
|
|
static SkImageFilter* make7() {
|
2014-03-10 10:51:58 +00:00
|
|
|
SkImageFilter* outer = SkOffsetImageFilter::Create(SkIntToScalar(16), SkIntToScalar(16));
|
2012-01-05 21:15:07 +00:00
|
|
|
SkImageFilter* inner = make3();
|
|
|
|
SkAutoUnref aur0(outer);
|
|
|
|
SkAutoUnref aur1(inner);
|
2014-03-10 10:51:58 +00:00
|
|
|
SkImageFilter* compose = SkComposeImageFilter::Create(outer, inner);
|
2012-01-05 21:15:07 +00:00
|
|
|
SkAutoUnref aur2(compose);
|
2012-08-23 18:14:13 +00:00
|
|
|
|
2012-01-05 21:15:07 +00:00
|
|
|
SkColorFilter* cf = SkColorFilter::CreateModeFilter(0x880000FF,
|
|
|
|
SkXfermode::kSrcIn_Mode);
|
|
|
|
SkAutoUnref aur3(cf);
|
2012-10-26 19:37:00 +00:00
|
|
|
SkImageFilter* blue = SkColorFilterImageFilter::Create(cf);
|
2012-01-05 21:15:07 +00:00
|
|
|
SkAutoUnref aur4(blue);
|
2012-08-23 18:14:13 +00:00
|
|
|
|
2014-03-10 10:51:58 +00:00
|
|
|
return SkMergeImageFilter::Create(compose, 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);
|
|
|
|
|
2011-12-20 16:19:00 +00:00
|
|
|
static 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;
|
|
|
|
paint.setImageFilter(gFilterProc[i]())->unref();
|
2011-12-20 16:19:00 +00:00
|
|
|
canvas->saveLayer(&bounds, &paint);
|
|
|
|
draw0(canvas);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
typedef GM INHERITED;
|
|
|
|
};
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
static skiagm::GM* MyFactory(void*) { return new TestImageFiltersGM; }
|
|
|
|
static skiagm::GMRegistry reg(MyFactory);
|