blob: 37b092e24e94e6ad1eee017d8a2542d4d83b90d7 [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 SkPath path;
bsalomon@google.com1a38d552012-03-15 14:40:46 +000042
Mike Kleinea3f0142019-03-20 11:12:10 -050043 SkPoint pt = {10 * SK_Scalar1, 10 * SK_Scalar1};
44 SkScalar small = 1 / (500 * SK_Scalar1);
bsalomon@google.com1a38d552012-03-15 14:40:46 +000045
Mike Kleinea3f0142019-03-20 11:12:10 -050046 m.mapPoints(&pt, 1);
47 path.addCircle(pt.fX, pt.fY, small);
48 canvas->drawPath(path, paint);
bsalomon@google.com1a38d552012-03-15 14:40:46 +000049
Mike Kleinea3f0142019-03-20 11:12:10 -050050 pt.set(30 * SK_Scalar1, 10 * SK_Scalar1);
51 m.mapPoints(&pt, 1);
52 SkRect rect = {pt.fX - small, pt.fY - small, pt.fX + small, pt.fY + small};
53 canvas->drawRect(rect, paint);
bsalomon@google.com1a38d552012-03-15 14:40:46 +000054
Mike Kleinea3f0142019-03-20 11:12:10 -050055 SkBitmap bmp;
56 bmp.allocN32Pixels(2, 2);
57 uint32_t* pixels = reinterpret_cast<uint32_t*>(bmp.getPixels());
58 pixels[0] = SkPackARGB32(0xFF, 0xFF, 0x00, 0x00);
59 pixels[1] = SkPackARGB32(0xFF, 0x00, 0xFF, 0x00);
60 pixels[2] = SkPackARGB32(0x80, 0x00, 0x00, 0x00);
61 pixels[3] = SkPackARGB32(0xFF, 0x00, 0x00, 0xFF);
62 pt.set(30 * SK_Scalar1, 30 * SK_Scalar1);
63 m.mapPoints(&pt, 1);
64 SkMatrix s;
65 s.reset();
66 s.setScale(SK_Scalar1 / 1000, SK_Scalar1 / 1000);
Mike Reed50acf8f2019-04-08 13:20:23 -040067 paint.setShader(bmp.makeShader(SkTileMode::kRepeat, SkTileMode::kRepeat, &s));
Mike Kleinea3f0142019-03-20 11:12:10 -050068 paint.setAntiAlias(false);
69 paint.setFilterQuality(kLow_SkFilterQuality);
70 rect.setLTRB(pt.fX - small, pt.fY - small, pt.fX + small, pt.fY + small);
71 canvas->drawRect(rect, paint);
bsalomon@google.com1a38d552012-03-15 14:40:46 +000072}