blob: 71d91e7f42a1b6746093fce5aa2cf6645129064e [file] [log] [blame]
senorblanco@chromium.orgc4b12f12014-02-05 17:51:22 +00001/*
2 * Copyright 2014 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
Mike Kleinc0bd9f92019-04-23 12:05:21 -05008#include "gm/gm.h"
Ben Wagner7fde8e12019-05-01 17:28:53 -04009#include "include/core/SkCanvas.h"
10#include "include/core/SkFont.h"
11#include "include/core/SkImageFilter.h"
12#include "include/core/SkPaint.h"
13#include "include/core/SkRect.h"
14#include "include/core/SkScalar.h"
15#include "include/core/SkSize.h"
16#include "include/core/SkString.h"
17#include "include/core/SkTypeface.h"
18#include "include/core/SkTypes.h"
Michael Ludwig898bbfa2019-08-02 15:21:23 -040019#include "include/effects/SkImageFilters.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050020#include "tools/ToolUtils.h"
Kevin Lubicke836c3a2023-10-20 06:55:35 -040021#include "tools/fonts/FontToolUtils.h"
senorblanco@chromium.orgc4b12f12014-02-05 17:51:22 +000022
23#define WIDTH 640
24#define HEIGHT 480
25
26namespace skiagm {
27
28class ImageBlurTiledGM : public GM {
29public:
30 ImageBlurTiledGM(SkScalar sigmaX, SkScalar sigmaY)
31 : fSigmaX(sigmaX), fSigmaY(sigmaY) {
32 }
33
34protected:
Leandro Lovisolo24fa2112023-08-15 19:05:17 +000035 SkString getName() const override { return SkString("imageblurtiled"); }
senorblanco@chromium.orgc4b12f12014-02-05 17:51:22 +000036
Leandro Lovisolo8f023882023-08-15 21:13:52 +000037 SkISize getISize() override { return SkISize::Make(WIDTH, HEIGHT); }
senorblanco@chromium.orgc4b12f12014-02-05 17:51:22 +000038
robertphillips6e7025a2016-04-04 04:31:25 -070039 void onDraw(SkCanvas* canvas) override {
senorblanco@chromium.orgc4b12f12014-02-05 17:51:22 +000040 SkPaint paint;
Michael Ludwig898bbfa2019-08-02 15:21:23 -040041 paint.setImageFilter(SkImageFilters::Blur(fSigmaX, fSigmaY, nullptr));
robertphillips6e7025a2016-04-04 04:31:25 -070042 const SkScalar tileSize = SkIntToScalar(128);
Mike Reed918e1442017-01-23 11:39:45 -050043 SkRect bounds = canvas->getLocalClipBounds();
robertphillips6e7025a2016-04-04 04:31:25 -070044 for (SkScalar y = bounds.top(); y < bounds.bottom(); y += tileSize) {
45 for (SkScalar x = bounds.left(); x < bounds.right(); x += tileSize) {
senorblanco@chromium.orgc4b12f12014-02-05 17:51:22 +000046 canvas->save();
robertphillips6e7025a2016-04-04 04:31:25 -070047 canvas->clipRect(SkRect::MakeXYWH(x, y, tileSize, tileSize));
halcanary96fcdcc2015-08-27 07:41:13 -070048 canvas->saveLayer(nullptr, &paint);
senorblanco@chromium.orgc4b12f12014-02-05 17:51:22 +000049 const char* str[] = {
50 "The quick",
51 "brown fox",
52 "jumped over",
53 "the lazy dog.",
54 };
Kevin Lubicke836c3a2023-10-20 06:55:35 -040055 SkFont font(ToolUtils::DefaultPortableTypeface(), 100);
senorblanco@chromium.orgc4b12f12014-02-05 17:51:22 +000056 int posY = 0;
Herb Derbyc37b3862022-06-21 09:49:17 -040057 for (unsigned i = 0; i < std::size(str); i++) {
senorblanco@chromium.orgc4b12f12014-02-05 17:51:22 +000058 posY += 100;
Mike Reed1af9b482019-01-07 11:01:57 -050059 canvas->drawString(str[i], 0, SkIntToScalar(posY), font, SkPaint());
senorblanco@chromium.orgc4b12f12014-02-05 17:51:22 +000060 }
61 canvas->restore();
62 canvas->restore();
63 }
64 }
65 }
66
67private:
68 SkScalar fSigmaX;
69 SkScalar fSigmaY;
70
John Stiles7571f9e2020-09-02 22:42:33 -040071 using INHERITED = GM;
senorblanco@chromium.orgc4b12f12014-02-05 17:51:22 +000072};
73
74//////////////////////////////////////////////////////////////////////////////
75
robertphillips6e7025a2016-04-04 04:31:25 -070076DEF_GM(return new ImageBlurTiledGM(3.0f, 3.0f);)
senorblanco@chromium.orgc4b12f12014-02-05 17:51:22 +000077
John Stilesa6841be2020-08-06 14:11:56 -040078} // namespace skiagm