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 | |
bsalomon@google.com | 1a38d55 | 2012-03-15 14:40:46 +0000 | [diff] [blame] | 8 | #include "gm.h" |
Mike Klein | 33d2055 | 2017-03-22 13:47:51 -0400 | [diff] [blame] | 9 | #include "sk_tool_utils.h" |
bsalomon@google.com | 1a38d55 | 2012-03-15 14:40:46 +0000 | [diff] [blame] | 10 | |
| 11 | #include "SkColorPriv.h" |
bungeman | d3ebb48 | 2015-08-05 13:57:49 -0700 | [diff] [blame] | 12 | #include "SkPath.h" |
bsalomon@google.com | 1a38d55 | 2012-03-15 14:40:46 +0000 | [diff] [blame] | 13 | #include "SkShader.h" |
| 14 | |
halcanary | 2a24338 | 2015-09-09 08:16:41 -0700 | [diff] [blame] | 15 | DEF_SIMPLE_GM_BG(bigmatrix, canvas, 50, 50, |
| 16 | sk_tool_utils::color_to_565(0xFF66AA99)) { |
bsalomon@google.com | 1a38d55 | 2012-03-15 14:40:46 +0000 | [diff] [blame] | 17 | SkMatrix m; |
| 18 | m.reset(); |
| 19 | m.setRotate(33 * SK_Scalar1); |
| 20 | m.postScale(3000 * SK_Scalar1, 3000 * SK_Scalar1); |
| 21 | m.postTranslate(6000 * SK_Scalar1, -5000 * SK_Scalar1); |
| 22 | canvas->concat(m); |
| 23 | |
| 24 | SkPaint paint; |
| 25 | paint.setColor(SK_ColorRED); |
| 26 | paint.setAntiAlias(true); |
| 27 | |
reed@google.com | 57b1935 | 2012-04-19 19:25:49 +0000 | [diff] [blame] | 28 | bool success = m.invert(&m); |
caryclark@google.com | 1313086 | 2012-06-06 12:10:45 +0000 | [diff] [blame] | 29 | SkASSERT(success); |
humper@google.com | 0e51577 | 2013-01-07 19:54:40 +0000 | [diff] [blame] | 30 | (void) success; // silence compiler :( |
bsalomon@google.com | 1a38d55 | 2012-03-15 14:40:46 +0000 | [diff] [blame] | 31 | |
| 32 | SkPath path; |
| 33 | |
| 34 | SkPoint pt = {10 * SK_Scalar1, 10 * SK_Scalar1}; |
| 35 | SkScalar small = 1 / (500 * SK_Scalar1); |
| 36 | |
| 37 | m.mapPoints(&pt, 1); |
| 38 | path.addCircle(pt.fX, pt.fY, small); |
| 39 | canvas->drawPath(path, paint); |
| 40 | |
| 41 | pt.set(30 * SK_Scalar1, 10 * SK_Scalar1); |
| 42 | m.mapPoints(&pt, 1); |
| 43 | SkRect rect = {pt.fX - small, pt.fY - small, |
| 44 | pt.fX + small, pt.fY + small}; |
| 45 | canvas->drawRect(rect, paint); |
| 46 | |
| 47 | SkBitmap bmp; |
reed@google.com | eb9a46c | 2014-01-25 16:46:20 +0000 | [diff] [blame] | 48 | bmp.allocN32Pixels(2, 2); |
bsalomon@google.com | 1a38d55 | 2012-03-15 14:40:46 +0000 | [diff] [blame] | 49 | uint32_t* pixels = reinterpret_cast<uint32_t*>(bmp.getPixels()); |
| 50 | pixels[0] = SkPackARGB32(0xFF, 0xFF, 0x00, 0x00); |
| 51 | pixels[1] = SkPackARGB32(0xFF, 0x00, 0xFF, 0x00); |
| 52 | pixels[2] = SkPackARGB32(0x80, 0x00, 0x00, 0x00); |
| 53 | pixels[3] = SkPackARGB32(0xFF, 0x00, 0x00, 0xFF); |
bsalomon@google.com | 1a38d55 | 2012-03-15 14:40:46 +0000 | [diff] [blame] | 54 | pt.set(30 * SK_Scalar1, 30 * SK_Scalar1); |
| 55 | m.mapPoints(&pt, 1); |
bsalomon@google.com | 1a38d55 | 2012-03-15 14:40:46 +0000 | [diff] [blame] | 56 | SkMatrix s; |
| 57 | s.reset(); |
| 58 | s.setScale(SK_Scalar1 / 1000, SK_Scalar1 / 1000); |
reed | 2ad1aa6 | 2016-03-09 09:50:50 -0800 | [diff] [blame] | 59 | paint.setShader(SkShader::MakeBitmapShader(bmp, SkShader::kRepeat_TileMode, |
| 60 | SkShader::kRepeat_TileMode, &s)); |
bsalomon@google.com | 1a38d55 | 2012-03-15 14:40:46 +0000 | [diff] [blame] | 61 | paint.setAntiAlias(false); |
reed | 93a1215 | 2015-03-16 10:08:34 -0700 | [diff] [blame] | 62 | paint.setFilterQuality(kLow_SkFilterQuality); |
bsalomon@google.com | 1a38d55 | 2012-03-15 14:40:46 +0000 | [diff] [blame] | 63 | rect.setLTRB(pt.fX - small, pt.fY - small, |
| 64 | pt.fX + small, pt.fY + small); |
| 65 | canvas->drawRect(rect, paint); |
bsalomon@google.com | 1a38d55 | 2012-03-15 14:40:46 +0000 | [diff] [blame] | 66 | } |