Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(23)

Side by Side Diff: bench/Sk4fBench.cpp

Issue 1324743002: Clean up remaining users of SkPMFloat (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: scale_rgb Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « bench/PMFloatBench.cpp ('k') | src/core/SkPMFloat.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2015 Google Inc. 2 * Copyright 2015 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "Benchmark.h" 8 #include "Benchmark.h"
9 #include "SkPMFloat.h" 9 #include "SkColor.h"
10 #include "SkNx.h"
10 11
11 // Used to prevent the compiler from optimizing away the whole loop. 12 // Used to prevent the compiler from optimizing away the whole loop.
12 volatile uint32_t blackhole = 0; 13 volatile uint32_t blackhole = 0;
13 14
14 // Not a great random number generator, but it's very fast. 15 // Not a great random number generator, but it's very fast.
15 // The code we're measuring is quite fast, so low overhead is essential. 16 // The code we're measuring is quite fast, so low overhead is essential.
16 static uint32_t lcg_rand(uint32_t* seed) { 17 static uint32_t lcg_rand(uint32_t* seed) {
17 *seed *= 1664525; 18 *seed *= 1664525;
18 *seed += 1013904223; 19 *seed += 1013904223;
19 return *seed; 20 return *seed;
20 } 21 }
21 22
22 // I'm having better luck getting these to constant-propagate away as template p arameters. 23 struct Sk4fBytesRoundtripBench : public Benchmark {
23 struct PMFloatRoundtripBench : public Benchmark { 24 Sk4fBytesRoundtripBench() {}
24 PMFloatRoundtripBench() {}
25 25
26 const char* onGetName() override { return "SkPMFloat_roundtrip"; } 26 const char* onGetName() override { return "Sk4f_roundtrip"; }
27 bool isSuitableFor(Backend backend) override { return backend == kNonRenderi ng_Backend; } 27 bool isSuitableFor(Backend backend) override { return backend == kNonRenderi ng_Backend; }
28 28
29 void onDraw(const int loops, SkCanvas* canvas) override { 29 void onDraw(const int loops, SkCanvas* canvas) override {
30 // Unlike blackhole, junk can and probably will be a register. 30 // Unlike blackhole, junk can and probably will be a register.
31 uint32_t junk = 0; 31 uint32_t junk = 0;
32 uint32_t seed = 0; 32 uint32_t seed = 0;
33 for (int i = 0; i < loops; i++) { 33 for (int i = 0; i < loops; i++) {
34 SkPMColor color; 34 uint32_t color = lcg_rand(&seed),
35 #ifdef SK_DEBUG 35 back;
36 // Our SkASSERTs will remind us that it's technically required that we premultiply. 36 auto f = Sk4f::FromBytes((const uint8_t*)&color);
37 color = SkPreMultiplyColor(lcg_rand(&seed)); 37 f.toBytes((uint8_t*)&back);
38 #else
39 // But it's a lot faster not to, and this code won't really mind the non-PM colors.
40 color = lcg_rand(&seed);
41 #endif
42
43 auto f = SkPMFloat::FromPMColor(color);
44 SkPMColor back = f.round();
45 junk ^= back; 38 junk ^= back;
46 } 39 }
47 blackhole ^= junk; 40 blackhole ^= junk;
48 } 41 }
49 }; 42 };
50 DEF_BENCH(return new PMFloatRoundtripBench;) 43 DEF_BENCH(return new Sk4fBytesRoundtripBench;)
51 44
52 struct PMFloatGradientBench : public Benchmark { 45 struct Sk4fGradientBench : public Benchmark {
53 const char* onGetName() override { return "PMFloat_gradient"; } 46 const char* onGetName() override { return "Sk4f_gradient"; }
54 bool isSuitableFor(Backend backend) override { return backend == kNonRenderi ng_Backend; } 47 bool isSuitableFor(Backend backend) override { return backend == kNonRenderi ng_Backend; }
55 48
56 SkPMColor fDevice[100]; 49 SkPMColor fDevice[100];
57 void onDraw(const int loops, SkCanvas*) override { 50 void onDraw(const int loops, SkCanvas*) override {
58 Sk4f c0 = SkPMFloat::FromARGB(1, 1, 0, 0), 51 Sk4f c0(0,0,255,255),
59 c1 = SkPMFloat::FromARGB(1, 0, 0, 1), 52 c1(255,0,0,255),
60 dc = c1 - c0, 53 dc = c1 - c0,
61 fx(0.1f), 54 fx(0.1f),
62 dx(0.002f), 55 dx(0.002f),
63 dcdx(dc*dx), 56 dcdx(dc*dx),
64 dcdx4(dcdx+dcdx+dcdx+dcdx); 57 dcdx4(dcdx+dcdx+dcdx+dcdx);
65 58
66 for (int n = 0; n < loops; n++) { 59 for (int n = 0; n < loops; n++) {
67 Sk4f a = c0 + dc*fx, 60 Sk4f a = c0 + dc*fx + Sk4f(0.5f), // add an extra 0.5f to get round ing for free.
68 b = a + dcdx, 61 b = a + dcdx,
69 c = b + dcdx, 62 c = b + dcdx,
70 d = c + dcdx; 63 d = c + dcdx;
71 for (size_t i = 0; i < SK_ARRAY_COUNT(fDevice); i += 4) { 64 for (size_t i = 0; i < SK_ARRAY_COUNT(fDevice); i += 4) {
72 fDevice[i+0] = SkPMFloat(a).round(); 65 a.toBytes((uint8_t*)(fDevice+i+0));
73 fDevice[i+1] = SkPMFloat(b).round(); 66 b.toBytes((uint8_t*)(fDevice+i+1));
74 fDevice[i+2] = SkPMFloat(c).round(); 67 c.toBytes((uint8_t*)(fDevice+i+2));
75 fDevice[i+3] = SkPMFloat(d).round(); 68 d.toBytes((uint8_t*)(fDevice+i+3));
76 a = a + dcdx4; 69 a = a + dcdx4;
77 b = b + dcdx4; 70 b = b + dcdx4;
78 c = c + dcdx4; 71 c = c + dcdx4;
79 d = d + dcdx4; 72 d = d + dcdx4;
80 } 73 }
81 } 74 }
82 } 75 }
83 }; 76 };
84 77 DEF_BENCH(return new Sk4fGradientBench;)
85 DEF_BENCH(return new PMFloatGradientBench;)
OLDNEW
« no previous file with comments | « bench/PMFloatBench.cpp ('k') | src/core/SkPMFloat.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698