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

Side by Side Diff: bench/PMFloatBench.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 | « no previous file | bench/Sk4fBench.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 /*
2 * Copyright 2015 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8 #include "Benchmark.h"
9 #include "SkPMFloat.h"
10
11 // Used to prevent the compiler from optimizing away the whole loop.
12 volatile uint32_t blackhole = 0;
13
14 // 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 static uint32_t lcg_rand(uint32_t* seed) {
17 *seed *= 1664525;
18 *seed += 1013904223;
19 return *seed;
20 }
21
22 // I'm having better luck getting these to constant-propagate away as template p arameters.
23 struct PMFloatRoundtripBench : public Benchmark {
24 PMFloatRoundtripBench() {}
25
26 const char* onGetName() override { return "SkPMFloat_roundtrip"; }
27 bool isSuitableFor(Backend backend) override { return backend == kNonRenderi ng_Backend; }
28
29 void onDraw(const int loops, SkCanvas* canvas) override {
30 // Unlike blackhole, junk can and probably will be a register.
31 uint32_t junk = 0;
32 uint32_t seed = 0;
33 for (int i = 0; i < loops; i++) {
34 SkPMColor color;
35 #ifdef SK_DEBUG
36 // Our SkASSERTs will remind us that it's technically required that we premultiply.
37 color = SkPreMultiplyColor(lcg_rand(&seed));
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;
46 }
47 blackhole ^= junk;
48 }
49 };
50 DEF_BENCH(return new PMFloatRoundtripBench;)
51
52 struct PMFloatGradientBench : public Benchmark {
53 const char* onGetName() override { return "PMFloat_gradient"; }
54 bool isSuitableFor(Backend backend) override { return backend == kNonRenderi ng_Backend; }
55
56 SkPMColor fDevice[100];
57 void onDraw(const int loops, SkCanvas*) override {
58 Sk4f c0 = SkPMFloat::FromARGB(1, 1, 0, 0),
59 c1 = SkPMFloat::FromARGB(1, 0, 0, 1),
60 dc = c1 - c0,
61 fx(0.1f),
62 dx(0.002f),
63 dcdx(dc*dx),
64 dcdx4(dcdx+dcdx+dcdx+dcdx);
65
66 for (int n = 0; n < loops; n++) {
67 Sk4f a = c0 + dc*fx,
68 b = a + dcdx,
69 c = b + dcdx,
70 d = c + dcdx;
71 for (size_t i = 0; i < SK_ARRAY_COUNT(fDevice); i += 4) {
72 fDevice[i+0] = SkPMFloat(a).round();
73 fDevice[i+1] = SkPMFloat(b).round();
74 fDevice[i+2] = SkPMFloat(c).round();
75 fDevice[i+3] = SkPMFloat(d).round();
76 a = a + dcdx4;
77 b = b + dcdx4;
78 c = c + dcdx4;
79 d = d + dcdx4;
80 }
81 }
82 }
83 };
84
85 DEF_BENCH(return new PMFloatGradientBench;)
OLDNEW
« no previous file with comments | « no previous file | bench/Sk4fBench.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698