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

Side by Side Diff: bench/PDFBench.cpp

Issue 1829693002: SkPDF: draw{Image,Bitmap} always serializes early (Closed) Base URL: https://skia.googlesource.com/skia.git@r1823683005
Patch Set: rebase Created 4 years, 9 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/pdf.gypi » ('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 "SkAutoPixmapStorage.h" 10 #include "SkAutoPixmapStorage.h"
11 #include "SkData.h" 11 #include "SkData.h"
12 #include "SkGradientShader.h" 12 #include "SkGradientShader.h"
13 #include "SkImage.h" 13 #include "SkImage.h"
14 #include "SkPDFBitmap.h" 14 #include "SkPDFBitmap.h"
15 #include "SkPDFDocument.h" 15 #include "SkPDFDocument.h"
16 #include "SkPDFShader.h" 16 #include "SkPDFShader.h"
17 #include "SkPDFUtils.h" 17 #include "SkPDFUtils.h"
18 #include "SkPixmap.h" 18 #include "SkPixmap.h"
19 #include "SkRandom.h" 19 #include "SkRandom.h"
20 20
21 namespace { 21 namespace {
22 struct NullWStream : public SkWStream { 22 struct NullWStream : public SkWStream {
23 NullWStream() : fN(0) {} 23 NullWStream() : fN(0) {}
24 bool write(const void*, size_t n) override { fN += n; return true; } 24 bool write(const void*, size_t n) override { fN += n; return true; }
25 size_t bytesWritten() const override { return fN; } 25 size_t bytesWritten() const override { return fN; }
26 size_t fN; 26 size_t fN;
27 }; 27 };
28 28
29 static void test_pdf_object_serialization(SkPDFObject* object) { 29 static void test_pdf_object_serialization(const sk_sp<SkPDFObject> object) {
30 // SkDebugWStream wStream; 30 // SkDebugWStream wStream;
31 NullWStream wStream; 31 NullWStream wStream;
32 SkPDFSubstituteMap substitutes; 32 SkPDFSubstituteMap substitutes;
33 SkPDFObjNumMap objNumMap; 33 SkPDFObjNumMap objNumMap;
34 objNumMap.addObjectRecursively(object, substitutes); 34 objNumMap.addObjectRecursively(object.get(), substitutes);
35 for (int i = 0; i < objNumMap.objects().count(); ++i) { 35 for (int i = 0; i < objNumMap.objects().count(); ++i) {
36 SkPDFObject* object = objNumMap.objects()[i].get(); 36 SkPDFObject* object = objNumMap.objects()[i].get();
37 wStream.writeDecAsText(i + 1); 37 wStream.writeDecAsText(i + 1);
38 wStream.writeText(" 0 obj\n"); 38 wStream.writeText(" 0 obj\n");
39 object->emitObject(&wStream, objNumMap, substitutes); 39 object->emitObject(&wStream, objNumMap, substitutes);
40 wStream.writeText("\nendobj\n"); 40 wStream.writeText("\nendobj\n");
41 } 41 }
42 } 42 }
43 43
44 class PDFImageBench : public Benchmark { 44 class PDFImageBench : public Benchmark {
(...skipping 15 matching lines...) Expand all
60 if (img->readPixels(pixmap, 0, 0)) { 60 if (img->readPixels(pixmap, 0, 0)) {
61 fImage = SkImage::MakeRasterCopy(pixmap); 61 fImage = SkImage::MakeRasterCopy(pixmap);
62 } 62 }
63 } 63 }
64 } 64 }
65 void onDraw(int loops, SkCanvas*) override { 65 void onDraw(int loops, SkCanvas*) override {
66 if (!fImage) { 66 if (!fImage) {
67 return; 67 return;
68 } 68 }
69 while (loops-- > 0) { 69 while (loops-- > 0) {
70 SkAutoTUnref<SkPDFObject> object( 70 auto object = SkPDFCreateBitmapObject(fImage, nullptr);
71 SkPDFCreateBitmapObject(fImage.get(), nullptr));
72 SkASSERT(object); 71 SkASSERT(object);
73 if (!object) { 72 if (!object) {
74 return; 73 return;
75 } 74 }
76 test_pdf_object_serialization(object); 75 test_pdf_object_serialization(object);
77 } 76 }
78 } 77 }
79 78
80 private: 79 private:
81 sk_sp<SkImage> fImage; 80 sk_sp<SkImage> fImage;
82 }; 81 };
83 82
84 class PDFJpegImageBench : public Benchmark { 83 class PDFJpegImageBench : public Benchmark {
85 public: 84 public:
86 PDFJpegImageBench() {} 85 PDFJpegImageBench() {}
87 virtual ~PDFJpegImageBench() {} 86 virtual ~PDFJpegImageBench() {}
88 87
89 protected: 88 protected:
90 const char* onGetName() override { return "PDFJpegImage"; } 89 const char* onGetName() override { return "PDFJpegImage"; }
91 bool isSuitableFor(Backend backend) override { 90 bool isSuitableFor(Backend backend) override {
92 return backend == kNonRendering_Backend; 91 return backend == kNonRendering_Backend;
93 } 92 }
94 void onDelayedSetup() override { 93 void onDelayedSetup() override {
95 sk_sp<SkImage> img(GetResourceAsImage("mandrill_512_q075.jpg")); 94 sk_sp<SkImage> img(GetResourceAsImage("mandrill_512_q075.jpg"));
96 if (!img) { return; } 95 if (!img) { return; }
97 SkAutoTUnref<SkData> encoded(img->refEncoded()); 96 sk_sp<SkData> encoded(img->refEncoded());
98 SkASSERT(encoded); 97 SkASSERT(encoded);
99 if (!encoded) { return; } 98 if (!encoded) { return; }
100 fImage = img; 99 fImage = img;
101 } 100 }
102 void onDraw(int loops, SkCanvas*) override { 101 void onDraw(int loops, SkCanvas*) override {
103 if (!fImage) { 102 if (!fImage) {
104 SkDEBUGFAIL(""); 103 SkDEBUGFAIL("");
105 return; 104 return;
106 } 105 }
107 while (loops-- > 0) { 106 while (loops-- > 0) {
108 SkAutoTUnref<SkPDFObject> object( 107 auto object = SkPDFCreateBitmapObject(fImage, nullptr);
109 SkPDFCreateBitmapObject(fImage.get(), nullptr));
110 SkASSERT(object); 108 SkASSERT(object);
111 if (!object) { 109 if (!object) {
112 return; 110 return;
113 } 111 }
114 test_pdf_object_serialization(object); 112 test_pdf_object_serialization(object);
115 } 113 }
116 } 114 }
117 115
118 private: 116 private:
119 sk_sp<SkImage> fImage; 117 sk_sp<SkImage> fImage;
(...skipping 11 matching lines...) Expand all
131 bool isSuitableFor(Backend backend) override { 129 bool isSuitableFor(Backend backend) override {
132 return backend == kNonRendering_Backend; 130 return backend == kNonRendering_Backend;
133 } 131 }
134 void onDelayedSetup() override { 132 void onDelayedSetup() override {
135 fAsset.reset(GetResourceAsStream("pdf_command_stream.txt")); 133 fAsset.reset(GetResourceAsStream("pdf_command_stream.txt"));
136 } 134 }
137 void onDraw(int loops, SkCanvas*) override { 135 void onDraw(int loops, SkCanvas*) override {
138 SkASSERT(fAsset); 136 SkASSERT(fAsset);
139 if (!fAsset) { return; } 137 if (!fAsset) { return; }
140 while (loops-- > 0) { 138 while (loops-- > 0) {
141 SkAutoTUnref<SkPDFObject> object( 139 sk_sp<SkPDFObject> object(
142 new SkPDFSharedStream(fAsset->duplicate())); 140 new SkPDFSharedStream(fAsset->duplicate()));
143 test_pdf_object_serialization(object); 141 test_pdf_object_serialization(object);
144 } 142 }
145 } 143 }
146 144
147 private: 145 private:
148 SkAutoTDelete<SkStreamAsset> fAsset; 146 SkAutoTDelete<SkStreamAsset> fAsset;
149 }; 147 };
150 148
151 // Test speed of SkPDFUtils::FloatToDecimal for typical floats that 149 // Test speed of SkPDFUtils::FloatToDecimal for typical floats that
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
191 } 189 }
192 } 190 }
193 }; 191 };
194 192
195 } // namespace 193 } // namespace
196 DEF_BENCH(return new PDFImageBench;) 194 DEF_BENCH(return new PDFImageBench;)
197 DEF_BENCH(return new PDFJpegImageBench;) 195 DEF_BENCH(return new PDFJpegImageBench;)
198 DEF_BENCH(return new PDFCompressionBench;) 196 DEF_BENCH(return new PDFCompressionBench;)
199 DEF_BENCH(return new PDFScalarBench;) 197 DEF_BENCH(return new PDFScalarBench;)
200 DEF_BENCH(return new PDFShaderBench;) 198 DEF_BENCH(return new PDFShaderBench;)
OLDNEW
« no previous file with comments | « no previous file | gyp/pdf.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698