2012-02-23 20:57:09 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2011 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
2020-08-03 17:21:46 +00:00
|
|
|
#include <memory>
|
|
|
|
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "bench/Benchmark.h"
|
|
|
|
#include "include/core/SkCanvas.h"
|
|
|
|
#include "include/core/SkColor.h"
|
|
|
|
#include "include/core/SkPaint.h"
|
|
|
|
#include "include/core/SkPicture.h"
|
|
|
|
#include "include/core/SkPictureRecorder.h"
|
|
|
|
#include "include/core/SkPoint.h"
|
|
|
|
#include "include/core/SkRect.h"
|
|
|
|
#include "include/core/SkString.h"
|
|
|
|
#include "include/utils/SkRandom.h"
|
2012-02-23 20:57:09 +00:00
|
|
|
|
|
|
|
// This is designed to emulate about 4 screens of textual content
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2014-11-11 18:39:27 +00:00
|
|
|
// Chrome draws into small tiles with impl-side painting.
|
|
|
|
// This benchmark measures the relative performance of our bounding-box hierarchies,
|
|
|
|
// both when querying tiles perfectly and when not.
|
2015-01-09 14:41:48 +00:00
|
|
|
enum BBH { kNone, kRTree };
|
2014-11-11 18:39:27 +00:00
|
|
|
enum Mode { kTiled, kRandom };
|
|
|
|
class TiledPlaybackBench : public Benchmark {
|
|
|
|
public:
|
|
|
|
TiledPlaybackBench(BBH bbh, Mode mode) : fBBH(bbh), fMode(mode), fName("tiled_playback") {
|
|
|
|
switch (fBBH) {
|
|
|
|
case kNone: fName.append("_none" ); break;
|
|
|
|
case kRTree: fName.append("_rtree" ); break;
|
|
|
|
}
|
|
|
|
switch (fMode) {
|
|
|
|
case kTiled: fName.append("_tiled" ); break;
|
|
|
|
case kRandom: fName.append("_random"); break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
const char* onGetName() override { return fName.c_str(); }
|
|
|
|
SkIPoint onGetSize() override { return SkIPoint::Make(1024,1024); }
|
2014-11-11 18:39:27 +00:00
|
|
|
|
2015-09-30 19:11:07 +00:00
|
|
|
void onDelayedSetup() override {
|
2016-11-03 18:40:50 +00:00
|
|
|
std::unique_ptr<SkBBHFactory> factory;
|
2014-11-11 18:39:27 +00:00
|
|
|
switch (fBBH) {
|
2020-08-03 17:21:46 +00:00
|
|
|
case kNone: break;
|
|
|
|
case kRTree: factory = std::make_unique<SkRTreeFactory>(); break;
|
2014-11-11 18:39:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
SkPictureRecorder recorder;
|
2016-11-03 18:40:50 +00:00
|
|
|
SkCanvas* canvas = recorder.beginRecording(1024, 1024, factory.get());
|
2014-11-11 18:39:27 +00:00
|
|
|
SkRandom rand;
|
|
|
|
for (int i = 0; i < 10000; i++) {
|
|
|
|
SkScalar x = rand.nextRangeScalar(0, 1024),
|
|
|
|
y = rand.nextRangeScalar(0, 1024),
|
|
|
|
w = rand.nextRangeScalar(0, 128),
|
|
|
|
h = rand.nextRangeScalar(0, 128);
|
|
|
|
SkPaint paint;
|
|
|
|
paint.setColor(rand.nextU());
|
|
|
|
paint.setAlpha(0xFF);
|
|
|
|
canvas->drawRect(SkRect::MakeXYWH(x,y,w,h), paint);
|
|
|
|
}
|
2016-03-18 14:25:55 +00:00
|
|
|
fPic = recorder.finishRecordingAsPicture();
|
2014-11-11 18:39:27 +00:00
|
|
|
}
|
|
|
|
|
2015-10-01 16:43:39 +00:00
|
|
|
void onDraw(int loops, SkCanvas* canvas) override {
|
2014-11-11 18:39:27 +00:00
|
|
|
for (int i = 0; i < loops; i++) {
|
|
|
|
// This inner loop guarantees we make the same choices for all bench variants.
|
|
|
|
SkRandom rand;
|
|
|
|
for (int j = 0; j < 10; j++) {
|
|
|
|
SkScalar x = 0, y = 0;
|
|
|
|
switch (fMode) {
|
|
|
|
case kTiled: x = SkScalar(256 * rand.nextULessThan(4));
|
|
|
|
y = SkScalar(256 * rand.nextULessThan(4));
|
|
|
|
break;
|
|
|
|
case kRandom: x = rand.nextRangeScalar(0, 768);
|
|
|
|
y = rand.nextRangeScalar(0, 768);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
SkAutoCanvasRestore ar(canvas, true/*save now*/);
|
|
|
|
canvas->clipRect(SkRect::MakeXYWH(x,y,256,256));
|
|
|
|
fPic->playback(canvas);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2016-03-18 14:25:55 +00:00
|
|
|
BBH fBBH;
|
|
|
|
Mode fMode;
|
|
|
|
SkString fName;
|
|
|
|
sk_sp<SkPicture> fPic;
|
2014-11-11 18:39:27 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
DEF_BENCH( return new TiledPlaybackBench(kNone, kRandom); )
|
|
|
|
DEF_BENCH( return new TiledPlaybackBench(kNone, kTiled ); )
|
|
|
|
DEF_BENCH( return new TiledPlaybackBench(kRTree, kRandom); )
|
|
|
|
DEF_BENCH( return new TiledPlaybackBench(kRTree, kTiled ); )
|