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 "SkAutoPixmapStorage.h" | 10 #include "SkAutoPixmapStorage.h" |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
42 public: | 42 public: |
43 PDFImageBench() {} | 43 PDFImageBench() {} |
44 virtual ~PDFImageBench() {} | 44 virtual ~PDFImageBench() {} |
45 | 45 |
46 protected: | 46 protected: |
47 const char* onGetName() override { return "PDFImage"; } | 47 const char* onGetName() override { return "PDFImage"; } |
48 bool isSuitableFor(Backend backend) override { | 48 bool isSuitableFor(Backend backend) override { |
49 return backend == kNonRendering_Backend; | 49 return backend == kNonRendering_Backend; |
50 } | 50 } |
51 void onDelayedSetup() override { | 51 void onDelayedSetup() override { |
52 SkAutoTUnref<SkImage> img(GetResourceAsImage("color_wheel.png")); | 52 sk_sp<SkImage> img(GetResourceAsImage("color_wheel.png")); |
53 if (img) { | 53 if (img) { |
54 // force decoding, throw away reference to encoded data. | 54 // force decoding, throw away reference to encoded data. |
55 SkAutoPixmapStorage pixmap; | 55 SkAutoPixmapStorage pixmap; |
56 pixmap.alloc(SkImageInfo::MakeN32Premul(img->dimensions())); | 56 pixmap.alloc(SkImageInfo::MakeN32Premul(img->dimensions())); |
57 if (img->readPixels(pixmap, 0, 0)) { | 57 if (img->readPixels(pixmap, 0, 0)) { |
58 fImage.reset(SkImage::NewRasterCopy( | 58 fImage = SkImage::MakeRasterCopy(pixmap); |
59 pixmap.info(), pixmap.addr(), | |
60 pixmap.rowBytes(), pixmap.ctable())); | |
61 } | 59 } |
62 } | 60 } |
63 } | 61 } |
64 void onDraw(int loops, SkCanvas*) override { | 62 void onDraw(int loops, SkCanvas*) override { |
65 if (!fImage) { | 63 if (!fImage) { |
66 return; | 64 return; |
67 } | 65 } |
68 while (loops-- > 0) { | 66 while (loops-- > 0) { |
69 SkAutoTUnref<SkPDFObject> object( | 67 SkAutoTUnref<SkPDFObject> object( |
70 SkPDFCreateBitmapObject(fImage, nullptr)); | 68 SkPDFCreateBitmapObject(fImage.get(), nullptr)); |
71 SkASSERT(object); | 69 SkASSERT(object); |
72 if (!object) { | 70 if (!object) { |
73 return; | 71 return; |
74 } | 72 } |
75 test_pdf_object_serialization(object); | 73 test_pdf_object_serialization(object); |
76 } | 74 } |
77 } | 75 } |
78 | 76 |
79 private: | 77 private: |
80 SkAutoTUnref<SkImage> fImage; | 78 sk_sp<SkImage> fImage; |
81 }; | 79 }; |
82 | 80 |
83 class PDFJpegImageBench : public Benchmark { | 81 class PDFJpegImageBench : public Benchmark { |
84 public: | 82 public: |
85 PDFJpegImageBench() {} | 83 PDFJpegImageBench() {} |
86 virtual ~PDFJpegImageBench() {} | 84 virtual ~PDFJpegImageBench() {} |
87 | 85 |
88 protected: | 86 protected: |
89 const char* onGetName() override { return "PDFJpegImage"; } | 87 const char* onGetName() override { return "PDFJpegImage"; } |
90 bool isSuitableFor(Backend backend) override { | 88 bool isSuitableFor(Backend backend) override { |
91 return backend == kNonRendering_Backend; | 89 return backend == kNonRendering_Backend; |
92 } | 90 } |
93 void onDelayedSetup() override { | 91 void onDelayedSetup() override { |
94 SkAutoTUnref<SkImage> img( | 92 sk_sp<SkImage> img(GetResourceAsImage("mandrill_512_q075.jpg")); |
95 GetResourceAsImage("mandrill_512_q075.jpg")); | |
96 if (!img) { return; } | 93 if (!img) { return; } |
97 SkAutoTUnref<SkData> encoded(img->refEncoded()); | 94 SkAutoTUnref<SkData> encoded(img->refEncoded()); |
98 SkASSERT(encoded); | 95 SkASSERT(encoded); |
99 if (!encoded) { return; } | 96 if (!encoded) { return; } |
100 fImage.reset(img.release()); | 97 fImage = img; |
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 SkAutoTUnref<SkPDFObject> object( | 105 SkAutoTUnref<SkPDFObject> object( |
109 SkPDFCreateBitmapObject(fImage, nullptr)); | 106 SkPDFCreateBitmapObject(fImage.get(), nullptr)); |
110 SkASSERT(object); | 107 SkASSERT(object); |
111 if (!object) { | 108 if (!object) { |
112 return; | 109 return; |
113 } | 110 } |
114 test_pdf_object_serialization(object); | 111 test_pdf_object_serialization(object); |
115 } | 112 } |
116 } | 113 } |
117 | 114 |
118 private: | 115 private: |
119 SkAutoTUnref<SkImage> fImage; | 116 sk_sp<SkImage> fImage; |
120 }; | 117 }; |
121 | 118 |
122 /** Test calling DEFLATE on a 78k PDF command stream. Used for measuring | 119 /** Test calling DEFLATE on a 78k PDF command stream. Used for measuring |
123 alternate zlib settings, usage, and library versions. */ | 120 alternate zlib settings, usage, and library versions. */ |
124 class PDFCompressionBench : public Benchmark { | 121 class PDFCompressionBench : public Benchmark { |
125 public: | 122 public: |
126 PDFCompressionBench() {} | 123 PDFCompressionBench() {} |
127 virtual ~PDFCompressionBench() {} | 124 virtual ~PDFCompressionBench() {} |
128 | 125 |
129 protected: | 126 protected: |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
163 (void)SkPDFUtils::FloatToDecimal(f, dst); | 160 (void)SkPDFUtils::FloatToDecimal(f, dst); |
164 } | 161 } |
165 } | 162 } |
166 }; | 163 }; |
167 | 164 |
168 } // namespace | 165 } // namespace |
169 DEF_BENCH(return new PDFImageBench;) | 166 DEF_BENCH(return new PDFImageBench;) |
170 DEF_BENCH(return new PDFJpegImageBench;) | 167 DEF_BENCH(return new PDFJpegImageBench;) |
171 DEF_BENCH(return new PDFCompressionBench;) | 168 DEF_BENCH(return new PDFCompressionBench;) |
172 DEF_BENCH(return new PDFScalarBench;) | 169 DEF_BENCH(return new PDFScalarBench;) |
OLD | NEW |