blob: 06495b957e46f7fdee9588c2249e504202f36309 [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) {
reed@google.comeb9a46c2014-01-25 16:46:20 +000012 bm->allocN32Pixels(60, 60);
reed@google.comd6382332013-04-16 16:55:38 +000013 bm->eraseColor(0);
14
15 SkCanvas canvas(*bm);
16 SkPaint paint;
reed@google.comf707adc2013-04-18 15:37:14 +000017
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.comd6382332013-04-16 16:55:38 +000024 paint.setStyle(SkPaint::kStroke_Style);
reed@google.com0a646592013-04-16 17:04:43 +000025 canvas.drawRect(SkRect::MakeLTRB(0.5f, 0.5f, 59.5f, 59.5f), paint);
reed@google.comd6382332013-04-16 16:55:38 +000026}
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//
36static void test_bitmaprect(SkCanvas* canvas) {
37 SkBitmap bm;
38 make_bm(&bm);
39
40 canvas->drawBitmap(bm, 150, 45, NULL);
skia.committer@gmail.com45fb8b62013-04-17 07:00:56 +000041
reed@google.com0a646592013-04-16 17:04:43 +000042 SkScalar scale = 0.472560018f;
reed@google.comf707adc2013-04-18 15:37:14 +000043 canvas->save();
reed@google.comd6382332013-04-16 16:55:38 +000044 canvas->scale(scale, scale);
45 canvas->drawBitmapRectToRect(bm, NULL, SkRect::MakeXYWH(100, 100, 128, 128), NULL);
reed@google.comf707adc2013-04-18 15:37:14 +000046 canvas->restore();
47
48 canvas->scale(-1, 1);
49 canvas->drawBitmap(bm, -310, 45, NULL);
reed@google.comd6382332013-04-16 16:55:38 +000050}
51
52class BitmapRectTestGM : public skiagm::GM {
53public:
54 BitmapRectTestGM() {
55
56 }
57
58protected:
commit-bot@chromium.orga90c6802014-04-30 13:20:45 +000059 virtual uint32_t onGetFlags() const SK_OVERRIDE {
60 return kSkipTiled_Flag;
61 }
62
reed@google.comd6382332013-04-16 16:55:38 +000063 virtual SkString onShortName() {
reed@google.com8f6f67e2013-04-16 17:58:38 +000064 return SkString("bitmaprecttest");
reed@google.comd6382332013-04-16 16:55:38 +000065 }
66
67 virtual SkISize onISize() {
68 return SkISize::Make(320, 240);
69 }
70
71 virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE {
72 test_bitmaprect(canvas);
73 }
74
75private:
76 typedef skiagm::GM INHERITED;
77};
78
79//////////////////////////////////////////////////////////////////////////////
80
81DEF_GM( return new BitmapRectTestGM; )