blob: 867baf791898630eede574d197bd041d5b11a674 [file] [log] [blame]
mtklein281b33f2016-07-12 15:01:26 -07001/*
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
mtkleinfe2042e2016-07-29 14:27:41 -070011SK_RASTER_STAGE(load) {
12 auto ptr = (const float*)ctx + x;
Mike Kleinc8dd6bc2016-09-28 10:43:53 -040013 switch(tail&3) {
14 case 0: a = Sk4f{ptr[3]};
15 case 3: b = Sk4f{ptr[2]};
16 case 2: g = Sk4f{ptr[1]};
17 case 1: r = Sk4f{ptr[0]};
18 }
mtklein281b33f2016-07-12 15:01:26 -070019}
20
mtkleinfe2042e2016-07-29 14:27:41 -070021SK_RASTER_STAGE(square) {
22 r *= r;
23 g *= g;
24 b *= b;
25 a *= a;
mtklein281b33f2016-07-12 15:01:26 -070026}
27
mtkleinfe2042e2016-07-29 14:27:41 -070028SK_RASTER_STAGE(store) {
29 auto ptr = (float*)ctx + x;
Mike Kleinc8dd6bc2016-09-28 10:43:53 -040030 switch (tail&3) {
31 case 0: ptr[3] = a[0];
32 case 3: ptr[2] = b[0];
33 case 2: ptr[1] = g[0];
34 case 1: ptr[0] = r[0];
35 }
mtklein281b33f2016-07-12 15:01:26 -070036}
37
38DEF_TEST(SkRasterPipeline, r) {
39 // We'll build up and run a simple pipeline that exercises the salient
40 // mechanics of SkRasterPipeline:
Mike Kleinc8dd6bc2016-09-28 10:43:53 -040041 // - context pointers (load,store)
42 // - stages sensitive to the number of pixels (load,store)
43 // - stages insensitive to the number of pixels (square)
mtklein281b33f2016-07-12 15:01:26 -070044 //
45 // This pipeline loads up some values, squares them, then writes them back to memory.
46
47 const float src_vals[] = { 1,2,3,4,5 };
48 float dst_vals[] = { 0,0,0,0,0 };
49
50 SkRasterPipeline p;
Mike Kleinc8dd6bc2016-09-28 10:43:53 -040051 p.append<load>(src_vals);
mtkleinfe2042e2016-07-29 14:27:41 -070052 p.append<square>();
Mike Kleinc8dd6bc2016-09-28 10:43:53 -040053 p.append<store>(dst_vals);
mtklein281b33f2016-07-12 15:01:26 -070054
55 p.run(5);
56
57 REPORTER_ASSERT(r, dst_vals[0] == 1);
58 REPORTER_ASSERT(r, dst_vals[1] == 4);
59 REPORTER_ASSERT(r, dst_vals[2] == 9);
60 REPORTER_ASSERT(r, dst_vals[3] == 16);
61 REPORTER_ASSERT(r, dst_vals[4] == 25);
62}
mtklein0abddf72016-07-13 08:22:20 -070063
64DEF_TEST(SkRasterPipeline_empty, r) {
65 // No asserts... just a test that this is safe to run.
66 SkRasterPipeline p;
67 p.run(20);
68}
69
70DEF_TEST(SkRasterPipeline_nonsense, r) {
71 // No asserts... just a test that this is safe to run and terminates.
72 // square() always calls st->next(); this makes sure we've always got something there to call.
73 SkRasterPipeline p;
mtkleinfe2042e2016-07-29 14:27:41 -070074 p.append<square>();
mtklein0abddf72016-07-13 08:22:20 -070075 p.run(20);
76}