cac5fd597f
This is part of an effort to ensure that all SkPaint effects can only be allocated on the heap. This patch makes the constructors of SkImageFilter and its subclasses non-public and instead provides factory methods for creating these objects on the heap. We temporarily keep constructor of publicly visible classes public behind a flag. BUG=skia:2187 R=scroggo@google.com, mtklein@chromium.org, reed@google.com, senorblanco@google.com, senorblanco@chromium.org, bsalomon@google.com, sugoi@chromium.org, zork@chromium.org Author: dominikg@chromium.org Review URL: https://codereview.chromium.org/182983003 git-svn-id: http://skia.googlecode.com/svn/trunk@13718 2bbb7eff-a529-9590-31e7-b0007b416f81
99 lines
2.4 KiB
C++
99 lines
2.4 KiB
C++
/*
|
|
* 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 "SkCanvas.h"
|
|
#include "SkBlurImageFilter.h"
|
|
|
|
static void make_bm(SkBitmap* bm) {
|
|
bm->allocN32Pixels(100, 100);
|
|
bm->eraseColor(SK_ColorBLUE);
|
|
|
|
SkCanvas canvas(*bm);
|
|
SkPaint paint;
|
|
paint.setAntiAlias(true);
|
|
paint.setColor(SK_ColorRED);
|
|
canvas.drawCircle(50, 50, 50, paint);
|
|
}
|
|
|
|
static void draw_2_bitmaps(SkCanvas* canvas, const SkBitmap& bm, bool doClip,
|
|
int dx, int dy, SkImageFilter* filter = NULL) {
|
|
SkAutoCanvasRestore acr(canvas, true);
|
|
SkPaint paint;
|
|
|
|
SkRect clipR = SkRect::MakeXYWH(SkIntToScalar(dx),
|
|
SkIntToScalar(dy),
|
|
SkIntToScalar(bm.width()),
|
|
SkIntToScalar(bm.height()));
|
|
|
|
paint.setImageFilter(filter);
|
|
clipR.inset(5, 5);
|
|
|
|
if (doClip) {
|
|
canvas->save();
|
|
canvas->clipRect(clipR);
|
|
}
|
|
canvas->drawSprite(bm, dx, dy, &paint);
|
|
if (doClip) {
|
|
canvas->restore();
|
|
}
|
|
|
|
canvas->translate(SkIntToScalar(bm.width() + 20), 0);
|
|
|
|
if (doClip) {
|
|
canvas->save();
|
|
canvas->clipRect(clipR);
|
|
}
|
|
canvas->drawBitmap(bm, SkIntToScalar(dx), SkIntToScalar(dy), &paint);
|
|
if (doClip) {
|
|
canvas->restore();
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Compare output of drawSprite and drawBitmap (esp. clipping and imagefilters)
|
|
*/
|
|
class SpriteBitmapGM : public skiagm::GM {
|
|
public:
|
|
SpriteBitmapGM() {}
|
|
|
|
protected:
|
|
virtual SkString onShortName() {
|
|
return SkString("spritebitmap");
|
|
}
|
|
|
|
virtual SkISize onISize() {
|
|
return SkISize::Make(640, 480);
|
|
}
|
|
|
|
virtual void onDraw(SkCanvas* canvas) {
|
|
SkBitmap bm;
|
|
make_bm(&bm);
|
|
|
|
int dx = 10;
|
|
int dy = 10;
|
|
|
|
SkScalar sigma = 8;
|
|
SkAutoTUnref<SkImageFilter> filter(SkBlurImageFilter::Create(sigma, sigma));
|
|
|
|
draw_2_bitmaps(canvas, bm, false, dx, dy);
|
|
dy += bm.height() + 20;
|
|
draw_2_bitmaps(canvas, bm, false, dx, dy, filter);
|
|
dy += bm.height() + 20;
|
|
draw_2_bitmaps(canvas, bm, true, dx, dy);
|
|
dy += bm.height() + 20;
|
|
draw_2_bitmaps(canvas, bm, true, dx, dy, filter);
|
|
}
|
|
|
|
private:
|
|
typedef GM INHERITED;
|
|
};
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
DEF_GM( return new SpriteBitmapGM; )
|