aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/SkRasterPipelineTest.cpp
blob: 76c68a316301ad935109aae3961399b40a27c8b8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
/*
 * Copyright 2016 Google Inc.
 *
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 */

#include "Test.h"
#include "SkHalf.h"
#include "SkRasterPipeline.h"

DEF_TEST(SkRasterPipeline, r) {
    // Build and run a simple pipeline to exercise SkRasterPipeline,
    // drawing 50% transparent blue over opaque red in half-floats.

    Sk4h red  = SkFloatToHalf_finite_ftz({ 1.0f, 0.0f, 0.0f, 1.0f }),
         blue = SkFloatToHalf_finite_ftz({ 0.0f, 0.0f, 0.5f, 0.5f }),
         result;

    SkRasterPipeline p;
    p.append(SkRasterPipeline::load_s_f16, &blue);
    p.append(SkRasterPipeline::load_d_f16, &red);
    p.append(SkRasterPipeline::srcover);
    p.append(SkRasterPipeline::store_f16, &result);
    p.run(1);

    Sk4f f = SkHalfToFloat_finite_ftz(result);

    uint64_t bits;
    memcpy(&bits, &result, 8);
    SkDebugf("SkRasterPipeline: 0x%016llx\n", bits);

    // We should see half-intensity magenta.
    REPORTER_ASSERT(r, f[0] == 0.5f);
    REPORTER_ASSERT(r, f[1] == 0.0f);
    REPORTER_ASSERT(r, f[2] == 0.5f);
    REPORTER_ASSERT(r, f[3] == 1.0f);
}

DEF_TEST(SkRasterPipeline_empty, r) {
    // No asserts... just a test that this is safe to run.
    SkRasterPipeline p;
    p.run(20);
}

DEF_TEST(SkRasterPipeline_nonsense, r) {
    // No asserts... just a test that this is safe to run and terminates.
    // srcover() calls st->next(); this makes sure we've always got something there to call.
    SkRasterPipeline p;
    p.append(SkRasterPipeline::srcover);
    p.run(20);
}