blob: 5138375ffbae41f428fd9b2758f8c5c0b170d09d [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:
44 virtual const char* onGetName() SK_OVERRIDE {
45 return fName.c_str();
46 }
47
commit-bot@chromium.org33614712013-12-03 18:17:16 +000048 virtual void onDraw(const int loops, SkCanvas* canvas) SK_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
commit-bot@chromium.org4cd9e212014-03-07 03:25:16 +000057 SkImageInfo info = bmp.info();
58 info.fColorType = fColorType;
59 info.fAlphaType = fAlphaType;
skia.committer@gmail.come62513f2014-03-08 03:02:06 +000060
commit-bot@chromium.org33614712013-12-03 18:17:16 +000061 for (int loop = 0; loop < loops; ++loop) {
commit-bot@chromium.org4cd9e212014-03-07 03:25:16 +000062 canvas->writePixels(info, bmp.getPixels(), bmp.rowBytes(), 0, 0);
commit-bot@chromium.org8f426972013-08-16 00:40:34 +000063 }
64 }
65
66private:
commit-bot@chromium.org4cd9e212014-03-07 03:25:16 +000067 SkColorType fColorType;
68 SkAlphaType fAlphaType;
69 SkString fName;
commit-bot@chromium.org8f426972013-08-16 00:40:34 +000070
tfarinaf168b862014-06-19 12:32:29 -070071 typedef Benchmark INHERITED;
commit-bot@chromium.org8f426972013-08-16 00:40:34 +000072};
73
74//////////////////////////////////////////////////////////////////////////////
75
commit-bot@chromium.org4cd9e212014-03-07 03:25:16 +000076DEF_BENCH( return SkNEW_ARGS(WritePixelsBench, (kRGBA_8888_SkColorType, kPremul_SkAlphaType)); )
77DEF_BENCH( return SkNEW_ARGS(WritePixelsBench, (kRGBA_8888_SkColorType, kUnpremul_SkAlphaType)); )