blob: 31c0a381fae37e42c7ccfcb69066f2665e4870e8 [file] [log] [blame]
bsalomon@google.com1a38d552012-03-15 14:40:46 +00001
2/*
3 * Copyright 2012 Google Inc.
4 *
5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file.
7 */
8#include "gm.h"
9
10#include "SkColorPriv.h"
11#include "SkShader.h"
12
13namespace skiagm {
14
15class BigMatrixGM : public GM {
16public:
17 BigMatrixGM() {
18 this->setBGColor(0xFF66AA99);
19 }
20
21protected:
22 virtual SkString onShortName() {
23 return SkString("bigmatrix");
24 }
25
26 virtual SkISize onISize() {
27 return make_isize(50, 50);
28 }
29
30 virtual void onDraw(SkCanvas* canvas) {
31 SkMatrix m;
32 m.reset();
33 m.setRotate(33 * SK_Scalar1);
34 m.postScale(3000 * SK_Scalar1, 3000 * SK_Scalar1);
35 m.postTranslate(6000 * SK_Scalar1, -5000 * SK_Scalar1);
36 canvas->concat(m);
37
38 SkPaint paint;
39 paint.setColor(SK_ColorRED);
40 paint.setAntiAlias(true);
41
reed@google.com57b19352012-04-19 19:25:49 +000042 bool success = m.invert(&m);
caryclark@google.com13130862012-06-06 12:10:45 +000043 SkASSERT(success);
bsalomon@google.com1a38d552012-03-15 14:40:46 +000044
45 SkPath path;
46
47 SkPoint pt = {10 * SK_Scalar1, 10 * SK_Scalar1};
48 SkScalar small = 1 / (500 * SK_Scalar1);
49
50 m.mapPoints(&pt, 1);
51 path.addCircle(pt.fX, pt.fY, small);
52 canvas->drawPath(path, paint);
53
54 pt.set(30 * SK_Scalar1, 10 * SK_Scalar1);
55 m.mapPoints(&pt, 1);
56 SkRect rect = {pt.fX - small, pt.fY - small,
57 pt.fX + small, pt.fY + small};
58 canvas->drawRect(rect, paint);
59
60 SkBitmap bmp;
61 bmp.setConfig(SkBitmap::kARGB_8888_Config, 2, 2);
62 bmp.allocPixels();
63 bmp.lockPixels();
64 uint32_t* pixels = reinterpret_cast<uint32_t*>(bmp.getPixels());
65 pixels[0] = SkPackARGB32(0xFF, 0xFF, 0x00, 0x00);
66 pixels[1] = SkPackARGB32(0xFF, 0x00, 0xFF, 0x00);
67 pixels[2] = SkPackARGB32(0x80, 0x00, 0x00, 0x00);
68 pixels[3] = SkPackARGB32(0xFF, 0x00, 0x00, 0xFF);
69 bmp.unlockPixels();
70 pt.set(30 * SK_Scalar1, 30 * SK_Scalar1);
71 m.mapPoints(&pt, 1);
72 SkShader* shader = SkShader::CreateBitmapShader(
73 bmp,
74 SkShader::kRepeat_TileMode,
75 SkShader::kRepeat_TileMode);
76 SkMatrix s;
77 s.reset();
78 s.setScale(SK_Scalar1 / 1000, SK_Scalar1 / 1000);
79 shader->setLocalMatrix(s);
80 paint.setShader(shader)->unref();
81 paint.setAntiAlias(false);
82 paint.setFilterBitmap(true);
83 rect.setLTRB(pt.fX - small, pt.fY - small,
84 pt.fX + small, pt.fY + small);
85 canvas->drawRect(rect, paint);
86 }
87
88private:
89 typedef GM INHERITED;
90};
91
92//////////////////////////////////////////////////////////////////////////////
93
94static GM* MyFactory(void*) { return new BigMatrixGM; }
95static GMRegistry reg(MyFactory);
96
97}
98