28struct WStreamWriteTextBenchmark :
public Benchmark {
29 std::unique_ptr<SkWStream> fWStream;
31 const char*
onGetName()
override {
return "WStreamWriteText"; }
37 for (
int i = 1000;
i-- > 0;) {
38 fWStream->writeText(
"HELLO SKIA!\n");
45DEF_BENCH(
return new WStreamWriteTextBenchmark;)
54 return b == Backend::kNonRendering;
61 auto f = fNextFloat(&random);
71 union { uint32_t u;
float f; };
73 static_assert(
sizeof(
float) ==
sizeof(uint32_t),
"");
82#include
"src/pdf/SkPDFBitmap.h"
83#include
"src/pdf/SkPDFDocumentPriv.h"
84#include
"src/pdf/SkPDFShader.h"
85#include
"src/pdf/SkPDFUtils.h"
91 ~PDFImageBench()
override {}
94 const char*
onGetName()
override {
return "PDFImage"; }
104 if (img->readPixels(
nullptr, pixmap, 0, 0)) {
113 while (loops-- > 0) {
116 doc.beginPage(256, 256);
125class PDFJpegImageBench :
public Benchmark {
127 PDFJpegImageBench() {}
128 ~PDFJpegImageBench()
override {}
131 const char*
onGetName()
override {
return "PDFJpegImage"; }
137 if (!img) {
return; }
140 if (!encoded) {
return; }
148 while (loops-- > 0) {
151 doc.beginPage(256, 256);
162class PDFCompressionBench :
public Benchmark {
164 PDFCompressionBench() {}
165 ~PDFCompressionBench()
override {}
168 const char*
onGetName()
override {
return "PDFCompression"; }
177 if (!fAsset) {
return; }
178 while (loops-- > 0) {
181 doc.beginPage(256, 256);
188 std::unique_ptr<SkStreamAsset> fAsset;
191struct PDFColorComponentBench :
public Benchmark {
195 const char*
onGetName()
override {
return "PDFColorComponent"; }
198 while (loops-- > 0) {
199 for (
int i = 0;
i < 256; ++
i) {
206struct PDFShaderBench :
public Benchmark {
208 const char*
onGetName() final {
return "PDFShader"; }
211 const SkPoint pts[2] = {{0.0f, 0.0f}, {100.0f, 100.0f}};
222 while (loops-- > 0) {
225 doc.beginPage(256, 256);
232struct WritePDFTextBenchmark :
public Benchmark {
233 std::unique_ptr<SkWStream> fWStream;
235 const char*
onGetName()
override {
return "WritePDFText"; }
240 static const char kHello[] =
"HELLO SKIA!\n";
241 static const char kBinary[] =
"\001\002\003\004\005\006";
242 while (loops-- > 0) {
243 for (
int i = 1000;
i-- > 0;) {
254struct PDFClipPathBenchmark :
public Benchmark {
258 bitmap.allocN32Pixels(256, 256);
263 paint.setAntiAlias(
false);
265 paint.setStrokeWidth(10);
266 for (
int r : {20, 40, 60, 80, 100, 120}) {
267 tmp.drawCircle(128, 128, (
float)r,
paint);
271 for (
int y = 0;
y < 256; ++
y) {
274 for (
int x = 0;
x < 256; ++
x) {
276 if (
color == current) {
291 const char*
onGetName()
override {
return "PDFClipPath"; }
296 while (loops-- > 0) {
299 SkCanvas* canvas = doc.beginPage(256, 256);
312DEF_BENCH(
return new PDFCompressionBench;)
313DEF_BENCH(
return new PDFColorComponentBench;)
315DEF_BENCH(
return new WritePDFTextBenchmark;)
316DEF_BENCH(
return new PDFClipPathBenchmark;)
318#ifdef SK_PDF_ENABLE_SLOW_TESTS
319#include
"include/core/SkExecutor.h"
322 static const char*
kText[] = {
323 "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do",
324 "eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad",
325 "minim veniam, quis nostrud exercitation ullamco laboris nisi ut",
326 "aliquip ex ea commodo consequat. Duis aute irure dolor in",
327 "reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla",
328 "pariatur. Excepteur sint occaecat cupidatat non proident, sunt in",
329 "culpa qui officia deserunt mollit anim id est laborum.",
331 "Sed ut perspiciatis, unde omnis iste natus error sit voluptatem",
332 "accusantium doloremque laudantium, totam rem aperiam eaque ipsa, quae",
333 "ab illo inventore veritatis et quasi architecto beatae vitae dicta",
334 "sunt, explicabo. Nemo enim ipsam voluptatem, quia voluptas sit,",
335 "aspernatur aut odit aut fugit, sed quia consequuntur magni dolores",
336 "eos, qui ratione voluptatem sequi nesciunt, neque porro quisquam est,",
337 "qui dolorem ipsum, quia dolor sit amet consectetur adipiscing velit,",
338 "sed quia non numquam do eius modi tempora incididunt, ut labore et",
339 "dolore magnam aliquam quaerat voluptatem. Ut enim ad minima veniam,",
340 "quis nostrum exercitationem ullam corporis suscipit laboriosam, nisi",
341 "ut aliquid ex ea commodi consequatur? Quis autem vel eum iure",
342 "reprehenderit, qui in ea voluptate velit esse, quam nihil molestiae",
343 "consequatur, vel illum, qui dolorem eum fugiat, quo voluptas nulla",
346 "At vero eos et accusamus et iusto odio dignissimos ducimus, qui",
347 "blanditiis praesentium voluptatum deleniti atque corrupti, quos",
348 "dolores et quas molestias excepturi sint, obcaecati cupiditate non",
349 "provident, similique sunt in culpa, qui officia deserunt mollitia",
350 "animi, id est laborum et dolorum fuga. Et harum quidem rerum facilis",
351 "est et expedita distinctio. Nam libero tempore, cum soluta nobis est",
352 "eligendi optio, cumque nihil impedit, quo minus id, quod maxime",
353 "placeat, facere possimus, omnis voluptas assumenda est, omnis dolor",
354 "repellendus. Temporibus autem quibusdam et aut officiis debitis aut",
355 "rerum necessitatibus saepe eveniet, ut et voluptates repudiandae sint",
356 "et molestiae non recusandae. Itaque earum rerum hic tenetur a sapiente",
357 "delectus, ut aut reiciendis voluptatibus maiores alias consequatur aut",
358 "perferendis doloribus asperiores repellat",
360 "Sed ut perspiciatis, unde omnis iste natus error sit voluptatem",
361 "accusantium doloremque laudantium, totam rem aperiam eaque ipsa, quae",
362 "ab illo inventore veritatis et quasi architecto beatae vitae dicta",
363 "sunt, explicabo. Nemo enim ipsam voluptatem, quia voluptas sit,",
364 "aspernatur aut odit aut fugit, sed quia consequuntur magni dolores",
365 "eos, qui ratione voluptatem sequi nesciunt, neque porro quisquam est,",
366 "qui dolorem ipsum, quia dolor sit amet consectetur adipiscing velit,",
367 "sed quia non numquam do eius modi tempora incididunt, ut labore et",
368 "dolore magnam aliquam quaerat voluptatem. Ut enim ad minima veniam,",
369 "quis nostrum exercitationem ullam corporis suscipit laboriosam, nisi",
370 "ut aliquid ex ea commodi consequatur? Quis autem vel eum iure",
371 "reprehenderit, qui in ea voluptate velit esse, quam nihil molestiae",
372 "consequatur, vel illum, qui dolorem eum fugiat, quo voluptas nulla",
380 constexpr int kLoopCount = 200;
383 for (
int loop = 0; loop < kLoopCount; ++loop) {
385 y +=
font.getSpacing();
386 if (!canvas ||
y > 792 - 36) {
387 y = 36 +
font.getSpacing();
390 canvas->drawBitmap(background, 0, 0);
400 bitmap.allocN32Pixels(32, 32);
405 tmp.drawRect({0,0,16,16}, gray);
406 tmp.drawRect({16,16,32,32}, gray);
409 SkShader::MakeBitmapShader(
410 bitmap, SkShader::kRepeat_TileMode, SkShader::kRepeat_TileMode));
413 tmp2.drawPaint(shader);
417struct PDFBigDocBench :
public Benchmark {
420 std::unique_ptr<SkExecutor> fExecutor;
421 PDFBigDocBench(
bool fast) : fFast(fast) {}
423 fBackground = make_background();
427 static const char kNameFast[] =
"PDFBigDocBench_fast";
428 static const char kNameSlow[] =
"PDFBigDocBench_slow";
429 return fFast ? kNameFast : kNameSlow;
433 while (loops-- > 0) {
434 #ifdef SK_PDF_TEST_BIGDOCBENCH_OUTPUT
442 big_pdf_test(doc.get(), fBackground);
447DEF_BENCH(
return new PDFBigDocBench(
false);)
448DEF_BENCH(
return new PDFBigDocBench(
true);)
float next_any(SkRandom *random)
float next_common(SkRandom *random)
std::unique_ptr< SkStreamAsset > GetResourceAsStream(const char *resource, bool useFileStream)
#define SkDEBUGFAIL(message)
constexpr SkColor SK_ColorBLUE
constexpr SkColor SK_ColorRED
static constexpr SkColor SkColorSetARGB(U8CPU a, U8CPU r, U8CPU g, U8CPU b)
constexpr SkColor SK_ColorBLACK
constexpr SkColor SK_ColorGREEN
constexpr SkColor SK_ColorWHITE
unsigned SkFloatToDecimal(float value, char output[kMaximumSkFloatToDecimalLength])
constexpr unsigned kMaximumSkFloatToDecimalLength
SkPDFIndirectReference SkPDFSerializeImage(const SkImage *img, SkPDFDocument *doc, int encodingQuality)
SkPDFIndirectReference SkPDFMakeShader(SkPDFDocument *doc, SkShader *shader, const SkMatrix &canvasTransform, const SkIRect &surfaceBBox, SkColor4f paintColor)
void SkPDFWriteByteString(SkWStream *wStream, const char *cin, size_t len)
void SkPDFWriteTextString(SkWStream *wStream, const char *cin, size_t len)
SkPDFIndirectReference SkPDFStreamOut(std::unique_ptr< SkPDFDict > dict, std::unique_ptr< SkStreamAsset > content, SkPDFDocument *doc, SkPDFSteamCompressionEnabled compress)
constexpr uint8_t SkToU8(S x)
virtual void onDraw(int loops, SkCanvas *)=0
virtual bool isSuitableFor(Backend backend)
virtual void onDelayedSetup()
virtual const char * onGetName()=0
void alloc(const SkImageInfo &)
void notifyPixelsChanged() const
void allocN32Pixels(int width, int height, bool isOpaque=false)
void translate(SkScalar dx, SkScalar dy)
void clear(SkColor color)
void clipPath(const SkPath &path, SkClipOp op, bool doAntiAlias)
void drawString(const char str[], SkScalar x, SkScalar y, const SkFont &font, const SkPaint &paint)
SkCanvas * beginPage(SkScalar width, SkScalar height, const SkRect *content=nullptr)
static std::unique_ptr< SkExecutor > MakeFIFOThreadPool(int threads=0, bool allowBorrowing=true)
static sk_sp< SkShader > MakeLinear(const SkPoint pts[2], const SkColor colors[], const SkScalar pos[], int count, SkTileMode mode, uint32_t flags=0, const SkMatrix *localMatrix=nullptr)
static const SkMatrix & I()
void setColor(SkColor color)
@ kStroke_Style
set to stroke geometry
void setShader(sk_sp< SkShader > shader)
SkPath & addRect(const SkRect &rect, SkPathDirection dir, unsigned start)
float nextRangeF(float min, float max)
constexpr SkColor4f kBlack
SK_API sk_sp< SkImage > RasterFromPixmapCopy(const SkPixmap &pixmap)
size_t ColorToDecimal(uint8_t value, char result[5])
SK_API sk_sp< SkDocument > MakeDocument(SkWStream *stream, const Metadata &metadata)
PODArray< SkColor > colors
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 keep the shell running after the Dart script has completed enable serial On low power devices with low core running concurrent GC tasks on threads can cause them to contend with the UI thread which could potentially lead to jank This option turns off all concurrent GC activities domain network JSON encoded network policy per domain This overrides the DisallowInsecureConnections switch Embedder can specify whether to allow or disallow insecure connections at a domain level old gen heap size
font
Font Metadata and Metrics.
PDFScalarBench(const char *n, float(*f)(SkRandom *))
const char * onGetName() override
void onDraw(int loops, SkCanvas *) override
bool isSuitableFor(Backend b) override
static SkImageInfo MakeN32Premul(int width, int height)
static SkRect Make(const SkISize &size)