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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "gm.h"
|
|
|
|
#include "SkBlurImageFilter.h"
|
2013-09-16 18:19:30 +00:00
|
|
|
#include "SkRandom.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;
|
2014-03-10 10:51:58 +00:00
|
|
|
paint.setImageFilter(SkBlurImageFilter::Create(fSigmaX, fSigmaY))->unref();
|
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;
|
|
|
|
textPaint.setAntiAlias(true);
|
2015-07-24 19:09:25 +00:00
|
|
|
sk_tool_utils::set_portable_typeface(&textPaint);
|
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);
|
2015-07-16 21:16:04 +00:00
|
|
|
textPaint.setColor(sk_tool_utils::color_to_565(rand.nextBits(24) | 0xFF000000));
|
2013-09-16 19:05:44 +00:00
|
|
|
textPaint.setTextSize(rand.nextRangeScalar(0, 300));
|
2012-04-10 17:42:21 +00:00
|
|
|
canvas->drawText(str, strlen(str), SkIntToScalar(x),
|
2012-07-18 19:52:53 +00:00
|
|
|
SkIntToScalar(y), 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
|
|
|
}
|