OLD | NEW |
1 | |
2 /* | 1 /* |
3 * Copyright 2013 Google Inc. | 2 * Copyright 2013 Google Inc. |
4 * | 3 * |
5 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
6 * found in the LICENSE file. | 5 * found in the LICENSE file. |
7 */ | 6 */ |
8 | 7 |
9 #include "SkBenchmark.h" | 8 #include "SkBenchmark.h" |
10 #include "SkCanvas.h" | 9 #include "SkCanvas.h" |
11 #include "SkConfig8888.h" | 10 #include "SkConfig8888.h" |
12 #include "SkString.h" | 11 #include "SkString.h" |
| 12 #include "sk_tool_utils.h" |
13 | 13 |
14 class PremulAndUnpremulAlphaOpsBench : public SkBenchmark { | 14 class PremulAndUnpremulAlphaOpsBench : public SkBenchmark { |
15 public: | 15 public: |
16 PremulAndUnpremulAlphaOpsBench(SkCanvas::Config8888 config) { | 16 PremulAndUnpremulAlphaOpsBench(SkCanvas::Config8888 config) { |
17 fUnPremulConfig = config; | 17 fUnPremulConfig = config; |
18 fName.printf("premul_and_unpremul_alpha_%s", | 18 fName.printf("premul_and_unpremul_alpha_%s", |
19 (config == SkCanvas::kRGBA_Unpremul_Config8888) ? | 19 (config == SkCanvas::kRGBA_Unpremul_Config8888) ? |
20 "RGBA8888" : "Native8888"); | 20 "RGBA8888" : "Native8888"); |
21 } | 21 } |
22 | 22 |
(...skipping 15 matching lines...) Expand all Loading... |
38 for (int h = 0; h < size.height(); ++h) { | 38 for (int h = 0; h < size.height(); ++h) { |
39 for (int w = 0; w < size.width(); ++w) | 39 for (int w = 0; w < size.width(); ++w) |
40 pixels[h * size.width() + w] = SkPackConfig8888(fUnPremulConfig, | 40 pixels[h * size.width() + w] = SkPackConfig8888(fUnPremulConfig, |
41 h & 0xFF, w & 0xFF, w & 0xFF, w & 0xFF); | 41 h & 0xFF, w & 0xFF, w & 0xFF, w & 0xFF); |
42 } | 42 } |
43 | 43 |
44 SkBitmap bmp2; | 44 SkBitmap bmp2; |
45 bmp2.setConfig(SkBitmap::kARGB_8888_Config, size.width(), | 45 bmp2.setConfig(SkBitmap::kARGB_8888_Config, size.width(), |
46 size.height()); | 46 size.height()); |
47 | 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 |
48 for (int loop = 0; loop < loops; ++loop) { | 55 for (int loop = 0; loop < loops; ++loop) { |
49 // Unpremul -> Premul | 56 // Unpremul -> Premul |
50 canvas->writePixels(bmp1, 0, 0, fUnPremulConfig); | 57 sk_tool_utils::write_pixels(canvas, bmp1, 0, 0, ct, at); |
51 // Premul -> Unpremul | 58 // Premul -> Unpremul |
52 canvas->readPixels(&bmp2, 0, 0, fUnPremulConfig); | 59 canvas->readPixels(&bmp2, 0, 0, fUnPremulConfig); |
53 } | 60 } |
54 } | 61 } |
55 | 62 |
56 private: | 63 private: |
57 SkCanvas::Config8888 fUnPremulConfig; | 64 SkCanvas::Config8888 fUnPremulConfig; |
58 SkString fName; | 65 SkString fName; |
59 typedef SkBenchmark INHERITED; | 66 typedef SkBenchmark INHERITED; |
60 }; | 67 }; |
61 | 68 |
62 | 69 |
63 DEF_BENCH(return new PremulAndUnpremulAlphaOpsBench(SkCanvas::kRGBA_Unpremul_Con
fig8888)); | 70 DEF_BENCH(return new PremulAndUnpremulAlphaOpsBench(SkCanvas::kRGBA_Unpremul_Con
fig8888)); |
64 DEF_BENCH(return new PremulAndUnpremulAlphaOpsBench(SkCanvas::kNative_Unpremul_C
onfig8888)); | 71 DEF_BENCH(return new PremulAndUnpremulAlphaOpsBench(SkCanvas::kNative_Unpremul_C
onfig8888)); |
OLD | NEW |