blob: c7c3b0dd07ea4855c9bf9ef12f833fdd3d0f2ddc [file] [log] [blame]
bsalomon@google.com1a38d552012-03-15 14:40:46 +00001/*
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 */
bungemand3ebb482015-08-05 13:57:49 -07007
bsalomon@google.com1a38d552012-03-15 14:40:46 +00008#include "gm.h"
9
10#include "SkColorPriv.h"
bungemand3ebb482015-08-05 13:57:49 -070011#include "SkPath.h"
bsalomon@google.com1a38d552012-03-15 14:40:46 +000012#include "SkShader.h"
13
14namespace skiagm {
15
16class BigMatrixGM : public GM {
17public:
18 BigMatrixGM() {
caryclark65cdba62015-06-15 06:51:08 -070019 this->setBGColor(sk_tool_utils::color_to_565(0xFF66AA99));
bsalomon@google.com1a38d552012-03-15 14:40:46 +000020 }
21
22protected:
23 virtual SkString onShortName() {
24 return SkString("bigmatrix");
25 }
26
27 virtual SkISize onISize() {
tfarinaf5393182014-06-09 23:59:03 -070028 return SkISize::Make(50, 50);
bsalomon@google.com1a38d552012-03-15 14:40:46 +000029 }
30
31 virtual void onDraw(SkCanvas* canvas) {
32 SkMatrix m;
33 m.reset();
34 m.setRotate(33 * SK_Scalar1);
35 m.postScale(3000 * SK_Scalar1, 3000 * SK_Scalar1);
36 m.postTranslate(6000 * SK_Scalar1, -5000 * SK_Scalar1);
37 canvas->concat(m);
38
39 SkPaint paint;
40 paint.setColor(SK_ColorRED);
41 paint.setAntiAlias(true);
42
reed@google.com57b19352012-04-19 19:25:49 +000043 bool success = m.invert(&m);
caryclark@google.com13130862012-06-06 12:10:45 +000044 SkASSERT(success);
humper@google.com0e515772013-01-07 19:54:40 +000045 (void) success; // silence compiler :(
bsalomon@google.com1a38d552012-03-15 14:40:46 +000046
47 SkPath path;
48
49 SkPoint pt = {10 * SK_Scalar1, 10 * SK_Scalar1};
50 SkScalar small = 1 / (500 * SK_Scalar1);
51
52 m.mapPoints(&pt, 1);
53 path.addCircle(pt.fX, pt.fY, small);
54 canvas->drawPath(path, paint);
55
56 pt.set(30 * SK_Scalar1, 10 * SK_Scalar1);
57 m.mapPoints(&pt, 1);
58 SkRect rect = {pt.fX - small, pt.fY - small,
59 pt.fX + small, pt.fY + small};
60 canvas->drawRect(rect, paint);
61
62 SkBitmap bmp;
reed@google.comeb9a46c2014-01-25 16:46:20 +000063 bmp.allocN32Pixels(2, 2);
bsalomon@google.com1a38d552012-03-15 14:40:46 +000064 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);
bsalomon@google.com1a38d552012-03-15 14:40:46 +000069 pt.set(30 * SK_Scalar1, 30 * SK_Scalar1);
70 m.mapPoints(&pt, 1);
bsalomon@google.com1a38d552012-03-15 14:40:46 +000071 SkMatrix s;
72 s.reset();
73 s.setScale(SK_Scalar1 / 1000, SK_Scalar1 / 1000);
commit-bot@chromium.org9c9005a2014-04-28 14:55:39 +000074 SkShader* shader = SkShader::CreateBitmapShader(
75 bmp,
76 SkShader::kRepeat_TileMode,
77 SkShader::kRepeat_TileMode,
78 &s);
bsalomon@google.com1a38d552012-03-15 14:40:46 +000079 paint.setShader(shader)->unref();
80 paint.setAntiAlias(false);
reed93a12152015-03-16 10:08:34 -070081 paint.setFilterQuality(kLow_SkFilterQuality);
bsalomon@google.com1a38d552012-03-15 14:40:46 +000082 rect.setLTRB(pt.fX - small, pt.fY - small,
83 pt.fX + small, pt.fY + small);
84 canvas->drawRect(rect, paint);
85 }
86
87private:
88 typedef GM INHERITED;
89};
90
91//////////////////////////////////////////////////////////////////////////////
92
93static GM* MyFactory(void*) { return new BigMatrixGM; }
94static GMRegistry reg(MyFactory);
95
96}