1 /*
2  * Copyright 2012 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/SkColor.h"
12 #include "include/core/SkColorPriv.h"
13 #include "include/core/SkFilterQuality.h"
14 #include "include/core/SkMatrix.h"
15 #include "include/core/SkPaint.h"
16 #include "include/core/SkPath.h"
17 #include "include/core/SkPoint.h"
18 #include "include/core/SkRect.h"
19 #include "include/core/SkScalar.h"
20 #include "include/core/SkShader.h"
21 #include "include/core/SkTileMode.h"
22 #include "include/core/SkTypes.h"
23 #include "tools/ToolUtils.h"
24 
25 DEF_SIMPLE_GM_BG(bigmatrix, canvas, 50, 50, ToolUtils::color_to_565(0xFF66AA99)) {
26     SkMatrix m;
27     m.reset();
28     m.setRotate(33 * SK_Scalar1);
29     m.postScale(3000 * SK_Scalar1, 3000 * SK_Scalar1);
30     m.postTranslate(6000 * SK_Scalar1, -5000 * SK_Scalar1);
31     canvas->concat(m);
32 
33     SkPaint paint;
34     paint.setColor(SK_ColorRED);
35     paint.setAntiAlias(true);
36 
37     bool success = m.invert(&m);
38     SkASSERT(success);
39     (void)success;  // silence compiler :(
40 
41     SkPoint  pt    = {10 * SK_Scalar1, 10 * SK_Scalar1};
42     SkScalar small = 1 / (500 * SK_Scalar1);
43 
44     m.mapPoints(&pt, 1);
45     canvas->drawCircle(pt.fX, pt.fY, small, paint);
46 
47     pt.set(30 * SK_Scalar1, 10 * SK_Scalar1);
48     m.mapPoints(&pt, 1);
49     SkRect rect = {pt.fX - small, pt.fY - small, pt.fX + small, pt.fY + small};
50     canvas->drawRect(rect, paint);
51 
52     SkBitmap bmp;
53     bmp.allocN32Pixels(2, 2);
54     uint32_t* pixels = reinterpret_cast<uint32_t*>(bmp.getPixels());
55     pixels[0]        = SkPackARGB32(0xFF, 0xFF, 0x00, 0x00);
56     pixels[1]        = SkPackARGB32(0xFF, 0x00, 0xFF, 0x00);
57     pixels[2]        = SkPackARGB32(0x80, 0x00, 0x00, 0x00);
58     pixels[3]        = SkPackARGB32(0xFF, 0x00, 0x00, 0xFF);
59     pt.set(30 * SK_Scalar1, 30 * SK_Scalar1);
60     m.mapPoints(&pt, 1);
61     SkMatrix s;
62     s.reset();
63     s.setScale(SK_Scalar1 / 1000, SK_Scalar1 / 1000);
64     paint.setShader(bmp.makeShader(SkTileMode::kRepeat, SkTileMode::kRepeat, &s));
65     paint.setAntiAlias(false);
66     paint.setFilterQuality(kLow_SkFilterQuality);
67     rect.setLTRB(pt.fX - small, pt.fY - small, pt.fX + small, pt.fY + small);
68     canvas->drawRect(rect, paint);
69 }
70