aboutsummaryrefslogtreecommitdiffhomepage
path: root/bench
diff options
context:
space:
mode:
authorGravatar halcanary <halcanary@google.com>2016-03-25 05:52:57 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2016-03-25 05:52:57 -0700
commitd11c7268a2a4303e842f4ba16da98fcd0a2b7555 (patch)
tree80a929bff0e3ded16db8625c6f62aa92160ab1f4 /bench
parent2e59f1f2fd497367585374eb20f5c04d92ae6d26 (diff)
SkPDF: speed up SkPDFShader generation.
Stop using SkString::append() when SkDynamicMemoryWStream works better. Also add a bench to prove that this speeds things up: before: micros bench 59.33 ? PDFShader nonrendering after: micros bench 34.55 ? PDFShader nonrendering GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1833793002 Review URL: https://codereview.chromium.org/1833793002
Diffstat (limited to 'bench')
-rw-r--r--bench/PDFBench.cpp31
1 files changed, 31 insertions, 0 deletions
diff --git a/bench/PDFBench.cpp b/bench/PDFBench.cpp
index 75b05de29d..289588a01b 100644
--- a/bench/PDFBench.cpp
+++ b/bench/PDFBench.cpp
@@ -9,8 +9,11 @@
#include "Resources.h"
#include "SkAutoPixmapStorage.h"
#include "SkData.h"
+#include "SkGradientShader.h"
#include "SkImage.h"
#include "SkPDFBitmap.h"
+#include "SkPDFDocument.h"
+#include "SkPDFShader.h"
#include "SkPDFUtils.h"
#include "SkPixmap.h"
#include "SkRandom.h"
@@ -162,8 +165,36 @@ struct PDFScalarBench : public Benchmark {
}
};
+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),
+ SkShader::kClamp_TileMode);
+ }
+ void onDraw(int loops, SkCanvas*) final {
+ SkASSERT(fShader);
+ while (loops-- > 0) {
+ NullWStream nullStream;
+ SkPDFDocument doc(&nullStream, nullptr, 72, nullptr);
+ sk_sp<SkPDFObject> shader(
+ SkPDFShader::GetPDFShader(
+ &doc, 72, *fShader, SkMatrix::I(),
+ SkIRect::MakeWH(400,400), 72));
+ }
+ }
+};
+
} // namespace
DEF_BENCH(return new PDFImageBench;)
DEF_BENCH(return new PDFJpegImageBench;)
DEF_BENCH(return new PDFCompressionBench;)
DEF_BENCH(return new PDFScalarBench;)
+DEF_BENCH(return new PDFShaderBench;)