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

Side by Side Diff: tests/ImageFilterTest.cpp

Issue 496963003: Fix saveLayer() with a pixel-moving filter vs SkBBoxHierarchyRecord / SkRecordDraw (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Simpler, no need to drop the bounds intersection. Created 6 years, 4 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 | « src/core/SkRecordDraw.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 "SkBitmap.h" 8 #include "SkBitmap.h"
9 #include "SkBitmapDevice.h" 9 #include "SkBitmapDevice.h"
10 #include "SkBitmapSource.h" 10 #include "SkBitmapSource.h"
(...skipping 403 matching lines...) Expand 10 before | Expand all | Expand 10 after
414 } 414 }
415 } 415 }
416 } 416 }
417 } 417 }
418 418
419 for (size_t i = 0; i < SK_ARRAY_COUNT(filters); ++i) { 419 for (size_t i = 0; i < SK_ARRAY_COUNT(filters); ++i) {
420 SkSafeUnref(filters[i].fFilter); 420 SkSafeUnref(filters[i].fFilter);
421 } 421 }
422 } 422 }
423 423
424 static void drawSaveLayerPicture(int width, int height, int tileSize, SkBBHFacto ry* factory, SkBitmap* result) {
425
426 SkMatrix matrix;
427 matrix.setTranslate(SkIntToScalar(50), 0);
428
429 SkAutoTUnref<SkColorFilter> cf(SkColorFilter::CreateModeFilter(SK_ColorWHITE , SkXfermode::kSrc_Mode));
430 SkAutoTUnref<SkImageFilter> cfif(SkColorFilterImageFilter::Create(cf.get())) ;
431 SkAutoTUnref<SkImageFilter> imageFilter(SkMatrixImageFilter::Create(matrix, SkPaint::kNone_FilterLevel, cfif.get()));
432
433 SkPaint paint;
434 paint.setImageFilter(imageFilter.get());
435 SkPictureRecorder recorder;
436 SkRect bounds = SkRect::Make(SkIRect::MakeXYWH(0, 0, 50, 50));
437 SkCanvas* recordingCanvas = recorder.beginRecording(width, height, factory, 0);
438 recordingCanvas->translate(-55, 0);
439 recordingCanvas->saveLayer(&bounds, &paint);
440 recordingCanvas->restore();
441 SkAutoTUnref<SkPicture> picture1(recorder.endRecording());
442
443 result->allocN32Pixels(width, height);
444 SkCanvas canvas(*result);
445 canvas.clear(0);
446 canvas.clipRect(SkRect::Make(SkIRect::MakeWH(tileSize, tileSize)));
447 canvas.drawPicture(picture1.get());
448 }
449
450 DEF_TEST(ImageFilterDrawMatrixBBH, reporter) {
451 // Check that matrix filter when drawn tiled with BBH exactly
452 // matches the same thing drawn without BBH.
453 // Tests pass by not asserting.
454
455 const int width = 200, height = 200;
456 const int tileSize = 100;
457 SkBitmap result1, result2;
458 SkRTreeFactory factory;
459
460 drawSaveLayerPicture(width, height, tileSize, &factory, &result1);
461 drawSaveLayerPicture(width, height, tileSize, NULL, &result2);
462
463 for (int y = 0; y < height; y++) {
464 int diffs = memcmp(result1.getAddr32(0, y), result2.getAddr32(0, y), res ult1.rowBytes());
465 REPORTER_ASSERT(reporter, !diffs);
466 if (diffs) {
467 break;
468 }
469 }
470 }
471
424 static void drawBlurredRect(SkCanvas* canvas) { 472 static void drawBlurredRect(SkCanvas* canvas) {
425 SkAutoTUnref<SkImageFilter> filter(SkBlurImageFilter::Create(SkIntToScalar(8 ), 0)); 473 SkAutoTUnref<SkImageFilter> filter(SkBlurImageFilter::Create(SkIntToScalar(8 ), 0));
426 SkPaint filterPaint; 474 SkPaint filterPaint;
427 filterPaint.setColor(SK_ColorWHITE); 475 filterPaint.setColor(SK_ColorWHITE);
428 filterPaint.setImageFilter(filter); 476 filterPaint.setImageFilter(filter);
429 canvas->saveLayer(NULL, &filterPaint); 477 canvas->saveLayer(NULL, &filterPaint);
430 SkPaint whitePaint; 478 SkPaint whitePaint;
431 whitePaint.setColor(SK_ColorWHITE); 479 whitePaint.setColor(SK_ColorWHITE);
432 canvas->drawRect(SkRect::Make(SkIRect::MakeWH(4, 4)), whitePaint); 480 canvas->drawRect(SkRect::Make(SkIRect::MakeWH(4, 4)), whitePaint);
433 canvas->restore(); 481 canvas->restore();
(...skipping 427 matching lines...) Expand 10 before | Expand all | Expand 10 after
861 } 909 }
862 910
863 DEF_GPUTEST(XfermodeImageFilterCroppedInputGPU, reporter, factory) { 911 DEF_GPUTEST(XfermodeImageFilterCroppedInputGPU, reporter, factory) {
864 GrContext* context = factory->get(static_cast<GrContextFactory::GLContextTyp e>(0)); 912 GrContext* context = factory->get(static_cast<GrContextFactory::GLContextTyp e>(0));
865 SkAutoTUnref<SkGpuDevice> device(SkGpuDevice::Create(context, 913 SkAutoTUnref<SkGpuDevice> device(SkGpuDevice::Create(context,
866 SkImageInfo::MakeN32Pre mul(1, 1), 914 SkImageInfo::MakeN32Pre mul(1, 1),
867 0)); 915 0));
868 test_xfermode_cropped_input(device, reporter); 916 test_xfermode_cropped_input(device, reporter);
869 } 917 }
870 #endif 918 #endif
OLDNEW
« no previous file with comments | « src/core/SkRecordDraw.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698