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

Side by Side Diff: bench/DisplacementBench.cpp

Issue 182983003: Factory methods for heap-allocated SkImageFilter objects. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Rebase 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
« no previous file with comments | « bench/BlurImageFilterBench.cpp ('k') | bench/MagnifierBench.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 * Copyright 2013 Google Inc. 2 * Copyright 2013 Google Inc.
3 * 3 *
4 * 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
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 #include "SkBenchmark.h" 7 #include "SkBenchmark.h"
8 #include "SkBitmapDevice.h" 8 #include "SkBitmapDevice.h"
9 #include "SkBitmapSource.h" 9 #include "SkBitmapSource.h"
10 #include "SkCanvas.h" 10 #include "SkCanvas.h"
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 DisplacementZeroBench(bool small) : INHERITED(small) { 94 DisplacementZeroBench(bool small) : INHERITED(small) {
95 } 95 }
96 96
97 protected: 97 protected:
98 virtual const char* onGetName() SK_OVERRIDE { 98 virtual const char* onGetName() SK_OVERRIDE {
99 return this->isSmall() ? "displacement_zero_small" : "displacement_zero_ large"; 99 return this->isSmall() ? "displacement_zero_small" : "displacement_zero_ large";
100 } 100 }
101 101
102 virtual void onDraw(const int loops, SkCanvas* canvas) SK_OVERRIDE { 102 virtual void onDraw(const int loops, SkCanvas* canvas) SK_OVERRIDE {
103 SkPaint paint; 103 SkPaint paint;
104 SkAutoTUnref<SkImageFilter> displ(SkNEW_ARGS(SkBitmapSource, (fCheckerbo ard))); 104 SkAutoTUnref<SkImageFilter> displ(SkBitmapSource::Create(fCheckerboard)) ;
105 // No displacement effect 105 // No displacement effect
106 paint.setImageFilter(SkNEW_ARGS(SkDisplacementMapEffect, 106 paint.setImageFilter(SkDisplacementMapEffect::Create(
107 (SkDisplacementMapEffect::kR_ChannelSelectorType, 107 SkDisplacementMapEffect::kR_ChannelSelectorType,
108 SkDisplacementMapEffect::kG_ChannelSelectorType, 0.0f, displ)))->un ref(); 108 SkDisplacementMapEffect::kG_ChannelSelectorType, 0.0f, displ))->unre f();
109 109
110 for (int i = 0; i < loops; i++) { 110 for (int i = 0; i < loops; i++) {
111 this->drawClippedBitmap(canvas, 0, 0, paint); 111 this->drawClippedBitmap(canvas, 0, 0, paint);
112 } 112 }
113 } 113 }
114 114
115 private: 115 private:
116 typedef DisplacementBaseBench INHERITED; 116 typedef DisplacementBaseBench INHERITED;
117 }; 117 };
118 118
119 class DisplacementAlphaBench : public DisplacementBaseBench { 119 class DisplacementAlphaBench : public DisplacementBaseBench {
120 public: 120 public:
121 DisplacementAlphaBench(bool small) : INHERITED(small) { 121 DisplacementAlphaBench(bool small) : INHERITED(small) {
122 } 122 }
123 123
124 protected: 124 protected:
125 virtual const char* onGetName() SK_OVERRIDE { 125 virtual const char* onGetName() SK_OVERRIDE {
126 return isSmall() ? "displacement_alpha_small" : "displacement_alpha_larg e"; 126 return isSmall() ? "displacement_alpha_small" : "displacement_alpha_larg e";
127 } 127 }
128 128
129 virtual void onDraw(const int loops, SkCanvas* canvas) SK_OVERRIDE { 129 virtual void onDraw(const int loops, SkCanvas* canvas) SK_OVERRIDE {
130 SkPaint paint; 130 SkPaint paint;
131 SkAutoTUnref<SkImageFilter> displ(SkNEW_ARGS(SkBitmapSource, (fCheckerbo ard))); 131 SkAutoTUnref<SkImageFilter> displ(SkBitmapSource::Create(fCheckerboard)) ;
132 // Displacement, with 1 alpha component (which isn't pre-multiplied) 132 // Displacement, with 1 alpha component (which isn't pre-multiplied)
133 paint.setImageFilter(SkNEW_ARGS(SkDisplacementMapEffect, 133 paint.setImageFilter(SkDisplacementMapEffect::Create(
134 (SkDisplacementMapEffect::kB_ChannelSelectorType, 134 SkDisplacementMapEffect::kB_ChannelSelectorType,
135 SkDisplacementMapEffect::kA_ChannelSelectorType, 16.0f, displ)))->u nref(); 135 SkDisplacementMapEffect::kA_ChannelSelectorType, 16.0f, displ))->unr ef();
136 for (int i = 0; i < loops; i++) { 136 for (int i = 0; i < loops; i++) {
137 drawClippedBitmap(canvas, 100, 0, paint); 137 drawClippedBitmap(canvas, 100, 0, paint);
138 } 138 }
139 } 139 }
140 140
141 private: 141 private:
142 typedef DisplacementBaseBench INHERITED; 142 typedef DisplacementBaseBench INHERITED;
143 }; 143 };
144 144
145 class DisplacementFullBench : public DisplacementBaseBench { 145 class DisplacementFullBench : public DisplacementBaseBench {
146 public: 146 public:
147 DisplacementFullBench(bool small) : INHERITED(small) { 147 DisplacementFullBench(bool small) : INHERITED(small) {
148 } 148 }
149 149
150 protected: 150 protected:
151 virtual const char* onGetName() SK_OVERRIDE { 151 virtual const char* onGetName() SK_OVERRIDE {
152 return isSmall() ? "displacement_full_small" : "displacement_full_large" ; 152 return isSmall() ? "displacement_full_small" : "displacement_full_large" ;
153 } 153 }
154 154
155 virtual void onDraw(const int loops, SkCanvas* canvas) SK_OVERRIDE { 155 virtual void onDraw(const int loops, SkCanvas* canvas) SK_OVERRIDE {
156 SkPaint paint; 156 SkPaint paint;
157 SkAutoTUnref<SkImageFilter> displ(SkNEW_ARGS(SkBitmapSource, (fCheckerbo ard))); 157 SkAutoTUnref<SkImageFilter> displ(SkBitmapSource::Create(fCheckerboard)) ;
158 // Displacement, with 2 non-alpha components 158 // Displacement, with 2 non-alpha components
159 paint.setImageFilter(SkNEW_ARGS(SkDisplacementMapEffect, 159 paint.setImageFilter(SkDisplacementMapEffect::Create(
160 (SkDisplacementMapEffect::kR_ChannelSelectorType, 160 SkDisplacementMapEffect::kR_ChannelSelectorType,
161 SkDisplacementMapEffect::kB_ChannelSelectorType, 32.0f, displ)))->u nref(); 161 SkDisplacementMapEffect::kB_ChannelSelectorType, 32.0f, displ))->unr ef();
162 for (int i = 0; i < loops; ++i) { 162 for (int i = 0; i < loops; ++i) {
163 this->drawClippedBitmap(canvas, 200, 0, paint); 163 this->drawClippedBitmap(canvas, 200, 0, paint);
164 } 164 }
165 } 165 }
166 166
167 private: 167 private:
168 typedef DisplacementBaseBench INHERITED; 168 typedef DisplacementBaseBench INHERITED;
169 }; 169 };
170 170
171 /////////////////////////////////////////////////////////////////////////////// 171 ///////////////////////////////////////////////////////////////////////////////
172 172
173 DEF_BENCH( return new DisplacementZeroBench(true); ) 173 DEF_BENCH( return new DisplacementZeroBench(true); )
174 DEF_BENCH( return new DisplacementAlphaBench(true); ) 174 DEF_BENCH( return new DisplacementAlphaBench(true); )
175 DEF_BENCH( return new DisplacementFullBench(true); ) 175 DEF_BENCH( return new DisplacementFullBench(true); )
176 DEF_BENCH( return new DisplacementZeroBench(false); ) 176 DEF_BENCH( return new DisplacementZeroBench(false); )
177 DEF_BENCH( return new DisplacementAlphaBench(false); ) 177 DEF_BENCH( return new DisplacementAlphaBench(false); )
178 DEF_BENCH( return new DisplacementFullBench(false); ) 178 DEF_BENCH( return new DisplacementFullBench(false); )
OLDNEW
« no previous file with comments | « bench/BlurImageFilterBench.cpp ('k') | bench/MagnifierBench.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698