2013-12-09 18:31:42 +00:00
|
|
|
/*
|
|
|
|
* 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 "SkBitmapSource.h"
|
|
|
|
|
|
|
|
// This GM exercises the SkBitmapSource ImageFilter class.
|
|
|
|
|
|
|
|
class BitmapSourceGM : public skiagm::GM {
|
|
|
|
public:
|
|
|
|
BitmapSourceGM() {
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
2015-03-26 01:17:31 +00:00
|
|
|
SkString onShortName() override {
|
2013-12-09 18:31:42 +00:00
|
|
|
return SkString("bitmapsource");
|
|
|
|
}
|
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
SkISize onISize() override { return SkISize::Make(500, 150); }
|
2013-12-09 18:31:42 +00:00
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
void onOnceBeforeDraw() override {
|
2015-09-03 20:32:33 +00:00
|
|
|
fBitmap = sk_tool_utils::create_string_bitmap(100, 100, 0xFFFFFFFF, 20, 70, 96, "e");
|
2013-12-09 18:31:42 +00:00
|
|
|
}
|
|
|
|
|
2015-09-03 20:32:33 +00:00
|
|
|
static void FillRectFiltered(SkCanvas* canvas, const SkRect& clipRect, SkImageFilter* filter) {
|
2013-12-09 18:31:42 +00:00
|
|
|
SkPaint paint;
|
|
|
|
paint.setImageFilter(filter);
|
|
|
|
canvas->save();
|
|
|
|
canvas->clipRect(clipRect);
|
|
|
|
canvas->drawPaint(paint);
|
|
|
|
canvas->restore();
|
|
|
|
}
|
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
void onDraw(SkCanvas* canvas) override {
|
2015-04-08 19:36:08 +00:00
|
|
|
canvas->clear(SK_ColorBLACK);
|
2013-12-09 18:31:42 +00:00
|
|
|
{
|
|
|
|
SkRect srcRect = SkRect::MakeXYWH(20, 20, 30, 30);
|
|
|
|
SkRect dstRect = SkRect::MakeXYWH(0, 10, 60, 60);
|
|
|
|
SkRect clipRect = SkRect::MakeXYWH(0, 0, 100, 100);
|
|
|
|
SkRect bounds;
|
|
|
|
fBitmap.getBounds(&bounds);
|
2014-03-10 10:51:58 +00:00
|
|
|
SkAutoTUnref<SkImageFilter> bitmapSource(SkBitmapSource::Create(fBitmap));
|
|
|
|
SkAutoTUnref<SkImageFilter> bitmapSourceSrcRect(SkBitmapSource::Create(fBitmap, srcRect, srcRect));
|
|
|
|
SkAutoTUnref<SkImageFilter> bitmapSourceSrcRectDstRect(SkBitmapSource::Create(fBitmap, srcRect, dstRect));
|
|
|
|
SkAutoTUnref<SkImageFilter> bitmapSourceDstRectOnly(SkBitmapSource::Create(fBitmap, bounds, dstRect));
|
2013-12-09 18:31:42 +00:00
|
|
|
|
|
|
|
// Draw an unscaled bitmap.
|
2015-09-03 20:32:33 +00:00
|
|
|
FillRectFiltered(canvas, clipRect, bitmapSource);
|
2013-12-09 18:31:42 +00:00
|
|
|
canvas->translate(SkIntToScalar(100), 0);
|
|
|
|
|
|
|
|
// Draw an unscaled subset of the source bitmap (srcRect -> srcRect).
|
2015-09-03 20:32:33 +00:00
|
|
|
FillRectFiltered(canvas, clipRect, bitmapSourceSrcRect);
|
2013-12-09 18:31:42 +00:00
|
|
|
canvas->translate(SkIntToScalar(100), 0);
|
|
|
|
|
|
|
|
// Draw a subset of the bitmap scaled to a destination rect (srcRect -> dstRect).
|
2015-09-03 20:32:33 +00:00
|
|
|
FillRectFiltered(canvas, clipRect, bitmapSourceSrcRectDstRect);
|
2013-12-09 18:31:42 +00:00
|
|
|
canvas->translate(SkIntToScalar(100), 0);
|
|
|
|
|
|
|
|
// Draw the entire bitmap scaled to a destination rect (bounds -> dstRect).
|
2015-09-03 20:32:33 +00:00
|
|
|
FillRectFiltered(canvas, clipRect, bitmapSourceDstRectOnly);
|
2013-12-09 18:31:42 +00:00
|
|
|
canvas->translate(SkIntToScalar(100), 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
SkBitmap fBitmap;
|
|
|
|
typedef GM INHERITED;
|
|
|
|
};
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
DEF_GM( return new BitmapSourceGM; )
|