OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2015 Google Inc. | 2 * Copyright 2015 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 | 7 |
8 #include "GrNonAAStrokeRectBatch.h" | 8 #include "GrNonAAStrokeRectBatch.h" |
9 | 9 |
10 #include "GrBatchTest.h" | 10 #include "GrBatchTest.h" |
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
204 | 204 |
205 const static int kVertsPerHairlineRect = 5; | 205 const static int kVertsPerHairlineRect = 5; |
206 const static int kVertsPerStrokeRect = 10; | 206 const static int kVertsPerStrokeRect = 10; |
207 | 207 |
208 BatchTracker fBatch; | 208 BatchTracker fBatch; |
209 SkSTArray<1, Geometry, true> fGeoData; | 209 SkSTArray<1, Geometry, true> fGeoData; |
210 | 210 |
211 typedef GrVertexBatch INHERITED; | 211 typedef GrVertexBatch INHERITED; |
212 }; | 212 }; |
213 | 213 |
| 214 // Allow all hairlines and all miters, so long as the miter limit doesn't produc
e beveled corners. |
| 215 inline static bool allowed_stroke(const SkStrokeRec& stroke) { |
| 216 SkASSERT(stroke.getStyle() == SkStrokeRec::kStroke_Style || |
| 217 stroke.getStyle() == SkStrokeRec::kHairline_Style); |
| 218 return !stroke.getWidth() || |
| 219 (stroke.getJoin() == SkPaint::kMiter_Join && stroke.getMiter() > SK_
ScalarSqrt2); |
| 220 } |
| 221 |
214 namespace GrNonAAStrokeRectBatch { | 222 namespace GrNonAAStrokeRectBatch { |
215 | 223 |
216 GrDrawBatch* Create(GrColor color, | 224 GrDrawBatch* Create(GrColor color, |
217 const SkMatrix& viewMatrix, | 225 const SkMatrix& viewMatrix, |
218 const SkRect& rect, | 226 const SkRect& rect, |
219 SkScalar strokeWidth, | 227 const SkStrokeRec& stroke, |
220 bool snapToPixelCenters) { | 228 bool snapToPixelCenters) { |
| 229 if (!allowed_stroke(stroke)) { |
| 230 return nullptr; |
| 231 } |
221 NonAAStrokeRectBatch* batch = NonAAStrokeRectBatch::Create(); | 232 NonAAStrokeRectBatch* batch = NonAAStrokeRectBatch::Create(); |
222 batch->append(color, viewMatrix, rect, strokeWidth); | 233 batch->append(color, viewMatrix, rect, stroke.getWidth()); |
223 batch->init(snapToPixelCenters); | 234 batch->init(snapToPixelCenters); |
224 return batch; | 235 return batch; |
225 } | 236 } |
226 | 237 |
227 void Append(GrBatch* origBatch, | |
228 GrColor color, | |
229 const SkMatrix& viewMatrix, | |
230 const SkRect& rect, | |
231 SkScalar strokeWidth, | |
232 bool snapToPixelCenters) { | |
233 NonAAStrokeRectBatch* batch = origBatch->cast<NonAAStrokeRectBatch>(); | |
234 batch->appendAndUpdateBounds(color, viewMatrix, rect, strokeWidth, snapToPix
elCenters); | |
235 } | |
236 | |
237 }; | 238 }; |
238 | 239 |
239 #ifdef GR_TEST_UTILS | 240 #ifdef GR_TEST_UTILS |
240 | 241 |
241 DRAW_BATCH_TEST_DEFINE(NonAAStrokeRectBatch) { | 242 DRAW_BATCH_TEST_DEFINE(NonAAStrokeRectBatch) { |
242 SkMatrix viewMatrix = GrTest::TestMatrix(random); | 243 SkMatrix viewMatrix = GrTest::TestMatrix(random); |
243 GrColor color = GrRandomColor(random); | 244 GrColor color = GrRandomColor(random); |
244 SkRect rect = GrTest::TestRect(random); | 245 SkRect rect = GrTest::TestRect(random); |
245 SkScalar strokeWidth = random->nextBool() ? 0.0f : 1.0f; | 246 SkScalar strokeWidth = random->nextBool() ? 0.0f : 2.0f; |
246 | 247 SkPaint paint; |
247 return GrNonAAStrokeRectBatch::Create(color, viewMatrix, rect, strokeWidth,
random->nextBool()); | 248 paint.setStrokeWidth(strokeWidth); |
| 249 paint.setStyle(SkPaint::kStroke_Style); |
| 250 paint.setStrokeJoin(SkPaint::kMiter_Join); |
| 251 SkStrokeRec strokeRec(paint); |
| 252 return GrNonAAStrokeRectBatch::Create(color, viewMatrix, rect, strokeRec, ra
ndom->nextBool()); |
248 } | 253 } |
249 | 254 |
250 #endif | 255 #endif |
OLD | NEW |