| Index: gm/resizeimagefilter.cpp
|
| diff --git a/gm/resizeimagefilter.cpp b/gm/resizeimagefilter.cpp
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..e92084c8f157506799ca9ccd3c55d1454d4034ee
|
| --- /dev/null
|
| +++ b/gm/resizeimagefilter.cpp
|
| @@ -0,0 +1,128 @@
|
| +/*
|
| + * 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 {
|
| +
|
| +// Don't use SkBitmapSource here, since it will resize automatically by the CTM.
|
| +// We want the resize image filter to take care of that, so this one simply returns the bitmap.
|
| +
|
| +class SimpleBitmapSource : public SkImageFilter {
|
| +public:
|
| + SimpleBitmapSource(const SkBitmap& bitmap)
|
| + : INHERITED(0, 0),
|
| + fBitmap(bitmap) {
|
| + }
|
| +
|
| + SimpleBitmapSource(SkFlattenableReadBuffer& buffer)
|
| + : INHERITED(0, buffer) {
|
| + fBitmap.unflatten(buffer);
|
| + }
|
| +
|
| + virtual void flatten(SkFlattenableWriteBuffer& buffer) const SK_OVERRIDE {
|
| + this->INHERITED::flatten(buffer);
|
| + fBitmap.flatten(buffer);
|
| + }
|
| +
|
| + virtual bool onFilterImage(Proxy* proxy, const SkBitmap&, const SkMatrix& matrix,
|
| + SkBitmap* result, SkIPoint* offset) SK_OVERRIDE {
|
| + *result = fBitmap;
|
| + offset->fX = offset->fY = 0;
|
| + return true;
|
| + }
|
| +
|
| + SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SimpleBitmapSource)
|
| +
|
| +private:
|
| + SkBitmap fBitmap;
|
| + typedef SkImageFilter INHERITED;
|
| +};
|
| +
|
| +class ResizeGM : public GM {
|
| +public:
|
| + ResizeGM() : fInitialized(false) {
|
| + this->setBGColor(0x00000000);
|
| + }
|
| +
|
| +protected:
|
| + virtual SkString onShortName() {
|
| + return SkString("resizeimagefilter");
|
| + }
|
| +
|
| + void make_checkerboard(int width, int height) {
|
| + SkASSERT(width % 2 == 0);
|
| + SkASSERT(height % 2 == 0);
|
| + fCheckerboard.setConfig(SkBitmap::kARGB_8888_Config, width, height);
|
| + fCheckerboard.allocPixels();
|
| + SkAutoLockPixels lock(fCheckerboard);
|
| + for (int y = 0; y < height; y += 2) {
|
| + SkPMColor* s = fCheckerboard.getAddr32(0, y);
|
| + for (int x = 0; x < width; x += 2) {
|
| + *s++ = 0xFFFFFFFF;
|
| + *s++ = 0xFF000000;
|
| + }
|
| + s = fCheckerboard.getAddr32(0, y + 1);
|
| + for (int x = 0; x < width; x += 2) {
|
| + *s++ = 0xFF000000;
|
| + *s++ = 0xFFFFFFFF;
|
| + }
|
| + }
|
| + }
|
| +
|
| + virtual SkISize onISize() {
|
| + return make_isize(400, 300);
|
| + }
|
| +
|
| + virtual void onDraw(SkCanvas* canvas) {
|
| + if (!fInitialized) {
|
| + make_checkerboard(4, 4);
|
| + fInitialized = true;
|
| + }
|
| + canvas->clear(0x00000000);
|
| + SkPaint paint;
|
| + SkSize scale = SkSize::Make(SkIntToScalar(32), SkIntToScalar(32));
|
| + SkAutoTUnref<SkImageFilter> source(new SimpleBitmapSource(fCheckerboard));
|
| + SkAutoTUnref<SkImageFilter> noneResize(new SkResizeImageFilter(scale, SkPaint::kNone_FilterLevel, source.get()));
|
| + SkAutoTUnref<SkImageFilter> lowResize(new SkResizeImageFilter(scale, SkPaint::kLow_FilterLevel, source.get()));
|
| + SkAutoTUnref<SkImageFilter> mediumResize(new SkResizeImageFilter(scale, SkPaint::kMedium_FilterLevel, source.get()));
|
| + SkAutoTUnref<SkImageFilter> highResize(new SkResizeImageFilter(scale, SkPaint::kHigh_FilterLevel, source.get()));
|
| + paint.setFilterLevel(SkPaint::kNone_FilterLevel); // Outer paint does no filtering; leave it all for the filter
|
| +
|
| + SkRect srcRect;
|
| + fCheckerboard.getBounds(&srcRect);
|
| +
|
| + paint.setImageFilter(noneResize);
|
| + canvas->drawRect(srcRect, paint);
|
| +
|
| + paint.setImageFilter(lowResize);
|
| + canvas->translate(SkIntToScalar(140), 0);
|
| + canvas->drawRect(srcRect, paint);
|
| +
|
| + paint.setImageFilter(mediumResize);
|
| + canvas->translate(SkIntToScalar(140), 0);
|
| + canvas->drawRect(srcRect, paint);
|
| +
|
| + paint.setImageFilter(highResize);
|
| + canvas->translate(SkIntToScalar(140), 0);
|
| + canvas->drawRect(srcRect, paint);
|
| + }
|
| +
|
| +private:
|
| + typedef GM INHERITED;
|
| + SkBitmap fCheckerboard;
|
| + bool fInitialized;
|
| +};
|
| +
|
| +//////////////////////////////////////////////////////////////////////////////
|
| +
|
| +static GM* MyFactory(void*) { return new ResizeGM; }
|
| +static GMRegistry reg(MyFactory);
|
| +
|
| +}
|
|
|