Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(201)

Unified Diff: bench/PDFBench.cpp

Issue 1730833003: SkPDF/Bench: add bench for SkPDFSharedStream (deflate) (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | gyp/bench.gyp » ('j') | gyp/bench.gyp » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: bench/PDFBench.cpp
diff --git a/bench/PDFBench.cpp b/bench/PDFBench.cpp
index 8b9eb520dcb0bbb84e6711fce11a22ff2b914e7a..4b7ae75112a11dc6aa922ff76e69ae40f32a584b 100644
--- a/bench/PDFBench.cpp
+++ b/bench/PDFBench.cpp
@@ -7,13 +7,11 @@
#include "Benchmark.h"
#include "Resources.h"
-#include "SkImage.h"
-#include "SkPixmap.h"
#include "SkData.h"
-
-#if SK_SUPPORT_PDF
-
+#include "SkImage.h"
#include "SkPDFBitmap.h"
+#include "SkPixmap.h"
+#include "SkRandom.h"
namespace {
struct NullWStream : public SkWStream {
@@ -23,13 +21,7 @@ struct NullWStream : public SkWStream {
size_t fN;
};
-static void test_pdf_image_serialization(SkImage* img) {
- SkAutoTUnref<SkPDFObject> object(
- SkPDFCreateBitmapObject(img, nullptr));
- if (!object) {
- SkDEBUGFAIL("");
- return;
- }
+static void test_pdf_object_serialization(SkPDFObject* object) {
// SkDebugWStream wStream;
NullWStream wStream;
SkPDFSubstituteMap substitutes;
@@ -44,6 +36,16 @@ static void test_pdf_image_serialization(SkImage* img) {
}
}
+static void test_pdf_image_serialization(SkImage* img) {
+ SkAutoTUnref<SkPDFObject> object(
+ SkPDFCreateBitmapObject(img, nullptr));
+ if (!object) {
+ SkDEBUGFAIL("");
+ return;
+ }
+ test_pdf_object_serialization(object);
+}
+
class PDFImageBench : public Benchmark {
public:
PDFImageBench() {}
@@ -113,8 +115,47 @@ private:
SkAutoTUnref<SkImage> fImage;
};
+static SkAutoTDelete<SkStreamAsset> generate_random_text() {
+ SkRandom random(0x5EED);
+ size_t N = 1 << 16;
+ SkAutoTDelete<SkStreamAsset> buffer(new SkMemoryStream(N));
+ uint8_t* ptr = (uint8_t*)(buffer->getMemoryBase());
+ const uint8_t* const end = &ptr[N];
+ while (ptr != end) {
+ *ptr++ = SkToU8(random.nextRangeU(' ', '~'));
+ }
+ return buffer;
+}
+
+/** Test calling DEFLATE on 64k of random text. Used for measuring
+ alternate zlib settings, usage, and library versions. */
+class PDFCompressionBench : public Benchmark {
+public:
+ PDFCompressionBench() {}
+ virtual ~PDFCompressionBench() {}
+
+protected:
+ const char* onGetName() override { return "PDFCompression"; }
+ bool isSuitableFor(Backend backend) override {
+ return backend == kNonRendering_Backend;
+ }
+ void onDelayedSetup() override {
+ fRandomText = generate_random_text();
+ }
+ void onDraw(int loops, SkCanvas*) override {
+ SkASSERT(fRandomText);
+ while (loops-- > 0) {
+ SkAutoTUnref<SkPDFObject> object(
+ new SkPDFSharedStream(fRandomText->duplicate()));
+ test_pdf_object_serialization(object);
+ }
+ }
+
+private:
+ SkAutoTDelete<SkStreamAsset> fRandomText;
+};
+
} // namespace
DEF_BENCH(return new PDFImageBench;)
DEF_BENCH(return new PDFJpegImageBench;)
-
-#endif // SK_SUPPORT_PDF
+DEF_BENCH(return new PDFCompressionBench;)
« no previous file with comments | « no previous file | gyp/bench.gyp » ('j') | gyp/bench.gyp » ('J')

Powered by Google App Engine
This is Rietveld 408576698