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

Side by Side Diff: bench/WritePixelsBench.cpp

Issue 180113010: Add SkCanvas::writePixels that takes info+pixels directly (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Created 6 years, 9 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 | « bench/PremulAndUnpremulAlphaOpsBench.cpp ('k') | gyp/bench.gyp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
12 #include "SkString.h" 10 #include "SkString.h"
13 11
14 class WritePixelsBench : public SkBenchmark { 12 class WritePixelsBench : public SkBenchmark {
15 public: 13 public:
16 WritePixelsBench(SkCanvas::Config8888 config) 14 WritePixelsBench(SkColorType ct, SkAlphaType at)
17 : fConfig(config) 15 : fColorType(ct)
18 , fName("writepix") { 16 , fAlphaType(at)
19 switch (config) { 17 , fName("writepix")
20 case SkCanvas::kNative_Premul_Config8888: 18 {
21 fName.append("_native_PM"); 19 switch (ct) {
20 case kRGBA_8888_SkColorType:
21 fName.append("_RGBA");
22 break; 22 break;
23 case SkCanvas::kNative_Unpremul_Config8888: 23 case kBGRA_8888_SkColorType:
24 fName.append("_native_UPM"); 24 fName.append("_BGRA");
25 break;
26 case SkCanvas::kBGRA_Premul_Config8888:
27 fName.append("_bgra_PM");
28 break;
29 case SkCanvas::kBGRA_Unpremul_Config8888:
30 fName.append("_bgra_UPM");
31 break;
32 case SkCanvas::kRGBA_Premul_Config8888:
33 fName.append("_rgba_PM");
34 break;
35 case SkCanvas::kRGBA_Unpremul_Config8888:
36 fName.append("_rgba_UPM");
37 break; 25 break;
38 default: 26 default:
39 SK_CRASH(); 27 SkASSERT(0);
28 break;
29 }
30 switch (at) {
31 case kPremul_SkAlphaType:
32 fName.append("_PM");
33 break;
34 case kUnpremul_SkAlphaType:
35 fName.append("_UPM");
36 break;
37 default:
38 SkASSERT(0);
40 break; 39 break;
41 } 40 }
42 } 41 }
43 42
44 protected: 43 protected:
45 virtual const char* onGetName() SK_OVERRIDE { 44 virtual const char* onGetName() SK_OVERRIDE {
46 return fName.c_str(); 45 return fName.c_str();
47 } 46 }
48 47
49 virtual void onDraw(const int loops, SkCanvas* canvas) SK_OVERRIDE { 48 virtual void onDraw(const int loops, SkCanvas* canvas) SK_OVERRIDE {
50 SkISize size = canvas->getDeviceSize(); 49 SkISize size = canvas->getDeviceSize();
51 50
52 canvas->clear(0xFFFF0000); 51 canvas->clear(0xFFFF0000);
53 52
54 SkBitmap bmp; 53 SkBitmap bmp;
55 bmp.setConfig(SkBitmap::kARGB_8888_Config, size.width(), size.height()); 54 bmp.allocN32Pixels(size.width(), size.height());
56 canvas->readPixels(&bmp, 0, 0); 55 canvas->readPixels(&bmp, 0, 0);
57 56
57 SkImageInfo info = bmp.info();
58 info.fColorType = fColorType;
59 info.fAlphaType = fAlphaType;
60
58 for (int loop = 0; loop < loops; ++loop) { 61 for (int loop = 0; loop < loops; ++loop) {
59 canvas->writePixels(bmp, 0, 0, fConfig); 62 canvas->writePixels(info, bmp.getPixels(), bmp.rowBytes(), 0, 0);
60 } 63 }
61 } 64 }
62 65
63 private: 66 private:
64 SkCanvas::Config8888 fConfig; 67 SkColorType fColorType;
65 SkString fName; 68 SkAlphaType fAlphaType;
69 SkString fName;
66 70
67 typedef SkBenchmark INHERITED; 71 typedef SkBenchmark INHERITED;
68 }; 72 };
69 73
70 ////////////////////////////////////////////////////////////////////////////// 74 //////////////////////////////////////////////////////////////////////////////
71 75
72 DEF_BENCH( return SkNEW_ARGS(WritePixelsBench, (SkCanvas::kRGBA_Premul_Config888 8)); ) 76 DEF_BENCH( return SkNEW_ARGS(WritePixelsBench, (kRGBA_8888_SkColorType, kPremul_ SkAlphaType)); )
73 DEF_BENCH( return SkNEW_ARGS(WritePixelsBench, (SkCanvas::kRGBA_Unpremul_Config8 888)); ) 77 DEF_BENCH( return SkNEW_ARGS(WritePixelsBench, (kRGBA_8888_SkColorType, kUnpremu l_SkAlphaType)); )
OLDNEW
« no previous file with comments | « bench/PremulAndUnpremulAlphaOpsBench.cpp ('k') | gyp/bench.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698