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

Side by Side 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: 2016-02-24 (Wednesday) 13:48:33 EST 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 unified diff | Download patch
« no previous file with comments | « no previous file | gyp/bench.gyp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2016 Google Inc. 2 * Copyright 2016 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "Benchmark.h" 8 #include "Benchmark.h"
9 #include "Resources.h" 9 #include "Resources.h"
10 #include "SkData.h"
10 #include "SkImage.h" 11 #include "SkImage.h"
12 #include "SkPDFBitmap.h"
11 #include "SkPixmap.h" 13 #include "SkPixmap.h"
12 #include "SkData.h"
13
14 #if SK_SUPPORT_PDF
15
16 #include "SkPDFBitmap.h"
17 14
18 namespace { 15 namespace {
19 struct NullWStream : public SkWStream { 16 struct NullWStream : public SkWStream {
20 NullWStream() : fN(0) {} 17 NullWStream() : fN(0) {}
21 bool write(const void*, size_t n) override { fN += n; return true; } 18 bool write(const void*, size_t n) override { fN += n; return true; }
22 size_t bytesWritten() const override { return fN; } 19 size_t bytesWritten() const override { return fN; }
23 size_t fN; 20 size_t fN;
24 }; 21 };
25 22
26 static void test_pdf_image_serialization(SkImage* img) { 23 static void test_pdf_object_serialization(SkPDFObject* object) {
27 SkAutoTUnref<SkPDFObject> object(
28 SkPDFCreateBitmapObject(img, nullptr));
29 if (!object) {
30 SkDEBUGFAIL("");
31 return;
32 }
33 // SkDebugWStream wStream; 24 // SkDebugWStream wStream;
34 NullWStream wStream; 25 NullWStream wStream;
35 SkPDFSubstituteMap substitutes; 26 SkPDFSubstituteMap substitutes;
36 SkPDFObjNumMap objNumMap; 27 SkPDFObjNumMap objNumMap;
37 objNumMap.addObjectRecursively(object, substitutes); 28 objNumMap.addObjectRecursively(object, substitutes);
38 for (int i = 0; i < objNumMap.objects().count(); ++i) { 29 for (int i = 0; i < objNumMap.objects().count(); ++i) {
39 SkPDFObject* object = objNumMap.objects()[i]; 30 SkPDFObject* object = objNumMap.objects()[i];
40 wStream.writeDecAsText(i + 1); 31 wStream.writeDecAsText(i + 1);
41 wStream.writeText(" 0 obj\n"); 32 wStream.writeText(" 0 obj\n");
42 object->emitObject(&wStream, objNumMap, substitutes); 33 object->emitObject(&wStream, objNumMap, substitutes);
43 wStream.writeText("\nendobj\n"); 34 wStream.writeText("\nendobj\n");
44 } 35 }
45 } 36 }
46 37
38 static void test_pdf_image_serialization(SkImage* img) {
39 SkAutoTUnref<SkPDFObject> object(
40 SkPDFCreateBitmapObject(img, nullptr));
41 if (!object) {
42 SkDEBUGFAIL("");
43 return;
44 }
45 test_pdf_object_serialization(object);
46 }
47
47 class PDFImageBench : public Benchmark { 48 class PDFImageBench : public Benchmark {
48 public: 49 public:
49 PDFImageBench() {} 50 PDFImageBench() {}
50 virtual ~PDFImageBench() {} 51 virtual ~PDFImageBench() {}
51 52
52 protected: 53 protected:
53 const char* onGetName() override { return "PDFImage"; } 54 const char* onGetName() override { return "PDFImage"; }
54 bool isSuitableFor(Backend backend) override { 55 bool isSuitableFor(Backend backend) override {
55 return backend == kNonRendering_Backend; 56 return backend == kNonRendering_Backend;
56 } 57 }
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
106 } 107 }
107 while (loops-- > 0) { 108 while (loops-- > 0) {
108 test_pdf_image_serialization(fImage); 109 test_pdf_image_serialization(fImage);
109 } 110 }
110 } 111 }
111 112
112 private: 113 private:
113 SkAutoTUnref<SkImage> fImage; 114 SkAutoTUnref<SkImage> fImage;
114 }; 115 };
115 116
117 /** Test calling DEFLATE on a 78k PDF command stream. Used for measuring
118 alternate zlib settings, usage, and library versions. */
119 class PDFCompressionBench : public Benchmark {
120 public:
121 PDFCompressionBench() {}
122 virtual ~PDFCompressionBench() {}
123
124 protected:
125 const char* onGetName() override { return "PDFCompression"; }
126 bool isSuitableFor(Backend backend) override {
127 return backend == kNonRendering_Backend;
128 }
129 void onDelayedSetup() override {
130 fRandomText.reset(GetResourceAsStream("pdf_command_stream.txt"));
131 }
132 void onDraw(int loops, SkCanvas*) override {
133 SkASSERT(fRandomText);
134 if (!fRandomText) { return; }
135 while (loops-- > 0) {
136 SkAutoTUnref<SkPDFObject> object(
137 new SkPDFSharedStream(fRandomText->duplicate()));
138 test_pdf_object_serialization(object);
139 }
140 }
141
142 private:
143 SkAutoTDelete<SkStreamAsset> fRandomText;
mtklein 2016/02/24 19:59:44 Funny name now.
hal.canary 2016/02/24 22:07:16 fixed
144 };
145
116 } // namespace 146 } // namespace
117 DEF_BENCH(return new PDFImageBench;) 147 DEF_BENCH(return new PDFImageBench;)
118 DEF_BENCH(return new PDFJpegImageBench;) 148 DEF_BENCH(return new PDFJpegImageBench;)
119 149 DEF_BENCH(return new PDFCompressionBench;)
120 #endif // SK_SUPPORT_PDF
OLDNEW
« no previous file with comments | « no previous file | gyp/bench.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698