• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
8 #include "bench/Benchmark.h"
9 #include "include/core/SkCanvas.h"
10 #include "include/core/SkPictureRecorder.h"
11 #include "include/core/SkRRect.h"
12 
13 class ClipOverheadRecordingBench : public Benchmark {
14 public:
ClipOverheadRecordingBench()15     ClipOverheadRecordingBench() {}
16 
17 private:
onGetName()18     const char* onGetName() override { return "clip_overhead_recording"; }
isSuitableFor(Backend backend)19     bool isSuitableFor(Backend backend) override { return backend == kNonRendering_Backend; }
20 
onDraw(int loops,SkCanvas *)21     void onDraw(int loops, SkCanvas*) override {
22         SkPictureRecorder rec;
23 
24         for (int loop = 0; loop < loops; loop++) {
25             SkCanvas* canvas = rec.beginRecording({0,0, 2000,3000});
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();
32                     canvas->translate(10, 10);
33                     canvas->clipRect({10,10, 1000, 1000});
34                     canvas->drawRRect(rrect, paint);
35                 canvas->restore();
36             }
37 
38             (void)rec.finishRecordingAsPicture();
39         }
40     }
41 };
42 DEF_BENCH( return new ClipOverheadRecordingBench; )
43