mtklein | 649e045 | 2015-04-03 13:25:13 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2015 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
| 7 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 8 | #include "bench/Benchmark.h" |
| 9 | #include "include/core/SkCanvas.h" |
| 10 | #include "include/core/SkPictureRecorder.h" |
Mike Klein | a705cb9 | 2019-05-14 12:33:40 -0500 | [diff] [blame] | 11 | #include "include/core/SkRRect.h" |
Mike Reed | 3802888e | 2017-03-06 14:14:09 -0500 | [diff] [blame] | 12 | |
| 13 | class ClipOverheadRecordingBench : public Benchmark { |
Mike Reed | 3802888e | 2017-03-06 14:14:09 -0500 | [diff] [blame] | 14 | public: |
Mike Klein | a705cb9 | 2019-05-14 12:33:40 -0500 | [diff] [blame] | 15 | ClipOverheadRecordingBench() {} |
Mike Reed | 3802888e | 2017-03-06 14:14:09 -0500 | [diff] [blame] | 16 | |
Mike Klein | a705cb9 | 2019-05-14 12:33:40 -0500 | [diff] [blame] | 17 | private: |
| 18 | const char* onGetName() override { return "clip_overhead_recording"; } |
Mike Reed | 3802888e | 2017-03-06 14:14:09 -0500 | [diff] [blame] | 19 | bool isSuitableFor(Backend backend) override { return backend == kNonRendering_Backend; } |
| 20 | |
| 21 | void onDraw(int loops, SkCanvas*) override { |
Mike Reed | 3802888e | 2017-03-06 14:14:09 -0500 | [diff] [blame] | 22 | SkPictureRecorder rec; |
| 23 | |
Mike Reed | 3802888e | 2017-03-06 14:14:09 -0500 | [diff] [blame] | 24 | for (int i = 0; i < loops; i++) { |
Mike Klein | a705cb9 | 2019-05-14 12:33:40 -0500 | [diff] [blame] | 25 | SkCanvas* canvas = rec.beginRecording({0,0, 2000,3000}); |
Mike Reed | 3802888e | 2017-03-06 14:14:09 -0500 | [diff] [blame] | 26 | |
| 27 | SkPaint paint; |
| 28 | SkRRect rrect; |
| 29 | rrect.setOval({0, 0, 1000, 1000}); |
| 30 | for (int i = 0; i < 1000; i++) { |
| 31 | canvas->save(); |
Mike Klein | a705cb9 | 2019-05-14 12:33:40 -0500 | [diff] [blame] | 32 | canvas->translate(10, 10); |
| 33 | canvas->clipRect({10,10, 1000, 1000}); |
| 34 | canvas->drawRRect(rrect, paint); |
Mike Reed | 3802888e | 2017-03-06 14:14:09 -0500 | [diff] [blame] | 35 | canvas->restore(); |
| 36 | } |
| 37 | |
Mike Klein | a705cb9 | 2019-05-14 12:33:40 -0500 | [diff] [blame] | 38 | (void)rec.finishRecordingAsPicture(); |
Mike Reed | 3802888e | 2017-03-06 14:14:09 -0500 | [diff] [blame] | 39 | } |
| 40 | } |
| 41 | }; |
Mike Klein | a705cb9 | 2019-05-14 12:33:40 -0500 | [diff] [blame] | 42 | DEF_BENCH( return new ClipOverheadRecordingBench; ) |