blob: 62a51ec3598d05a8a2b13c48db8d01dff1dbebac [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
8// A benchmark designed to isolate the constant overheads of picture recording.
mtkleinf559de42015-04-06 07:25:04 -07009// We record an empty picture and a picture with one draw op to force memory allocation.
mtklein649e0452015-04-03 13:25:13 -070010
11#include "Benchmark.h"
12#include "SkCanvas.h"
13#include "SkPictureRecorder.h"
14
mtkleinf559de42015-04-06 07:25:04 -070015template <bool kDraw>
mtklein649e0452015-04-03 13:25:13 -070016struct PictureOverheadBench : public Benchmark {
mtkleinf559de42015-04-06 07:25:04 -070017 const char* onGetName() override {
18 return kDraw ? "picture_overhead_draw" : "picture_overhead_nodraw";
19 }
mtklein649e0452015-04-03 13:25:13 -070020 bool isSuitableFor(Backend backend) override { return backend == kNonRendering_Backend; }
21
mtkleina1ebeb22015-10-01 09:43:39 -070022 void onDraw(int loops, SkCanvas*) override {
mtklein649e0452015-04-03 13:25:13 -070023 SkPictureRecorder rec;
24 for (int i = 0; i < loops; i++) {
mtkleinf559de42015-04-06 07:25:04 -070025 rec.beginRecording(SkRect::MakeWH(2000,3000));
26 if (kDraw) {
27 rec.getRecordingCanvas()->drawRect(SkRect::MakeXYWH(10, 10, 1000, 1000), SkPaint());
28 }
mtklein649e0452015-04-03 13:25:13 -070029 SkAutoTUnref<SkPicture> pic(rec.endRecordingAsPicture());
30 }
31 }
32};
mtkleinf559de42015-04-06 07:25:04 -070033
34DEF_BENCH(return (new PictureOverheadBench<false>);)
35DEF_BENCH(return (new PictureOverheadBench< true>);)