Flutter Engine
The Flutter Engine
Functions
PDFOpaqueSrcModeToSrcOverTest.cpp File Reference
#include "include/core/SkBlendMode.h"
#include "include/core/SkCanvas.h"
#include "include/core/SkColor.h"
#include "include/core/SkDocument.h"
#include "include/core/SkPaint.h"
#include "include/core/SkRect.h"
#include "include/core/SkRefCnt.h"
#include "include/core/SkStream.h"
#include "include/core/SkTypes.h"
#include "include/docs/SkPDFDocument.h"
#include "include/private/base/SkCPUTypes.h"
#include "tests/Test.h"

Go to the source code of this file.

Functions

static void run_test (SkWStream *out, SkBlendMode mode, U8CPU alpha)
 
 DEF_TEST (SkPDF_OpaqueSrcModeToSrcOver, r)
 

Function Documentation

◆ DEF_TEST()

DEF_TEST ( SkPDF_OpaqueSrcModeToSrcOver  ,
 
)

Definition at line 37 of file PDFOpaqueSrcModeToSrcOverTest.cpp.

37 {
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}
static void run_test(SkWStream *out, SkBlendMode mode, U8CPU alpha)
@ kSrcOver
r = s + (1-sa)*d
unsigned U8CPU
Definition: SkCPUTypes.h:18
constexpr SkAlpha SK_AlphaOPAQUE
Definition: SkColor.h:94
#define REPORTER_ASSERT(r, cond,...)
Definition: Test.h:286
#define REQUIRE_PDF_DOCUMENT(TEST_NAME, REPORTER)
Definition: Test.h:485
size_t bytesWritten() const override
Definition: SkStream.cpp:526

◆ run_test()

static void run_test ( SkWStream out,
SkBlendMode  mode,
U8CPU  alpha 
)
static

Definition at line 21 of file PDFOpaqueSrcModeToSrcOverTest.cpp.

21 {
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}
constexpr SkColor SK_ColorWHITE
Definition: SkColor.h:122
void drawRect(const SkRect &rect, const SkPaint &paint)
Definition: SkCanvas.cpp:1673
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