OLD | NEW |
---|---|
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2014 Google Inc. | 3 * Copyright 2014 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 | 8 |
9 #include "gm.h" | 9 #include "gm.h" |
10 | 10 |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
76 ConvexPolyClip() { | 76 ConvexPolyClip() { |
77 this->setBGColor(0xFFFFFFFF); | 77 this->setBGColor(0xFFFFFFFF); |
78 } | 78 } |
79 | 79 |
80 protected: | 80 protected: |
81 virtual SkString onShortName() SK_OVERRIDE { | 81 virtual SkString onShortName() SK_OVERRIDE { |
82 return SkString("convex_poly_clip"); | 82 return SkString("convex_poly_clip"); |
83 } | 83 } |
84 | 84 |
85 virtual SkISize onISize() SK_OVERRIDE { | 85 virtual SkISize onISize() SK_OVERRIDE { |
86 return make_isize(435, 540); | 86 // When benchmarking the saveLayer set of draws is skipped. |
87 int w = 435; | |
robertphillips
2014/02/07 15:58:47
w -> this->getMode()?
bsalomon
2014/02/07 20:56:55
ha yes.
| |
88 if (kBench_Mode != w) { | |
89 w *= 2; | |
90 } | |
91 return make_isize(w, 540); | |
87 } | 92 } |
88 | 93 |
89 virtual void onOnceBeforeDraw() SK_OVERRIDE { | 94 virtual void onOnceBeforeDraw() SK_OVERRIDE { |
90 SkPath tri; | 95 SkPath tri; |
91 tri.moveTo(5.f, 5.f); | 96 tri.moveTo(5.f, 5.f); |
92 tri.lineTo(100.f, 20.f); | 97 tri.lineTo(100.f, 20.f); |
93 tri.lineTo(15.f, 100.f); | 98 tri.lineTo(15.f, 100.f); |
94 | 99 |
95 fClips.addToTail()->setPath(tri); | 100 fClips.addToTail()->setPath(tri); |
96 | 101 |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
133 SkScalar y = 0; | 138 SkScalar y = 0; |
134 static const SkScalar kMargin = 10.f; | 139 static const SkScalar kMargin = 10.f; |
135 | 140 |
136 SkPaint bgPaint; | 141 SkPaint bgPaint; |
137 bgPaint.setAlpha(0x15); | 142 bgPaint.setAlpha(0x15); |
138 SkISize size = canvas->getDeviceSize(); | 143 SkISize size = canvas->getDeviceSize(); |
139 SkRect dstRect = SkRect::MakeWH(SkIntToScalar(size.fWidth), | 144 SkRect dstRect = SkRect::MakeWH(SkIntToScalar(size.fWidth), |
140 SkIntToScalar(size.fHeight)); | 145 SkIntToScalar(size.fHeight)); |
141 canvas->drawBitmapRectToRect(fBmp, NULL, dstRect, &bgPaint); | 146 canvas->drawBitmapRectToRect(fBmp, NULL, dstRect, &bgPaint); |
142 | 147 |
143 for (SkTLList<Clip>::Iter iter(fClips, SkTLList<Clip>::Iter::kHead_IterS tart); | 148 static const char kTxt[] = "Clip Me!"; |
144 NULL != iter.get(); | 149 SkPaint txtPaint; |
145 iter.next()) { | 150 txtPaint.setTextSize(23.f); |
146 const Clip* clip = iter.get(); | 151 txtPaint.setAntiAlias(true); |
147 SkScalar x = 0; | 152 txtPaint.setColor(SK_ColorDKGRAY); |
148 for (int aa = 0; aa < 2; ++aa) { | 153 SkScalar textW = txtPaint.measureText(kTxt, SK_ARRAY_COUNT(kTxt)-1); |
149 canvas->save(); | 154 |
150 canvas->translate(x, y); | 155 SkScalar startX = 0; |
151 clip->setOnCanvas(canvas, SkRegion::kIntersect_Op, SkToBool(aa)) ; | 156 int testLayers = kBench_Mode != this->getMode(); |
152 canvas->drawBitmap(fBmp, 0, 0); | 157 for (int doLayer = 0; doLayer <= testLayers; ++doLayer) { |
153 canvas->restore(); | 158 for (SkTLList<Clip>::Iter iter(fClips, SkTLList<Clip>::Iter::kHead_I terStart); |
154 x += fBmp.width() + kMargin; | 159 NULL != iter.get(); |
160 iter.next()) { | |
161 const Clip* clip = iter.get(); | |
162 SkScalar x = startX; | |
163 for (int aa = 0; aa < 2; ++aa) { | |
164 if (doLayer) { | |
165 SkRect bounds; | |
166 clip->getBounds(&bounds); | |
167 bounds.outset(2, 2); | |
168 bounds.offset(x, y); | |
169 canvas->saveLayer(&bounds, NULL); | |
170 } else { | |
171 canvas->save(); | |
172 } | |
173 canvas->translate(x, y); | |
174 clip->setOnCanvas(canvas, SkRegion::kIntersect_Op, SkToBool( aa)); | |
175 canvas->drawBitmap(fBmp, 0, 0); | |
176 canvas->restore(); | |
177 x += fBmp.width() + kMargin; | |
178 } | |
179 for (int aa = 0; aa < 2; ++aa) { | |
180 | |
181 SkPaint clipOutlinePaint; | |
182 clipOutlinePaint.setAntiAlias(true); | |
183 clipOutlinePaint.setColor(0x50505050); | |
184 clipOutlinePaint.setStyle(SkPaint::kStroke_Style); | |
185 clipOutlinePaint.setStrokeWidth(0); | |
186 | |
187 if (doLayer) { | |
188 SkRect bounds; | |
189 clip->getBounds(&bounds); | |
190 bounds.outset(2, 2); | |
191 bounds.offset(x, y); | |
192 canvas->saveLayer(&bounds, NULL); | |
193 } else { | |
194 canvas->save(); | |
195 } | |
196 canvas->translate(x, y); | |
197 SkPath closedClipPath; | |
198 clip->asClosedPath(&closedClipPath); | |
199 canvas->drawPath(closedClipPath, clipOutlinePaint); | |
200 clip->setOnCanvas(canvas, SkRegion::kIntersect_Op, SkToBool( aa)); | |
201 canvas->scale(1.f, 1.8f); | |
202 canvas->drawText(kTxt, SK_ARRAY_COUNT(kTxt)-1, | |
203 0, 1.5f * txtPaint.getTextSize(), | |
204 txtPaint); | |
205 canvas->restore(); | |
206 x += textW + 2 * kMargin; | |
207 } | |
208 y += fBmp.height() + kMargin; | |
155 } | 209 } |
156 for (int aa = 0; aa < 2; ++aa) { | 210 y = 0; |
157 static const char kTxt[] = "Clip Me!"; | 211 startX += 2 * fBmp.width() + SkScalarCeilToInt(2 * textW) + 6 * kMar gin; |
158 SkPaint txtPaint; | |
159 txtPaint.setTextSize(23.f); | |
160 txtPaint.setAntiAlias(true); | |
161 txtPaint.setColor(SK_ColorDKGRAY); | |
162 | |
163 SkPaint clipOutlinePaint; | |
164 clipOutlinePaint.setAntiAlias(true); | |
165 clipOutlinePaint.setColor(0x50505050); | |
166 clipOutlinePaint.setStyle(SkPaint::kStroke_Style); | |
167 clipOutlinePaint.setStrokeWidth(0); | |
168 | |
169 canvas->save(); | |
170 canvas->translate(x, y); | |
171 SkPath closedClipPath; | |
172 clip->asClosedPath(&closedClipPath); | |
173 canvas->drawPath(closedClipPath, clipOutlinePaint); | |
174 clip->setOnCanvas(canvas, SkRegion::kIntersect_Op, SkToBool(aa)) ; | |
175 canvas->scale(1.f, 1.8f); | |
176 canvas->drawText(kTxt, SK_ARRAY_COUNT(kTxt)-1, | |
177 0, 1.5f * txtPaint.getTextSize(), | |
178 txtPaint); | |
179 canvas->restore(); | |
180 x += fBmp.width() + kMargin; | |
181 } | |
182 | |
183 y += fBmp.height() + kMargin; | |
184 } | 212 } |
185 } | 213 } |
186 | 214 |
187 virtual uint32_t onGetFlags() const { | 215 virtual uint32_t onGetFlags() const { |
188 return kAsBench_Flag; | 216 return kAsBench_Flag; |
189 } | 217 } |
190 | 218 |
191 private: | 219 private: |
192 class Clip { | 220 class Clip { |
193 public: | 221 public: |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
235 } | 263 } |
236 | 264 |
237 void setRect(const SkRect& rect) { | 265 void setRect(const SkRect& rect) { |
238 fClipType = kRect_ClipType; | 266 fClipType = kRect_ClipType; |
239 fRect = rect; | 267 fRect = rect; |
240 fPath.reset(); | 268 fPath.reset(); |
241 } | 269 } |
242 | 270 |
243 ClipType getType() const { return fClipType; } | 271 ClipType getType() const { return fClipType; } |
244 | 272 |
273 void getBounds(SkRect* bounds) const { | |
274 switch (fClipType) { | |
275 case kPath_ClipType: | |
276 *bounds = fPath.getBounds(); | |
277 break; | |
278 case kRect_ClipType: | |
279 *bounds = fRect; | |
280 break; | |
281 case kNone_ClipType: | |
282 SkDEBUGFAIL("Uninitialized Clip."); | |
283 break; | |
284 } | |
285 } | |
286 | |
245 private: | 287 private: |
246 ClipType fClipType; | 288 ClipType fClipType; |
247 SkPath fPath; | 289 SkPath fPath; |
248 SkRect fRect; | 290 SkRect fRect; |
249 }; | 291 }; |
250 | 292 |
251 SkTLList<Clip> fClips; | 293 SkTLList<Clip> fClips; |
252 SkBitmap fBmp; | 294 SkBitmap fBmp; |
253 | 295 |
254 typedef GM INHERITED; | 296 typedef GM INHERITED; |
255 }; | 297 }; |
256 | 298 |
257 DEF_GM( return SkNEW(ConvexPolyClip); ) | 299 DEF_GM( return SkNEW(ConvexPolyClip); ) |
258 | 300 |
259 } | 301 } |
OLD | NEW |