OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2015 Google Inc. | 2 * Copyright 2015 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 // A benchmark designed to isolate the constant overheads of picture recording. | 8 // A benchmark designed to isolate the constant overheads of picture recording. |
9 // We record an empty picture and a picture with one draw op to force memory all
ocation. | 9 // We record an empty picture and a picture with one draw op to force memory all
ocation. |
10 | 10 |
11 #include "Benchmark.h" | 11 #include "Benchmark.h" |
12 #include "SkCanvas.h" | 12 #include "SkCanvas.h" |
| 13 #include "SkLiteDL.h" |
| 14 #include "SkLiteRecorder.h" |
13 #include "SkPictureRecorder.h" | 15 #include "SkPictureRecorder.h" |
14 | 16 |
15 template <bool kDraw> | 17 template <int kDraws, bool kLite> |
16 struct PictureOverheadBench : public Benchmark { | 18 struct PictureOverheadBench : public Benchmark { |
17 const char* onGetName() override { | 19 PictureOverheadBench() { |
18 return kDraw ? "picture_overhead_draw" : "picture_overhead_nodraw"; | 20 fName.appendf("picture_overhead_%d%s\n", kDraws, kLite ? "_lite" : ""); |
19 } | 21 } |
| 22 const char* onGetName() override { return fName.c_str(); } |
20 bool isSuitableFor(Backend backend) override { return backend == kNonRenderi
ng_Backend; } | 23 bool isSuitableFor(Backend backend) override { return backend == kNonRenderi
ng_Backend; } |
21 | 24 |
22 void onDraw(int loops, SkCanvas*) override { | 25 void onDraw(int loops, SkCanvas*) override { |
| 26 SkLiteRecorder lite; |
23 SkPictureRecorder rec; | 27 SkPictureRecorder rec; |
24 for (int i = 0; i < loops; i++) { | 28 for (int i = 0; i < loops; i++) { |
25 rec.beginRecording(SkRect::MakeWH(2000,3000)); | 29 SkRect bounds{0,0, 2000,3000}; |
26 if (kDraw) { | 30 |
27 rec.getRecordingCanvas()->drawRect(SkRect::MakeXYWH(10, 10, 1000
, 1000), SkPaint()); | 31 sk_sp<SkLiteDL> liteDL; |
| 32 SkCanvas* canvas; |
| 33 if (kLite) { |
| 34 liteDL = SkLiteDL::New(bounds); |
| 35 lite.reset(liteDL.get()); |
| 36 canvas = &lite; |
| 37 } else { |
| 38 rec.beginRecording(bounds); |
| 39 canvas = rec.getRecordingCanvas(); |
28 } | 40 } |
29 (void)rec.finishRecordingAsPicture(); | 41 |
| 42 for (int i = 0; i < kDraws; i++) { |
| 43 canvas->drawRect({10,10, 1000, 1000}, SkPaint{}); |
| 44 } |
| 45 |
| 46 if (!kLite) { |
| 47 (void)rec.finishRecordingAsPicture(); |
| 48 } |
30 } | 49 } |
31 } | 50 } |
| 51 |
| 52 SkString fName; |
32 }; | 53 }; |
33 | 54 |
34 DEF_BENCH(return (new PictureOverheadBench<false>);) | 55 DEF_BENCH(return (new PictureOverheadBench<0, false>);) |
35 DEF_BENCH(return (new PictureOverheadBench< true>);) | 56 DEF_BENCH(return (new PictureOverheadBench<1, false>);) |
| 57 DEF_BENCH(return (new PictureOverheadBench<2, false>);) |
| 58 DEF_BENCH(return (new PictureOverheadBench<10,false>);) |
| 59 DEF_BENCH(return (new PictureOverheadBench<0, true>);) |
| 60 DEF_BENCH(return (new PictureOverheadBench<1, true>);) |
| 61 DEF_BENCH(return (new PictureOverheadBench<2, true>);) |
| 62 DEF_BENCH(return (new PictureOverheadBench<10, true>);) |
OLD | NEW |