blob: 4a4303d40600c9feec950bd0cb403241b2a5ad44 [file] [log] [blame]
commit-bot@chromium.org8f426972013-08-16 00:40:34 +00001/*
2 * Copyright 2013 Google Inc.
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 Kleinc0bd9f92019-04-23 12:05:21 -05008#include "bench/Benchmark.h"
9#include "include/core/SkBitmap.h"
10#include "include/core/SkCanvas.h"
11#include "include/core/SkString.h"
commit-bot@chromium.org8f426972013-08-16 00:40:34 +000012
Mike Reedaf990f32019-03-21 15:55:05 -040013// Time variants of write-pixels
14// [ colortype ][ alphatype ][ colorspace ]
15// Different combinations can trigger fast or slow paths in the impls
16//
tfarinaf168b862014-06-19 12:32:29 -070017class WritePixelsBench : public Benchmark {
commit-bot@chromium.org8f426972013-08-16 00:40:34 +000018public:
Mike Reedaf990f32019-03-21 15:55:05 -040019 WritePixelsBench(SkColorType ct, SkAlphaType at, sk_sp<SkColorSpace> cs)
commit-bot@chromium.org4cd9e212014-03-07 03:25:16 +000020 : fColorType(ct)
21 , fAlphaType(at)
Mike Reedaf990f32019-03-21 15:55:05 -040022 , fCS(cs)
commit-bot@chromium.org4cd9e212014-03-07 03:25:16 +000023 {
Mike Reedaf990f32019-03-21 15:55:05 -040024 fName.printf("writepix_%s_%s_%s",
25 at == kPremul_SkAlphaType ? "pm" : "um",
26 ct == kRGBA_8888_SkColorType ? "rgba" : "bgra",
27 cs ? "srgb" : "null");
commit-bot@chromium.org8f426972013-08-16 00:40:34 +000028 }
29
30protected:
mtklein36352bf2015-03-25 18:17:31 -070031 const char* onGetName() override {
commit-bot@chromium.org8f426972013-08-16 00:40:34 +000032 return fName.c_str();
33 }
34
mtkleina1ebeb22015-10-01 09:43:39 -070035 void onDraw(int loops, SkCanvas* canvas) override {
Mike Reed3661bc92017-02-22 13:21:42 -050036 SkISize size = canvas->getBaseLayerSize();
commit-bot@chromium.org8f426972013-08-16 00:40:34 +000037
Brian Salomon4bc0c1f2019-09-30 15:12:27 -040038 SkImageInfo info = SkImageInfo::Make(size, fColorType, fAlphaType, fCS);
commit-bot@chromium.org8f426972013-08-16 00:40:34 +000039 SkBitmap bmp;
Mike Reedaf990f32019-03-21 15:55:05 -040040 bmp.allocPixels(info);
41 bmp.eraseColor(SK_ColorBLACK);
skia.committer@gmail.come62513f2014-03-08 03:02:06 +000042
commit-bot@chromium.org33614712013-12-03 18:17:16 +000043 for (int loop = 0; loop < loops; ++loop) {
commit-bot@chromium.org4cd9e212014-03-07 03:25:16 +000044 canvas->writePixels(info, bmp.getPixels(), bmp.rowBytes(), 0, 0);
commit-bot@chromium.org8f426972013-08-16 00:40:34 +000045 }
46 }
47
48private:
commit-bot@chromium.org4cd9e212014-03-07 03:25:16 +000049 SkColorType fColorType;
50 SkAlphaType fAlphaType;
Mike Reedaf990f32019-03-21 15:55:05 -040051 sk_sp<SkColorSpace> fCS;
commit-bot@chromium.org4cd9e212014-03-07 03:25:16 +000052 SkString fName;
commit-bot@chromium.org8f426972013-08-16 00:40:34 +000053
John Stiles7571f9e2020-09-02 22:42:33 -040054 using INHERITED = Benchmark;
commit-bot@chromium.org8f426972013-08-16 00:40:34 +000055};
56
57//////////////////////////////////////////////////////////////////////////////
58
Mike Reedaf990f32019-03-21 15:55:05 -040059DEF_BENCH(return new WritePixelsBench(kRGBA_8888_SkColorType, kPremul_SkAlphaType, nullptr);)
60DEF_BENCH(return new WritePixelsBench(kRGBA_8888_SkColorType, kUnpremul_SkAlphaType, nullptr);)
61DEF_BENCH(return new WritePixelsBench(kRGBA_8888_SkColorType, kPremul_SkAlphaType, SkColorSpace::MakeSRGB());)
62DEF_BENCH(return new WritePixelsBench(kRGBA_8888_SkColorType, kUnpremul_SkAlphaType, SkColorSpace::MakeSRGB());)
63
64DEF_BENCH(return new WritePixelsBench(kBGRA_8888_SkColorType, kPremul_SkAlphaType, nullptr);)
65DEF_BENCH(return new WritePixelsBench(kBGRA_8888_SkColorType, kUnpremul_SkAlphaType, nullptr);)
66DEF_BENCH(return new WritePixelsBench(kBGRA_8888_SkColorType, kPremul_SkAlphaType, SkColorSpace::MakeSRGB());)
67DEF_BENCH(return new WritePixelsBench(kBGRA_8888_SkColorType, kUnpremul_SkAlphaType, SkColorSpace::MakeSRGB());)