blob: d19b0490318b81e83468f64cd9c4d70b2de0f197 [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
Mike Kleinc0bd9f92019-04-23 12:05:21 -05008#include "gm/gm.h"
Ben Wagner6a34f3a2019-05-01 10:59:30 -04009#include "include/core/SkBitmap.h"
10#include "include/core/SkCanvas.h"
11#include "include/core/SkColor.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050012#include "include/core/SkColorPriv.h"
Ben Wagner6a34f3a2019-05-01 10:59:30 -040013#include "include/core/SkFilterQuality.h"
14#include "include/core/SkMatrix.h"
15#include "include/core/SkPaint.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050016#include "include/core/SkPath.h"
Ben Wagner6a34f3a2019-05-01 10:59:30 -040017#include "include/core/SkPoint.h"
18#include "include/core/SkRect.h"
19#include "include/core/SkScalar.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050020#include "include/core/SkShader.h"
Ben Wagner6a34f3a2019-05-01 10:59:30 -040021#include "include/core/SkTileMode.h"
22#include "include/core/SkTypes.h"
23#include "tools/ToolUtils.h"
bsalomon@google.com1a38d552012-03-15 14:40:46 +000024
Mike Kleinea3f0142019-03-20 11:12:10 -050025DEF_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);
bsalomon@google.com1a38d552012-03-15 14:40:46 +000032
Mike Kleinea3f0142019-03-20 11:12:10 -050033 SkPaint paint;
34 paint.setColor(SK_ColorRED);
35 paint.setAntiAlias(true);
bsalomon@google.com1a38d552012-03-15 14:40:46 +000036
Mike Kleinea3f0142019-03-20 11:12:10 -050037 bool success = m.invert(&m);
38 SkASSERT(success);
39 (void)success; // silence compiler :(
bsalomon@google.com1a38d552012-03-15 14:40:46 +000040
Mike Kleinea3f0142019-03-20 11:12:10 -050041 SkPoint pt = {10 * SK_Scalar1, 10 * SK_Scalar1};
42 SkScalar small = 1 / (500 * SK_Scalar1);
bsalomon@google.com1a38d552012-03-15 14:40:46 +000043
Mike Kleinea3f0142019-03-20 11:12:10 -050044 m.mapPoints(&pt, 1);
Mike Reed92f6eb12020-08-25 11:48:41 -040045 canvas->drawCircle(pt.fX, pt.fY, small, paint);
bsalomon@google.com1a38d552012-03-15 14:40:46 +000046
Mike Kleinea3f0142019-03-20 11:12:10 -050047 pt.set(30 * SK_Scalar1, 10 * SK_Scalar1);
48 m.mapPoints(&pt, 1);
49 SkRect rect = {pt.fX - small, pt.fY - small, pt.fX + small, pt.fY + small};
50 canvas->drawRect(rect, paint);
bsalomon@google.com1a38d552012-03-15 14:40:46 +000051
Mike Kleinea3f0142019-03-20 11:12:10 -050052 SkBitmap bmp;
53 bmp.allocN32Pixels(2, 2);
54 uint32_t* pixels = reinterpret_cast<uint32_t*>(bmp.getPixels());
55 pixels[0] = SkPackARGB32(0xFF, 0xFF, 0x00, 0x00);
56 pixels[1] = SkPackARGB32(0xFF, 0x00, 0xFF, 0x00);
57 pixels[2] = SkPackARGB32(0x80, 0x00, 0x00, 0x00);
58 pixels[3] = SkPackARGB32(0xFF, 0x00, 0x00, 0xFF);
59 pt.set(30 * SK_Scalar1, 30 * SK_Scalar1);
60 m.mapPoints(&pt, 1);
61 SkMatrix s;
62 s.reset();
63 s.setScale(SK_Scalar1 / 1000, SK_Scalar1 / 1000);
Mike Reed50acf8f2019-04-08 13:20:23 -040064 paint.setShader(bmp.makeShader(SkTileMode::kRepeat, SkTileMode::kRepeat, &s));
Mike Kleinea3f0142019-03-20 11:12:10 -050065 paint.setAntiAlias(false);
66 paint.setFilterQuality(kLow_SkFilterQuality);
67 rect.setLTRB(pt.fX - small, pt.fY - small, pt.fX + small, pt.fY + small);
68 canvas->drawRect(rect, paint);
bsalomon@google.com1a38d552012-03-15 14:40:46 +000069}