aboutsummaryrefslogtreecommitdiff
path: root/bench/PictureOverheadBench.cpp
blob: daacf5e65f3df20c1a323928f920c28d4dcb3637 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
/*
 * Copyright 2015 Google Inc.
 *
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 */

#include "bench/Benchmark.h"
#include "include/core/SkCanvas.h"
#include "include/core/SkPictureRecorder.h"
#include "include/core/SkRRect.h"

class ClipOverheadRecordingBench : public Benchmark {
public:
    ClipOverheadRecordingBench() {}

private:
    const char* onGetName() override { return "clip_overhead_recording"; }
    bool isSuitableFor(Backend backend) override { return backend == kNonRendering_Backend; }

    void onDraw(int loops, SkCanvas*) override {
        SkPictureRecorder rec;

        for (int loop = 0; loop < loops; loop++) {
            SkCanvas* canvas = rec.beginRecording({0,0, 2000,3000});

            SkPaint paint;
            SkRRect rrect;
            rrect.setOval({0, 0, 1000, 1000});
            for (int i = 0; i < 1000; i++) {
                canvas->save();
                    canvas->translate(10, 10);
                    canvas->clipRect({10,10, 1000, 1000});
                    canvas->drawRRect(rrect, paint);
                canvas->restore();
            }

            (void)rec.finishRecordingAsPicture();
        }
    }
};
DEF_BENCH( return new ClipOverheadRecordingBench; )