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

Side by Side Diff: bench/PremulAndUnpremulAlphaOpsBench.cpp

Issue 99893003: Simplify benchmark internal API. (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: rebase Created 7 years 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 | « bench/PictureRecordBench.cpp ('k') | bench/RTreeBench.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 1
2 /* 2 /*
3 * Copyright 2013 Google Inc. 3 * Copyright 2013 Google Inc.
4 * 4 *
5 * Use of this source code is governed by a BSD-style license that can be 5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file. 6 * found in the LICENSE file.
7 */ 7 */
8 8
9 #include "SkBenchmark.h" 9 #include "SkBenchmark.h"
10 #include "SkCanvas.h" 10 #include "SkCanvas.h"
11 #include "SkConfig8888.h" 11 #include "SkConfig8888.h"
12 #include "SkString.h" 12 #include "SkString.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
23 protected: 23 protected:
24 virtual const char* onGetName() SK_OVERRIDE { 24 virtual const char* onGetName() SK_OVERRIDE {
25 return fName.c_str(); 25 return fName.c_str();
26 } 26 }
27 27
28 virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE { 28 virtual void onDraw(const int loops, SkCanvas* canvas) SK_OVERRIDE {
29 canvas->clear(SK_ColorBLACK); 29 canvas->clear(SK_ColorBLACK);
30 SkISize size = canvas->getDeviceSize(); 30 SkISize size = canvas->getDeviceSize();
31 31
32 SkBitmap bmp1; 32 SkBitmap bmp1;
33 bmp1.setConfig(SkBitmap::kARGB_8888_Config, size.width(), 33 bmp1.setConfig(SkBitmap::kARGB_8888_Config, size.width(),
34 size.height()); 34 size.height());
35 bmp1.allocPixels(); 35 bmp1.allocPixels();
36 SkAutoLockPixels alp(bmp1); 36 SkAutoLockPixels alp(bmp1);
37 uint32_t* pixels = reinterpret_cast<uint32_t*>(bmp1.getPixels()); 37 uint32_t* pixels = reinterpret_cast<uint32_t*>(bmp1.getPixels());
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 for (int loop = 0; loop < this->getLoops(); ++loop) { 48 for (int loop = 0; loop < loops; ++loop) {
49 // Unpremul -> Premul 49 // Unpremul -> Premul
50 canvas->writePixels(bmp1, 0, 0, fUnPremulConfig); 50 canvas->writePixels(bmp1, 0, 0, fUnPremulConfig);
51 // Premul -> Unpremul 51 // Premul -> Unpremul
52 canvas->readPixels(&bmp2, 0, 0, fUnPremulConfig); 52 canvas->readPixels(&bmp2, 0, 0, fUnPremulConfig);
53 } 53 }
54 } 54 }
55 55
56 private: 56 private:
57 SkCanvas::Config8888 fUnPremulConfig; 57 SkCanvas::Config8888 fUnPremulConfig;
58 SkString fName; 58 SkString fName;
59 typedef SkBenchmark INHERITED; 59 typedef SkBenchmark INHERITED;
60 }; 60 };
61 61
62 62
63 DEF_BENCH(return new PremulAndUnpremulAlphaOpsBench(SkCanvas::kRGBA_Unpremul_Con fig8888)); 63 DEF_BENCH(return new PremulAndUnpremulAlphaOpsBench(SkCanvas::kRGBA_Unpremul_Con fig8888));
64 DEF_BENCH(return new PremulAndUnpremulAlphaOpsBench(SkCanvas::kNative_Unpremul_C onfig8888)); 64 DEF_BENCH(return new PremulAndUnpremulAlphaOpsBench(SkCanvas::kNative_Unpremul_C onfig8888));
OLDNEW
« no previous file with comments | « bench/PictureRecordBench.cpp ('k') | bench/RTreeBench.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698