• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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/gm.h"
9 #include "include/core/SkBitmap.h"
10 #include "include/core/SkCanvas.h"
11 #include "include/core/SkPaint.h"
12 #include "include/core/SkPath.h"
13 #include "include/core/SkRect.h"
14 #include "include/core/SkScalar.h"
15 
make_bm(SkBitmap * bm)16 static void make_bm(SkBitmap* bm) {
17     bm->allocN32Pixels(60, 60);
18     bm->eraseColor(0);
19 
20     SkCanvas canvas(*bm);
21     SkPaint paint;
22 
23     SkPath path;
24     path.moveTo(6, 6);
25     path.lineTo(6, 54);
26     path.lineTo(30, 54);
27     canvas.drawPath(path, paint);
28 
29     paint.setStyle(SkPaint::kStroke_Style);
30     canvas.drawRect(SkRect::MakeLTRB(0.5f, 0.5f, 59.5f, 59.5f), paint);
31 }
32 
33 // This creates a close, but imperfect concatenation of
34 //      scaling the image up by its dst-rect
35 //      scaling the image down by the matrix' scale
36 //  The bug was that for cases like this, we were incorrectly trying to take a
37 //  fast-path in the bitmapshader, but ended up drawing the last col of pixels
38 //  twice. The fix resulted in (a) not taking the fast-path, but (b) drawing
39 //  the image correctly.
40 //
41 DEF_SIMPLE_GM(bitmaprecttest, canvas, 320, 240) {
42     SkBitmap bm;
43     make_bm(&bm);
44 
45     canvas->drawBitmap(bm, 150, 45, nullptr);
46 
47     SkScalar scale = 0.472560018f;
48     canvas->save();
49     canvas->scale(scale, scale);
50     canvas->drawBitmapRect(bm, SkRect::MakeXYWH(100, 100, 128, 128), nullptr);
51     canvas->restore();
52 
53     canvas->scale(-1, 1);
54     canvas->drawBitmap(bm, -310, 45, nullptr);
55 }
56