aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/PDFOpaqueSrcModeToSrcOverTest.cpp
blob: 76796f5500bd84e38c6ca7679473a64871fb113a (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
/*
 * Copyright 2015 Google Inc.
 *
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 */
#include "SkCanvas.h"
#include "SkDocument.h"
#include "SkStream.h"
#include "Test.h"

static void run_test(SkWStream* out, SkXfermode::Mode mode, U8CPU alpha) {
    sk_sp<SkDocument> pdfDoc(SkDocument::MakePDF(out));
    SkCanvas* c = pdfDoc->beginPage(612.0f, 792.0f);
    SkPaint black;
    SkPaint background;
    background.setColor(SK_ColorWHITE);
    background.setAlpha(alpha);
    background.setXfermodeMode(mode);
    c->drawRect(SkRect::MakeWH(612.0f, 792.0f), background);
    c->drawRect(SkRect::MakeXYWH(36.0f, 36.0f, 9.0f, 9.0f), black);
    c->drawRect(SkRect::MakeXYWH(72.0f, 72.0f, 468.0f, 648.0f), background);
    c->drawRect(SkRect::MakeXYWH(108.0f, 108.0f, 9.0f, 9.0f), black);
    pdfDoc->close();
}

// http://crbug.com/473572
DEF_TEST(SkPDF_OpaqueSrcModeToSrcOver, r) {
    REQUIRE_PDF_DOCUMENT(SkPDF_OpaqueSrcModeToSrcOver, r);
    SkDynamicMemoryWStream srcMode;
    SkDynamicMemoryWStream srcOverMode;

    U8CPU alpha = SK_AlphaOPAQUE;
    run_test(&srcMode, SkXfermode::kSrc_Mode, alpha);
    run_test(&srcOverMode, SkXfermode::kSrcOver_Mode, alpha);
    REPORTER_ASSERT(r, srcMode.getOffset() == srcOverMode.getOffset());
    // The two PDFs should be equal because they have an opaque alpha.

    srcMode.reset();
    srcOverMode.reset();

    alpha = 0x80;
    run_test(&srcMode, SkXfermode::kSrc_Mode, alpha);
    run_test(&srcOverMode, SkXfermode::kSrcOver_Mode, alpha);
    REPORTER_ASSERT(r, srcMode.getOffset() > srcOverMode.getOffset());
    // The two PDFs should not be equal because they have a non-opaque alpha.
}