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"
|
2015-08-05 20:57:49 +00:00
|
|
|
#include "SkPath.h"
|
2013-04-16 16:55:38 +00:00
|
|
|
|
|
|
|
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.
|
|
|
|
//
|
2015-09-09 15:16:41 +00:00
|
|
|
DEF_SIMPLE_GM(bitmaprecttest, canvas, 320, 240) {
|
2013-04-16 16:55:38 +00:00
|
|
|
SkBitmap bm;
|
|
|
|
make_bm(&bm);
|
|
|
|
|
2015-08-27 14:41:13 +00:00
|
|
|
canvas->drawBitmap(bm, 150, 45, nullptr);
|
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);
|
2015-08-06 17:02:53 +00:00
|
|
|
canvas->drawBitmapRect(bm, SkRect::MakeXYWH(100, 100, 128, 128), nullptr);
|
2013-04-18 15:37:14 +00:00
|
|
|
canvas->restore();
|
|
|
|
|
|
|
|
canvas->scale(-1, 1);
|
2015-08-27 14:41:13 +00:00
|
|
|
canvas->drawBitmap(bm, -310, 45, nullptr);
|
2013-04-16 16:55:38 +00:00
|
|
|
}
|