Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(252)

Side by Side Diff: bench/PremulAndUnpremulAlphaOpsBench.cpp

Issue 16654004: Add benchmark for PremultiplyAlpha and UnpremultiplyAlpha in Skia (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Fix the code line length Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | gyp/bench.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1
2 /*
3 * Copyright 2013 Google Inc.
4 *
5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file.
7 */
8
9 #include "SkBenchmark.h"
10 #include "SkCanvas.h"
11 #include "SkConfig8888.h"
12
13 class PremulAndUnpremulAlphaOpsBench : public SkBenchmark {
14 public:
15 PremulAndUnpremulAlphaOpsBench(void* param, SkCanvas::Config8888 config,
16 const char* name)
17 : INHERITED(param) {
18 unPremulConfig = config;
19 benchName = name;
20 }
21
22 protected:
23 virtual const char* onGetName() SK_OVERRIDE {
24 return benchName;
25 }
26
27 virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE {
28 canvas->clear(SK_ColorBLACK);
29 SkISize size = canvas->getDeviceSize();
30
31 SkBitmap bmp1;
32 bmp1.setConfig(SkBitmap::kARGB_8888_Config, size.width(),
33 size.height());
34 bmp1.allocPixels();
35 SkAutoLockPixels alp(bmp1);
36 uint32_t* pixels = reinterpret_cast<uint32_t*>(bmp1.getPixels());
37 for (int h = 0; h < size.height(); ++h) {
38 for (int w = 0; w < size.width(); ++w)
39 pixels[h * size.width() + w] = SkPackConfig8888(unPremulConfig,
40 h & 0xFF, w & 0xFF, w & 0xFF, w & 0xFF);
41 }
42
43 SkBitmap bmp2;
44 bmp2.setConfig(SkBitmap::kARGB_8888_Config, size.width(),
45 size.height());
46
47 static const int kLoopCount = SkBENCHLOOP(10);
48 for (int loop = 0; loop < kLoopCount; ++loop) {
49 // Unpremul -> Premul
50 canvas->writePixels(bmp1, 0, 0, unPremulConfig);
51 // Premul -> Unpremul
52 canvas->readPixels(&bmp2, 0, 0, unPremulConfig);
53 }
54 }
55
56 private:
57 SkCanvas::Config8888 unPremulConfig;
58 const char* benchName;
tomhudson 2013/06/12 09:23:34 I wasn't reading carefully enough earlier - anothe
Jun Jiang 2013/06/12 16:59:26 Done.
59 typedef SkBenchmark INHERITED;
60 };
61
62 static SkBenchmark* fact0(void* p) {
63 return new PremulAndUnpremulAlphaOpsBench(p,
64 SkCanvas::kRGBA_Unpremul_Config8888,
65 "premul_and_unpremul_alpha_RGBA8888");
66 }
67 static SkBenchmark* fact1(void* p) {
68 return new PremulAndUnpremulAlphaOpsBench(p,
69 SkCanvas::kNative_Unpremul_Config8888,
70 "premul_and_unpremul_alpha_Native8888");
71 }
72
73 static BenchRegistry gReg0(fact0);
74 static BenchRegistry gReg1(fact1);
OLDNEW
« no previous file with comments | « no previous file | gyp/bench.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698