2014-08-11 20:55:34 +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"
|
|
|
|
#include "SkRandom.h"
|
|
|
|
|
|
|
|
// TODO deprecate imageblur
|
|
|
|
|
|
|
|
#define WIDTH 500
|
|
|
|
#define HEIGHT 500
|
|
|
|
|
|
|
|
static const float kBlurSigmas[] = {
|
|
|
|
0.0, 0.3f, 0.5f, 2.0f, 32.0f, 80.0f };
|
|
|
|
|
|
|
|
const char* kTestStrings[] = {
|
|
|
|
"The quick`~",
|
|
|
|
"brown fox[]",
|
|
|
|
"jumped over",
|
|
|
|
"the lazy@#$",
|
|
|
|
"dog.{}!%^&",
|
|
|
|
"*()+=-\\'\"/",
|
|
|
|
};
|
|
|
|
|
|
|
|
namespace skiagm {
|
|
|
|
|
|
|
|
class BlurImageFilter : public GM {
|
|
|
|
public:
|
|
|
|
BlurImageFilter() {
|
|
|
|
this->setBGColor(0xFFFFFFFF);
|
|
|
|
fName.printf("imageblur2");
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
SkString onShortName() override {
|
2014-08-11 20:55:34 +00:00
|
|
|
return fName;
|
|
|
|
}
|
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
SkISize onISize() override {
|
2014-08-11 20:55:34 +00:00
|
|
|
return SkISize::Make(WIDTH, HEIGHT);
|
|
|
|
}
|
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
void onDraw(SkCanvas* canvas) override {
|
2014-08-11 20:55:34 +00:00
|
|
|
const int sigmaCount = SK_ARRAY_COUNT(kBlurSigmas);
|
|
|
|
const int testStringCount = SK_ARRAY_COUNT(kTestStrings);
|
|
|
|
SkScalar dx = WIDTH / sigmaCount;
|
|
|
|
SkScalar dy = HEIGHT / sigmaCount;
|
|
|
|
const SkScalar textSize = 12;
|
|
|
|
|
|
|
|
for (int x = 0; x < sigmaCount; x++) {
|
|
|
|
SkScalar sigmaX = kBlurSigmas[x];
|
|
|
|
for (int y = 0; y < sigmaCount; y++) {
|
|
|
|
SkScalar sigmaY = kBlurSigmas[y];
|
|
|
|
|
|
|
|
SkPaint paint;
|
|
|
|
paint.setImageFilter(SkBlurImageFilter::Create(sigmaX, sigmaY))->unref();
|
2015-08-27 14:41:13 +00:00
|
|
|
canvas->saveLayer(nullptr, &paint);
|
2014-08-11 20:55:34 +00:00
|
|
|
|
|
|
|
SkRandom rand;
|
|
|
|
SkPaint textPaint;
|
|
|
|
textPaint.setAntiAlias(false);
|
2015-07-28 17:37:53 +00:00
|
|
|
textPaint.setColor(sk_tool_utils::color_to_565(rand.nextBits(24) | 0xFF000000));
|
|
|
|
sk_tool_utils::set_portable_typeface(&textPaint);
|
2014-08-11 20:55:34 +00:00
|
|
|
textPaint.setTextSize(textSize);
|
|
|
|
|
|
|
|
for (int i = 0; i < testStringCount; i++) {
|
|
|
|
canvas->drawText(kTestStrings[i],
|
|
|
|
strlen(kTestStrings[i]),
|
|
|
|
SkIntToScalar(x * dx),
|
|
|
|
SkIntToScalar(y * dy + textSize * i + textSize),
|
|
|
|
textPaint);
|
|
|
|
}
|
|
|
|
canvas->restore();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
SkString fName;
|
|
|
|
|
|
|
|
typedef GM INHERITED;
|
|
|
|
};
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
static GM* MyFactory(void*) { return new BlurImageFilter; }
|
|
|
|
static GMRegistry reg(MyFactory);
|
|
|
|
|
|
|
|
}
|