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 "SkImage.h" | 13 #include "SkImage.h" |
13 #include "SkPDFBitmap.h" | 14 #include "SkPDFBitmap.h" |
| 15 #include "SkPDFDocument.h" |
| 16 #include "SkPDFShader.h" |
14 #include "SkPDFUtils.h" | 17 #include "SkPDFUtils.h" |
15 #include "SkPixmap.h" | 18 #include "SkPixmap.h" |
16 #include "SkRandom.h" | 19 #include "SkRandom.h" |
17 | 20 |
18 namespace { | 21 namespace { |
19 struct NullWStream : public SkWStream { | 22 struct NullWStream : public SkWStream { |
20 NullWStream() : fN(0) {} | 23 NullWStream() : fN(0) {} |
21 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; } |
22 size_t bytesWritten() const override { return fN; } | 25 size_t bytesWritten() const override { return fN; } |
23 size_t fN; | 26 size_t fN; |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
155 void onDraw(int loops, SkCanvas*) override { | 158 void onDraw(int loops, SkCanvas*) override { |
156 SkRandom random; | 159 SkRandom random; |
157 char dst[SkPDFUtils::kMaximumFloatDecimalLength]; | 160 char dst[SkPDFUtils::kMaximumFloatDecimalLength]; |
158 while (loops-- > 0) { | 161 while (loops-- > 0) { |
159 auto f = random.nextRangeF(-500.0f, 1500.0f); | 162 auto f = random.nextRangeF(-500.0f, 1500.0f); |
160 (void)SkPDFUtils::FloatToDecimal(f, dst); | 163 (void)SkPDFUtils::FloatToDecimal(f, dst); |
161 } | 164 } |
162 } | 165 } |
163 }; | 166 }; |
164 | 167 |
| 168 struct PDFShaderBench : public Benchmark { |
| 169 sk_sp<SkShader> fShader; |
| 170 const char* onGetName() final { return "PDFShader"; } |
| 171 bool isSuitableFor(Backend b) final { return b == kNonRendering_Backend; } |
| 172 void onDelayedSetup() final { |
| 173 const SkPoint pts[2] = {{0.0f, 0.0f}, {100.0f, 100.0f}}; |
| 174 const SkColor colors[] = { |
| 175 SK_ColorRED, SK_ColorGREEN, SK_ColorBLUE, |
| 176 SK_ColorWHITE, SK_ColorBLACK, |
| 177 }; |
| 178 fShader = SkGradientShader::MakeLinear( |
| 179 pts, colors, nullptr, SK_ARRAY_COUNT(colors), |
| 180 SkShader::kClamp_TileMode); |
| 181 } |
| 182 void onDraw(int loops, SkCanvas*) final { |
| 183 SkASSERT(fShader); |
| 184 while (loops-- > 0) { |
| 185 NullWStream nullStream; |
| 186 SkPDFDocument doc(&nullStream, nullptr, 72, nullptr); |
| 187 sk_sp<SkPDFObject> shader( |
| 188 SkPDFShader::GetPDFShader( |
| 189 &doc, 72, *fShader, SkMatrix::I(), |
| 190 SkIRect::MakeWH(400,400), 72)); |
| 191 } |
| 192 } |
| 193 }; |
| 194 |
165 } // namespace | 195 } // namespace |
166 DEF_BENCH(return new PDFImageBench;) | 196 DEF_BENCH(return new PDFImageBench;) |
167 DEF_BENCH(return new PDFJpegImageBench;) | 197 DEF_BENCH(return new PDFJpegImageBench;) |
168 DEF_BENCH(return new PDFCompressionBench;) | 198 DEF_BENCH(return new PDFCompressionBench;) |
169 DEF_BENCH(return new PDFScalarBench;) | 199 DEF_BENCH(return new PDFScalarBench;) |
| 200 DEF_BENCH(return new PDFShaderBench;) |
OLD | NEW |