Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(466)

Side by Side Diff: tests/PDFOpaqueSrcModeToSrcOverTest.cpp

Issue 1278403006: SkPDF: clean up overuse of SK_SUPPORT_PDF (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: 2015-08-11 (Tuesday) 16:25:36 EDT Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « tests/PDFJpegEmbedTest.cpp ('k') | tests/PDFPrimitivesTest.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2015 Google Inc. 2 * Copyright 2015 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 #include "SkCanvas.h" 7 #include "SkCanvas.h"
8 #include "SkDocument.h" 8 #include "SkDocument.h"
9 #include "SkStream.h" 9 #include "SkStream.h"
10 #include "Test.h" 10 #include "Test.h"
11 11
12 #if SK_SUPPORT_PDF
13
14 static void run_test(SkWStream* out, SkXfermode::Mode mode, U8CPU alpha) { 12 static void run_test(SkWStream* out, SkXfermode::Mode mode, U8CPU alpha) {
15 SkAutoTUnref<SkDocument> pdfDoc(SkDocument::CreatePDF(out)); 13 SkAutoTUnref<SkDocument> pdfDoc(SkDocument::CreatePDF(out));
16 SkCanvas* c = pdfDoc->beginPage(612.0f, 792.0f); 14 SkCanvas* c = pdfDoc->beginPage(612.0f, 792.0f);
17 SkPaint black; 15 SkPaint black;
18 SkPaint background; 16 SkPaint background;
19 background.setColor(SK_ColorWHITE); 17 background.setColor(SK_ColorWHITE);
20 background.setAlpha(alpha); 18 background.setAlpha(alpha);
21 background.setXfermodeMode(mode); 19 background.setXfermodeMode(mode);
22 c->drawRect(SkRect::MakeWH(612.0f, 792.0f), background); 20 c->drawRect(SkRect::MakeWH(612.0f, 792.0f), background);
23 c->drawRect(SkRect::MakeXYWH(36.0f, 36.0f, 9.0f, 9.0f), black); 21 c->drawRect(SkRect::MakeXYWH(36.0f, 36.0f, 9.0f, 9.0f), black);
24 c->drawRect(SkRect::MakeXYWH(72.0f, 72.0f, 468.0f, 648.0f), background); 22 c->drawRect(SkRect::MakeXYWH(72.0f, 72.0f, 468.0f, 648.0f), background);
25 c->drawRect(SkRect::MakeXYWH(108.0f, 108.0f, 9.0f, 9.0f), black); 23 c->drawRect(SkRect::MakeXYWH(108.0f, 108.0f, 9.0f, 9.0f), black);
26 pdfDoc->close(); 24 pdfDoc->close();
27 } 25 }
28 26
29 // http://crbug.com/473572 27 // http://crbug.com/473572
30 DEF_TEST(SkPDF_OpaqueSrcModeToSrcOver, r) { 28 DEF_TEST(SkPDF_OpaqueSrcModeToSrcOver, r) {
29 REQUIRE_PDF_DOCUMENT(SkPDF_OpaqueSrcModeToSrcOver, r);
31 SkDynamicMemoryWStream srcMode; 30 SkDynamicMemoryWStream srcMode;
32 SkDynamicMemoryWStream srcOverMode; 31 SkDynamicMemoryWStream srcOverMode;
33 32
34 U8CPU alpha = SK_AlphaOPAQUE; 33 U8CPU alpha = SK_AlphaOPAQUE;
35 run_test(&srcMode, SkXfermode::kSrc_Mode, alpha); 34 run_test(&srcMode, SkXfermode::kSrc_Mode, alpha);
36 run_test(&srcOverMode, SkXfermode::kSrcOver_Mode, alpha); 35 run_test(&srcOverMode, SkXfermode::kSrcOver_Mode, alpha);
37 REPORTER_ASSERT(r, srcMode.getOffset() == srcOverMode.getOffset()); 36 REPORTER_ASSERT(r, srcMode.getOffset() == srcOverMode.getOffset());
38 // The two PDFs should be equal because they have an opaque alpha. 37 // The two PDFs should be equal because they have an opaque alpha.
39 38
40 srcMode.reset(); 39 srcMode.reset();
41 srcOverMode.reset(); 40 srcOverMode.reset();
42 41
43 alpha = 0x80; 42 alpha = 0x80;
44 run_test(&srcMode, SkXfermode::kSrc_Mode, alpha); 43 run_test(&srcMode, SkXfermode::kSrc_Mode, alpha);
45 run_test(&srcOverMode, SkXfermode::kSrcOver_Mode, alpha); 44 run_test(&srcOverMode, SkXfermode::kSrcOver_Mode, alpha);
46 REPORTER_ASSERT(r, srcMode.getOffset() > srcOverMode.getOffset()); 45 REPORTER_ASSERT(r, srcMode.getOffset() > srcOverMode.getOffset());
47 // The two PDFs should not be equal because they have a non-opaque alpha. 46 // The two PDFs should not be equal because they have a non-opaque alpha.
48 } 47 }
49 #endif // SK_SUPPORT_PDF
OLDNEW
« no previous file with comments | « tests/PDFJpegEmbedTest.cpp ('k') | tests/PDFPrimitivesTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698