Greg Daniel | 6d2febd | 2020-05-04 16:47:15 -0400 | [diff] [blame] | 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" |
Robert Phillips | f028810 | 2020-07-06 13:45:34 -0400 | [diff] [blame] | 10 | #include "include/gpu/GrDirectContext.h" |
Greg Daniel | 6d2febd | 2020-05-04 16:47:15 -0400 | [diff] [blame] | 11 | |
| 12 | class CreateBackendTextureBench : public Benchmark { |
| 13 | private: |
| 14 | SkString fName; |
| 15 | SkTArray<GrBackendTexture> fBackendTextures; |
Brian Salomon | 40a4062 | 2020-07-21 10:32:07 -0400 | [diff] [blame] | 16 | GrMipmapped fMipmapped; |
Greg Daniel | 6d2febd | 2020-05-04 16:47:15 -0400 | [diff] [blame] | 17 | |
| 18 | public: |
Brian Salomon | 40a4062 | 2020-07-21 10:32:07 -0400 | [diff] [blame] | 19 | CreateBackendTextureBench(GrMipmapped mipMapped) : fMipmapped(mipMapped) { |
Brian Salomon | 7e67dca | 2020-07-21 09:27:25 -0400 | [diff] [blame] | 20 | fName.printf("create_backend_texture%s", mipMapped == GrMipmapped::kYes ? "_mipped" : ""); |
Greg Daniel | 6d2febd | 2020-05-04 16:47:15 -0400 | [diff] [blame] | 21 | } |
| 22 | |
| 23 | private: |
| 24 | bool isSuitableFor(Backend backend) override { return kGPU_Backend == backend; } |
| 25 | |
| 26 | const char* onGetName() override { return fName.c_str(); } |
| 27 | |
| 28 | void onDraw(int loops, SkCanvas* canvas) override { |
Robert Phillips | f028810 | 2020-07-06 13:45:34 -0400 | [diff] [blame] | 29 | auto context = canvas->recordingContext()->asDirectContext(); |
Greg Daniel | 6d2febd | 2020-05-04 16:47:15 -0400 | [diff] [blame] | 30 | |
John Stiles | f4bda74 | 2020-10-14 16:57:41 -0400 | [diff] [blame] | 31 | fBackendTextures.reserve_back(loops); |
Greg Daniel | 6d2febd | 2020-05-04 16:47:15 -0400 | [diff] [blame] | 32 | |
| 33 | static const int kSize = 16; |
| 34 | for (int i = 0; i < loops; ++i) { |
| 35 | fBackendTextures.push_back(context->createBackendTexture( |
Brian Salomon | 40a4062 | 2020-07-21 10:32:07 -0400 | [diff] [blame] | 36 | kSize, kSize, kRGBA_8888_SkColorType, SkColors::kRed, fMipmapped, |
Greg Daniel | 6d2febd | 2020-05-04 16:47:15 -0400 | [diff] [blame] | 37 | GrRenderable::kNo, GrProtected::kNo)); |
| 38 | } |
| 39 | } |
| 40 | |
| 41 | void onPerCanvasPostDraw(SkCanvas* canvas) override { |
Robert Phillips | f028810 | 2020-07-06 13:45:34 -0400 | [diff] [blame] | 42 | auto context = canvas->recordingContext()->asDirectContext(); |
Greg Daniel | 6d2febd | 2020-05-04 16:47:15 -0400 | [diff] [blame] | 43 | |
Greg Daniel | ce9f016 | 2020-06-30 13:42:46 -0400 | [diff] [blame] | 44 | context->flush(); |
Greg Daniel | 0a2464f | 2020-05-14 15:45:44 -0400 | [diff] [blame] | 45 | context->submit(true); |
Greg Daniel | 6d2febd | 2020-05-04 16:47:15 -0400 | [diff] [blame] | 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 | |
Brian Salomon | 7e67dca | 2020-07-21 09:27:25 -0400 | [diff] [blame] | 56 | DEF_BENCH(return new CreateBackendTextureBench(GrMipmapped::kNo);) |
| 57 | DEF_BENCH(return new CreateBackendTextureBench(GrMipmapped::kYes);) |