2013-04-16 16:55:38 +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 "SkCanvas.h"
|
|
|
|
|
|
|
|
static void make_bm(SkBitmap* bm) {
|
2014-01-25 16:46:20 +00:00
|
|
|
bm->allocN32Pixels(60, 60);
|
2013-04-16 16:55:38 +00:00
|
|
|
bm->eraseColor(0);
|
|
|
|
|
|
|
|
SkCanvas canvas(*bm);
|
|
|
|
SkPaint paint;
|
2013-04-18 15:37:14 +00:00
|
|
|
|
|
|
|
SkPath path;
|
|
|
|
path.moveTo(6, 6);
|
|
|
|
path.lineTo(6, 54);
|
|
|
|
path.lineTo(30, 54);
|
|
|
|
canvas.drawPath(path, paint);
|
|
|
|
|
2013-04-16 16:55:38 +00:00
|
|
|
paint.setStyle(SkPaint::kStroke_Style);
|
2013-04-16 17:04:43 +00:00
|
|
|
canvas.drawRect(SkRect::MakeLTRB(0.5f, 0.5f, 59.5f, 59.5f), paint);
|
2013-04-16 16:55:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// This creates a close, but imperfect concatenation of
|
|
|
|
// scaling the image up by its dst-rect
|
|
|
|
// scaling the image down by the matrix' scale
|
|
|
|
// The bug was that for cases like this, we were incorrectly trying to take a
|
|
|
|
// fast-path in the bitmapshader, but ended up drawing the last col of pixels
|
|
|
|
// twice. The fix resulted in (a) not taking the fast-path, but (b) drawing
|
|
|
|
// the image correctly.
|
|
|
|
//
|
|
|
|
static void test_bitmaprect(SkCanvas* canvas) {
|
|
|
|
SkBitmap bm;
|
|
|
|
make_bm(&bm);
|
|
|
|
|
|
|
|
canvas->drawBitmap(bm, 150, 45, NULL);
|
2013-04-17 07:00:56 +00:00
|
|
|
|
2013-04-16 17:04:43 +00:00
|
|
|
SkScalar scale = 0.472560018f;
|
2013-04-18 15:37:14 +00:00
|
|
|
canvas->save();
|
2013-04-16 16:55:38 +00:00
|
|
|
canvas->scale(scale, scale);
|
|
|
|
canvas->drawBitmapRectToRect(bm, NULL, SkRect::MakeXYWH(100, 100, 128, 128), NULL);
|
2013-04-18 15:37:14 +00:00
|
|
|
canvas->restore();
|
|
|
|
|
|
|
|
canvas->scale(-1, 1);
|
|
|
|
canvas->drawBitmap(bm, -310, 45, NULL);
|
2013-04-16 16:55:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
class BitmapRectTestGM : public skiagm::GM {
|
|
|
|
public:
|
|
|
|
BitmapRectTestGM() {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
2015-01-09 18:06:39 +00:00
|
|
|
SkString onShortName() SK_OVERRIDE {
|
2013-04-16 17:58:38 +00:00
|
|
|
return SkString("bitmaprecttest");
|
2013-04-16 16:55:38 +00:00
|
|
|
}
|
|
|
|
|
2015-01-09 18:06:39 +00:00
|
|
|
SkISize onISize() SK_OVERRIDE {
|
2013-04-16 16:55:38 +00:00
|
|
|
return SkISize::Make(320, 240);
|
|
|
|
}
|
|
|
|
|
2015-01-09 18:06:39 +00:00
|
|
|
void onDraw(SkCanvas* canvas) SK_OVERRIDE {
|
2013-04-16 16:55:38 +00:00
|
|
|
test_bitmaprect(canvas);
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
typedef skiagm::GM INHERITED;
|
|
|
|
};
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
DEF_GM( return new BitmapRectTestGM; )
|