robertphillips@google.com | 6806bda | 2012-09-04 13:39:01 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2012 The Android Open Source Project |
| 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 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 8 | #include "bench/Benchmark.h" |
| 9 | #include "include/core/SkBitmap.h" |
| 10 | #include "include/core/SkCanvas.h" |
| 11 | #include "include/core/SkColorSpace.h" |
robertphillips@google.com | 6806bda | 2012-09-04 13:39:01 +0000 | [diff] [blame] | 12 | |
Mike Reed | af990f3 | 2019-03-21 15:55:05 -0400 | [diff] [blame] | 13 | // Time variants of read-pixels |
| 14 | // [ colortype ][ alphatype ][ colorspace ] |
| 15 | // Different combinations can trigger fast or slow paths in the impls |
| 16 | // |
tfarina | f168b86 | 2014-06-19 12:32:29 -0700 | [diff] [blame] | 17 | class ReadPixBench : public Benchmark { |
robertphillips@google.com | 6806bda | 2012-09-04 13:39:01 +0000 | [diff] [blame] | 18 | public: |
Mike Reed | af990f3 | 2019-03-21 15:55:05 -0400 | [diff] [blame] | 19 | ReadPixBench(SkColorType ct, SkAlphaType at, sk_sp<SkColorSpace> cs) |
| 20 | : fCT(ct), fAT(at), fCS(cs) |
| 21 | { |
| 22 | fName.printf("readpix_%s_%s_%s", |
| 23 | at == kPremul_SkAlphaType ? "pm" : "um", |
| 24 | ct == kRGBA_8888_SkColorType ? "rgba" : "bgra", |
| 25 | cs ? "srgb" : "null"); |
| 26 | } |
robertphillips@google.com | 6806bda | 2012-09-04 13:39:01 +0000 | [diff] [blame] | 27 | |
| 28 | protected: |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 29 | const char* onGetName() override { |
Mike Reed | af990f3 | 2019-03-21 15:55:05 -0400 | [diff] [blame] | 30 | return fName.c_str(); |
robertphillips@google.com | 6806bda | 2012-09-04 13:39:01 +0000 | [diff] [blame] | 31 | } |
| 32 | |
mtklein | a1ebeb2 | 2015-10-01 09:43:39 -0700 | [diff] [blame] | 33 | void onDraw(int loops, SkCanvas* canvas) override { |
Mike Reed | af990f3 | 2019-03-21 15:55:05 -0400 | [diff] [blame] | 34 | canvas->clear(0x80000000); |
robertphillips@google.com | 6806bda | 2012-09-04 13:39:01 +0000 | [diff] [blame] | 35 | |
Mike Reed | 3661bc9 | 2017-02-22 13:21:42 -0500 | [diff] [blame] | 36 | SkISize size = canvas->getBaseLayerSize(); |
robertphillips@google.com | 6806bda | 2012-09-04 13:39:01 +0000 | [diff] [blame] | 37 | |
Brian Salomon | 4bc0c1f | 2019-09-30 15:12:27 -0400 | [diff] [blame] | 38 | auto info = SkImageInfo::Make(size, fCT, fAT, fCS); |
robertphillips@google.com | 6806bda | 2012-09-04 13:39:01 +0000 | [diff] [blame] | 39 | SkBitmap bitmap; |
Mike Reed | af990f3 | 2019-03-21 15:55:05 -0400 | [diff] [blame] | 40 | bitmap.allocPixels(info); |
robertphillips@google.com | 6806bda | 2012-09-04 13:39:01 +0000 | [diff] [blame] | 41 | |
commit-bot@chromium.org | 3361471 | 2013-12-03 18:17:16 +0000 | [diff] [blame] | 42 | for (int i = 0; i < loops; i++) { |
Mike Reed | af990f3 | 2019-03-21 15:55:05 -0400 | [diff] [blame] | 43 | canvas->readPixels(bitmap.info(), bitmap.getPixels(), bitmap.rowBytes(), 0, 0); |
robertphillips@google.com | 6806bda | 2012-09-04 13:39:01 +0000 | [diff] [blame] | 44 | } |
| 45 | } |
| 46 | |
| 47 | private: |
Mike Reed | af990f3 | 2019-03-21 15:55:05 -0400 | [diff] [blame] | 48 | SkColorType fCT; |
| 49 | SkAlphaType fAT; |
| 50 | sk_sp<SkColorSpace> fCS; |
| 51 | SkString fName; |
John Stiles | 7571f9e | 2020-09-02 22:42:33 -0400 | [diff] [blame] | 52 | using INHERITED = Benchmark; |
robertphillips@google.com | 6806bda | 2012-09-04 13:39:01 +0000 | [diff] [blame] | 53 | }; |
Mike Reed | af990f3 | 2019-03-21 15:55:05 -0400 | [diff] [blame] | 54 | DEF_BENCH( return new ReadPixBench(kRGBA_8888_SkColorType, kPremul_SkAlphaType, nullptr); ) |
| 55 | DEF_BENCH( return new ReadPixBench(kRGBA_8888_SkColorType, kUnpremul_SkAlphaType, nullptr); ) |
| 56 | DEF_BENCH( return new ReadPixBench(kRGBA_8888_SkColorType, kPremul_SkAlphaType, SkColorSpace::MakeSRGB()); ) |
| 57 | DEF_BENCH( return new ReadPixBench(kRGBA_8888_SkColorType, kUnpremul_SkAlphaType, SkColorSpace::MakeSRGB()); ) |
| 58 | |
| 59 | DEF_BENCH( return new ReadPixBench(kBGRA_8888_SkColorType, kPremul_SkAlphaType, nullptr); ) |
| 60 | DEF_BENCH( return new ReadPixBench(kBGRA_8888_SkColorType, kUnpremul_SkAlphaType, nullptr); ) |
| 61 | DEF_BENCH( return new ReadPixBench(kBGRA_8888_SkColorType, kPremul_SkAlphaType, SkColorSpace::MakeSRGB()); ) |
| 62 | DEF_BENCH( return new ReadPixBench(kBGRA_8888_SkColorType, kUnpremul_SkAlphaType, SkColorSpace::MakeSRGB()); ) |
robertphillips@google.com | 6806bda | 2012-09-04 13:39:01 +0000 | [diff] [blame] | 63 | |
| 64 | //////////////////////////////////////////////////////////////////////////////// |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 65 | #include "include/core/SkBitmap.h" |
| 66 | #include "src/core/SkPixmapPriv.h" |
robertphillips@google.com | 6806bda | 2012-09-04 13:39:01 +0000 | [diff] [blame] | 67 | |
Mike Reed | 7306bcd | 2017-10-25 10:37:30 -0400 | [diff] [blame] | 68 | class PixmapOrientBench : public Benchmark { |
| 69 | public: |
| 70 | PixmapOrientBench() {} |
| 71 | |
| 72 | protected: |
| 73 | void onDelayedSetup() override { |
| 74 | const SkImageInfo info = SkImageInfo::MakeN32Premul(2048, 1024); |
| 75 | fSrc.allocPixels(info); |
| 76 | fSrc.eraseColor(SK_ColorBLACK); |
Brian Salomon | 9241a6d | 2019-10-03 13:26:54 -0400 | [diff] [blame] | 77 | fDst.allocPixels(info.makeDimensions(info.dimensions())); |
Mike Reed | 7306bcd | 2017-10-25 10:37:30 -0400 | [diff] [blame] | 78 | } |
| 79 | |
| 80 | const char* onGetName() override { |
| 81 | return "orient_pixmap"; |
| 82 | } |
| 83 | |
| 84 | bool isSuitableFor(Backend backend) override { |
| 85 | return backend == kNonRendering_Backend; |
| 86 | } |
| 87 | |
| 88 | void onDraw(int loops, SkCanvas*) override { |
Mike Reed | 7306bcd | 2017-10-25 10:37:30 -0400 | [diff] [blame] | 89 | SkPixmap src, dst; |
| 90 | fSrc.peekPixels(&src); |
| 91 | fDst.peekPixels(&dst); |
| 92 | for (int i = 0; i < loops; ++i) { |
Brian Osman | c337a63 | 2018-11-30 10:39:32 -0500 | [diff] [blame] | 93 | SkPixmapPriv::Orient(dst, src, kTopRight_SkEncodedOrigin); |
Mike Reed | 7306bcd | 2017-10-25 10:37:30 -0400 | [diff] [blame] | 94 | } |
| 95 | } |
| 96 | |
| 97 | private: |
| 98 | SkBitmap fSrc, fDst; |
| 99 | |
John Stiles | 7571f9e | 2020-09-02 22:42:33 -0400 | [diff] [blame] | 100 | using INHERITED = Benchmark; |
Mike Reed | 7306bcd | 2017-10-25 10:37:30 -0400 | [diff] [blame] | 101 | }; |
| 102 | DEF_BENCH( return new PixmapOrientBench(); ) |
Mike Reed | c25f440 | 2018-09-20 15:00:56 -0400 | [diff] [blame] | 103 | |
| 104 | |
| 105 | class GetAlphafBench : public Benchmark { |
| 106 | SkString fName; |
| 107 | SkColorType fCT; |
| 108 | public: |
| 109 | GetAlphafBench(SkColorType ct, const char label[]) : fCT(ct) { |
| 110 | fName.printf("getalphaf_%s", label); |
| 111 | } |
| 112 | |
| 113 | protected: |
| 114 | void onDelayedSetup() override { |
| 115 | fBM.allocPixels(SkImageInfo::Make(1024, 1024, fCT, kPremul_SkAlphaType)); |
| 116 | fBM.eraseColor(0x88112233); |
| 117 | } |
| 118 | |
| 119 | const char* onGetName() override { |
| 120 | return fName.c_str(); |
| 121 | } |
| 122 | |
| 123 | bool isSuitableFor(Backend backend) override { |
| 124 | return backend == kNonRendering_Backend; |
| 125 | } |
| 126 | |
| 127 | void onDraw(int loops, SkCanvas*) override { |
| 128 | for (int i = 0; i < loops; ++i) { |
| 129 | for (int y = 0; y < fBM.height(); ++y) { |
| 130 | for (int x = 0; x < fBM.width(); ++x) { |
| 131 | fBM.getAlphaf(x, y); |
| 132 | } |
| 133 | } |
| 134 | } |
| 135 | } |
| 136 | |
| 137 | private: |
| 138 | SkBitmap fBM; |
| 139 | |
John Stiles | 7571f9e | 2020-09-02 22:42:33 -0400 | [diff] [blame] | 140 | using INHERITED = Benchmark; |
Mike Reed | c25f440 | 2018-09-20 15:00:56 -0400 | [diff] [blame] | 141 | }; |
| 142 | DEF_BENCH( return new GetAlphafBench(kN32_SkColorType, "rgba"); ) |
| 143 | DEF_BENCH( return new GetAlphafBench(kRGB_888x_SkColorType, "rgbx"); ) |
| 144 | DEF_BENCH( return new GetAlphafBench(kRGBA_F16_SkColorType, "f16"); ) |
| 145 | DEF_BENCH( return new GetAlphafBench(kRGBA_F32_SkColorType, "f32"); ) |
| 146 | |