| 1 |
/* |
| 2 |
* Copyright 2011 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/SkColor.h" |
| 11 |
#include "include/core/SkFont.h" |
| 12 |
#include "include/core/SkImageFilter.h" |
| 13 |
#include "include/core/SkPaint.h" |
| 14 |
#include "include/core/SkScalar.h" |
| 15 |
#include "include/core/SkTypeface.h" |
| 16 |
#include "include/effects/SkImageFilters.h" |
| 17 |
#include "src/base/SkRandom.h" |
| 18 |
#include "tools/ToolUtils.h" |
| 19 |
#include "tools/fonts/FontToolUtils.h" |
| 20 |
|
| 21 |
#define WIDTH 500 |
| 22 |
#define HEIGHT 500 |
| 23 |
|
| 24 |
void imageblurgm_draw(SkScalar fSigmaX, SkScalar fSigmaY, SkCanvas* canvas) { |
| 25 |
SkPaint paint; |
| 26 |
paint.setImageFilter(SkImageFilters::Blur(fSigmaX, fSigmaY, nullptr)); |
| 27 |
canvas->saveLayer(nullptr, &paint); |
| 28 |
const char* str = "The quick brown fox jumped over the lazy dog."; |
| 29 |
|
| 30 |
SkRandom rand; |
| 31 |
SkPaint textPaint; |
| 32 |
SkFont font = ToolUtils::DefaultPortableFont(); |
| 33 |
for (int i = 0; i < 25; ++i) { |
| 34 |
int x = rand.nextULessThan(WIDTH); |
| 35 |
int y = rand.nextULessThan(HEIGHT); |
| 36 |
textPaint.setColor(ToolUtils::color_to_565(rand.nextBits(24) | 0xFF000000)); |
| 37 |
font.setSize(rand.nextRangeScalar(0, 300)); |
| 38 |
canvas->drawString(str, SkIntToScalar(x), SkIntToScalar(y), font, textPaint); |
| 39 |
} |
| 40 |
canvas->restore(); |
| 41 |
} |
| 42 |
DEF_SIMPLE_GM_BG(imageblur, canvas, WIDTH, HEIGHT, SK_ColorBLACK) { |
| 43 |
imageblurgm_draw(24.0f, 0.0f, canvas); |
| 44 |
} |
| 45 |
DEF_SIMPLE_GM_BG(imageblur_large, canvas, WIDTH, HEIGHT, SK_ColorBLACK) { |
| 46 |
imageblurgm_draw(80.0f, 80.0f, canvas); |
| 47 |
} |