blob: 5a57721f09e37bcf6a74df13359e23464be8b023 [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
8#include "gm.h"
Mike Klein33d20552017-03-22 13:47:51 -04009#include "sk_tool_utils.h"
senorblanco@chromium.orgc4b12f12014-02-05 17:51:22 +000010#include "SkBlurImageFilter.h"
11#include "SkRandom.h"
12
13#define WIDTH 640
14#define HEIGHT 480
15
16namespace skiagm {
17
18class ImageBlurTiledGM : public GM {
19public:
20 ImageBlurTiledGM(SkScalar sigmaX, SkScalar sigmaY)
21 : fSigmaX(sigmaX), fSigmaY(sigmaY) {
22 }
23
24protected:
robertphillips6e7025a2016-04-04 04:31:25 -070025 SkString onShortName() override {
senorblanco@chromium.orgc4b12f12014-02-05 17:51:22 +000026 return SkString("imageblurtiled");
27 }
28
robertphillips6e7025a2016-04-04 04:31:25 -070029 SkISize onISize() override {
tfarinaf5393182014-06-09 23:59:03 -070030 return SkISize::Make(WIDTH, HEIGHT);
senorblanco@chromium.orgc4b12f12014-02-05 17:51:22 +000031 }
32
robertphillips6e7025a2016-04-04 04:31:25 -070033 void onDraw(SkCanvas* canvas) override {
senorblanco@chromium.orgc4b12f12014-02-05 17:51:22 +000034 SkPaint paint;
robertphillips6e7025a2016-04-04 04:31:25 -070035 paint.setImageFilter(SkBlurImageFilter::Make(fSigmaX, fSigmaY, nullptr));
36 const SkScalar tileSize = SkIntToScalar(128);
Mike Reed918e1442017-01-23 11:39:45 -050037 SkRect bounds = canvas->getLocalClipBounds();
robertphillips6e7025a2016-04-04 04:31:25 -070038 for (SkScalar y = bounds.top(); y < bounds.bottom(); y += tileSize) {
39 for (SkScalar x = bounds.left(); x < bounds.right(); x += tileSize) {
senorblanco@chromium.orgc4b12f12014-02-05 17:51:22 +000040 canvas->save();
robertphillips6e7025a2016-04-04 04:31:25 -070041 canvas->clipRect(SkRect::MakeXYWH(x, y, tileSize, tileSize));
halcanary96fcdcc2015-08-27 07:41:13 -070042 canvas->saveLayer(nullptr, &paint);
senorblanco@chromium.orgc4b12f12014-02-05 17:51:22 +000043 const char* str[] = {
44 "The quick",
45 "brown fox",
46 "jumped over",
47 "the lazy dog.",
48 };
Mike Reed1af9b482019-01-07 11:01:57 -050049 SkFont font(sk_tool_utils::create_portable_typeface(), 100);
senorblanco@chromium.orgc4b12f12014-02-05 17:51:22 +000050 int posY = 0;
51 for (unsigned i = 0; i < SK_ARRAY_COUNT(str); i++) {
52 posY += 100;
Mike Reed1af9b482019-01-07 11:01:57 -050053 canvas->drawString(str[i], 0, SkIntToScalar(posY), font, SkPaint());
senorblanco@chromium.orgc4b12f12014-02-05 17:51:22 +000054 }
55 canvas->restore();
56 canvas->restore();
57 }
58 }
59 }
60
61private:
62 SkScalar fSigmaX;
63 SkScalar fSigmaY;
64
65 typedef GM INHERITED;
66};
67
68//////////////////////////////////////////////////////////////////////////////
69
robertphillips6e7025a2016-04-04 04:31:25 -070070DEF_GM(return new ImageBlurTiledGM(3.0f, 3.0f);)
senorblanco@chromium.orgc4b12f12014-02-05 17:51:22 +000071
72}