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

Side by Side Diff: bench/RepeatTileBench.cpp

Issue 20997003: move intensive computing/rendering from bench constructor to onPreDraw. (Closed) Base URL: http://skia.googlecode.com/svn/trunk/
Patch Set: Created 7 years, 4 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
« bench/RTreeBench.cpp ('K') | « bench/RTreeBench.cpp ('k') | no next file » | 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 2011 Google Inc. 3 * Copyright 2011 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 #include "SkBenchmark.h" 8 #include "SkBenchmark.h"
9 #include "SkBitmap.h" 9 #include "SkBitmap.h"
10 #include "SkCanvas.h" 10 #include "SkCanvas.h"
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 const SkPMColor* srcP = src.getAddr32(0, y); 78 const SkPMColor* srcP = src.getAddr32(0, y);
79 uint8_t* dstP = dst->getAddr8(0, y); 79 uint8_t* dstP = dst->getAddr8(0, y);
80 for (int x = src.width() - 1; x >= 0; --x) { 80 for (int x = src.width() - 1; x >= 0; --x) {
81 *dstP++ = compute666Index(*srcP++); 81 *dstP++ = compute666Index(*srcP++);
82 } 82 }
83 } 83 }
84 } 84 }
85 85
86 class RepeatTileBench : public SkBenchmark { 86 class RepeatTileBench : public SkBenchmark {
87 SkPaint fPaint; 87 SkPaint fPaint;
88 SkString fName; 88 SkString fName;
robertphillips 2013/07/29 11:57:10 line up all the member variable names
89 SkBitmap fBitmap;
90 SkBitmap::Config fConfig;
robertphillips 2013/07/29 11:57:10 fIsOpaque
91 bool fOpaque;
89 enum { N = SkBENCHLOOP(20) }; 92 enum { N = SkBENCHLOOP(20) };
90 public: 93 public:
91 RepeatTileBench(void* param, SkBitmap::Config c, bool isOpaque = false) : IN HERITED(param) { 94 RepeatTileBench(void* param, SkBitmap::Config c, bool isOpaque = false) : IN HERITED(param) {
92 const int w = 50; 95 const int w = 50;
93 const int h = 50; 96 const int h = 50;
94 SkBitmap bm; 97 fConfig = c;
98 fOpaque = isOpaque;
95 99
96 if (SkBitmap::kIndex8_Config == c) { 100 if (SkBitmap::kIndex8_Config == fConfig) {
97 bm.setConfig(SkBitmap::kARGB_8888_Config, w, h); 101 fBitmap.setConfig(SkBitmap::kARGB_8888_Config, w, h);
98 } else { 102 } else {
99 bm.setConfig(c, w, h); 103 fBitmap.setConfig(fConfig, w, h);
100 } 104 }
101 bm.allocPixels(); 105 fName.printf("repeatTile_%s_%c",
102 bm.eraseColor(isOpaque ? SK_ColorWHITE : 0); 106 gConfigName[fBitmap.config()], isOpaque ? 'X' : 'A');
103 bm.setIsOpaque(isOpaque);
104
105 drawIntoBitmap(bm);
106
107 if (SkBitmap::kIndex8_Config == c) {
108 SkBitmap tmp;
109 convertToIndex666(bm, &tmp);
110 bm = tmp;
111 }
112
113 SkShader* s = SkShader::CreateBitmapShader(bm,
114 SkShader::kRepeat_TileMode,
115 SkShader::kRepeat_TileMode);
116 fPaint.setShader(s)->unref();
117 fName.printf("repeatTile_%s_%c", gConfigName[bm.config()], isOpaque ? 'X ' : 'A');
118 } 107 }
119 108
120 protected: 109 protected:
robertphillips 2013/07/29 11:57:10 SK_OVERRIDE
121 virtual const char* onGetName() { 110 virtual const char* onGetName() {
122 return fName.c_str(); 111 return fName.c_str();
123 } 112 }
124 113
robertphillips 2013/07/29 11:57:10 SK_OVERRIDE
114 virtual void onPreDraw() {
115 fBitmap.allocPixels();
116 fBitmap.eraseColor(fOpaque ? SK_ColorWHITE : 0);
117 fBitmap.setIsOpaque(fOpaque);
118
robertphillips 2013/07/29 11:57:10 rename to draw_into_bitmap
119 drawIntoBitmap(fBitmap);
120
121 if (SkBitmap::kIndex8_Config == fConfig) {
122 SkBitmap tmp;
robertphillips 2013/07/29 11:57:10 rename to convert_to_index666
123 convertToIndex666(fBitmap, &tmp);
124 fBitmap = tmp;
125 }
126
127 SkShader* s = SkShader::CreateBitmapShader(fBitmap,
128 SkShader::kRepeat_TileMode,
129 SkShader::kRepeat_TileMode);
130 fPaint.setShader(s)->unref();
131 }
132
133
robertphillips 2013/07/29 11:57:10 SK_OVERRIDE
125 virtual void onDraw(SkCanvas* canvas) { 134 virtual void onDraw(SkCanvas* canvas) {
126 SkPaint paint(fPaint); 135 SkPaint paint(fPaint);
127 this->setupPaint(&paint); 136 this->setupPaint(&paint);
128 137
129 for (int i = 0; i < N; i++) { 138 for (int i = 0; i < N; i++) {
130 canvas->drawPaint(paint); 139 canvas->drawPaint(paint);
131 } 140 }
132 } 141 }
133 142
134 private: 143 private:
135 typedef SkBenchmark INHERITED; 144 typedef SkBenchmark INHERITED;
136 }; 145 };
137 146
138 DEF_BENCH(return new RepeatTileBench(p, SkBitmap::kARGB_8888_Config, true)) 147 DEF_BENCH(return new RepeatTileBench(p, SkBitmap::kARGB_8888_Config, true))
139 DEF_BENCH(return new RepeatTileBench(p, SkBitmap::kARGB_8888_Config, false)) 148 DEF_BENCH(return new RepeatTileBench(p, SkBitmap::kARGB_8888_Config, false))
140 DEF_BENCH(return new RepeatTileBench(p, SkBitmap::kRGB_565_Config)) 149 DEF_BENCH(return new RepeatTileBench(p, SkBitmap::kRGB_565_Config))
141 DEF_BENCH(return new RepeatTileBench(p, SkBitmap::kIndex8_Config)) 150 DEF_BENCH(return new RepeatTileBench(p, SkBitmap::kIndex8_Config))
OLDNEW
« bench/RTreeBench.cpp ('K') | « bench/RTreeBench.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698