blob: 0313846a3bc503f9429a4b76c242954551e77763 [file] [log] [blame]
commit-bot@chromium.org8f426972013-08-16 00:40:34 +00001
2/*
3 * Copyright 2013 Google Inc.
4 *
5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file.
7 */
8
9#include "SkBenchmark.h"
10#include "SkCanvas.h"
11#include "SkConfig8888.h"
12#include "SkString.h"
13
14class WritePixelsBench : public SkBenchmark {
15public:
mtklein@google.com410e6e82013-09-13 19:52:27 +000016 WritePixelsBench(SkCanvas::Config8888 config)
17 : fConfig(config)
commit-bot@chromium.org8f426972013-08-16 00:40:34 +000018 , fName("writepix") {
19 switch (config) {
20 case SkCanvas::kNative_Premul_Config8888:
21 fName.append("_native_PM");
22 break;
23 case SkCanvas::kNative_Unpremul_Config8888:
24 fName.append("_native_UPM");
25 break;
26 case SkCanvas::kBGRA_Premul_Config8888:
27 fName.append("_bgra_PM");
28 break;
29 case SkCanvas::kBGRA_Unpremul_Config8888:
30 fName.append("_bgra_UPM");
31 break;
32 case SkCanvas::kRGBA_Premul_Config8888:
33 fName.append("_rgba_PM");
34 break;
35 case SkCanvas::kRGBA_Unpremul_Config8888:
36 fName.append("_rgba_UPM");
37 break;
skia.committer@gmail.comc9917c02013-08-16 07:01:49 +000038 default:
commit-bot@chromium.org8f426972013-08-16 00:40:34 +000039 SK_CRASH();
40 break;
41 }
42 }
43
44protected:
45 virtual const char* onGetName() SK_OVERRIDE {
46 return fName.c_str();
47 }
48
commit-bot@chromium.org33614712013-12-03 18:17:16 +000049 virtual void onDraw(const int loops, SkCanvas* canvas) SK_OVERRIDE {
commit-bot@chromium.org8f426972013-08-16 00:40:34 +000050 SkISize size = canvas->getDeviceSize();
51
52 canvas->clear(0xFFFF0000);
53
54 SkBitmap bmp;
55 bmp.setConfig(SkBitmap::kARGB_8888_Config, size.width(), size.height());
56 canvas->readPixels(&bmp, 0, 0);
57
commit-bot@chromium.org33614712013-12-03 18:17:16 +000058 for (int loop = 0; loop < loops; ++loop) {
commit-bot@chromium.org8f426972013-08-16 00:40:34 +000059 canvas->writePixels(bmp, 0, 0, fConfig);
60 }
61 }
62
63private:
commit-bot@chromium.org8f426972013-08-16 00:40:34 +000064 SkCanvas::Config8888 fConfig;
65 SkString fName;
66
67 typedef SkBenchmark INHERITED;
68};
69
70//////////////////////////////////////////////////////////////////////////////
71
mtklein@google.com410e6e82013-09-13 19:52:27 +000072DEF_BENCH( return SkNEW_ARGS(WritePixelsBench, (SkCanvas::kRGBA_Premul_Config8888)); )
73DEF_BENCH( return SkNEW_ARGS(WritePixelsBench, (SkCanvas::kRGBA_Unpremul_Config8888)); )