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