• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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:
BigMatrixGM()17     BigMatrixGM() {
18         this->setBGColor(0xFF66AA99);
19     }
20 
21 protected:
onShortName()22     virtual SkString onShortName() {
23         return SkString("bigmatrix");
24     }
25 
onISize()26     virtual SkISize onISize() {
27         return make_isize(50, 50);
28     }
29 
onDraw(SkCanvas * canvas)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 
42         bool success = m.invert(&m);
43         SkASSERT(success);
44         (void) success; // silence compiler :(
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;
62         bmp.setConfig(SkBitmap::kARGB_8888_Config, 2, 2);
63         bmp.allocPixels();
64         bmp.lockPixels();
65         uint32_t* pixels = reinterpret_cast<uint32_t*>(bmp.getPixels());
66         pixels[0] = SkPackARGB32(0xFF, 0xFF, 0x00, 0x00);
67         pixels[1] = SkPackARGB32(0xFF, 0x00, 0xFF, 0x00);
68         pixels[2] = SkPackARGB32(0x80, 0x00, 0x00, 0x00);
69         pixels[3] = SkPackARGB32(0xFF, 0x00, 0x00, 0xFF);
70         bmp.unlockPixels();
71         pt.set(30 * SK_Scalar1, 30 * SK_Scalar1);
72         m.mapPoints(&pt, 1);
73         SkShader* shader = SkShader::CreateBitmapShader(
74                                             bmp,
75                                             SkShader::kRepeat_TileMode,
76                                             SkShader::kRepeat_TileMode);
77         SkMatrix s;
78         s.reset();
79         s.setScale(SK_Scalar1 / 1000, SK_Scalar1 / 1000);
80         shader->setLocalMatrix(s);
81         paint.setShader(shader)->unref();
82         paint.setAntiAlias(false);
83         paint.setFilterLevel(SkPaint::kLow_FilterLevel);
84         rect.setLTRB(pt.fX - small, pt.fY - small,
85                      pt.fX + small, pt.fY + small);
86         canvas->drawRect(rect, paint);
87     }
88 
89 private:
90     typedef GM INHERITED;
91 };
92 
93 //////////////////////////////////////////////////////////////////////////////
94 
MyFactory(void *)95 static GM* MyFactory(void*) { return new BigMatrixGM; }
96 static GMRegistry reg(MyFactory);
97 
98 }
99