Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(55)

Side by Side Diff: src/gpu/GrContext.cpp

Issue 939623005: Pass Rendertarget into context (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: sampleapp Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/gpu/GrBitmapTextContext.cpp ('k') | src/gpu/GrDistanceFieldTextContext.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 365 matching lines...) Expand 10 before | Expand all | Expand 10 after
376 376
377 void GrContext::clear(const SkIRect* rect, 377 void GrContext::clear(const SkIRect* rect,
378 const GrColor color, 378 const GrColor color,
379 bool canIgnoreRect, 379 bool canIgnoreRect,
380 GrRenderTarget* renderTarget) { 380 GrRenderTarget* renderTarget) {
381 ASSERT_OWNED_RESOURCE(renderTarget); 381 ASSERT_OWNED_RESOURCE(renderTarget);
382 SkASSERT(renderTarget); 382 SkASSERT(renderTarget);
383 383
384 AutoCheckFlush acf(this); 384 AutoCheckFlush acf(this);
385 GR_CREATE_TRACE_MARKER_CONTEXT("GrContext::clear", this); 385 GR_CREATE_TRACE_MARKER_CONTEXT("GrContext::clear", this);
386 GrDrawTarget* target = this->prepareToDraw(NULL, NULL, &acf); 386 GrDrawTarget* target = this->prepareToDraw(NULL, renderTarget, NULL, &acf);
387 if (NULL == target) { 387 if (NULL == target) {
388 return; 388 return;
389 } 389 }
390 target->clear(rect, color, canIgnoreRect, renderTarget); 390 target->clear(rect, color, canIgnoreRect, renderTarget);
391 } 391 }
392 392
393 void GrContext::drawPaint(const GrPaint& origPaint, const SkMatrix& viewMatrix) { 393 void GrContext::drawPaint(GrRenderTarget* rt,
394 const GrPaint& origPaint,
395 const SkMatrix& viewMatrix) {
394 // set rect to be big enough to fill the space, but not super-huge, so we 396 // set rect to be big enough to fill the space, but not super-huge, so we
395 // don't overflow fixed-point implementations 397 // don't overflow fixed-point implementations
396 SkRect r; 398 SkRect r;
397 r.setLTRB(0, 0, 399 r.setLTRB(0, 0,
398 SkIntToScalar(getRenderTarget()->width()), 400 SkIntToScalar(rt->width()),
399 SkIntToScalar(getRenderTarget()->height())); 401 SkIntToScalar(rt->height()));
400 SkTCopyOnFirstWrite<GrPaint> paint(origPaint); 402 SkTCopyOnFirstWrite<GrPaint> paint(origPaint);
401 403
402 // by definition this fills the entire clip, no need for AA 404 // by definition this fills the entire clip, no need for AA
403 if (paint->isAntiAlias()) { 405 if (paint->isAntiAlias()) {
404 paint.writable()->setAntiAlias(false); 406 paint.writable()->setAntiAlias(false);
405 } 407 }
406 408
407 bool isPerspective = viewMatrix.hasPerspective(); 409 bool isPerspective = viewMatrix.hasPerspective();
408 410
409 // We attempt to map r by the inverse matrix and draw that. mapRect will 411 // We attempt to map r by the inverse matrix and draw that. mapRect will
410 // map the four corners and bound them with a new rect. This will not 412 // map the four corners and bound them with a new rect. This will not
411 // produce a correct result for some perspective matrices. 413 // produce a correct result for some perspective matrices.
412 if (!isPerspective) { 414 if (!isPerspective) {
413 SkMatrix inverse; 415 SkMatrix inverse;
414 if (!viewMatrix.invert(&inverse)) { 416 if (!viewMatrix.invert(&inverse)) {
415 SkDebugf("Could not invert matrix\n"); 417 SkDebugf("Could not invert matrix\n");
416 return; 418 return;
417 } 419 }
418 inverse.mapRect(&r); 420 inverse.mapRect(&r);
419 this->drawRect(*paint, viewMatrix, r); 421 this->drawRect(rt, *paint, viewMatrix, r);
420 } else { 422 } else {
421 SkMatrix localMatrix; 423 SkMatrix localMatrix;
422 if (!viewMatrix.invert(&localMatrix)) { 424 if (!viewMatrix.invert(&localMatrix)) {
423 SkDebugf("Could not invert matrix\n"); 425 SkDebugf("Could not invert matrix\n");
424 return; 426 return;
425 } 427 }
426 428
427 AutoCheckFlush acf(this); 429 AutoCheckFlush acf(this);
428 GrPipelineBuilder pipelineBuilder; 430 GrPipelineBuilder pipelineBuilder;
429 GrDrawTarget* target = this->prepareToDraw(&pipelineBuilder, paint, &acf ); 431 GrDrawTarget* target = this->prepareToDraw(&pipelineBuilder, rt, paint, &acf);
430 if (NULL == target) { 432 if (NULL == target) {
431 return; 433 return;
432 } 434 }
433 435
434 GR_CREATE_TRACE_MARKER("GrContext::drawPaintWithPerspective", target); 436 GR_CREATE_TRACE_MARKER("GrContext::drawPaintWithPerspective", target);
435 target->drawRect(&pipelineBuilder, paint->getColor(), SkMatrix::I(), r, NULL, &localMatrix); 437 target->drawRect(&pipelineBuilder, paint->getColor(), SkMatrix::I(), r, NULL, &localMatrix);
436 } 438 }
437 } 439 }
438 440
439 #ifdef SK_DEVELOPER 441 #ifdef SK_DEVELOPER
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
515 } 517 }
516 518
517 return true; 519 return true;
518 } 520 }
519 521
520 static inline bool rect_contains_inclusive(const SkRect& rect, const SkPoint& po int) { 522 static inline bool rect_contains_inclusive(const SkRect& rect, const SkPoint& po int) {
521 return point.fX >= rect.fLeft && point.fX <= rect.fRight && 523 return point.fX >= rect.fLeft && point.fX <= rect.fRight &&
522 point.fY >= rect.fTop && point.fY <= rect.fBottom; 524 point.fY >= rect.fTop && point.fY <= rect.fBottom;
523 } 525 }
524 526
525 void GrContext::drawRect(const GrPaint& paint, 527 void GrContext::drawRect(GrRenderTarget* rt,
528 const GrPaint& paint,
526 const SkMatrix& viewMatrix, 529 const SkMatrix& viewMatrix,
527 const SkRect& rect, 530 const SkRect& rect,
528 const GrStrokeInfo* strokeInfo) { 531 const GrStrokeInfo* strokeInfo) {
529 if (strokeInfo && strokeInfo->isDashed()) { 532 if (strokeInfo && strokeInfo->isDashed()) {
530 SkPath path; 533 SkPath path;
531 path.addRect(rect); 534 path.addRect(rect);
532 this->drawPath(paint, viewMatrix, path, *strokeInfo); 535 this->drawPath(rt, paint, viewMatrix, path, *strokeInfo);
533 return; 536 return;
534 } 537 }
535 538
536 AutoCheckFlush acf(this); 539 AutoCheckFlush acf(this);
537 GrPipelineBuilder pipelineBuilder; 540 GrPipelineBuilder pipelineBuilder;
538 GrDrawTarget* target = this->prepareToDraw(&pipelineBuilder, &paint, &acf); 541 GrDrawTarget* target = this->prepareToDraw(&pipelineBuilder, rt, &paint, &ac f);
539 if (NULL == target) { 542 if (NULL == target) {
540 return; 543 return;
541 } 544 }
542 545
543 GR_CREATE_TRACE_MARKER("GrContext::drawRect", target); 546 GR_CREATE_TRACE_MARKER("GrContext::drawRect", target);
544 SkScalar width = NULL == strokeInfo ? -1 : strokeInfo->getStrokeRec().getWid th(); 547 SkScalar width = NULL == strokeInfo ? -1 : strokeInfo->getStrokeRec().getWid th();
545 548
546 // Check if this is a full RT draw and can be replaced with a clear. We don' t bother checking 549 // Check if this is a full RT draw and can be replaced with a clear. We don' t bother checking
547 // cases where the RT is fully inside a stroke. 550 // cases where the RT is fully inside a stroke.
548 if (width < 0) { 551 if (width < 0) {
(...skipping 15 matching lines...) Expand all
564 // Does the rect bound the RT? 567 // Does the rect bound the RT?
565 SkPoint srcSpaceRTQuad[4]; 568 SkPoint srcSpaceRTQuad[4];
566 invM.mapRectToQuad(srcSpaceRTQuad, rtRect); 569 invM.mapRectToQuad(srcSpaceRTQuad, rtRect);
567 if (rect_contains_inclusive(rect, srcSpaceRTQuad[0]) && 570 if (rect_contains_inclusive(rect, srcSpaceRTQuad[0]) &&
568 rect_contains_inclusive(rect, srcSpaceRTQuad[1]) && 571 rect_contains_inclusive(rect, srcSpaceRTQuad[1]) &&
569 rect_contains_inclusive(rect, srcSpaceRTQuad[2]) && 572 rect_contains_inclusive(rect, srcSpaceRTQuad[2]) &&
570 rect_contains_inclusive(rect, srcSpaceRTQuad[3])) { 573 rect_contains_inclusive(rect, srcSpaceRTQuad[3])) {
571 // Will it blend? 574 // Will it blend?
572 GrColor clearColor; 575 GrColor clearColor;
573 if (paint.isOpaqueAndConstantColor(&clearColor)) { 576 if (paint.isOpaqueAndConstantColor(&clearColor)) {
574 target->clear(NULL, clearColor, true, fRenderTarget); 577 target->clear(NULL, clearColor, true, rt);
575 return; 578 return;
576 } 579 }
577 } 580 }
578 } 581 }
579 } 582 }
580 583
581 GrColor color = paint.getColor(); 584 GrColor color = paint.getColor();
582 SkRect devBoundRect; 585 SkRect devBoundRect;
583 bool needAA = paint.isAntiAlias() && !pipelineBuilder.getRenderTarget()->isM ultisampled(); 586 bool needAA = paint.isAntiAlias() && !pipelineBuilder.getRenderTarget()->isM ultisampled();
584 bool doAA = needAA && apply_aa_to_rect(target, &pipelineBuilder, &devBoundRe ct, rect, width, 587 bool doAA = needAA && apply_aa_to_rect(target, &pipelineBuilder, &devBoundRe ct, rect, width,
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
647 vertex[4].set(rect.fLeft, rect.fTop); 650 vertex[4].set(rect.fLeft, rect.fTop);
648 } 651 }
649 652
650 target->drawNonIndexed(&pipelineBuilder, gp, primType, 0, vertCount); 653 target->drawNonIndexed(&pipelineBuilder, gp, primType, 0, vertCount);
651 } else { 654 } else {
652 // filled BW rect 655 // filled BW rect
653 target->drawSimpleRect(&pipelineBuilder, color, viewMatrix, rect); 656 target->drawSimpleRect(&pipelineBuilder, color, viewMatrix, rect);
654 } 657 }
655 } 658 }
656 659
657 void GrContext::drawNonAARectToRect(const GrPaint& paint, 660 void GrContext::drawNonAARectToRect(GrRenderTarget* rt,
661 const GrPaint& paint,
658 const SkMatrix& viewMatrix, 662 const SkMatrix& viewMatrix,
659 const SkRect& rectToDraw, 663 const SkRect& rectToDraw,
660 const SkRect& localRect, 664 const SkRect& localRect,
661 const SkMatrix* localMatrix) { 665 const SkMatrix* localMatrix) {
662 AutoCheckFlush acf(this); 666 AutoCheckFlush acf(this);
663 GrPipelineBuilder pipelineBuilder; 667 GrPipelineBuilder pipelineBuilder;
664 GrDrawTarget* target = this->prepareToDraw(&pipelineBuilder, &paint, &acf); 668 GrDrawTarget* target = this->prepareToDraw(&pipelineBuilder, rt, &paint, &ac f);
665 if (NULL == target) { 669 if (NULL == target) {
666 return; 670 return;
667 } 671 }
668 672
669 GR_CREATE_TRACE_MARKER("GrContext::drawRectToRect", target); 673 GR_CREATE_TRACE_MARKER("GrContext::drawRectToRect", target);
670 674
671 target->drawRect(&pipelineBuilder, paint.getColor(), viewMatrix, rectToDraw, &localRect, 675 target->drawRect(&pipelineBuilder, paint.getColor(), viewMatrix, rectToDraw, &localRect,
672 localMatrix); 676 localMatrix);
673 } 677 }
674 678
(...skipping 14 matching lines...) Expand all
689 } else if (texCoords) { 693 } else if (texCoords) {
690 *texOffset = sizeof(SkPoint); 694 *texOffset = sizeof(SkPoint);
691 flags |= GrDefaultGeoProcFactory::kLocalCoord_GPType; 695 flags |= GrDefaultGeoProcFactory::kLocalCoord_GPType;
692 } else if (colors) { 696 } else if (colors) {
693 *colorOffset = sizeof(SkPoint); 697 *colorOffset = sizeof(SkPoint);
694 flags |= GrDefaultGeoProcFactory::kColor_GPType; 698 flags |= GrDefaultGeoProcFactory::kColor_GPType;
695 } 699 }
696 return GrDefaultGeoProcFactory::Create(flags, color, viewMatrix, SkMatrix::I ()); 700 return GrDefaultGeoProcFactory::Create(flags, color, viewMatrix, SkMatrix::I ());
697 } 701 }
698 702
699 void GrContext::drawVertices(const GrPaint& paint, 703 void GrContext::drawVertices(GrRenderTarget* rt,
704 const GrPaint& paint,
700 const SkMatrix& viewMatrix, 705 const SkMatrix& viewMatrix,
701 GrPrimitiveType primitiveType, 706 GrPrimitiveType primitiveType,
702 int vertexCount, 707 int vertexCount,
703 const SkPoint positions[], 708 const SkPoint positions[],
704 const SkPoint texCoords[], 709 const SkPoint texCoords[],
705 const GrColor colors[], 710 const GrColor colors[],
706 const uint16_t indices[], 711 const uint16_t indices[],
707 int indexCount) { 712 int indexCount) {
708 AutoCheckFlush acf(this); 713 AutoCheckFlush acf(this);
709 GrPipelineBuilder pipelineBuilder; 714 GrPipelineBuilder pipelineBuilder;
710 GrDrawTarget::AutoReleaseGeometry geo; // must be inside AutoCheckFlush scop e 715 GrDrawTarget::AutoReleaseGeometry geo; // must be inside AutoCheckFlush scop e
711 716
712 GrDrawTarget* target = this->prepareToDraw(&pipelineBuilder, &paint, &acf); 717 GrDrawTarget* target = this->prepareToDraw(&pipelineBuilder, rt, &paint, &ac f);
713 if (NULL == target) { 718 if (NULL == target) {
714 return; 719 return;
715 } 720 }
716 721
717 GR_CREATE_TRACE_MARKER("GrContext::drawVertices", target); 722 GR_CREATE_TRACE_MARKER("GrContext::drawVertices", target);
718 723
719 int colorOffset = -1, texOffset = -1; 724 int colorOffset = -1, texOffset = -1;
720 SkAutoTUnref<const GrGeometryProcessor> gp( 725 SkAutoTUnref<const GrGeometryProcessor> gp(
721 set_vertex_attributes(texCoords, colors, &colorOffset, &texOffset, 726 set_vertex_attributes(texCoords, colors, &colorOffset, &texOffset,
722 paint.getColor(), viewMatrix)); 727 paint.getColor(), viewMatrix));
(...skipping 27 matching lines...) Expand all
750 curIndex[i] = indices[i]; 755 curIndex[i] = indices[i];
751 } 756 }
752 target->drawIndexed(&pipelineBuilder, gp, primitiveType, 0, 0, vertexCou nt, indexCount); 757 target->drawIndexed(&pipelineBuilder, gp, primitiveType, 0, 0, vertexCou nt, indexCount);
753 } else { 758 } else {
754 target->drawNonIndexed(&pipelineBuilder, gp, primitiveType, 0, vertexCou nt); 759 target->drawNonIndexed(&pipelineBuilder, gp, primitiveType, 0, vertexCou nt);
755 } 760 }
756 } 761 }
757 762
758 /////////////////////////////////////////////////////////////////////////////// 763 ///////////////////////////////////////////////////////////////////////////////
759 764
760 void GrContext::drawRRect(const GrPaint& paint, 765 void GrContext::drawRRect(GrRenderTarget*rt,
766 const GrPaint& paint,
761 const SkMatrix& viewMatrix, 767 const SkMatrix& viewMatrix,
762 const SkRRect& rrect, 768 const SkRRect& rrect,
763 const GrStrokeInfo& strokeInfo) { 769 const GrStrokeInfo& strokeInfo) {
764 if (rrect.isEmpty()) { 770 if (rrect.isEmpty()) {
765 return; 771 return;
766 } 772 }
767 773
768 if (strokeInfo.isDashed()) { 774 if (strokeInfo.isDashed()) {
769 SkPath path; 775 SkPath path;
770 path.addRRect(rrect); 776 path.addRRect(rrect);
771 this->drawPath(paint, viewMatrix, path, strokeInfo); 777 this->drawPath(rt, paint, viewMatrix, path, strokeInfo);
772 return; 778 return;
773 } 779 }
774 780
775 AutoCheckFlush acf(this); 781 AutoCheckFlush acf(this);
776 GrPipelineBuilder pipelineBuilder; 782 GrPipelineBuilder pipelineBuilder;
777 GrDrawTarget* target = this->prepareToDraw(&pipelineBuilder, &paint, &acf); 783 GrDrawTarget* target = this->prepareToDraw(&pipelineBuilder, rt, &paint, &ac f);
778 if (NULL == target) { 784 if (NULL == target) {
779 return; 785 return;
780 } 786 }
781 787
782 GR_CREATE_TRACE_MARKER("GrContext::drawRRect", target); 788 GR_CREATE_TRACE_MARKER("GrContext::drawRRect", target);
783 789
784 const SkStrokeRec& strokeRec = strokeInfo.getStrokeRec(); 790 const SkStrokeRec& strokeRec = strokeInfo.getStrokeRec();
785 791
786 GrColor color = paint.getColor(); 792 GrColor color = paint.getColor();
787 if (!fOvalRenderer->drawRRect(target, &pipelineBuilder, color, viewMatrix, p aint.isAntiAlias(), 793 if (!fOvalRenderer->drawRRect(target, &pipelineBuilder, color, viewMatrix, p aint.isAntiAlias(),
788 rrect, strokeRec)) { 794 rrect, strokeRec)) {
789 SkPath path; 795 SkPath path;
790 path.addRRect(rrect); 796 path.addRRect(rrect);
791 this->internalDrawPath(target, &pipelineBuilder, viewMatrix, color, pain t.isAntiAlias(), 797 this->internalDrawPath(target, &pipelineBuilder, viewMatrix, color, pain t.isAntiAlias(),
792 path, strokeInfo); 798 path, strokeInfo);
793 } 799 }
794 } 800 }
795 801
796 /////////////////////////////////////////////////////////////////////////////// 802 ///////////////////////////////////////////////////////////////////////////////
797 803
798 void GrContext::drawDRRect(const GrPaint& paint, 804 void GrContext::drawDRRect(GrRenderTarget* rt,
805 const GrPaint& paint,
799 const SkMatrix& viewMatrix, 806 const SkMatrix& viewMatrix,
800 const SkRRect& outer, 807 const SkRRect& outer,
801 const SkRRect& inner) { 808 const SkRRect& inner) {
802 if (outer.isEmpty()) { 809 if (outer.isEmpty()) {
803 return; 810 return;
804 } 811 }
805 812
806 AutoCheckFlush acf(this); 813 AutoCheckFlush acf(this);
807 GrPipelineBuilder pipelineBuilder; 814 GrPipelineBuilder pipelineBuilder;
808 GrDrawTarget* target = this->prepareToDraw(&pipelineBuilder, &paint, &acf); 815 GrDrawTarget* target = this->prepareToDraw(&pipelineBuilder, rt, &paint, &ac f);
809 816
810 GR_CREATE_TRACE_MARKER("GrContext::drawDRRect", target); 817 GR_CREATE_TRACE_MARKER("GrContext::drawDRRect", target);
811 818
812 GrColor color = paint.getColor(); 819 GrColor color = paint.getColor();
813 if (!fOvalRenderer->drawDRRect(target, &pipelineBuilder, color, viewMatrix, paint.isAntiAlias(), 820 if (!fOvalRenderer->drawDRRect(target, &pipelineBuilder, color, viewMatrix, paint.isAntiAlias(),
814 outer, inner)) { 821 outer, inner)) {
815 SkPath path; 822 SkPath path;
816 path.addRRect(inner); 823 path.addRRect(inner);
817 path.addRRect(outer); 824 path.addRRect(outer);
818 path.setFillType(SkPath::kEvenOdd_FillType); 825 path.setFillType(SkPath::kEvenOdd_FillType);
819 826
820 GrStrokeInfo fillRec(SkStrokeRec::kFill_InitStyle); 827 GrStrokeInfo fillRec(SkStrokeRec::kFill_InitStyle);
821 this->internalDrawPath(target, &pipelineBuilder, viewMatrix, color, pain t.isAntiAlias(), 828 this->internalDrawPath(target, &pipelineBuilder, viewMatrix, color, pain t.isAntiAlias(),
822 path, fillRec); 829 path, fillRec);
823 } 830 }
824 } 831 }
825 832
826 /////////////////////////////////////////////////////////////////////////////// 833 ///////////////////////////////////////////////////////////////////////////////
827 834
828 void GrContext::drawOval(const GrPaint& paint, 835 void GrContext::drawOval(GrRenderTarget*rt,
836 const GrPaint& paint,
829 const SkMatrix& viewMatrix, 837 const SkMatrix& viewMatrix,
830 const SkRect& oval, 838 const SkRect& oval,
831 const GrStrokeInfo& strokeInfo) { 839 const GrStrokeInfo& strokeInfo) {
832 if (oval.isEmpty()) { 840 if (oval.isEmpty()) {
833 return; 841 return;
834 } 842 }
835 843
836 if (strokeInfo.isDashed()) { 844 if (strokeInfo.isDashed()) {
837 SkPath path; 845 SkPath path;
838 path.addOval(oval); 846 path.addOval(oval);
839 this->drawPath(paint, viewMatrix, path, strokeInfo); 847 this->drawPath(rt, paint, viewMatrix, path, strokeInfo);
840 return; 848 return;
841 } 849 }
842 850
843 AutoCheckFlush acf(this); 851 AutoCheckFlush acf(this);
844 GrPipelineBuilder pipelineBuilder; 852 GrPipelineBuilder pipelineBuilder;
845 GrDrawTarget* target = this->prepareToDraw(&pipelineBuilder, &paint, &acf); 853 GrDrawTarget* target = this->prepareToDraw(&pipelineBuilder, rt, &paint, &ac f);
846 if (NULL == target) { 854 if (NULL == target) {
847 return; 855 return;
848 } 856 }
849 857
850 GR_CREATE_TRACE_MARKER("GrContext::drawOval", target); 858 GR_CREATE_TRACE_MARKER("GrContext::drawOval", target);
851 859
852 const SkStrokeRec& strokeRec = strokeInfo.getStrokeRec(); 860 const SkStrokeRec& strokeRec = strokeInfo.getStrokeRec();
853 861
854 GrColor color = paint.getColor(); 862 GrColor color = paint.getColor();
855 if (!fOvalRenderer->drawOval(target, &pipelineBuilder, color, viewMatrix, pa int.isAntiAlias(), 863 if (!fOvalRenderer->drawOval(target, &pipelineBuilder, color, viewMatrix, pa int.isAntiAlias(),
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
912 allGoE1 = false; 920 allGoE1 = false;
913 } 921 }
914 if (!SkScalarNearlyEqual(margin, temp)) { 922 if (!SkScalarNearlyEqual(margin, temp)) {
915 allEq = false; 923 allEq = false;
916 } 924 }
917 } 925 }
918 926
919 return allEq || allGoE1; 927 return allEq || allGoE1;
920 } 928 }
921 929
922 void GrContext::drawPath(const GrPaint& paint, 930 void GrContext::drawPath(GrRenderTarget* rt,
931 const GrPaint& paint,
923 const SkMatrix& viewMatrix, 932 const SkMatrix& viewMatrix,
924 const SkPath& path, 933 const SkPath& path,
925 const GrStrokeInfo& strokeInfo) { 934 const GrStrokeInfo& strokeInfo) {
926 935
927 if (path.isEmpty()) { 936 if (path.isEmpty()) {
928 if (path.isInverseFillType()) { 937 if (path.isInverseFillType()) {
929 this->drawPaint(paint, viewMatrix); 938 this->drawPaint(rt, paint, viewMatrix);
930 } 939 }
931 return; 940 return;
932 } 941 }
933 942
934 GrColor color = paint.getColor(); 943 GrColor color = paint.getColor();
935 if (strokeInfo.isDashed()) { 944 if (strokeInfo.isDashed()) {
936 SkPoint pts[2]; 945 SkPoint pts[2];
937 if (path.isLine(pts)) { 946 if (path.isLine(pts)) {
938 AutoCheckFlush acf(this); 947 AutoCheckFlush acf(this);
939 GrPipelineBuilder pipelineBuilder; 948 GrPipelineBuilder pipelineBuilder;
940 GrDrawTarget* target = this->prepareToDraw(&pipelineBuilder, &paint, &acf); 949 GrDrawTarget* target = this->prepareToDraw(&pipelineBuilder, rt, &pa int, &acf);
941 if (NULL == target) { 950 if (NULL == target) {
942 return; 951 return;
943 } 952 }
944 953
945 if (GrDashingEffect::DrawDashLine(fGpu, target, &pipelineBuilder, co lor, viewMatrix, 954 if (GrDashingEffect::DrawDashLine(fGpu, target, &pipelineBuilder, co lor, viewMatrix,
946 pts, paint, strokeInfo)) { 955 pts, paint, strokeInfo)) {
947 return; 956 return;
948 } 957 }
949 } 958 }
950 959
951 // Filter dashed path into new path with the dashing applied 960 // Filter dashed path into new path with the dashing applied
952 const SkPathEffect::DashInfo& info = strokeInfo.getDashInfo(); 961 const SkPathEffect::DashInfo& info = strokeInfo.getDashInfo();
953 SkTLazy<SkPath> effectPath; 962 SkTLazy<SkPath> effectPath;
954 GrStrokeInfo newStrokeInfo(strokeInfo, false); 963 GrStrokeInfo newStrokeInfo(strokeInfo, false);
955 SkStrokeRec* stroke = newStrokeInfo.getStrokeRecPtr(); 964 SkStrokeRec* stroke = newStrokeInfo.getStrokeRecPtr();
956 if (SkDashPath::FilterDashPath(effectPath.init(), path, stroke, NULL, in fo)) { 965 if (SkDashPath::FilterDashPath(effectPath.init(), path, stroke, NULL, in fo)) {
957 this->drawPath(paint, viewMatrix, *effectPath.get(), newStrokeInfo); 966 this->drawPath(rt, paint, viewMatrix, *effectPath.get(), newStrokeIn fo);
958 return; 967 return;
959 } 968 }
960 969
961 this->drawPath(paint, viewMatrix, path, newStrokeInfo); 970 this->drawPath(rt, paint, viewMatrix, path, newStrokeInfo);
962 return; 971 return;
963 } 972 }
964 973
965 // Note that internalDrawPath may sw-rasterize the path into a scratch textu re. 974 // Note that internalDrawPath may sw-rasterize the path into a scratch textu re.
966 // Scratch textures can be recycled after they are returned to the texture 975 // Scratch textures can be recycled after they are returned to the texture
967 // cache. This presents a potential hazard for buffered drawing. However, 976 // cache. This presents a potential hazard for buffered drawing. However,
968 // the writePixels that uploads to the scratch will perform a flush so we're 977 // the writePixels that uploads to the scratch will perform a flush so we're
969 // OK. 978 // OK.
970 AutoCheckFlush acf(this); 979 AutoCheckFlush acf(this);
971 GrPipelineBuilder pipelineBuilder; 980 GrPipelineBuilder pipelineBuilder;
972 GrDrawTarget* target = this->prepareToDraw(&pipelineBuilder, &paint, &acf); 981 GrDrawTarget* target = this->prepareToDraw(&pipelineBuilder, rt, &paint, &ac f);
973 if (NULL == target) { 982 if (NULL == target) {
974 return; 983 return;
975 } 984 }
976 985
977 GR_CREATE_TRACE_MARKER1("GrContext::drawPath", target, "Is Convex", path.isC onvex()); 986 GR_CREATE_TRACE_MARKER1("GrContext::drawPath", target, "Is Convex", path.isC onvex());
978 987
979 const SkStrokeRec& strokeRec = strokeInfo.getStrokeRec(); 988 const SkStrokeRec& strokeRec = strokeInfo.getStrokeRec();
980 989
981 bool useCoverageAA = paint.isAntiAlias() && 990 bool useCoverageAA = paint.isAntiAlias() &&
982 !pipelineBuilder.getRenderTarget()->isMultisampled(); 991 !pipelineBuilder.getRenderTarget()->isMultisampled();
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after
1187 } 1196 }
1188 1197
1189 SkMatrix matrix; 1198 SkMatrix matrix;
1190 matrix.setTranslate(SkIntToScalar(left), SkIntToScalar(top)); 1199 matrix.setTranslate(SkIntToScalar(left), SkIntToScalar(top));
1191 1200
1192 // This function can be called in the midst of drawing another object (e.g., when uploading a 1201 // This function can be called in the midst of drawing another object (e.g., when uploading a
1193 // SW-rasterized clip while issuing a draw). So we push the current geometry state before 1202 // SW-rasterized clip while issuing a draw). So we push the current geometry state before
1194 // drawing a rect to the render target. 1203 // drawing a rect to the render target.
1195 // The bracket ensures we pop the stack if we wind up flushing below. 1204 // The bracket ensures we pop the stack if we wind up flushing below.
1196 { 1205 {
1197 GrDrawTarget* drawTarget = this->prepareToDraw(NULL, NULL, NULL); 1206 GrDrawTarget* drawTarget = this->prepareToDraw(NULL, NULL, NULL, NULL);
1198 GrDrawTarget::AutoGeometryPush agp(drawTarget); 1207 GrDrawTarget::AutoGeometryPush agp(drawTarget);
1199 1208
1200 GrPipelineBuilder pipelineBuilder; 1209 GrPipelineBuilder pipelineBuilder;
1201 pipelineBuilder.addColorProcessor(fp); 1210 pipelineBuilder.addColorProcessor(fp);
1202 pipelineBuilder.setRenderTarget(renderTarget); 1211 pipelineBuilder.setRenderTarget(renderTarget);
1203 drawTarget->drawSimpleRect(&pipelineBuilder, GrColor_WHITE, matrix, 1212 drawTarget->drawSimpleRect(&pipelineBuilder, GrColor_WHITE, matrix,
1204 SkRect::MakeWH(SkIntToScalar(width), SkIntToS calar(height))); 1213 SkRect::MakeWH(SkIntToScalar(width), SkIntToS calar(height)));
1205 } 1214 }
1206 1215
1207 if (kFlushWrites_PixelOp & pixelOpsFlags) { 1216 if (kFlushWrites_PixelOp & pixelOpsFlags) {
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
1369 GrRenderTarget* rt = surface->asRenderTarget(); 1378 GrRenderTarget* rt = surface->asRenderTarget();
1370 if (fGpu && rt) { 1379 if (fGpu && rt) {
1371 fGpu->resolveRenderTarget(rt); 1380 fGpu->resolveRenderTarget(rt);
1372 } 1381 }
1373 } 1382 }
1374 1383
1375 void GrContext::discardRenderTarget(GrRenderTarget* renderTarget) { 1384 void GrContext::discardRenderTarget(GrRenderTarget* renderTarget) {
1376 SkASSERT(renderTarget); 1385 SkASSERT(renderTarget);
1377 ASSERT_OWNED_RESOURCE(renderTarget); 1386 ASSERT_OWNED_RESOURCE(renderTarget);
1378 AutoCheckFlush acf(this); 1387 AutoCheckFlush acf(this);
1379 GrDrawTarget* target = this->prepareToDraw(NULL, NULL, &acf); 1388 GrDrawTarget* target = this->prepareToDraw(NULL, NULL, NULL, NULL);
1380 if (NULL == target) { 1389 if (NULL == target) {
1381 return; 1390 return;
1382 } 1391 }
1383 target->discard(renderTarget); 1392 target->discard(renderTarget);
1384 } 1393 }
1385 1394
1386 void GrContext::copySurface(GrSurface* dst, GrSurface* src, const SkIRect& srcRe ct, 1395 void GrContext::copySurface(GrSurface* dst, GrSurface* src, const SkIRect& srcRe ct,
1387 const SkIPoint& dstPoint, uint32_t pixelOpsFlags) { 1396 const SkIPoint& dstPoint, uint32_t pixelOpsFlags) {
1388 if (NULL == src || NULL == dst) { 1397 if (NULL == src || NULL == dst) {
1389 return; 1398 return;
1390 } 1399 }
1391 ASSERT_OWNED_RESOURCE(src); 1400 ASSERT_OWNED_RESOURCE(src);
1392 ASSERT_OWNED_RESOURCE(dst); 1401 ASSERT_OWNED_RESOURCE(dst);
1393 1402
1394 // Since we're going to the draw target and not GPU, no need to check kNoFlu sh 1403 // Since we're going to the draw target and not GPU, no need to check kNoFlu sh
1395 // here. 1404 // here.
1396 1405
1397 GrDrawTarget* target = this->prepareToDraw(NULL, NULL, NULL); 1406 GrDrawTarget* target = this->prepareToDraw(NULL, NULL, NULL, NULL);
1398 if (NULL == target) { 1407 if (NULL == target) {
1399 return; 1408 return;
1400 } 1409 }
1401 target->copySurface(dst, src, srcRect, dstPoint); 1410 target->copySurface(dst, src, srcRect, dstPoint);
1402 1411
1403 if (kFlushWrites_PixelOp & pixelOpsFlags) { 1412 if (kFlushWrites_PixelOp & pixelOpsFlags) {
1404 this->flush(); 1413 this->flush();
1405 } 1414 }
1406 } 1415 }
1407 1416
1408 void GrContext::flushSurfaceWrites(GrSurface* surface) { 1417 void GrContext::flushSurfaceWrites(GrSurface* surface) {
1409 if (surface->surfacePriv().hasPendingWrite()) { 1418 if (surface->surfacePriv().hasPendingWrite()) {
1410 this->flush(); 1419 this->flush();
1411 } 1420 }
1412 } 1421 }
1413 1422
1414 GrDrawTarget* GrContext::prepareToDraw(GrPipelineBuilder* pipelineBuilder, 1423 GrDrawTarget* GrContext::prepareToDraw(GrPipelineBuilder* pipelineBuilder,
1424 GrRenderTarget* rt,
1415 const GrPaint* paint, 1425 const GrPaint* paint,
1416 const AutoCheckFlush* acf) { 1426 const AutoCheckFlush* acf) {
1417 if (NULL == fGpu) { 1427 if (NULL == fGpu) {
1418 return NULL; 1428 return NULL;
1419 } 1429 }
1420 1430
1421 ASSERT_OWNED_RESOURCE(fRenderTarget.get());
1422 if (pipelineBuilder) { 1431 if (pipelineBuilder) {
1423 SkASSERT(paint && acf); 1432 ASSERT_OWNED_RESOURCE(rt);
1424 pipelineBuilder->setFromPaint(*paint, fRenderTarget.get()); 1433 SkASSERT(rt && paint && acf);
1434 pipelineBuilder->setFromPaint(*paint, rt);
1425 pipelineBuilder->setState(GrPipelineBuilder::kClip_StateBit, 1435 pipelineBuilder->setState(GrPipelineBuilder::kClip_StateBit,
1426 fClip && !fClip->fClipStack->isWideOpen()); 1436 fClip && !fClip->fClipStack->isWideOpen());
1427 } 1437 }
1428 fDrawBuffer->setClip(fClip); 1438 fDrawBuffer->setClip(fClip);
1429 return fDrawBuffer; 1439 return fDrawBuffer;
1430 } 1440 }
1431 1441
1432 /* 1442 /*
1433 * This method finds a path renderer that can draw the specified path on 1443 * This method finds a path renderer that can draw the specified path on
1434 * the provided target. 1444 * the provided target.
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
1501 SkNEW_ARGS(GrIndexBufferAllocPool, (fGpu, false, 1511 SkNEW_ARGS(GrIndexBufferAllocPool, (fGpu, false,
1502 DRAW_BUFFER_IBPOOL_BUFFER_SIZE, 1512 DRAW_BUFFER_IBPOOL_BUFFER_SIZE,
1503 DRAW_BUFFER_IBPOOL_PREALLOC_BUFFERS)); 1513 DRAW_BUFFER_IBPOOL_PREALLOC_BUFFERS));
1504 1514
1505 fDrawBuffer = SkNEW_ARGS(GrInOrderDrawBuffer, (fGpu, 1515 fDrawBuffer = SkNEW_ARGS(GrInOrderDrawBuffer, (fGpu,
1506 fDrawBufferVBAllocPool, 1516 fDrawBufferVBAllocPool,
1507 fDrawBufferIBAllocPool)); 1517 fDrawBufferIBAllocPool));
1508 } 1518 }
1509 1519
1510 GrDrawTarget* GrContext::getTextTarget() { 1520 GrDrawTarget* GrContext::getTextTarget() {
1511 return this->prepareToDraw(NULL, NULL, NULL); 1521 return this->prepareToDraw(NULL, NULL, NULL, NULL);
1512 } 1522 }
1513 1523
1514 const GrIndexBuffer* GrContext::getQuadIndexBuffer() const { 1524 const GrIndexBuffer* GrContext::getQuadIndexBuffer() const {
1515 return fGpu->getQuadIndexBuffer(); 1525 return fGpu->getQuadIndexBuffer();
1516 } 1526 }
1517 1527
1518 namespace { 1528 namespace {
1519 void test_pm_conversions(GrContext* ctx, int* pmToUPMValue, int* upmToPMValue) { 1529 void test_pm_conversions(GrContext* ctx, int* pmToUPMValue, int* upmToPMValue) {
1520 GrConfigConversionEffect::PMConversion pmToUPM; 1530 GrConfigConversionEffect::PMConversion pmToUPM;
1521 GrConfigConversionEffect::PMConversion upmToPM; 1531 GrConfigConversionEffect::PMConversion upmToPM;
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
1597 } 1607 }
1598 } 1608 }
1599 1609
1600 void GrContext::removeGpuTraceMarker(const GrGpuTraceMarker* marker) { 1610 void GrContext::removeGpuTraceMarker(const GrGpuTraceMarker* marker) {
1601 fGpu->removeGpuTraceMarker(marker); 1611 fGpu->removeGpuTraceMarker(marker);
1602 if (fDrawBuffer) { 1612 if (fDrawBuffer) {
1603 fDrawBuffer->removeGpuTraceMarker(marker); 1613 fDrawBuffer->removeGpuTraceMarker(marker);
1604 } 1614 }
1605 } 1615 }
1606 1616
OLDNEW
« no previous file with comments | « src/gpu/GrBitmapTextContext.cpp ('k') | src/gpu/GrDistanceFieldTextContext.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698