• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
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 
8 #include "Benchmark.h"
9 #include "SkBitmap.h"
10 #include "SkCanvas.h"
11 #include "SkString.h"
12 
13 class WritePixelsBench : public Benchmark {
14 public:
WritePixelsBench(SkColorType ct,SkAlphaType at)15     WritePixelsBench(SkColorType ct, SkAlphaType at)
16         : fColorType(ct)
17         , fAlphaType(at)
18         , fName("writepix")
19     {
20         switch (ct) {
21             case kRGBA_8888_SkColorType:
22                 fName.append("_RGBA");
23                 break;
24             case kBGRA_8888_SkColorType:
25                 fName.append("_BGRA");
26                 break;
27             default:
28                 SkASSERT(0);
29                 break;
30         }
31         switch (at) {
32             case kPremul_SkAlphaType:
33                 fName.append("_PM");
34                 break;
35             case kUnpremul_SkAlphaType:
36                 fName.append("_UPM");
37                 break;
38             default:
39                 SkASSERT(0);
40                 break;
41         }
42     }
43 
44 protected:
onGetName()45     const char* onGetName() override {
46         return fName.c_str();
47     }
48 
onDraw(int loops,SkCanvas * canvas)49     void onDraw(int loops, SkCanvas* canvas) override {
50         SkISize size = canvas->getBaseLayerSize();
51 
52         canvas->clear(0xFFFF0000);
53 
54         SkBitmap bmp;
55         bmp.allocN32Pixels(size.width(), size.height());
56         canvas->readPixels(bmp, 0, 0);
57 
58         SkImageInfo info = SkImageInfo::Make(bmp.width(), bmp.height(), fColorType, fAlphaType);
59 
60         for (int loop = 0; loop < loops; ++loop) {
61             canvas->writePixels(info, bmp.getPixels(), bmp.rowBytes(), 0, 0);
62         }
63     }
64 
65 private:
66     SkColorType fColorType;
67     SkAlphaType fAlphaType;
68     SkString    fName;
69 
70     typedef Benchmark INHERITED;
71 };
72 
73 //////////////////////////////////////////////////////////////////////////////
74 
75 DEF_BENCH(return new WritePixelsBench(kRGBA_8888_SkColorType, kPremul_SkAlphaType);)
76 DEF_BENCH(return new WritePixelsBench(kRGBA_8888_SkColorType, kUnpremul_SkAlphaType);)
77