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

Side by Side Diff: tests/ImageFilterTest.cpp

Issue 222723002: Fix matrix adjustment passed to filter processing. (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Created 6 years, 8 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
« no previous file with comments | « src/core/SkCanvas.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 * 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"
11 #include "SkBitmapSource.h" 11 #include "SkBitmapSource.h"
12 #include "SkBlurImageFilter.h" 12 #include "SkBlurImageFilter.h"
13 #include "SkCanvas.h" 13 #include "SkCanvas.h"
14 #include "SkColorFilterImageFilter.h" 14 #include "SkColorFilterImageFilter.h"
15 #include "SkColorMatrixFilter.h" 15 #include "SkColorMatrixFilter.h"
16 #include "SkDeviceImageFilterProxy.h" 16 #include "SkDeviceImageFilterProxy.h"
17 #include "SkDisplacementMapEffect.h" 17 #include "SkDisplacementMapEffect.h"
18 #include "SkDropShadowImageFilter.h" 18 #include "SkDropShadowImageFilter.h"
19 #include "SkFlattenableBuffers.h" 19 #include "SkFlattenableBuffers.h"
20 #include "SkLightingImageFilter.h" 20 #include "SkLightingImageFilter.h"
21 #include "SkMatrixConvolutionImageFilter.h" 21 #include "SkMatrixConvolutionImageFilter.h"
22 #include "SkMatrixImageFilter.h"
22 #include "SkMergeImageFilter.h" 23 #include "SkMergeImageFilter.h"
23 #include "SkMorphologyImageFilter.h" 24 #include "SkMorphologyImageFilter.h"
24 #include "SkOffsetImageFilter.h" 25 #include "SkOffsetImageFilter.h"
25 #include "SkPicture.h" 26 #include "SkPicture.h"
26 #include "SkRect.h" 27 #include "SkRect.h"
27 #include "SkTileImageFilter.h" 28 #include "SkTileImageFilter.h"
28 #include "SkXfermodeImageFilter.h" 29 #include "SkXfermodeImageFilter.h"
29 #include "Test.h" 30 #include "Test.h"
30 31
31 #if SK_SUPPORT_GPU 32 #if SK_SUPPORT_GPU
(...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after
356 canvas.drawSprite(bitmap, 0, 0, &paint); 357 canvas.drawSprite(bitmap, 0, 0, &paint);
357 canvas.readPixels(info, &pixel, 4, 0, 0); 358 canvas.readPixels(info, &pixel, 4, 0, 0);
358 REPORTER_ASSERT(reporter, pixel == SK_ColorGREEN); 359 REPORTER_ASSERT(reporter, pixel == SK_ColorGREEN);
359 360
360 paint.setImageFilter(xfermodeNoFgNoBg); 361 paint.setImageFilter(xfermodeNoFgNoBg);
361 canvas.drawSprite(bitmap, 0, 0, &paint); 362 canvas.drawSprite(bitmap, 0, 0, &paint);
362 canvas.readPixels(info, &pixel, 4, 0, 0); 363 canvas.readPixels(info, &pixel, 4, 0, 0);
363 REPORTER_ASSERT(reporter, pixel == SK_ColorGREEN); 364 REPORTER_ASSERT(reporter, pixel == SK_ColorGREEN);
364 } 365 }
365 366
367 DEF_TEST(ImageFilterNestedSaveLayer, reporter) {
368 SkBitmap temp;
369 temp.allocN32Pixels(50, 50);
370 SkBitmapDevice device(temp);
371 SkCanvas canvas(&device);
372 canvas.clear(0x0);
373
374 SkBitmap bitmap;
375 bitmap.allocN32Pixels(10, 10);
376 bitmap.eraseColor(SK_ColorGREEN);
377
378 SkMatrix matrix;
379 matrix.setScale(SkIntToScalar(2), SkIntToScalar(2));
380 matrix.postTranslate(SkIntToScalar(-20), SkIntToScalar(-20));
381 SkAutoTUnref<SkImageFilter> matrixFilter(
382 SkMatrixImageFilter::Create(matrix, SkPaint::kLow_FilterLevel));
383
384 // Test that saveLayer() with a filter nested inside another saveLayer() app lies the
385 // correct offset to the filter matrix.
386 SkRect bounds1 = SkRect::MakeXYWH(10, 10, 30, 30);
387 canvas.saveLayer(&bounds1, NULL);
388 SkPaint filterPaint;
389 filterPaint.setImageFilter(matrixFilter);
390 SkRect bounds2 = SkRect::MakeXYWH(20, 20, 10, 10);
391 canvas.saveLayer(&bounds2, &filterPaint);
392 SkPaint greenPaint;
393 greenPaint.setColor(SK_ColorGREEN);
394 canvas.drawRect(bounds2, greenPaint);
395 canvas.restore();
396 canvas.restore();
397 SkPaint strokePaint;
398 strokePaint.setStyle(SkPaint::kStroke_Style);
399 strokePaint.setColor(SK_ColorRED);
400
401 SkImageInfo info = SkImageInfo::MakeN32Premul(1, 1);
402 uint32_t pixel;
403 canvas.readPixels(info, &pixel, 4, 25, 25);
404 REPORTER_ASSERT(reporter, pixel == SK_ColorGREEN);
405
406 // Test that drawSprite() with a filter nested inside a saveLayer() applies the
407 // correct offset to the filter matrix.
408 canvas.clear(0x0);
409 canvas.readPixels(info, &pixel, 4, 25, 25);
410 canvas.saveLayer(&bounds1, NULL);
411 canvas.drawSprite(bitmap, 20, 20, &filterPaint);
412 canvas.restore();
413
414 canvas.readPixels(info, &pixel, 4, 25, 25);
415 REPORTER_ASSERT(reporter, pixel == SK_ColorGREEN);
416 }
417
366 DEF_TEST(XfermodeImageFilterCroppedInput, reporter) { 418 DEF_TEST(XfermodeImageFilterCroppedInput, reporter) {
367 SkBitmap temp; 419 SkBitmap temp;
368 temp.allocN32Pixels(100, 100); 420 temp.allocN32Pixels(100, 100);
369 SkBitmapDevice device(temp); 421 SkBitmapDevice device(temp);
370 test_xfermode_cropped_input(&device, reporter); 422 test_xfermode_cropped_input(&device, reporter);
371 } 423 }
372 424
373 #if SK_SUPPORT_GPU 425 #if SK_SUPPORT_GPU
374 DEF_GPUTEST(ImageFilterCropRectGPU, reporter, factory) { 426 DEF_GPUTEST(ImageFilterCropRectGPU, reporter, factory) {
375 GrContext* context = factory->get(static_cast<GrContextFactory::GLContextTyp e>(0)); 427 GrContext* context = factory->get(static_cast<GrContextFactory::GLContextTyp e>(0));
(...skipping 12 matching lines...) Expand all
388 } 440 }
389 441
390 DEF_GPUTEST(XfermodeImageFilterCroppedInputGPU, reporter, factory) { 442 DEF_GPUTEST(XfermodeImageFilterCroppedInputGPU, reporter, factory) {
391 GrContext* context = factory->get(static_cast<GrContextFactory::GLContextTyp e>(0)); 443 GrContext* context = factory->get(static_cast<GrContextFactory::GLContextTyp e>(0));
392 SkAutoTUnref<SkGpuDevice> device(SkGpuDevice::Create(context, 444 SkAutoTUnref<SkGpuDevice> device(SkGpuDevice::Create(context,
393 SkImageInfo::MakeN32Pre mul(1, 1), 445 SkImageInfo::MakeN32Pre mul(1, 1),
394 0)); 446 0));
395 test_xfermode_cropped_input(device, reporter); 447 test_xfermode_cropped_input(device, reporter);
396 } 448 }
397 #endif 449 #endif
OLDNEW
« no previous file with comments | « src/core/SkCanvas.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698