blob: 76fbc2541c1d5e403bb33be2ae2d71f7e69b9daf [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"
Mike Klein9161ef02016-10-04 14:03:27 -04009#include "SkHalf.h"
mtklein281b33f2016-07-12 15:01:26 -070010#include "SkRasterPipeline.h"
11
mtklein281b33f2016-07-12 15:01:26 -070012DEF_TEST(SkRasterPipeline, r) {
Mike Klein9161ef02016-10-04 14:03:27 -040013 // Build and run a simple pipeline to exercise SkRasterPipeline,
14 // drawing 50% transparent blue over opaque red in half-floats.
Mike Klein26bea5d2016-10-05 10:36:38 -040015 uint64_t red = 0x3c00000000003c00ull,
16 blue = 0x3800380000000000ull,
17 result;
Mike Kleind0ccb572016-10-05 09:36:26 -040018
mtklein281b33f2016-07-12 15:01:26 -070019 SkRasterPipeline p;
Mike Klein9161ef02016-10-04 14:03:27 -040020 p.append(SkRasterPipeline::load_s_f16, &blue);
21 p.append(SkRasterPipeline::load_d_f16, &red);
22 p.append(SkRasterPipeline::srcover);
23 p.append(SkRasterPipeline::store_f16, &result);
24 p.run(1);
mtklein281b33f2016-07-12 15:01:26 -070025
Mike Klein9161ef02016-10-04 14:03:27 -040026 // We should see half-intensity magenta.
Mike Klein26bea5d2016-10-05 10:36:38 -040027 REPORTER_ASSERT(r, ((result >> 0) & 0xffff) == 0x3800);
28 REPORTER_ASSERT(r, ((result >> 16) & 0xffff) == 0x0000);
29 REPORTER_ASSERT(r, ((result >> 32) & 0xffff) == 0x3800);
30 REPORTER_ASSERT(r, ((result >> 48) & 0xffff) == 0x3c00);
mtklein281b33f2016-07-12 15:01:26 -070031}
mtklein0abddf72016-07-13 08:22:20 -070032
33DEF_TEST(SkRasterPipeline_empty, r) {
34 // No asserts... just a test that this is safe to run.
35 SkRasterPipeline p;
36 p.run(20);
37}
38
39DEF_TEST(SkRasterPipeline_nonsense, r) {
40 // No asserts... just a test that this is safe to run and terminates.
Mike Klein9161ef02016-10-04 14:03:27 -040041 // srcover() calls st->next(); this makes sure we've always got something there to call.
mtklein0abddf72016-07-13 08:22:20 -070042 SkRasterPipeline p;
Mike Klein9161ef02016-10-04 14:03:27 -040043 p.append(SkRasterPipeline::srcover);
mtklein0abddf72016-07-13 08:22:20 -070044 p.run(20);
45}