bsalomon@google.com | 1a38d55 | 2012-03-15 14:40:46 +0000 | [diff] [blame] | 1 | /* |
| 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 | */ |
bungeman | d3ebb48 | 2015-08-05 13:57:49 -0700 | [diff] [blame] | 7 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 8 | #include "gm/gm.h" |
Ben Wagner | 6a34f3a | 2019-05-01 10:59:30 -0400 | [diff] [blame] | 9 | #include "include/core/SkBitmap.h" |
| 10 | #include "include/core/SkCanvas.h" |
| 11 | #include "include/core/SkColor.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 12 | #include "include/core/SkColorPriv.h" |
Ben Wagner | 6a34f3a | 2019-05-01 10:59:30 -0400 | [diff] [blame] | 13 | #include "include/core/SkFilterQuality.h" |
| 14 | #include "include/core/SkMatrix.h" |
| 15 | #include "include/core/SkPaint.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 16 | #include "include/core/SkPath.h" |
Ben Wagner | 6a34f3a | 2019-05-01 10:59:30 -0400 | [diff] [blame] | 17 | #include "include/core/SkPoint.h" |
| 18 | #include "include/core/SkRect.h" |
| 19 | #include "include/core/SkScalar.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 20 | #include "include/core/SkShader.h" |
Ben Wagner | 6a34f3a | 2019-05-01 10:59:30 -0400 | [diff] [blame] | 21 | #include "include/core/SkTileMode.h" |
| 22 | #include "include/core/SkTypes.h" |
| 23 | #include "tools/ToolUtils.h" |
bsalomon@google.com | 1a38d55 | 2012-03-15 14:40:46 +0000 | [diff] [blame] | 24 | |
Mike Klein | ea3f014 | 2019-03-20 11:12:10 -0500 | [diff] [blame] | 25 | DEF_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.com | 1a38d55 | 2012-03-15 14:40:46 +0000 | [diff] [blame] | 32 | |
Mike Klein | ea3f014 | 2019-03-20 11:12:10 -0500 | [diff] [blame] | 33 | SkPaint paint; |
| 34 | paint.setColor(SK_ColorRED); |
| 35 | paint.setAntiAlias(true); |
bsalomon@google.com | 1a38d55 | 2012-03-15 14:40:46 +0000 | [diff] [blame] | 36 | |
Mike Klein | ea3f014 | 2019-03-20 11:12:10 -0500 | [diff] [blame] | 37 | bool success = m.invert(&m); |
| 38 | SkASSERT(success); |
| 39 | (void)success; // silence compiler :( |
bsalomon@google.com | 1a38d55 | 2012-03-15 14:40:46 +0000 | [diff] [blame] | 40 | |
Mike Klein | ea3f014 | 2019-03-20 11:12:10 -0500 | [diff] [blame] | 41 | SkPath path; |
bsalomon@google.com | 1a38d55 | 2012-03-15 14:40:46 +0000 | [diff] [blame] | 42 | |
Mike Klein | ea3f014 | 2019-03-20 11:12:10 -0500 | [diff] [blame] | 43 | SkPoint pt = {10 * SK_Scalar1, 10 * SK_Scalar1}; |
| 44 | SkScalar small = 1 / (500 * SK_Scalar1); |
bsalomon@google.com | 1a38d55 | 2012-03-15 14:40:46 +0000 | [diff] [blame] | 45 | |
Mike Klein | ea3f014 | 2019-03-20 11:12:10 -0500 | [diff] [blame] | 46 | m.mapPoints(&pt, 1); |
| 47 | path.addCircle(pt.fX, pt.fY, small); |
| 48 | canvas->drawPath(path, paint); |
bsalomon@google.com | 1a38d55 | 2012-03-15 14:40:46 +0000 | [diff] [blame] | 49 | |
Mike Klein | ea3f014 | 2019-03-20 11:12:10 -0500 | [diff] [blame] | 50 | 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.com | 1a38d55 | 2012-03-15 14:40:46 +0000 | [diff] [blame] | 54 | |
Mike Klein | ea3f014 | 2019-03-20 11:12:10 -0500 | [diff] [blame] | 55 | 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 Reed | 50acf8f | 2019-04-08 13:20:23 -0400 | [diff] [blame] | 67 | paint.setShader(bmp.makeShader(SkTileMode::kRepeat, SkTileMode::kRepeat, &s)); |
Mike Klein | ea3f014 | 2019-03-20 11:12:10 -0500 | [diff] [blame] | 68 | 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.com | 1a38d55 | 2012-03-15 14:40:46 +0000 | [diff] [blame] | 72 | } |