extend gradient_create bench to test opaque and alpha gradient ramps

git-svn-id: http://skia.googlecode.com/svn/trunk@7548 2bbb7eff-a529-9590-31e7-b0007b416f81
This commit is contained in:
reed@google.com 2013-02-04 18:09:58 +00:00
parent 58ba41034e
commit 73349aa332

View File

@ -221,12 +221,18 @@ private:
}; };
class Gradient2Bench : public SkBenchmark { class Gradient2Bench : public SkBenchmark {
SkString fName;
bool fHasAlpha;
public: public:
Gradient2Bench(void* param) : INHERITED(param) {} Gradient2Bench(void* param, bool hasAlpha) : INHERITED(param) {
fName.printf("gradient_create_%s", hasAlpha ? "alpha" : "opaque");
fHasAlpha = hasAlpha;
}
protected: protected:
virtual const char* onGetName() { virtual const char* onGetName() {
return "gradient_create"; return fName.c_str();
} }
virtual void onDraw(SkCanvas* canvas) { virtual void onDraw(SkCanvas* canvas) {
@ -240,10 +246,11 @@ protected:
}; };
for (int i = 0; i < SkBENCHLOOP(1000); i++) { for (int i = 0; i < SkBENCHLOOP(1000); i++) {
const int a = i % 256; const int gray = i % 256;
const int alpha = fHasAlpha ? gray : 0xFF;
SkColor colors[] = { SkColor colors[] = {
SK_ColorBLACK, SK_ColorBLACK,
SkColorSetARGB(a, a, a, a), SkColorSetARGB(alpha, gray, gray, gray),
SK_ColorWHITE }; SK_ColorWHITE };
SkShader* s = SkGradientShader::CreateLinear(pts, colors, NULL, SkShader* s = SkGradientShader::CreateLinear(pts, colors, NULL,
SK_ARRAY_COUNT(colors), SK_ARRAY_COUNT(colors),
@ -274,4 +281,5 @@ DEF_BENCH( return new GradientBench(p, kRadial2_GradType); )
DEF_BENCH( return new GradientBench(p, kRadial2_GradType, SkShader::kMirror_TileMode); ) DEF_BENCH( return new GradientBench(p, kRadial2_GradType, SkShader::kMirror_TileMode); )
DEF_BENCH( return new GradientBench(p, kConical_GradType); ) DEF_BENCH( return new GradientBench(p, kConical_GradType); )
DEF_BENCH( return new Gradient2Bench(p); ) DEF_BENCH( return new Gradient2Bench(p, false); )
DEF_BENCH( return new Gradient2Bench(p, true); )