OLD | NEW |
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); |
(...skipping 22 matching lines...) Expand all Loading... |
65 pixmap.info(), pixmap.addr(), | 56 pixmap.info(), pixmap.addr(), |
66 pixmap.rowBytes(), pixmap.ctable())); | 57 pixmap.rowBytes(), pixmap.ctable())); |
67 } | 58 } |
68 } | 59 } |
69 } | 60 } |
70 void onDraw(int loops, SkCanvas*) override { | 61 void onDraw(int loops, SkCanvas*) override { |
71 if (!fImage) { | 62 if (!fImage) { |
72 return; | 63 return; |
73 } | 64 } |
74 while (loops-- > 0) { | 65 while (loops-- > 0) { |
75 test_pdf_image_serialization(fImage); | 66 SkAutoTUnref<SkPDFObject> object( |
| 67 SkPDFCreateBitmapObject(fImage, nullptr)); |
| 68 SkASSERT(object); |
| 69 if (!object) { |
| 70 return; |
| 71 } |
| 72 test_pdf_object_serialization(object); |
76 } | 73 } |
77 } | 74 } |
78 | 75 |
79 private: | 76 private: |
80 SkAutoTUnref<SkImage> fImage; | 77 SkAutoTUnref<SkImage> fImage; |
81 }; | 78 }; |
82 | 79 |
83 class PDFJpegImageBench : public Benchmark { | 80 class PDFJpegImageBench : public Benchmark { |
84 public: | 81 public: |
85 PDFJpegImageBench() {} | 82 PDFJpegImageBench() {} |
(...skipping 12 matching lines...) Expand all Loading... |
98 SkASSERT(encoded); | 95 SkASSERT(encoded); |
99 if (!encoded) { return; } | 96 if (!encoded) { return; } |
100 fImage.reset(img.release()); | 97 fImage.reset(img.release()); |
101 } | 98 } |
102 void onDraw(int loops, SkCanvas*) override { | 99 void onDraw(int loops, SkCanvas*) override { |
103 if (!fImage) { | 100 if (!fImage) { |
104 SkDEBUGFAIL(""); | 101 SkDEBUGFAIL(""); |
105 return; | 102 return; |
106 } | 103 } |
107 while (loops-- > 0) { | 104 while (loops-- > 0) { |
108 test_pdf_image_serialization(fImage); | 105 SkAutoTUnref<SkPDFObject> object( |
| 106 SkPDFCreateBitmapObject(fImage, nullptr)); |
| 107 SkASSERT(object); |
| 108 if (!object) { |
| 109 return; |
| 110 } |
| 111 test_pdf_object_serialization(object); |
109 } | 112 } |
110 } | 113 } |
111 | 114 |
112 private: | 115 private: |
113 SkAutoTUnref<SkImage> fImage; | 116 SkAutoTUnref<SkImage> fImage; |
114 }; | 117 }; |
115 | 118 |
| 119 /** Test calling DEFLATE on a 78k PDF command stream. Used for measuring |
| 120 alternate zlib settings, usage, and library versions. */ |
| 121 class PDFCompressionBench : public Benchmark { |
| 122 public: |
| 123 PDFCompressionBench() {} |
| 124 virtual ~PDFCompressionBench() {} |
| 125 |
| 126 protected: |
| 127 const char* onGetName() override { return "PDFCompression"; } |
| 128 bool isSuitableFor(Backend backend) override { |
| 129 return backend == kNonRendering_Backend; |
| 130 } |
| 131 void onDelayedSetup() override { |
| 132 fAsset.reset(GetResourceAsStream("pdf_command_stream.txt")); |
| 133 } |
| 134 void onDraw(int loops, SkCanvas*) override { |
| 135 SkASSERT(fAsset); |
| 136 if (!fAsset) { return; } |
| 137 while (loops-- > 0) { |
| 138 SkAutoTUnref<SkPDFObject> object( |
| 139 new SkPDFSharedStream(fAsset->duplicate())); |
| 140 test_pdf_object_serialization(object); |
| 141 } |
| 142 } |
| 143 |
| 144 private: |
| 145 SkAutoTDelete<SkStreamAsset> fAsset; |
| 146 }; |
| 147 |
116 } // namespace | 148 } // namespace |
117 DEF_BENCH(return new PDFImageBench;) | 149 DEF_BENCH(return new PDFImageBench;) |
118 DEF_BENCH(return new PDFJpegImageBench;) | 150 DEF_BENCH(return new PDFJpegImageBench;) |
119 | 151 DEF_BENCH(return new PDFCompressionBench;) |
120 #endif // SK_SUPPORT_PDF | |
OLD | NEW |