2019-09-12 15:17:16 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2019 Google LLC
|
|
|
|
*
|
|
|
|
* 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-09-12 15:17:16 +00:00
|
|
|
#include "bench/Benchmark.h"
|
|
|
|
|
2020-03-30 19:57:14 +00:00
|
|
|
#include "include/core/SkCanvas.h"
|
2019-09-12 15:17:16 +00:00
|
|
|
#include "include/core/SkDeferredDisplayListRecorder.h"
|
|
|
|
#include "include/core/SkSurfaceCharacterization.h"
|
2020-07-06 17:45:34 +00:00
|
|
|
#include "include/gpu/GrDirectContext.h"
|
2019-09-12 15:17:16 +00:00
|
|
|
|
2020-07-06 17:45:34 +00:00
|
|
|
static SkSurfaceCharacterization create_characterization(GrDirectContext* direct) {
|
|
|
|
size_t maxResourceBytes = direct->getResourceCacheLimit();
|
2019-09-12 15:17:16 +00:00
|
|
|
|
2020-07-06 17:45:34 +00:00
|
|
|
if (!direct->colorTypeSupportedAsSurface(kRGBA_8888_SkColorType)) {
|
2019-09-12 15:17:16 +00:00
|
|
|
return SkSurfaceCharacterization();
|
|
|
|
}
|
|
|
|
|
|
|
|
SkImageInfo ii = SkImageInfo::Make(32, 32, kRGBA_8888_SkColorType,
|
|
|
|
kPremul_SkAlphaType, nullptr);
|
|
|
|
|
2020-07-06 17:45:34 +00:00
|
|
|
GrBackendFormat backendFormat = direct->defaultBackendFormat(kRGBA_8888_SkColorType,
|
|
|
|
GrRenderable::kYes);
|
2019-09-12 15:17:16 +00:00
|
|
|
if (!backendFormat.isValid()) {
|
|
|
|
return SkSurfaceCharacterization();
|
|
|
|
}
|
|
|
|
|
|
|
|
SkSurfaceProps props(0x0, kUnknown_SkPixelGeometry);
|
|
|
|
|
2020-07-06 17:45:34 +00:00
|
|
|
SkSurfaceCharacterization c = direct->threadSafeProxy()->createCharacterization(
|
2019-09-12 15:17:16 +00:00
|
|
|
maxResourceBytes, ii, backendFormat, 1,
|
|
|
|
kTopLeft_GrSurfaceOrigin, props, false);
|
|
|
|
return c;
|
|
|
|
}
|
|
|
|
|
|
|
|
// This benchmark tries to simulate how Viz is using SkDDLRecorders.
|
|
|
|
// For each config it will create a single DDLRecorder which it reuses for all the runs
|
|
|
|
// For each run it creates a DDL and stores it for later deletion.
|
|
|
|
class DDLRecorderBench : public Benchmark {
|
|
|
|
public:
|
|
|
|
DDLRecorderBench() { }
|
|
|
|
|
|
|
|
protected:
|
2020-07-06 17:45:34 +00:00
|
|
|
bool isSuitableFor(Backend backend) override { return kGPU_Backend == backend; }
|
|
|
|
|
2019-09-12 15:17:16 +00:00
|
|
|
const char* onGetName() override { return "DDLRecorder"; }
|
|
|
|
|
|
|
|
void onDraw(int loops, SkCanvas* origCanvas) override {
|
|
|
|
if (!fRecorder) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
SkASSERT(!fDDLs.size());
|
|
|
|
fDDLs.reserve(loops);
|
|
|
|
|
|
|
|
for (int i = 0; i < loops; ++i) {
|
|
|
|
SkCanvas* recordingCanvas = fRecorder->getCanvas();
|
|
|
|
|
|
|
|
recordingCanvas->drawRect(SkRect::MakeWH(32, 32), SkPaint());
|
|
|
|
|
|
|
|
fDDLs.emplace_back(fRecorder->detach());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
// We create one DDLRecorder for all the timing runs and just keep reusing it
|
|
|
|
void onPerCanvasPreDraw(SkCanvas* origCanvas) override {
|
2020-07-06 17:45:34 +00:00
|
|
|
auto context = origCanvas->recordingContext()->asDirectContext();
|
2019-09-12 15:17:16 +00:00
|
|
|
if (!context) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
SkSurfaceCharacterization c = create_characterization(context);
|
|
|
|
|
2020-08-03 17:21:46 +00:00
|
|
|
fRecorder = std::make_unique<SkDeferredDisplayListRecorder>(c);
|
2019-09-12 15:17:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// We defer the clean up of the DDLs so it is done outside of the timing loop
|
|
|
|
void onPostDraw(SkCanvas*) override {
|
|
|
|
fDDLs.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
std::unique_ptr<SkDeferredDisplayListRecorder> fRecorder = nullptr;
|
2020-06-29 14:00:08 +00:00
|
|
|
std::vector<sk_sp<SkDeferredDisplayList>> fDDLs;
|
2019-09-12 15:17:16 +00:00
|
|
|
|
|
|
|
typedef Benchmark INHERITED;
|
|
|
|
};
|
|
|
|
|
|
|
|
DEF_BENCH(return new DDLRecorderBench();)
|