blob: 4fca2f4d321ab70194ec09ed7bd5cd50fb472a54 [file] [log] [blame]
mtklein649e0452015-04-03 13:25:13 -07001/*
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 Kleinc0bd9f92019-04-23 12:05:21 -05008#include "bench/Benchmark.h"
9#include "include/core/SkCanvas.h"
10#include "include/core/SkPictureRecorder.h"
Mike Kleina705cb92019-05-14 12:33:40 -050011#include "include/core/SkRRect.h"
Mike Reed3802888e2017-03-06 14:14:09 -050012
13class ClipOverheadRecordingBench : public Benchmark {
Mike Reed3802888e2017-03-06 14:14:09 -050014public:
Mike Kleina705cb92019-05-14 12:33:40 -050015 ClipOverheadRecordingBench() {}
Mike Reed3802888e2017-03-06 14:14:09 -050016
Mike Kleina705cb92019-05-14 12:33:40 -050017private:
18 const char* onGetName() override { return "clip_overhead_recording"; }
Mike Reed3802888e2017-03-06 14:14:09 -050019 bool isSuitableFor(Backend backend) override { return backend == kNonRendering_Backend; }
20
21 void onDraw(int loops, SkCanvas*) override {
Mike Reed3802888e2017-03-06 14:14:09 -050022 SkPictureRecorder rec;
23
Mike Reed3802888e2017-03-06 14:14:09 -050024 for (int i = 0; i < loops; i++) {
Mike Kleina705cb92019-05-14 12:33:40 -050025 SkCanvas* canvas = rec.beginRecording({0,0, 2000,3000});
Mike Reed3802888e2017-03-06 14:14:09 -050026
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 Kleina705cb92019-05-14 12:33:40 -050032 canvas->translate(10, 10);
33 canvas->clipRect({10,10, 1000, 1000});
34 canvas->drawRRect(rrect, paint);
Mike Reed3802888e2017-03-06 14:14:09 -050035 canvas->restore();
36 }
37
Mike Kleina705cb92019-05-14 12:33:40 -050038 (void)rec.finishRecordingAsPicture();
Mike Reed3802888e2017-03-06 14:14:09 -050039 }
40 }
41};
Mike Kleina705cb92019-05-14 12:33:40 -050042DEF_BENCH( return new ClipOverheadRecordingBench; )