skia2/tests/PDFOpaqueSrcModeToSrcOverTest.cpp
Mike Reed 2cbcd12281 Revert "Revert "Revert "replace SkXfermode obj with SkBlendMode enum in paints"""
This reverts commit I86875511a13497112827cbaed1dbd7639e9e3d10.

legacy (100K) skp failure

Original change's description:
> Revert "Revert "replace SkXfermode obj with SkBlendMode enum in paints""
> 
> This reverts commit ce02e71758.
> 
> BUG=skia:
> 
> GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=2878
> 
> Change-Id: I86875511a13497112827cbaed1dbd7639e9e3d10
> Reviewed-on: https://skia-review.googlesource.com/2878
> Reviewed-by: Matt Sarett <msarett@google.com>
> Commit-Queue: Mike Reed <reed@google.com>
> 

TBR=msarett@google.com,reed@google.com,reviews@skia.org
NOPRESUBMIT=true
NOTREECHECKS=true
NOTRY=true

Change-Id: Ife6f0cf3a22b3e8cf885a188f7f44e1ff62e06a5
Reviewed-on: https://skia-review.googlesource.com/2881
Reviewed-by: Mike Reed <reed@google.com>
Commit-Queue: Mike Reed <reed@google.com>
2016-10-03 21:34:36 +00:00

48 lines
1.7 KiB
C++

/*
* 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.
}