Fix imagemagnifier GM quality and speed.
The imagemagnifier GM was applying the filter both to a saveLayer()
restore() around the whole scene, as well as to each individual
text draw.
Applying the filter only in the saveLayer() makes it run ~20x faster
on my Linux box, and the quality is improved as well (since the
primitives are not double-filtered).
BUG=skia:
Review URL: https://codereview.chromium.org/637283009
diff --git a/gm/imagemagnifier.cpp b/gm/imagemagnifier.cpp
index e2847b4..371b308 100644
--- a/gm/imagemagnifier.cpp
+++ b/gm/imagemagnifier.cpp
@@ -35,23 +35,24 @@
}
virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE {
- SkPaint paint;
- paint.setImageFilter(
+ SkPaint filterPaint;
+ filterPaint.setImageFilter(
SkMagnifierImageFilter::Create(
SkRect::MakeXYWH(SkIntToScalar(100), SkIntToScalar(100),
SkIntToScalar(WIDTH / 2),
SkIntToScalar(HEIGHT / 2)),
100))->unref();
- canvas->saveLayer(NULL, &paint);
- paint.setAntiAlias(true);
- sk_tool_utils::set_portable_typeface(&paint);
+ canvas->saveLayer(NULL, &filterPaint);
const char* str = "The quick brown fox jumped over the lazy dog.";
SkRandom rand;
for (int i = 0; i < 25; ++i) {
int x = rand.nextULessThan(WIDTH);
int y = rand.nextULessThan(HEIGHT);
+ SkPaint paint;
+ sk_tool_utils::set_portable_typeface(&paint);
paint.setColor(rand.nextBits(24) | 0xFF000000);
paint.setTextSize(rand.nextRangeScalar(0, 300));
+ paint.setAntiAlias(true);
canvas->drawText(str, strlen(str), SkIntToScalar(x),
SkIntToScalar(y), paint);
}