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 | 8 |
9 #include "GrContext.h" | 9 #include "GrContext.h" |
10 | 10 |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
79 if (context->init(backend, backendContext)) { | 79 if (context->init(backend, backendContext)) { |
80 return context; | 80 return context; |
81 } else { | 81 } else { |
82 context->unref(); | 82 context->unref(); |
83 return NULL; | 83 return NULL; |
84 } | 84 } |
85 } | 85 } |
86 | 86 |
87 GrContext::GrContext(const Options& opts) : fOptions(opts) { | 87 GrContext::GrContext(const Options& opts) : fOptions(opts) { |
88 fGpu = NULL; | 88 fGpu = NULL; |
| 89 fClip = NULL; |
89 fPathRendererChain = NULL; | 90 fPathRendererChain = NULL; |
90 fSoftwarePathRenderer = NULL; | 91 fSoftwarePathRenderer = NULL; |
91 fResourceCache = NULL; | 92 fResourceCache = NULL; |
92 fFontCache = NULL; | 93 fFontCache = NULL; |
93 fDrawBuffer = NULL; | 94 fDrawBuffer = NULL; |
94 fDrawBufferVBAllocPool = NULL; | 95 fDrawBufferVBAllocPool = NULL; |
95 fDrawBufferIBAllocPool = NULL; | 96 fDrawBufferIBAllocPool = NULL; |
96 fFlushToReduceCacheSize = false; | 97 fFlushToReduceCacheSize = false; |
97 fAARectRenderer = NULL; | 98 fAARectRenderer = NULL; |
98 fOvalRenderer = NULL; | 99 fOvalRenderer = NULL; |
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
355 | 356 |
356 void GrContext::clear(const SkIRect* rect, | 357 void GrContext::clear(const SkIRect* rect, |
357 const GrColor color, | 358 const GrColor color, |
358 bool canIgnoreRect, | 359 bool canIgnoreRect, |
359 GrRenderTarget* renderTarget) { | 360 GrRenderTarget* renderTarget) { |
360 ASSERT_OWNED_RESOURCE(renderTarget); | 361 ASSERT_OWNED_RESOURCE(renderTarget); |
361 SkASSERT(renderTarget); | 362 SkASSERT(renderTarget); |
362 | 363 |
363 AutoCheckFlush acf(this); | 364 AutoCheckFlush acf(this); |
364 GR_CREATE_TRACE_MARKER_CONTEXT("GrContext::clear", this); | 365 GR_CREATE_TRACE_MARKER_CONTEXT("GrContext::clear", this); |
365 GrDrawTarget* target = this->prepareToDraw(); | 366 GrDrawTarget* target = this->prepareToDraw(NULL, renderTarget, NULL, &acf); |
366 if (NULL == target) { | 367 if (NULL == target) { |
367 return; | 368 return; |
368 } | 369 } |
369 target->clear(rect, color, canIgnoreRect, renderTarget); | 370 target->clear(rect, color, canIgnoreRect, renderTarget); |
370 } | 371 } |
371 | 372 |
372 void GrContext::drawPaint(GrRenderTarget* rt, | 373 void GrContext::drawPaint(GrRenderTarget* rt, |
373 const GrClip& clip, | |
374 const GrPaint& origPaint, | 374 const GrPaint& origPaint, |
375 const SkMatrix& viewMatrix) { | 375 const SkMatrix& viewMatrix) { |
376 // set rect to be big enough to fill the space, but not super-huge, so we | 376 // set rect to be big enough to fill the space, but not super-huge, so we |
377 // don't overflow fixed-point implementations | 377 // don't overflow fixed-point implementations |
378 SkRect r; | 378 SkRect r; |
379 r.setLTRB(0, 0, | 379 r.setLTRB(0, 0, |
380 SkIntToScalar(rt->width()), | 380 SkIntToScalar(rt->width()), |
381 SkIntToScalar(rt->height())); | 381 SkIntToScalar(rt->height())); |
382 SkTCopyOnFirstWrite<GrPaint> paint(origPaint); | 382 SkTCopyOnFirstWrite<GrPaint> paint(origPaint); |
383 | 383 |
384 // by definition this fills the entire clip, no need for AA | 384 // by definition this fills the entire clip, no need for AA |
385 if (paint->isAntiAlias()) { | 385 if (paint->isAntiAlias()) { |
386 paint.writable()->setAntiAlias(false); | 386 paint.writable()->setAntiAlias(false); |
387 } | 387 } |
388 | 388 |
389 bool isPerspective = viewMatrix.hasPerspective(); | 389 bool isPerspective = viewMatrix.hasPerspective(); |
390 | 390 |
391 // We attempt to map r by the inverse matrix and draw that. mapRect will | 391 // We attempt to map r by the inverse matrix and draw that. mapRect will |
392 // map the four corners and bound them with a new rect. This will not | 392 // map the four corners and bound them with a new rect. This will not |
393 // produce a correct result for some perspective matrices. | 393 // produce a correct result for some perspective matrices. |
394 if (!isPerspective) { | 394 if (!isPerspective) { |
395 SkMatrix inverse; | 395 SkMatrix inverse; |
396 if (!viewMatrix.invert(&inverse)) { | 396 if (!viewMatrix.invert(&inverse)) { |
397 SkDebugf("Could not invert matrix\n"); | 397 SkDebugf("Could not invert matrix\n"); |
398 return; | 398 return; |
399 } | 399 } |
400 inverse.mapRect(&r); | 400 inverse.mapRect(&r); |
401 this->drawRect(rt, clip, *paint, viewMatrix, r); | 401 this->drawRect(rt, *paint, viewMatrix, r); |
402 } else { | 402 } else { |
403 SkMatrix localMatrix; | 403 SkMatrix localMatrix; |
404 if (!viewMatrix.invert(&localMatrix)) { | 404 if (!viewMatrix.invert(&localMatrix)) { |
405 SkDebugf("Could not invert matrix\n"); | 405 SkDebugf("Could not invert matrix\n"); |
406 return; | 406 return; |
407 } | 407 } |
408 | 408 |
409 AutoCheckFlush acf(this); | 409 AutoCheckFlush acf(this); |
410 GrPipelineBuilder pipelineBuilder; | 410 GrPipelineBuilder pipelineBuilder; |
411 GrDrawTarget* target = this->prepareToDraw(&pipelineBuilder, rt, clip, p
aint, &acf); | 411 GrDrawTarget* target = this->prepareToDraw(&pipelineBuilder, rt, paint,
&acf); |
412 if (NULL == target) { | 412 if (NULL == target) { |
413 return; | 413 return; |
414 } | 414 } |
415 | 415 |
416 GR_CREATE_TRACE_MARKER("GrContext::drawPaintWithPerspective", target); | 416 GR_CREATE_TRACE_MARKER("GrContext::drawPaintWithPerspective", target); |
417 target->drawRect(&pipelineBuilder, | 417 target->drawRect(&pipelineBuilder, |
418 paint->getColor(), | 418 paint->getColor(), |
419 SkMatrix::I(), | 419 SkMatrix::I(), |
420 r, | 420 r, |
421 NULL, | 421 NULL, |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
495 | 495 |
496 return true; | 496 return true; |
497 } | 497 } |
498 | 498 |
499 static inline bool rect_contains_inclusive(const SkRect& rect, const SkPoint& po
int) { | 499 static inline bool rect_contains_inclusive(const SkRect& rect, const SkPoint& po
int) { |
500 return point.fX >= rect.fLeft && point.fX <= rect.fRight && | 500 return point.fX >= rect.fLeft && point.fX <= rect.fRight && |
501 point.fY >= rect.fTop && point.fY <= rect.fBottom; | 501 point.fY >= rect.fTop && point.fY <= rect.fBottom; |
502 } | 502 } |
503 | 503 |
504 void GrContext::drawRect(GrRenderTarget* rt, | 504 void GrContext::drawRect(GrRenderTarget* rt, |
505 const GrClip& clip, | |
506 const GrPaint& paint, | 505 const GrPaint& paint, |
507 const SkMatrix& viewMatrix, | 506 const SkMatrix& viewMatrix, |
508 const SkRect& rect, | 507 const SkRect& rect, |
509 const GrStrokeInfo* strokeInfo) { | 508 const GrStrokeInfo* strokeInfo) { |
510 if (strokeInfo && strokeInfo->isDashed()) { | 509 if (strokeInfo && strokeInfo->isDashed()) { |
511 SkPath path; | 510 SkPath path; |
512 path.addRect(rect); | 511 path.addRect(rect); |
513 this->drawPath(rt, clip, paint, viewMatrix, path, *strokeInfo); | 512 this->drawPath(rt, paint, viewMatrix, path, *strokeInfo); |
514 return; | 513 return; |
515 } | 514 } |
516 | 515 |
517 AutoCheckFlush acf(this); | 516 AutoCheckFlush acf(this); |
518 GrPipelineBuilder pipelineBuilder; | 517 GrPipelineBuilder pipelineBuilder; |
519 GrDrawTarget* target = this->prepareToDraw(&pipelineBuilder, rt, clip, &pain
t, &acf); | 518 GrDrawTarget* target = this->prepareToDraw(&pipelineBuilder, rt, &paint, &ac
f); |
520 if (NULL == target) { | 519 if (NULL == target) { |
521 return; | 520 return; |
522 } | 521 } |
523 | 522 |
524 GR_CREATE_TRACE_MARKER("GrContext::drawRect", target); | 523 GR_CREATE_TRACE_MARKER("GrContext::drawRect", target); |
525 SkScalar width = NULL == strokeInfo ? -1 : strokeInfo->getStrokeRec().getWid
th(); | 524 SkScalar width = NULL == strokeInfo ? -1 : strokeInfo->getStrokeRec().getWid
th(); |
526 | 525 |
527 // Check if this is a full RT draw and can be replaced with a clear. We don'
t bother checking | 526 // Check if this is a full RT draw and can be replaced with a clear. We don'
t bother checking |
528 // cases where the RT is fully inside a stroke. | 527 // cases where the RT is fully inside a stroke. |
529 if (width < 0) { | 528 if (width < 0) { |
530 SkRect rtRect; | 529 SkRect rtRect; |
531 pipelineBuilder.getRenderTarget()->getBoundsRect(&rtRect); | 530 pipelineBuilder.getRenderTarget()->getBoundsRect(&rtRect); |
532 SkRect clipSpaceRTRect = rtRect; | 531 SkRect clipSpaceRTRect = rtRect; |
533 bool checkClip = GrClip::kWideOpen_ClipType != clip.clipType(); | 532 bool checkClip = fClip && GrClip::kWideOpen_ClipType != fClip->clipType(
); |
534 if (checkClip) { | 533 if (checkClip) { |
535 clipSpaceRTRect.offset(SkIntToScalar(clip.origin().fX), | 534 clipSpaceRTRect.offset(SkIntToScalar(this->getClip()->origin().fX), |
536 SkIntToScalar(clip.origin().fY)); | 535 SkIntToScalar(this->getClip()->origin().fY)); |
537 } | 536 } |
538 // Does the clip contain the entire RT? | 537 // Does the clip contain the entire RT? |
539 if (!checkClip || clip.quickContains(clipSpaceRTRect)) { | 538 if (!checkClip || fClip->clipStack()->quickContains(clipSpaceRTRect)) { |
540 SkMatrix invM; | 539 SkMatrix invM; |
541 if (!viewMatrix.invert(&invM)) { | 540 if (!viewMatrix.invert(&invM)) { |
542 return; | 541 return; |
543 } | 542 } |
544 // Does the rect bound the RT? | 543 // Does the rect bound the RT? |
545 SkPoint srcSpaceRTQuad[4]; | 544 SkPoint srcSpaceRTQuad[4]; |
546 invM.mapRectToQuad(srcSpaceRTQuad, rtRect); | 545 invM.mapRectToQuad(srcSpaceRTQuad, rtRect); |
547 if (rect_contains_inclusive(rect, srcSpaceRTQuad[0]) && | 546 if (rect_contains_inclusive(rect, srcSpaceRTQuad[0]) && |
548 rect_contains_inclusive(rect, srcSpaceRTQuad[1]) && | 547 rect_contains_inclusive(rect, srcSpaceRTQuad[1]) && |
549 rect_contains_inclusive(rect, srcSpaceRTQuad[2]) && | 548 rect_contains_inclusive(rect, srcSpaceRTQuad[2]) && |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
628 } | 627 } |
629 | 628 |
630 target->drawNonIndexed(&pipelineBuilder, gp, primType, 0, vertCount); | 629 target->drawNonIndexed(&pipelineBuilder, gp, primType, 0, vertCount); |
631 } else { | 630 } else { |
632 // filled BW rect | 631 // filled BW rect |
633 target->drawSimpleRect(&pipelineBuilder, color, viewMatrix, rect); | 632 target->drawSimpleRect(&pipelineBuilder, color, viewMatrix, rect); |
634 } | 633 } |
635 } | 634 } |
636 | 635 |
637 void GrContext::drawNonAARectToRect(GrRenderTarget* rt, | 636 void GrContext::drawNonAARectToRect(GrRenderTarget* rt, |
638 const GrClip& clip, | |
639 const GrPaint& paint, | 637 const GrPaint& paint, |
640 const SkMatrix& viewMatrix, | 638 const SkMatrix& viewMatrix, |
641 const SkRect& rectToDraw, | 639 const SkRect& rectToDraw, |
642 const SkRect& localRect, | 640 const SkRect& localRect, |
643 const SkMatrix* localMatrix) { | 641 const SkMatrix* localMatrix) { |
644 AutoCheckFlush acf(this); | 642 AutoCheckFlush acf(this); |
645 GrPipelineBuilder pipelineBuilder; | 643 GrPipelineBuilder pipelineBuilder; |
646 GrDrawTarget* target = this->prepareToDraw(&pipelineBuilder, rt, clip, &pain
t, &acf); | 644 GrDrawTarget* target = this->prepareToDraw(&pipelineBuilder, rt, &paint, &ac
f); |
647 if (NULL == target) { | 645 if (NULL == target) { |
648 return; | 646 return; |
649 } | 647 } |
650 | 648 |
651 GR_CREATE_TRACE_MARKER("GrContext::drawRectToRect", target); | 649 GR_CREATE_TRACE_MARKER("GrContext::drawRectToRect", target); |
652 | 650 |
653 target->drawRect(&pipelineBuilder, | 651 target->drawRect(&pipelineBuilder, |
654 paint.getColor(), | 652 paint.getColor(), |
655 viewMatrix, | 653 viewMatrix, |
656 rectToDraw, | 654 rectToDraw, |
(...skipping 19 matching lines...) Expand all Loading... |
676 *texOffset = sizeof(SkPoint); | 674 *texOffset = sizeof(SkPoint); |
677 flags |= GrDefaultGeoProcFactory::kLocalCoord_GPType; | 675 flags |= GrDefaultGeoProcFactory::kLocalCoord_GPType; |
678 } else if (colors) { | 676 } else if (colors) { |
679 *colorOffset = sizeof(SkPoint); | 677 *colorOffset = sizeof(SkPoint); |
680 flags |= GrDefaultGeoProcFactory::kColor_GPType; | 678 flags |= GrDefaultGeoProcFactory::kColor_GPType; |
681 } | 679 } |
682 return GrDefaultGeoProcFactory::Create(flags, color, viewMatrix, SkMatrix::I
()); | 680 return GrDefaultGeoProcFactory::Create(flags, color, viewMatrix, SkMatrix::I
()); |
683 } | 681 } |
684 | 682 |
685 void GrContext::drawVertices(GrRenderTarget* rt, | 683 void GrContext::drawVertices(GrRenderTarget* rt, |
686 const GrClip& clip, | |
687 const GrPaint& paint, | 684 const GrPaint& paint, |
688 const SkMatrix& viewMatrix, | 685 const SkMatrix& viewMatrix, |
689 GrPrimitiveType primitiveType, | 686 GrPrimitiveType primitiveType, |
690 int vertexCount, | 687 int vertexCount, |
691 const SkPoint positions[], | 688 const SkPoint positions[], |
692 const SkPoint texCoords[], | 689 const SkPoint texCoords[], |
693 const GrColor colors[], | 690 const GrColor colors[], |
694 const uint16_t indices[], | 691 const uint16_t indices[], |
695 int indexCount) { | 692 int indexCount) { |
696 AutoCheckFlush acf(this); | 693 AutoCheckFlush acf(this); |
697 GrPipelineBuilder pipelineBuilder; | 694 GrPipelineBuilder pipelineBuilder; |
698 GrDrawTarget::AutoReleaseGeometry geo; // must be inside AutoCheckFlush scop
e | 695 GrDrawTarget::AutoReleaseGeometry geo; // must be inside AutoCheckFlush scop
e |
699 | 696 |
700 GrDrawTarget* target = this->prepareToDraw(&pipelineBuilder, rt, clip, &pain
t, &acf); | 697 GrDrawTarget* target = this->prepareToDraw(&pipelineBuilder, rt, &paint, &ac
f); |
701 if (NULL == target) { | 698 if (NULL == target) { |
702 return; | 699 return; |
703 } | 700 } |
704 | 701 |
705 GR_CREATE_TRACE_MARKER("GrContext::drawVertices", target); | 702 GR_CREATE_TRACE_MARKER("GrContext::drawVertices", target); |
706 | 703 |
707 int colorOffset = -1, texOffset = -1; | 704 int colorOffset = -1, texOffset = -1; |
708 SkAutoTUnref<const GrGeometryProcessor> gp( | 705 SkAutoTUnref<const GrGeometryProcessor> gp( |
709 set_vertex_attributes(texCoords, colors, &colorOffset, &texOffset, | 706 set_vertex_attributes(texCoords, colors, &colorOffset, &texOffset, |
710 paint.getColor(), viewMatrix)); | 707 paint.getColor(), viewMatrix)); |
(...skipping 28 matching lines...) Expand all Loading... |
739 } | 736 } |
740 target->drawIndexed(&pipelineBuilder, gp, primitiveType, 0, 0, vertexCou
nt, indexCount); | 737 target->drawIndexed(&pipelineBuilder, gp, primitiveType, 0, 0, vertexCou
nt, indexCount); |
741 } else { | 738 } else { |
742 target->drawNonIndexed(&pipelineBuilder, gp, primitiveType, 0, vertexCou
nt); | 739 target->drawNonIndexed(&pipelineBuilder, gp, primitiveType, 0, vertexCou
nt); |
743 } | 740 } |
744 } | 741 } |
745 | 742 |
746 /////////////////////////////////////////////////////////////////////////////// | 743 /////////////////////////////////////////////////////////////////////////////// |
747 | 744 |
748 void GrContext::drawRRect(GrRenderTarget*rt, | 745 void GrContext::drawRRect(GrRenderTarget*rt, |
749 const GrClip& clip, | |
750 const GrPaint& paint, | 746 const GrPaint& paint, |
751 const SkMatrix& viewMatrix, | 747 const SkMatrix& viewMatrix, |
752 const SkRRect& rrect, | 748 const SkRRect& rrect, |
753 const GrStrokeInfo& strokeInfo) { | 749 const GrStrokeInfo& strokeInfo) { |
754 if (rrect.isEmpty()) { | 750 if (rrect.isEmpty()) { |
755 return; | 751 return; |
756 } | 752 } |
757 | 753 |
758 if (strokeInfo.isDashed()) { | 754 if (strokeInfo.isDashed()) { |
759 SkPath path; | 755 SkPath path; |
760 path.addRRect(rrect); | 756 path.addRRect(rrect); |
761 this->drawPath(rt, clip, paint, viewMatrix, path, strokeInfo); | 757 this->drawPath(rt, paint, viewMatrix, path, strokeInfo); |
762 return; | 758 return; |
763 } | 759 } |
764 | 760 |
765 AutoCheckFlush acf(this); | 761 AutoCheckFlush acf(this); |
766 GrPipelineBuilder pipelineBuilder; | 762 GrPipelineBuilder pipelineBuilder; |
767 GrDrawTarget* target = this->prepareToDraw(&pipelineBuilder, rt, clip, &pain
t, &acf); | 763 GrDrawTarget* target = this->prepareToDraw(&pipelineBuilder, rt, &paint, &ac
f); |
768 if (NULL == target) { | 764 if (NULL == target) { |
769 return; | 765 return; |
770 } | 766 } |
771 | 767 |
772 GR_CREATE_TRACE_MARKER("GrContext::drawRRect", target); | 768 GR_CREATE_TRACE_MARKER("GrContext::drawRRect", target); |
773 | 769 |
774 const SkStrokeRec& strokeRec = strokeInfo.getStrokeRec(); | 770 const SkStrokeRec& strokeRec = strokeInfo.getStrokeRec(); |
775 | 771 |
776 GrColor color = paint.getColor(); | 772 GrColor color = paint.getColor(); |
777 if (!fOvalRenderer->drawRRect(target, | 773 if (!fOvalRenderer->drawRRect(target, |
778 &pipelineBuilder, | 774 &pipelineBuilder, |
779 color, | 775 color, |
780 viewMatrix, | 776 viewMatrix, |
781 paint.isAntiAlias(), | 777 paint.isAntiAlias(), |
782 rrect, | 778 rrect, |
783 strokeRec)) { | 779 strokeRec)) { |
784 SkPath path; | 780 SkPath path; |
785 path.addRRect(rrect); | 781 path.addRRect(rrect); |
786 this->internalDrawPath(target, &pipelineBuilder, viewMatrix, color, pain
t.isAntiAlias(), | 782 this->internalDrawPath(target, &pipelineBuilder, viewMatrix, color, pain
t.isAntiAlias(), |
787 path, strokeInfo); | 783 path, strokeInfo); |
788 } | 784 } |
789 } | 785 } |
790 | 786 |
791 /////////////////////////////////////////////////////////////////////////////// | 787 /////////////////////////////////////////////////////////////////////////////// |
792 | 788 |
793 void GrContext::drawDRRect(GrRenderTarget* rt, | 789 void GrContext::drawDRRect(GrRenderTarget* rt, |
794 const GrClip& clip, | |
795 const GrPaint& paint, | 790 const GrPaint& paint, |
796 const SkMatrix& viewMatrix, | 791 const SkMatrix& viewMatrix, |
797 const SkRRect& outer, | 792 const SkRRect& outer, |
798 const SkRRect& inner) { | 793 const SkRRect& inner) { |
799 if (outer.isEmpty()) { | 794 if (outer.isEmpty()) { |
800 return; | 795 return; |
801 } | 796 } |
802 | 797 |
803 AutoCheckFlush acf(this); | 798 AutoCheckFlush acf(this); |
804 GrPipelineBuilder pipelineBuilder; | 799 GrPipelineBuilder pipelineBuilder; |
805 GrDrawTarget* target = this->prepareToDraw(&pipelineBuilder, rt, clip, &pain
t, &acf); | 800 GrDrawTarget* target = this->prepareToDraw(&pipelineBuilder, rt, &paint, &ac
f); |
806 | 801 |
807 GR_CREATE_TRACE_MARKER("GrContext::drawDRRect", target); | 802 GR_CREATE_TRACE_MARKER("GrContext::drawDRRect", target); |
808 | 803 |
809 GrColor color = paint.getColor(); | 804 GrColor color = paint.getColor(); |
810 if (!fOvalRenderer->drawDRRect(target, | 805 if (!fOvalRenderer->drawDRRect(target, |
811 &pipelineBuilder, | 806 &pipelineBuilder, |
812 color, | 807 color, |
813 viewMatrix, | 808 viewMatrix, |
814 paint.isAntiAlias(), | 809 paint.isAntiAlias(), |
815 outer, | 810 outer, |
816 inner)) { | 811 inner)) { |
817 SkPath path; | 812 SkPath path; |
818 path.addRRect(inner); | 813 path.addRRect(inner); |
819 path.addRRect(outer); | 814 path.addRRect(outer); |
820 path.setFillType(SkPath::kEvenOdd_FillType); | 815 path.setFillType(SkPath::kEvenOdd_FillType); |
821 | 816 |
822 GrStrokeInfo fillRec(SkStrokeRec::kFill_InitStyle); | 817 GrStrokeInfo fillRec(SkStrokeRec::kFill_InitStyle); |
823 this->internalDrawPath(target, &pipelineBuilder, viewMatrix, color, pain
t.isAntiAlias(), | 818 this->internalDrawPath(target, &pipelineBuilder, viewMatrix, color, pain
t.isAntiAlias(), |
824 path, fillRec); | 819 path, fillRec); |
825 } | 820 } |
826 } | 821 } |
827 | 822 |
828 /////////////////////////////////////////////////////////////////////////////// | 823 /////////////////////////////////////////////////////////////////////////////// |
829 | 824 |
830 void GrContext::drawOval(GrRenderTarget* rt, | 825 void GrContext::drawOval(GrRenderTarget*rt, |
831 const GrClip& clip, | |
832 const GrPaint& paint, | 826 const GrPaint& paint, |
833 const SkMatrix& viewMatrix, | 827 const SkMatrix& viewMatrix, |
834 const SkRect& oval, | 828 const SkRect& oval, |
835 const GrStrokeInfo& strokeInfo) { | 829 const GrStrokeInfo& strokeInfo) { |
836 if (oval.isEmpty()) { | 830 if (oval.isEmpty()) { |
837 return; | 831 return; |
838 } | 832 } |
839 | 833 |
840 if (strokeInfo.isDashed()) { | 834 if (strokeInfo.isDashed()) { |
841 SkPath path; | 835 SkPath path; |
842 path.addOval(oval); | 836 path.addOval(oval); |
843 this->drawPath(rt, clip, paint, viewMatrix, path, strokeInfo); | 837 this->drawPath(rt, paint, viewMatrix, path, strokeInfo); |
844 return; | 838 return; |
845 } | 839 } |
846 | 840 |
847 AutoCheckFlush acf(this); | 841 AutoCheckFlush acf(this); |
848 GrPipelineBuilder pipelineBuilder; | 842 GrPipelineBuilder pipelineBuilder; |
849 GrDrawTarget* target = this->prepareToDraw(&pipelineBuilder, rt, clip, &pain
t, &acf); | 843 GrDrawTarget* target = this->prepareToDraw(&pipelineBuilder, rt, &paint, &ac
f); |
850 if (NULL == target) { | 844 if (NULL == target) { |
851 return; | 845 return; |
852 } | 846 } |
853 | 847 |
854 GR_CREATE_TRACE_MARKER("GrContext::drawOval", target); | 848 GR_CREATE_TRACE_MARKER("GrContext::drawOval", target); |
855 | 849 |
856 const SkStrokeRec& strokeRec = strokeInfo.getStrokeRec(); | 850 const SkStrokeRec& strokeRec = strokeInfo.getStrokeRec(); |
857 | 851 |
858 GrColor color = paint.getColor(); | 852 GrColor color = paint.getColor(); |
859 if (!fOvalRenderer->drawOval(target, | 853 if (!fOvalRenderer->drawOval(target, |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
917 } | 911 } |
918 if (!SkScalarNearlyEqual(margin, temp)) { | 912 if (!SkScalarNearlyEqual(margin, temp)) { |
919 allEq = false; | 913 allEq = false; |
920 } | 914 } |
921 } | 915 } |
922 | 916 |
923 return allEq || allGoE1; | 917 return allEq || allGoE1; |
924 } | 918 } |
925 | 919 |
926 void GrContext::drawPath(GrRenderTarget* rt, | 920 void GrContext::drawPath(GrRenderTarget* rt, |
927 const GrClip& clip, | |
928 const GrPaint& paint, | 921 const GrPaint& paint, |
929 const SkMatrix& viewMatrix, | 922 const SkMatrix& viewMatrix, |
930 const SkPath& path, | 923 const SkPath& path, |
931 const GrStrokeInfo& strokeInfo) { | 924 const GrStrokeInfo& strokeInfo) { |
932 | 925 |
933 if (path.isEmpty()) { | 926 if (path.isEmpty()) { |
934 if (path.isInverseFillType()) { | 927 if (path.isInverseFillType()) { |
935 this->drawPaint(rt, clip, paint, viewMatrix); | 928 this->drawPaint(rt, paint, viewMatrix); |
936 } | 929 } |
937 return; | 930 return; |
938 } | 931 } |
939 | 932 |
940 GrColor color = paint.getColor(); | 933 GrColor color = paint.getColor(); |
941 if (strokeInfo.isDashed()) { | 934 if (strokeInfo.isDashed()) { |
942 SkPoint pts[2]; | 935 SkPoint pts[2]; |
943 if (path.isLine(pts)) { | 936 if (path.isLine(pts)) { |
944 AutoCheckFlush acf(this); | 937 AutoCheckFlush acf(this); |
945 GrPipelineBuilder pipelineBuilder; | 938 GrPipelineBuilder pipelineBuilder; |
946 GrDrawTarget* target = this->prepareToDraw(&pipelineBuilder, rt, cli
p, &paint, &acf); | 939 GrDrawTarget* target = this->prepareToDraw(&pipelineBuilder, rt, &pa
int, &acf); |
947 if (NULL == target) { | 940 if (NULL == target) { |
948 return; | 941 return; |
949 } | 942 } |
950 | 943 |
951 if (GrDashingEffect::DrawDashLine(fGpu, target, &pipelineBuilder, co
lor, viewMatrix, | 944 if (GrDashingEffect::DrawDashLine(fGpu, target, &pipelineBuilder, co
lor, viewMatrix, |
952 pts, paint, strokeInfo)) { | 945 pts, paint, strokeInfo)) { |
953 return; | 946 return; |
954 } | 947 } |
955 } | 948 } |
956 | 949 |
957 // Filter dashed path into new path with the dashing applied | 950 // Filter dashed path into new path with the dashing applied |
958 const SkPathEffect::DashInfo& info = strokeInfo.getDashInfo(); | 951 const SkPathEffect::DashInfo& info = strokeInfo.getDashInfo(); |
959 SkTLazy<SkPath> effectPath; | 952 SkTLazy<SkPath> effectPath; |
960 GrStrokeInfo newStrokeInfo(strokeInfo, false); | 953 GrStrokeInfo newStrokeInfo(strokeInfo, false); |
961 SkStrokeRec* stroke = newStrokeInfo.getStrokeRecPtr(); | 954 SkStrokeRec* stroke = newStrokeInfo.getStrokeRecPtr(); |
962 if (SkDashPath::FilterDashPath(effectPath.init(), path, stroke, NULL, in
fo)) { | 955 if (SkDashPath::FilterDashPath(effectPath.init(), path, stroke, NULL, in
fo)) { |
963 this->drawPath(rt, clip, paint, viewMatrix, *effectPath.get(), newSt
rokeInfo); | 956 this->drawPath(rt, paint, viewMatrix, *effectPath.get(), newStrokeIn
fo); |
964 return; | 957 return; |
965 } | 958 } |
966 | 959 |
967 this->drawPath(rt, clip, paint, viewMatrix, path, newStrokeInfo); | 960 this->drawPath(rt, paint, viewMatrix, path, newStrokeInfo); |
968 return; | 961 return; |
969 } | 962 } |
970 | 963 |
971 // Note that internalDrawPath may sw-rasterize the path into a scratch textu
re. | 964 // Note that internalDrawPath may sw-rasterize the path into a scratch textu
re. |
972 // Scratch textures can be recycled after they are returned to the texture | 965 // Scratch textures can be recycled after they are returned to the texture |
973 // cache. This presents a potential hazard for buffered drawing. However, | 966 // cache. This presents a potential hazard for buffered drawing. However, |
974 // the writePixels that uploads to the scratch will perform a flush so we're | 967 // the writePixels that uploads to the scratch will perform a flush so we're |
975 // OK. | 968 // OK. |
976 AutoCheckFlush acf(this); | 969 AutoCheckFlush acf(this); |
977 GrPipelineBuilder pipelineBuilder; | 970 GrPipelineBuilder pipelineBuilder; |
978 GrDrawTarget* target = this->prepareToDraw(&pipelineBuilder, rt, clip, &pain
t, &acf); | 971 GrDrawTarget* target = this->prepareToDraw(&pipelineBuilder, rt, &paint, &ac
f); |
979 if (NULL == target) { | 972 if (NULL == target) { |
980 return; | 973 return; |
981 } | 974 } |
982 | 975 |
983 GR_CREATE_TRACE_MARKER1("GrContext::drawPath", target, "Is Convex", path.isC
onvex()); | 976 GR_CREATE_TRACE_MARKER1("GrContext::drawPath", target, "Is Convex", path.isC
onvex()); |
984 | 977 |
985 const SkStrokeRec& strokeRec = strokeInfo.getStrokeRec(); | 978 const SkStrokeRec& strokeRec = strokeInfo.getStrokeRec(); |
986 | 979 |
987 bool useCoverageAA = paint.isAntiAlias() && | 980 bool useCoverageAA = paint.isAntiAlias() && |
988 !pipelineBuilder.getRenderTarget()->isMultisampled(); | 981 !pipelineBuilder.getRenderTarget()->isMultisampled(); |
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1197 } | 1190 } |
1198 | 1191 |
1199 SkMatrix matrix; | 1192 SkMatrix matrix; |
1200 matrix.setTranslate(SkIntToScalar(left), SkIntToScalar(top)); | 1193 matrix.setTranslate(SkIntToScalar(left), SkIntToScalar(top)); |
1201 | 1194 |
1202 // This function can be called in the midst of drawing another object (e.g.,
when uploading a | 1195 // This function can be called in the midst of drawing another object (e.g.,
when uploading a |
1203 // SW-rasterized clip while issuing a draw). So we push the current geometry
state before | 1196 // SW-rasterized clip while issuing a draw). So we push the current geometry
state before |
1204 // drawing a rect to the render target. | 1197 // drawing a rect to the render target. |
1205 // The bracket ensures we pop the stack if we wind up flushing below. | 1198 // The bracket ensures we pop the stack if we wind up flushing below. |
1206 { | 1199 { |
1207 GrDrawTarget* drawTarget = this->prepareToDraw(); | 1200 GrDrawTarget* drawTarget = this->prepareToDraw(NULL, NULL, NULL, NULL); |
1208 if (!drawTarget) { | |
1209 return false; | |
1210 } | |
1211 GrDrawTarget::AutoGeometryPush agp(drawTarget); | 1201 GrDrawTarget::AutoGeometryPush agp(drawTarget); |
1212 | 1202 |
1213 GrPipelineBuilder pipelineBuilder; | 1203 GrPipelineBuilder pipelineBuilder; |
1214 pipelineBuilder.addColorProcessor(fp); | 1204 pipelineBuilder.addColorProcessor(fp); |
1215 pipelineBuilder.setRenderTarget(renderTarget); | 1205 pipelineBuilder.setRenderTarget(renderTarget); |
1216 drawTarget->drawSimpleRect(&pipelineBuilder, | 1206 drawTarget->drawSimpleRect(&pipelineBuilder, |
1217 GrColor_WHITE, | 1207 GrColor_WHITE, |
1218 matrix, | 1208 matrix, |
1219 SkRect::MakeWH(SkIntToScalar(width), SkIntToS
calar(height))); | 1209 SkRect::MakeWH(SkIntToScalar(width), SkIntToS
calar(height))); |
1220 } | 1210 } |
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1386 GrRenderTarget* rt = surface->asRenderTarget(); | 1376 GrRenderTarget* rt = surface->asRenderTarget(); |
1387 if (fGpu && rt) { | 1377 if (fGpu && rt) { |
1388 fGpu->resolveRenderTarget(rt); | 1378 fGpu->resolveRenderTarget(rt); |
1389 } | 1379 } |
1390 } | 1380 } |
1391 | 1381 |
1392 void GrContext::discardRenderTarget(GrRenderTarget* renderTarget) { | 1382 void GrContext::discardRenderTarget(GrRenderTarget* renderTarget) { |
1393 SkASSERT(renderTarget); | 1383 SkASSERT(renderTarget); |
1394 ASSERT_OWNED_RESOURCE(renderTarget); | 1384 ASSERT_OWNED_RESOURCE(renderTarget); |
1395 AutoCheckFlush acf(this); | 1385 AutoCheckFlush acf(this); |
1396 GrDrawTarget* target = this->prepareToDraw(); | 1386 GrDrawTarget* target = this->prepareToDraw(NULL, NULL, NULL, NULL); |
1397 if (NULL == target) { | 1387 if (NULL == target) { |
1398 return; | 1388 return; |
1399 } | 1389 } |
1400 target->discard(renderTarget); | 1390 target->discard(renderTarget); |
1401 } | 1391 } |
1402 | 1392 |
1403 void GrContext::copySurface(GrSurface* dst, GrSurface* src, const SkIRect& srcRe
ct, | 1393 void GrContext::copySurface(GrSurface* dst, GrSurface* src, const SkIRect& srcRe
ct, |
1404 const SkIPoint& dstPoint, uint32_t pixelOpsFlags) { | 1394 const SkIPoint& dstPoint, uint32_t pixelOpsFlags) { |
1405 if (NULL == src || NULL == dst) { | 1395 if (NULL == src || NULL == dst) { |
1406 return; | 1396 return; |
1407 } | 1397 } |
1408 ASSERT_OWNED_RESOURCE(src); | 1398 ASSERT_OWNED_RESOURCE(src); |
1409 ASSERT_OWNED_RESOURCE(dst); | 1399 ASSERT_OWNED_RESOURCE(dst); |
1410 | 1400 |
1411 // Since we're going to the draw target and not GPU, no need to check kNoFlu
sh | 1401 // Since we're going to the draw target and not GPU, no need to check kNoFlu
sh |
1412 // here. | 1402 // here. |
1413 | 1403 |
1414 GrDrawTarget* target = this->prepareToDraw(); | 1404 GrDrawTarget* target = this->prepareToDraw(NULL, NULL, NULL, NULL); |
1415 if (NULL == target) { | 1405 if (NULL == target) { |
1416 return; | 1406 return; |
1417 } | 1407 } |
1418 target->copySurface(dst, src, srcRect, dstPoint); | 1408 target->copySurface(dst, src, srcRect, dstPoint); |
1419 | 1409 |
1420 if (kFlushWrites_PixelOp & pixelOpsFlags) { | 1410 if (kFlushWrites_PixelOp & pixelOpsFlags) { |
1421 this->flush(); | 1411 this->flush(); |
1422 } | 1412 } |
1423 } | 1413 } |
1424 | 1414 |
1425 void GrContext::flushSurfaceWrites(GrSurface* surface) { | 1415 void GrContext::flushSurfaceWrites(GrSurface* surface) { |
1426 if (surface->surfacePriv().hasPendingWrite()) { | 1416 if (surface->surfacePriv().hasPendingWrite()) { |
1427 this->flush(); | 1417 this->flush(); |
1428 } | 1418 } |
1429 } | 1419 } |
1430 | 1420 |
1431 GrDrawTarget* GrContext::prepareToDraw(GrPipelineBuilder* pipelineBuilder, | 1421 GrDrawTarget* GrContext::prepareToDraw(GrPipelineBuilder* pipelineBuilder, |
1432 GrRenderTarget* rt, | 1422 GrRenderTarget* rt, |
1433 const GrClip& clip, | |
1434 const GrPaint* paint, | 1423 const GrPaint* paint, |
1435 const AutoCheckFlush* acf) { | 1424 const AutoCheckFlush* acf) { |
1436 if (NULL == fGpu) { | 1425 if (NULL == fGpu) { |
1437 return NULL; | 1426 return NULL; |
1438 } | 1427 } |
1439 | 1428 |
1440 ASSERT_OWNED_RESOURCE(rt); | 1429 if (pipelineBuilder) { |
1441 SkASSERT(rt && paint && acf); | 1430 ASSERT_OWNED_RESOURCE(rt); |
1442 pipelineBuilder->setFromPaint(*paint, rt, clip); | 1431 SkASSERT(rt && paint && acf); |
1443 return fDrawBuffer; | 1432 pipelineBuilder->setFromPaint(*paint, rt, fClip); |
1444 } | |
1445 | |
1446 GrDrawTarget* GrContext::prepareToDraw() { | |
1447 if (NULL == fGpu) { | |
1448 return NULL; | |
1449 } | 1433 } |
1450 return fDrawBuffer; | 1434 return fDrawBuffer; |
1451 } | 1435 } |
1452 | 1436 |
1453 /* | 1437 /* |
1454 * This method finds a path renderer that can draw the specified path on | 1438 * This method finds a path renderer that can draw the specified path on |
1455 * the provided target. | 1439 * the provided target. |
1456 * Due to its expense, the software path renderer has split out so it can | 1440 * Due to its expense, the software path renderer has split out so it can |
1457 * can be individually allowed/disallowed via the "allowSW" boolean. | 1441 * can be individually allowed/disallowed via the "allowSW" boolean. |
1458 */ | 1442 */ |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1522 SkNEW_ARGS(GrIndexBufferAllocPool, (fGpu, false, | 1506 SkNEW_ARGS(GrIndexBufferAllocPool, (fGpu, false, |
1523 DRAW_BUFFER_IBPOOL_BUFFER_SIZE, | 1507 DRAW_BUFFER_IBPOOL_BUFFER_SIZE, |
1524 DRAW_BUFFER_IBPOOL_PREALLOC_BUFFERS)); | 1508 DRAW_BUFFER_IBPOOL_PREALLOC_BUFFERS)); |
1525 | 1509 |
1526 fDrawBuffer = SkNEW_ARGS(GrInOrderDrawBuffer, (fGpu, | 1510 fDrawBuffer = SkNEW_ARGS(GrInOrderDrawBuffer, (fGpu, |
1527 fDrawBufferVBAllocPool, | 1511 fDrawBufferVBAllocPool, |
1528 fDrawBufferIBAllocPool)); | 1512 fDrawBufferIBAllocPool)); |
1529 } | 1513 } |
1530 | 1514 |
1531 GrDrawTarget* GrContext::getTextTarget() { | 1515 GrDrawTarget* GrContext::getTextTarget() { |
1532 return this->prepareToDraw(); | 1516 return this->prepareToDraw(NULL, NULL, NULL, NULL); |
1533 } | 1517 } |
1534 | 1518 |
1535 const GrIndexBuffer* GrContext::getQuadIndexBuffer() const { | 1519 const GrIndexBuffer* GrContext::getQuadIndexBuffer() const { |
1536 return fGpu->getQuadIndexBuffer(); | 1520 return fGpu->getQuadIndexBuffer(); |
1537 } | 1521 } |
1538 | 1522 |
1539 namespace { | 1523 namespace { |
1540 void test_pm_conversions(GrContext* ctx, int* pmToUPMValue, int* upmToPMValue) { | 1524 void test_pm_conversions(GrContext* ctx, int* pmToUPMValue, int* upmToPMValue) { |
1541 GrConfigConversionEffect::PMConversion pmToUPM; | 1525 GrConfigConversionEffect::PMConversion pmToUPM; |
1542 GrConfigConversionEffect::PMConversion upmToPM; | 1526 GrConfigConversionEffect::PMConversion upmToPM; |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1618 } | 1602 } |
1619 } | 1603 } |
1620 | 1604 |
1621 void GrContext::removeGpuTraceMarker(const GrGpuTraceMarker* marker) { | 1605 void GrContext::removeGpuTraceMarker(const GrGpuTraceMarker* marker) { |
1622 fGpu->removeGpuTraceMarker(marker); | 1606 fGpu->removeGpuTraceMarker(marker); |
1623 if (fDrawBuffer) { | 1607 if (fDrawBuffer) { |
1624 fDrawBuffer->removeGpuTraceMarker(marker); | 1608 fDrawBuffer->removeGpuTraceMarker(marker); |
1625 } | 1609 } |
1626 } | 1610 } |
1627 | 1611 |
OLD | NEW |