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

Side by Side Diff: tests/ImageFilterTest.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 | « tests/GLProgramsTest.cpp ('k') | tests/SerializationTest.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 "SkBicubicImageFilter.h" 8 #include "SkBicubicImageFilter.h"
9 #include "SkBitmap.h" 9 #include "SkBitmap.h"
10 #include "SkBitmapDevice.h" 10 #include "SkBitmapDevice.h"
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
161 161
162 { 162 {
163 // This tests for : 163 // This tests for :
164 // 1 ) location at (0,0,1) 164 // 1 ) location at (0,0,1)
165 SkPoint3 location(0, 0, SK_Scalar1); 165 SkPoint3 location(0, 0, SK_Scalar1);
166 // 2 ) location and target at same value 166 // 2 ) location and target at same value
167 SkPoint3 target(location.fX, location.fY, location.fZ); 167 SkPoint3 target(location.fX, location.fY, location.fZ);
168 // 3 ) large negative specular exponent value 168 // 3 ) large negative specular exponent value
169 SkScalar specularExponent = -1000; 169 SkScalar specularExponent = -1000;
170 170
171 SkAutoTUnref<SkImageFilter> bmSrc(new SkBitmapSource(bitmap)); 171 SkAutoTUnref<SkImageFilter> bmSrc(SkBitmapSource::Create(bitmap));
172 SkPaint paint; 172 SkPaint paint;
173 paint.setImageFilter(SkLightingImageFilter::CreateSpotLitSpecular( 173 paint.setImageFilter(SkLightingImageFilter::CreateSpotLitSpecular(
174 location, target, specularExponent, 180, 174 location, target, specularExponent, 180,
175 0xFFFFFFFF, SK_Scalar1, SK_Scalar1, SK_Scalar1, 175 0xFFFFFFFF, SK_Scalar1, SK_Scalar1, SK_Scalar1,
176 bmSrc))->unref(); 176 bmSrc))->unref();
177 SkCanvas canvas(result); 177 SkCanvas canvas(result);
178 SkRect r = SkRect::MakeWH(SkIntToScalar(kBitmapSize), 178 SkRect r = SkRect::MakeWH(SkIntToScalar(kBitmapSize),
179 SkIntToScalar(kBitmapSize)); 179 SkIntToScalar(kBitmapSize));
180 canvas.drawRect(r, paint); 180 canvas.drawRect(r, paint);
181 } 181 }
182 182
183 { 183 {
184 // This tests for scale bringing width to 0 184 // This tests for scale bringing width to 0
185 SkSize scale = SkSize::Make(-0.001f, SK_Scalar1); 185 SkSize scale = SkSize::Make(-0.001f, SK_Scalar1);
186 SkAutoTUnref<SkImageFilter> bmSrc(new SkBitmapSource(bitmap)); 186 SkAutoTUnref<SkImageFilter> bmSrc(SkBitmapSource::Create(bitmap));
187 SkAutoTUnref<SkBicubicImageFilter> bicubic( 187 SkAutoTUnref<SkBicubicImageFilter> bicubic(
188 SkBicubicImageFilter::CreateMitchell(scale, bmSrc)); 188 SkBicubicImageFilter::CreateMitchell(scale, bmSrc));
189 SkBitmapDevice device(bitmap); 189 SkBitmapDevice device(bitmap);
190 SkDeviceImageFilterProxy proxy(&device); 190 SkDeviceImageFilterProxy proxy(&device);
191 SkIPoint loc = SkIPoint::Make(0, 0); 191 SkIPoint loc = SkIPoint::Make(0, 0);
192 // An empty input should early return and return false 192 // An empty input should early return and return false
193 REPORTER_ASSERT(reporter, 193 REPORTER_ASSERT(reporter,
194 !bicubic->filterImage(&proxy, bitmap, SkMatrix::I(), &result, &loc)); 194 !bicubic->filterImage(&proxy, bitmap, SkMatrix::I(), &result, &loc));
195 } 195 }
196 } 196 }
(...skipping 18 matching lines...) Expand all
215 SkScalar kernel[9] = { 215 SkScalar kernel[9] = {
216 SkIntToScalar( 1), SkIntToScalar( 1), SkIntToScalar( 1), 216 SkIntToScalar( 1), SkIntToScalar( 1), SkIntToScalar( 1),
217 SkIntToScalar( 1), SkIntToScalar(-7), SkIntToScalar( 1), 217 SkIntToScalar( 1), SkIntToScalar(-7), SkIntToScalar( 1),
218 SkIntToScalar( 1), SkIntToScalar( 1), SkIntToScalar( 1), 218 SkIntToScalar( 1), SkIntToScalar( 1), SkIntToScalar( 1),
219 }; 219 };
220 SkISize kernelSize = SkISize::Make(3, 3); 220 SkISize kernelSize = SkISize::Make(3, 3);
221 SkScalar gain = SK_Scalar1, bias = 0; 221 SkScalar gain = SK_Scalar1, bias = 0;
222 222
223 SkImageFilter* filters[] = { 223 SkImageFilter* filters[] = {
224 SkColorFilterImageFilter::Create(cf.get(), input.get(), &cropRect), 224 SkColorFilterImageFilter::Create(cf.get(), input.get(), &cropRect),
225 new SkDisplacementMapEffect(SkDisplacementMapEffect::kR_ChannelSelectorT ype, 225 SkDisplacementMapEffect::Create(SkDisplacementMapEffect::kR_ChannelSelec torType,
226 SkDisplacementMapEffect::kB_ChannelSelectorT ype, 226 SkDisplacementMapEffect::kB_ChannelSelec torType,
227 40.0f, input.get(), input.get(), &cropRect), 227 40.0f, input.get(), input.get(), &cropRe ct),
228 new SkBlurImageFilter(SK_Scalar1, SK_Scalar1, input.get(), &cropRect), 228 SkBlurImageFilter::Create(SK_Scalar1, SK_Scalar1, input.get(), &cropRect ),
229 new SkDropShadowImageFilter(SK_Scalar1, SK_Scalar1, SK_Scalar1, SK_Scala r1, SK_ColorGREEN, input.get(), &cropRect), 229 SkDropShadowImageFilter::Create(SK_Scalar1, SK_Scalar1, SK_Scalar1, SK_S calar1, SK_ColorGREEN, input.get(), &cropRect),
230 SkLightingImageFilter::CreatePointLitDiffuse(location, SK_ColorGREEN, 0, 0, input.get(), &cropRect), 230 SkLightingImageFilter::CreatePointLitDiffuse(location, SK_ColorGREEN, 0, 0, input.get(), &cropRect),
231 SkLightingImageFilter::CreatePointLitSpecular(location, SK_ColorGREEN, 0 , 0, 0, input.get(), &cropRect), 231 SkLightingImageFilter::CreatePointLitSpecular(location, SK_ColorGREEN, 0 , 0, 0, input.get(), &cropRect),
232 new SkMatrixConvolutionImageFilter(kernelSize, kernel, gain, bias, SkIPo int::Make(1, 1), SkMatrixConvolutionImageFilter::kRepeat_TileMode, false, input. get(), &cropRect), 232 SkMatrixConvolutionImageFilter::Create(kernelSize, kernel, gain, bias, S kIPoint::Make(1, 1), SkMatrixConvolutionImageFilter::kRepeat_TileMode, false, in put.get(), &cropRect),
233 new SkMergeImageFilter(input.get(), input.get(), SkXfermode::kSrcOver_Mo de, &cropRect), 233 SkMergeImageFilter::Create(input.get(), input.get(), SkXfermode::kSrcOve r_Mode, &cropRect),
234 new SkOffsetImageFilter(SK_Scalar1, SK_Scalar1, input.get(), &cropRect), 234 SkOffsetImageFilter::Create(SK_Scalar1, SK_Scalar1, input.get(), &cropRe ct),
235 new SkOffsetImageFilter(SK_Scalar1, SK_Scalar1, input.get(), &cropRect), 235 SkOffsetImageFilter::Create(SK_Scalar1, SK_Scalar1, input.get(), &cropRe ct),
236 new SkDilateImageFilter(3, 2, input.get(), &cropRect), 236 SkDilateImageFilter::Create(3, 2, input.get(), &cropRect),
237 new SkErodeImageFilter(2, 3, input.get(), &cropRect), 237 SkErodeImageFilter::Create(2, 3, input.get(), &cropRect),
238 new SkTileImageFilter(inputCropRect.rect(), cropRect.rect(), input.get() ), 238 SkTileImageFilter::Create(inputCropRect.rect(), cropRect.rect(), input.g et()),
239 new SkXfermodeImageFilter(SkXfermode::Create(SkXfermode::kSrcOver_Mode), input.get(), input.get(), &cropRect), 239 SkXfermodeImageFilter::Create(SkXfermode::Create(SkXfermode::kSrcOver_Mo de), input.get(), input.get(), &cropRect),
240 }; 240 };
241 241
242 for (size_t i = 0; i < SK_ARRAY_COUNT(filters); ++i) { 242 for (size_t i = 0; i < SK_ARRAY_COUNT(filters); ++i) {
243 SkImageFilter* filter = filters[i]; 243 SkImageFilter* filter = filters[i];
244 SkBitmap result; 244 SkBitmap result;
245 SkIPoint offset; 245 SkIPoint offset;
246 SkString str; 246 SkString str;
247 str.printf("filter %d", static_cast<int>(i)); 247 str.printf("filter %d", static_cast<int>(i));
248 REPORTER_ASSERT_MESSAGE(reporter, filter->filterImage(&proxy, bitmap, Sk Matrix::I(), &result, &offset), str.c_str()); 248 REPORTER_ASSERT_MESSAGE(reporter, filter->filterImage(&proxy, bitmap, Sk Matrix::I(), &result, &offset), str.c_str());
249 REPORTER_ASSERT_MESSAGE(reporter, offset.fX == 20 && offset.fY == 30, st r.c_str()); 249 REPORTER_ASSERT_MESSAGE(reporter, offset.fX == 20 && offset.fY == 30, st r.c_str());
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
295 295
296 #if SK_SUPPORT_GPU 296 #if SK_SUPPORT_GPU
297 DEF_GPUTEST(ImageFilterCropRectGPU, reporter, factory) { 297 DEF_GPUTEST(ImageFilterCropRectGPU, reporter, factory) {
298 GrContext* context = factory->get(static_cast<GrContextFactory::GLContextTyp e>(0)); 298 GrContext* context = factory->get(static_cast<GrContextFactory::GLContextTyp e>(0));
299 SkAutoTUnref<SkGpuDevice> device(SkGpuDevice::Create(context, 299 SkAutoTUnref<SkGpuDevice> device(SkGpuDevice::Create(context,
300 SkImageInfo::MakeN32Pre mul(100, 100), 300 SkImageInfo::MakeN32Pre mul(100, 100),
301 0)); 301 0));
302 test_crop_rects(device, reporter); 302 test_crop_rects(device, reporter);
303 } 303 }
304 #endif 304 #endif
OLDNEW
« no previous file with comments | « tests/GLProgramsTest.cpp ('k') | tests/SerializationTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698