• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
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/gm.h"
9 #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"
19 #include "include/effects/SkImageFilters.h"
20 #include "tools/ToolUtils.h"
21 
22 #define WIDTH 640
23 #define HEIGHT 480
24 
25 namespace skiagm {
26 
27 class ImageBlurTiledGM : public GM {
28 public:
ImageBlurTiledGM(SkScalar sigmaX,SkScalar sigmaY)29     ImageBlurTiledGM(SkScalar sigmaX, SkScalar sigmaY)
30         : fSigmaX(sigmaX), fSigmaY(sigmaY) {
31     }
32 
33 protected:
onShortName()34     SkString onShortName() override {
35         return SkString("imageblurtiled");
36     }
37 
onISize()38     SkISize onISize() override {
39         return SkISize::Make(WIDTH, HEIGHT);
40     }
41 
onDraw(SkCanvas * canvas)42     void onDraw(SkCanvas* canvas) override {
43         SkPaint paint;
44         paint.setImageFilter(SkImageFilters::Blur(fSigmaX, fSigmaY, nullptr));
45         const SkScalar tileSize = SkIntToScalar(128);
46         SkRect bounds = canvas->getLocalClipBounds();
47         for (SkScalar y = bounds.top(); y < bounds.bottom(); y += tileSize) {
48             for (SkScalar x = bounds.left(); x < bounds.right(); x += tileSize) {
49                 canvas->save();
50                 canvas->clipRect(SkRect::MakeXYWH(x, y, tileSize, tileSize));
51                 canvas->saveLayer(nullptr, &paint);
52                 const char* str[] = {
53                     "The quick",
54                     "brown fox",
55                     "jumped over",
56                     "the lazy dog.",
57                 };
58                 SkFont font(ToolUtils::create_portable_typeface(), 100);
59                 int posY = 0;
60                 for (unsigned i = 0; i < SK_ARRAY_COUNT(str); i++) {
61                     posY += 100;
62                     canvas->drawString(str[i], 0, SkIntToScalar(posY), font, SkPaint());
63                 }
64                 canvas->restore();
65                 canvas->restore();
66             }
67         }
68     }
69 
70 private:
71     SkScalar fSigmaX;
72     SkScalar fSigmaY;
73 
74     using INHERITED = GM;
75 };
76 
77 //////////////////////////////////////////////////////////////////////////////
78 
79 DEF_GM(return new  ImageBlurTiledGM(3.0f, 3.0f);)
80 
81 }  // namespace skiagm
82