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" |
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 "SkFlattenableSerialization.h" |
20 #include "SkGradientShader.h" | 21 #include "SkGradientShader.h" |
21 #include "SkLightingImageFilter.h" | 22 #include "SkLightingImageFilter.h" |
22 #include "SkMatrixConvolutionImageFilter.h" | 23 #include "SkMatrixConvolutionImageFilter.h" |
23 #include "SkMatrixImageFilter.h" | 24 #include "SkMatrixImageFilter.h" |
24 #include "SkMergeImageFilter.h" | 25 #include "SkMergeImageFilter.h" |
25 #include "SkMorphologyImageFilter.h" | 26 #include "SkMorphologyImageFilter.h" |
26 #include "SkOffsetImageFilter.h" | 27 #include "SkOffsetImageFilter.h" |
27 #include "SkPicture.h" | 28 #include "SkPicture.h" |
| 29 #include "SkPictureImageFilter.h" |
28 #include "SkPictureRecorder.h" | 30 #include "SkPictureRecorder.h" |
29 #include "SkRect.h" | 31 #include "SkRect.h" |
30 #include "SkTileImageFilter.h" | 32 #include "SkTileImageFilter.h" |
31 #include "SkXfermodeImageFilter.h" | 33 #include "SkXfermodeImageFilter.h" |
32 #include "Test.h" | 34 #include "Test.h" |
33 | 35 |
34 #if SK_SUPPORT_GPU | 36 #if SK_SUPPORT_GPU |
35 #include "GrContextFactory.h" | 37 #include "GrContextFactory.h" |
36 #include "SkGpuDevice.h" | 38 #include "SkGpuDevice.h" |
37 #endif | 39 #endif |
(...skipping 436 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
474 recordingCanvas->save(); | 476 recordingCanvas->save(); |
475 recordingCanvas->scale(SkIntToScalar(10), SkIntToScalar(10)); | 477 recordingCanvas->scale(SkIntToScalar(10), SkIntToScalar(10)); |
476 recordingCanvas->drawRect(SkRect::Make(SkIRect::MakeWH(100, 100)), solidPain
t); | 478 recordingCanvas->drawRect(SkRect::Make(SkIRect::MakeWH(100, 100)), solidPain
t); |
477 recordingCanvas->restore(); // scale | 479 recordingCanvas->restore(); // scale |
478 recordingCanvas->restore(); // saveLayer | 480 recordingCanvas->restore(); // saveLayer |
479 SkAutoTUnref<SkPicture> picture(recorder.endRecording()); | 481 SkAutoTUnref<SkPicture> picture(recorder.endRecording()); |
480 | 482 |
481 canvas.drawPicture(*picture); | 483 canvas.drawPicture(*picture); |
482 } | 484 } |
483 | 485 |
| 486 DEF_TEST(ImageFilterPictureImageFilterTest, reporter) { |
| 487 |
| 488 SkRTreeFactory factory; |
| 489 SkPictureRecorder recorder; |
| 490 SkCanvas* recordingCanvas = recorder.beginRecording(1, 1, &factory, 0); |
| 491 |
| 492 // Create an SkPicture which simply draws a green 1x1 rectangle. |
| 493 SkPaint greenPaint; |
| 494 greenPaint.setColor(SK_ColorGREEN); |
| 495 recordingCanvas->drawRect(SkRect::Make(SkIRect::MakeWH(1, 1)), greenPaint); |
| 496 SkAutoTUnref<SkPicture> picture(recorder.endRecording()); |
| 497 |
| 498 // Wrap that SkPicture in an SkPictureImageFilter. |
| 499 SkAutoTUnref<SkImageFilter> imageFilter( |
| 500 SkPictureImageFilter::Create(picture.get())); |
| 501 |
| 502 // Check that SkPictureImageFilter successfully serializes its contained |
| 503 // SkPicture when not in cross-process mode. |
| 504 SkPaint paint; |
| 505 paint.setImageFilter(imageFilter.get()); |
| 506 SkPictureRecorder outerRecorder; |
| 507 SkCanvas* outerCanvas = outerRecorder.beginRecording(1, 1, &factory, 0); |
| 508 SkPaint redPaintWithFilter; |
| 509 redPaintWithFilter.setColor(SK_ColorRED); |
| 510 redPaintWithFilter.setImageFilter(imageFilter.get()); |
| 511 outerCanvas->drawRect(SkRect::Make(SkIRect::MakeWH(1, 1)), redPaintWithFilte
r); |
| 512 SkAutoTUnref<SkPicture> outerPicture(outerRecorder.endRecording()); |
| 513 |
| 514 SkBitmap bitmap; |
| 515 bitmap.allocN32Pixels(1, 1); |
| 516 SkBitmapDevice device(bitmap); |
| 517 SkCanvas canvas(&device); |
| 518 |
| 519 // The result here should be green, since the filter |
| 520 canvas.clear(0x0); |
| 521 canvas.drawPicture(*outerPicture); |
| 522 uint32_t pixel = *bitmap.getAddr32(0, 0); |
| 523 REPORTER_ASSERT(reporter, pixel == SK_ColorGREEN); |
| 524 |
| 525 // Check that, for now, SkPictureImageFilter does not serialize or |
| 526 // deserialize its contained picture when the filter is serialized |
| 527 // cross-process. Do this by "laundering" it through SkValidatingReadBuffer. |
| 528 SkAutoTUnref<SkData> data(SkValidatingSerializeFlattenable(imageFilter.get()
)); |
| 529 SkFlattenable* flattenable = SkValidatingDeserializeFlattenable( |
| 530 data->data(), data->size(), SkImageFilter::GetFlattenableType()); |
| 531 SkImageFilter* unflattenedFilter = static_cast<SkImageFilter*>(flattenable); |
| 532 |
| 533 redPaintWithFilter.setImageFilter(unflattenedFilter); |
| 534 SkPictureRecorder crossProcessRecorder; |
| 535 SkCanvas* crossProcessCanvas = crossProcessRecorder.beginRecording(1, 1, &fa
ctory, 0); |
| 536 crossProcessCanvas->drawRect(SkRect::Make(SkIRect::MakeWH(1, 1)), redPaintWi
thFilter); |
| 537 SkAutoTUnref<SkPicture> crossProcessPicture(crossProcessRecorder.endRecordin
g()); |
| 538 |
| 539 canvas.clear(SK_ColorBLUE); |
| 540 canvas.drawPicture(*crossProcessPicture); |
| 541 pixel = *bitmap.getAddr32(0, 0); |
| 542 // The result here should be the canvas background (blue), since the filter
draws nothing. |
| 543 REPORTER_ASSERT(reporter, pixel == SK_ColorBLUE); |
| 544 } |
| 545 |
484 DEF_TEST(ImageFilterEmptySaveLayerTest, reporter) { | 546 DEF_TEST(ImageFilterEmptySaveLayerTest, reporter) { |
485 | 547 |
486 // Even when there's an empty saveLayer()/restore(), ensure that an image | 548 // Even when there's an empty saveLayer()/restore(), ensure that an image |
487 // filter or color filter which affects transparent black still draws. | 549 // filter or color filter which affects transparent black still draws. |
488 | 550 |
489 SkBitmap bitmap; | 551 SkBitmap bitmap; |
490 bitmap.allocN32Pixels(10, 10); | 552 bitmap.allocN32Pixels(10, 10); |
491 SkBitmapDevice device(bitmap); | 553 SkBitmapDevice device(bitmap); |
492 SkCanvas canvas(&device); | 554 SkCanvas canvas(&device); |
493 | 555 |
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
680 } | 742 } |
681 | 743 |
682 DEF_GPUTEST(XfermodeImageFilterCroppedInputGPU, reporter, factory) { | 744 DEF_GPUTEST(XfermodeImageFilterCroppedInputGPU, reporter, factory) { |
683 GrContext* context = factory->get(static_cast<GrContextFactory::GLContextTyp
e>(0)); | 745 GrContext* context = factory->get(static_cast<GrContextFactory::GLContextTyp
e>(0)); |
684 SkAutoTUnref<SkGpuDevice> device(SkGpuDevice::Create(context, | 746 SkAutoTUnref<SkGpuDevice> device(SkGpuDevice::Create(context, |
685 SkImageInfo::MakeN32Pre
mul(1, 1), | 747 SkImageInfo::MakeN32Pre
mul(1, 1), |
686 0)); | 748 0)); |
687 test_xfermode_cropped_input(device, reporter); | 749 test_xfermode_cropped_input(device, reporter); |
688 } | 750 } |
689 #endif | 751 #endif |
OLD | NEW |