diff options
author | commit-bot@chromium.org <commit-bot@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2013-06-13 10:18:02 +0000 |
---|---|---|
committer | commit-bot@chromium.org <commit-bot@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2013-06-13 10:18:02 +0000 |
commit | 5f879755f4928cb8cc5f88daddaf0fc11b44d1bb (patch) | |
tree | 2adfa60ff6de8584bed8e79d297be3c408c13fc2 /bench/PremulAndUnpremulAlphaOpsBench.cpp | |
parent | a707fd53f779843cf9354db27589bb0ef6cb1a0b (diff) |
Add benchmark for PremultiplyAlpha and UnpremultiplyAlpha in Skia
BUG=248549
R=tomhudson@chromium.org, bsalomon@chromium.org, reed@google.com, noel@chromium.org, tomhudson@google.com
Author: jun.a.jiang@intel.com
Review URL: https://chromiumcodereview.appspot.com/16654004
git-svn-id: http://skia.googlecode.com/svn/trunk@9569 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'bench/PremulAndUnpremulAlphaOpsBench.cpp')
-rw-r--r-- | bench/PremulAndUnpremulAlphaOpsBench.cpp | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/bench/PremulAndUnpremulAlphaOpsBench.cpp b/bench/PremulAndUnpremulAlphaOpsBench.cpp new file mode 100644 index 0000000000..f552097b60 --- /dev/null +++ b/bench/PremulAndUnpremulAlphaOpsBench.cpp @@ -0,0 +1,74 @@ + +/* + * 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" +#include "SkString.h" + +class PremulAndUnpremulAlphaOpsBench : public SkBenchmark { +public: + PremulAndUnpremulAlphaOpsBench(void* param, SkCanvas::Config8888 config) + : INHERITED(param) { + fUnPremulConfig = config; + fName.printf("premul_and_unpremul_alpha_%s", + (config == SkCanvas::kRGBA_Unpremul_Config8888) ? + "RGBA8888" : "Native8888"); + } + +protected: + virtual const char* onGetName() SK_OVERRIDE { + return fName.c_str(); + } + + virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE { + canvas->clear(SK_ColorBLACK); + SkISize size = canvas->getDeviceSize(); + + 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(fUnPremulConfig, + h & 0xFF, w & 0xFF, w & 0xFF, w & 0xFF); + } + + SkBitmap bmp2; + bmp2.setConfig(SkBitmap::kARGB_8888_Config, size.width(), + size.height()); + + static const int kLoopCount = SkBENCHLOOP(10); + for (int loop = 0; loop < kLoopCount; ++loop) { + // Unpremul -> Premul + canvas->writePixels(bmp1, 0, 0, fUnPremulConfig); + // Premul -> Unpremul + canvas->readPixels(&bmp2, 0, 0, fUnPremulConfig); + } + } + +private: + SkCanvas::Config8888 fUnPremulConfig; + SkString fName; + typedef SkBenchmark INHERITED; +}; + +static SkBenchmark* fact0(void* p) { + return new PremulAndUnpremulAlphaOpsBench(p, + SkCanvas::kRGBA_Unpremul_Config8888); +} +static SkBenchmark* fact1(void* p) { + return new PremulAndUnpremulAlphaOpsBench(p, + SkCanvas::kNative_Unpremul_Config8888); +} + +static BenchRegistry gReg0(fact0); +static BenchRegistry gReg1(fact1); |