skia2/bench/CreateBackendTextureBench.cpp
Robert Phillips f0288101b5 Remove SkCanvas::getGrContext calls from benches
This will get us closer to deprecating getGrContext.

The benches have no SkSurface::getContext calls.

TBR=bsalomon@google.com
Change-Id: I6496a6324091a75d2829bd7ee20bdbe0dc3b6fe9
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/300654
Reviewed-by: Adlai Holler <adlai@google.com>
Reviewed-by: Brian Salomon <bsalomon@google.com>
Commit-Queue: Robert Phillips <robertphillips@google.com>
2020-07-08 14:55:57 +00:00

58 lines
1.8 KiB
C++

/*
* Copyright 2020 Google LLC
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include "bench/Benchmark.h"
#include "include/core/SkCanvas.h"
#include "include/gpu/GrDirectContext.h"
class CreateBackendTextureBench : public Benchmark {
private:
SkString fName;
SkTArray<GrBackendTexture> fBackendTextures;
GrMipMapped fMipMapped;
public:
CreateBackendTextureBench(GrMipMapped mipMapped) : fMipMapped(mipMapped) {
fName.printf("create_backend_texture%s", mipMapped == GrMipMapped::kYes ? "_mipped" : "");
}
private:
bool isSuitableFor(Backend backend) override { return kGPU_Backend == backend; }
const char* onGetName() override { return fName.c_str(); }
void onDraw(int loops, SkCanvas* canvas) override {
auto context = canvas->recordingContext()->asDirectContext();
fBackendTextures.reserve(loops);
static const int kSize = 16;
for (int i = 0; i < loops; ++i) {
fBackendTextures.push_back(context->createBackendTexture(
kSize, kSize, kRGBA_8888_SkColorType, SkColors::kRed, fMipMapped,
GrRenderable::kNo, GrProtected::kNo));
}
}
void onPerCanvasPostDraw(SkCanvas* canvas) override {
auto context = canvas->recordingContext()->asDirectContext();
context->flush();
context->submit(true);
for (int i = 0; i < fBackendTextures.count(); ++i) {
if (fBackendTextures[i].isValid()) {
context->deleteBackendTexture(fBackendTextures[i]);
}
}
fBackendTextures.reset();
}
};
DEF_BENCH(return new CreateBackendTextureBench(GrMipMapped::kNo);)
DEF_BENCH(return new CreateBackendTextureBench(GrMipMapped::kYes);)