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

Side by Side Diff: tests/ImageFilterTest.cpp

Issue 311443003: Allow SkPictureImageFilter to be serialized when not run cross-process. (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Fix comment Created 6 years, 6 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/effects/SkPictureImageFilter.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 "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"
28 #include "SkPictureImageFilter.h" 29 #include "SkPictureImageFilter.h"
29 #include "SkPictureRecorder.h" 30 #include "SkPictureRecorder.h"
(...skipping 456 matching lines...) Expand 10 before | Expand all | Expand 10 after
486 recordingCanvas->save(); 487 recordingCanvas->save();
487 recordingCanvas->scale(SkIntToScalar(10), SkIntToScalar(10)); 488 recordingCanvas->scale(SkIntToScalar(10), SkIntToScalar(10));
488 recordingCanvas->drawRect(SkRect::Make(SkIRect::MakeWH(100, 100)), solidPain t); 489 recordingCanvas->drawRect(SkRect::Make(SkIRect::MakeWH(100, 100)), solidPain t);
489 recordingCanvas->restore(); // scale 490 recordingCanvas->restore(); // scale
490 recordingCanvas->restore(); // saveLayer 491 recordingCanvas->restore(); // saveLayer
491 SkAutoTUnref<SkPicture> picture(recorder.endRecording()); 492 SkAutoTUnref<SkPicture> picture(recorder.endRecording());
492 493
493 canvas.drawPicture(*picture); 494 canvas.drawPicture(*picture);
494 } 495 }
495 496
497 DEF_TEST(ImageFilterPictureImageFilterTest, reporter) {
498
499 SkRTreeFactory factory;
500 SkPictureRecorder recorder;
501 SkCanvas* recordingCanvas = recorder.beginRecording(1, 1, &factory, 0);
502
503 // Create an SkPicture which simply draws a green 1x1 rectangle.
504 SkPaint greenPaint;
505 greenPaint.setColor(SK_ColorGREEN);
506 recordingCanvas->drawRect(SkRect::Make(SkIRect::MakeWH(1, 1)), greenPaint);
507 SkAutoTUnref<SkPicture> picture(recorder.endRecording());
508
509 // Wrap that SkPicture in an SkPictureImageFilter.
510 SkAutoTUnref<SkImageFilter> imageFilter(
511 SkPictureImageFilter::Create(picture.get()));
512
513 // Check that SkPictureImageFilter successfully serializes its contained
514 // SkPicture when not in cross-process mode.
515 SkPaint paint;
516 paint.setImageFilter(imageFilter.get());
517 SkPictureRecorder outerRecorder;
518 SkCanvas* outerCanvas = outerRecorder.beginRecording(1, 1, &factory, 0);
519 SkPaint redPaintWithFilter;
520 redPaintWithFilter.setColor(SK_ColorRED);
521 redPaintWithFilter.setImageFilter(imageFilter.get());
522 outerCanvas->drawRect(SkRect::Make(SkIRect::MakeWH(1, 1)), redPaintWithFilte r);
523 SkAutoTUnref<SkPicture> outerPicture(outerRecorder.endRecording());
524
525 SkBitmap bitmap;
526 bitmap.allocN32Pixels(1, 1);
527 SkBitmapDevice device(bitmap);
528 SkCanvas canvas(&device);
529
530 // The result here should be green, since the filter replaces the primitive' s red interior.
531 canvas.clear(0x0);
532 canvas.drawPicture(*outerPicture);
533 uint32_t pixel = *bitmap.getAddr32(0, 0);
534 REPORTER_ASSERT(reporter, pixel == SK_ColorGREEN);
535
536 // Check that, for now, SkPictureImageFilter does not serialize or
537 // deserialize its contained picture when the filter is serialized
538 // cross-process. Do this by "laundering" it through SkValidatingReadBuffer.
539 SkAutoTUnref<SkData> data(SkValidatingSerializeFlattenable(imageFilter.get() ));
540 SkAutoTUnref<SkFlattenable> flattenable(SkValidatingDeserializeFlattenable(
541 data->data(), data->size(), SkImageFilter::GetFlattenableType()));
542 SkImageFilter* unflattenedFilter = static_cast<SkImageFilter*>(flattenable.g et());
543
544 redPaintWithFilter.setImageFilter(unflattenedFilter);
545 SkPictureRecorder crossProcessRecorder;
546 SkCanvas* crossProcessCanvas = crossProcessRecorder.beginRecording(1, 1, &fa ctory, 0);
547 crossProcessCanvas->drawRect(SkRect::Make(SkIRect::MakeWH(1, 1)), redPaintWi thFilter);
548 SkAutoTUnref<SkPicture> crossProcessPicture(crossProcessRecorder.endRecordin g());
549
550 canvas.clear(0x0);
551 canvas.drawPicture(*crossProcessPicture);
552 pixel = *bitmap.getAddr32(0, 0);
553 // The result here should not be green, since the filter draws nothing.
554 REPORTER_ASSERT(reporter, pixel != SK_ColorGREEN);
555 }
556
496 DEF_TEST(ImageFilterEmptySaveLayerTest, reporter) { 557 DEF_TEST(ImageFilterEmptySaveLayerTest, reporter) {
497 558
498 // Even when there's an empty saveLayer()/restore(), ensure that an image 559 // Even when there's an empty saveLayer()/restore(), ensure that an image
499 // filter or color filter which affects transparent black still draws. 560 // filter or color filter which affects transparent black still draws.
500 561
501 SkBitmap bitmap; 562 SkBitmap bitmap;
502 bitmap.allocN32Pixels(10, 10); 563 bitmap.allocN32Pixels(10, 10);
503 SkBitmapDevice device(bitmap); 564 SkBitmapDevice device(bitmap);
504 SkCanvas canvas(&device); 565 SkCanvas canvas(&device);
505 566
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after
692 } 753 }
693 754
694 DEF_GPUTEST(XfermodeImageFilterCroppedInputGPU, reporter, factory) { 755 DEF_GPUTEST(XfermodeImageFilterCroppedInputGPU, reporter, factory) {
695 GrContext* context = factory->get(static_cast<GrContextFactory::GLContextTyp e>(0)); 756 GrContext* context = factory->get(static_cast<GrContextFactory::GLContextTyp e>(0));
696 SkAutoTUnref<SkGpuDevice> device(SkGpuDevice::Create(context, 757 SkAutoTUnref<SkGpuDevice> device(SkGpuDevice::Create(context,
697 SkImageInfo::MakeN32Pre mul(1, 1), 758 SkImageInfo::MakeN32Pre mul(1, 1),
698 0)); 759 0));
699 test_xfermode_cropped_input(device, reporter); 760 test_xfermode_cropped_input(device, reporter);
700 } 761 }
701 #endif 762 #endif
OLDNEW
« no previous file with comments | « src/effects/SkPictureImageFilter.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698