2015-08-31 17:28:49 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2015 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "gm/gm.h"
|
2019-05-01 21:28:53 +00:00
|
|
|
#include "include/core/SkCanvas.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/core/SkColor.h"
|
2019-05-01 21:28:53 +00:00
|
|
|
#include "include/core/SkImageFilter.h"
|
|
|
|
#include "include/core/SkMatrix.h"
|
|
|
|
#include "include/core/SkPaint.h"
|
|
|
|
#include "include/core/SkRect.h"
|
|
|
|
#include "include/core/SkRefCnt.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/core/SkScalar.h"
|
2019-05-01 21:28:53 +00:00
|
|
|
#include "include/core/SkSize.h"
|
|
|
|
#include "include/core/SkString.h"
|
|
|
|
#include "include/core/SkTypes.h"
|
2019-08-02 19:21:23 +00:00
|
|
|
#include "include/effects/SkImageFilters.h"
|
2015-08-31 17:28:49 +00:00
|
|
|
|
|
|
|
#define RESIZE_FACTOR_X SkIntToScalar(2)
|
|
|
|
#define RESIZE_FACTOR_Y SkIntToScalar(5)
|
|
|
|
|
|
|
|
namespace skiagm {
|
|
|
|
|
|
|
|
class ImageFiltersStrokedGM : public GM {
|
|
|
|
public:
|
|
|
|
ImageFiltersStrokedGM() {
|
|
|
|
this->setBGColor(0x00000000);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
|
|
|
SkString onShortName() override {
|
|
|
|
return SkString("imagefiltersstroked");
|
|
|
|
}
|
|
|
|
|
|
|
|
SkISize onISize() override {
|
|
|
|
return SkISize::Make(860, 500);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void draw_circle(SkCanvas* canvas, const SkRect& r, const SkPaint& paint) {
|
|
|
|
canvas->drawCircle(r.centerX(), r.centerY(),
|
|
|
|
r.width() * 2 / 5, paint);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void draw_line(SkCanvas* canvas, const SkRect& r, const SkPaint& paint) {
|
|
|
|
canvas->drawLine(r.fLeft, r.fBottom, r.fRight, r.fTop, paint);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void draw_rect(SkCanvas* canvas, const SkRect& r, const SkPaint& paint) {
|
|
|
|
canvas->drawRect(r, paint);
|
|
|
|
}
|
|
|
|
|
|
|
|
void onDraw(SkCanvas* canvas) override {
|
|
|
|
void (*drawProc[])(SkCanvas*, const SkRect&, const SkPaint&) = {
|
|
|
|
draw_line, draw_rect, draw_circle,
|
|
|
|
};
|
|
|
|
|
|
|
|
canvas->clear(SK_ColorBLACK);
|
|
|
|
|
|
|
|
SkMatrix resizeMatrix;
|
|
|
|
resizeMatrix.setScale(RESIZE_FACTOR_X, RESIZE_FACTOR_Y);
|
|
|
|
|
2016-04-05 22:09:00 +00:00
|
|
|
sk_sp<SkImageFilter> filters[] = {
|
2019-08-02 19:21:23 +00:00
|
|
|
SkImageFilters::Blur(5, 5, nullptr),
|
|
|
|
SkImageFilters::DropShadow(10, 10, 3, 3, SK_ColorGREEN, nullptr),
|
|
|
|
SkImageFilters::Offset(-16, 32, nullptr),
|
2021-02-01 18:07:32 +00:00
|
|
|
SkImageFilters::MatrixTransform(resizeMatrix, SkSamplingOptions(), nullptr),
|
2015-08-31 17:28:49 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
SkRect r = SkRect::MakeWH(64, 64);
|
|
|
|
SkScalar margin = 32;
|
|
|
|
SkPaint paint;
|
|
|
|
paint.setColor(SK_ColorWHITE);
|
|
|
|
paint.setAntiAlias(true);
|
|
|
|
paint.setStrokeWidth(10);
|
|
|
|
paint.setStyle(SkPaint::kStroke_Style);
|
|
|
|
|
|
|
|
for (size_t i = 0; i < SK_ARRAY_COUNT(drawProc); ++i) {
|
|
|
|
canvas->translate(0, margin);
|
|
|
|
canvas->save();
|
|
|
|
for (size_t j = 0; j < SK_ARRAY_COUNT(filters); ++j) {
|
|
|
|
canvas->translate(margin, 0);
|
|
|
|
canvas->save();
|
|
|
|
if (2 == j) {
|
|
|
|
canvas->translate(16, -32);
|
|
|
|
} else if (3 == j) {
|
|
|
|
canvas->scale(SkScalarInvert(RESIZE_FACTOR_X),
|
|
|
|
SkScalarInvert(RESIZE_FACTOR_Y));
|
|
|
|
}
|
|
|
|
paint.setImageFilter(filters[j]);
|
|
|
|
drawProc[i](canvas, r, paint);
|
|
|
|
canvas->restore();
|
|
|
|
canvas->translate(r.width() + margin, 0);
|
|
|
|
}
|
|
|
|
canvas->restore();
|
|
|
|
canvas->translate(0, r.height());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2020-09-03 02:42:33 +00:00
|
|
|
using INHERITED = GM;
|
2015-08-31 17:28:49 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
DEF_GM(return new ImageFiltersStrokedGM;)
|
|
|
|
|
2020-08-06 18:11:56 +00:00
|
|
|
} // namespace skiagm
|