reed@google.com | d638233 | 2013-04-16 16:55:38 +0000 | [diff] [blame] | 1 | /* |
| 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 Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 8 | #include "gm/gm.h" |
Ben Wagner | 6a34f3a | 2019-05-01 10:59:30 -0400 | [diff] [blame] | 9 | #include "include/core/SkBitmap.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 10 | #include "include/core/SkCanvas.h" |
Mike Reed | fa582c8 | 2021-01-23 22:07:05 -0500 | [diff] [blame] | 11 | #include "include/core/SkImage.h" |
Ben Wagner | 6a34f3a | 2019-05-01 10:59:30 -0400 | [diff] [blame] | 12 | #include "include/core/SkPaint.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 13 | #include "include/core/SkPath.h" |
Ben Wagner | 6a34f3a | 2019-05-01 10:59:30 -0400 | [diff] [blame] | 14 | #include "include/core/SkRect.h" |
| 15 | #include "include/core/SkScalar.h" |
reed@google.com | d638233 | 2013-04-16 16:55:38 +0000 | [diff] [blame] | 16 | |
Mike Reed | fa582c8 | 2021-01-23 22:07:05 -0500 | [diff] [blame] | 17 | static sk_sp<SkImage> make_bm() { |
| 18 | SkBitmap bm; |
| 19 | bm.allocN32Pixels(60, 60); |
| 20 | bm.eraseColor(0); |
reed@google.com | d638233 | 2013-04-16 16:55:38 +0000 | [diff] [blame] | 21 | |
Mike Reed | fa582c8 | 2021-01-23 22:07:05 -0500 | [diff] [blame] | 22 | SkCanvas canvas(bm); |
reed@google.com | d638233 | 2013-04-16 16:55:38 +0000 | [diff] [blame] | 23 | SkPaint paint; |
Mike Reed | 093de4e | 2020-08-03 16:33:14 -0400 | [diff] [blame] | 24 | canvas.drawPath(SkPath::Polygon({{6,6}, {6,54}, {30,54}}, false), paint); |
reed@google.com | f707adc | 2013-04-18 15:37:14 +0000 | [diff] [blame] | 25 | |
reed@google.com | d638233 | 2013-04-16 16:55:38 +0000 | [diff] [blame] | 26 | paint.setStyle(SkPaint::kStroke_Style); |
reed@google.com | 0a64659 | 2013-04-16 17:04:43 +0000 | [diff] [blame] | 27 | canvas.drawRect(SkRect::MakeLTRB(0.5f, 0.5f, 59.5f, 59.5f), paint); |
Mike Reed | fa582c8 | 2021-01-23 22:07:05 -0500 | [diff] [blame] | 28 | return bm.asImage(); |
reed@google.com | d638233 | 2013-04-16 16:55:38 +0000 | [diff] [blame] | 29 | } |
| 30 | |
| 31 | // This creates a close, but imperfect concatenation of |
| 32 | // scaling the image up by its dst-rect |
| 33 | // scaling the image down by the matrix' scale |
| 34 | // The bug was that for cases like this, we were incorrectly trying to take a |
| 35 | // fast-path in the bitmapshader, but ended up drawing the last col of pixels |
| 36 | // twice. The fix resulted in (a) not taking the fast-path, but (b) drawing |
| 37 | // the image correctly. |
| 38 | // |
halcanary | 2a24338 | 2015-09-09 08:16:41 -0700 | [diff] [blame] | 39 | DEF_SIMPLE_GM(bitmaprecttest, canvas, 320, 240) { |
Mike Reed | fa582c8 | 2021-01-23 22:07:05 -0500 | [diff] [blame] | 40 | auto image = make_bm(); |
reed@google.com | d638233 | 2013-04-16 16:55:38 +0000 | [diff] [blame] | 41 | |
Mike Reed | fa582c8 | 2021-01-23 22:07:05 -0500 | [diff] [blame] | 42 | canvas->drawImage(image, 150, 45); |
skia.committer@gmail.com | 45fb8b6 | 2013-04-17 07:00:56 +0000 | [diff] [blame] | 43 | |
reed@google.com | 0a64659 | 2013-04-16 17:04:43 +0000 | [diff] [blame] | 44 | SkScalar scale = 0.472560018f; |
reed@google.com | f707adc | 2013-04-18 15:37:14 +0000 | [diff] [blame] | 45 | canvas->save(); |
reed@google.com | d638233 | 2013-04-16 16:55:38 +0000 | [diff] [blame] | 46 | canvas->scale(scale, scale); |
Mike Reed | fa582c8 | 2021-01-23 22:07:05 -0500 | [diff] [blame] | 47 | canvas->drawImageRect(image, SkRect::MakeXYWH(100, 100, 128, 128), SkSamplingOptions()); |
reed@google.com | f707adc | 2013-04-18 15:37:14 +0000 | [diff] [blame] | 48 | canvas->restore(); |
| 49 | |
| 50 | canvas->scale(-1, 1); |
Mike Reed | fa582c8 | 2021-01-23 22:07:05 -0500 | [diff] [blame] | 51 | canvas->drawImage(image, -310, 45); |
reed@google.com | d638233 | 2013-04-16 16:55:38 +0000 | [diff] [blame] | 52 | } |