2011-11-09 16:05:58 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2011 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "gm/gm.h"
|
|
|
|
#include "include/effects/SkBlurImageFilter.h"
|
|
|
|
#include "include/utils/SkRandom.h"
|
|
|
|
#include "tools/ToolUtils.h"
|
2011-11-09 16:05:58 +00:00
|
|
|
|
2011-11-16 18:20:47 +00:00
|
|
|
#define WIDTH 500
|
|
|
|
#define HEIGHT 500
|
|
|
|
|
2015-09-09 15:16:41 +00:00
|
|
|
void imageblurgm_draw(SkScalar fSigmaX, SkScalar fSigmaY, SkCanvas* canvas) {
|
2011-11-09 16:05:58 +00:00
|
|
|
SkPaint paint;
|
2016-04-04 11:31:25 +00:00
|
|
|
paint.setImageFilter(SkBlurImageFilter::Make(fSigmaX, fSigmaY, nullptr));
|
2015-08-27 14:41:13 +00:00
|
|
|
canvas->saveLayer(nullptr, &paint);
|
2011-11-09 16:05:58 +00:00
|
|
|
const char* str = "The quick brown fox jumped over the lazy dog.";
|
2013-09-16 18:19:30 +00:00
|
|
|
|
|
|
|
SkRandom rand;
|
2012-07-18 19:52:53 +00:00
|
|
|
SkPaint textPaint;
|
2019-03-20 16:12:10 +00:00
|
|
|
SkFont font(ToolUtils::create_portable_typeface());
|
2011-11-09 16:05:58 +00:00
|
|
|
for (int i = 0; i < 25; ++i) {
|
2013-09-16 18:19:30 +00:00
|
|
|
int x = rand.nextULessThan(WIDTH);
|
|
|
|
int y = rand.nextULessThan(HEIGHT);
|
2019-03-20 16:12:10 +00:00
|
|
|
textPaint.setColor(ToolUtils::color_to_565(rand.nextBits(24) | 0xFF000000));
|
2019-01-07 16:01:57 +00:00
|
|
|
font.setSize(rand.nextRangeScalar(0, 300));
|
|
|
|
canvas->drawString(str, SkIntToScalar(x), SkIntToScalar(y), font, textPaint);
|
2011-11-09 16:05:58 +00:00
|
|
|
}
|
|
|
|
canvas->restore();
|
2015-09-09 15:16:41 +00:00
|
|
|
}
|
|
|
|
DEF_SIMPLE_GM_BG(imageblur, canvas, WIDTH, HEIGHT, SK_ColorBLACK) {
|
|
|
|
imageblurgm_draw(24.0f, 0.0f, canvas);
|
|
|
|
}
|
|
|
|
DEF_SIMPLE_GM_BG(imageblur_large, canvas, WIDTH, HEIGHT, SK_ColorBLACK) {
|
|
|
|
imageblurgm_draw(80.0f, 80.0f, canvas);
|
2011-11-09 16:05:58 +00:00
|
|
|
}
|