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" |
| 10 | |
| 11 | static void make_bm(SkBitmap* bm) { |
reed@google.com | eb9a46c | 2014-01-25 16:46:20 +0000 | [diff] [blame] | 12 | bm->allocN32Pixels(60, 60); |
reed@google.com | d638233 | 2013-04-16 16:55:38 +0000 | [diff] [blame] | 13 | bm->eraseColor(0); |
| 14 | |
| 15 | SkCanvas canvas(*bm); |
| 16 | SkPaint paint; |
reed@google.com | f707adc | 2013-04-18 15:37:14 +0000 | [diff] [blame] | 17 | |
| 18 | SkPath path; |
| 19 | path.moveTo(6, 6); |
| 20 | path.lineTo(6, 54); |
| 21 | path.lineTo(30, 54); |
| 22 | canvas.drawPath(path, paint); |
| 23 | |
reed@google.com | d638233 | 2013-04-16 16:55:38 +0000 | [diff] [blame] | 24 | paint.setStyle(SkPaint::kStroke_Style); |
reed@google.com | 0a64659 | 2013-04-16 17:04:43 +0000 | [diff] [blame] | 25 | 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] | 26 | } |
| 27 | |
| 28 | // This creates a close, but imperfect concatenation of |
| 29 | // scaling the image up by its dst-rect |
| 30 | // scaling the image down by the matrix' scale |
| 31 | // The bug was that for cases like this, we were incorrectly trying to take a |
| 32 | // fast-path in the bitmapshader, but ended up drawing the last col of pixels |
| 33 | // twice. The fix resulted in (a) not taking the fast-path, but (b) drawing |
| 34 | // the image correctly. |
| 35 | // |
| 36 | static void test_bitmaprect(SkCanvas* canvas) { |
| 37 | SkBitmap bm; |
| 38 | make_bm(&bm); |
| 39 | |
| 40 | canvas->drawBitmap(bm, 150, 45, NULL); |
skia.committer@gmail.com | 45fb8b6 | 2013-04-17 07:00:56 +0000 | [diff] [blame] | 41 | |
reed@google.com | 0a64659 | 2013-04-16 17:04:43 +0000 | [diff] [blame] | 42 | SkScalar scale = 0.472560018f; |
reed@google.com | f707adc | 2013-04-18 15:37:14 +0000 | [diff] [blame] | 43 | canvas->save(); |
reed@google.com | d638233 | 2013-04-16 16:55:38 +0000 | [diff] [blame] | 44 | canvas->scale(scale, scale); |
| 45 | canvas->drawBitmapRectToRect(bm, NULL, SkRect::MakeXYWH(100, 100, 128, 128), NULL); |
reed@google.com | f707adc | 2013-04-18 15:37:14 +0000 | [diff] [blame] | 46 | canvas->restore(); |
| 47 | |
| 48 | canvas->scale(-1, 1); |
| 49 | canvas->drawBitmap(bm, -310, 45, NULL); |
reed@google.com | d638233 | 2013-04-16 16:55:38 +0000 | [diff] [blame] | 50 | } |
| 51 | |
| 52 | class BitmapRectTestGM : public skiagm::GM { |
| 53 | public: |
| 54 | BitmapRectTestGM() { |
| 55 | |
| 56 | } |
| 57 | |
| 58 | protected: |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 59 | SkString onShortName() override { |
reed@google.com | 8f6f67e | 2013-04-16 17:58:38 +0000 | [diff] [blame] | 60 | return SkString("bitmaprecttest"); |
reed@google.com | d638233 | 2013-04-16 16:55:38 +0000 | [diff] [blame] | 61 | } |
| 62 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 63 | SkISize onISize() override { |
reed@google.com | d638233 | 2013-04-16 16:55:38 +0000 | [diff] [blame] | 64 | return SkISize::Make(320, 240); |
| 65 | } |
| 66 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 67 | void onDraw(SkCanvas* canvas) override { |
reed@google.com | d638233 | 2013-04-16 16:55:38 +0000 | [diff] [blame] | 68 | test_bitmaprect(canvas); |
| 69 | } |
| 70 | |
| 71 | private: |
| 72 | typedef skiagm::GM INHERITED; |
| 73 | }; |
| 74 | |
| 75 | ////////////////////////////////////////////////////////////////////////////// |
| 76 | |
| 77 | DEF_GM( return new BitmapRectTestGM; ) |