blob: 50c417f5f015c01d4654b7a66f7252d306d2bf65 [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
Mike Kleinbd3fe472016-10-25 15:43:46 -040019 void* load_s_ctx = &blue;
20 void* load_d_ctx = &red;
21 void* store_ctx = &result;
22
mtklein281b33f2016-07-12 15:01:26 -070023 SkRasterPipeline p;
Mike Klein729b5822016-11-28 18:23:23 -050024 p.append(SkRasterPipeline::load_f16, &load_s_ctx);
25 p.append(SkRasterPipeline::load_f16_d, &load_d_ctx);
Mike Klein9161ef02016-10-04 14:03:27 -040026 p.append(SkRasterPipeline::srcover);
Mike Kleinbd3fe472016-10-25 15:43:46 -040027 p.append(SkRasterPipeline::store_f16, &store_ctx);
Mike Kleinc789b612016-11-30 13:45:06 -050028 p.run(0,0, 1);
mtklein281b33f2016-07-12 15:01:26 -070029
Mike Klein9161ef02016-10-04 14:03:27 -040030 // We should see half-intensity magenta.
Mike Klein26bea5d2016-10-05 10:36:38 -040031 REPORTER_ASSERT(r, ((result >> 0) & 0xffff) == 0x3800);
32 REPORTER_ASSERT(r, ((result >> 16) & 0xffff) == 0x0000);
33 REPORTER_ASSERT(r, ((result >> 32) & 0xffff) == 0x3800);
34 REPORTER_ASSERT(r, ((result >> 48) & 0xffff) == 0x3c00);
mtklein281b33f2016-07-12 15:01:26 -070035}
mtklein0abddf72016-07-13 08:22:20 -070036
37DEF_TEST(SkRasterPipeline_empty, r) {
38 // No asserts... just a test that this is safe to run.
39 SkRasterPipeline p;
Mike Kleinc789b612016-11-30 13:45:06 -050040 p.run(0,0, 20);
mtklein0abddf72016-07-13 08:22:20 -070041}
42
43DEF_TEST(SkRasterPipeline_nonsense, r) {
44 // No asserts... just a test that this is safe to run and terminates.
Mike Klein9161ef02016-10-04 14:03:27 -040045 // srcover() calls st->next(); this makes sure we've always got something there to call.
mtklein0abddf72016-07-13 08:22:20 -070046 SkRasterPipeline p;
Mike Klein9161ef02016-10-04 14:03:27 -040047 p.append(SkRasterPipeline::srcover);
Mike Kleinc789b612016-11-30 13:45:06 -050048 p.run(0,0, 20);
mtklein0abddf72016-07-13 08:22:20 -070049}