blob: 8bd4f4b8b6ebe94ead877596c06ba5f2392524ee [file] [log] [blame]
reed@google.comd6382332013-04-16 16:55:38 +00001/*
2 * Copyright 2013 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
Mike Kleinc0bd9f92019-04-23 12:05:21 -05008#include "gm/gm.h"
Ben Wagner6a34f3a2019-05-01 10:59:30 -04009#include "include/core/SkBitmap.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050010#include "include/core/SkCanvas.h"
Ben Wagner6a34f3a2019-05-01 10:59:30 -040011#include "include/core/SkPaint.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050012#include "include/core/SkPath.h"
Ben Wagner6a34f3a2019-05-01 10:59:30 -040013#include "include/core/SkRect.h"
14#include "include/core/SkScalar.h"
reed@google.comd6382332013-04-16 16:55:38 +000015
16static void make_bm(SkBitmap* bm) {
reed@google.comeb9a46c2014-01-25 16:46:20 +000017 bm->allocN32Pixels(60, 60);
reed@google.comd6382332013-04-16 16:55:38 +000018 bm->eraseColor(0);
19
20 SkCanvas canvas(*bm);
21 SkPaint paint;
reed@google.comf707adc2013-04-18 15:37:14 +000022
23 SkPath path;
24 path.moveTo(6, 6);
25 path.lineTo(6, 54);
26 path.lineTo(30, 54);
27 canvas.drawPath(path, paint);
28
reed@google.comd6382332013-04-16 16:55:38 +000029 paint.setStyle(SkPaint::kStroke_Style);
reed@google.com0a646592013-04-16 17:04:43 +000030 canvas.drawRect(SkRect::MakeLTRB(0.5f, 0.5f, 59.5f, 59.5f), paint);
reed@google.comd6382332013-04-16 16:55:38 +000031}
32
33// This creates a close, but imperfect concatenation of
34// scaling the image up by its dst-rect
35// scaling the image down by the matrix' scale
36// The bug was that for cases like this, we were incorrectly trying to take a
37// fast-path in the bitmapshader, but ended up drawing the last col of pixels
38// twice. The fix resulted in (a) not taking the fast-path, but (b) drawing
39// the image correctly.
40//
halcanary2a243382015-09-09 08:16:41 -070041DEF_SIMPLE_GM(bitmaprecttest, canvas, 320, 240) {
reed@google.comd6382332013-04-16 16:55:38 +000042 SkBitmap bm;
43 make_bm(&bm);
44
halcanary96fcdcc2015-08-27 07:41:13 -070045 canvas->drawBitmap(bm, 150, 45, nullptr);
skia.committer@gmail.com45fb8b62013-04-17 07:00:56 +000046
reed@google.com0a646592013-04-16 17:04:43 +000047 SkScalar scale = 0.472560018f;
reed@google.comf707adc2013-04-18 15:37:14 +000048 canvas->save();
reed@google.comd6382332013-04-16 16:55:38 +000049 canvas->scale(scale, scale);
reede47829b2015-08-06 10:02:53 -070050 canvas->drawBitmapRect(bm, SkRect::MakeXYWH(100, 100, 128, 128), nullptr);
reed@google.comf707adc2013-04-18 15:37:14 +000051 canvas->restore();
52
53 canvas->scale(-1, 1);
halcanary96fcdcc2015-08-27 07:41:13 -070054 canvas->drawBitmap(bm, -310, 45, nullptr);
reed@google.comd6382332013-04-16 16:55:38 +000055}