2020-05-04 20:47:15 +00:00
|
|
|
/*
|
|
|
|
* 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"
|
2020-07-06 17:45:34 +00:00
|
|
|
#include "include/gpu/GrDirectContext.h"
|
2020-05-04 20:47:15 +00:00
|
|
|
|
|
|
|
class CreateBackendTextureBench : public Benchmark {
|
|
|
|
private:
|
|
|
|
SkString fName;
|
|
|
|
SkTArray<GrBackendTexture> fBackendTextures;
|
2020-07-21 14:32:07 +00:00
|
|
|
GrMipmapped fMipmapped;
|
2020-05-04 20:47:15 +00:00
|
|
|
|
|
|
|
public:
|
2020-07-21 14:32:07 +00:00
|
|
|
CreateBackendTextureBench(GrMipmapped mipMapped) : fMipmapped(mipMapped) {
|
2020-07-21 13:27:25 +00:00
|
|
|
fName.printf("create_backend_texture%s", mipMapped == GrMipmapped::kYes ? "_mipped" : "");
|
2020-05-04 20:47:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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 {
|
2020-07-06 17:45:34 +00:00
|
|
|
auto context = canvas->recordingContext()->asDirectContext();
|
2020-05-04 20:47:15 +00:00
|
|
|
|
2020-10-14 20:57:41 +00:00
|
|
|
fBackendTextures.reserve_back(loops);
|
2020-05-04 20:47:15 +00:00
|
|
|
|
|
|
|
static const int kSize = 16;
|
|
|
|
for (int i = 0; i < loops; ++i) {
|
|
|
|
fBackendTextures.push_back(context->createBackendTexture(
|
2020-07-21 14:32:07 +00:00
|
|
|
kSize, kSize, kRGBA_8888_SkColorType, SkColors::kRed, fMipmapped,
|
2020-05-04 20:47:15 +00:00
|
|
|
GrRenderable::kNo, GrProtected::kNo));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void onPerCanvasPostDraw(SkCanvas* canvas) override {
|
2020-07-06 17:45:34 +00:00
|
|
|
auto context = canvas->recordingContext()->asDirectContext();
|
2020-05-04 20:47:15 +00:00
|
|
|
|
2020-06-30 17:42:46 +00:00
|
|
|
context->flush();
|
2020-05-14 19:45:44 +00:00
|
|
|
context->submit(true);
|
2020-05-04 20:47:15 +00:00
|
|
|
|
|
|
|
for (int i = 0; i < fBackendTextures.count(); ++i) {
|
|
|
|
if (fBackendTextures[i].isValid()) {
|
|
|
|
context->deleteBackendTexture(fBackendTextures[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fBackendTextures.reset();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2020-07-21 13:27:25 +00:00
|
|
|
DEF_BENCH(return new CreateBackendTextureBench(GrMipmapped::kNo);)
|
|
|
|
DEF_BENCH(return new CreateBackendTextureBench(GrMipmapped::kYes);)
|