• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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"
9 #include "include/core/SkCanvas.h"
10 #include "include/gpu/GrDirectContext.h"
11 
12 class CreateBackendTextureBench : public Benchmark {
13 private:
14     SkString fName;
15     SkTArray<GrBackendTexture> fBackendTextures;
16     GrMipmapped fMipmapped;
17 
18 public:
CreateBackendTextureBench(GrMipmapped mipMapped)19     CreateBackendTextureBench(GrMipmapped mipMapped) : fMipmapped(mipMapped) {
20         fName.printf("create_backend_texture%s", mipMapped == GrMipmapped::kYes ? "_mipped" : "");
21     }
22 
23 private:
isSuitableFor(Backend backend)24     bool isSuitableFor(Backend backend) override { return kGPU_Backend == backend; }
25 
onGetName()26     const char* onGetName() override { return fName.c_str(); }
27 
onDraw(int loops,SkCanvas * canvas)28     void onDraw(int loops, SkCanvas* canvas) override {
29         auto context = canvas->recordingContext()->asDirectContext();
30 
31         fBackendTextures.reserve_back(loops);
32 
33         static const int kSize = 16;
34         for (int i = 0; i < loops; ++i) {
35             fBackendTextures.push_back(context->createBackendTexture(
36                     kSize, kSize, kRGBA_8888_SkColorType, SkColors::kRed, fMipmapped,
37                     GrRenderable::kNo, GrProtected::kNo));
38         }
39     }
40 
onPerCanvasPostDraw(SkCanvas * canvas)41     void onPerCanvasPostDraw(SkCanvas* canvas) override {
42         auto context = canvas->recordingContext()->asDirectContext();
43 
44         context->flush();
45         context->submit(true);
46 
47         for (int i = 0; i < fBackendTextures.count(); ++i) {
48             if (fBackendTextures[i].isValid()) {
49                 context->deleteBackendTexture(fBackendTextures[i]);
50             }
51         }
52         fBackendTextures.reset();
53     }
54 };
55 
56 DEF_BENCH(return new CreateBackendTextureBench(GrMipmapped::kNo);)
57 DEF_BENCH(return new CreateBackendTextureBench(GrMipmapped::kYes);)
58