blob: 3b4252a4247222f3356b3f5f944dd4006c8bbe4a [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"
senorblanco@chromium.orgc4b12f12014-02-05 17:51:22 +000021
22#define WIDTH 640
23#define HEIGHT 480
24
25namespace skiagm {
26
27class ImageBlurTiledGM : public GM {
28public:
29 ImageBlurTiledGM(SkScalar sigmaX, SkScalar sigmaY)
30 : fSigmaX(sigmaX), fSigmaY(sigmaY) {
31 }
32
33protected:
robertphillips6e7025a2016-04-04 04:31:25 -070034 SkString onShortName() override {
senorblanco@chromium.orgc4b12f12014-02-05 17:51:22 +000035 return SkString("imageblurtiled");
36 }
37
robertphillips6e7025a2016-04-04 04:31:25 -070038 SkISize onISize() override {
tfarinaf5393182014-06-09 23:59:03 -070039 return SkISize::Make(WIDTH, HEIGHT);
senorblanco@chromium.orgc4b12f12014-02-05 17:51:22 +000040 }
41
robertphillips6e7025a2016-04-04 04:31:25 -070042 void onDraw(SkCanvas* canvas) override {
senorblanco@chromium.orgc4b12f12014-02-05 17:51:22 +000043 SkPaint paint;
Michael Ludwig898bbfa2019-08-02 15:21:23 -040044 paint.setImageFilter(SkImageFilters::Blur(fSigmaX, fSigmaY, nullptr));
robertphillips6e7025a2016-04-04 04:31:25 -070045 const SkScalar tileSize = SkIntToScalar(128);
Mike Reed918e1442017-01-23 11:39:45 -050046 SkRect bounds = canvas->getLocalClipBounds();
robertphillips6e7025a2016-04-04 04:31:25 -070047 for (SkScalar y = bounds.top(); y < bounds.bottom(); y += tileSize) {
48 for (SkScalar x = bounds.left(); x < bounds.right(); x += tileSize) {
senorblanco@chromium.orgc4b12f12014-02-05 17:51:22 +000049 canvas->save();
robertphillips6e7025a2016-04-04 04:31:25 -070050 canvas->clipRect(SkRect::MakeXYWH(x, y, tileSize, tileSize));
halcanary96fcdcc2015-08-27 07:41:13 -070051 canvas->saveLayer(nullptr, &paint);
senorblanco@chromium.orgc4b12f12014-02-05 17:51:22 +000052 const char* str[] = {
53 "The quick",
54 "brown fox",
55 "jumped over",
56 "the lazy dog.",
57 };
Mike Kleinea3f0142019-03-20 11:12:10 -050058 SkFont font(ToolUtils::create_portable_typeface(), 100);
senorblanco@chromium.orgc4b12f12014-02-05 17:51:22 +000059 int posY = 0;
60 for (unsigned i = 0; i < SK_ARRAY_COUNT(str); i++) {
61 posY += 100;
Mike Reed1af9b482019-01-07 11:01:57 -050062 canvas->drawString(str[i], 0, SkIntToScalar(posY), font, SkPaint());
senorblanco@chromium.orgc4b12f12014-02-05 17:51:22 +000063 }
64 canvas->restore();
65 canvas->restore();
66 }
67 }
68 }
69
70private:
71 SkScalar fSigmaX;
72 SkScalar fSigmaY;
73
John Stiles7571f9e2020-09-02 22:42:33 -040074 using INHERITED = GM;
senorblanco@chromium.orgc4b12f12014-02-05 17:51:22 +000075};
76
77//////////////////////////////////////////////////////////////////////////////
78
robertphillips6e7025a2016-04-04 04:31:25 -070079DEF_GM(return new ImageBlurTiledGM(3.0f, 3.0f);)
senorblanco@chromium.orgc4b12f12014-02-05 17:51:22 +000080
John Stilesa6841be2020-08-06 14:11:56 -040081} // namespace skiagm