blob: bf5d3d11046d0b07958344f26c055622ad712c44 [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"
9#include "SkBlurImageFilter.h"
10#include "SkRandom.h"
11
12#define WIDTH 640
13#define HEIGHT 480
14
15namespace skiagm {
16
17class ImageBlurTiledGM : public GM {
18public:
19 ImageBlurTiledGM(SkScalar sigmaX, SkScalar sigmaY)
20 : fSigmaX(sigmaX), fSigmaY(sigmaY) {
21 }
22
23protected:
robertphillips6e7025a2016-04-04 04:31:25 -070024 SkString onShortName() override {
senorblanco@chromium.orgc4b12f12014-02-05 17:51:22 +000025 return SkString("imageblurtiled");
26 }
27
robertphillips6e7025a2016-04-04 04:31:25 -070028 SkISize onISize() override {
tfarinaf5393182014-06-09 23:59:03 -070029 return SkISize::Make(WIDTH, HEIGHT);
senorblanco@chromium.orgc4b12f12014-02-05 17:51:22 +000030 }
31
robertphillips6e7025a2016-04-04 04:31:25 -070032 void onDraw(SkCanvas* canvas) override {
senorblanco@chromium.orgc4b12f12014-02-05 17:51:22 +000033 SkPaint paint;
robertphillips6e7025a2016-04-04 04:31:25 -070034 paint.setImageFilter(SkBlurImageFilter::Make(fSigmaX, fSigmaY, nullptr));
35 const SkScalar tileSize = SkIntToScalar(128);
Mike Reed918e1442017-01-23 11:39:45 -050036 SkRect bounds = canvas->getLocalClipBounds();
robertphillips6e7025a2016-04-04 04:31:25 -070037 for (SkScalar y = bounds.top(); y < bounds.bottom(); y += tileSize) {
38 for (SkScalar x = bounds.left(); x < bounds.right(); x += tileSize) {
senorblanco@chromium.orgc4b12f12014-02-05 17:51:22 +000039 canvas->save();
robertphillips6e7025a2016-04-04 04:31:25 -070040 canvas->clipRect(SkRect::MakeXYWH(x, y, tileSize, tileSize));
halcanary96fcdcc2015-08-27 07:41:13 -070041 canvas->saveLayer(nullptr, &paint);
senorblanco@chromium.orgc4b12f12014-02-05 17:51:22 +000042 const char* str[] = {
43 "The quick",
44 "brown fox",
45 "jumped over",
46 "the lazy dog.",
47 };
48 SkPaint textPaint;
49 textPaint.setAntiAlias(true);
caryclark1818acb2015-07-24 12:09:25 -070050 sk_tool_utils::set_portable_typeface(&textPaint);
senorblanco@chromium.orgc4b12f12014-02-05 17:51:22 +000051 textPaint.setTextSize(SkIntToScalar(100));
52 int posY = 0;
53 for (unsigned i = 0; i < SK_ARRAY_COUNT(str); i++) {
54 posY += 100;
55 canvas->drawText(str[i], strlen(str[i]), SkIntToScalar(0),
56 SkIntToScalar(posY), textPaint);
57 }
58 canvas->restore();
59 canvas->restore();
60 }
61 }
62 }
63
64private:
65 SkScalar fSigmaX;
66 SkScalar fSigmaY;
67
68 typedef GM INHERITED;
69};
70
71//////////////////////////////////////////////////////////////////////////////
72
robertphillips6e7025a2016-04-04 04:31:25 -070073DEF_GM(return new ImageBlurTiledGM(3.0f, 3.0f);)
senorblanco@chromium.orgc4b12f12014-02-05 17:51:22 +000074
75}