OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright 2011 Google Inc. | 2 * Copyright 2011 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 #include "gm.h" | 7 #include "gm.h" |
8 #include "SkCanvas.h" | 8 #include "SkCanvas.h" |
9 #include "SkGradientShader.h" | 9 #include "SkGradientShader.h" |
10 #include "SkUnitMappers.h" | 10 #include "SkUnitMappers.h" |
(...skipping 29 matching lines...) Expand all Loading... | |
40 canvas.drawPaint(paint); | 40 canvas.drawPaint(paint); |
41 } | 41 } |
42 | 42 |
43 /////////////////////////////////////////////////////////////////////////////// | 43 /////////////////////////////////////////////////////////////////////////////// |
44 | 44 |
45 struct LabeledMatrix { | 45 struct LabeledMatrix { |
46 SkMatrix fMatrix; | 46 SkMatrix fMatrix; |
47 const char* fLabel; | 47 const char* fLabel; |
48 }; | 48 }; |
49 | 49 |
50 static const char kText[] = "B"; | |
51 static const int kTextLen = SK_ARRAY_COUNT(kText) - 1; | |
mtklein
2014/03/26 20:47:17
I love this. AKA, 1.
bsalomon
2014/03/26 20:49:02
:) I'll leave to you to guess where "B" comes from
| |
52 static const int kPointSize = 300; | |
53 | |
50 class ShaderText3GM : public GM { | 54 class ShaderText3GM : public GM { |
51 public: | 55 public: |
52 ShaderText3GM() { | 56 ShaderText3GM() { |
53 this->setBGColor(0xFFDDDDDD); | 57 this->setBGColor(0xFFDDDDDD); |
54 } | 58 } |
55 | 59 |
56 protected: | 60 protected: |
57 | 61 |
58 SkString onShortName() { | 62 virtual SkString onShortName() SK_OVERRIDE { |
59 return SkString("shadertext3"); | 63 return SkString("shadertext3"); |
60 } | 64 } |
61 | 65 |
62 SkISize onISize() { return make_isize(800, 1000); } | 66 virtual SkISize onISize() SK_OVERRIDE{ return make_isize(800, 1000); } |
63 | 67 |
64 virtual void onDraw(SkCanvas* canvas) { | 68 virtual void onOnceBeforeDraw() SK_OVERRIDE { |
65 static const char kText[] = "B"; | 69 makebm(&fBmp, kPointSize / 4, kPointSize / 4); |
66 static const int kTextLen = SK_ARRAY_COUNT(kText) - 1; | 70 } |
67 static const int kPointSize = 300; | |
68 | 71 |
69 static SkBitmap bmp; | 72 virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE { |
70 if (bmp.isNull()) { | |
71 makebm(&bmp, kPointSize / 4, kPointSize / 4); | |
72 } | |
73 | 73 |
74 SkPaint bmpPaint; | 74 SkPaint bmpPaint; |
75 bmpPaint.setAntiAlias(true); | 75 bmpPaint.setAntiAlias(true); |
76 bmpPaint.setFilterLevel(SkPaint::kLow_FilterLevel); | 76 bmpPaint.setFilterLevel(SkPaint::kLow_FilterLevel); |
77 bmpPaint.setAlpha(0x80); | 77 bmpPaint.setAlpha(0x80); |
78 canvas->drawBitmap(bmp, 5.f, 5.f, &bmpPaint); | 78 canvas->drawBitmap(fBmp, 5.f, 5.f, &bmpPaint); |
79 | 79 |
80 SkPaint outlinePaint; | 80 SkPaint outlinePaint; |
81 outlinePaint.setAntiAlias(true); | 81 outlinePaint.setAntiAlias(true); |
82 outlinePaint.setTextSize(SkIntToScalar(kPointSize)); | 82 outlinePaint.setTextSize(SkIntToScalar(kPointSize)); |
83 outlinePaint.setStyle(SkPaint::kStroke_Style); | 83 outlinePaint.setStyle(SkPaint::kStroke_Style); |
84 outlinePaint.setStrokeWidth(0.f); | 84 outlinePaint.setStrokeWidth(0.f); |
85 | 85 |
86 canvas->translate(15.f, 15.f); | 86 canvas->translate(15.f, 15.f); |
87 | 87 |
88 // draw glyphs scaled up | 88 // draw glyphs scaled up |
89 canvas->scale(2.f, 2.f); | 89 canvas->scale(2.f, 2.f); |
90 | 90 |
91 static const SkShader::TileMode kTileModes[] = { | 91 static const SkShader::TileMode kTileModes[] = { |
92 SkShader::kRepeat_TileMode, | 92 SkShader::kRepeat_TileMode, |
93 SkShader::kMirror_TileMode, | 93 SkShader::kMirror_TileMode, |
94 }; | 94 }; |
95 | 95 |
96 // position the baseline of the first run | 96 // position the baseline of the first run |
97 canvas->translate(0.f, 0.75f * kPointSize); | 97 canvas->translate(0.f, 0.75f * kPointSize); |
98 | 98 |
99 canvas->save(); | 99 canvas->save(); |
100 int i = 0; | 100 int i = 0; |
101 for (size_t tm0 = 0; tm0 < SK_ARRAY_COUNT(kTileModes); ++tm0) { | 101 for (size_t tm0 = 0; tm0 < SK_ARRAY_COUNT(kTileModes); ++tm0) { |
102 for (size_t tm1 = 0; tm1 < SK_ARRAY_COUNT(kTileModes); ++tm1) { | 102 for (size_t tm1 = 0; tm1 < SK_ARRAY_COUNT(kTileModes); ++tm1) { |
103 SkAutoTUnref<SkShader> shader(SkShader::CreateBitmapShader(bmp, | 103 SkAutoTUnref<SkShader> shader(SkShader::CreateBitmapShader(fBmp, |
104 kTile Modes[tm0], | 104 kTile Modes[tm0], |
105 kTile Modes[tm1])); | 105 kTile Modes[tm1])); |
106 SkMatrix localM; | 106 SkMatrix localM; |
107 localM.setTranslate(5.f, 5.f); | 107 localM.setTranslate(5.f, 5.f); |
108 localM.postRotate(20); | 108 localM.postRotate(20); |
109 localM.postScale(1.15f, .85f); | 109 localM.postScale(1.15f, .85f); |
110 shader->setLocalMatrix(localM); | 110 shader->setLocalMatrix(localM); |
111 | 111 |
112 SkPaint fillPaint; | 112 SkPaint fillPaint; |
113 fillPaint.setAntiAlias(true); | 113 fillPaint.setAntiAlias(true); |
(...skipping 10 matching lines...) Expand all Loading... | |
124 canvas->restore(); | 124 canvas->restore(); |
125 canvas->translate(0, 0.75f * kPointSize); | 125 canvas->translate(0, 0.75f * kPointSize); |
126 canvas->save(); | 126 canvas->save(); |
127 } | 127 } |
128 } | 128 } |
129 } | 129 } |
130 canvas->restore(); | 130 canvas->restore(); |
131 } | 131 } |
132 | 132 |
133 private: | 133 private: |
134 SkBitmap fBmp; | |
134 typedef GM INHERITED; | 135 typedef GM INHERITED; |
135 }; | 136 }; |
136 | 137 |
137 /////////////////////////////////////////////////////////////////////////////// | 138 /////////////////////////////////////////////////////////////////////////////// |
138 | 139 |
139 static GM* MyFactory(void*) { return new ShaderText3GM; } | 140 static GM* MyFactory(void*) { return new ShaderText3GM; } |
140 static GMRegistry reg(MyFactory); | 141 static GMRegistry reg(MyFactory); |
141 } | 142 } |
OLD | NEW |