2016-02-24 17:25:58 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2016 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "bench/Benchmark.h"
|
2016-12-30 18:09:03 +00:00
|
|
|
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/core/SkData.h"
|
|
|
|
#include "include/core/SkExecutor.h"
|
|
|
|
#include "include/core/SkImage.h"
|
|
|
|
#include "include/core/SkPixmap.h"
|
|
|
|
#include "include/core/SkStream.h"
|
|
|
|
#include "include/effects/SkGradientShader.h"
|
|
|
|
#include "include/private/SkTo.h"
|
|
|
|
#include "include/utils/SkRandom.h"
|
|
|
|
#include "src/core/SkAutoPixmapStorage.h"
|
|
|
|
#include "src/pdf/SkPDFUnion.h"
|
|
|
|
#include "src/utils/SkFloatToDecimal.h"
|
|
|
|
#include "tools/Resources.h"
|
2016-02-24 17:25:58 +00:00
|
|
|
|
|
|
|
namespace {
|
2016-12-30 18:09:03 +00:00
|
|
|
struct WStreamWriteTextBenchmark : public Benchmark {
|
|
|
|
std::unique_ptr<SkWStream> fWStream;
|
2017-03-22 14:01:53 +00:00
|
|
|
WStreamWriteTextBenchmark() : fWStream(new SkNullWStream) {}
|
2016-12-30 18:09:03 +00:00
|
|
|
const char* onGetName() override { return "WStreamWriteText"; }
|
|
|
|
bool isSuitableFor(Backend backend) override {
|
|
|
|
return backend == kNonRendering_Backend;
|
|
|
|
}
|
|
|
|
void onDraw(int loops, SkCanvas*) override {
|
|
|
|
while (loops-- > 0) {
|
|
|
|
for (int i = 1000; i-- > 0;) {
|
|
|
|
fWStream->writeText("HELLO SKIA!\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
DEF_BENCH(return new WStreamWriteTextBenchmark;)
|
|
|
|
|
2018-01-02 21:25:53 +00:00
|
|
|
// Test speed of SkFloatToDecimal for typical floats that
|
|
|
|
// might be found in a PDF document.
|
|
|
|
struct PDFScalarBench : public Benchmark {
|
2018-02-21 20:49:41 +00:00
|
|
|
PDFScalarBench(const char* n, float (*f)(SkRandom*)) : fName(n), fNextFloat(f) {}
|
|
|
|
const char* fName;
|
|
|
|
float (*fNextFloat)(SkRandom*);
|
2018-01-02 21:25:53 +00:00
|
|
|
bool isSuitableFor(Backend b) override {
|
|
|
|
return b == kNonRendering_Backend;
|
|
|
|
}
|
2018-02-21 20:49:41 +00:00
|
|
|
const char* onGetName() override { return fName; }
|
2018-01-02 21:25:53 +00:00
|
|
|
void onDraw(int loops, SkCanvas*) override {
|
|
|
|
SkRandom random;
|
|
|
|
char dst[kMaximumSkFloatToDecimalLength];
|
|
|
|
while (loops-- > 0) {
|
2018-02-21 20:49:41 +00:00
|
|
|
auto f = fNextFloat(&random);
|
2018-01-02 21:25:53 +00:00
|
|
|
(void)SkFloatToDecimal(f, dst);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2018-02-21 20:49:41 +00:00
|
|
|
float next_common(SkRandom* random) {
|
|
|
|
return random->nextRangeF(-500.0f, 1500.0f);
|
|
|
|
}
|
|
|
|
float next_any(SkRandom* random) {
|
|
|
|
union { uint32_t u; float f; };
|
|
|
|
u = random->nextU();
|
|
|
|
static_assert(sizeof(float) == sizeof(uint32_t), "");
|
|
|
|
return f;
|
|
|
|
}
|
|
|
|
|
|
|
|
DEF_BENCH(return new PDFScalarBench("PDFScalar_common", next_common);)
|
|
|
|
DEF_BENCH(return new PDFScalarBench("PDFScalar_random", next_any);)
|
2018-01-02 21:25:53 +00:00
|
|
|
|
2016-12-30 18:09:03 +00:00
|
|
|
#ifdef SK_SUPPORT_PDF
|
|
|
|
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "src/pdf/SkPDFBitmap.h"
|
|
|
|
#include "src/pdf/SkPDFDocumentPriv.h"
|
|
|
|
#include "src/pdf/SkPDFShader.h"
|
|
|
|
#include "src/pdf/SkPDFUtils.h"
|
2016-12-30 18:09:03 +00:00
|
|
|
|
|
|
|
namespace {
|
2016-02-24 17:25:58 +00:00
|
|
|
class PDFImageBench : public Benchmark {
|
|
|
|
public:
|
|
|
|
PDFImageBench() {}
|
2017-03-22 16:05:03 +00:00
|
|
|
~PDFImageBench() override {}
|
2016-02-24 17:25:58 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
const char* onGetName() override { return "PDFImage"; }
|
|
|
|
bool isSuitableFor(Backend backend) override {
|
|
|
|
return backend == kNonRendering_Backend;
|
|
|
|
}
|
|
|
|
void onDelayedSetup() override {
|
2017-12-08 15:21:31 +00:00
|
|
|
sk_sp<SkImage> img(GetResourceAsImage("images/color_wheel.png"));
|
2016-02-24 17:25:58 +00:00
|
|
|
if (img) {
|
|
|
|
// force decoding, throw away reference to encoded data.
|
|
|
|
SkAutoPixmapStorage pixmap;
|
|
|
|
pixmap.alloc(SkImageInfo::MakeN32Premul(img->dimensions()));
|
2020-08-27 16:44:07 +00:00
|
|
|
if (img->readPixels(nullptr, pixmap, 0, 0)) {
|
2016-03-17 17:51:11 +00:00
|
|
|
fImage = SkImage::MakeRasterCopy(pixmap);
|
2016-02-24 17:25:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
void onDraw(int loops, SkCanvas*) override {
|
|
|
|
if (!fImage) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
while (loops-- > 0) {
|
2018-11-13 21:45:14 +00:00
|
|
|
SkNullWStream nullStream;
|
|
|
|
SkPDFDocument doc(&nullStream, SkPDF::Metadata());
|
|
|
|
doc.beginPage(256, 256);
|
|
|
|
(void)SkPDFSerializeImage(fImage.get(), &doc);
|
2016-02-24 17:25:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2016-03-17 17:51:11 +00:00
|
|
|
sk_sp<SkImage> fImage;
|
2016-02-24 17:25:58 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class PDFJpegImageBench : public Benchmark {
|
|
|
|
public:
|
|
|
|
PDFJpegImageBench() {}
|
2017-03-22 16:05:03 +00:00
|
|
|
~PDFJpegImageBench() override {}
|
2016-02-24 17:25:58 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
const char* onGetName() override { return "PDFJpegImage"; }
|
|
|
|
bool isSuitableFor(Backend backend) override {
|
|
|
|
return backend == kNonRendering_Backend;
|
|
|
|
}
|
|
|
|
void onDelayedSetup() override {
|
2017-12-08 15:21:31 +00:00
|
|
|
sk_sp<SkImage> img(GetResourceAsImage("images/mandrill_512_q075.jpg"));
|
2016-02-24 17:25:58 +00:00
|
|
|
if (!img) { return; }
|
2017-07-11 20:03:13 +00:00
|
|
|
sk_sp<SkData> encoded = img->refEncodedData();
|
2016-02-24 17:25:58 +00:00
|
|
|
SkASSERT(encoded);
|
|
|
|
if (!encoded) { return; }
|
2016-03-17 17:51:11 +00:00
|
|
|
fImage = img;
|
2016-02-24 17:25:58 +00:00
|
|
|
}
|
|
|
|
void onDraw(int loops, SkCanvas*) override {
|
|
|
|
if (!fImage) {
|
|
|
|
SkDEBUGFAIL("");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
while (loops-- > 0) {
|
2018-11-13 21:45:14 +00:00
|
|
|
SkNullWStream nullStream;
|
|
|
|
SkPDFDocument doc(&nullStream, SkPDF::Metadata());
|
|
|
|
doc.beginPage(256, 256);
|
|
|
|
(void)SkPDFSerializeImage(fImage.get(), &doc);
|
2016-02-24 17:25:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2016-03-17 17:51:11 +00:00
|
|
|
sk_sp<SkImage> fImage;
|
2016-02-24 17:25:58 +00:00
|
|
|
};
|
|
|
|
|
2016-02-24 23:17:19 +00:00
|
|
|
/** Test calling DEFLATE on a 78k PDF command stream. Used for measuring
|
|
|
|
alternate zlib settings, usage, and library versions. */
|
|
|
|
class PDFCompressionBench : public Benchmark {
|
|
|
|
public:
|
|
|
|
PDFCompressionBench() {}
|
2017-03-22 16:05:03 +00:00
|
|
|
~PDFCompressionBench() override {}
|
2016-02-24 23:17:19 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
const char* onGetName() override { return "PDFCompression"; }
|
|
|
|
bool isSuitableFor(Backend backend) override {
|
|
|
|
return backend == kNonRendering_Backend;
|
|
|
|
}
|
|
|
|
void onDelayedSetup() override {
|
2017-07-23 17:14:10 +00:00
|
|
|
fAsset = GetResourceAsStream("pdf_command_stream.txt");
|
2016-02-24 23:17:19 +00:00
|
|
|
}
|
|
|
|
void onDraw(int loops, SkCanvas*) override {
|
|
|
|
SkASSERT(fAsset);
|
|
|
|
if (!fAsset) { return; }
|
|
|
|
while (loops-- > 0) {
|
2018-12-11 00:59:07 +00:00
|
|
|
SkNullWStream wStream;
|
|
|
|
SkPDFDocument doc(&wStream, SkPDF::Metadata());
|
|
|
|
doc.beginPage(256, 256);
|
|
|
|
(void)SkPDFStreamOut(nullptr, fAsset->duplicate(), &doc, true);
|
|
|
|
}
|
2016-02-24 23:17:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2016-11-03 18:40:50 +00:00
|
|
|
std::unique_ptr<SkStreamAsset> fAsset;
|
2016-02-24 23:17:19 +00:00
|
|
|
};
|
|
|
|
|
2016-07-15 20:41:27 +00:00
|
|
|
struct PDFColorComponentBench : public Benchmark {
|
|
|
|
bool isSuitableFor(Backend b) override {
|
|
|
|
return b == kNonRendering_Backend;
|
|
|
|
}
|
|
|
|
const char* onGetName() override { return "PDFColorComponent"; }
|
|
|
|
void onDraw(int loops, SkCanvas*) override {
|
|
|
|
char dst[5];
|
|
|
|
while (loops-- > 0) {
|
|
|
|
for (int i = 0; i < 256; ++i) {
|
|
|
|
(void)SkPDFUtils::ColorToDecimal(SkToU8(i), dst);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2016-03-25 12:52:57 +00:00
|
|
|
struct PDFShaderBench : public Benchmark {
|
|
|
|
sk_sp<SkShader> fShader;
|
|
|
|
const char* onGetName() final { return "PDFShader"; }
|
|
|
|
bool isSuitableFor(Backend b) final { return b == kNonRendering_Backend; }
|
|
|
|
void onDelayedSetup() final {
|
|
|
|
const SkPoint pts[2] = {{0.0f, 0.0f}, {100.0f, 100.0f}};
|
|
|
|
const SkColor colors[] = {
|
|
|
|
SK_ColorRED, SK_ColorGREEN, SK_ColorBLUE,
|
|
|
|
SK_ColorWHITE, SK_ColorBLACK,
|
|
|
|
};
|
|
|
|
fShader = SkGradientShader::MakeLinear(
|
|
|
|
pts, colors, nullptr, SK_ARRAY_COUNT(colors),
|
2019-04-03 14:27:45 +00:00
|
|
|
SkTileMode::kClamp);
|
2016-03-25 12:52:57 +00:00
|
|
|
}
|
|
|
|
void onDraw(int loops, SkCanvas*) final {
|
|
|
|
SkASSERT(fShader);
|
|
|
|
while (loops-- > 0) {
|
2017-03-22 14:01:53 +00:00
|
|
|
SkNullWStream nullStream;
|
2018-09-07 18:33:14 +00:00
|
|
|
SkPDFDocument doc(&nullStream, SkPDF::Metadata());
|
2018-12-11 00:59:07 +00:00
|
|
|
doc.beginPage(256, 256);
|
|
|
|
(void) SkPDFMakeShader(&doc, fShader.get(), SkMatrix::I(),
|
2019-05-30 13:19:53 +00:00
|
|
|
{0, 0, 400, 400}, SkColors::kBlack);
|
2016-03-25 12:52:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2016-06-23 21:08:11 +00:00
|
|
|
struct WritePDFTextBenchmark : public Benchmark {
|
|
|
|
std::unique_ptr<SkWStream> fWStream;
|
2017-03-22 14:01:53 +00:00
|
|
|
WritePDFTextBenchmark() : fWStream(new SkNullWStream) {}
|
2016-06-23 21:08:11 +00:00
|
|
|
const char* onGetName() override { return "WritePDFText"; }
|
|
|
|
bool isSuitableFor(Backend backend) override {
|
|
|
|
return backend == kNonRendering_Backend;
|
|
|
|
}
|
|
|
|
void onDraw(int loops, SkCanvas*) override {
|
|
|
|
static const char kHello[] = "HELLO SKIA!\n";
|
|
|
|
static const char kBinary[] = "\001\002\003\004\005\006";
|
|
|
|
while (loops-- > 0) {
|
|
|
|
for (int i = 1000; i-- > 0;) {
|
2018-09-12 13:12:36 +00:00
|
|
|
SkPDFWriteString(fWStream.get(), kHello, strlen(kHello));
|
|
|
|
SkPDFWriteString(fWStream.get(), kBinary, strlen(kBinary));
|
2016-06-23 21:08:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2019-04-05 15:51:03 +00:00
|
|
|
// Test for regression chromium:947381
|
|
|
|
// with 5c83ae81aa : 2364.99 microsec
|
|
|
|
// without 5c83ae81aa : 302821.78 microsec
|
|
|
|
struct PDFClipPathBenchmark : public Benchmark {
|
|
|
|
SkPath fPath;
|
|
|
|
void onDelayedSetup() override {
|
|
|
|
SkBitmap bitmap;
|
|
|
|
bitmap.allocN32Pixels(256, 256);
|
|
|
|
bitmap.eraseColor(SK_ColorWHITE);
|
|
|
|
{
|
|
|
|
SkCanvas tmp(bitmap);
|
|
|
|
SkPaint paint;
|
|
|
|
paint.setAntiAlias(false);
|
|
|
|
paint.setStyle(SkPaint::kStroke_Style);
|
|
|
|
paint.setStrokeWidth(10);
|
|
|
|
for (int r : {20, 40, 60, 80, 100, 120}) {
|
|
|
|
tmp.drawCircle(128, 128, (float)r, paint);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fPath.reset();
|
|
|
|
for (int y = 0; y < 256; ++y) {
|
|
|
|
SkColor current = bitmap.getColor(0, y);
|
|
|
|
int start = 0;
|
|
|
|
for (int x = 0; x < 256; ++x) {
|
|
|
|
SkColor color = bitmap.getColor(x, y);
|
|
|
|
if (color == current) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (color == SK_ColorBLACK) {
|
|
|
|
start = x;
|
|
|
|
} else {
|
|
|
|
fPath.addRect(SkRect::Make(SkIRect{start, y, x, y + 1}));
|
|
|
|
}
|
|
|
|
current = color;
|
|
|
|
}
|
|
|
|
if (current == SK_ColorBLACK) {
|
|
|
|
fPath.addRect(SkRect::Make(SkIRect{start, y, 256, y + 1}));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
const char* onGetName() override { return "PDFClipPath"; }
|
|
|
|
bool isSuitableFor(Backend backend) override {
|
|
|
|
return backend == kNonRendering_Backend;
|
|
|
|
}
|
|
|
|
void onDraw(int loops, SkCanvas*) override {
|
|
|
|
while (loops-- > 0) {
|
|
|
|
SkNullWStream wStream;
|
|
|
|
SkPDFDocument doc(&wStream, SkPDF::Metadata());
|
|
|
|
SkCanvas* canvas = doc.beginPage(256, 256);
|
|
|
|
canvas->clipPath(fPath);
|
|
|
|
canvas->translate(4.0f/3, 4.0f/3);
|
|
|
|
canvas->clipPath(fPath);
|
|
|
|
canvas->clear(SK_ColorRED);
|
|
|
|
doc.endPage();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2016-02-24 17:25:58 +00:00
|
|
|
} // namespace
|
|
|
|
DEF_BENCH(return new PDFImageBench;)
|
|
|
|
DEF_BENCH(return new PDFJpegImageBench;)
|
2016-02-24 23:17:19 +00:00
|
|
|
DEF_BENCH(return new PDFCompressionBench;)
|
2016-07-15 20:41:27 +00:00
|
|
|
DEF_BENCH(return new PDFColorComponentBench;)
|
2016-03-25 12:52:57 +00:00
|
|
|
DEF_BENCH(return new PDFShaderBench;)
|
2016-06-23 21:08:11 +00:00
|
|
|
DEF_BENCH(return new WritePDFTextBenchmark;)
|
2019-04-05 15:51:03 +00:00
|
|
|
DEF_BENCH(return new PDFClipPathBenchmark;)
|
2016-12-30 18:09:03 +00:00
|
|
|
|
2019-01-09 20:32:35 +00:00
|
|
|
#ifdef SK_PDF_ENABLE_SLOW_TESTS
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/core/SkExecutor.h"
|
2018-12-11 00:59:07 +00:00
|
|
|
namespace {
|
2019-01-09 20:32:35 +00:00
|
|
|
void big_pdf_test(SkDocument* doc, const SkBitmap& background) {
|
2018-12-11 00:59:07 +00:00
|
|
|
static const char* kText[] = {
|
|
|
|
"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do",
|
|
|
|
"eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad",
|
|
|
|
"minim veniam, quis nostrud exercitation ullamco laboris nisi ut",
|
|
|
|
"aliquip ex ea commodo consequat. Duis aute irure dolor in",
|
|
|
|
"reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla",
|
|
|
|
"pariatur. Excepteur sint occaecat cupidatat non proident, sunt in",
|
|
|
|
"culpa qui officia deserunt mollit anim id est laborum.",
|
|
|
|
"",
|
|
|
|
"Sed ut perspiciatis, unde omnis iste natus error sit voluptatem",
|
|
|
|
"accusantium doloremque laudantium, totam rem aperiam eaque ipsa, quae",
|
|
|
|
"ab illo inventore veritatis et quasi architecto beatae vitae dicta",
|
|
|
|
"sunt, explicabo. Nemo enim ipsam voluptatem, quia voluptas sit,",
|
|
|
|
"aspernatur aut odit aut fugit, sed quia consequuntur magni dolores",
|
|
|
|
"eos, qui ratione voluptatem sequi nesciunt, neque porro quisquam est,",
|
|
|
|
"qui dolorem ipsum, quia dolor sit amet consectetur adipiscing velit,",
|
|
|
|
"sed quia non numquam do eius modi tempora incididunt, ut labore et",
|
|
|
|
"dolore magnam aliquam quaerat voluptatem. Ut enim ad minima veniam,",
|
|
|
|
"quis nostrum exercitationem ullam corporis suscipit laboriosam, nisi",
|
|
|
|
"ut aliquid ex ea commodi consequatur? Quis autem vel eum iure",
|
|
|
|
"reprehenderit, qui in ea voluptate velit esse, quam nihil molestiae",
|
|
|
|
"consequatur, vel illum, qui dolorem eum fugiat, quo voluptas nulla",
|
|
|
|
"pariatur?",
|
|
|
|
"",
|
|
|
|
"At vero eos et accusamus et iusto odio dignissimos ducimus, qui",
|
|
|
|
"blanditiis praesentium voluptatum deleniti atque corrupti, quos",
|
|
|
|
"dolores et quas molestias excepturi sint, obcaecati cupiditate non",
|
|
|
|
"provident, similique sunt in culpa, qui officia deserunt mollitia",
|
|
|
|
"animi, id est laborum et dolorum fuga. Et harum quidem rerum facilis",
|
|
|
|
"est et expedita distinctio. Nam libero tempore, cum soluta nobis est",
|
|
|
|
"eligendi optio, cumque nihil impedit, quo minus id, quod maxime",
|
|
|
|
"placeat, facere possimus, omnis voluptas assumenda est, omnis dolor",
|
|
|
|
"repellendus. Temporibus autem quibusdam et aut officiis debitis aut",
|
|
|
|
"rerum necessitatibus saepe eveniet, ut et voluptates repudiandae sint",
|
|
|
|
"et molestiae non recusandae. Itaque earum rerum hic tenetur a sapiente",
|
|
|
|
"delectus, ut aut reiciendis voluptatibus maiores alias consequatur aut",
|
|
|
|
"perferendis doloribus asperiores repellat",
|
|
|
|
"",
|
|
|
|
"Sed ut perspiciatis, unde omnis iste natus error sit voluptatem",
|
|
|
|
"accusantium doloremque laudantium, totam rem aperiam eaque ipsa, quae",
|
|
|
|
"ab illo inventore veritatis et quasi architecto beatae vitae dicta",
|
|
|
|
"sunt, explicabo. Nemo enim ipsam voluptatem, quia voluptas sit,",
|
|
|
|
"aspernatur aut odit aut fugit, sed quia consequuntur magni dolores",
|
|
|
|
"eos, qui ratione voluptatem sequi nesciunt, neque porro quisquam est,",
|
|
|
|
"qui dolorem ipsum, quia dolor sit amet consectetur adipiscing velit,",
|
|
|
|
"sed quia non numquam do eius modi tempora incididunt, ut labore et",
|
|
|
|
"dolore magnam aliquam quaerat voluptatem. Ut enim ad minima veniam,",
|
|
|
|
"quis nostrum exercitationem ullam corporis suscipit laboriosam, nisi",
|
|
|
|
"ut aliquid ex ea commodi consequatur? Quis autem vel eum iure",
|
|
|
|
"reprehenderit, qui in ea voluptate velit esse, quam nihil molestiae",
|
|
|
|
"consequatur, vel illum, qui dolorem eum fugiat, quo voluptas nulla",
|
|
|
|
"pariatur?",
|
|
|
|
"",
|
|
|
|
};
|
|
|
|
SkCanvas* canvas = nullptr;
|
|
|
|
float x = 36;
|
|
|
|
float y = 36;
|
|
|
|
constexpr size_t kLineCount = SK_ARRAY_COUNT(kText);
|
|
|
|
constexpr int kLoopCount = 200;
|
2019-01-09 20:32:35 +00:00
|
|
|
SkFont font;
|
2018-12-11 00:59:07 +00:00
|
|
|
SkPaint paint;
|
|
|
|
for (int loop = 0; loop < kLoopCount; ++loop) {
|
|
|
|
for (size_t line = 0; line < kLineCount; ++line) {
|
2019-01-09 20:32:35 +00:00
|
|
|
y += font.getSpacing();
|
2018-12-11 00:59:07 +00:00
|
|
|
if (!canvas || y > 792 - 36) {
|
2019-01-09 20:32:35 +00:00
|
|
|
y = 36 + font.getSpacing();
|
2018-12-11 00:59:07 +00:00
|
|
|
canvas = doc->beginPage(612, 792);
|
|
|
|
background.notifyPixelsChanged();
|
|
|
|
canvas->drawBitmap(background, 0, 0);
|
|
|
|
}
|
2019-01-09 20:32:35 +00:00
|
|
|
canvas->drawString(kText[line], x, y, font, paint);
|
2018-12-11 00:59:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
SkBitmap make_background() {
|
|
|
|
SkBitmap background;
|
|
|
|
SkBitmap bitmap;
|
|
|
|
bitmap.allocN32Pixels(32, 32);
|
|
|
|
bitmap.eraseColor(SK_ColorWHITE);
|
|
|
|
SkCanvas tmp(bitmap);
|
|
|
|
SkPaint gray;
|
|
|
|
gray.setColor(SkColorSetARGB(0xFF, 0xEE, 0xEE, 0xEE));
|
|
|
|
tmp.drawRect({0,0,16,16}, gray);
|
|
|
|
tmp.drawRect({16,16,32,32}, gray);
|
|
|
|
SkPaint shader;
|
|
|
|
shader.setShader(
|
|
|
|
SkShader::MakeBitmapShader(
|
|
|
|
bitmap, SkShader::kRepeat_TileMode, SkShader::kRepeat_TileMode));
|
|
|
|
background.allocN32Pixels(612, 792);
|
|
|
|
SkCanvas tmp2(background);
|
|
|
|
tmp2.drawPaint(shader);
|
|
|
|
return background;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct PDFBigDocBench : public Benchmark {
|
2019-01-09 20:32:35 +00:00
|
|
|
bool fFast;
|
2018-12-11 00:59:07 +00:00
|
|
|
SkBitmap fBackground;
|
2019-01-09 20:32:35 +00:00
|
|
|
std::unique_ptr<SkExecutor> fExecutor;
|
|
|
|
PDFBigDocBench(bool fast) : fFast(fast) {}
|
|
|
|
void onDelayedSetup() override {
|
|
|
|
fBackground = make_background();
|
|
|
|
fExecutor = fFast ? SkExecutor::MakeFIFOThreadPool() : nullptr;
|
2018-12-11 00:59:07 +00:00
|
|
|
}
|
2019-01-09 20:32:35 +00:00
|
|
|
const char* onGetName() override {
|
|
|
|
static const char kNameFast[] = "PDFBigDocBench_fast";
|
|
|
|
static const char kNameSlow[] = "PDFBigDocBench_slow";
|
|
|
|
return fFast ? kNameFast : kNameSlow;
|
|
|
|
}
|
|
|
|
bool isSuitableFor(Backend backend) override { return backend == kNonRendering_Backend; }
|
2018-12-11 00:59:07 +00:00
|
|
|
void onDraw(int loops, SkCanvas*) override {
|
2019-01-09 20:32:35 +00:00
|
|
|
while (loops-- > 0) {
|
|
|
|
#ifdef SK_PDF_TEST_BIGDOCBENCH_OUTPUT
|
|
|
|
SkFILEWStream wStream("/tmp/big_pdf.pdf");
|
|
|
|
#else
|
|
|
|
SkNullWStream wStream;
|
|
|
|
#endif
|
|
|
|
SkPDF::Metadata metadata;
|
|
|
|
metadata.fExecutor = fExecutor.get();
|
2019-01-07 15:00:48 +00:00
|
|
|
auto doc = SkPDF::MakeDocument(&wStream, metadata);
|
2019-01-09 20:32:35 +00:00
|
|
|
big_pdf_test(doc.get(), fBackground);
|
|
|
|
}
|
2018-12-11 00:59:07 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
} // namespace
|
2019-01-09 20:32:35 +00:00
|
|
|
DEF_BENCH(return new PDFBigDocBench(false);)
|
|
|
|
DEF_BENCH(return new PDFBigDocBench(true);)
|
2016-12-30 18:09:03 +00:00
|
|
|
#endif
|
|
|
|
|
2018-12-11 00:59:07 +00:00
|
|
|
#endif // SK_SUPPORT_PDF
|