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

Side by Side Diff: gm/displacement.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 | « gm/colorfilterimagefilter.cpp ('k') | gm/dropshadowimagefilter.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 7
8 #include "gm.h" 8 #include "gm.h"
9 #include "SkDisplacementMapEffect.h" 9 #include "SkDisplacementMapEffect.h"
10 #include "SkBitmapSource.h" 10 #include "SkBitmapSource.h"
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 canvas->restore(); 76 canvas->restore();
77 } 77 }
78 78
79 virtual void onDraw(SkCanvas* canvas) { 79 virtual void onDraw(SkCanvas* canvas) {
80 if (!fInitialized) { 80 if (!fInitialized) {
81 make_bitmaps(); 81 make_bitmaps();
82 fInitialized = true; 82 fInitialized = true;
83 } 83 }
84 canvas->clear(0x00000000); 84 canvas->clear(0x00000000);
85 SkPaint paint; 85 SkPaint paint;
86 SkAutoTUnref<SkImageFilter> displ(SkNEW_ARGS(SkBitmapSource, (fCheckerbo ard))); 86 SkAutoTUnref<SkImageFilter> displ(SkBitmapSource::Create(fCheckerboard)) ;
87 paint.setImageFilter(SkNEW_ARGS(SkDisplacementMapEffect, 87 paint.setImageFilter(SkDisplacementMapEffect::Create(
88 (SkDisplacementMapEffect::kR_ChannelSelectorType, 88 SkDisplacementMapEffect::kR_ChannelSelectorType,
89 SkDisplacementMapEffect::kG_ChannelSelectorType, 0.0f, displ)))->un ref(); 89 SkDisplacementMapEffect::kG_ChannelSelectorType, 0.0f, displ))->unre f();
90 drawClippedBitmap(canvas, 0, 0, paint); 90 drawClippedBitmap(canvas, 0, 0, paint);
91 paint.setImageFilter(SkNEW_ARGS(SkDisplacementMapEffect, 91 paint.setImageFilter(SkDisplacementMapEffect::Create(
92 (SkDisplacementMapEffect::kB_ChannelSelectorType, 92 SkDisplacementMapEffect::kB_ChannelSelectorType,
93 SkDisplacementMapEffect::kA_ChannelSelectorType, 16.0f, displ)))->u nref(); 93 SkDisplacementMapEffect::kA_ChannelSelectorType, 16.0f, displ))->unr ef();
94 drawClippedBitmap(canvas, 100, 0, paint); 94 drawClippedBitmap(canvas, 100, 0, paint);
95 paint.setImageFilter(SkNEW_ARGS(SkDisplacementMapEffect, 95 paint.setImageFilter(SkDisplacementMapEffect::Create(
96 (SkDisplacementMapEffect::kR_ChannelSelectorType, 96 SkDisplacementMapEffect::kR_ChannelSelectorType,
97 SkDisplacementMapEffect::kB_ChannelSelectorType, 32.0f, displ)))->u nref(); 97 SkDisplacementMapEffect::kB_ChannelSelectorType, 32.0f, displ))->unr ef();
98 drawClippedBitmap(canvas, 200, 0, paint); 98 drawClippedBitmap(canvas, 200, 0, paint);
99 paint.setImageFilter(SkNEW_ARGS(SkDisplacementMapEffect, 99 paint.setImageFilter(SkDisplacementMapEffect::Create(
100 (SkDisplacementMapEffect::kG_ChannelSelectorType, 100 SkDisplacementMapEffect::kG_ChannelSelectorType,
101 SkDisplacementMapEffect::kA_ChannelSelectorType, 48.0f, displ)))->u nref(); 101 SkDisplacementMapEffect::kA_ChannelSelectorType, 48.0f, displ))->unr ef();
102 drawClippedBitmap(canvas, 300, 0, paint); 102 drawClippedBitmap(canvas, 300, 0, paint);
103 paint.setImageFilter(SkNEW_ARGS(SkDisplacementMapEffect, 103 paint.setImageFilter(SkDisplacementMapEffect::Create(
104 (SkDisplacementMapEffect::kR_ChannelSelectorType, 104 SkDisplacementMapEffect::kR_ChannelSelectorType,
105 SkDisplacementMapEffect::kA_ChannelSelectorType, 64.0f, displ)))->u nref(); 105 SkDisplacementMapEffect::kA_ChannelSelectorType, 64.0f, displ))->unr ef();
106 drawClippedBitmap(canvas, 400, 0, paint); 106 drawClippedBitmap(canvas, 400, 0, paint);
107 107
108 paint.setImageFilter(SkNEW_ARGS(SkDisplacementMapEffect, 108 paint.setImageFilter(SkDisplacementMapEffect::Create(
109 (SkDisplacementMapEffect::kR_ChannelSelectorType, 109 SkDisplacementMapEffect::kR_ChannelSelectorType,
110 SkDisplacementMapEffect::kG_ChannelSelectorType, 40.0f, displ)))->u nref(); 110 SkDisplacementMapEffect::kG_ChannelSelectorType, 40.0f, displ))->unr ef();
111 drawClippedBitmap(canvas, 0, 100, paint); 111 drawClippedBitmap(canvas, 0, 100, paint);
112 paint.setImageFilter(SkNEW_ARGS(SkDisplacementMapEffect, 112 paint.setImageFilter(SkDisplacementMapEffect::Create(
113 (SkDisplacementMapEffect::kB_ChannelSelectorType, 113 SkDisplacementMapEffect::kB_ChannelSelectorType,
114 SkDisplacementMapEffect::kA_ChannelSelectorType, 40.0f, displ)))->u nref(); 114 SkDisplacementMapEffect::kA_ChannelSelectorType, 40.0f, displ))->unr ef();
115 drawClippedBitmap(canvas, 100, 100, paint); 115 drawClippedBitmap(canvas, 100, 100, paint);
116 paint.setImageFilter(SkNEW_ARGS(SkDisplacementMapEffect, 116 paint.setImageFilter(SkDisplacementMapEffect::Create(
117 (SkDisplacementMapEffect::kR_ChannelSelectorType, 117 SkDisplacementMapEffect::kR_ChannelSelectorType,
118 SkDisplacementMapEffect::kB_ChannelSelectorType, 40.0f, displ)))->u nref(); 118 SkDisplacementMapEffect::kB_ChannelSelectorType, 40.0f, displ))->unr ef();
119 drawClippedBitmap(canvas, 200, 100, paint); 119 drawClippedBitmap(canvas, 200, 100, paint);
120 paint.setImageFilter(SkNEW_ARGS(SkDisplacementMapEffect, 120 paint.setImageFilter(SkDisplacementMapEffect::Create(
121 (SkDisplacementMapEffect::kG_ChannelSelectorType, 121 SkDisplacementMapEffect::kG_ChannelSelectorType,
122 SkDisplacementMapEffect::kA_ChannelSelectorType, 40.0f, displ)))->u nref(); 122 SkDisplacementMapEffect::kA_ChannelSelectorType, 40.0f, displ))->unr ef();
123 drawClippedBitmap(canvas, 300, 100, paint); 123 drawClippedBitmap(canvas, 300, 100, paint);
124 paint.setImageFilter(SkNEW_ARGS(SkDisplacementMapEffect, 124 paint.setImageFilter(SkDisplacementMapEffect::Create(
125 (SkDisplacementMapEffect::kR_ChannelSelectorType, 125 SkDisplacementMapEffect::kR_ChannelSelectorType,
126 SkDisplacementMapEffect::kA_ChannelSelectorType, 40.0f, displ)))->u nref(); 126 SkDisplacementMapEffect::kA_ChannelSelectorType, 40.0f, displ))->unr ef();
127 drawClippedBitmap(canvas, 400, 100, paint); 127 drawClippedBitmap(canvas, 400, 100, paint);
128 128
129 SkImageFilter::CropRect cropRect(SkRect::MakeXYWH(30, 30, 40, 40)); 129 SkImageFilter::CropRect cropRect(SkRect::MakeXYWH(30, 30, 40, 40));
130 paint.setImageFilter(SkNEW_ARGS(SkDisplacementMapEffect, 130 paint.setImageFilter(SkDisplacementMapEffect::Create(
131 (SkDisplacementMapEffect::kR_ChannelSelectorType, 131 SkDisplacementMapEffect::kR_ChannelSelectorType,
132 SkDisplacementMapEffect::kG_ChannelSelectorType, 132 SkDisplacementMapEffect::kG_ChannelSelectorType,
133 0.0f, displ, NULL, &cropRect)))->unref(); 133 0.0f, displ, NULL, &cropRect))->unref();
134 drawClippedBitmap(canvas, 0, 200, paint); 134 drawClippedBitmap(canvas, 0, 200, paint);
135 paint.setImageFilter(SkNEW_ARGS(SkDisplacementMapEffect, 135 paint.setImageFilter(SkDisplacementMapEffect::Create(
136 (SkDisplacementMapEffect::kB_ChannelSelectorType, 136 SkDisplacementMapEffect::kB_ChannelSelectorType,
137 SkDisplacementMapEffect::kA_ChannelSelectorType, 137 SkDisplacementMapEffect::kA_ChannelSelectorType,
138 16.0f, displ, NULL, &cropRect)))->unref(); 138 16.0f, displ, NULL, &cropRect))->unref();
139 drawClippedBitmap(canvas, 100, 200, paint); 139 drawClippedBitmap(canvas, 100, 200, paint);
140 paint.setImageFilter(SkNEW_ARGS(SkDisplacementMapEffect, 140 paint.setImageFilter(SkDisplacementMapEffect::Create(
141 (SkDisplacementMapEffect::kR_ChannelSelectorType, 141 SkDisplacementMapEffect::kR_ChannelSelectorType,
142 SkDisplacementMapEffect::kB_ChannelSelectorType, 142 SkDisplacementMapEffect::kB_ChannelSelectorType,
143 32.0f, displ, NULL, &cropRect)))->unref(); 143 32.0f, displ, NULL, &cropRect))->unref();
144 drawClippedBitmap(canvas, 200, 200, paint); 144 drawClippedBitmap(canvas, 200, 200, paint);
145 paint.setImageFilter(SkNEW_ARGS(SkDisplacementMapEffect, 145 paint.setImageFilter(SkDisplacementMapEffect::Create(
146 (SkDisplacementMapEffect::kG_ChannelSelectorType, 146 SkDisplacementMapEffect::kG_ChannelSelectorType,
147 SkDisplacementMapEffect::kA_ChannelSelectorType, 147 SkDisplacementMapEffect::kA_ChannelSelectorType,
148 48.0f, displ, NULL, &cropRect)))->unref(); 148 48.0f, displ, NULL, &cropRect))->unref();
149 drawClippedBitmap(canvas, 300, 200, paint); 149 drawClippedBitmap(canvas, 300, 200, paint);
150 paint.setImageFilter(SkNEW_ARGS(SkDisplacementMapEffect, 150 paint.setImageFilter(SkDisplacementMapEffect::Create(
151 (SkDisplacementMapEffect::kR_ChannelSelectorType, 151 SkDisplacementMapEffect::kR_ChannelSelectorType,
152 SkDisplacementMapEffect::kA_ChannelSelectorType, 152 SkDisplacementMapEffect::kA_ChannelSelectorType,
153 64.0f, displ, NULL, &cropRect)))->unref(); 153 64.0f, displ, NULL, &cropRect))->unref();
154 drawClippedBitmap(canvas, 400, 200, paint); 154 drawClippedBitmap(canvas, 400, 200, paint);
155 155
156 paint.setImageFilter(SkNEW_ARGS(SkDisplacementMapEffect, 156 paint.setImageFilter(SkDisplacementMapEffect::Create(
157 (SkDisplacementMapEffect::kR_ChannelSelectorType, 157 SkDisplacementMapEffect::kR_ChannelSelectorType,
158 SkDisplacementMapEffect::kG_ChannelSelectorType, 158 SkDisplacementMapEffect::kG_ChannelSelectorType,
159 40.0f, displ, NULL, &cropRect)))->unref(); 159 40.0f, displ, NULL, &cropRect))->unref();
160 drawClippedBitmap(canvas, 0, 300, paint); 160 drawClippedBitmap(canvas, 0, 300, paint);
161 paint.setImageFilter(SkNEW_ARGS(SkDisplacementMapEffect, 161 paint.setImageFilter(SkDisplacementMapEffect::Create(
162 (SkDisplacementMapEffect::kB_ChannelSelectorType, 162 SkDisplacementMapEffect::kB_ChannelSelectorType,
163 SkDisplacementMapEffect::kA_ChannelSelectorType, 163 SkDisplacementMapEffect::kA_ChannelSelectorType,
164 40.0f, displ, NULL, &cropRect)))->unref(); 164 40.0f, displ, NULL, &cropRect))->unref();
165 drawClippedBitmap(canvas, 100, 300, paint); 165 drawClippedBitmap(canvas, 100, 300, paint);
166 paint.setImageFilter(SkNEW_ARGS(SkDisplacementMapEffect, 166 paint.setImageFilter(SkDisplacementMapEffect::Create(
167 (SkDisplacementMapEffect::kR_ChannelSelectorType, 167 SkDisplacementMapEffect::kR_ChannelSelectorType,
168 SkDisplacementMapEffect::kB_ChannelSelectorType, 168 SkDisplacementMapEffect::kB_ChannelSelectorType,
169 40.0f, displ, NULL, &cropRect)))->unref(); 169 40.0f, displ, NULL, &cropRect))->unref();
170 drawClippedBitmap(canvas, 200, 300, paint); 170 drawClippedBitmap(canvas, 200, 300, paint);
171 paint.setImageFilter(SkNEW_ARGS(SkDisplacementMapEffect, 171 paint.setImageFilter(SkDisplacementMapEffect::Create(
172 (SkDisplacementMapEffect::kG_ChannelSelectorType, 172 SkDisplacementMapEffect::kG_ChannelSelectorType,
173 SkDisplacementMapEffect::kA_ChannelSelectorType, 173 SkDisplacementMapEffect::kA_ChannelSelectorType,
174 40.0f, displ, NULL, &cropRect)))->unref(); 174 40.0f, displ, NULL, &cropRect))->unref();
175 drawClippedBitmap(canvas, 300, 300, paint); 175 drawClippedBitmap(canvas, 300, 300, paint);
176 paint.setImageFilter(SkNEW_ARGS(SkDisplacementMapEffect, 176 paint.setImageFilter(SkDisplacementMapEffect::Create(
177 (SkDisplacementMapEffect::kR_ChannelSelectorType, 177 SkDisplacementMapEffect::kR_ChannelSelectorType,
178 SkDisplacementMapEffect::kA_ChannelSelectorType, 178 SkDisplacementMapEffect::kA_ChannelSelectorType,
179 40.0f, displ, NULL, &cropRect)))->unref(); 179 40.0f, displ, NULL, &cropRect))->unref();
180 drawClippedBitmap(canvas, 400, 300, paint); 180 drawClippedBitmap(canvas, 400, 300, paint);
181 181
182 // Tests for images of different sizes 182 // Tests for images of different sizes
183 displ.reset(SkNEW_ARGS(SkBitmapSource, (fSmall))); 183 displ.reset(SkBitmapSource::Create(fSmall));
184 paint.setImageFilter(SkNEW_ARGS(SkDisplacementMapEffect, 184 paint.setImageFilter(SkDisplacementMapEffect::Create(
185 (SkDisplacementMapEffect::kR_ChannelSelectorType, 185 SkDisplacementMapEffect::kR_ChannelSelectorType,
186 SkDisplacementMapEffect::kG_ChannelSelectorType, 186 SkDisplacementMapEffect::kG_ChannelSelectorType,
187 40.0f, displ)))->unref(); 187 40.0f, displ))->unref();
188 drawClippedBitmap(canvas, 0, 400, paint); 188 drawClippedBitmap(canvas, 0, 400, paint);
189 displ.reset(SkNEW_ARGS(SkBitmapSource, (fLarge))); 189 displ.reset(SkBitmapSource::Create(fLarge));
190 paint.setImageFilter(SkNEW_ARGS(SkDisplacementMapEffect, 190 paint.setImageFilter(SkDisplacementMapEffect::Create(
191 (SkDisplacementMapEffect::kB_ChannelSelectorType, 191 SkDisplacementMapEffect::kB_ChannelSelectorType,
192 SkDisplacementMapEffect::kA_ChannelSelectorType, 192 SkDisplacementMapEffect::kA_ChannelSelectorType,
193 40.0f, displ)))->unref(); 193 40.0f, displ))->unref();
194 drawClippedBitmap(canvas, 100, 400, paint); 194 drawClippedBitmap(canvas, 100, 400, paint);
195 displ.reset(SkNEW_ARGS(SkBitmapSource, (fLargeW))); 195 displ.reset(SkBitmapSource::Create(fLargeW));
196 paint.setImageFilter(SkNEW_ARGS(SkDisplacementMapEffect, 196 paint.setImageFilter(SkDisplacementMapEffect::Create(
197 (SkDisplacementMapEffect::kR_ChannelSelectorType, 197 SkDisplacementMapEffect::kR_ChannelSelectorType,
198 SkDisplacementMapEffect::kB_ChannelSelectorType, 198 SkDisplacementMapEffect::kB_ChannelSelectorType,
199 40.0f, displ)))->unref(); 199 40.0f, displ))->unref();
200 drawClippedBitmap(canvas, 200, 400, paint); 200 drawClippedBitmap(canvas, 200, 400, paint);
201 displ.reset(SkNEW_ARGS(SkBitmapSource, (fLargeH))); 201 displ.reset(SkBitmapSource::Create(fLargeH));
202 paint.setImageFilter(SkNEW_ARGS(SkDisplacementMapEffect, 202 paint.setImageFilter(SkDisplacementMapEffect::Create(
203 (SkDisplacementMapEffect::kG_ChannelSelectorType, 203 SkDisplacementMapEffect::kG_ChannelSelectorType,
204 SkDisplacementMapEffect::kA_ChannelSelectorType, 204 SkDisplacementMapEffect::kA_ChannelSelectorType,
205 40.0f, displ)))->unref(); 205 40.0f, displ))->unref();
206 drawClippedBitmap(canvas, 300, 400, paint); 206 drawClippedBitmap(canvas, 300, 400, paint);
207 207
208 // Test for no given displacement input. In this case, both displacement 208 // Test for no given displacement input. In this case, both displacement
209 // and color should use the same bitmap, given to SkCanvas::drawBitmap() 209 // and color should use the same bitmap, given to SkCanvas::drawBitmap()
210 // as an input argument. 210 // as an input argument.
211 paint.setImageFilter(SkNEW_ARGS(SkDisplacementMapEffect, 211 paint.setImageFilter(SkDisplacementMapEffect::Create(
212 (SkDisplacementMapEffect::kG_ChannelSelectorType, 212 SkDisplacementMapEffect::kG_ChannelSelectorType,
213 SkDisplacementMapEffect::kA_ChannelSelectorType, 213 SkDisplacementMapEffect::kA_ChannelSelectorType,
214 40.0f, NULL)))->unref(); 214 40.0f, NULL))->unref();
215 drawClippedBitmap(canvas, 400, 400, paint); 215 drawClippedBitmap(canvas, 400, 400, paint);
216 } 216 }
217 217
218 private: 218 private:
219 typedef GM INHERITED; 219 typedef GM INHERITED;
220 SkBitmap fBitmap, fCheckerboard, fSmall, fLarge, fLargeW, fLargeH; 220 SkBitmap fBitmap, fCheckerboard, fSmall, fLarge, fLargeW, fLargeH;
221 bool fInitialized; 221 bool fInitialized;
222 }; 222 };
223 223
224 ////////////////////////////////////////////////////////////////////////////// 224 //////////////////////////////////////////////////////////////////////////////
225 225
226 static GM* MyFactory(void*) { return new DisplacementMapGM; } 226 static GM* MyFactory(void*) { return new DisplacementMapGM; }
227 static GMRegistry reg(MyFactory); 227 static GMRegistry reg(MyFactory);
228 228
229 } 229 }
OLDNEW
« no previous file with comments | « gm/colorfilterimagefilter.cpp ('k') | gm/dropshadowimagefilter.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698