• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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     SkPath path;
42 
43     SkPoint  pt    = {10 * SK_Scalar1, 10 * SK_Scalar1};
44     SkScalar small = 1 / (500 * SK_Scalar1);
45 
46     m.mapPoints(&pt, 1);
47     path.addCircle(pt.fX, pt.fY, small);
48     canvas->drawPath(path, paint);
49 
50     pt.set(30 * SK_Scalar1, 10 * SK_Scalar1);
51     m.mapPoints(&pt, 1);
52     SkRect rect = {pt.fX - small, pt.fY - small, pt.fX + small, pt.fY + small};
53     canvas->drawRect(rect, paint);
54 
55     SkBitmap bmp;
56     bmp.allocN32Pixels(2, 2);
57     uint32_t* pixels = reinterpret_cast<uint32_t*>(bmp.getPixels());
58     pixels[0]        = SkPackARGB32(0xFF, 0xFF, 0x00, 0x00);
59     pixels[1]        = SkPackARGB32(0xFF, 0x00, 0xFF, 0x00);
60     pixels[2]        = SkPackARGB32(0x80, 0x00, 0x00, 0x00);
61     pixels[3]        = SkPackARGB32(0xFF, 0x00, 0x00, 0xFF);
62     pt.set(30 * SK_Scalar1, 30 * SK_Scalar1);
63     m.mapPoints(&pt, 1);
64     SkMatrix s;
65     s.reset();
66     s.setScale(SK_Scalar1 / 1000, SK_Scalar1 / 1000);
67     paint.setShader(bmp.makeShader(SkTileMode::kRepeat, SkTileMode::kRepeat, &s));
68     paint.setAntiAlias(false);
69     paint.setFilterQuality(kLow_SkFilterQuality);
70     rect.setLTRB(pt.fX - small, pt.fY - small, pt.fX + small, pt.fY + small);
71     canvas->drawRect(rect, paint);
72 }
73