blob: 282b2347ef9dd232cf2de0a6d054b42828f9ced5 [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.
mtklein281b33f2016-07-12 15:01:26 -070015
Mike Klein9161ef02016-10-04 14:03:27 -040016 Sk4h red = SkFloatToHalf_finite_ftz({ 1.0f, 0.0f, 0.0f, 1.0f }),
17 blue = SkFloatToHalf_finite_ftz({ 0.0f, 0.0f, 0.5f, 0.5f }),
18 result;
mtklein281b33f2016-07-12 15:01:26 -070019
20 SkRasterPipeline p;
Mike Klein9161ef02016-10-04 14:03:27 -040021 p.append(SkRasterPipeline::load_s_f16, &blue);
22 p.append(SkRasterPipeline::load_d_f16, &red);
23 p.append(SkRasterPipeline::srcover);
24 p.append(SkRasterPipeline::store_f16, &result);
25 p.run(1);
mtklein281b33f2016-07-12 15:01:26 -070026
Mike Klein9161ef02016-10-04 14:03:27 -040027 Sk4f f = SkHalfToFloat_finite_ftz(result);
mtklein281b33f2016-07-12 15:01:26 -070028
Mike Klein9161ef02016-10-04 14:03:27 -040029 // We should see half-intensity magenta.
30 REPORTER_ASSERT(r, f[0] == 0.5f);
31 REPORTER_ASSERT(r, f[1] == 0.0f);
32 REPORTER_ASSERT(r, f[2] == 0.5f);
33 REPORTER_ASSERT(r, f[3] == 1.0f);
mtklein281b33f2016-07-12 15:01:26 -070034}
mtklein0abddf72016-07-13 08:22:20 -070035
36DEF_TEST(SkRasterPipeline_empty, r) {
37 // No asserts... just a test that this is safe to run.
38 SkRasterPipeline p;
39 p.run(20);
40}
41
42DEF_TEST(SkRasterPipeline_nonsense, r) {
43 // No asserts... just a test that this is safe to run and terminates.
Mike Klein9161ef02016-10-04 14:03:27 -040044 // srcover() calls st->next(); this makes sure we've always got something there to call.
mtklein0abddf72016-07-13 08:22:20 -070045 SkRasterPipeline p;
Mike Klein9161ef02016-10-04 14:03:27 -040046 p.append(SkRasterPipeline::srcover);
mtklein0abddf72016-07-13 08:22:20 -070047 p.run(20);
48}