OLD | NEW |
---|---|
(Empty) | |
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 "SkBenchmark.h" | |
9 #include "SkCanvas.h" | |
10 #include "SkConfig8888.h" | |
11 #include "SkString.h" | |
12 #include "sk_tool_utils.h" | |
13 | |
14 class PremulAndUnpremulAlphaOpsBench : public SkBenchmark { | |
bsalomon
2014/03/17 18:19:47
Removing this benchmark scares me a little bit. Th
reed1
2014/03/17 18:47:09
Restored and updated
| |
15 public: | |
16 PremulAndUnpremulAlphaOpsBench(SkCanvas::Config8888 config) { | |
17 fUnPremulConfig = config; | |
18 fName.printf("premul_and_unpremul_alpha_%s", | |
19 (config == SkCanvas::kRGBA_Unpremul_Config8888) ? | |
20 "RGBA8888" : "Native8888"); | |
21 } | |
22 | |
23 protected: | |
24 virtual const char* onGetName() SK_OVERRIDE { | |
25 return fName.c_str(); | |
26 } | |
27 | |
28 virtual void onDraw(const int loops, SkCanvas* canvas) SK_OVERRIDE { | |
29 canvas->clear(SK_ColorBLACK); | |
30 SkISize size = canvas->getDeviceSize(); | |
31 | |
32 SkBitmap bmp1; | |
33 bmp1.setConfig(SkBitmap::kARGB_8888_Config, size.width(), | |
34 size.height()); | |
35 bmp1.allocPixels(); | |
36 SkAutoLockPixels alp(bmp1); | |
37 uint32_t* pixels = reinterpret_cast<uint32_t*>(bmp1.getPixels()); | |
38 for (int h = 0; h < size.height(); ++h) { | |
39 for (int w = 0; w < size.width(); ++w) | |
40 pixels[h * size.width() + w] = SkPackConfig8888(fUnPremulConfig, | |
41 h & 0xFF, w & 0xFF, w & 0xFF, w & 0xFF); | |
42 } | |
43 | |
44 SkBitmap bmp2; | |
45 bmp2.setConfig(SkBitmap::kARGB_8888_Config, size.width(), | |
46 size.height()); | |
47 | |
48 SkColorType ct; | |
49 SkAlphaType at; | |
50 sk_tool_utils::config8888_to_imagetypes(fUnPremulConfig, &ct, &at); | |
51 if (bmp1.isOpaque()) { | |
52 at = kOpaque_SkAlphaType; | |
53 } | |
54 | |
55 for (int loop = 0; loop < loops; ++loop) { | |
56 // Unpremul -> Premul | |
57 sk_tool_utils::write_pixels(canvas, bmp1, 0, 0, ct, at); | |
58 // Premul -> Unpremul | |
59 canvas->readPixels(&bmp2, 0, 0, fUnPremulConfig); | |
60 } | |
61 } | |
62 | |
63 private: | |
64 SkCanvas::Config8888 fUnPremulConfig; | |
65 SkString fName; | |
66 typedef SkBenchmark INHERITED; | |
67 }; | |
68 | |
69 | |
70 DEF_BENCH(return new PremulAndUnpremulAlphaOpsBench(SkCanvas::kRGBA_Unpremul_Con fig8888)); | |
71 DEF_BENCH(return new PremulAndUnpremulAlphaOpsBench(SkCanvas::kNative_Unpremul_C onfig8888)); | |
OLD | NEW |