2013-01-16 18:54:15 +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.
|
|
|
|
*/
|
|
|
|
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "gm/gm.h"
|
2019-05-01 21:28:53 +00:00
|
|
|
#include "include/core/SkBitmap.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/core/SkCanvas.h"
|
2019-05-01 21:28:53 +00:00
|
|
|
#include "include/core/SkColor.h"
|
|
|
|
#include "include/core/SkImageFilter.h"
|
|
|
|
#include "include/core/SkPaint.h"
|
|
|
|
#include "include/core/SkRect.h"
|
|
|
|
#include "include/core/SkRefCnt.h"
|
|
|
|
#include "include/core/SkScalar.h"
|
|
|
|
#include "include/core/SkSize.h"
|
|
|
|
#include "include/core/SkString.h"
|
2019-08-02 19:21:23 +00:00
|
|
|
#include "include/effects/SkImageFilters.h"
|
2013-01-16 18:54:15 +00:00
|
|
|
|
2019-05-01 21:28:53 +00:00
|
|
|
#include <utility>
|
|
|
|
|
2013-01-16 18:54:15 +00:00
|
|
|
static void make_bm(SkBitmap* bm) {
|
2014-01-25 16:46:20 +00:00
|
|
|
bm->allocN32Pixels(100, 100);
|
2013-01-16 18:54:15 +00:00
|
|
|
bm->eraseColor(SK_ColorBLUE);
|
|
|
|
|
|
|
|
SkCanvas canvas(*bm);
|
|
|
|
SkPaint paint;
|
|
|
|
paint.setAntiAlias(true);
|
|
|
|
paint.setColor(SK_ColorRED);
|
|
|
|
canvas.drawCircle(50, 50, 50, paint);
|
|
|
|
}
|
|
|
|
|
2015-12-16 16:38:15 +00:00
|
|
|
static void draw_1_bitmap(SkCanvas* canvas, const SkBitmap& bm, bool doClip,
|
2016-04-04 11:31:25 +00:00
|
|
|
int dx, int dy, sk_sp<SkImageFilter> filter) {
|
2013-01-16 18:54:15 +00:00
|
|
|
SkAutoCanvasRestore acr(canvas, true);
|
|
|
|
SkPaint paint;
|
|
|
|
|
2013-01-17 07:06:06 +00:00
|
|
|
SkRect clipR = SkRect::MakeXYWH(SkIntToScalar(dx),
|
2013-01-16 19:57:02 +00:00
|
|
|
SkIntToScalar(dy),
|
2013-01-16 19:24:15 +00:00
|
|
|
SkIntToScalar(bm.width()),
|
|
|
|
SkIntToScalar(bm.height()));
|
2013-01-16 18:54:15 +00:00
|
|
|
|
2016-04-04 11:31:25 +00:00
|
|
|
paint.setImageFilter(std::move(filter));
|
2013-01-16 18:54:15 +00:00
|
|
|
clipR.inset(5, 5);
|
|
|
|
|
2013-01-16 19:24:15 +00:00
|
|
|
canvas->translate(SkIntToScalar(bm.width() + 20), 0);
|
2013-01-16 18:54:15 +00:00
|
|
|
|
|
|
|
if (doClip) {
|
|
|
|
canvas->save();
|
|
|
|
canvas->clipRect(clipR);
|
|
|
|
}
|
2013-01-16 19:24:15 +00:00
|
|
|
canvas->drawBitmap(bm, SkIntToScalar(dx), SkIntToScalar(dy), &paint);
|
2013-01-16 18:54:15 +00:00
|
|
|
if (doClip) {
|
|
|
|
canvas->restore();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Compare output of drawSprite and drawBitmap (esp. clipping and imagefilters)
|
|
|
|
*/
|
|
|
|
class SpriteBitmapGM : public skiagm::GM {
|
|
|
|
public:
|
|
|
|
SpriteBitmapGM() {}
|
|
|
|
|
|
|
|
protected:
|
2014-04-30 13:20:45 +00:00
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
SkString onShortName() override {
|
2013-01-16 18:54:15 +00:00
|
|
|
return SkString("spritebitmap");
|
|
|
|
}
|
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
SkISize onISize() override {
|
2013-01-16 18:54:15 +00:00
|
|
|
return SkISize::Make(640, 480);
|
|
|
|
}
|
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
void onDraw(SkCanvas* canvas) override {
|
2013-01-16 18:54:15 +00:00
|
|
|
SkBitmap bm;
|
|
|
|
make_bm(&bm);
|
|
|
|
|
|
|
|
int dx = 10;
|
|
|
|
int dy = 10;
|
|
|
|
|
|
|
|
SkScalar sigma = 8;
|
2019-08-02 19:21:23 +00:00
|
|
|
sk_sp<SkImageFilter> filter(SkImageFilters::Blur(sigma, sigma, nullptr));
|
2013-01-16 18:54:15 +00:00
|
|
|
|
2016-04-04 11:31:25 +00:00
|
|
|
draw_1_bitmap(canvas, bm, false, dx, dy, nullptr);
|
2013-01-16 18:54:15 +00:00
|
|
|
dy += bm.height() + 20;
|
2015-12-16 16:38:15 +00:00
|
|
|
draw_1_bitmap(canvas, bm, false, dx, dy, filter);
|
2013-01-16 18:54:15 +00:00
|
|
|
dy += bm.height() + 20;
|
2016-04-04 11:31:25 +00:00
|
|
|
draw_1_bitmap(canvas, bm, true, dx, dy, nullptr);
|
2013-01-16 18:54:15 +00:00
|
|
|
dy += bm.height() + 20;
|
2015-12-16 16:38:15 +00:00
|
|
|
draw_1_bitmap(canvas, bm, true, dx, dy, filter);
|
2013-01-16 18:54:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
typedef GM INHERITED;
|
|
|
|
};
|
|
|
|
DEF_GM( return new SpriteBitmapGM; )
|