2012-08-13 14:22:17 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2012 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 "SkMagnifierImageFilter.h"
|
2013-09-16 18:19:30 +00:00
|
|
|
#include "SkRandom.h"
|
2012-08-13 14:22:17 +00:00
|
|
|
|
|
|
|
#define WIDTH 500
|
|
|
|
#define HEIGHT 500
|
|
|
|
|
|
|
|
namespace skiagm {
|
|
|
|
|
|
|
|
class ImageMagnifierGM : public GM {
|
|
|
|
public:
|
|
|
|
ImageMagnifierGM() {
|
|
|
|
this->setBGColor(0xFF000000);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
2012-08-15 16:32:19 +00:00
|
|
|
virtual uint32_t onGetFlags() const SK_OVERRIDE {
|
|
|
|
// Skip tiled drawing until https://code.google.com/p/skia/issues/detail?id=781 is fixed.
|
|
|
|
return this->INHERITED::onGetFlags() | GM::kSkipTiled_Flag;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual SkString onShortName() SK_OVERRIDE {
|
2012-08-13 14:22:17 +00:00
|
|
|
return SkString("imagemagnifier");
|
|
|
|
}
|
|
|
|
|
2012-08-15 16:32:19 +00:00
|
|
|
virtual SkISize onISize() SK_OVERRIDE {
|
2014-06-10 06:59:03 +00:00
|
|
|
return SkISize::Make(WIDTH, HEIGHT);
|
2012-08-13 14:22:17 +00:00
|
|
|
}
|
|
|
|
|
2012-08-15 16:32:19 +00:00
|
|
|
virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE {
|
2014-10-23 22:00:10 +00:00
|
|
|
SkPaint filterPaint;
|
|
|
|
filterPaint.setImageFilter(
|
2014-03-10 10:51:58 +00:00
|
|
|
SkMagnifierImageFilter::Create(
|
2013-10-21 15:59:26 +00:00
|
|
|
SkRect::MakeXYWH(SkIntToScalar(100), SkIntToScalar(100),
|
2012-08-13 14:22:17 +00:00
|
|
|
SkIntToScalar(WIDTH / 2),
|
|
|
|
SkIntToScalar(HEIGHT / 2)),
|
|
|
|
100))->unref();
|
2014-10-23 22:00:10 +00:00
|
|
|
canvas->saveLayer(NULL, &filterPaint);
|
2012-08-13 14:22:17 +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-08-13 14:22:17 +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);
|
2014-10-23 22:00:10 +00:00
|
|
|
SkPaint paint;
|
|
|
|
sk_tool_utils::set_portable_typeface(&paint);
|
2013-09-16 18:19:30 +00:00
|
|
|
paint.setColor(rand.nextBits(24) | 0xFF000000);
|
2013-09-16 19:05:44 +00:00
|
|
|
paint.setTextSize(rand.nextRangeScalar(0, 300));
|
2014-10-23 22:00:10 +00:00
|
|
|
paint.setAntiAlias(true);
|
2012-08-13 14:22:17 +00:00
|
|
|
canvas->drawText(str, strlen(str), SkIntToScalar(x),
|
|
|
|
SkIntToScalar(y), paint);
|
|
|
|
}
|
|
|
|
canvas->restore();
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
typedef GM INHERITED;
|
|
|
|
};
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
static GM* MyFactory(void*) { return new ImageMagnifierGM; }
|
|
|
|
static GMRegistry reg(MyFactory);
|
|
|
|
|
|
|
|
}
|