Flutter Engine
The Flutter Engine
PDFOpaqueSrcModeToSrcOverTest.cpp
Go to the documentation of this file.
1/*
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
13#include "include/core/SkRect.h"
19#include "tests/Test.h"
20
21static void run_test(SkWStream* out, SkBlendMode mode, U8CPU alpha) {
22 auto pdfDoc = SkPDF::MakeDocument(out);
23 SkCanvas* c = pdfDoc->beginPage(612.0f, 792.0f);
24 SkPaint black;
25 SkPaint background;
26 background.setColor(SK_ColorWHITE);
27 background.setAlpha(alpha);
28 background.setBlendMode(mode);
29 c->drawRect(SkRect::MakeWH(612.0f, 792.0f), background);
30 c->drawRect(SkRect::MakeXYWH(36.0f, 36.0f, 9.0f, 9.0f), black);
31 c->drawRect(SkRect::MakeXYWH(72.0f, 72.0f, 468.0f, 648.0f), background);
32 c->drawRect(SkRect::MakeXYWH(108.0f, 108.0f, 9.0f, 9.0f), black);
33 pdfDoc->close();
34}
35
36// http://crbug.com/473572
37DEF_TEST(SkPDF_OpaqueSrcModeToSrcOver, r) {
38 REQUIRE_PDF_DOCUMENT(SkPDF_OpaqueSrcModeToSrcOver, r);
40 SkDynamicMemoryWStream srcOverMode;
41
42 U8CPU alpha = SK_AlphaOPAQUE;
43 run_test(&srcMode, SkBlendMode::kSrc, alpha);
44 run_test(&srcOverMode, SkBlendMode::kSrcOver, alpha);
45 REPORTER_ASSERT(r, srcMode.bytesWritten() == srcOverMode.bytesWritten());
46 // The two PDFs should be equal because they have an opaque alpha.
47
48 srcMode.reset();
49 srcOverMode.reset();
50
51 alpha = 0x80;
52 run_test(&srcMode, SkBlendMode::kSrc, alpha);
53 run_test(&srcOverMode, SkBlendMode::kSrcOver, alpha);
54 REPORTER_ASSERT(r, srcMode.bytesWritten() > srcOverMode.bytesWritten());
55 // The two PDFs should not be equal because they have a non-opaque alpha.
56}
DEF_TEST(SkPDF_OpaqueSrcModeToSrcOver, r)
static void run_test(SkWStream *out, SkBlendMode mode, U8CPU alpha)
SkBlendMode
Definition: SkBlendMode.h:38
@ kSrcOver
r = s + (1-sa)*d
unsigned U8CPU
Definition: SkCPUTypes.h:18
constexpr SkAlpha SK_AlphaOPAQUE
Definition: SkColor.h:94
constexpr SkColor SK_ColorWHITE
Definition: SkColor.h:122
#define REPORTER_ASSERT(r, cond,...)
Definition: Test.h:286
#define REQUIRE_PDF_DOCUMENT(TEST_NAME, REPORTER)
Definition: Test.h:485
void drawRect(const SkRect &rect, const SkPaint &paint)
Definition: SkCanvas.cpp:1673
size_t bytesWritten() const override
Definition: SkStream.cpp:526
void setColor(SkColor color)
Definition: SkPaint.cpp:119
void setAlpha(U8CPU a)
Definition: SkPaint.h:279
void setBlendMode(SkBlendMode mode)
Definition: SkPaint.cpp:151
SK_API sk_sp< SkDocument > MakeDocument(SkWStream *stream, const Metadata &metadata)
it will be possible to load the file into Perfetto s trace viewer disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive mode
Definition: switches.h:228
static constexpr SkRect MakeXYWH(float x, float y, float w, float h)
Definition: SkRect.h:659
static constexpr SkRect MakeWH(float w, float h)
Definition: SkRect.h:609