Flutter Engine
The Flutter Engine
CreateBackendTextureBench.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2020 Google LLC
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8#include "bench/Benchmark.h"
12
13using namespace skia_private;
14
16private:
17 SkString fName;
18 TArray<GrBackendTexture> fBackendTextures;
19 skgpu::Mipmapped fMipmapped;
20
21public:
22 CreateBackendTextureBench(skgpu::Mipmapped mipmapped) : fMipmapped(mipmapped) {
23 fName.printf("create_backend_texture%s",
24 mipmapped == skgpu::Mipmapped::kYes ? "_mipped" : "");
25 }
26
27private:
28 bool isSuitableFor(Backend backend) override { return Backend::kGanesh == backend; }
29
30 const char* onGetName() override { return fName.c_str(); }
31
32 void onDraw(int loops, SkCanvas* canvas) override {
33 auto context = canvas->recordingContext()->asDirectContext();
34
35 fBackendTextures.reserve_exact(fBackendTextures.size() + loops);
36
37 static const int kSize = 16;
38 for (int i = 0; i < loops; ++i) {
39 fBackendTextures.push_back(
40 context->createBackendTexture(kSize,
41 kSize,
44 fMipmapped,
47 nullptr,
48 nullptr,
49 /*label=*/"DrawBackendTextureBench"));
50 }
51 }
52
53 void onPerCanvasPostDraw(SkCanvas* canvas) override {
54 auto context = canvas->recordingContext()->asDirectContext();
55
56 context->flush();
57 context->submit(GrSyncCpu::kYes);
58
59 for (int i = 0; i < fBackendTextures.size(); ++i) {
60 if (fBackendTextures[i].isValid()) {
61 context->deleteBackendTexture(fBackendTextures[i]);
62 }
63 }
64 fBackendTextures.clear();
65 }
66};
67
#define DEF_BENCH(code)
Definition: Benchmark.h:20
const char * backend
const char * fName
@ kRGBA_8888_SkColorType
pixel with 8 bits for red, green, blue, alpha; in 32-bit word
Definition: SkColorType.h:24
CreateBackendTextureBench(skgpu::Mipmapped mipmapped)
virtual GrDirectContext * asDirectContext()
GrSemaphoresSubmitted flush(const GrFlushInfo &info)
virtual GrRecordingContext * recordingContext() const
Definition: SkCanvas.cpp:1637
int size() const
Definition: SkTArray.h:421
void reserve_exact(int n)
Definition: SkTArray.h:181
constexpr int kSize
constexpr SkColor4f kRed
Definition: SkColor.h:440
Mipmapped
Definition: GpuTypes.h:53