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
|
|
|
|
|
2011-11-09 16:05:58 +00:00
|
|
|
namespace skiagm {
|
|
|
|
|
|
|
|
class ImageBlurGM : public GM {
|
|
|
|
public:
|
2014-01-13 08:16:45 +00:00
|
|
|
ImageBlurGM(SkScalar sigmaX, SkScalar sigmaY, const char* suffix)
|
|
|
|
: fSigmaX(sigmaX), fSigmaY(sigmaY) {
|
2011-11-09 16:05:58 +00:00
|
|
|
this->setBGColor(0xFF000000);
|
2014-01-13 08:16:45 +00:00
|
|
|
fName.printf("imageblur%s", suffix);
|
2011-11-09 16:05:58 +00:00
|
|
|
}
|
2012-08-23 18:14:13 +00:00
|
|
|
|
2011-11-09 16:05:58 +00:00
|
|
|
protected:
|
2014-04-30 13:20:45 +00:00
|
|
|
virtual uint32_t onGetFlags() const SK_OVERRIDE {
|
|
|
|
return kSkipTiled_Flag;
|
|
|
|
}
|
|
|
|
|
2011-11-09 16:05:58 +00:00
|
|
|
virtual SkString onShortName() {
|
2014-01-13 08:16:45 +00:00
|
|
|
return fName;
|
2011-11-09 16:05:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
virtual SkISize onISize() {
|
2011-11-16 18:20:47 +00:00
|
|
|
return make_isize(WIDTH, HEIGHT);
|
2011-11-09 16:05:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
virtual void onDraw(SkCanvas* canvas) {
|
|
|
|
SkPaint paint;
|
2014-03-10 10:51:58 +00:00
|
|
|
paint.setImageFilter(SkBlurImageFilter::Create(fSigmaX, fSigmaY))->unref();
|
2011-11-09 16:05:58 +00:00
|
|
|
canvas->saveLayer(NULL, &paint);
|
|
|
|
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);
|
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);
|
|
|
|
textPaint.setColor(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();
|
|
|
|
}
|
2012-08-23 18:14:13 +00:00
|
|
|
|
2011-11-09 16:05:58 +00:00
|
|
|
private:
|
2014-01-13 08:16:45 +00:00
|
|
|
SkScalar fSigmaX;
|
|
|
|
SkScalar fSigmaY;
|
|
|
|
SkString fName;
|
|
|
|
|
2011-11-09 16:05:58 +00:00
|
|
|
typedef GM INHERITED;
|
|
|
|
};
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2014-01-13 08:16:45 +00:00
|
|
|
static GM* MyFactory1(void*) { return new ImageBlurGM(24.0f, 0.0f, ""); }
|
|
|
|
static GMRegistry reg1(MyFactory1);
|
|
|
|
|
|
|
|
static GM* MyFactory2(void*) { return new ImageBlurGM(80.0f, 80.0f, "_large"); }
|
|
|
|
static GMRegistry reg2(MyFactory2);
|
2011-11-09 16:05:58 +00:00
|
|
|
|
|
|
|
}
|