2015-05-27 15:53:36 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2015 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
2018-09-07 18:33:14 +00:00
|
|
|
|
2015-05-27 15:53:36 +00:00
|
|
|
#include "SkCanvas.h"
|
2018-09-07 18:33:14 +00:00
|
|
|
#include "SkPDFDocument.h"
|
2015-05-27 15:53:36 +00:00
|
|
|
#include "SkStream.h"
|
|
|
|
#include "Test.h"
|
|
|
|
|
2016-10-06 00:33:02 +00:00
|
|
|
static void run_test(SkWStream* out, SkBlendMode mode, U8CPU alpha) {
|
2019-01-07 15:00:48 +00:00
|
|
|
auto pdfDoc = SkPDF::MakeDocument(out);
|
2015-05-27 15:53:36 +00:00
|
|
|
SkCanvas* c = pdfDoc->beginPage(612.0f, 792.0f);
|
|
|
|
SkPaint black;
|
|
|
|
SkPaint background;
|
|
|
|
background.setColor(SK_ColorWHITE);
|
|
|
|
background.setAlpha(alpha);
|
2016-10-06 00:33:02 +00:00
|
|
|
background.setBlendMode(mode);
|
2015-05-27 15:53:36 +00:00
|
|
|
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) {
|
2015-08-11 20:35:12 +00:00
|
|
|
REQUIRE_PDF_DOCUMENT(SkPDF_OpaqueSrcModeToSrcOver, r);
|
2015-05-27 15:53:36 +00:00
|
|
|
SkDynamicMemoryWStream srcMode;
|
|
|
|
SkDynamicMemoryWStream srcOverMode;
|
|
|
|
|
|
|
|
U8CPU alpha = SK_AlphaOPAQUE;
|
2016-10-06 00:33:02 +00:00
|
|
|
run_test(&srcMode, SkBlendMode::kSrc, alpha);
|
|
|
|
run_test(&srcOverMode, SkBlendMode::kSrcOver, alpha);
|
2016-12-16 16:51:41 +00:00
|
|
|
REPORTER_ASSERT(r, srcMode.bytesWritten() == srcOverMode.bytesWritten());
|
2015-05-27 15:53:36 +00:00
|
|
|
// The two PDFs should be equal because they have an opaque alpha.
|
|
|
|
|
|
|
|
srcMode.reset();
|
|
|
|
srcOverMode.reset();
|
|
|
|
|
|
|
|
alpha = 0x80;
|
2016-10-06 00:33:02 +00:00
|
|
|
run_test(&srcMode, SkBlendMode::kSrc, alpha);
|
|
|
|
run_test(&srcOverMode, SkBlendMode::kSrcOver, alpha);
|
2016-12-16 16:51:41 +00:00
|
|
|
REPORTER_ASSERT(r, srcMode.bytesWritten() > srcOverMode.bytesWritten());
|
2015-05-27 15:53:36 +00:00
|
|
|
// The two PDFs should not be equal because they have a non-opaque alpha.
|
|
|
|
}
|