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 "GrBatchTest.h" | 8 #include "GrBatchTest.h" |
9 #include "GrColor.h" | 9 #include "GrColor.h" |
10 #include "GrDrawContext.h" | 10 #include "GrDrawContext.h" |
(...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
314 ASSERT_SINGLE_OWNER | 314 ASSERT_SINGLE_OWNER |
315 RETURN_IF_ABANDONED | 315 RETURN_IF_ABANDONED |
316 SkDEBUGCODE(this->validate();) | 316 SkDEBUGCODE(this->validate();) |
317 GR_AUDIT_TRAIL_AUTO_FRAME(fAuditTrail, "GrDrawContext::drawRect"); | 317 GR_AUDIT_TRAIL_AUTO_FRAME(fAuditTrail, "GrDrawContext::drawRect"); |
318 | 318 |
319 // Path effects should've been devolved to a path in SkGpuDevice | 319 // Path effects should've been devolved to a path in SkGpuDevice |
320 SkASSERT(!style->pathEffect()); | 320 SkASSERT(!style->pathEffect()); |
321 | 321 |
322 AutoCheckFlush acf(fDrawingManager); | 322 AutoCheckFlush acf(fDrawingManager); |
323 | 323 |
324 const SkStrokeRec& stroke = style->strokeRec(); | 324 const SkStrokeRec& stroke = style->strokeRec(); |
robertphillips
2016/07/06 15:01:47
Do we still need this code? If so, I think it need
bsalomon
2016/07/06 15:57:53
Oh no, left it by accident. Removed.
| |
325 SkScalar width = stroke.getWidth(); | 325 #if 0 |
326 // We have no special cases for stroke-and-fill. | |
327 if (stroke.getStyle() == SkStrokeRec::kStrokeAndFill_Style) { | |
328 SkPath path; | |
329 path.addRect(rect); | |
330 this->internalDrawPath(clip, paint, viewMatrix, path, *style); | |
331 } | |
332 #endif | |
326 | 333 |
327 // Check if this is a full RT draw and can be replaced with a clear. We don' t bother checking | 334 bool useHWAA; |
328 // cases where the RT is fully inside a stroke. | 335 bool snapToPixelCenters = false; |
329 if (width < 0) { | 336 SkAutoTUnref<GrDrawBatch> batch; |
337 if (stroke.getStyle() == SkStrokeRec::kFill_Style) { | |
338 // Check if this is a full RT draw and can be replaced with a clear. We don't bother | |
339 // checking cases where the RT is fully inside a stroke. | |
330 SkRect rtRect; | 340 SkRect rtRect; |
331 fRenderTarget->getBoundsRect(&rtRect); | 341 fRenderTarget->getBoundsRect(&rtRect); |
332 // Does the clip contain the entire RT? | 342 // Does the clip contain the entire RT? |
333 if (clip.quickContains(rtRect)) { | 343 if (clip.quickContains(rtRect)) { |
334 SkMatrix invM; | 344 SkMatrix invM; |
335 if (!viewMatrix.invert(&invM)) { | 345 if (!viewMatrix.invert(&invM)) { |
336 return; | 346 return; |
337 } | 347 } |
338 // Does the rect bound the RT? | 348 // Does the rect bound the RT? |
339 SkPoint srcSpaceRTQuad[4]; | 349 SkPoint srcSpaceRTQuad[4]; |
340 invM.mapRectToQuad(srcSpaceRTQuad, rtRect); | 350 invM.mapRectToQuad(srcSpaceRTQuad, rtRect); |
341 if (rect_contains_inclusive(rect, srcSpaceRTQuad[0]) && | 351 if (rect_contains_inclusive(rect, srcSpaceRTQuad[0]) && |
342 rect_contains_inclusive(rect, srcSpaceRTQuad[1]) && | 352 rect_contains_inclusive(rect, srcSpaceRTQuad[1]) && |
343 rect_contains_inclusive(rect, srcSpaceRTQuad[2]) && | 353 rect_contains_inclusive(rect, srcSpaceRTQuad[2]) && |
344 rect_contains_inclusive(rect, srcSpaceRTQuad[3])) { | 354 rect_contains_inclusive(rect, srcSpaceRTQuad[3])) { |
345 // Will it blend? | 355 // Will it blend? |
346 GrColor clearColor; | 356 GrColor clearColor; |
347 if (paint.isConstantBlendedColor(&clearColor)) { | 357 if (paint.isConstantBlendedColor(&clearColor)) { |
348 this->getDrawTarget()->clear(nullptr, clearColor, true, this ); | 358 this->getDrawTarget()->clear(nullptr, clearColor, true, this ); |
349 return; | 359 return; |
350 } | 360 } |
351 } | 361 } |
352 } | 362 } |
353 } | |
354 | |
355 bool useHWAA; | |
356 bool snapToPixelCenters = false; | |
357 SkAutoTUnref<GrDrawBatch> batch; | |
358 if (width < 0) { | |
359 batch.reset(this->getFillRectBatch(paint, viewMatrix, rect, &useHWAA)); | 363 batch.reset(this->getFillRectBatch(paint, viewMatrix, rect, &useHWAA)); |
360 } else { | 364 } else if (stroke.getStyle() == SkStrokeRec::kStroke_Style || |
365 stroke.getStyle() == SkStrokeRec::kHairline_Style) { | |
robertphillips
2016/07/06 15:01:47
// Handle special case where the stroked rect dege
bsalomon
2016/07/06 15:57:53
That seems to me a bit like rewriting "if (!width
| |
366 if ((!rect.width() || !rect.height()) && | |
367 SkStrokeRec::kHairline_Style != stroke.getStyle()) { | |
368 SkScalar r = stroke.getWidth() / 2; | |
369 // TODO: Move these stroke->fill fallbacks to GrShape? | |
370 switch (stroke.getJoin()) { | |
371 case SkPaint::kMiter_Join: | |
372 this->drawRect(clip, paint, viewMatrix, | |
373 {rect.fLeft - r, rect.fTop - r, | |
374 rect.fRight + r, rect.fBottom + r}, | |
375 &GrStyle::SimpleFill()); | |
376 return; | |
377 case SkPaint::kRound_Join: | |
robertphillips
2016/07/06 15:01:47
Isn't that a bug in raster though ?
bsalomon
2016/07/06 15:57:53
I'm not sure. Will check with reed@
| |
378 // Raster draws nothing when both dimensions are empty. | |
379 if (rect.width() || rect.height()){ | |
380 SkRRect rrect = SkRRect::MakeRectXY(rect.makeOutset(r, r ), r, r); | |
381 this->drawRRect(clip, paint, viewMatrix, rrect, GrStyle: :SimpleFill()); | |
382 return; | |
383 } | |
384 case SkPaint::kBevel_Join: | |
385 if (!rect.width()) { | |
386 this->drawRect(clip, paint, viewMatrix, | |
387 {rect.fLeft - r, rect.fTop, rect.fRight + r, rect.fBottom}, | |
388 &GrStyle::SimpleFill()); | |
389 } else { | |
390 this->drawRect(clip, paint, viewMatrix, | |
391 {rect.fLeft, rect.fTop - r, rect.fRight, rect.fBottom + r}, | |
392 &GrStyle::SimpleFill()); | |
393 } | |
394 return; | |
395 } | |
396 } | |
361 GrColor color = paint.getColor(); | 397 GrColor color = paint.getColor(); |
362 | |
363 if (should_apply_coverage_aa(paint, fRenderTarget.get(), &useHWAA)) { | 398 if (should_apply_coverage_aa(paint, fRenderTarget.get(), &useHWAA)) { |
364 // The stroke path needs the rect to remain axis aligned (no rotatio n or skew). | 399 // The stroke path needs the rect to remain axis aligned (no rotatio n or skew). |
365 if (viewMatrix.rectStaysRect()) { | 400 if (viewMatrix.rectStaysRect()) { |
366 batch.reset(GrRectBatchFactory::CreateAAStroke(color, viewMatrix , rect, | 401 batch.reset(GrRectBatchFactory::CreateAAStroke(color, viewMatrix , rect, stroke)); |
367 stroke)); | |
368 } | 402 } |
369 } else { | 403 } else { |
370 // Non-AA hairlines are snapped to pixel centers to make which pixel s are hit | |
371 // deterministic | |
372 snapToPixelCenters = (0 == width && !fRenderTarget->isUnifiedMultisa mpled()); | |
373 batch.reset(GrRectBatchFactory::CreateNonAAStroke(color, viewMatrix, rect, | |
374 width, snapToPixel Centers)); | |
375 | |
376 // Depending on sub-pixel coordinates and the particular GPU, we may lose a corner of | 404 // Depending on sub-pixel coordinates and the particular GPU, we may lose a corner of |
377 // hairline rects. We jam all the vertices to pixel centers to avoid this, but not | 405 // hairline rects. We jam all the vertices to pixel centers to avoid this, but not |
378 // when MSAA is enabled because it can cause ugly artifacts. | 406 // when MSAA is enabled because it can cause ugly artifacts. |
407 snapToPixelCenters = stroke.getStyle() == SkStrokeRec::kHairline_Sty le && | |
408 !fRenderTarget->isUnifiedMultisampled(); | |
409 batch.reset(GrRectBatchFactory::CreateNonAAStroke(color, viewMatrix, rect, | |
410 stroke, snapToPixe lCenters)); | |
379 } | 411 } |
380 } | 412 } |
381 | 413 |
382 if (batch) { | 414 if (batch) { |
383 GrPipelineBuilder pipelineBuilder(paint, useHWAA); | 415 GrPipelineBuilder pipelineBuilder(paint, useHWAA); |
384 | 416 |
385 if (snapToPixelCenters) { | 417 if (snapToPixelCenters) { |
386 pipelineBuilder.setState(GrPipelineBuilder::kSnapVerticesToPixelCent ers_Flag, | 418 pipelineBuilder.setState(GrPipelineBuilder::kSnapVerticesToPixelCent ers_Flag, |
387 snapToPixelCenters); | 419 snapToPixelCenters); |
388 } | 420 } |
(...skipping 708 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1097 | 1129 |
1098 void GrDrawContext::drawBatch(const GrPipelineBuilder& pipelineBuilder, const Gr Clip& clip, | 1130 void GrDrawContext::drawBatch(const GrPipelineBuilder& pipelineBuilder, const Gr Clip& clip, |
1099 GrDrawBatch* batch) { | 1131 GrDrawBatch* batch) { |
1100 ASSERT_SINGLE_OWNER | 1132 ASSERT_SINGLE_OWNER |
1101 RETURN_IF_ABANDONED | 1133 RETURN_IF_ABANDONED |
1102 SkDEBUGCODE(this->validate();) | 1134 SkDEBUGCODE(this->validate();) |
1103 GR_AUDIT_TRAIL_AUTO_FRAME(fAuditTrail, "GrDrawContext::drawBatch"); | 1135 GR_AUDIT_TRAIL_AUTO_FRAME(fAuditTrail, "GrDrawContext::drawBatch"); |
1104 | 1136 |
1105 this->getDrawTarget()->drawBatch(pipelineBuilder, this, clip, batch); | 1137 this->getDrawTarget()->drawBatch(pipelineBuilder, this, clip, batch); |
1106 } | 1138 } |
OLD | NEW |