Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
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
#define DEF_BENCH(code)
Definition Benchmark.h:20
void drawRect(const SkRect &rect, const SkPaint &paint)
void clipRect(const SkRect &rect, SkClipOp op, bool doAntiAlias)
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
float SkScalar
Definition extension.cpp:12
double y
double x
SkScalar w
SkScalar h
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