blob: 701aadc066ac3bc08412e913d9f454e9827fc4b5 [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
8#include "gm.h"
9#include "SkCanvas.h"
10
11static 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);
19 canvas.drawRect(SkRect::MakeLTRB(0.5f, 0.5f, 29.5f, 29.5f), paint);
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//
30static void test_bitmaprect(SkCanvas* canvas) {
31 SkBitmap bm;
32 make_bm(&bm);
33
34 canvas->drawBitmap(bm, 150, 45, NULL);
35
36 SkScalar scale = 0.452560018f;
37 canvas->scale(scale, scale);
38 canvas->drawBitmapRectToRect(bm, NULL, SkRect::MakeXYWH(100, 100, 128, 128), NULL);
39}
40
41class BitmapRectTestGM : public skiagm::GM {
42public:
43 BitmapRectTestGM() {
44
45 }
46
47protected:
48 virtual SkString onShortName() {
49 return SkString("bitmaprectest");
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
60private:
61 typedef skiagm::GM INHERITED;
62};
63
64//////////////////////////////////////////////////////////////////////////////
65
66DEF_GM( return new BitmapRectTestGM; )
67