blob: 8b3cfe0e1d36019c50f4f6885b59bf1b03133d3e [file] [log] [blame]
halcanarya6814332015-05-27 08:53:36 -07001/*
2 * Copyright 2015 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#include "SkCanvas.h"
8#include "SkDocument.h"
9#include "SkStream.h"
10#include "Test.h"
11
reed374772b2016-10-05 17:33:02 -070012static void run_test(SkWStream* out, SkBlendMode mode, U8CPU alpha) {
halcanary4b656662016-04-27 07:45:18 -070013 sk_sp<SkDocument> pdfDoc(SkDocument::MakePDF(out));
halcanarya6814332015-05-27 08:53:36 -070014 SkCanvas* c = pdfDoc->beginPage(612.0f, 792.0f);
15 SkPaint black;
16 SkPaint background;
17 background.setColor(SK_ColorWHITE);
18 background.setAlpha(alpha);
reed374772b2016-10-05 17:33:02 -070019 background.setBlendMode(mode);
halcanarya6814332015-05-27 08:53:36 -070020 c->drawRect(SkRect::MakeWH(612.0f, 792.0f), background);
21 c->drawRect(SkRect::MakeXYWH(36.0f, 36.0f, 9.0f, 9.0f), black);
22 c->drawRect(SkRect::MakeXYWH(72.0f, 72.0f, 468.0f, 648.0f), background);
23 c->drawRect(SkRect::MakeXYWH(108.0f, 108.0f, 9.0f, 9.0f), black);
24 pdfDoc->close();
25}
26
27// http://crbug.com/473572
28DEF_TEST(SkPDF_OpaqueSrcModeToSrcOver, r) {
halcanary2ccdb632015-08-11 13:35:12 -070029 REQUIRE_PDF_DOCUMENT(SkPDF_OpaqueSrcModeToSrcOver, r);
halcanarya6814332015-05-27 08:53:36 -070030 SkDynamicMemoryWStream srcMode;
31 SkDynamicMemoryWStream srcOverMode;
32
33 U8CPU alpha = SK_AlphaOPAQUE;
reed374772b2016-10-05 17:33:02 -070034 run_test(&srcMode, SkBlendMode::kSrc, alpha);
35 run_test(&srcOverMode, SkBlendMode::kSrcOver, alpha);
Ben Wagner884300d2016-12-16 16:51:41 +000036 REPORTER_ASSERT(r, srcMode.bytesWritten() == srcOverMode.bytesWritten());
halcanarya6814332015-05-27 08:53:36 -070037 // The two PDFs should be equal because they have an opaque alpha.
38
39 srcMode.reset();
40 srcOverMode.reset();
41
42 alpha = 0x80;
reed374772b2016-10-05 17:33:02 -070043 run_test(&srcMode, SkBlendMode::kSrc, alpha);
44 run_test(&srcOverMode, SkBlendMode::kSrcOver, alpha);
Ben Wagner884300d2016-12-16 16:51:41 +000045 REPORTER_ASSERT(r, srcMode.bytesWritten() > srcOverMode.bytesWritten());
halcanarya6814332015-05-27 08:53:36 -070046 // The two PDFs should not be equal because they have a non-opaque alpha.
47}