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