OLD | NEW |
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 299 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
310 canvas.drawSprite(bitmap, 0, 0, &paint); | 310 canvas.drawSprite(bitmap, 0, 0, &paint); |
311 } | 311 } |
312 | 312 |
313 DEF_TEST(HugeBlurImageFilter, reporter) { | 313 DEF_TEST(HugeBlurImageFilter, reporter) { |
314 SkBitmap temp; | 314 SkBitmap temp; |
315 temp.allocN32Pixels(100, 100); | 315 temp.allocN32Pixels(100, 100); |
316 SkBitmapDevice device(temp); | 316 SkBitmapDevice device(temp); |
317 test_huge_blur(&device, reporter); | 317 test_huge_blur(&device, reporter); |
318 } | 318 } |
319 | 319 |
| 320 static void test_xfermode_cropped_input(SkBaseDevice* device, skiatest::Reporter
* reporter) { |
| 321 SkCanvas canvas(device); |
| 322 canvas.clear(0); |
| 323 |
| 324 SkBitmap bitmap; |
| 325 bitmap.allocN32Pixels(1, 1); |
| 326 bitmap.eraseARGB(255, 255, 255, 255); |
| 327 |
| 328 SkAutoTUnref<SkColorFilter> green( |
| 329 SkColorFilter::CreateModeFilter(SK_ColorGREEN, SkXfermode::kSrcIn_Mode))
; |
| 330 SkAutoTUnref<SkColorFilterImageFilter> greenFilter( |
| 331 SkColorFilterImageFilter::Create(green.get())); |
| 332 SkImageFilter::CropRect cropRect(SkRect::MakeEmpty()); |
| 333 SkAutoTUnref<SkColorFilterImageFilter> croppedOut( |
| 334 SkColorFilterImageFilter::Create(green.get(), NULL, &cropRect)); |
| 335 |
| 336 // Check that an xfermode image filter whose input has been cropped out stil
l draws the other |
| 337 // input. Also check that drawing with both inputs cropped out doesn't cause
a GPU warning. |
| 338 SkXfermode* mode = SkXfermode::Create(SkXfermode::kSrcOver_Mode); |
| 339 SkAutoTUnref<SkImageFilter> xfermodeNoFg( |
| 340 SkXfermodeImageFilter::Create(mode, greenFilter, croppedOut)); |
| 341 SkAutoTUnref<SkImageFilter> xfermodeNoBg( |
| 342 SkXfermodeImageFilter::Create(mode, croppedOut, greenFilter)); |
| 343 SkAutoTUnref<SkImageFilter> xfermodeNoFgNoBg( |
| 344 SkXfermodeImageFilter::Create(mode, croppedOut, croppedOut)); |
| 345 |
| 346 SkPaint paint; |
| 347 paint.setImageFilter(xfermodeNoFg); |
| 348 canvas.drawSprite(bitmap, 0, 0, &paint); |
| 349 |
| 350 uint32_t pixel; |
| 351 SkImageInfo info = SkImageInfo::MakeN32Premul(1, 1); |
| 352 canvas.readPixels(info, &pixel, 4, 0, 0); |
| 353 REPORTER_ASSERT(reporter, pixel == SK_ColorGREEN); |
| 354 |
| 355 paint.setImageFilter(xfermodeNoBg); |
| 356 canvas.drawSprite(bitmap, 0, 0, &paint); |
| 357 canvas.readPixels(info, &pixel, 4, 0, 0); |
| 358 REPORTER_ASSERT(reporter, pixel == SK_ColorGREEN); |
| 359 |
| 360 paint.setImageFilter(xfermodeNoFgNoBg); |
| 361 canvas.drawSprite(bitmap, 0, 0, &paint); |
| 362 canvas.readPixels(info, &pixel, 4, 0, 0); |
| 363 REPORTER_ASSERT(reporter, pixel == SK_ColorGREEN); |
| 364 } |
| 365 |
| 366 DEF_TEST(XfermodeImageFilterCroppedInput, reporter) { |
| 367 SkBitmap temp; |
| 368 temp.allocN32Pixels(100, 100); |
| 369 SkBitmapDevice device(temp); |
| 370 test_xfermode_cropped_input(&device, reporter); |
| 371 } |
320 | 372 |
321 #if SK_SUPPORT_GPU | 373 #if SK_SUPPORT_GPU |
322 DEF_GPUTEST(ImageFilterCropRectGPU, reporter, factory) { | 374 DEF_GPUTEST(ImageFilterCropRectGPU, reporter, factory) { |
323 GrContext* context = factory->get(static_cast<GrContextFactory::GLContextTyp
e>(0)); | 375 GrContext* context = factory->get(static_cast<GrContextFactory::GLContextTyp
e>(0)); |
324 SkAutoTUnref<SkGpuDevice> device(SkGpuDevice::Create(context, | 376 SkAutoTUnref<SkGpuDevice> device(SkGpuDevice::Create(context, |
325 SkImageInfo::MakeN32Pre
mul(100, 100), | 377 SkImageInfo::MakeN32Pre
mul(100, 100), |
326 0)); | 378 0)); |
327 test_crop_rects(device, reporter); | 379 test_crop_rects(device, reporter); |
328 } | 380 } |
329 | 381 |
330 DEF_GPUTEST(HugeBlurImageFilterGPU, reporter, factory) { | 382 DEF_GPUTEST(HugeBlurImageFilterGPU, reporter, factory) { |
331 GrContext* context = factory->get(static_cast<GrContextFactory::GLContextTyp
e>(0)); | 383 GrContext* context = factory->get(static_cast<GrContextFactory::GLContextTyp
e>(0)); |
332 SkAutoTUnref<SkGpuDevice> device(SkGpuDevice::Create(context, | 384 SkAutoTUnref<SkGpuDevice> device(SkGpuDevice::Create(context, |
333 SkImageInfo::MakeN32Pre
mul(100, 100), | 385 SkImageInfo::MakeN32Pre
mul(100, 100), |
334 0)); | 386 0)); |
335 test_huge_blur(device, reporter); | 387 test_huge_blur(device, reporter); |
336 } | 388 } |
| 389 |
| 390 DEF_GPUTEST(XfermodeImageFilterCroppedInputGPU, reporter, factory) { |
| 391 GrContext* context = factory->get(static_cast<GrContextFactory::GLContextTyp
e>(0)); |
| 392 SkAutoTUnref<SkGpuDevice> device(SkGpuDevice::Create(context, |
| 393 SkImageInfo::MakeN32Pre
mul(1, 1), |
| 394 0)); |
| 395 test_xfermode_cropped_input(device, reporter); |
| 396 } |
337 #endif | 397 #endif |
OLD | NEW |