OLD | NEW |
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2011 Google Inc. | 3 * Copyright 2011 Google Inc. |
4 * | 4 * |
5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
7 */ | 7 */ |
8 #include "SampleCode.h" | 8 #include "SampleCode.h" |
9 #include "SkView.h" | 9 #include "SkView.h" |
10 #include "SkCanvas.h" | 10 #include "SkCanvas.h" |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
55 } | 55 } |
56 | 56 |
57 static const SkColorType gColorTypes[] = { | 57 static const SkColorType gColorTypes[] = { |
58 kPMColor_SkColorType, | 58 kPMColor_SkColorType, |
59 kRGB_565_SkColorType, | 59 kRGB_565_SkColorType, |
60 }; | 60 }; |
61 static const int gWidth = 32; | 61 static const int gWidth = 32; |
62 static const int gHeight = 32; | 62 static const int gHeight = 32; |
63 | 63 |
64 class TilingView : public SampleView { | 64 class TilingView : public SampleView { |
65 SkPicture* fTextPicture; | 65 SkAutoTUnref<SkPicture> fTextPicture; |
66 SkBlurDrawLooper fLooper; | 66 SkAutoTUnref<SkBlurDrawLooper> fLooper; |
67 public: | 67 public: |
68 TilingView() | 68 TilingView() |
69 : fLooper(0x88000000, | 69 : fTextPicture(new SkPicture) |
70 SkBlurMask::ConvertRadiusToSigma(SkIntToScalar(1)), | 70 , fLooper(SkBlurDrawLooper::Create(0x88000000, |
71 SkIntToScalar(2), SkIntToScalar(2)) { | 71 SkBlurMask::ConvertRadiusToSigma(
SkIntToScalar(1)), |
72 fTextPicture = new SkPicture(); | 72 SkIntToScalar(2), SkIntToScalar(2
))) { |
73 for (size_t i = 0; i < SK_ARRAY_COUNT(gColorTypes); i++) { | 73 for (size_t i = 0; i < SK_ARRAY_COUNT(gColorTypes); i++) { |
74 makebm(&fTexture[i], gColorTypes[i], gWidth, gHeight); | 74 makebm(&fTexture[i], gColorTypes[i], gWidth, gHeight); |
75 } | 75 } |
76 } | 76 } |
77 | 77 |
78 ~TilingView() { | |
79 fTextPicture->unref(); | |
80 } | |
81 | |
82 SkBitmap fTexture[SK_ARRAY_COUNT(gColorTypes)]; | 78 SkBitmap fTexture[SK_ARRAY_COUNT(gColorTypes)]; |
83 | 79 |
84 protected: | 80 protected: |
85 // overrides from SkEventSink | 81 // overrides from SkEventSink |
86 virtual bool onQuery(SkEvent* evt) { | 82 virtual bool onQuery(SkEvent* evt) { |
87 if (SampleCode::TitleQ(*evt)) { | 83 if (SampleCode::TitleQ(*evt)) { |
88 SampleCode::TitleR(evt, "Tiling"); | 84 SampleCode::TitleR(evt, "Tiling"); |
89 return true; | 85 return true; |
90 } | 86 } |
91 return this->INHERITED::onQuery(evt); | 87 return this->INHERITED::onQuery(evt); |
(...skipping 18 matching lines...) Expand all Loading... |
110 textCanvas = fTextPicture->beginRecording(1000, 1000); | 106 textCanvas = fTextPicture->beginRecording(1000, 1000); |
111 } | 107 } |
112 | 108 |
113 if (textCanvas) { | 109 if (textCanvas) { |
114 for (size_t kx = 0; kx < SK_ARRAY_COUNT(gModes); kx++) { | 110 for (size_t kx = 0; kx < SK_ARRAY_COUNT(gModes); kx++) { |
115 for (size_t ky = 0; ky < SK_ARRAY_COUNT(gModes); ky++) { | 111 for (size_t ky = 0; ky < SK_ARRAY_COUNT(gModes); ky++) { |
116 SkPaint p; | 112 SkPaint p; |
117 SkString str; | 113 SkString str; |
118 p.setAntiAlias(true); | 114 p.setAntiAlias(true); |
119 p.setDither(true); | 115 p.setDither(true); |
120 p.setLooper(&fLooper); | 116 p.setLooper(fLooper); |
121 str.printf("[%s,%s]", gModeNames[kx], gModeNames[ky]); | 117 str.printf("[%s,%s]", gModeNames[kx], gModeNames[ky]); |
122 | 118 |
123 p.setTextAlign(SkPaint::kCenter_Align); | 119 p.setTextAlign(SkPaint::kCenter_Align); |
124 textCanvas->drawText(str.c_str(), str.size(), x + r.width()/
2, y, p); | 120 textCanvas->drawText(str.c_str(), str.size(), x + r.width()/
2, y, p); |
125 | 121 |
126 x += r.width() * 4 / 3; | 122 x += r.width() * 4 / 3; |
127 } | 123 } |
128 } | 124 } |
129 } | 125 } |
130 | 126 |
(...skipping 13 matching lines...) Expand all Loading... |
144 canvas->drawRect(r, paint); | 140 canvas->drawRect(r, paint); |
145 canvas->restore(); | 141 canvas->restore(); |
146 | 142 |
147 x += r.width() * 4 / 3; | 143 x += r.width() * 4 / 3; |
148 } | 144 } |
149 } | 145 } |
150 if (textCanvas) { | 146 if (textCanvas) { |
151 SkPaint p; | 147 SkPaint p; |
152 SkString str; | 148 SkString str; |
153 p.setAntiAlias(true); | 149 p.setAntiAlias(true); |
154 p.setLooper(&fLooper); | 150 p.setLooper(fLooper); |
155 str.printf("%s, %s", gConfigNames[i], gFilterNames[j]); | 151 str.printf("%s, %s", gConfigNames[i], gFilterNames[j]); |
156 textCanvas->drawText(str.c_str(), str.size(), x, y + r.heigh
t() * 2 / 3, p); | 152 textCanvas->drawText(str.c_str(), str.size(), x, y + r.heigh
t() * 2 / 3, p); |
157 } | 153 } |
158 | 154 |
159 y += r.height() * 4 / 3; | 155 y += r.height() * 4 / 3; |
160 } | 156 } |
161 } | 157 } |
162 | 158 |
163 canvas->drawPicture(*fTextPicture); | 159 canvas->drawPicture(*fTextPicture); |
164 } | 160 } |
165 | 161 |
166 private: | 162 private: |
167 typedef SampleView INHERITED; | 163 typedef SampleView INHERITED; |
168 }; | 164 }; |
169 | 165 |
170 ////////////////////////////////////////////////////////////////////////////// | 166 ////////////////////////////////////////////////////////////////////////////// |
171 | 167 |
172 static SkView* MyFactory() { return new TilingView; } | 168 static SkView* MyFactory() { return new TilingView; } |
173 static SkViewRegister reg(MyFactory); | 169 static SkViewRegister reg(MyFactory); |
OLD | NEW |