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 */ 7 8 #include "gm/gm.h" 9 #include "include/core/SkBitmap.h" 10 #include "include/core/SkCanvas.h" 11 #include "include/core/SkColor.h" 12 #include "include/core/SkColorPriv.h" 13 #include "include/core/SkMatrix.h" 14 #include "include/core/SkPaint.h" 15 #include "include/core/SkPath.h" 16 #include "include/core/SkPoint.h" 17 #include "include/core/SkRect.h" 18 #include "include/core/SkScalar.h" 19 #include "include/core/SkShader.h" 20 #include "include/core/SkTileMode.h" 21 #include "include/core/SkTypes.h" 22 #include "tools/ToolUtils.h" 23 24 DEF_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); 31 32 SkPaint paint; 33 paint.setColor(SK_ColorRED); 34 paint.setAntiAlias(true); 35 36 bool success = m.invert(&m); 37 SkASSERT(success); 38 (void)success; // silence compiler :( 39 40 SkPoint pt = {10 * SK_Scalar1, 10 * SK_Scalar1}; 41 SkScalar small = 1 / (500 * SK_Scalar1); 42 43 m.mapPoints(&pt, 1); 44 canvas->drawCircle(pt.fX, pt.fY, small, paint); 45 46 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); 50 51 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); 63 paint.setShader(bmp.makeShader(SkTileMode::kRepeat, SkTileMode::kRepeat, 64 SkSamplingOptions(SkFilterMode::kLinear), s)); 65 paint.setAntiAlias(false); 66 rect.setLTRB(pt.fX - small, pt.fY - small, pt.fX + small, pt.fY + small); 67 canvas->drawRect(rect, paint); 68 } 69