Chromium Code Reviews| Index: bench/PremulAndUnpremulAlphaOpsBench.cpp |
| diff --git a/bench/PremulAndUnpremulAlphaOpsBench.cpp b/bench/PremulAndUnpremulAlphaOpsBench.cpp |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..3d8843f205f73412597a8f1da3f996749b6d0178 |
| --- /dev/null |
| +++ b/bench/PremulAndUnpremulAlphaOpsBench.cpp |
| @@ -0,0 +1,61 @@ |
| + |
| +/* |
| + * Copyright 2013 Google Inc. |
| + * |
| + * Use of this source code is governed by a BSD-style license that can be |
| + * found in the LICENSE file. |
| + */ |
| + |
| +#include "SkBenchmark.h" |
| +#include "SkCanvas.h" |
| +#include "SkConfig8888.h" |
| + |
| +class PremulAndUnpremulAlphaOpsBench : public SkBenchmark { |
| +public: |
| + PremulAndUnpremulAlphaOpsBench(void* param, SkCanvas::Config8888 config, const char* name) |
| + : INHERITED(param) { |
| + unPremulConfig = config; |
| + benchName = name; |
| + } |
| + |
| +protected: |
| + virtual const char* onGetName() SK_OVERRIDE { |
| + return benchName; |
| + } |
| + |
| + virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE { |
| + canvas->clear(SK_ColorBLACK); |
| + SkISize size = canvas->getDeviceSize(); |
| + |
| + const unsigned int LoopTime = 10; |
|
bsalomon
2013/05/31 12:42:08
style-nit:
static const int kLoopCount = 10;
Actu
Jun Jiang
2013/05/31 15:10:58
Done.
|
| + for (unsigned int loop = 0; loop < LoopTime; ++loop) { |
|
bsalomon
2013/05/31 12:42:08
style-nit: "int loop = 0"
We use ints unless it i
Jun Jiang
2013/05/31 15:10:58
Done.
|
| + SkBitmap bmp1; |
| + bmp1.setConfig(SkBitmap::kARGB_8888_Config, size.width(), size.height()); |
| + bmp1.allocPixels(); |
| + SkAutoLockPixels alp(bmp1); |
| + uint32_t* pixels = reinterpret_cast<uint32_t*>(bmp1.getPixels()); |
| + for (int h = 0; h < size.height(); ++h) { |
| + for (int w = 0; w < size.width(); ++w) |
| + pixels[h * size.width() + w] = SkPackConfig8888(unPremulConfig, h & 0xFF, w & 0xFF, w & 0xFF, w & 0xFF); |
| + } |
| + // Unpremul -> Premul |
| + canvas->writePixels(bmp1, 0, 0, unPremulConfig); |
| + |
| + SkBitmap bmp2; |
| + bmp2.setConfig(SkBitmap::kARGB_8888_Config, size.width(), size.height()); |
| + // Premul -> Unpremul |
| + canvas->readPixels(&bmp2, 0, 0, unPremulConfig); |
| + } |
| + } |
| + |
| +private: |
| + SkCanvas::Config8888 unPremulConfig; |
| + const char* benchName; |
| + typedef SkBenchmark INHERITED; |
| +}; |
| + |
| +static SkBenchmark* fact0(void* p) { return new PremulAndUnpremulAlphaOpsBench(p, SkCanvas::kRGBA_Unpremul_Config8888, "premul_and_unpremul_alpha_RGBA8888"); } |
| +static SkBenchmark* fact1(void* p) { return new PremulAndUnpremulAlphaOpsBench(p, SkCanvas::kNative_Unpremul_Config8888, "premul_and_unpremul_alpha_Native8888"); } |
| + |
| +static BenchRegistry gReg0(fact0); |
| +static BenchRegistry gReg1(fact1); |