add test for shader text w/ and w/o lcd (and w/ and w/o opaque)

git-svn-id: http://skia.googlecode.com/svn/trunk@2753 2bbb7eff-a529-9590-31e7-b0007b416f81
This commit is contained in:
reed@google.com 2011-11-28 16:31:28 +00:00
parent b9d1c6a3c4
commit e805535b19
2 changed files with 88 additions and 0 deletions

87
gm/gradtext.cpp Normal file
View File

@ -0,0 +1,87 @@
/*
* 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 "SkCanvas.h"
#include "SkGradientShader.h"
static SkShader* make_grad(SkScalar width) {
SkColor colors[] = { SK_ColorBLACK, SK_ColorBLACK, 0 };
SkScalar pos[] = { 0, SK_Scalar1 * 5 / 10, SK_Scalar1 };
SkPoint pts[] = { { 0, 0 }, { width, 0 } };
return SkGradientShader::CreateLinear(pts, colors, pos,
SK_ARRAY_COUNT(colors),
SkShader::kMirror_TileMode);
}
static SkShader* make_grad2(SkScalar width) {
SkColor colors[] = { SK_ColorRED, SK_ColorGREEN, SK_ColorBLUE };
SkPoint pts[] = { { 0, 0 }, { width, 0 } };
return SkGradientShader::CreateLinear(pts, colors, NULL,
SK_ARRAY_COUNT(colors),
SkShader::kMirror_TileMode);
}
namespace skiagm {
class GradTextGM : public GM {
public:
GradTextGM () {}
protected:
virtual SkString onShortName() {
return SkString("gradtext");
}
virtual SkISize onISize() { return make_isize(640, 480); }
static void draw_text(SkCanvas* canvas, const SkPaint& paint) {
const char* text = "When in the course of human events";
size_t len = strlen(text);
canvas->drawText(text, len, 0, 0, paint);
}
static void draw_text3(SkCanvas* canvas, const SkPaint& paint) {
SkPaint p(paint);
p.setAntiAlias(false);
draw_text(canvas, p);
p.setAntiAlias(true);
canvas->translate(0, SkIntToScalar(20));
draw_text(canvas, p);
p.setLCDRenderText(true);
canvas->translate(0, SkIntToScalar(20));
draw_text(canvas, p);
}
virtual void onDraw(SkCanvas* canvas) {
canvas->translate(SkIntToScalar(20), SkIntToScalar(20));
// The blits special-case opaque and non-paque shaders, so test both
SkPaint paint;
paint.setTextSize(SkIntToScalar(16));
paint.setShader(make_grad(SkIntToScalar(80)))->unref();
draw_text3(canvas, paint);
canvas->translate(0, SkIntToScalar(40));
paint.setShader(make_grad2(SkIntToScalar(80)))->unref();
draw_text3(canvas, paint);
}
private:
typedef GM INHERITED;
};
//////////////////////////////////////////////////////////////////////////////
static GM* MyFactory(void*) { return new GradTextGM; }
static GMRegistry reg(MyFactory);
}

View File

@ -12,6 +12,7 @@
'../gm/filltypespersp.cpp',
'../gm/fontscaler.cpp',
'../gm/gradients.cpp',
'../gm/gradtext.cpp',
'../gm/hairmodes.cpp',
# commented out until SkPicture support for SkImageFilter is complete
# See http://code.google.com/p/skia/issues/detail?id=391