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.
|
|
|
|
*/
|
|
|
|
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "gm/gm.h"
|
2019-05-01 14:59:30 +00:00
|
|
|
#include "include/core/SkBitmap.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/core/SkCanvas.h"
|
2021-01-24 03:07:05 +00:00
|
|
|
#include "include/core/SkImage.h"
|
2019-05-01 14:59:30 +00:00
|
|
|
#include "include/core/SkPaint.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/core/SkPath.h"
|
2019-05-01 14:59:30 +00:00
|
|
|
#include "include/core/SkRect.h"
|
|
|
|
#include "include/core/SkScalar.h"
|
2013-04-16 16:55:38 +00:00
|
|
|
|
2021-01-24 03:07:05 +00:00
|
|
|
static sk_sp<SkImage> make_bm() {
|
|
|
|
SkBitmap bm;
|
|
|
|
bm.allocN32Pixels(60, 60);
|
|
|
|
bm.eraseColor(0);
|
2013-04-16 16:55:38 +00:00
|
|
|
|
2021-01-24 03:07:05 +00:00
|
|
|
SkCanvas canvas(bm);
|
2013-04-16 16:55:38 +00:00
|
|
|
SkPaint paint;
|
2020-08-03 20:33:14 +00:00
|
|
|
canvas.drawPath(SkPath::Polygon({{6,6}, {6,54}, {30,54}}, false), paint);
|
2013-04-18 15:37:14 +00:00
|
|
|
|
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);
|
2021-01-24 03:07:05 +00:00
|
|
|
return bm.asImage();
|
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) {
|
2021-01-24 03:07:05 +00:00
|
|
|
auto image = make_bm();
|
2013-04-16 16:55:38 +00:00
|
|
|
|
2021-01-24 03:07:05 +00:00
|
|
|
canvas->drawImage(image, 150, 45);
|
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);
|
2021-01-24 03:07:05 +00:00
|
|
|
canvas->drawImageRect(image, SkRect::MakeXYWH(100, 100, 128, 128), SkSamplingOptions());
|
2013-04-18 15:37:14 +00:00
|
|
|
canvas->restore();
|
|
|
|
|
|
|
|
canvas->scale(-1, 1);
|
2021-01-24 03:07:05 +00:00
|
|
|
canvas->drawImage(image, -310, 45);
|
2013-04-16 16:55:38 +00:00
|
|
|
}
|