mtklein | 281b33f | 2016-07-12 15:01:26 -0700 | [diff] [blame] | 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" |
Mike Klein | 9161ef0 | 2016-10-04 14:03:27 -0400 | [diff] [blame] | 9 | #include "SkHalf.h" |
mtklein | 281b33f | 2016-07-12 15:01:26 -0700 | [diff] [blame] | 10 | #include "SkRasterPipeline.h" |
| 11 | |
mtklein | 281b33f | 2016-07-12 15:01:26 -0700 | [diff] [blame] | 12 | DEF_TEST(SkRasterPipeline, r) { |
Mike Klein | 9161ef0 | 2016-10-04 14:03:27 -0400 | [diff] [blame] | 13 | // Build and run a simple pipeline to exercise SkRasterPipeline, |
| 14 | // drawing 50% transparent blue over opaque red in half-floats. |
Mike Klein | 26bea5d | 2016-10-05 10:36:38 -0400 | [diff] [blame] | 15 | uint64_t red = 0x3c00000000003c00ull, |
| 16 | blue = 0x3800380000000000ull, |
| 17 | result; |
Mike Klein | d0ccb57 | 2016-10-05 09:36:26 -0400 | [diff] [blame] | 18 | |
Mike Klein | bd3fe47 | 2016-10-25 15:43:46 -0400 | [diff] [blame] | 19 | void* load_s_ctx = &blue; |
| 20 | void* load_d_ctx = &red; |
| 21 | void* store_ctx = &result; |
| 22 | |
mtklein | 281b33f | 2016-07-12 15:01:26 -0700 | [diff] [blame] | 23 | SkRasterPipeline p; |
Mike Klein | 729b582 | 2016-11-28 18:23:23 -0500 | [diff] [blame] | 24 | p.append(SkRasterPipeline::load_f16, &load_s_ctx); |
Mike Klein | 8c8cb5b | 2017-01-06 10:21:56 -0500 | [diff] [blame] | 25 | p.append(SkRasterPipeline::move_src_dst); |
| 26 | p.append(SkRasterPipeline::load_f16, &load_d_ctx); |
| 27 | p.append(SkRasterPipeline::swap); |
Mike Klein | 9161ef0 | 2016-10-04 14:03:27 -0400 | [diff] [blame] | 28 | p.append(SkRasterPipeline::srcover); |
Mike Klein | bd3fe47 | 2016-10-25 15:43:46 -0400 | [diff] [blame] | 29 | p.append(SkRasterPipeline::store_f16, &store_ctx); |
Mike Klein | 319ba3d | 2017-01-20 15:11:54 -0500 | [diff] [blame] | 30 | p.run(0,1); |
mtklein | 281b33f | 2016-07-12 15:01:26 -0700 | [diff] [blame] | 31 | |
Mike Klein | 9161ef0 | 2016-10-04 14:03:27 -0400 | [diff] [blame] | 32 | // We should see half-intensity magenta. |
Mike Klein | 26bea5d | 2016-10-05 10:36:38 -0400 | [diff] [blame] | 33 | REPORTER_ASSERT(r, ((result >> 0) & 0xffff) == 0x3800); |
| 34 | REPORTER_ASSERT(r, ((result >> 16) & 0xffff) == 0x0000); |
| 35 | REPORTER_ASSERT(r, ((result >> 32) & 0xffff) == 0x3800); |
| 36 | REPORTER_ASSERT(r, ((result >> 48) & 0xffff) == 0x3c00); |
mtklein | 281b33f | 2016-07-12 15:01:26 -0700 | [diff] [blame] | 37 | } |
mtklein | 0abddf7 | 2016-07-13 08:22:20 -0700 | [diff] [blame] | 38 | |
| 39 | DEF_TEST(SkRasterPipeline_empty, r) { |
| 40 | // No asserts... just a test that this is safe to run. |
| 41 | SkRasterPipeline p; |
Mike Klein | 319ba3d | 2017-01-20 15:11:54 -0500 | [diff] [blame] | 42 | p.run(0,20); |
mtklein | 0abddf7 | 2016-07-13 08:22:20 -0700 | [diff] [blame] | 43 | } |
| 44 | |
| 45 | DEF_TEST(SkRasterPipeline_nonsense, r) { |
| 46 | // No asserts... just a test that this is safe to run and terminates. |
Mike Klein | 9161ef0 | 2016-10-04 14:03:27 -0400 | [diff] [blame] | 47 | // srcover() calls st->next(); this makes sure we've always got something there to call. |
mtklein | 0abddf7 | 2016-07-13 08:22:20 -0700 | [diff] [blame] | 48 | SkRasterPipeline p; |
Mike Klein | 9161ef0 | 2016-10-04 14:03:27 -0400 | [diff] [blame] | 49 | p.append(SkRasterPipeline::srcover); |
Mike Klein | 319ba3d | 2017-01-20 15:11:54 -0500 | [diff] [blame] | 50 | p.run(0,20); |
mtklein | 0abddf7 | 2016-07-13 08:22:20 -0700 | [diff] [blame] | 51 | } |
Mike Klein | 7ba89a1 | 2017-01-10 13:42:51 -0500 | [diff] [blame] | 52 | |
| 53 | DEF_TEST(SkRasterPipeline_JIT, r) { |
| 54 | // This tests a couple odd corners that a JIT backend can stumble over. |
| 55 | |
| 56 | uint32_t buf[72] = { |
| 57 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
| 58 | 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, |
| 59 | 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, |
| 60 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
| 61 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
| 62 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
| 63 | }; |
| 64 | |
| 65 | const uint32_t* src = buf + 0; |
| 66 | uint32_t* dst = buf + 36; |
| 67 | |
| 68 | // Copy buf[x] to buf[x+36] for x in [15,35). |
| 69 | SkRasterPipeline p; |
| 70 | p.append(SkRasterPipeline:: load_8888, &src); |
| 71 | p.append(SkRasterPipeline::store_8888, &dst); |
Mike Klein | 8729e5b | 2017-02-16 06:51:48 -0500 | [diff] [blame] | 72 | p.run(15, 20); |
Mike Klein | 7ba89a1 | 2017-01-10 13:42:51 -0500 | [diff] [blame] | 73 | |
| 74 | for (int i = 0; i < 36; i++) { |
| 75 | if (i < 15 || i == 35) { |
| 76 | REPORTER_ASSERT(r, dst[i] == 0); |
| 77 | } else { |
| 78 | REPORTER_ASSERT(r, dst[i] == (uint32_t)(i - 11)); |
| 79 | } |
| 80 | } |
| 81 | } |