blob: 630c90c600d6d8530ee5cccee693a8d3cf1dc6f1 [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"
bungemand3ebb482015-08-05 13:57:49 -070010#include "SkPath.h"
reed@google.comd6382332013-04-16 16:55:38 +000011
12static void make_bm(SkBitmap* bm) {
reed@google.comeb9a46c2014-01-25 16:46:20 +000013 bm->allocN32Pixels(60, 60);
reed@google.comd6382332013-04-16 16:55:38 +000014 bm->eraseColor(0);
15
16 SkCanvas canvas(*bm);
17 SkPaint paint;
reed@google.comf707adc2013-04-18 15:37:14 +000018
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.comd6382332013-04-16 16:55:38 +000025 paint.setStyle(SkPaint::kStroke_Style);
reed@google.com0a646592013-04-16 17:04:43 +000026 canvas.drawRect(SkRect::MakeLTRB(0.5f, 0.5f, 59.5f, 59.5f), paint);
reed@google.comd6382332013-04-16 16:55:38 +000027}
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//
37static void test_bitmaprect(SkCanvas* canvas) {
38 SkBitmap bm;
39 make_bm(&bm);
40
41 canvas->drawBitmap(bm, 150, 45, NULL);
skia.committer@gmail.com45fb8b62013-04-17 07:00:56 +000042
reed@google.com0a646592013-04-16 17:04:43 +000043 SkScalar scale = 0.472560018f;
reed@google.comf707adc2013-04-18 15:37:14 +000044 canvas->save();
reed@google.comd6382332013-04-16 16:55:38 +000045 canvas->scale(scale, scale);
reeda5517e22015-07-14 10:54:12 -070046 canvas->drawBitmapRect(bm, SkRect::MakeXYWH(100, 100, 128, 128));
reed@google.comf707adc2013-04-18 15:37:14 +000047 canvas->restore();
48
49 canvas->scale(-1, 1);
50 canvas->drawBitmap(bm, -310, 45, NULL);
reed@google.comd6382332013-04-16 16:55:38 +000051}
52
53class BitmapRectTestGM : public skiagm::GM {
54public:
55 BitmapRectTestGM() {
56
57 }
58
59protected:
mtklein36352bf2015-03-25 18:17:31 -070060 SkString onShortName() override {
reed@google.com8f6f67e2013-04-16 17:58:38 +000061 return SkString("bitmaprecttest");
reed@google.comd6382332013-04-16 16:55:38 +000062 }
63
mtklein36352bf2015-03-25 18:17:31 -070064 SkISize onISize() override {
reed@google.comd6382332013-04-16 16:55:38 +000065 return SkISize::Make(320, 240);
66 }
67
mtklein36352bf2015-03-25 18:17:31 -070068 void onDraw(SkCanvas* canvas) override {
reed@google.comd6382332013-04-16 16:55:38 +000069 test_bitmaprect(canvas);
70 }
71
72private:
73 typedef skiagm::GM INHERITED;
74};
75
76//////////////////////////////////////////////////////////////////////////////
77
78DEF_GM( return new BitmapRectTestGM; )