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

Side by Side Diff: tests/ImageFilterTest.cpp

Issue 262363007: Fix for empty saveLayer() with a filter which affects transparent black. (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Created 6 years, 7 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/SkPictureRecord.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"
(...skipping 449 matching lines...) Expand 10 before | Expand all | Expand 10 after
460 recordingCanvas->save(); 460 recordingCanvas->save();
461 recordingCanvas->scale(SkIntToScalar(10), SkIntToScalar(10)); 461 recordingCanvas->scale(SkIntToScalar(10), SkIntToScalar(10));
462 recordingCanvas->drawRect(SkRect::Make(SkIRect::MakeWH(100, 100)), solidPain t); 462 recordingCanvas->drawRect(SkRect::Make(SkIRect::MakeWH(100, 100)), solidPain t);
463 recordingCanvas->restore(); // scale 463 recordingCanvas->restore(); // scale
464 recordingCanvas->restore(); // saveLayer 464 recordingCanvas->restore(); // saveLayer
465 SkAutoTUnref<SkPicture> picture(recorder.endRecording()); 465 SkAutoTUnref<SkPicture> picture(recorder.endRecording());
466 466
467 canvas.drawPicture(*picture); 467 canvas.drawPicture(*picture);
468 } 468 }
469 469
470 DEF_TEST(ImageFilterEmptySaveLayerTest, reporter) {
471
472 // Even when there's an empty saveLayer()/restore(), ensure that an image
473 // filter or color filter which affects transparent black still draws.
474
475 SkBitmap bitmap;
476 bitmap.allocN32Pixels(10, 10);
477 SkBitmapDevice device(bitmap);
478 SkCanvas canvas(&device);
479
480 SkRTreeFactory factory;
481 SkPictureRecorder recorder;
482
483 SkAutoTUnref<SkColorFilter> green(
484 SkColorFilter::CreateModeFilter(SK_ColorGREEN, SkXfermode::kSrc_Mode));
485 SkAutoTUnref<SkColorFilterImageFilter> imageFilter(
486 SkColorFilterImageFilter::Create(green.get()));
487 SkPaint imageFilterPaint;
488 imageFilterPaint.setImageFilter(imageFilter.get());
489 SkPaint colorFilterPaint;
490 colorFilterPaint.setColorFilter(green.get());
491
492 SkRect bounds = SkRect::MakeWH(10, 10);
493
494 SkCanvas* recordingCanvas = recorder.beginRecording(10, 10, &factory, 0);
495 recordingCanvas->saveLayer(&bounds, &imageFilterPaint);
496 recordingCanvas->restore();
497 SkAutoTUnref<SkPicture> picture(recorder.endRecording());
498
499 canvas.clear(0);
500 canvas.drawPicture(*picture);
501 uint32_t pixel = *bitmap.getAddr32(0, 0);
502 REPORTER_ASSERT(reporter, pixel == SK_ColorGREEN);
503
504 recordingCanvas = recorder.beginRecording(10, 10, &factory, 0);
505 recordingCanvas->saveLayer(NULL, &imageFilterPaint);
506 recordingCanvas->restore();
507 SkAutoTUnref<SkPicture> picture2(recorder.endRecording());
508
509 canvas.clear(0);
510 canvas.drawPicture(*picture2);
511 pixel = *bitmap.getAddr32(0, 0);
512 REPORTER_ASSERT(reporter, pixel == SK_ColorGREEN);
513
514 recordingCanvas = recorder.beginRecording(10, 10, &factory, 0);
515 recordingCanvas->saveLayer(&bounds, &colorFilterPaint);
516 recordingCanvas->restore();
517 SkAutoTUnref<SkPicture> picture3(recorder.endRecording());
518
519 canvas.clear(0);
520 canvas.drawPicture(*picture3);
521 pixel = *bitmap.getAddr32(0, 0);
522 REPORTER_ASSERT(reporter, pixel == SK_ColorGREEN);
523 }
524
470 static void test_huge_blur(SkBaseDevice* device, skiatest::Reporter* reporter) { 525 static void test_huge_blur(SkBaseDevice* device, skiatest::Reporter* reporter) {
471 SkCanvas canvas(device); 526 SkCanvas canvas(device);
472 527
473 SkBitmap bitmap; 528 SkBitmap bitmap;
474 bitmap.allocN32Pixels(100, 100); 529 bitmap.allocN32Pixels(100, 100);
475 bitmap.eraseARGB(0, 0, 0, 0); 530 bitmap.eraseARGB(0, 0, 0, 0);
476 531
477 // Check that a blur with an insane radius does not crash or assert. 532 // Check that a blur with an insane radius does not crash or assert.
478 SkAutoTUnref<SkImageFilter> blur(SkBlurImageFilter::Create(SkIntToScalar(1<< 30), SkIntToScalar(1<<30))); 533 SkAutoTUnref<SkImageFilter> blur(SkBlurImageFilter::Create(SkIntToScalar(1<< 30), SkIntToScalar(1<<30)));
479 534
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
611 } 666 }
612 667
613 DEF_GPUTEST(XfermodeImageFilterCroppedInputGPU, reporter, factory) { 668 DEF_GPUTEST(XfermodeImageFilterCroppedInputGPU, reporter, factory) {
614 GrContext* context = factory->get(static_cast<GrContextFactory::GLContextTyp e>(0)); 669 GrContext* context = factory->get(static_cast<GrContextFactory::GLContextTyp e>(0));
615 SkAutoTUnref<SkGpuDevice> device(SkGpuDevice::Create(context, 670 SkAutoTUnref<SkGpuDevice> device(SkGpuDevice::Create(context,
616 SkImageInfo::MakeN32Pre mul(1, 1), 671 SkImageInfo::MakeN32Pre mul(1, 1),
617 0)); 672 0));
618 test_xfermode_cropped_input(device, reporter); 673 test_xfermode_cropped_input(device, reporter);
619 } 674 }
620 #endif 675 #endif
OLDNEW
« no previous file with comments | « src/core/SkPictureRecord.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698