blob: 33c5b18b620afee178d9a98e88c33d3a4b2a36ea [file] [log] [blame]
robertphillips@google.com6806bda2012-09-04 13:39:01 +00001/*
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 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/SkColorSpace.h"
robertphillips@google.com6806bda2012-09-04 13:39:01 +000012
Mike Reedaf990f32019-03-21 15:55:05 -040013// Time variants of read-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 ReadPixBench : public Benchmark {
robertphillips@google.com6806bda2012-09-04 13:39:01 +000018public:
Mike Reedaf990f32019-03-21 15:55:05 -040019 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.com6806bda2012-09-04 13:39:01 +000027
28protected:
mtklein36352bf2015-03-25 18:17:31 -070029 const char* onGetName() override {
Mike Reedaf990f32019-03-21 15:55:05 -040030 return fName.c_str();
robertphillips@google.com6806bda2012-09-04 13:39:01 +000031 }
32
mtkleina1ebeb22015-10-01 09:43:39 -070033 void onDraw(int loops, SkCanvas* canvas) override {
Mike Reedaf990f32019-03-21 15:55:05 -040034 canvas->clear(0x80000000);
robertphillips@google.com6806bda2012-09-04 13:39:01 +000035
Mike Reed3661bc92017-02-22 13:21:42 -050036 SkISize size = canvas->getBaseLayerSize();
robertphillips@google.com6806bda2012-09-04 13:39:01 +000037
Brian Salomon4bc0c1f2019-09-30 15:12:27 -040038 auto info = SkImageInfo::Make(size, fCT, fAT, fCS);
robertphillips@google.com6806bda2012-09-04 13:39:01 +000039 SkBitmap bitmap;
Mike Reedaf990f32019-03-21 15:55:05 -040040 bitmap.allocPixels(info);
robertphillips@google.com6806bda2012-09-04 13:39:01 +000041
commit-bot@chromium.org33614712013-12-03 18:17:16 +000042 for (int i = 0; i < loops; i++) {
Mike Reedaf990f32019-03-21 15:55:05 -040043 canvas->readPixels(bitmap.info(), bitmap.getPixels(), bitmap.rowBytes(), 0, 0);
robertphillips@google.com6806bda2012-09-04 13:39:01 +000044 }
45 }
46
47private:
Mike Reedaf990f32019-03-21 15:55:05 -040048 SkColorType fCT;
49 SkAlphaType fAT;
50 sk_sp<SkColorSpace> fCS;
51 SkString fName;
John Stiles7571f9e2020-09-02 22:42:33 -040052 using INHERITED = Benchmark;
robertphillips@google.com6806bda2012-09-04 13:39:01 +000053};
Mike Reedaf990f32019-03-21 15:55:05 -040054DEF_BENCH( return new ReadPixBench(kRGBA_8888_SkColorType, kPremul_SkAlphaType, nullptr); )
55DEF_BENCH( return new ReadPixBench(kRGBA_8888_SkColorType, kUnpremul_SkAlphaType, nullptr); )
56DEF_BENCH( return new ReadPixBench(kRGBA_8888_SkColorType, kPremul_SkAlphaType, SkColorSpace::MakeSRGB()); )
57DEF_BENCH( return new ReadPixBench(kRGBA_8888_SkColorType, kUnpremul_SkAlphaType, SkColorSpace::MakeSRGB()); )
58
59DEF_BENCH( return new ReadPixBench(kBGRA_8888_SkColorType, kPremul_SkAlphaType, nullptr); )
60DEF_BENCH( return new ReadPixBench(kBGRA_8888_SkColorType, kUnpremul_SkAlphaType, nullptr); )
61DEF_BENCH( return new ReadPixBench(kBGRA_8888_SkColorType, kPremul_SkAlphaType, SkColorSpace::MakeSRGB()); )
62DEF_BENCH( return new ReadPixBench(kBGRA_8888_SkColorType, kUnpremul_SkAlphaType, SkColorSpace::MakeSRGB()); )
robertphillips@google.com6806bda2012-09-04 13:39:01 +000063
64////////////////////////////////////////////////////////////////////////////////
Mike Kleinc0bd9f92019-04-23 12:05:21 -050065#include "include/core/SkBitmap.h"
66#include "src/core/SkPixmapPriv.h"
robertphillips@google.com6806bda2012-09-04 13:39:01 +000067
Mike Reed7306bcd2017-10-25 10:37:30 -040068class PixmapOrientBench : public Benchmark {
69public:
70 PixmapOrientBench() {}
71
72protected:
73 void onDelayedSetup() override {
74 const SkImageInfo info = SkImageInfo::MakeN32Premul(2048, 1024);
75 fSrc.allocPixels(info);
76 fSrc.eraseColor(SK_ColorBLACK);
Brian Salomon9241a6d2019-10-03 13:26:54 -040077 fDst.allocPixels(info.makeDimensions(info.dimensions()));
Mike Reed7306bcd2017-10-25 10:37:30 -040078 }
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 Reed7306bcd2017-10-25 10:37:30 -040089 SkPixmap src, dst;
90 fSrc.peekPixels(&src);
91 fDst.peekPixels(&dst);
92 for (int i = 0; i < loops; ++i) {
Brian Osmanc337a632018-11-30 10:39:32 -050093 SkPixmapPriv::Orient(dst, src, kTopRight_SkEncodedOrigin);
Mike Reed7306bcd2017-10-25 10:37:30 -040094 }
95 }
96
97private:
98 SkBitmap fSrc, fDst;
99
John Stiles7571f9e2020-09-02 22:42:33 -0400100 using INHERITED = Benchmark;
Mike Reed7306bcd2017-10-25 10:37:30 -0400101};
102DEF_BENCH( return new PixmapOrientBench(); )
Mike Reedc25f4402018-09-20 15:00:56 -0400103
104
105class GetAlphafBench : public Benchmark {
106 SkString fName;
107 SkColorType fCT;
108public:
109 GetAlphafBench(SkColorType ct, const char label[]) : fCT(ct) {
110 fName.printf("getalphaf_%s", label);
111 }
112
113protected:
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
137private:
138 SkBitmap fBM;
139
John Stiles7571f9e2020-09-02 22:42:33 -0400140 using INHERITED = Benchmark;
Mike Reedc25f4402018-09-20 15:00:56 -0400141};
142DEF_BENCH( return new GetAlphafBench(kN32_SkColorType, "rgba"); )
143DEF_BENCH( return new GetAlphafBench(kRGB_888x_SkColorType, "rgbx"); )
144DEF_BENCH( return new GetAlphafBench(kRGBA_F16_SkColorType, "f16"); )
145DEF_BENCH( return new GetAlphafBench(kRGBA_F32_SkColorType, "f32"); )
146