blob: 3ee90345fa3080a1c8aacd0731157358c56b2a6a [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
tfarinaf168b862014-06-19 12:32:29 -07008#include "Benchmark.h"
commit-bot@chromium.org8f426972013-08-16 00:40:34 +00009#include "SkCanvas.h"
commit-bot@chromium.org8f426972013-08-16 00:40:34 +000010#include "SkString.h"
11
tfarinaf168b862014-06-19 12:32:29 -070012class WritePixelsBench : public Benchmark {
commit-bot@chromium.org8f426972013-08-16 00:40:34 +000013public:
commit-bot@chromium.org4cd9e212014-03-07 03:25:16 +000014 WritePixelsBench(SkColorType ct, SkAlphaType at)
15 : fColorType(ct)
16 , fAlphaType(at)
17 , fName("writepix")
18 {
19 switch (ct) {
20 case kRGBA_8888_SkColorType:
21 fName.append("_RGBA");
commit-bot@chromium.org8f426972013-08-16 00:40:34 +000022 break;
commit-bot@chromium.org4cd9e212014-03-07 03:25:16 +000023 case kBGRA_8888_SkColorType:
24 fName.append("_BGRA");
commit-bot@chromium.org8f426972013-08-16 00:40:34 +000025 break;
skia.committer@gmail.comc9917c02013-08-16 07:01:49 +000026 default:
commit-bot@chromium.org4cd9e212014-03-07 03:25:16 +000027 SkASSERT(0);
28 break;
29 }
30 switch (at) {
31 case kPremul_SkAlphaType:
32 fName.append("_PM");
33 break;
34 case kUnpremul_SkAlphaType:
35 fName.append("_UPM");
36 break;
37 default:
38 SkASSERT(0);
commit-bot@chromium.org8f426972013-08-16 00:40:34 +000039 break;
40 }
41 }
42
43protected:
mtklein36352bf2015-03-25 18:17:31 -070044 const char* onGetName() override {
commit-bot@chromium.org8f426972013-08-16 00:40:34 +000045 return fName.c_str();
46 }
47
mtklein36352bf2015-03-25 18:17:31 -070048 void onDraw(const int loops, SkCanvas* canvas) override {
commit-bot@chromium.org8f426972013-08-16 00:40:34 +000049 SkISize size = canvas->getDeviceSize();
50
51 canvas->clear(0xFFFF0000);
52
53 SkBitmap bmp;
commit-bot@chromium.org4cd9e212014-03-07 03:25:16 +000054 bmp.allocN32Pixels(size.width(), size.height());
commit-bot@chromium.org8f426972013-08-16 00:40:34 +000055 canvas->readPixels(&bmp, 0, 0);
56
reede5ea5002014-09-03 11:54:58 -070057 SkImageInfo info = SkImageInfo::Make(bmp.width(), bmp.height(), fColorType, fAlphaType);
skia.committer@gmail.come62513f2014-03-08 03:02:06 +000058
commit-bot@chromium.org33614712013-12-03 18:17:16 +000059 for (int loop = 0; loop < loops; ++loop) {
commit-bot@chromium.org4cd9e212014-03-07 03:25:16 +000060 canvas->writePixels(info, bmp.getPixels(), bmp.rowBytes(), 0, 0);
commit-bot@chromium.org8f426972013-08-16 00:40:34 +000061 }
62 }
63
64private:
commit-bot@chromium.org4cd9e212014-03-07 03:25:16 +000065 SkColorType fColorType;
66 SkAlphaType fAlphaType;
67 SkString fName;
commit-bot@chromium.org8f426972013-08-16 00:40:34 +000068
tfarinaf168b862014-06-19 12:32:29 -070069 typedef Benchmark INHERITED;
commit-bot@chromium.org8f426972013-08-16 00:40:34 +000070};
71
72//////////////////////////////////////////////////////////////////////////////
73
commit-bot@chromium.org4cd9e212014-03-07 03:25:16 +000074DEF_BENCH( return SkNEW_ARGS(WritePixelsBench, (kRGBA_8888_SkColorType, kPremul_SkAlphaType)); )
75DEF_BENCH( return SkNEW_ARGS(WritePixelsBench, (kRGBA_8888_SkColorType, kUnpremul_SkAlphaType)); )