• 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 "bench/Benchmark.h"
9 #include "include/core/SkBitmap.h"
10 #include "include/core/SkCanvas.h"
11 #include "include/core/SkString.h"
12 
13 // Time variants of write-pixels
14 //  [ colortype ][ alphatype ][ colorspace ]
15 //  Different combinations can trigger fast or slow paths in the impls
16 //
17 class WritePixelsBench : public Benchmark {
18 public:
WritePixelsBench(SkColorType ct,SkAlphaType at,sk_sp<SkColorSpace> cs)19     WritePixelsBench(SkColorType ct, SkAlphaType at, sk_sp<SkColorSpace> cs)
20         : fColorType(ct)
21         , fAlphaType(at)
22         , fCS(cs)
23     {
24         fName.printf("writepix_%s_%s_%s",
25                      at == kPremul_SkAlphaType ? "pm" : "um",
26                      ct == kRGBA_8888_SkColorType ? "rgba" : "bgra",
27                      cs ? "srgb" : "null");
28     }
29 
30 protected:
onGetName()31     const char* onGetName() override {
32         return fName.c_str();
33     }
34 
onDraw(int loops,SkCanvas * canvas)35     void onDraw(int loops, SkCanvas* canvas) override {
36         SkISize size = canvas->getBaseLayerSize();
37 
38         SkImageInfo info = SkImageInfo::Make(size.width(), size.height(), fColorType, fAlphaType,
39                                              fCS);
40         SkBitmap bmp;
41         bmp.allocPixels(info);
42         bmp.eraseColor(SK_ColorBLACK);
43 
44         for (int loop = 0; loop < loops; ++loop) {
45             canvas->writePixels(info, bmp.getPixels(), bmp.rowBytes(), 0, 0);
46         }
47     }
48 
49 private:
50     SkColorType fColorType;
51     SkAlphaType fAlphaType;
52     sk_sp<SkColorSpace> fCS;
53     SkString    fName;
54 
55     typedef Benchmark INHERITED;
56 };
57 
58 //////////////////////////////////////////////////////////////////////////////
59 
60 DEF_BENCH(return new WritePixelsBench(kRGBA_8888_SkColorType, kPremul_SkAlphaType, nullptr);)
61 DEF_BENCH(return new WritePixelsBench(kRGBA_8888_SkColorType, kUnpremul_SkAlphaType, nullptr);)
62 DEF_BENCH(return new WritePixelsBench(kRGBA_8888_SkColorType, kPremul_SkAlphaType, SkColorSpace::MakeSRGB());)
63 DEF_BENCH(return new WritePixelsBench(kRGBA_8888_SkColorType, kUnpremul_SkAlphaType, SkColorSpace::MakeSRGB());)
64 
65 DEF_BENCH(return new WritePixelsBench(kBGRA_8888_SkColorType, kPremul_SkAlphaType, nullptr);)
66 DEF_BENCH(return new WritePixelsBench(kBGRA_8888_SkColorType, kUnpremul_SkAlphaType, nullptr);)
67 DEF_BENCH(return new WritePixelsBench(kBGRA_8888_SkColorType, kPremul_SkAlphaType, SkColorSpace::MakeSRGB());)
68 DEF_BENCH(return new WritePixelsBench(kBGRA_8888_SkColorType, kUnpremul_SkAlphaType, SkColorSpace::MakeSRGB());)
69