bsalomon@google.com | 1a38d55 | 2012-03-15 14:40:46 +0000 | [diff] [blame] | 1 | |
| 2 | /* |
| 3 | * Copyright 2012 Google Inc. |
| 4 | * |
| 5 | * Use of this source code is governed by a BSD-style license that can be |
| 6 | * found in the LICENSE file. |
| 7 | */ |
| 8 | #include "gm.h" |
| 9 | |
| 10 | #include "SkColorPriv.h" |
| 11 | #include "SkShader.h" |
| 12 | |
| 13 | namespace skiagm { |
| 14 | |
| 15 | class BigMatrixGM : public GM { |
| 16 | public: |
| 17 | BigMatrixGM() { |
caryclark | 65cdba6 | 2015-06-15 06:51:08 -0700 | [diff] [blame] | 18 | this->setBGColor(sk_tool_utils::color_to_565(0xFF66AA99)); |
bsalomon@google.com | 1a38d55 | 2012-03-15 14:40:46 +0000 | [diff] [blame] | 19 | } |
| 20 | |
| 21 | protected: |
| 22 | virtual SkString onShortName() { |
| 23 | return SkString("bigmatrix"); |
| 24 | } |
| 25 | |
| 26 | virtual SkISize onISize() { |
tfarina | f539318 | 2014-06-09 23:59:03 -0700 | [diff] [blame] | 27 | return SkISize::Make(50, 50); |
bsalomon@google.com | 1a38d55 | 2012-03-15 14:40:46 +0000 | [diff] [blame] | 28 | } |
| 29 | |
| 30 | virtual void onDraw(SkCanvas* canvas) { |
| 31 | SkMatrix m; |
| 32 | m.reset(); |
| 33 | m.setRotate(33 * SK_Scalar1); |
| 34 | m.postScale(3000 * SK_Scalar1, 3000 * SK_Scalar1); |
| 35 | m.postTranslate(6000 * SK_Scalar1, -5000 * SK_Scalar1); |
| 36 | canvas->concat(m); |
| 37 | |
| 38 | SkPaint paint; |
| 39 | paint.setColor(SK_ColorRED); |
| 40 | paint.setAntiAlias(true); |
| 41 | |
reed@google.com | 57b1935 | 2012-04-19 19:25:49 +0000 | [diff] [blame] | 42 | bool success = m.invert(&m); |
caryclark@google.com | 1313086 | 2012-06-06 12:10:45 +0000 | [diff] [blame] | 43 | SkASSERT(success); |
humper@google.com | 0e51577 | 2013-01-07 19:54:40 +0000 | [diff] [blame] | 44 | (void) success; // silence compiler :( |
bsalomon@google.com | 1a38d55 | 2012-03-15 14:40:46 +0000 | [diff] [blame] | 45 | |
| 46 | SkPath path; |
| 47 | |
| 48 | SkPoint pt = {10 * SK_Scalar1, 10 * SK_Scalar1}; |
| 49 | SkScalar small = 1 / (500 * SK_Scalar1); |
| 50 | |
| 51 | m.mapPoints(&pt, 1); |
| 52 | path.addCircle(pt.fX, pt.fY, small); |
| 53 | canvas->drawPath(path, paint); |
| 54 | |
| 55 | pt.set(30 * SK_Scalar1, 10 * SK_Scalar1); |
| 56 | m.mapPoints(&pt, 1); |
| 57 | SkRect rect = {pt.fX - small, pt.fY - small, |
| 58 | pt.fX + small, pt.fY + small}; |
| 59 | canvas->drawRect(rect, paint); |
| 60 | |
| 61 | SkBitmap bmp; |
reed@google.com | eb9a46c | 2014-01-25 16:46:20 +0000 | [diff] [blame] | 62 | bmp.allocN32Pixels(2, 2); |
bsalomon@google.com | 1a38d55 | 2012-03-15 14:40:46 +0000 | [diff] [blame] | 63 | uint32_t* pixels = reinterpret_cast<uint32_t*>(bmp.getPixels()); |
| 64 | pixels[0] = SkPackARGB32(0xFF, 0xFF, 0x00, 0x00); |
| 65 | pixels[1] = SkPackARGB32(0xFF, 0x00, 0xFF, 0x00); |
| 66 | pixels[2] = SkPackARGB32(0x80, 0x00, 0x00, 0x00); |
| 67 | pixels[3] = SkPackARGB32(0xFF, 0x00, 0x00, 0xFF); |
bsalomon@google.com | 1a38d55 | 2012-03-15 14:40:46 +0000 | [diff] [blame] | 68 | pt.set(30 * SK_Scalar1, 30 * SK_Scalar1); |
| 69 | m.mapPoints(&pt, 1); |
bsalomon@google.com | 1a38d55 | 2012-03-15 14:40:46 +0000 | [diff] [blame] | 70 | SkMatrix s; |
| 71 | s.reset(); |
| 72 | s.setScale(SK_Scalar1 / 1000, SK_Scalar1 / 1000); |
commit-bot@chromium.org | 9c9005a | 2014-04-28 14:55:39 +0000 | [diff] [blame] | 73 | SkShader* shader = SkShader::CreateBitmapShader( |
| 74 | bmp, |
| 75 | SkShader::kRepeat_TileMode, |
| 76 | SkShader::kRepeat_TileMode, |
| 77 | &s); |
bsalomon@google.com | 1a38d55 | 2012-03-15 14:40:46 +0000 | [diff] [blame] | 78 | paint.setShader(shader)->unref(); |
| 79 | paint.setAntiAlias(false); |
reed | 93a1215 | 2015-03-16 10:08:34 -0700 | [diff] [blame] | 80 | paint.setFilterQuality(kLow_SkFilterQuality); |
bsalomon@google.com | 1a38d55 | 2012-03-15 14:40:46 +0000 | [diff] [blame] | 81 | rect.setLTRB(pt.fX - small, pt.fY - small, |
| 82 | pt.fX + small, pt.fY + small); |
| 83 | canvas->drawRect(rect, paint); |
| 84 | } |
| 85 | |
| 86 | private: |
| 87 | typedef GM INHERITED; |
| 88 | }; |
| 89 | |
| 90 | ////////////////////////////////////////////////////////////////////////////// |
| 91 | |
| 92 | static GM* MyFactory(void*) { return new BigMatrixGM; } |
| 93 | static GMRegistry reg(MyFactory); |
| 94 | |
| 95 | } |