blob: 288e827589ca3f146ba281a6bdb8e41eae818622 [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:
commit-bot@chromium.orga90c6802014-04-30 13:20:45 +000022 virtual uint32_t onGetFlags() const SK_OVERRIDE {
23 return kSkipTiled_Flag;
24 }
25
bsalomon@google.com1a38d552012-03-15 14:40:46 +000026 virtual SkString onShortName() {
27 return SkString("bigmatrix");
28 }
29
30 virtual SkISize onISize() {
31 return make_isize(50, 50);
32 }
33
34 virtual void onDraw(SkCanvas* canvas) {
35 SkMatrix m;
36 m.reset();
37 m.setRotate(33 * SK_Scalar1);
38 m.postScale(3000 * SK_Scalar1, 3000 * SK_Scalar1);
39 m.postTranslate(6000 * SK_Scalar1, -5000 * SK_Scalar1);
40 canvas->concat(m);
41
42 SkPaint paint;
43 paint.setColor(SK_ColorRED);
44 paint.setAntiAlias(true);
45
reed@google.com57b19352012-04-19 19:25:49 +000046 bool success = m.invert(&m);
caryclark@google.com13130862012-06-06 12:10:45 +000047 SkASSERT(success);
humper@google.com0e515772013-01-07 19:54:40 +000048 (void) success; // silence compiler :(
bsalomon@google.com1a38d552012-03-15 14:40:46 +000049
50 SkPath path;
51
52 SkPoint pt = {10 * SK_Scalar1, 10 * SK_Scalar1};
53 SkScalar small = 1 / (500 * SK_Scalar1);
54
55 m.mapPoints(&pt, 1);
56 path.addCircle(pt.fX, pt.fY, small);
57 canvas->drawPath(path, paint);
58
59 pt.set(30 * SK_Scalar1, 10 * SK_Scalar1);
60 m.mapPoints(&pt, 1);
61 SkRect rect = {pt.fX - small, pt.fY - small,
62 pt.fX + small, pt.fY + small};
63 canvas->drawRect(rect, paint);
64
65 SkBitmap bmp;
reed@google.comeb9a46c2014-01-25 16:46:20 +000066 bmp.allocN32Pixels(2, 2);
bsalomon@google.com1a38d552012-03-15 14:40:46 +000067 uint32_t* pixels = reinterpret_cast<uint32_t*>(bmp.getPixels());
68 pixels[0] = SkPackARGB32(0xFF, 0xFF, 0x00, 0x00);
69 pixels[1] = SkPackARGB32(0xFF, 0x00, 0xFF, 0x00);
70 pixels[2] = SkPackARGB32(0x80, 0x00, 0x00, 0x00);
71 pixels[3] = SkPackARGB32(0xFF, 0x00, 0x00, 0xFF);
bsalomon@google.com1a38d552012-03-15 14:40:46 +000072 pt.set(30 * SK_Scalar1, 30 * SK_Scalar1);
73 m.mapPoints(&pt, 1);
bsalomon@google.com1a38d552012-03-15 14:40:46 +000074 SkMatrix s;
75 s.reset();
76 s.setScale(SK_Scalar1 / 1000, SK_Scalar1 / 1000);
commit-bot@chromium.org9c9005a2014-04-28 14:55:39 +000077 SkShader* shader = SkShader::CreateBitmapShader(
78 bmp,
79 SkShader::kRepeat_TileMode,
80 SkShader::kRepeat_TileMode,
81 &s);
bsalomon@google.com1a38d552012-03-15 14:40:46 +000082 paint.setShader(shader)->unref();
83 paint.setAntiAlias(false);
reed@google.com44699382013-10-31 17:28:30 +000084 paint.setFilterLevel(SkPaint::kLow_FilterLevel);
bsalomon@google.com1a38d552012-03-15 14:40:46 +000085 rect.setLTRB(pt.fX - small, pt.fY - small,
86 pt.fX + small, pt.fY + small);
87 canvas->drawRect(rect, paint);
88 }
89
90private:
91 typedef GM INHERITED;
92};
93
94//////////////////////////////////////////////////////////////////////////////
95
96static GM* MyFactory(void*) { return new BigMatrixGM; }
97static GMRegistry reg(MyFactory);
98
99}