From: mtklein Date: Thu, 26 Mar 2015 01:13:02 +0000 (-0700) Subject: hack on linear gradient X-Git-Tag: submit/tizen/20180928.044319~3028 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=02fd592c8d190058652bb715fb34feb7a72992e5;p=platform%2Fupstream%2FlibSkiaSharp.git hack on linear gradient Am I going nuts or can we get this down to just adds and converts in the loop? #floats #n9 BUG=skia:3592 CQ_INCLUDE_TRYBOTS=client.skia.android:Test-Android-Nexus9-TegraK1-Arm64-Release-Trybot Review URL: https://codereview.chromium.org/1008973004 --- diff --git a/bench/PMFloatBench.cpp b/bench/PMFloatBench.cpp index f3caea5673..62dc444d58 100644 --- a/bench/PMFloatBench.cpp +++ b/bench/PMFloatBench.cpp @@ -21,8 +21,8 @@ static uint32_t lcg_rand(uint32_t* seed) { // I'm having better luck getting these to constant-propagate away as template parameters. template -struct PMFloatBench : public Benchmark { - PMFloatBench() {} +struct PMFloatGetSetBench : public Benchmark { + PMFloatGetSetBench() {} const char* onGetName() SK_OVERRIDE { switch (kClamp << 1 | kWide) { @@ -92,7 +92,42 @@ struct PMFloatBench : public Benchmark { }; // Extra () help DEF_BENCH not get confused by the comma inside the <>. -DEF_BENCH(return (new PMFloatBench< true, true>);) -DEF_BENCH(return (new PMFloatBench);) -DEF_BENCH(return (new PMFloatBench< true, false>);) -DEF_BENCH(return (new PMFloatBench);) +DEF_BENCH(return (new PMFloatGetSetBench< true, true>);) +DEF_BENCH(return (new PMFloatGetSetBench);) +DEF_BENCH(return (new PMFloatGetSetBench< true, false>);) +DEF_BENCH(return (new PMFloatGetSetBench);) + +struct PMFloatGradientBench : public Benchmark { + const char* onGetName() override { return "PMFloat_gradient"; } + bool isSuitableFor(Backend backend) override { return backend == kNonRendering_Backend; } + + SkPMColor fDevice[100]; + void onDraw(const int loops, SkCanvas*) override { + Sk4f c0 = SkPMFloat::FromARGB(255, 255, 0, 0), + c1 = SkPMFloat::FromARGB(255, 0, 0, 255), + dc = c1 - c0, + fx(0.1f), + dx(0.002f), + dcdx(dc*dx), + dcdx4(dcdx+dcdx+dcdx+dcdx); + + for (int n = 0; n < loops; n++) { + Sk4f a = c0 + dc*fx, // TODO: add 0.5f, here call trunc() instead of get(). + b = a + dcdx, + c = b + dcdx, + d = c + dcdx; + for (size_t i = 0; i < SK_ARRAY_COUNT(fDevice); i += 4) { + fDevice[i+0] = SkPMFloat(a).get(); + fDevice[i+1] = SkPMFloat(b).get(); + fDevice[i+2] = SkPMFloat(c).get(); + fDevice[i+3] = SkPMFloat(d).get(); + a += dcdx4; + b += dcdx4; + c += dcdx4; + d += dcdx4; + } + } + } +}; + +DEF_BENCH(return new PMFloatGradientBench;)