aboutsummaryrefslogtreecommitdiffhomepage
path: root/gm/resizeimagefilter.cpp
diff options
context:
space:
mode:
authorGravatar senorblanco@chromium.org <senorblanco@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81>2014-01-14 22:20:48 +0000
committerGravatar senorblanco@chromium.org <senorblanco@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81>2014-01-14 22:20:48 +0000
commit535e1ccbd0161d80cc43fcc0c90dc1fec1737367 (patch)
tree104422e893542a47f6f7e7c64c302f60f024fbc1 /gm/resizeimagefilter.cpp
parent8844f997805ee6c554f457b2777a9af0ff2f3ed3 (diff)
Implement a resize image filter. This is needed for the "filterRes" feature in SVG filter effects, which specifies the required size for intermediate processing buffers. In order to make this work, we need to render the primitive at the given resolution (doable at the callsite in Blink), and then to resize the result to the actual on-screen size. The latter is where this filter comes in.
It simply applies a scaling factor (and the current CTM) to its input, and draws its input bitmap at that size. R=reed@google.com Review URL: https://codereview.chromium.org/136863006 git-svn-id: http://skia.googlecode.com/svn/trunk@13077 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'gm/resizeimagefilter.cpp')
-rw-r--r--gm/resizeimagefilter.cpp96
1 files changed, 96 insertions, 0 deletions
diff --git a/gm/resizeimagefilter.cpp b/gm/resizeimagefilter.cpp
new file mode 100644
index 0000000000..fa407c4bfa
--- /dev/null
+++ b/gm/resizeimagefilter.cpp
@@ -0,0 +1,96 @@
+/*
+ * 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 "SkColor.h"
+#include "SkResizeImageFilter.h"
+
+namespace skiagm {
+
+class ResizeGM : public GM {
+public:
+ ResizeGM() {
+ this->setBGColor(0x00000000);
+ }
+
+protected:
+ virtual SkString onShortName() {
+ return SkString("resizeimagefilter");
+ }
+
+ void draw(SkCanvas* canvas,
+ const SkRect& rect,
+ const SkSize& deviceSize,
+ SkPaint::FilterLevel filterLevel) {
+ SkRect dstRect;
+ canvas->getTotalMatrix().mapRect(&dstRect, rect);
+ canvas->save();
+ SkScalar deviceScaleX = SkScalarDiv(deviceSize.width(), dstRect.width());
+ SkScalar deviceScaleY = SkScalarDiv(deviceSize.height(), dstRect.height());
+ canvas->translate(rect.x(), rect.y());
+ canvas->scale(deviceScaleX, deviceScaleY);
+ canvas->translate(-rect.x(), -rect.y());
+ SkAutoTUnref<SkImageFilter> imageFilter(
+ new SkResizeImageFilter(SkScalarInvert(deviceScaleX),
+ SkScalarInvert(deviceScaleY),
+ filterLevel));
+ SkPaint filteredPaint;
+ filteredPaint.setImageFilter(imageFilter.get());
+ canvas->saveLayer(&rect, &filteredPaint);
+ SkPaint paint;
+ paint.setColor(0xFF00FF00);
+ SkRect ovalRect = rect;
+ ovalRect.inset(SkIntToScalar(4), SkIntToScalar(4));
+ canvas->drawOval(ovalRect, paint);
+ canvas->restore(); // for saveLayer
+ canvas->restore();
+ }
+
+ virtual SkISize onISize() {
+ return make_isize(420, 100);
+ }
+
+ virtual void onDraw(SkCanvas* canvas) {
+ canvas->clear(0x00000000);
+
+ SkRect srcRect = SkRect::MakeWH(96, 96);
+
+ SkSize deviceSize = SkSize::Make(16, 16);
+ draw(canvas,
+ srcRect,
+ deviceSize,
+ SkPaint::kNone_FilterLevel);
+
+ canvas->translate(srcRect.width() + SkIntToScalar(10), 0);
+ draw(canvas,
+ srcRect,
+ deviceSize,
+ SkPaint::kLow_FilterLevel);
+
+ canvas->translate(srcRect.width() + SkIntToScalar(10), 0);
+ draw(canvas,
+ srcRect,
+ deviceSize,
+ SkPaint::kMedium_FilterLevel);
+
+ canvas->translate(srcRect.width() + SkIntToScalar(10), 0);
+ draw(canvas,
+ srcRect,
+ deviceSize,
+ SkPaint::kHigh_FilterLevel);
+ }
+
+private:
+ typedef GM INHERITED;
+};
+
+//////////////////////////////////////////////////////////////////////////////
+
+static GM* MyFactory(void*) { return new ResizeGM; }
+static GMRegistry reg(MyFactory);
+
+}