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

Side by Side Diff: tests/SkRasterPipelineTest.cpp

Issue 2147533002: SkRasterPipeline preliminaries (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: add & 0xff... >> is arithmetic for Sk4i Created 4 years, 5 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
« src/core/SkRasterPipeline.cpp ('K') | « src/opts/SkNx_sse.h ('k') | no next file » | 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 2016 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 "Test.h"
9 #include "SkRasterPipeline.h"
10
11 DEF_TEST(SkRasterPipeline, r) {
12 // We'll build up and run a simple pipeline that exercises the salient
13 // mechanics of SkRasterPipeline:
14 // - context pointers
15 // - stages sensitive to the number of pixels
16 // - stages insensitive to the number of pixels
17 //
18 // This pipeline loads up some values, squares them, then writes them back t o memory.
19
20 SkRasterPipeline p;
21
22 // Load needs two variants, one to load 4 values...
23 auto load_4 = [](SkRasterPipeline::Stage* st, size_t x, Sk4f v0, Sk4f v1, Sk 4f v2, Sk4f v3,
24 Sk4f v4, Sk4f v5, Sk 4f v6, Sk4f v7) {
25 auto ptr = st->ctx<const float*>();
26 v0 = Sk4f{ptr[x+0]};
27 v1 = Sk4f{ptr[x+1]};
28 v2 = Sk4f{ptr[x+2]};
29 v3 = Sk4f{ptr[x+3]};
30
31 st->next(x, v0,v1,v2,v3, v4,v5,v6,v7);
32 };
33 // ...and one to load a single value.
34 auto load_1 = [](SkRasterPipeline::Stage* st, size_t x, Sk4f v0, Sk4f v1, Sk 4f v2, Sk4f v3,
35 Sk4f v4, Sk4f v5, Sk 4f v6, Sk4f v7) {
36 auto ptr = st->ctx<const float*>();
37 v0 = Sk4f{ptr[x]};
38
39 st->next(x, v0,v1,v2,v3, v4,v5,v6,v7);
40 };
41
42 // square doesn't really care how many of its inputs are active, nor does it need a context.
43 auto square = [](SkRasterPipeline::Stage* st, size_t x, Sk4f v0, Sk4f v1, Sk 4f v2, Sk4f v3,
44 Sk4f v4, Sk4f v5, Sk 4f v6, Sk4f v7) {
45 v0 *= v0;
46 v1 *= v1;
47 v2 *= v2;
48 v3 *= v3;
49 st->next(x, v0,v1,v2,v3, v4,v5,v6,v7);
50 };
51
52 // Like load, store has _4 and _1 variants. It ends the pipeline by returni ng.
53 auto store_4 = [](SkRasterPipeline::Stage* st, size_t x, Sk4f v0, Sk4f v1, S k4f v2, Sk4f v3,
54 Sk4f v4, Sk4f v5, S k4f v6, Sk4f v7) {
55 auto ptr = st->ctx<float*>();
56 ptr[x+0] = v0[0];
57 ptr[x+1] = v1[0];
58 ptr[x+2] = v2[0];
59 ptr[x+3] = v3[0];
60 };
61 auto store_1 = [](SkRasterPipeline::Stage* st, size_t x, Sk4f v0, Sk4f v1, S k4f v2, Sk4f v3,
62 Sk4f v4, Sk4f v5, S k4f v6, Sk4f v7) {
63 auto ptr = st->ctx<float*>();
64 ptr[x+0] = v0[0];
65 };
66
67 const float src_vals[] = { 1,2,3,4,5 };
68 float dst_vals[] = { 0,0,0,0,0 };
69 p.append(load_4, load_1, src_vals);
70 p.append(square);
71 p.append(store_4, store_1, dst_vals);
72
73 // Run the pipeline.
74 p.run(5);
75
76 REPORTER_ASSERT(r, dst_vals[0] == 1);
77 REPORTER_ASSERT(r, dst_vals[1] == 4);
78 REPORTER_ASSERT(r, dst_vals[2] == 9);
79 REPORTER_ASSERT(r, dst_vals[3] == 16);
80 REPORTER_ASSERT(r, dst_vals[4] == 25);
81 }
OLDNEW
« src/core/SkRasterPipeline.cpp ('K') | « src/opts/SkNx_sse.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698