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