From 533330065a28b51808e5bf564ae45e56f8d9956a Mon Sep 17 00:00:00 2001 From: "senorblanco@chromium.org" Date: Thu, 12 Dec 2013 23:28:52 +0000 Subject: Implement an SkPicture image filter source. This is required for the external-SVG reference feature of feImage. It simply plays back an SkPicture to a given destination rect. R=reed@google.com Review URL: https://codereview.chromium.org/114263002 git-svn-id: http://skia.googlecode.com/svn/trunk@12661 2bbb7eff-a529-9590-31e7-b0007b416f81 --- gm/pictureimagefilter.cpp | 82 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 gm/pictureimagefilter.cpp (limited to 'gm') diff --git a/gm/pictureimagefilter.cpp b/gm/pictureimagefilter.cpp new file mode 100644 index 0000000000..781088ce0e --- /dev/null +++ b/gm/pictureimagefilter.cpp @@ -0,0 +1,82 @@ +/* + * Copyright 2013 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#include "gm.h" + +#include "SkPictureImageFilter.h" + +// This GM exercises the SkPictureImageFilter ImageFilter class. + +class PictureImageFilterGM : public skiagm::GM { +public: + PictureImageFilterGM() { + } + +protected: + virtual SkString onShortName() SK_OVERRIDE { + return SkString("pictureimagefilter"); + } + + void makePicture() { + SkCanvas* canvas = fPicture.beginRecording(100, 100); + canvas->clear(0x00000000); + SkPaint paint; + paint.setAntiAlias(true); + paint.setColor(0xFFFFFFFF); + paint.setTextSize(SkIntToScalar(96)); + const char* str = "e"; + canvas->drawText(str, strlen(str), SkIntToScalar(20), SkIntToScalar(70), paint); + fPicture.endRecording(); + } + + virtual SkISize onISize() SK_OVERRIDE { return SkISize::Make(500, 150); } + + virtual void onOnceBeforeDraw() SK_OVERRIDE { + this->makePicture(); + } + + static void fillRectFiltered(SkCanvas* canvas, const SkRect& clipRect, SkImageFilter* filter) { + SkPaint paint; + paint.setImageFilter(filter); + canvas->save(); + canvas->clipRect(clipRect); + canvas->drawPaint(paint); + canvas->restore(); + } + + virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE { + canvas->clear(0x00000000); + { + SkRect srcRect = SkRect::MakeXYWH(20, 20, 30, 30); + SkRect emptyRect = SkRect::MakeXYWH(20, 20, 0, 0); + SkRect bounds = SkRect::MakeXYWH(0, 0, 100, 100); + SkAutoTUnref pictureSource(new SkPictureImageFilter(&fPicture)); + SkAutoTUnref pictureSourceSrcRect(new SkPictureImageFilter(&fPicture, srcRect)); + SkAutoTUnref pictureSourceEmptyRect(new SkPictureImageFilter(&fPicture, emptyRect)); + + // Draw the picture unscaled. + fillRectFiltered(canvas, bounds, pictureSource); + canvas->translate(SkIntToScalar(100), 0); + + // Draw an unscaled subset of the source picture. + fillRectFiltered(canvas, bounds, pictureSourceSrcRect); + canvas->translate(SkIntToScalar(100), 0); + + // Draw the picture to an empty rect (should draw nothing). + fillRectFiltered(canvas, bounds, pictureSourceEmptyRect); + canvas->translate(SkIntToScalar(100), 0); + } + } + +private: + SkPicture fPicture; + typedef GM INHERITED; +}; + +/////////////////////////////////////////////////////////////////////////////// + +DEF_GM( return new PictureImageFilterGM; ) -- cgit v1.2.3