blob: 3720d10f41195be48e5c5e7ce69e82aeb78bea81 [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/SkMatrix.h"
14#include "include/core/SkPaint.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050015#include "include/core/SkPath.h"
Ben Wagner6a34f3a2019-05-01 10:59:30 -040016#include "include/core/SkPoint.h"
17#include "include/core/SkRect.h"
18#include "include/core/SkScalar.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050019#include "include/core/SkShader.h"
Ben Wagner6a34f3a2019-05-01 10:59:30 -040020#include "include/core/SkTileMode.h"
21#include "include/core/SkTypes.h"
22#include "tools/ToolUtils.h"
bsalomon@google.com1a38d552012-03-15 14:40:46 +000023
Mike Kleinea3f0142019-03-20 11:12:10 -050024DEF_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);
bsalomon@google.com1a38d552012-03-15 14:40:46 +000031
Mike Kleinea3f0142019-03-20 11:12:10 -050032 SkPaint paint;
33 paint.setColor(SK_ColorRED);
34 paint.setAntiAlias(true);
bsalomon@google.com1a38d552012-03-15 14:40:46 +000035
Mike Kleinea3f0142019-03-20 11:12:10 -050036 bool success = m.invert(&m);
37 SkASSERT(success);
38 (void)success; // silence compiler :(
bsalomon@google.com1a38d552012-03-15 14:40:46 +000039
Mike Kleinea3f0142019-03-20 11:12:10 -050040 SkPoint pt = {10 * SK_Scalar1, 10 * SK_Scalar1};
41 SkScalar small = 1 / (500 * SK_Scalar1);
bsalomon@google.com1a38d552012-03-15 14:40:46 +000042
Mike Kleinea3f0142019-03-20 11:12:10 -050043 m.mapPoints(&pt, 1);
Mike Reed92f6eb12020-08-25 11:48:41 -040044 canvas->drawCircle(pt.fX, pt.fY, small, paint);
bsalomon@google.com1a38d552012-03-15 14:40:46 +000045
Mike Kleinea3f0142019-03-20 11:12:10 -050046 pt.set(30 * SK_Scalar1, 10 * SK_Scalar1);
47 m.mapPoints(&pt, 1);
48 SkRect rect = {pt.fX - small, pt.fY - small, pt.fX + small, pt.fY + small};
49 canvas->drawRect(rect, paint);
bsalomon@google.com1a38d552012-03-15 14:40:46 +000050
Mike Kleinea3f0142019-03-20 11:12:10 -050051 SkBitmap bmp;
52 bmp.allocN32Pixels(2, 2);
53 uint32_t* pixels = reinterpret_cast<uint32_t*>(bmp.getPixels());
54 pixels[0] = SkPackARGB32(0xFF, 0xFF, 0x00, 0x00);
55 pixels[1] = SkPackARGB32(0xFF, 0x00, 0xFF, 0x00);
56 pixels[2] = SkPackARGB32(0x80, 0x00, 0x00, 0x00);
57 pixels[3] = SkPackARGB32(0xFF, 0x00, 0x00, 0xFF);
58 pt.set(30 * SK_Scalar1, 30 * SK_Scalar1);
59 m.mapPoints(&pt, 1);
60 SkMatrix s;
61 s.reset();
62 s.setScale(SK_Scalar1 / 1000, SK_Scalar1 / 1000);
Mike Reed82abece2020-12-12 09:51:11 -050063 paint.setShader(bmp.makeShader(SkTileMode::kRepeat, SkTileMode::kRepeat,
Mike Reed5ec22382021-01-14 21:59:01 -050064 SkSamplingOptions(SkFilterMode::kLinear), s));
Mike Kleinea3f0142019-03-20 11:12:10 -050065 paint.setAntiAlias(false);
Mike Kleinea3f0142019-03-20 11:12:10 -050066 rect.setLTRB(pt.fX - small, pt.fY - small, pt.fX + small, pt.fY + small);
67 canvas->drawRect(rect, paint);
bsalomon@google.com1a38d552012-03-15 14:40:46 +000068}