Flutter Engine
The Flutter Engine
PicturePlaybackBench.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2011 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#include <memory>
8
9#include "bench/Benchmark.h"
17#include "include/core/SkRect.h"
19#include "src/base/SkRandom.h"
20
21// This is designed to emulate about 4 screens of textual content
22
23///////////////////////////////////////////////////////////////////////////////
24
25// Chrome draws into small tiles with impl-side painting.
26// This benchmark measures the relative performance of our bounding-box hierarchies,
27// both when querying tiles perfectly and when not.
28enum BBH { kNone, kRTree };
31public:
32 TiledPlaybackBench(BBH bbh, Mode mode) : fBBH(bbh), fMode(mode), fName("tiled_playback") {
33 switch (fBBH) {
34 case kNone: fName.append("_none" ); break;
35 case kRTree: fName.append("_rtree" ); break;
36 }
37 switch (fMode) {
38 case kTiled: fName.append("_tiled" ); break;
39 case kRandom: fName.append("_random"); break;
40 }
41 }
42
43 const char* onGetName() override { return fName.c_str(); }
44 SkISize onGetSize() override { return SkISize::Make(1024,1024); }
45
46 void onDelayedSetup() override {
47 std::unique_ptr<SkBBHFactory> factory;
48 switch (fBBH) {
49 case kNone: break;
50 case kRTree: factory = std::make_unique<SkRTreeFactory>(); break;
51 }
52
53 SkPictureRecorder recorder;
54 SkCanvas* canvas = recorder.beginRecording(1024, 1024, factory.get());
55 SkRandom rand;
56 for (int i = 0; i < 10000; i++) {
57 SkScalar x = rand.nextRangeScalar(0, 1024),
58 y = rand.nextRangeScalar(0, 1024),
59 w = rand.nextRangeScalar(0, 128),
60 h = rand.nextRangeScalar(0, 128);
62 paint.setColor(rand.nextU());
63 paint.setAlpha(0xFF);
64 canvas->drawRect(SkRect::MakeXYWH(x,y,w,h), paint);
65 }
66 fPic = recorder.finishRecordingAsPicture();
67 }
68
69 void onDraw(int loops, SkCanvas* canvas) override {
70 for (int i = 0; i < loops; i++) {
71 // This inner loop guarantees we make the same choices for all bench variants.
72 SkRandom rand;
73 for (int j = 0; j < 10; j++) {
74 SkScalar x = 0, y = 0;
75 switch (fMode) {
76 case kTiled: x = SkScalar(256 * rand.nextULessThan(4));
77 y = SkScalar(256 * rand.nextULessThan(4));
78 break;
79 case kRandom: x = rand.nextRangeScalar(0, 768);
80 y = rand.nextRangeScalar(0, 768);
81 break;
82 }
83 SkAutoCanvasRestore ar(canvas, true/*save now*/);
84 canvas->clipRect(SkRect::MakeXYWH(x,y,256,256));
85 fPic->playback(canvas);
86 }
87 }
88 }
89
90private:
91 BBH fBBH;
92 Mode fMode;
93 SkString fName;
95};
96
97DEF_BENCH( return new TiledPlaybackBench(kNone, kRandom); )
98DEF_BENCH( return new TiledPlaybackBench(kNone, kTiled ); )
99DEF_BENCH( return new TiledPlaybackBench(kRTree, kRandom); )
100DEF_BENCH( return new TiledPlaybackBench(kRTree, kTiled ); )
#define DEF_BENCH(code)
Definition: Benchmark.h:20
void drawRect(const SkRect &rect, const SkPaint &paint)
Definition: SkCanvas.cpp:1673
void clipRect(const SkRect &rect, SkClipOp op, bool doAntiAlias)
Definition: SkCanvas.cpp:1361
SkCanvas * beginRecording(const SkRect &bounds, sk_sp< SkBBoxHierarchy > bbh)
sk_sp< SkPicture > finishRecordingAsPicture()
virtual void playback(SkCanvas *canvas, AbortCallback *callback=nullptr) const =0
uint32_t nextU()
Definition: SkRandom.h:42
SkScalar nextRangeScalar(SkScalar min, SkScalar max)
Definition: SkRandom.h:106
uint32_t nextULessThan(uint32_t count)
Definition: SkRandom.h:93
void append(const char text[])
Definition: SkString.h:203
const char * c_str() const
Definition: SkString.h:133
void onDelayedSetup() override
const char * onGetName() override
void onDraw(int loops, SkCanvas *canvas) override
SkISize onGetSize() override
TiledPlaybackBench(BBH bbh, Mode mode)
const Paint & paint
Definition: color_source.cc:38
float SkScalar
Definition: extension.cpp:12
double y
double x
it will be possible to load the file into Perfetto s trace viewer disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive mode
Definition: switches.h:228
SkScalar w
SkScalar h
Definition: SkSize.h:16
static constexpr SkISize Make(int32_t w, int32_t h)
Definition: SkSize.h:20
static constexpr SkRect MakeXYWH(float x, float y, float w, float h)
Definition: SkRect.h:659