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