Debian Codegraph @

gm/bigmatrix.cpp

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