OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2016 Google Inc. | 2 * Copyright 2016 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 "SkRasterPipeline.h" | 9 #include "SkRasterPipeline.h" |
10 #include "SkSRGB.h" | 10 #include "SkSRGB.h" |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
132 Sk4f dr, Sk4f dg, Sk4f db, Sk4f da) { | 132 Sk4f dr, Sk4f dg, Sk4f db, Sk4f da) { |
133 auto A = 1.0f - a; | 133 auto A = 1.0f - a; |
134 r += dr * A; | 134 r += dr * A; |
135 g += dg * A; | 135 g += dg * A; |
136 b += db * A; | 136 b += db * A; |
137 a += da * A; | 137 a += da * A; |
138 | 138 |
139 st->next(x, r,g,b,a, dr,dg,db,da); | 139 st->next(x, r,g,b,a, dr,dg,db,da); |
140 } | 140 } |
141 | 141 |
142 static Sk4f clamp(const Sk4f& x) { | |
143 return Sk4f::Min(Sk4f::Max(x, 0.0f), 255.0f); | |
144 } | |
145 | |
146 static void SK_VECTORCALL store_srgb(SkRasterPipeline::Stage* st, size_t x, | 142 static void SK_VECTORCALL store_srgb(SkRasterPipeline::Stage* st, size_t x, |
147 Sk4f r, Sk4f g, Sk4f b, Sk4f a, | 143 Sk4f r, Sk4f g, Sk4f b, Sk4f a, |
148 Sk4f dr, Sk4f dg, Sk4f db, Sk4f da) { | 144 Sk4f dr, Sk4f dg, Sk4f db, Sk4f da) { |
149 auto ptr = st->ctx<uint32_t*>() + x; | 145 auto ptr = st->ctx<uint32_t*>() + x; |
150 | 146 |
151 r = clamp(sk_linear_to_srgb(r)); | 147 ( sk_linear_to_srgb(r) |
152 g = clamp(sk_linear_to_srgb(g)); | 148 | sk_linear_to_srgb(g) << 8 |
153 b = clamp(sk_linear_to_srgb(b)); | 149 | sk_linear_to_srgb(b) << 16 |
154 a = clamp( 255.0f * a ); | 150 | Sk4f_round(255.0f*a) << 24).store(ptr); |
155 | |
156 ( SkNx_cast<int>(r) | |
157 | SkNx_cast<int>(g) << 8 | |
158 | SkNx_cast<int>(b) << 16 | |
159 | SkNx_cast<int>(a) << 24 ).store(ptr); | |
160 } | 151 } |
161 | 152 |
162 static void SK_VECTORCALL store_srgb_tail(SkRasterPipeline::Stage* st, size_t x, | 153 static void SK_VECTORCALL store_srgb_tail(SkRasterPipeline::Stage* st, size_t x, |
163 Sk4f r, Sk4f g, Sk4f b, Sk4f a, | 154 Sk4f r, Sk4f g, Sk4f b, Sk4f a, |
164 Sk4f dr, Sk4f dg, Sk4f db, Sk4f da) { | 155 Sk4f dr, Sk4f dg, Sk4f db, Sk4f da) { |
165 auto ptr = st->ctx<uint32_t*>() + x; | 156 auto ptr = st->ctx<uint32_t*>() + x; |
166 | 157 |
167 auto rgba = sk_linear_to_srgb({r[0], g[0], b[0], 0}); | 158 Sk4i rgba = sk_linear_to_srgb({r[0], g[0], b[0], 0}); |
168 rgba = {rgba[0], rgba[1], rgba[2], 255.0f*a[0]}; | 159 rgba = {rgba[0], rgba[1], rgba[2], (int)(255.0f * a[0] + 0.5f)}; |
169 rgba = clamp(rgba); | |
170 | 160 |
171 SkNx_cast<uint8_t>(rgba).store(ptr); | 161 SkNx_cast<uint8_t>(rgba).store(ptr); |
172 } | 162 } |
173 | 163 |
174 class SkRasterPipelineBench : public Benchmark { | 164 class SkRasterPipelineBench : public Benchmark { |
175 public: | 165 public: |
176 SkRasterPipelineBench() {} | 166 SkRasterPipelineBench() {} |
177 | 167 |
178 bool isSuitableFor(Backend backend) override { return backend == kNonRenderi
ng_Backend; } | 168 bool isSuitableFor(Backend backend) override { return backend == kNonRenderi
ng_Backend; } |
179 const char* onGetName() override { return "SkRasterPipelineBench"; } | 169 const char* onGetName() override { return "SkRasterPipelineBench"; } |
180 | 170 |
181 void onDraw(int loops, SkCanvas*) override { | 171 void onDraw(int loops, SkCanvas*) override { |
182 SkRasterPipeline p; | 172 SkRasterPipeline p; |
183 p.append(load_s_srgb, load_s_srgb_tail, src); | 173 p.append(load_s_srgb, load_s_srgb_tail, src); |
184 p.append( scale_u8, scale_u8_tail, mask); | 174 p.append( scale_u8, scale_u8_tail, mask); |
185 p.append(load_d_srgb, load_d_srgb_tail, dst); | 175 p.append(load_d_srgb, load_d_srgb_tail, dst); |
186 p.append(srcover); | 176 p.append(srcover); |
187 p.append( store_srgb, store_srgb_tail, dst); | 177 p.append( store_srgb, store_srgb_tail, dst); |
188 | 178 |
189 while (loops --> 0) { | 179 while (loops --> 0) { |
190 p.run(N); | 180 p.run(N); |
191 } | 181 } |
192 } | 182 } |
193 }; | 183 }; |
194 | 184 |
195 DEF_BENCH( return new SkRasterPipelineBench; ) | 185 DEF_BENCH( return new SkRasterPipelineBench; ) |
OLD | NEW |