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