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" |
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 #include "SkStream.h" |
20 | 21 |
21 namespace { | 22 namespace { |
22 struct NullWStream : public SkWStream { | 23 struct NullWStream : public SkWStream { |
23 NullWStream() : fN(0) {} | 24 NullWStream() : fN(0) {} |
24 bool write(const void*, size_t n) override { fN += n; return true; } | 25 bool write(const void*, size_t n) override { fN += n; return true; } |
25 size_t bytesWritten() const override { return fN; } | 26 size_t bytesWritten() const override { return fN; } |
26 size_t fN; | 27 size_t fN; |
27 }; | 28 }; |
28 | 29 |
29 static void test_pdf_object_serialization(const sk_sp<SkPDFObject> object) { | 30 static void test_pdf_object_serialization(const sk_sp<SkPDFObject> object) { |
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
183 NullWStream nullStream; | 184 NullWStream nullStream; |
184 SkPDFDocument doc(&nullStream, nullptr, 72, nullptr); | 185 SkPDFDocument doc(&nullStream, nullptr, 72, nullptr); |
185 sk_sp<SkPDFObject> shader( | 186 sk_sp<SkPDFObject> shader( |
186 SkPDFShader::GetPDFShader( | 187 SkPDFShader::GetPDFShader( |
187 &doc, 72, fShader.get(), SkMatrix::I(), | 188 &doc, 72, fShader.get(), SkMatrix::I(), |
188 SkIRect::MakeWH(400,400), 72)); | 189 SkIRect::MakeWH(400,400), 72)); |
189 } | 190 } |
190 } | 191 } |
191 }; | 192 }; |
192 | 193 |
| 194 struct WStreamWriteTextBenchmark : public Benchmark { |
| 195 std::unique_ptr<SkWStream> fWStream; |
| 196 WStreamWriteTextBenchmark() : fWStream(new NullWStream) {} |
| 197 const char* onGetName() override { return "WStreamWriteText"; } |
| 198 bool isSuitableFor(Backend backend) override { |
| 199 return backend == kNonRendering_Backend; |
| 200 } |
| 201 void onDraw(int loops, SkCanvas*) override { |
| 202 while (loops-- > 0) { |
| 203 for (int i = 1000; i-- > 0;) { |
| 204 fWStream->writeText("HELLO SKIA!\n"); |
| 205 } |
| 206 } |
| 207 } |
| 208 }; |
| 209 |
193 } // namespace | 210 } // namespace |
194 DEF_BENCH(return new PDFImageBench;) | 211 DEF_BENCH(return new PDFImageBench;) |
195 DEF_BENCH(return new PDFJpegImageBench;) | 212 DEF_BENCH(return new PDFJpegImageBench;) |
196 DEF_BENCH(return new PDFCompressionBench;) | 213 DEF_BENCH(return new PDFCompressionBench;) |
197 DEF_BENCH(return new PDFScalarBench;) | 214 DEF_BENCH(return new PDFScalarBench;) |
198 DEF_BENCH(return new PDFShaderBench;) | 215 DEF_BENCH(return new PDFShaderBench;) |
| 216 DEF_BENCH(return new WStreamWriteTextBenchmark;) |
OLD | NEW |