OLD | NEW |
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2015 Google Inc. | 3 * Copyright 2015 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 "GrAtlasTextContext.h" | 9 #include "GrAtlasTextContext.h" |
10 #include "GrBatchTest.h" | 10 #include "GrBatchTest.h" |
(...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
297 } | 297 } |
298 | 298 |
299 GrColor color = paint.getColor(); | 299 GrColor color = paint.getColor(); |
300 SkRect devBoundRect; | 300 SkRect devBoundRect; |
301 bool needAA = paint.isAntiAlias() && | 301 bool needAA = paint.isAntiAlias() && |
302 !pipelineBuilder.getRenderTarget()->isUnifiedMultisampled(); | 302 !pipelineBuilder.getRenderTarget()->isUnifiedMultisampled(); |
303 bool doAA = needAA && apply_aa_to_rect(fDrawTarget, &pipelineBuilder, &devBo
undRect, rect, | 303 bool doAA = needAA && apply_aa_to_rect(fDrawTarget, &pipelineBuilder, &devBo
undRect, rect, |
304 width, viewMatrix, color); | 304 width, viewMatrix, color); |
305 | 305 |
306 if (doAA) { | 306 if (doAA) { |
307 SkAutoTUnref<GrBatch> batch; | 307 SkAutoTUnref<GrDrawBatch> batch; |
308 if (width >= 0) { | 308 if (width >= 0) { |
309 batch.reset(GrRectBatchFactory::CreateStrokeAA(color, viewMatrix, re
ct, devBoundRect, | 309 batch.reset(GrRectBatchFactory::CreateStrokeAA(color, viewMatrix, re
ct, devBoundRect, |
310 *strokeInfo)); | 310 *strokeInfo)); |
311 } else { | 311 } else { |
312 batch.reset(GrRectBatchFactory::CreateFillAA(color, viewMatrix, rect
, devBoundRect)); | 312 batch.reset(GrRectBatchFactory::CreateFillAA(color, viewMatrix, rect
, devBoundRect)); |
313 } | 313 } |
314 fDrawTarget->drawBatch(pipelineBuilder, batch); | 314 fDrawTarget->drawBatch(pipelineBuilder, batch); |
315 return; | 315 return; |
316 } | 316 } |
317 | 317 |
318 if (width >= 0) { | 318 if (width >= 0) { |
319 // Non-AA hairlines are snapped to pixel centers to make which pixels ar
e hit deterministic | 319 // Non-AA hairlines are snapped to pixel centers to make which pixels ar
e hit deterministic |
320 bool snapToPixelCenters = (0 == width && !rt->isUnifiedMultisampled()); | 320 bool snapToPixelCenters = (0 == width && !rt->isUnifiedMultisampled()); |
321 SkAutoTUnref<GrBatch> batch(GrRectBatchFactory::CreateStrokeBW(color, vi
ewMatrix, rect, | 321 SkAutoTUnref<GrDrawBatch> batch(GrRectBatchFactory::CreateStrokeBW( |
322 width, sn
apToPixelCenters)); | 322 color, viewMatrix, rect, width, snapToPi
xelCenters)); |
323 | 323 |
324 // Depending on sub-pixel coordinates and the particular GPU, we may los
e a corner of | 324 // Depending on sub-pixel coordinates and the particular GPU, we may los
e a corner of |
325 // hairline rects. We jam all the vertices to pixel centers to avoid thi
s, but not when MSAA | 325 // hairline rects. We jam all the vertices to pixel centers to avoid thi
s, but not when MSAA |
326 // is enabled because it can cause ugly artifacts. | 326 // is enabled because it can cause ugly artifacts. |
327 pipelineBuilder.setState(GrPipelineBuilder::kSnapVerticesToPixelCenters_
Flag, | 327 pipelineBuilder.setState(GrPipelineBuilder::kSnapVerticesToPixelCenters_
Flag, |
328 snapToPixelCenters); | 328 snapToPixelCenters); |
329 fDrawTarget->drawBatch(pipelineBuilder, batch); | 329 fDrawTarget->drawBatch(pipelineBuilder, batch); |
330 } else { | 330 } else { |
331 // filled BW rect | 331 // filled BW rect |
332 fDrawTarget->drawSimpleRect(pipelineBuilder, color, viewMatrix, rect); | 332 fDrawTarget->drawSimpleRect(pipelineBuilder, color, viewMatrix, rect); |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
384 viewMatrix.mapRect(&bounds); | 384 viewMatrix.mapRect(&bounds); |
385 | 385 |
386 // If we don't have AA then we outset for a half pixel in each direction to
account for | 386 // If we don't have AA then we outset for a half pixel in each direction to
account for |
387 // snapping | 387 // snapping |
388 if (!paint.isAntiAlias()) { | 388 if (!paint.isAntiAlias()) { |
389 bounds.outset(0.5f, 0.5f); | 389 bounds.outset(0.5f, 0.5f); |
390 } | 390 } |
391 | 391 |
392 GrDrawVerticesBatch::Geometry geometry; | 392 GrDrawVerticesBatch::Geometry geometry; |
393 geometry.fColor = paint.getColor(); | 393 geometry.fColor = paint.getColor(); |
394 SkAutoTUnref<GrBatch> batch(GrDrawVerticesBatch::Create(geometry, primitiveT
ype, viewMatrix, | 394 SkAutoTUnref<GrDrawBatch> batch(GrDrawVerticesBatch::Create(geometry, primit
iveType, viewMatrix, |
395 positions, vertexCou
nt, indices, | 395 positions, verte
xCount, indices, |
396 indexCount, colors,
texCoords, | 396 indexCount, colo
rs, texCoords, |
397 bounds)); | 397 bounds)); |
398 | 398 |
399 fDrawTarget->drawBatch(pipelineBuilder, batch); | 399 fDrawTarget->drawBatch(pipelineBuilder, batch); |
400 } | 400 } |
401 | 401 |
402 /////////////////////////////////////////////////////////////////////////////// | 402 /////////////////////////////////////////////////////////////////////////////// |
403 | 403 |
404 void GrDrawContext::drawAtlas(GrRenderTarget* rt, | 404 void GrDrawContext::drawAtlas(GrRenderTarget* rt, |
405 const GrClip& clip, | 405 const GrClip& clip, |
406 const GrPaint& paint, | 406 const GrPaint& paint, |
407 const SkMatrix& viewMatrix, | 407 const SkMatrix& viewMatrix, |
408 int spriteCount, | 408 int spriteCount, |
409 const SkRSXform xform[], | 409 const SkRSXform xform[], |
410 const SkRect texRect[], | 410 const SkRect texRect[], |
411 const SkColor colors[]) { | 411 const SkColor colors[]) { |
412 RETURN_IF_ABANDONED | 412 RETURN_IF_ABANDONED |
413 AutoCheckFlush acf(fContext); | 413 AutoCheckFlush acf(fContext); |
414 if (!this->prepareToDraw(rt)) { | 414 if (!this->prepareToDraw(rt)) { |
415 return; | 415 return; |
416 } | 416 } |
417 | 417 |
418 GrPipelineBuilder pipelineBuilder(paint, rt, clip); | 418 GrPipelineBuilder pipelineBuilder(paint, rt, clip); |
419 | 419 |
420 GrDrawAtlasBatch::Geometry geometry; | 420 GrDrawAtlasBatch::Geometry geometry; |
421 geometry.fColor = paint.getColor(); | 421 geometry.fColor = paint.getColor(); |
422 SkAutoTUnref<GrBatch> batch(GrDrawAtlasBatch::Create(geometry, viewMatrix, s
priteCount, | 422 SkAutoTUnref<GrDrawBatch> batch(GrDrawAtlasBatch::Create(geometry, viewMatri
x, spriteCount, |
423 xform, texRect, colors)
); | 423 xform, texRect, col
ors)); |
424 | 424 |
425 fDrawTarget->drawBatch(pipelineBuilder, batch); | 425 fDrawTarget->drawBatch(pipelineBuilder, batch); |
426 } | 426 } |
427 | 427 |
428 /////////////////////////////////////////////////////////////////////////////// | 428 /////////////////////////////////////////////////////////////////////////////// |
429 | 429 |
430 void GrDrawContext::drawRRect(GrRenderTarget*rt, | 430 void GrDrawContext::drawRRect(GrRenderTarget*rt, |
431 const GrClip& clip, | 431 const GrClip& clip, |
432 const GrPaint& paint, | 432 const GrPaint& paint, |
433 const SkMatrix& viewMatrix, | 433 const SkMatrix& viewMatrix, |
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
594 } | 594 } |
595 if (!SkScalarNearlyEqual(margin, temp)) { | 595 if (!SkScalarNearlyEqual(margin, temp)) { |
596 allEq = false; | 596 allEq = false; |
597 } | 597 } |
598 } | 598 } |
599 | 599 |
600 return allEq || allGoE1; | 600 return allEq || allGoE1; |
601 } | 601 } |
602 | 602 |
603 void GrDrawContext::drawBatch(GrRenderTarget* rt, const GrClip& clip, | 603 void GrDrawContext::drawBatch(GrRenderTarget* rt, const GrClip& clip, |
604 const GrPaint& paint, GrBatch* batch) { | 604 const GrPaint& paint, GrDrawBatch* batch) { |
605 RETURN_IF_ABANDONED | 605 RETURN_IF_ABANDONED |
606 | 606 |
607 AutoCheckFlush acf(fContext); | 607 AutoCheckFlush acf(fContext); |
608 if (!this->prepareToDraw(rt)) { | 608 if (!this->prepareToDraw(rt)) { |
609 return; | 609 return; |
610 } | 610 } |
611 | 611 |
612 GrPipelineBuilder pipelineBuilder(paint, rt, clip); | 612 GrPipelineBuilder pipelineBuilder(paint, rt, clip); |
613 fDrawTarget->drawBatch(pipelineBuilder, batch); | 613 fDrawTarget->drawBatch(pipelineBuilder, batch); |
614 } | 614 } |
(...skipping 27 matching lines...) Expand all Loading... |
642 GrPipelineBuilder pipelineBuilder(paint, rt, clip); | 642 GrPipelineBuilder pipelineBuilder(paint, rt, clip); |
643 if (!strokeInfo.isDashed()) { | 643 if (!strokeInfo.isDashed()) { |
644 bool useCoverageAA = paint.isAntiAlias() && | 644 bool useCoverageAA = paint.isAntiAlias() && |
645 !pipelineBuilder.getRenderTarget()->isUnifiedMultisampled(); | 645 !pipelineBuilder.getRenderTarget()->isUnifiedMultisampled(); |
646 | 646 |
647 if (useCoverageAA && strokeInfo.getWidth() < 0 && !path.isConvex()) { | 647 if (useCoverageAA && strokeInfo.getWidth() < 0 && !path.isConvex()) { |
648 // Concave AA paths are expensive - try to avoid them for special ca
ses | 648 // Concave AA paths are expensive - try to avoid them for special ca
ses |
649 SkRect rects[2]; | 649 SkRect rects[2]; |
650 | 650 |
651 if (is_nested_rects(viewMatrix, path, strokeInfo, rects)) { | 651 if (is_nested_rects(viewMatrix, path, strokeInfo, rects)) { |
652 SkAutoTUnref<GrBatch> batch(GrRectBatchFactory::CreateFillNested
RectsAA(color, | 652 SkAutoTUnref<GrDrawBatch> batch(GrRectBatchFactory::CreateFillNe
stedRectsAA( |
653
viewMatrix, | 653 color, viewMatrix, rects)); |
654
rects)); | |
655 fDrawTarget->drawBatch(pipelineBuilder, batch); | 654 fDrawTarget->drawBatch(pipelineBuilder, batch); |
656 return; | 655 return; |
657 } | 656 } |
658 } | 657 } |
659 SkRect ovalRect; | 658 SkRect ovalRect; |
660 bool isOval = path.isOval(&ovalRect); | 659 bool isOval = path.isOval(&ovalRect); |
661 | 660 |
662 if (isOval && !path.isInverseFillType()) { | 661 if (isOval && !path.isInverseFillType()) { |
663 if (GrOvalRenderer::DrawOval(fDrawTarget, | 662 if (GrOvalRenderer::DrawOval(fDrawTarget, |
664 pipelineBuilder, | 663 pipelineBuilder, |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
765 } | 764 } |
766 | 765 |
767 bool GrDrawContext::prepareToDraw(GrRenderTarget* rt) { | 766 bool GrDrawContext::prepareToDraw(GrRenderTarget* rt) { |
768 RETURN_FALSE_IF_ABANDONED | 767 RETURN_FALSE_IF_ABANDONED |
769 | 768 |
770 ASSERT_OWNED_RESOURCE(rt); | 769 ASSERT_OWNED_RESOURCE(rt); |
771 SkASSERT(rt); | 770 SkASSERT(rt); |
772 return true; | 771 return true; |
773 } | 772 } |
774 | 773 |
775 void GrDrawContext::drawBatch(GrPipelineBuilder* pipelineBuilder, GrBatch* batch
) { | 774 void GrDrawContext::drawBatch(GrPipelineBuilder* pipelineBuilder, GrDrawBatch* b
atch) { |
776 fDrawTarget->drawBatch(*pipelineBuilder, batch); | 775 fDrawTarget->drawBatch(*pipelineBuilder, batch); |
777 } | 776 } |
OLD | NEW |