fbd050bd0b
The majority of existing call sites were automatically updated using clang-tidy -fix. A small handful required a manual update, e.g. CppCodeGen. This check is a bit lenient, and in particular will not flag cases like `std::unique_ptr<Base>(new Derived())` which is still pretty common throughout our codebase. This CL does not attempt to replace all the cases that ClangTidy does not flag. Change-Id: I5eba48ef880e25d22de80f321a68c389ba769e36 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/307459 Commit-Queue: John Stiles <johnstiles@google.com> Reviewed-by: Mike Klein <mtklein@google.com>
95 lines
3.0 KiB
C++
95 lines
3.0 KiB
C++
/*
|
|
* Copyright 2019 Google LLC
|
|
*
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
* found in the LICENSE file.
|
|
*/
|
|
|
|
#include <memory>
|
|
|
|
#include "bench/Benchmark.h"
|
|
|
|
#include "include/core/SkCanvas.h"
|
|
#include "include/core/SkDeferredDisplayListRecorder.h"
|
|
#include "include/core/SkSurfaceCharacterization.h"
|
|
#include "include/gpu/GrDirectContext.h"
|
|
|
|
static SkSurfaceCharacterization create_characterization(GrDirectContext* direct) {
|
|
size_t maxResourceBytes = direct->getResourceCacheLimit();
|
|
|
|
if (!direct->colorTypeSupportedAsSurface(kRGBA_8888_SkColorType)) {
|
|
return SkSurfaceCharacterization();
|
|
}
|
|
|
|
SkImageInfo ii = SkImageInfo::Make(32, 32, kRGBA_8888_SkColorType,
|
|
kPremul_SkAlphaType, nullptr);
|
|
|
|
GrBackendFormat backendFormat = direct->defaultBackendFormat(kRGBA_8888_SkColorType,
|
|
GrRenderable::kYes);
|
|
if (!backendFormat.isValid()) {
|
|
return SkSurfaceCharacterization();
|
|
}
|
|
|
|
SkSurfaceProps props(0x0, kUnknown_SkPixelGeometry);
|
|
|
|
SkSurfaceCharacterization c = direct->threadSafeProxy()->createCharacterization(
|
|
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:
|
|
bool isSuitableFor(Backend backend) override { return kGPU_Backend == backend; }
|
|
|
|
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 {
|
|
auto context = origCanvas->recordingContext()->asDirectContext();
|
|
if (!context) {
|
|
return;
|
|
}
|
|
|
|
SkSurfaceCharacterization c = create_characterization(context);
|
|
|
|
fRecorder = std::make_unique<SkDeferredDisplayListRecorder>(c);
|
|
}
|
|
|
|
// 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;
|
|
std::vector<sk_sp<SkDeferredDisplayList>> fDDLs;
|
|
|
|
typedef Benchmark INHERITED;
|
|
};
|
|
|
|
DEF_BENCH(return new DDLRecorderBench();)
|